Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Replacement for SADR

Former Member
0 Likes
2,706

I'm learning to work with ABAP-SAP and I want to know how can I replace this obsolete code:

SELECT SINGLE * FROM SADR

     WHERE ADRNR EQ T001-ADRNR

I know SADR table is obsolet but I don´t know where do I start to replace this code.

Please somebody help me.

Thanks in advanced.

Message was edited by: Matthew Billingham - added meaningful subject.

I'm learning to work with ABAP-SAP and I want to know how can I replace this obsolete code:

SELECT SINGLE * FROM SADR

     WHERE ADRNR EQ T001-ADRNR

I know SADR table is obsolet but I don´t know where do I start to replace this code.

Please somebody help me.

Thanks in advanced.

Message was edited by: Matthew Billingham - added meaningful subject.

14 REPLIES 14
Read only

Former Member
0 Likes
2,279

Hey mate,

Easy fix, just do the following,

SELECT UP TO 1 ROWS

                     INTO lv_address

                     FROM adrc

                    WHERE addrnumber EQ lv_t001-adrnr

                      AND date_from  LE sy-datum

                      AND date_to    GE sy-datum.

   ENDSELECT.

Make sure when doing a select statement always use the SELECT / ENDSELECT and UP TO 1 ROWS when you are not selecting the whole key of a table. Just using SELECT SINGLE will sometimes get you the wrong result.

Cheers

Shaun

Read only

0 Likes
2,279

Hey, thanks for the response, but, what if I use call function

WK_ADDR_SEL-ADDRNUMBER  = TVBUR-ADRNR.

CALL FUNCTION 'ADDR_GET'

            EXPORTING

              ADDRESS_SELECTION       = WK_ADDR_SEL

            IMPORTING

              SADR                    = SADR

            EXCEPTIONS

              PARAMETER_ERROR         = 1

              ADDRESS_NOT_EXIST       = 2

              VERSION_NOT_EXIST       = 3

              INTERNAL_ERROR          = 4

              OTHERS                  = 5.

what´s your opinion.

thank u.

Read only

0 Likes
2,279

Hi,

If you have a FM then you should go with it. But its all based on your requirement.

I checked the the above FM and its retrieving the value from SADR.

All you need to do is, declare an internal table of type sadr and use it in the importing parameter.

Regards.

Read only

0 Likes
2,279

Hi  alejandro Alvarez ,

Try like this

DATA : wa_adrc TYPE adrc.

SELECT SINGLE * FROM adrc
                 INTO wa_adrc
                 WHERE addrnumber EQ wa_t001-adrnr
                 AND date_from  LE sy-datum
                 AND date_to    GE sy-datum.

If your requirement fulfills with  Function Module ADDR_GET

then you can proceed with that......

Read only

matt
Active Contributor
0 Likes
2,279

Shaun Bradridge wrote:

Hey mate,

Easy fix, just do the following,

SELECT UP TO 1 ROWS

                     INTO lv_address

                     FROM adrc

                    WHERE addrnumber EQ lv_t001-adrnr

                      AND date_from  LE sy-datum

                      AND date_to    GE sy-datum.

   ENDSELECT.

Make sure when doing a select statement always use the SELECT / ENDSELECT and UP TO 1 ROWS when you are not selecting the whole key of a table. Just using SELECT SINGLE will sometimes get you the wrong result.

Cheers

Shaun

Wrong.

Read only

0 Likes
2,279

Thanks for the kind words Matthew really helpful pointing out problems without giving resolution, but you are right, when you look at the sql statements that are actually the same when you use Select single or UP to 1 rows. It is just a developers best practice to use UP to 1 rows when not selecting from the whole key.

Shaun

Only

Read only

matt
Active Contributor
0 Likes
2,279

I thought highlighting the incorrect statement was sufficient explanation.

"Just using SELECT SINGLE will sometimes get you the wrong result." No, it won't.

Is that enough?

It is not, in my view, developers best practice to use up to 1 rows when not selecting the whole key. It makes the code less readily understandable, so I think it is bad programming practice. SELECT SINGLE as an existence check, or when I'm only wanting results from part of the key, or where the table has a unique index that I'm actually using is perfectly acceptable. The only reason, in my view, that the SELECT ... UP TO 1 ROWS came up was because SLIN at one time objected to a SELECT SINGLEs where the full primary key isn't specified. Unfortunately many programmers (and QA departments) take SLIN as law, rather than as guidance - resulting in more complex code with all the consequences of that.

On this site, there are many myths that are perpetuated. If someone gives incorrect technical information I will point it out. Rejecting the post is an option, but I feel that closes discussion.

Read only

0 Likes
2,279

Hi Ramesh I mean ,  if I want to use a function module, what FM would I use, because I have seen several options about that.

Can you tell me.

Thanks in advanced

Read only

former_member192854
Active Participant
0 Likes
2,279

DATA lw_sadr TYPE sadr.

DATA lw_t001 TYPE t0001.

* First fetch your lw_t001 variable

SELECT SINGLE *

    INTO lw_sadr

    FROM sadr

     WHERE adrnr EQ lw_t001-adrnr.

Read only

Former Member
0 Likes
2,279

SELECT SINGLE * FROM SADR

     WHERE ADRNR EQ T001-ADRNR

In this query where you are storing your result. You need to create a workarea of type SADR and store your result into that.

Read only

Former Member
0 Likes
2,279

Hi , EASY ANSWER

data   lv_var type sadr .   

  SELECT SINGLE * FROM SADR

                      Into lv_var

                        WHERE ADRNR EQ T001-ADRNR

Read only

0 Likes
2,279

Hello Shiva,

what is the difference between ans posted by you and ans posted by ..???

small tip for you.. lv_var means (lv- local variable) which is use for single value.. you you want to make a work area the either use wa_var(work area) or ls_var(local structure)..

Read only

sivaganesh_krishnan
Contributor
0 Likes
2,279

HI alejandro,

ADRC is the central address table. It is has any address that you enter in SAP.

SADR is no longer used, it was the table prior to ADRC.

Check  OSS note 85676 - Customer objects: conversion of SADR addresses.

You can code it like :

Select single *

           from   adrc

            into   internal_table

        where condition.

Regards,

sivaganesh

Read only

Former Member
0 Likes
2,279

Hi Alvarez,

ADRC is the central address table. U can use this table as a replacement of SADR table.. and use ADDRNUMBER (address no) fied in where condition.

One more thing, create a work area (type ADRC) to hold the fetched values..