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

Can not insert or update [TABLE] from internal table in method

Former Member
0 Likes
2,744

I've faced a problem with OO abap. I've tried to insert into [ TABLE ] from internal table, but i've got error msg after i compiled.

"An explicit work area is necessary in the OO context. Use "INSERT wa INTO [TABLE] itab""

After i changed to loop in work area and INSERT INTO [TABLE] VALUES gw_data., everything is fine, can compile and run.

This is error code.


  METHOD set_data_to_table.
    REFRESH gi_data.
    CLEAR gi_data.

    IF gi_file[] IS NOT INITIAL.
* Set data for modify table
      LOOP AT gi_file INTO gw_file.
        MOVE-CORRESPONDING gw_file TO gw_data.

        me->conversion_input( EXPORTING im_vendor = gw_data-vendor
                              CHANGING  ch_vendor = gw_data-vendor ).
        APPEND gw_data TO gi_data.
      ENDLOOP.


      INSERT [TABLE] FROM TABLE gi_data.

*      LOOP AT gi_data INTO gw_data.
*        INSERT INTO  [TABLE] VALUES gw_data.
*        IF sy-subrc = 0.
*          COMMIT WORK.
*        ELSE.
*          ROLLBACK WORK.
*        ENDIF.
*      ENDLOOP.
    ELSE.
      MESSAGE 'No data found' TYPE 'I'.
    ENDIF.

  ENDMETHOD.                    "set_data_to_table

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,732

If I understand correctly, you're wanting to update a database table from an internal table in the method. You've tried:

INSERT my_dbtable FROM TABLE gi_data.

but that doesn't work. So you've tried.

INSERT INTO  my_dbtable VALUES gw_data.

Which compiles but doesn't give you the right result?

The correct syntax is

INSERT INTO my_dbtable FROM TABLE gi_data.

By the way, in a OO context, you don't have tables with header lines, so you don't need IF gi_file[] IS NOT INITIAL. rather use IF gi_file IS NOT INITIAL.

4 REPLIES 4
Read only

Former Member
0 Likes
1,732

is it possible that i use insert or update [TABLE] from internal table in method ?

Read only

matt
Active Contributor
0 Likes
1,733

If I understand correctly, you're wanting to update a database table from an internal table in the method. You've tried:

INSERT my_dbtable FROM TABLE gi_data.

but that doesn't work. So you've tried.

INSERT INTO  my_dbtable VALUES gw_data.

Which compiles but doesn't give you the right result?

The correct syntax is

INSERT INTO my_dbtable FROM TABLE gi_data.

By the way, in a OO context, you don't have tables with header lines, so you don't need IF gi_file[] IS NOT INITIAL. rather use IF gi_file IS NOT INITIAL.

Read only

Clemenss
Active Contributor
0 Likes
1,732

Hi Matthew,

I think there is no difference in database insert between OO and non-OO.

The correct syntax according to ECC600 online documentation is

[Inserting Several Lines|http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm]

--

To insert several lines into a database table, use the following:

INSERT target FROM TABLE itab \[ACCEPTING DUPLICATE KEYS].

This writes all lines of the internal table itabto the database table in one single operation. If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS.

Whenever you want to insert more than one line into a database table, it is more efficient to work with an internal table than to insert the lines one by one.

--

I think the syntax


INSERT my_dbtable FROM TABLE gi_data.

should work, your suggestion may lead to syntax error.

Regards,

Clemens

Read only

matt
Active Contributor
0 Likes
1,732

You're correct. My bad...