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: 

dyanamically add field form an internal table

Former Member
0 Kudos

Hiii

there are data that i am extraction from database from FAGFLEXT tabel more exactly

in that table i have field KSL01, KSL02, KSL03, KSL04, KSL05 .... until 16

on my selection screen i have a parameter P_period

if ever i specify 05 on my selection screen i have to add KSL01 + KSL02 + KSL03+ KSL04 + kSL05

if ever i specify 02 on my selection screen i have to add KSL01 + KSL02

Note that i will have an internal table of fype FAGFLEXT and also i am treating multiple record.

The first thing that i am thinking of i building a routine or macro so as to put

if field P_PERIOD CS 01 then value = KSL01

if field P_PERIOD CS 04 then value = KSL01 + 02 +03 +04

But there will be too much if and this is not performance wise

8 REPLIES 8

former_member156446
Active Contributor
0 Kudos

Hi ....Check this :

PARAMETER: p_path TYPE i.
DATA: count(2) TYPE i, num(2) TYPE c, wa TYPE string.

FIELD-SYMBOLS: <fs> TYPE ANY.

DO p_path TIMES.
  num = count = sy-index.
  CONCATENATE 'wa-ksl' num INTO wa.
  ASSIGN wa TO <fs>.
  count = count + 1.

ENDDO.

<fs> will have the wa of the itab.. and keep things going...

Former Member
0 Kudos

Use : DO - Varying.

Go for the below code.

DATA : KSLXX Like FAGFLEXT-KSL01.

Loop at itab.

DO P_PERIOD TIMES VARYING KSLXX FROM itab-KSL01 NEXT itab-KSL02.

value = value + KSLXX.

ENDDO.

Endloop.

0 Kudos

can you please advise about the declaration KSLXX

0 Kudos

KSLXX is a work area of type KSL01.

Former Member
0 Kudos

Hi,

there are data that i am extraction from database from FAGFLEXT tabel more exactly 

in that table i have field KSL01, KSL02, KSL03, KSL04, KSL05 .... until 16

Just clear me one thing, R these 16 fields are included in the internaln table of type FAGFLEXT or they will be appended to some fixed fields of ur internal table?

Regards,

Anirban

0 Kudos

They will be in the internal table of FAGFLEXT

Former Member
0 Kudos

hi,

can you please check this link

http://www.saptechies.com/how-to-create-a-dynamic-internal-table-or-array/

Thanks and regards

Durga.K

Former Member
0 Kudos

Try the code and let me know wheather it serves ur requirment.

REPORT  zrtts.

PARAMETERS: p_period TYPE i.

DATA: comptab TYPE cl_abap_structdescr=>component_table.
DATA: newstr TYPE REF TO cl_abap_structdescr.
DATA: wa_comp LIKE LINE OF comptab.
DATA: tab_type TYPE REF TO cl_abap_tabledescr.
DATA: itab TYPE REF TO data.
DATA: wa TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.

DATA: ind(2) TYPE n.

ind = 01.
DO p_period TIMES.
  CONCATENATE 'PERIOD' ind INTO wa_comp-name.
  wa_comp-type ?= cl_abap_datadescr=>describe_by_name( 'CHAR10' ).
  APPEND wa_comp TO comptab.
  CLEAR wa_comp.
  ind = ind + 1.
ENDDO.
newstr = cl_abap_structdescr=>create( comptab ).
tab_type = cl_abap_tabledescr=>create( newstr ).


CREATE DATA itab TYPE HANDLE tab_type.

ASSIGN itab->* TO <fs>.

BREAK-POINT.

here <fs> will hold ur required internal table. Needless to say, break-point is only for demo purpose.

Reagrds,

Anirban