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

Insert statement inside loop

former_member186648
Active Contributor
0 Likes
4,665
   LOOP AT lr_strucdescr->components ASSIGNING <ls_fieldname>.

*   INSERTs
    ASSIGN COMPONENT     <ls_fieldname>-name
           OF STRUCTURE  is_insert
           TO            <lt_data>.         
...
        INSERT (<ls_fieldname>-name) FROM TABLE <lt_data>.
endloop.
What does this INSERT statement do?
Moderator message: Please read F1 help of insert statement

Message was edited by: Kesavadas Thekkillath

8 REPLIES 8
Read only

Former Member
0 Likes
2,459

Hi Pradeep,

Search in ABAP Keyword Documentation .

Regard's

Smruti

Read only

arindam_m
Active Contributor
0 Likes
2,459

Hi,

Take cursor on the word do F1 you will know

Cheers,

Arindam

Read only

Former Member
0 Likes
2,459

Hi Pradeep,

That insert statement is used to insert multiple lines/records from internal table to database table.

INSERT (<ls_fieldname>-name) FROM TABLE <lt_data>.

Here <ls_fieldname>-name contains the name of the DB Table. ( ) Represents token. So that  <ls_fieldname>-name is replaced with its containing value. And <lt_data> is the field symbol pointing to a table.

In short,

Inserting Several Lines

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 <itab> to the database table in one single operation. The same rules apply to the line type of <itab> as to the work area <wa> described above.

Refer following link.....
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm

- Regards

ShashanK MarathE

Read only

uppu_narayan
Active Participant
0 Likes
2,459

Hi Pradeep,

     The following  insert statement will throw you dump.....

        INSERT (<ls_fieldname>-name) FROM TABLE <lt_data>...........since that table name is not existing.....

regards,

narayan


Read only

Former Member
0 Likes
2,459

Hi Pradeep,

According to my knowledge it gives dump, because the attribute <ls_fieldname>-name holds the field name no the database table name. So it is not possible to insert the work area into field name.

INSERT <dbname> FROM TABLE itab.

The syntax is use should use the database table name.

So it gives dump.

Or you can store your database table name into some variable and it can be used as:

INSERT (lv_database) FROM TABLE itab.

Read only

0 Likes
2,459

If you use variable name inside the ( ), then the value inside that variable name will be considered.

Read only

Former Member
0 Likes
2,459

Hi Pradeep,

This will give you a Dump.

I guess you are using type descriptor, If that is the case the proper way to insert is using a Table Name. This can be done using a method in type descriptor get_ddic_structure. Use this and you will get the table name, now store it in a variable (lv_name) now use INSERT ( lv_name )

Regards,

Pratheek

Read only

uppu_narayan
Active Participant
0 Likes
2,459

Hi Pradeep,

     your code should be somewhat like this.......

field-symbol: <f1> type any.

   LOOP AT lr_strucdescr->components ASSIGNING <ls_fieldname>.
            ASSIGN COMPONENT     <ls_fieldname>-name  OF STRUCTURE  ls_insert   to <f1>.        

           INSERT (lv_tablename) FROM <f1>.

endloop.

since your assign statement will be returning a name from structure ls_insert and not an internal table

regards,

narayan