Skip to Content
-1

All data from internal table is not being retrieved

Nov 09, 2016 at 10:16 PM

48

avatar image
Former Member

In my table control, the internal table "IT_SITEM" seems to be working right since it displays all values appended to it.

But when i tried to get the values from the internal table and insert it into my database table, only the last record appended to it is being retrieved.

WHEN 'ADD'.
    SELECT INAME SUNIT PRICE FROM Z032_ITEM_DB INTO CORRESPONDING FIELDS OF wa_sitem1 WHERE INAME EQ ITEM_NAME.

      wa_sitem1-SNUM = SO_NUM.

      wa_SITEM1-DQTY = DSP_QTY.

      ENDSELECT.

      APPEND wa_sitem1 TO it_sitem.

WHEN 'SAVE'.
    LOOP AT it_sitem INTO wa_sitem.

        wa_itemsold-SNUM = wa_sitem-SNUM.

        wa_itemsold-SQUA = wa_sitem-DQTY.

        SELECT INUM FROM Z032_ITEM_DB INTO CORRESPONDING FIELDS OF wa_itemsold WHERE INAME EQ wa_sitem-INAME.
        ENDSELECT.

      ENDLOOP.

    INSERT INTO Z032_ITEMSOLD_DB VALUES wa_itemsold.
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Nov 10, 2016 at 03:11 AM
1

Hey mate, your insert 'INSERTINTO Z032_ITEMSOLD_DB VALUES wa_itemsold.' Is outside of your loop. You could either move this above the ENDLOOP.

SELECT INUM FROM Z032_ITEM_DB INTO CORRESPONDING FIELDS OF wa_itemsold WHERE INAME EQ wa_sitem-INAME.
        ENDSELECT.

      INSERT INTO Z032_ITEMSOLD_DB VALUES wa_itemsold.

      ENDLOOP.

    "" comment out / delete 
    "" INSERT INTO Z032_ITEMSOLD_DB VALUES wa_itemsold.

Or during your loop you could append wa_itemsold to an internal table similarly to what you are doing with wa_sitem1 to it_sitem earlier in your code.

 SELECT INUM FROM Z032_ITEM_DB INTOCORRESPONDINGFIELDSOF wa_itemsold WHERE INAME EQ wa_sitem-INAME.
 APPEND wa_itemsold TO it_itemsold ""Ensure you have declared this table in your data statements.

Then insert from the internal table

INSERT Z032_ITEMSOLD_DB FROM TABLE it_itemsold
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

I actually got working then checked here. Yeah, the insert just needed to get inside the loop. Thanks

0

A simple check in the debugger would have solved your issue much faster than a post on the SCN...

Depending on the number of records you are trying to insert here, the second method that Dan Kennedy mentions with the INSERT ... FROM TABLE ... could be significantly faster.

0
Neil Morris Nov 09, 2016 at 11:23 PM
1

You are selecting into a structure in wa_itemsold and not appending to an internal table.

Append to an internal table and insert into Z032_ITEMSOLD_DB from the internal table.

Share
10 |10000 characters needed characters left characters exceeded
Raghu Govindarajan Nov 10, 2016 at 02:54 AM
0

Use the format INSERT target FROM TABLE itab [ACCEPTING DUPLICATE KEYS].

INSERT z032_itemsold_db FROM TABLE it_sitem.

You could have just looked at SAP help here https://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm?frameset=/en/fc/eb3ac8358411d1829f0000e829fbfe/frameset.htm¤t_toc=/en/d3/2e974d35c511d1829f0000e829fbfe/plain.htm&node_id=192

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Wrong table my man, he is selecting a different subset of data from it_sitem data - he doesnt want to insert taht data.

1

Yeah, I saw that after I posted - my bad for not correcting. In my quick scan that was the only internal table I saw. The important point is the format of the statement, and the fact that you do have to use an internal table and not just a one line structure if you are hoping to insert more than one record! Or like you said call it one line at a time several times.

0