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

Write values to generated internal table

Former Member
0 Likes
638

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




1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
607

 

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.

3 REPLIES 3
Read only

Former Member
0 Likes
607

Hi

<fs>-field1 = 'name'.

<fs>-field2 = 'Age'.

append <fs> to itab.

loops can be used as required.

Warm Regards

Suneesh Thampi

Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
608

 

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.

Read only

0 Likes
607

Hi nabheet,

you are my hero of 2013!

Thanks and many regards

Mario