10-19-2007 11:40 AM
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.
10-19-2007 11:45 AM
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
10-19-2007 11:45 AM
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
10-19-2007 11:56 AM
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.
10-19-2007 12:00 PM
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
10-19-2007 12:09 PM
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.
10-19-2007 12:13 PM
10-19-2007 11:56 AM
10-19-2007 12:09 PM
while declaring field symbol try :
FIELD-SYMBOLS <TABLE_NAME> TYPE ANY.