Application Development 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: 

checking for data in tables

Former Member
0 Kudos
108

hi gurus,

i have an itab which has fi transactional data , which inlcudes glaccounts with the name belnr.

now i need to check if each glaccount has a master data , if a match is not found that glaccounts must be stored to display later.

so i thought of doing this way, is it a best practise to do this way.

****************************

tables: skb1.

data : i_skb1 like skb1 occurs 0 with header line.

data:begin of i_saknr occurs 0,

saknr like skb1-saknr,

end of i_saknr.

loop at itab.

select single * from skb1 into i_skb1 where saknr EQ itab-belnr.

if sy-subrc <> 0.

i_saknr-saknr = itab-belnr.

append i_saknr.

endif.

endloop.

is there a better way of doing this.

4 REPLIES 4

Former Member
0 Kudos
81

Sanjana,

Do like this

tables: skb1.

data : i_skb1 like skb1 occurs 0 with header line.

types:begin of ty_saknr,
saknr like skb1-saknr,
end of ty_saknr.

data: i_saknr type table of ty_saknr,
        wa_saknr type ty_saknr.

select * from skb1 into table i_skb1 for all entries in itab where saknr EQ itab-belnr.
loop at itab into wa.
read table itab into wa with key saknr = wa-belnr.
if sy-subrc <> 0.
wa_saknr-saknr = wa-belnr.
append wa_saknr to i_saknr.
endif.
endloop.

Regards,

Satish

Former Member
0 Kudos
81

Hello,

Looks fine . If you can replace the Select End Select by a single select Query int an internal table and then Comapre the Entries with itab by a combination of loop and READ , then it would become better performance wise.

Regards

Saket Sharma

naimesh_patel
Active Contributor
0 Kudos
81

Try like this:

DATA : BEGIN OF I_SKB1 OCCURS 0,
       SAKNR TYPE SAKNR,
       END   OF I_SKB1.

DATA:BEGIN OF I_SAKNR OCCURS 0,
SAKNR LIKE SKB1-SAKNR,
END OF I_SAKNR.

* this will reduce DB access
SELECT SAKNR
       INTO TABLE I_SKB1
       FROM SKB1
       FOR  ALL ENTRIES IN ITAB
       WHERE SAKNR = ITAB-BELNR.


LOOP AT ITAB.
  READ TABLE I_SKB1 WITH KEY SAKNR = ITAB-BELNR.
  IF SY-SUBRC <> 0.
    I_SAKNR-SAKNR = ITAB-BELNR.
    APPEND I_SAKNR.
  ENDIF.
ENDLOOP.

Regards,

Naimesh Patel

Former Member
0 Kudos
81

Well, I don't think itab-belnr and skb1-saknr will be the same type.

And since you aren't using the company code (BUKRS), you should use SKA1 instead of SKB1.

Rob

Message was edited by:

Rob Burbank