Register Login

Loop Internal Table - Inner Join - Insert Into - only getting last row.

Updated May 18, 2018

I have a ABAP program where I read a file from the local machine into table (T_EXCEL) with 1 field.  In this case this is a list of order numbers.

This is working correctly where I am reading in the list (100 orders).  I am then trying to do a loop at this table selecting from 3 tables using inner joins to then insert into a different table.

I am only getting the last record from my table T_EXCEL in my table ORDLIST1

Here is my table def for T_EXCEL:

 

DATA:

BEGIN OF T_EXCEL OCCURS 0,
     VBELN LIKE VBAK-VBELN, 
END OF T_EXCEL.
 

************************** and here is my form I am having the issue with

 Form Get_SO_List2.
*
 SORT T_EXCEL.
*
LOOP AT T_EXCEL.
*
select VBAK~VBELN VBAK~ERDAT VBAK~ERZET VBAK~ERNAM VBAK~AUART
       VBAK~AUGRU VBAK~VKORG VBAK~VKGRP VBAK~VKBUR VBAK~VDATU
       VBAK~KUNNR VBAK~OBJNR VBAK~FAKSK VBAK~LIFSK VBAK~IHREZ
       VBAK~KVGR5
       VBUK~ABSTK VBUK~LFSTK VBUK~LFGSK
       VBAK~BSTNK VBUK~COSTA
       vbap~posnr  vbap~matnr vbap~matwa vbap~werks vbap~vstel
       vbap~kwmeng vbap~abgru vbap~pstyv vbap~route vbap~netpr
       vbap~ktgrm  vbap~kondm
         INTO TABLE ORDLIST1
           FROM ( (  VBAK
            INNER JOIN VBUK ON VBUK~VBELN = VBAK~VBELN )
            inner join vbap on vbap~vbeln = vbak~vbeln )
           WHERE VBAK~VBELN = T_EXCEL-VBELN.
  append ordlist1.
  clear: vbak, vbuk, vbap.
endloop.
loop at ordlist1.
   write:/ 'Ordlist1-SalesOrd - ', ordlist1-salesord.
endloop.

If I place a write statement above the select I do see this is looping through all 100 records, but my table ORDLIST1 only has 1 row populated instead of 100+.
 

What am I doing wrong?
Thanks!

 

 

*******************************************************************************************************
Here is my form where I am looping through T_EXCEL trying to insert the data into my table ORDLIST1.


Comments

  • 13 Aug 2008 2:14 am Guest
    Try to append from another table e.g ordlist2.
    because it may initialized the internal table when everytimes is used in a select statement.

    cheers.
  • 13 Aug 2008 2:25 am Sammy C. Marquez
    Or try to change the syntax of the select statement.

    select VBAK~VBELN VBAK~ERDAT VBAK~ERZET VBAK~ERNAM VBAK~AUART
    VBAK~AUGRU VBAK~VKORG VBAK~VKGRP VBAK~VKBUR VBAK~VDATU
    VBAK~KUNNR VBAK~OBJNR VBAK~FAKSK VBAK~LIFSK VBAK~IHREZ
    VBAK~KVGR5
    VBUK~ABSTK VBUK~LFSTK VBUK~LFGSK
    VBAK~BSTNK VBUK~COSTA
    vbap~posnr vbap~matnr vbap~matwa vbap~werks vbap~vstel
    vbap~kwmeng vbap~abgru vbap~pstyv vbap~route vbap~netpr
    vbap~ktgrm vbap~kondm
    APPENDING TABLE ORDLIST1
    FROM ( ( VBAK
    INNER JOIN VBUK ON VBUK~VBELN = VBAK~VBELN )
    inner join vbap on vbap~vbeln = vbak~vbeln )
    WHERE VBAK~VBELN = T_EXCEL-VBELN.
    append ordlist1. " remove this line
  • 13 Aug 2008 2:27 pm J. Himes
    The APPENDING TABLE ORDLIST1 instead of INTO TABLE did the trick!

    Thank you very much.

×