‎2018 Oct 17 10:13 AM
I know that the instruction read table reads only one row but if I put it inside a loop it will read multiple rows right ?
refer to my code below :
select vbpa~parvw kna1~kunnr vbap~netwr from vbap
inner join vbpa on vbap~vbeln = vbpa~vbeln
inner join kna1 on vbpa~kunnr = kna1~kunnr
into corresponding fields of table gt_local
where ( vbpa~parvw = 'AG' ) and
kna1~kunnr in s_kunnr .
loop at gt_local into gs_local .
collect gs_local into gt_local2 .
endloop .
select *
from vbpa as a inner join vbap as b on ( a~vbeln = b~vbeln )
inner join vbfa as c on ( c~vbelv = b~vbeln )
inner join lips as d on ( d~vbeln = c~vbeln and d~posnr = c~posnn )
into corresponding fields of table gt_local3
where ( a~parvw = 'WE' )
and c~vbtyp_n = 'J' or c~vbtyp_n = 'R' .
clear gt_local .
clear gs_local .
loop at gt_local3 into gs_local3 where vbtyp_n = 'J'.
collect gs_local3 into gt_local.
endloop.
*
loop at gt_local2 into gs_local2 .
move sy-tabix to lv_index .
read table gt_local into gs_local with key kunnr = gs_local2-kunnr .
gs_local2-lfimg = gs_local-lfimg.
modify gt_local2 from gs_local2 index lv_index .
endloop.
*
clear gt_local .
clear gs_local .
loop at gt_local3 into gs_local3 where vbtyp_n ='R'.
collect gs_local3 into gt_local.
endloop.
loop at gt_local2 into gs_local2 .
move sy-tabix to idx .
read table gt_local into gs_local with key kunnr = gs_local2-kunnr .
gs_local2-rfmng = gs_local-rfmng.
modify gt_local2 from gs_local2 index idx .
endloop.
‎2018 Oct 17 3:06 PM
Read statement used inside or outside the loop will give you only 1 record. Read statement will never return multiple records back.
If you want to access multiple records then go for loop.
‎2018 Oct 17 11:25 AM
What is the reason of this question? ABAP has its statement to read multiple rows from internal table.
And the answer to your question is "maybe", because if the read condition doesn't change, you can have a 100000000 cycles loop and still read the same record.
‎2018 Oct 17 11:37 AM
‎2018 Oct 17 12:16 PM
Apart the naming convention totally scarying from my point of view (G... for global and name local, local2, local3) which makes really hard for me trying to understand what are you trying to achieve, the first question i have is: did you set a breakpoint on the read and debug it?
‎2018 Oct 17 3:06 PM
Read statement used inside or outside the loop will give you only 1 record. Read statement will never return multiple records back.
If you want to access multiple records then go for loop.