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

Query in loop....!

sap_pak_lhr
Discoverer
1,010
  • 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
Read only

Harish_Vatsa
SAP Champion
SAP Champion
911
  • 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
Read only

Harish_Vatsa
SAP Champion
SAP Champion
912
  • 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.
Read only

911
  • SAP Managed Tags

Thank u soo much for the guidence.

Read only

911
  • SAP Managed Tags

Dear Shahzaib,

Happy to help you. Keep posting in SAP community.

--

Regards,

H.V.