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

Dynamic Internal table values read and assign it back

Former Member
0 Likes
568

Hi All,

I want to get the internal table field name dynamically and fetch its value and do some calculation and asign the new value to the same field name.

CONCATENATE '<WA_PIPE>-ZW' v_index INTO v_fld.

CONDENSE v_fld NO-GAPS.

FIELD-SYMBOLS <fs> TYPE ANY.

ASSIGN (v_fld) TO <fs>.

v_fld1 = <fs> * <wa_pipe>-zrate.

Now i've the internal table field name as <WA_PIPE>-ZW1 in v_fld and v_fld1 is having the value of the same field.

How to assign it to the internal table field.

Thanks.

Ashok

Hi All,

I want to get the internal table field name dynamically and fetch its value and do some calculation and asign the new value to the same field name.

CONCATENATE '<WA_PIPE>-ZW' v_index INTO v_fld.

CONDENSE v_fld NO-GAPS.

FIELD-SYMBOLS <fs> TYPE ANY.

ASSIGN (v_fld) TO <fs>.

v_fld1 = <fs> * <wa_pipe>-zrate.

Now i've the internal table field name as <WA_PIPE>-ZW1 in v_fld and v_fld1 is having the value of the same field.

How to assign it to the internal table field.

Thanks.

Ashok

4 REPLIES 4
Read only

JozsefSzikszai
Active Contributor
0 Likes
538

hi Ashok,

you have to use the ASSIGN COMPONENT field OF STRUCTURE wa TO <fs> statement!

hope this helps

ec

Read only

0 Likes
538

Hi,

I've these fields and values .

Field name Field contents

v_fld <WA_PIPE>-ZW1

v_fld1 32000

How to assign <wa_pipe>-zw1 value as 32000.

Thanks,

Ashok...

Read only

Madhurivs23
Participant
0 Likes
538

&----


*& Report YY_TEST1

*&

&----


*&

*&

&----


REPORT YY_TEST1.

type-pools: slis.

field-symbols: <dyn_table> type standard table,

<dyn_wa>.

data: it_alvfc type slis_t_fieldcat_alv,

wa_alvfc type slis_fieldcat_alv,

it_fldcat type lvc_t_fcat,

wa_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text-001.

parameters: p_flds(5) type c.

selection-screen end of block b1.

start-of-selection.

*build the dynamic internal table

perform build_dyn_itab.

*write 5 records to the alv grid

do 5 times.

perform build_report.

enddo.

*call the alv grid.

perform call_alv.

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

*Build_dyn_itab

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

form build_dyn_itab.

*Create the dynamic internal table

data: new_table type ref to data,

new_line type ref to data.

*Create fields .

do p_flds times.

clear wa_fldcat.

wa_fldcat-fieldname = sy-index.

wa_fldcat-datatype = 'CHAR'.

wa_fldcat-intlen = 5.

append wa_fldcat to it_fldcat .

enddo.

*Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fldcat

importing

ep_table = new_table.

assign new_table->* to <dyn_table>.

*Create dynamic work area and assign to FS

create data new_line like line of <dyn_table>.

assign new_line->* to <dyn_wa>.

endform.

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

*Form build_report

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

form build_report.

*Fill some values into the dynamic internal table

data: fieldname(20) type c.

data: fieldvalue(5) type c.

data: index(3) type c.

field-symbols: <fs1>.

do p_flds times.

index = sy-index.

*Set up fieldvalue

concatenate 'FLD' index into

fieldvalue.

condense fieldvalue no-gaps.

assign component index of structure <dyn_wa> to <fs1>.

<fs1> = fieldvalue.

enddo.

*Append to the dynamic internal table

append <dyn_wa> to <dyn_table>.

endform.

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

*CALL_ALV

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

form call_alv.

*Build FC for ALV

loop at it_fldcat into wa_fldcat.

wa_alvfc-fieldname = wa_fldcat-fieldname.

wa_alvfc-seltext_s = sy-tabix.

wa_alvfc-outputlen = wa_fldcat-intlen.

append wa_alvfc to it_alvfc.

endloop.

*Call ABAP List Viewer (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = it_alvfc

tables

t_outtab = <dyn_table>.

endform.

Read only

uwe_schieferstein
Active Contributor
0 Likes
538

Hello Ashok

Below is a sample coding which shows how to work with dynamic itabs and field symbols:



LOOP AT <lt_itab>  ASSIGNING <ls_record>.
  CONCATENATE '<WA_PIPE>-ZW' v_index INTO v_fld.
  CONDENSE v_fld NO-GAPS.

  ASSIGN COMPONENT v_fld      OF STRUCTURE <ls_record> to <ld_fld>.
  ASSIGN COMPONENT 'ZRATE' OF STRUCTURE <ls_record> to <ld_zrate>.

  <ld_fld> = <ld_fld> * <ld_zrate>.
  " NOTE: Since we are working with field symbols there is no need to make
  "            a modify of the itab since it is immediately updated
ENDLOOP.

Regards

Uwe