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

Regarding source code evaluation

Former Member
0 Likes
1,087

Hi guys

Can you please suggest me whether below statements has any logical or performance problem?

1) Get address information of PO items and save it to internal table "address information".

Is the below logic is correct to fetch the address information?

Join with T001W buffered table is not good way to write code? pls confirm.

SELECT 
T001W~NAME1								
T001W~STRAS								
ADRC~STR_SUPPL2							
ADRC~TEL_NUMBER								
ADRC~FAX_NUMBER						
FROM T001W
JOIN ADRC
ON T001W~ADRNR = ADRC~ADDRNUMBER
FOR ALL ENTRIES IN Internal table "PO information"
INTO Internal table "address information"
WHERE T001W~WERKS = "PO information"-WERKS

2)Using Sort command before Read table binary search.

Gives error that "SORT does not exist before ( READ TABLE U_TG_ADDRESS ) or was not found."

is this incorrect logic error? should i have to use SORT command just before line of Read ....Binary search statement.?

or can i use anywhere before and go with below statement. pls confirm

i sorted below internal tables in Previous Subroutine Perform.
  SORT C_TG_ADDRESS   BY WERKS      ASCENDING.
  SORT C_TG_DRAW_NO   BY MATNR      ASCENDING.
  SORT C_TG_PO_MASTER BY EBELN      ASCENDING

In next subroutine Perform i used like this
  LOOP AT U_TG_PO_MASTER INTO WL_PO_MASTER.

*   Read PO address information
    READ TABLE U_TG_ADDRESS INTO WL_ADDRESS
    WITH KEY WERKS = WL_PO_MASTER-WERKS
    BINARY SEARCH.

*   Read Drawing No.
    READ TABLE U_TG_DRAW_NO INTO WL_DRAW_NO
    WITH KEY MATNR = WL_PO_MASTER-MATNR
    BINARY SEARCH.

Regards

Kumar

Edited by: princeck on Aug 8, 2011 1:39 PM

Edited by: princeck on Aug 8, 2011 1:48 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,052

Hi,

You could replace your code like below:

IF NOT i_poinfo IS  INITIAL.
    SELECT name1
           stras
           INTO TABLE i_t001w
           FROM t001w
           FOR ALL ENTRIES IN i_poinfo 
           WHERE werks = i_poinfo-werks.
    IF NOT i_t001w IS NOT INITIAL.
    SELECT
           str_suppl2
           tel_number
           fax_number
           INTO TABLE i_adrc
           FROM t001w 
           FOR ALL ENTRIES IN i_t001w 
           WHERE adrnr = i_t001w-addrnumber.
    ENDIF.
    ENDIF.

BR

Dep

10 REPLIES 10
Read only

Former Member
0 Likes
1,053

Hi,

You could replace your code like below:

IF NOT i_poinfo IS  INITIAL.
    SELECT name1
           stras
           INTO TABLE i_t001w
           FROM t001w
           FOR ALL ENTRIES IN i_poinfo 
           WHERE werks = i_poinfo-werks.
    IF NOT i_t001w IS NOT INITIAL.
    SELECT
           str_suppl2
           tel_number
           fax_number
           INTO TABLE i_adrc
           FROM t001w 
           FOR ALL ENTRIES IN i_t001w 
           WHERE adrnr = i_t001w-addrnumber.
    ENDIF.
    ENDIF.

BR

Dep

Read only

0 Likes
1,052

Hello deepak

Thanks for your reply.

Any idea about Sort statement

Appreciate your response.

Regards

kumar

Read only

0 Likes
1,052

For my previous post:

IF NOT i_poinfo IS  INITIAL.
    SELECT name1
           stras
           INTO TABLE i_t001w
           FROM t001w
           FOR ALL ENTRIES IN i_poinfo 
           WHERE werks = i_poinfo-werks.
    IF NOT i_t001w IS NOT INITIAL.
    SELECT str_suppl2
           tel_number
           fax_number
           INTO TABLE i_adrc
           FROM adrc
           FOR ALL ENTRIES IN i_t001w 
           WHERE adrnr = i_t001w-addrnumber.
    ENDIF.
  ENDIF.

Regarding SORT:

SORT U_TG_ADDRESS by werks ascending.
  SORT U_TG_DRAW_NO by matnr ascending.

  LOOP AT U_TG_PO_MASTER INTO WL_PO_MASTER.
 
*   Read PO address information
    READ TABLE U_TG_ADDRESS INTO WL_ADDRESS
    WITH KEY WERKS = WL_PO_MASTER-WERKS
    BINARY SEARCH.
 
*   Read Drawing No.
    READ TABLE U_TG_DRAW_NO INTO WL_DRAW_NO
    WITH KEY MATNR = WL_PO_MASTER-MATNR
    BINARY SEARCH.

or Just remove keyword BINARY SEARCH if the internal table you are reading is huge because this keyword BINARY SEARCH causes issues in Production with sy-subrc values 6 or 8.

BR

Dep

Read only

0 Likes
1,052

or Just remove keyword BINARY SEARCH if the internal table you are reading is huge because this keyword BINARY SEARCH causes issues in Production with sy-subrc values 6 or 8.

How does this make sense?

Rob

Read only

0 Likes
1,052

Hi Rob,

I faced this issue for one of my developments where I used:

Sort Itab by f1 f2.

then within the loop I used

Read table itab into wa with key a1 = loop-a1 BINARY SEARCH.

if sy-subrc eq 0.

*do something.

endif.

the above was creating problem as sy-subrc was set to 6 0r 8. So, I refered to my collegues and searched fourms where they suggested to remove the keyword BINARY SEARCH for some anonymous reason( I would really like to know why ). But did not remove SORT statement before entering loop.

So I made changes accordingly and it worked.

type declaation which I used for internal table was TYPE STANDARD TABLE of.. well I hear people of suggesting to use TYPE SORTED or HASHED.

But with very short period to complete the report such suggestions go unnoticed.

Probably when using TYPE STANDARD TABLE OF and using BINARY SEARCH there should be a :

SORT ITAB BY F1 F2.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING F1 F2.

then

SORT ITAB BY F1 F2.

Loop at itab2 into wa2.

read table itab into wa with key a1 = wa2-a1 BINARY SEARCH.

if sy-subrc eq 0.

*do something.

endif.

Would not result sy-subrc value to 6 or 8.

BR

Dep

Read only

0 Likes
1,052

Well, I think a READ statement can only return sy-subrc of 0, 4 or 8, but not 6.

For standard tables, removing the binary search option from a read statement will certainly work, but it will force a linear search, so depending on the number of entries, it may be prohobitavely expensive. It's better to get the binary search option working. Remember to use all aof the sort fileds in the keys. Better still to used sorted or hashed tables.

Rob

Read only

0 Likes
1,052

Thank You Rob.

BR

Dep

Read only

Former Member
0 Likes
1,052

Hi Kumar,

Let me know if you require any more info.

BR

Dep

Read only

0 Likes
1,052

Hi deepak

Thanks for your reply.

So you mean to say my above usage of sort statement is wrong?

Can you explain why Binary search will give sy-subrc 6 or 8.

I thaught Read statement have binary search will increase performance.

Regards

Chandra

Read only

0 Likes
1,052

> How does this make sense?

>

> Rob

It really does not !

> Can you explain why Binary search will give sy-subrc 6 or 8.

> I thaught Read statement have binary search will increase performance.

Yes, BINARY SEARCH option dramatically increases performance. But in order to work correctly, your internal table must be sorted first. If this is not the case, the READ statement can't find the correct record and you'll get SY-SUBRC = 8.

You can also try to use HASHED TABLES which are very fast to read but require an unique key defined on them.

See F1 help on READ statement for more details.

Regards.

Nicolas

Edited by: Nicolas Saulnier on Aug 8, 2011 5:00 PM