Application Development 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: 

inserting into a database table using field symbols?

Former Member
0 Kudos

Hi.

If I have a database table that I do not know the name at design-time, how do i insert records into that database table at run-time?

****************************************************************************************

Do i use field-symbols, as follow:

FIELD-SYMBOLS <TABLE_NAME> TYPE TABLE.

INSERT <TABLE_NAME> FROM ITAB.

1 ACCEPTED SOLUTION

h_senden2
Active Contributor

I dont think this will work.

You have to put the DB table's name into the fieldsymbol. Maybe you have to try the next code.

data: l_dbname(30) type c value 'VBAK'.

field-symbols: <fs>.

assign (l_dbname) to <fs>.

check sy-subrc eq 0.

insert <fs> from itab.

regards,

hans

7 REPLIES 7

h_senden2
Active Contributor

I dont think this will work.

You have to put the DB table's name into the fieldsymbol. Maybe you have to try the next code.

data: l_dbname(30) type c value 'VBAK'.

field-symbols: <fs>.

assign (l_dbname) to <fs>.

check sy-subrc eq 0.

insert <fs> from itab.

regards,

hans

Former Member
0 Kudos

Hi, thanks for the prompt reply.

I did something similar to your codes, but it got a syntax error:

************************************************************************

FIELD-SYMBOLS: <DTAB>.

DATA: DTABNAME(20) TYPE C VALUE 'ZTABLE'.

"ZTABLE = SAP Database Table Name

ASSIGN (DTABNAME) TO <DTAB>.

INSERT <TRYOUT1> FROM TABLE UPITAB.

"ITAB = Internal Table with same type as ZTABLE

************************************************************************

I got the error message: Field "FROM" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement.

h_senden2
Active Contributor
0 Kudos

strange !

according to the F1 for the INSERT statement you can use

INSERT dbtab FROM TABLE itab. or

INSERT (dbtabname) FROM TABLE itab.

So the 2nd solution can also be used in stead of field-symbol.

regards

Hans

Former Member
0 Kudos

Hi Hans, thanks a million for the last post.

It solved my problem! All I need to do is to change <DTAB> to (DTABNAME) in the INSERT statement.

i.e. INSERT <DTAB> FROM TABLE UPITAB. ==> WRONG

INSERT (DTABNAME) FROM TABLE UPITAB. ==> CORRECT.

Thanks for your help, points given

######################################################

I did something similar to your codes, but it got a syntax error:

************************************************************************

FIELD-SYMBOLS: <DTAB>.

DATA: DTABNAME(20) TYPE C VALUE 'ZTABLE'.

"ZTABLE = SAP Database Table Name

ASSIGN (DTABNAME) TO <DTAB>.

INSERT <DTAB> FROM TABLE UPITAB.

"ITAB = Internal Table with same type as ZTABLE

************************************************************************

I got the error message: Field "FROM" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement.

h_senden2
Active Contributor
0 Kudos

you're welcome

Former Member
0 Kudos

.

Message was edited by:

Kian Keong

Former Member
0 Kudos

while declaring field symbol try :

FIELD-SYMBOLS <TABLE_NAME> TYPE ANY.