‎2013 Dec 27 10:53 AM
Hello all,
I wrote a program, that generates an generic internal table.
In the red line (see coding below) I have a field-symbol <fs_table>,that has now 3 fields:
How can I write values to <fs_table>-FIELDNAME1, <fs_table>-FIELDNAME2 and <fs_table>-FIELDNAME3?
many Thanks & Regards Mario
REPORT Z_MM_GENPROG_002.
data: fieldname type string.
data: dyn_table type ref to data,
dyn_line type ref to data,
wa_fieldcat type lvc_s_fcat,
it_fieldcat type lvc_t_fcat.
field-symbols: <fs_table> type standard table,
<fs_wa>,
<fs_field>.
perform fill_fieldcat.
perform create_dynamic_table.
assign dyn_table->* to <fs_table>.
* Create dynamic work area and assign to Field Symbol
create data dyn_line like line of <fs_table>.
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT .
data: linecount type DDLENG.
DO 3 TIMES.
linecount = linecount + 1.
FIELDNAME = sy-index.
CONCATENATE 'FIELDNAME' FIELDNAME into FIELDNAME.
wa_fieldcat-fieldname = FIELDNAME.
wa_fieldcat-inttype = 'C'.
wa_fieldcat-DATATYPE = 'C'.
wa_fieldcat-INTLEN = linecount * 3.
append wa_fieldcat to it_fieldcat.
ENDDO.
ENDFORM. " FILL_FIELDCAT
*&---------------------------------------------------------------------*
*& Form CREATE_DYNAMIC_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CREATE_DYNAMIC_TABLE .
* Create dynamic internal table and assign to Field-Symbol
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = dyn_table.
ENDFORM. " CREATE_DYNAMIC_TABLE
‎2013 Dec 27 11:16 AM
assign dyn_line->* to <FS_WA>.
DO 2 TIMES .
LOOP AT it_fieldcat INTO wa_fieldcat.
ASSIGN COMPONENT wa_fieldcat-fieldname OF STRUCTURE <fs_wa> TO <fs_field>.
IF sy-subrc EQ 0.
<fs_field> = wa_fieldcat-fieldname.
ENDIF.
ENDLOOP.
APPEND <fs_wa> TO <fs_table>.
ENDDO.
‎2013 Dec 27 11:09 AM
Hi
<fs>-field1 = 'name'.
<fs>-field2 = 'Age'.
append <fs> to itab.
loops can be used as required.
Warm Regards
Suneesh Thampi
‎2013 Dec 27 11:16 AM
assign dyn_line->* to <FS_WA>.
DO 2 TIMES .
LOOP AT it_fieldcat INTO wa_fieldcat.
ASSIGN COMPONENT wa_fieldcat-fieldname OF STRUCTURE <fs_wa> TO <fs_field>.
IF sy-subrc EQ 0.
<fs_field> = wa_fieldcat-fieldname.
ENDIF.
ENDLOOP.
APPEND <fs_wa> TO <fs_table>.
ENDDO.
‎2013 Dec 27 11:23 AM
Hi nabheet,
you are my hero of 2013!
Thanks and many regards
Mario