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: 

Changing Field name Dynamically

Former Member
0 Kudos

Hi Experts,

I need to change the Internal table field name dynamically.

Lets say the structure looks like the below,

-


NAME | ABSNT01 | ABSNT02 | ABSNT03 | ABSNT04

-


Now, I need to populate this ABSNT* fields based upon some index.

ABSNT+sy-tabix = 'A'

I tried using do varying loop but am not able to acheive the result.

4 REPLIES 4

Former Member

Hi

U need to use the field-symbols:

FIELD-SYMBOLS: <FS> TYPE ANY.
DATA: FIELD_NAME(30) TYPE C.
DATA: V_INDEX(2) TYPE N.

FIELD_NAME = 'ABSNT'.

DO.
  MOVE SY-INDEX TO V_INDEX.
  FIELD_NAME(5) = 'ABSNT'.
  FIELD_NAME+5(2) = V_INDEX.
  ASSIGN COMPONENT FIELD_NAME OF STRUCTURE ITAB TO <FS>.
  IF SY-SUBRC = 0.
    <FS> = ....
  ELSE. 
    EXIT.
  ENDIF.
ENDDO.

mAX

Subhankar
Active Contributor
0 Kudos

Hi ,

You can use the statement assign component . Dynamically it will populate the fields.

awin_prabhu
Active Contributor
0 Kudos

Hi Benu,

See below logic.

DATA:fcat_wa TYPE lvc_s_fcat,

fcat_itab TYPE lvc_t_fcat,

poi_itab TYPE REF TO data,

cha(4) TYPE c.

FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.

DO 5 TIMES.

cha = sy-index.

CONCATENATE 'ABSNT' cha INTO cha.

CONDENSE cha NO-GAPS.

fcat_wa-fieldname = cha.

fcat_wa-datatype = 'STRG'.

APPEND fcat_wa TO fcat_itab.

ENDDO.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = fcat_itab

IMPORTING

ep_table = poi_itab

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

ASSIGN poi_itab->* TO <itab>. " <itab> contains dynamic fields

Might help u.

Thanks,

Edited by: Sap Fan on Oct 27, 2009 4:02 PM

Former Member
0 Kudos

Hi Benu,

You can use Dynamic Internal table. the way to create it is given in the following link:

http://www.saptechies.com/how-to-declare-an-internal-table-dynamically-2/

Regards,

Sana.