Skip to Content
author's profile photo Former Member
-2
Former Member

Read table inside a loop .

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Oct 17, 2018 at 02: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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.