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: 

how can i assign value to the certain field in dynmic table ?

Former Member
0 Kudos

i have created a dynmic table .now i want to assign value to the certain field,how can i do that?

for eg,

<dyn_table> contains fields of name age ,now i want assign 'jack' to this internal talbe's field name ,

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

See the Following code.

data: dy_table type ref to data,
       dy_line  type ref to data,
       xfc type lvc_s_fcat,
       ifc type lvc_t_fcat.

data :  <dyn_wa> type any .
 xfc-fieldname = 'LIFNR'.
    xfc-datatype = 'C'.
    xfc-intlen = 18.
    xfc-seltext = 'Vendor'.
    xfc-outputlen = 10.
    xfc-fix_column = 'X'.
    append xfc to ifc.

 call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = ifc
    importing
      ep_table        = dy_table.
  assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

  assign component 'LIFNR' of structure <dyn_wa> to <fs>.
      <fs> = '30000'.

  append <dyn_wa> to <dyn_table>.
    clear <dyn_wa>.

Regards,

Morris Bond.

Reward Points if Helpful.

6 REPLIES 6

Former Member
0 Kudos

Hi,

You must use a field symbol.

If your table is dynamic :

FIELD-SYMBOLS: <itab> TYPE ANY TABLE.

Best regards

JozsefSzikszai
Active Contributor
0 Kudos

hi,

this is the way to do:

FIELD-SYMBOLS : <field> TYPE ANY.

LOOP AT <dyn_table> INTO <dyn_line>.

ASSIGN COMPONENT 'AGE' OF STRUCTURE <dyn_line> TO <field>.

<field> = 'jack'.

MODIFY <dyn_table> FROM <dyn_line>.

ENDLOOP.

Pls. note that you'll need a dynamic line as well (<dyn_line>) to the dynamic internal table.

hope this helps

ec

Former Member
0 Kudos

Hi

See the Following code.

data: dy_table type ref to data,
       dy_line  type ref to data,
       xfc type lvc_s_fcat,
       ifc type lvc_t_fcat.

data :  <dyn_wa> type any .
 xfc-fieldname = 'LIFNR'.
    xfc-datatype = 'C'.
    xfc-intlen = 18.
    xfc-seltext = 'Vendor'.
    xfc-outputlen = 10.
    xfc-fix_column = 'X'.
    append xfc to ifc.

 call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = ifc
    importing
      ep_table        = dy_table.
  assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

  assign component 'LIFNR' of structure <dyn_wa> to <fs>.
      <fs> = '30000'.

  append <dyn_wa> to <dyn_table>.
    clear <dyn_wa>.

Regards,

Morris Bond.

Reward Points if Helpful.

0 Kudos

thanks a lot.

matt
Active Contributor
0 Kudos
DATA: lp_data TYPE REF TO DATA.

FIELD-SYMBOLS: <wa> TYPE ANY,
             <nm> TYPE ANY. " Better to give it the real type

CREATE DATA lp_data LIKE LINE OF <dyn_table>.
ASSIGN lp_data->* TO <wa>.

ASSIGN COMPONENT 'NAME' OF STRUCTURE <wa> TO <nm>.
<nm> = 'Jack'.

INSERT <nm> INTO TABLE <dyn_table>.

matt

Former Member
0 Kudos

Hi,

try this:

FIELD-SYMBOLS: <GT_ITAB> TYPE TABLE,

<GS_ITAB>,

<FS>, <FS1>.

*

DATA: GT_DATA TYPE REF TO DATA.

DATA: GS_DATA TYPE REF TO DATA.

*

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

*

START-OF-SELECTION.

*

CREATE DATA GT_DATA TYPE TABLE OF PA0002.

ASSIGN GT_DATA->* TO <GT_ITAB>.

*

CREATE DATA GS_DATA LIKE LINE OF <GT_ITAB>.

ASSIGN GS_DATA->* TO <GS_ITAB>.

*

ASSIGN COMPONENT 'NACHN' OF STRUCTURE <GS_ITAB> TO <FS>.

<FS> = 'Smith'.

ASSIGN COMPONENT 'VORNA' OF STRUCTURE <GS_ITAB> TO <FS>.

<FS> = 'Paul'.

APPEND <GS_ITAB> TO <GT_ITAB>.

*

ASSIGN COMPONENT 'NACHN' OF STRUCTURE <GS_ITAB> TO <FS>.

<FS> = 'Jones'.

ASSIGN COMPONENT 'VORNA' OF STRUCTURE <GS_ITAB> TO <FS>.

<FS> = 'Martin'.

APPEND <GS_ITAB> TO <GT_ITAB>.

*

LOOP AT <GT_ITAB> INTO <GS_ITAB>.

ASSIGN COMPONENT 'NACHN' OF STRUCTURE <GS_ITAB> TO <FS>.

ASSIGN COMPONENT 'VORNA' OF STRUCTURE <GS_ITAB> TO <FS1>.

WRITE: / <FS>, <FS1>.

ENDLOOP.

Regards, Dieter