cancel
Showing results for 
Search instead for 
Did you mean: 

Generate table field names dinamically

Former Member
0 Kudos

Hello everybody:

I need to get some data from KNC1 table based on a range of fields. Let's say I need the period from 4 to 6 so I need to get these fields:

UM04S

UM04H

UM04U

UM05S

UM05H

UM05U

UM06S

UM06H

UM06U

That is, is there a way for me to loop through the table and dinamically select the fields I'd like to pick, something like concatenating 'UM' + fieldNo + '2' ??

Thanks!

Alejandro

Accepted Solutions (1)

Accepted Solutions (1)

andreas_mann3
Active Contributor
0 Kudos

Hi,

use :

select-options : s_buper for bkpf-buper.
...
  ADD IRVKZ-UM04S THEN IRVKZ-UM04HS UNTIL IRVKZ-UM16S 
  GIVING total  <b>ACCORDING TO s_buper</b>.
...

Andreas

Former Member
0 Kudos

Hello Andreas, could you please elaborate the use for select-options please?

Thanks!

alejandro

Former Member
0 Kudos

Hi Alejandro,

You can try this one..

DATA: BEGIN OF TEXT,
W1(2) VALUE '04',
W2(2) VALUE '05',
W3(2) VALUE '06',
END OF TEXT.

DATA: BEGIN OF TEXT1,
n1(2) VALUE 'S',
n2(2) VALUE 'H',
n3(2) VALUE 'U',
END OF TEXT1.

data : str1 type string , str2 type string.

DO 3 TIMES VARYING str1 FROM text-w1 NEXT text-w2.
 DO 3 TIMES VARYING str2 FROM text1-n1 NEXT text1-n2.
  concatente 'UM' str1 str2 into cond.
  concatenate '<FIELDNAME> EQ ' cond into cond seperated by space.

select * from <table> into table itab where (cond).
 ENDDO.
ENDDO.

regards

satesh

Answers (5)

Answers (5)

ferry_lianto
Active Contributor
0 Kudos

Hi Alejandro,

Please try this FM <b>DB_GET_TABLE_FIELDS</b>.

Hope this will help.

Regards,

Ferry Lianto

Former Member
0 Kudos

hi Alejandro,

you can use select with a dynamic condtion like this..

data : cond(50).

data : fieldno(2) type c value '04'

concatente 'UM' fieldno '2' into cond

concatenate '<FIELDNAME> EQ ' cond into cond seperated by space.

select * from <table> into table itab where (cond).

regards

satesh

vinod_gunaware2
Active Contributor
0 Kudos

For dynamic table name....

REPORT demo_select_dynamic_database .

DATA wa TYPE scarr.

DATA name(10) TYPE c VALUE 'SCARR'.

SELECT *

INTO wa

FROM (name) CLIENT SPECIFIED

WHERE mandt = '000'.

WRITE: / wa-carrid, wa-carrname.

ENDSELECT.

*-----

For dynamic field list

REPORT demo_select_dynamic_columns .

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

line = ' CITYFROM CITYTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

WRITE: / wa-cityfrom, wa-cityto.

ENDLOOP.

ENDIF.

regard

vinod

FredericGirod
Active Contributor
0 Kudos

Hi Alejandro,

you have two ways :

1.

data : w_field(50)
field-symbols : <field> type any.

move UM04S to w_field.
assign (w_field) to <field>.

2.

while .. varying .. from .. next.

(better one)

If you want the complete help, press F1 on the command while or do.

Rgd

Frédéric

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

Check this FM : ISB_TABLE_READ_FIELDS

Laxman