‎2006 Jul 25 10:03 AM
Hi Gurus,
i have a difficult question, and i currently do not know how find a solution. I would like to add a entry in a database table, but i only know the name through runtime. So my insert should generic. I am able to create the Structure type of the table, but how do i assign the values to the components,
here is the source code i tried.
FIELD-SYMBOLS: <ITAB> TYPE TABLE.
FIELD-SYMBOLS: <FIELD> TYPE ANY.
FIELD-SYMBOLS: <ROW> TYPE ANY.
data: table_fields like dbfield occurs 0 with header line.
data: TABNAME LIKE DD02L-TABNAME Value 'ZKW1'.
data: itab type ref to data.
data: lrow type ref to data.
create data: itab type standard table of (tabname).
create data: lrow type (tabname).
assign: itab->* to <itab>.
assign: lrow to <row>.
call function 'DB_GET_TABLE_FIELDS'
exporting
FIELD_INFO = 'A'
tabname = tabname
IMPORTING
SUBRC =
tables
dbfields = table_fields
exceptions
others = 1.
sort table_fields by keyflag descending keypos column.
do.
read table table_fields index sy-index.
this will always fail, because the Structure is initial.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <row> TO
<FIELD>.
if sy-subrc <> 0.
exit.
endif.
<FIELD> = 'TEST'.
enddo.
insert (tabname) from <row>.
this is just a test, later i have the values of the table fields in an internal table with position of the field in the structure (Position = 1, Value = '123423'.
best regards,
Kai
‎2006 Jul 25 10:20 AM
Hi kai,
Probably this code may help a little.
1. To display data of internal table, using field-symbols
2. just copy paste
Report abc.
*----
data : itab like t001 occurs 0 with header line.
*----
field-symbols : <ft> type table.
FIELD-SYMBOLS: <dynline> TYPE ANY.
FIELD-SYMBOLS: <fld> TYPE ANY.
select * from t001 into table itab.
*----
assign itab[] to <FT>.
LOOP AT <ft> ASSIGNING <DYNLINE>.
sy-subrc = 0.
write 😕 '----
'.
WHILE SY-SUBRC = 0.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYNLINE> TO <FLD>.
WRITE : <FLD>.
ENDWHILE.
ENDLOOP.
regards,
amit m.
‎2006 Jul 25 10:12 AM
‎2006 Jul 25 10:20 AM
you mean by defining the Fields and Values separately?
Can you explain that in more detail?
‎2006 Jul 25 10:17 AM
hi Kai,
try this
REPORT ABC.
TABLES : DD03L.
PARAMETERS : DTAB LIKE DD03L-TABNAME.
SELECT SINGLE TABNAME FROM (DTAB) INTO DD03L-TABNAME WHERE TABNAME =
'MARA'.where dtab is the parameter
‎2006 Jul 25 10:20 AM
Hi kai,
Probably this code may help a little.
1. To display data of internal table, using field-symbols
2. just copy paste
Report abc.
*----
data : itab like t001 occurs 0 with header line.
*----
field-symbols : <ft> type table.
FIELD-SYMBOLS: <dynline> TYPE ANY.
FIELD-SYMBOLS: <fld> TYPE ANY.
select * from t001 into table itab.
*----
assign itab[] to <FT>.
LOOP AT <ft> ASSIGNING <DYNLINE>.
sy-subrc = 0.
write 😕 '----
'.
WHILE SY-SUBRC = 0.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYNLINE> TO <FLD>.
WRITE : <FLD>.
ENDWHILE.
ENDLOOP.
regards,
amit m.
‎2006 Jul 25 10:27 AM
Thanks for your help,
but my problem is not the display of data this is working correctly, my problem is how to fill the values of the Workarea <ROW> by specifying simply the position of the Field, because <row>-fieldname is not working because i do not know the name during designtime, only on runtime.
best regards,
Kai
‎2006 Jul 25 11:56 PM
Hi guys,
thaanks for your help,
but i fixed it on my own. For those who are interested here is a sample.
DATA LID LIKE DD02L-TABNAME VALUE '/CAMELOT/DOCS'.
DATA L_T_PARAMS TYPE /CAMELOT/DCPF_T_PARAMS.
DATA: L_S_PARAMS TYPE /CAMELOT/DCPF_S_PARAM.
DATA: TABLE_FIELDS LIKE DBFIELD OCCURS 0 WITH HEADER LINE.
DATA L_DATA TYPE REF TO DATA.
DATA L_S_FIELDS TYPE DBFIELD.
DATA L_COLUMN TYPE I.
FIELD-SYMBOLS: <FIELD> TYPE ANY,
<FIELD2> TYPE ANY..
L_S_PARAMS-NAME = 1.
L_S_PARAMS-VALUE = 12345.
APPEND L_S_PARAMS TO L_T_PARAMS.
L_S_PARAMS-NAME = 2.
L_S_PARAMS-VALUE = 'Meins'.
APPEND L_S_PARAMS TO L_T_PARAMS.
*Create empty Data
CREATE DATA L_DATA TYPE (LID).
Dereference Structure to fieldsymbol
ASSIGN L_DATA->* TO <FIELD>.
Get Field Definition
CALL FUNCTION 'DB_GET_TABLE_FIELDS'
EXPORTING
TABNAME = LID
TABLES
DBFIELDS = TABLE_FIELDS
EXCEPTIONS
OTHERS = 1.
SORT TABLE_FIELDS BY KEYFLAG DESCENDING KEYPOS COLUMN.
*
LOOP AT TABLE_FIELDS INTO L_S_FIELDS.
L_COLUMN = L_S_FIELDS-COLUMN.
CLEAR L_S_PARAMS.
ASSIGN COMPONENT L_COLUMN OF STRUCTURE <FIELD> TO <FIELD2>.
READ TABLE L_T_PARAMS INTO L_S_PARAMS WITH KEY NAME = L_COLUMN.
IF SY-SUBRC = 0.
MOVE L_S_PARAMS-VALUE TO <FIELD2>.
ENDIF.
ENDLOOP.
INSERT (LID) FROM <FIELD>.
‎2025 Jan 27 1:14 PM
This is if you already know what the table is going to be. If you do not know the table /CAMELOT/DCPF_T_PARAMS, then you would use a generic type and then it would not let you use append.