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 problem

Former Member
0 Likes
767

Hi,

I need to fetch multiple records from an interntal table using another internal table. ARC_PPDIX is an internal table that has multiple records for each selection of select_kostl-docnum and select_kostl-doclin. I am aware of 'FOR ALL ENTRIES' syntax but it works only in case of DB tables. Now I am able to retrieve just one record for each query. How can I change this code to get the desired result?

Here is the code.

LOOP AT select_kostl.

read TABLE ARC_PPDIX with key docnum = select_kostl-docnum

doclin = select_kostl-doclin binary search.

if sy-subrc = 0.

MOVE-CORRESPONDING ARC_PPDIX TO run_doc_xref.

Append run_doc_xref.

clear run_doc_xref.

ENDIF.

ENDLOOP.

Thanks,

VG

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
664

Hi,

You will have to use a loop inside another loop as you say there is many to many relation.


LOOP AT select_kostl.
loop at ARC_PPDIX where docnum = select_kostl-docnum and
doclin = select_kostl-doclin 
MOVE-CORRESPONDING ARC_PPDIX TO run_doc_xref.
Append run_doc_xref.
clear run_doc_xref.
endloop.
ENDLOOP.

.

Hope this helps.

Regards,

Sachin

4 REPLIES 4
Read only

Former Member
0 Likes
665

Hi,

You will have to use a loop inside another loop as you say there is many to many relation.


LOOP AT select_kostl.
loop at ARC_PPDIX where docnum = select_kostl-docnum and
doclin = select_kostl-doclin 
MOVE-CORRESPONDING ARC_PPDIX TO run_doc_xref.
Append run_doc_xref.
clear run_doc_xref.
endloop.
ENDLOOP.

.

Hope this helps.

Regards,

Sachin

Read only

Former Member
0 Likes
664

Hi,

If u have to fetch multiple records based on another internal table, you cannot use READ statement since its fetches only one record per main loop. what you can do is write a nested loop and acheive it.


LOOP AT select_kostl.
LOOP AT ARC_PPDIX where docnum = select_kostl-docnum and doclin = select_kostl-doclin binary search.
MOVE-CORRESPONDING ARC_PPDIX TO run_doc_xref.
Append run_doc_xref.
clear run_doc_xref.
ENDLOOP.
ENDLOOP.

Regards,

Vik

Read only

former_member194669
Active Contributor
0 Likes
664

Try with loop inside loop


LOOP AT select_kostl.
LOOP AT ARC_PPDIX where  docnum = select_kostl-docnum
                                    and  doclin = select_kostl-doclin.
MOVE-CORRESPONDING ARC_PPDIX TO run_doc_xref.
Append run_doc_xref.
ENDLOOP.
ENDLOOP.

a®

Read only

0 Likes
664

thanks. I was aware of using NESTED loops. I wanted to know is there a different way keeping the performance in view. it seems nested loop is the uanimous choice.

VG