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: 

Query in loop....!

sap_pak_lhr
Discoverer
334
  • SAP Managed Tags:
HI all,

Can anybody tell me the alternative method to avoid query in loop.

Code: (Alternative Method is required).

DATA: vstlnr LIKE mast-stlnr.


LOOP AT stb1 INTO wa_stb1.
SELECT SINGLE stlnr FROM mast INTO vstlnr WHERE matnr = wa_stb1-idnrk.
wa_mast-stlnr = vstlnr.
append wa_mast to it_mast.

ENDLOOP.

Regards,

1 ACCEPTED SOLUTION

Harish_Vatsa
Active Contributor
235
  • SAP Managed Tags:

Dear Shahzaib,
Can you please try the following:

DATA: lt_mast TYPE TABLE OF mast,
ls_mast LIKE LINE OF lt_mast.
SELECT matnr stlnr FROM mast INTO TABLE lt_mast FOR ALL ENTRIES IN stb1 WHERE matnr = stb1-idnrk.
LOOP AT stb1 INTO wa_stb1.
READ TABLE lt_mast INTO ls_mast WITH KEY matnr = wa_stb1-idnrk.
IF sy-subrc = 0.
wa_mast-stlnr = ls_mast-stlnr.
APPEND wa_mast TO it_mast.
ENDIF.
ENDLOOP.
3 REPLIES 3

Harish_Vatsa
Active Contributor
236
  • SAP Managed Tags:

Dear Shahzaib,
Can you please try the following:

DATA: lt_mast TYPE TABLE OF mast,
ls_mast LIKE LINE OF lt_mast.
SELECT matnr stlnr FROM mast INTO TABLE lt_mast FOR ALL ENTRIES IN stb1 WHERE matnr = stb1-idnrk.
LOOP AT stb1 INTO wa_stb1.
READ TABLE lt_mast INTO ls_mast WITH KEY matnr = wa_stb1-idnrk.
IF sy-subrc = 0.
wa_mast-stlnr = ls_mast-stlnr.
APPEND wa_mast TO it_mast.
ENDIF.
ENDLOOP.

235
  • SAP Managed Tags:

Thank u soo much for the guidence.

235
  • SAP Managed Tags:

Dear Shahzaib,

Happy to help you. Keep posting in SAP community.

--

Regards,

H.V.