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

ABAP 7.4 - multiple FOR Vs Nested Loop operation

KumarAakash
Participant
0 Likes
12,156
DATA : it_review TYPE STANDARD TABLE OF z_review,<br>       it_roles TYPE STANDARD TABLE OF z_roles,<br>       it_count TYPE STANDARD TABLE OF z_count.<br><br>select * FROM z_review INTO TABLE it_review.      "--> count =     22477 Rows<br>  select * FROM z_roles INTO TABLE it_roles.       "---> count  =  858035 ROws <br>    select * FROM z_count   INTO TABLE it_count.    "---->count  =  187458 Rows <br><br>*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<br>data(gt_final) = VALUE lt_final( for lt_review in it_review<br>                          for ls_roles IN it_roles FROM line_index( it_roles[ AGR_NAME = lt_review-AGR_NAME  ] )<br>                          where ( AGR_NAME = lt_review-AGR_NAME )<br>                          for ls_count in it_count FROM line_index( it_count[ uname = lt_review-uname ] )<br>                          WHERE ( uname = lt_review-uname and tcode = ls_roles-tcode )<br>                          LET ls_final = VALUE ty_final(<br>                            uname = lt_review-uname<br>                           AGR_NAME = lt_review-AGR_NAME<br>                            tcode = ls_roles-tcode<br>                            count = ls_count-zcount )<br>                       IN ( CORRESPONDING #( BASE ( ls_final ) lt_review ) ) ).<br><br><br>   LOOP AT it_review INTO DATA(wa_review).<br>**         check if user and tcode has count..<br>      LOOP AT it_roles INTO DATA(wa_roles) WHERE agr_name = wa_review-agr_name.<br>         TRY .<br>           data(wa_count) = it_count[ UNAME = wa_review-uname TCODE = wa_roles-tcode  ].<br>         CATCH cx_sy_itab_line_not_found..<br>           CONTINUE.<br>         ENDTRY.<br>         write :/10  wa_review-uname  ,20  wa_review-agr_name , 60 wa_roles-tcode , 75 wa_count-zcount.<br>         exit.<br>        endloop.<br>       ENDLOOP.<br>
<br>

I need help / suggestion i m trying my hands on 7.4 syntax on SQL 'FOR " multiple joins and trying to check if i replace the nested looped operation , but my Nested FOR never gave the result where as nested Loop did gave output..

can you all help me figure out , where I going completely wrong...

Ask here is - if my FOR nested is wrong or right , how can design it such that it behaves as nested looped and i get final table appended with desired fields .. as i done in the above loop statments.

9 REPLIES 9
Read only

matt
Active Contributor
10,154

Edit your question and this time click on the "code" button in the question editor, and enter the code into a code box so that it's readable.

Read only

KumarAakash
Participant
0 Likes
10,154

thanks Mathew !! did exactly as asked .

Read only

Sandra_Rossi
Active Contributor
0 Likes
10,154

I think it's a better practice to explain the problem before the code.

Read only

Sandra_Rossi
Active Contributor
0 Likes
10,154

Your "for" loops look completely different from the second block, I don't understand what you want to achieve.

Read only

KumarAakash
Participant
0 Likes
10,154

sandra.rossi - i did mention in the above question , let me know if i need to add more details .. happy to help !!

Read only

Sandra_Rossi
Active Contributor
10,154

I don't understand how you came to have a so complex expression. Why not simplifying it:

data(gt_final) = VALUE lt_final( 
for wa_review in it_review for wa_roles IN it_roles where ( AGR_NAME = wa_review-AGR_NAME ) ( uname = wa_review-uname
agr_name = wa_review-agr_name
tcode = wa_roles-tcode
count = VALUE #( it_count[ UNAME = wa_review-uname TCODE = wa_roles-tcode ] OPTIONAL ) ) ).
Read only

KumarAakash
Participant
0 Likes
10,154

Thanks sandra.rossi for the code , I need some more help if you can suggest would be great.

in above code you have mentioned 2 FOR statement together with where single clause , does that mean if both are met then only record gets inserted in the GT_FINAL...

Read only

Sandra_Rossi
Active Contributor
10,154

Yes. Not different from your 2 LOOP AT.

   LOOP AT it_review INTO DATA(wa_review).
     LOOP AT it_roles INTO DATA(wa_roles) WHERE agr_name = wa_review-agr_name.
Read only

KumarAakash
Participant
0 Likes
10,154

Thanks @sandra rossi - for your help , I will mark it as close ...