‎2008 Jun 20 6:25 AM
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
‎2008 Jun 20 8:52 AM
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.
‎2008 Jun 20 8:01 AM
is it possible that i use insert or update [TABLE] from internal table in method ?
‎2008 Jun 20 8:52 AM
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.
‎2008 Jun 21 3:50 PM
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
‎2008 Jun 23 10:20 AM