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

Internal table dynamic column selection

Former Member
0 Likes
1,288

Consider this example

DATA: BEGIN OF itab OCCURS 0,
  carrid LIKE spfli-carrid,
  connid LIKE spfli-connid,
END OF itab.

FIELD-SYMBOLS: <fs> LIKE LINE OF itab.
               

START-OF-SELECTION.
  SELECT carrid connid
  INTO TABLE itab
  FROM spfli.

END-OF-SELECTION.

  LOOP AT itab ASSIGNING <fs>.
    
    <fs>-

<b>"column name is known at runtime say in a variable"

Any suggestions to retrieve the same.</b>

ENDLOOP.

6 REPLIES 6
Read only

hymavathi_oruganti
Active Contributor
0 Likes
829

hi deepak,

can u be some more clear?

according to ur code,

itab contains two columns u decalred caarid and connid.

so when u say

loop at itab assigning <fs>.

<fs> obviously points to only two columns carrid and connid.

so please explain clearly what u need exactly so that we can help u out

Read only

0 Likes
829

The column to select is in a variable for example

<fs>-column_name

is only known at runtime

column_name can be carrid or connid

Read only

hymavathi_oruganti
Active Contributor
0 Likes
829

then do one thing,

loop at itab intom wa.

field-symbol <fs1> type any.

if <condition>.

assign caarid to <fs1>.

else.

assign carrid to <fs1>.

wa-<fs1> =

endloop.

Message was edited by: Hymavathi Oruganti

Read only

0 Likes
829

that does not work ..tried it

Thanks

Read only

0 Likes
829

HI DEEPAK,

i have tried a small example like ur scnario,

try like this it will surely work.

REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 172.

field-symbols: <fs> type any.

data: check.

types: begin of typ_itab,

a type i,

b type i,

end of typ_itab.

data: itab type table of typ_itab, wa like line of itab.

wa-a = 1.

wa-b = 2.

append wa to itab.

wa-a = 2.

wa-b = 3.

append wa to itab.

loop at itab assigning <fs>.

field-symbols: <fs1> type any.

data: var type i.

if sy-tabix = 1.

assign component 'A' of structure <fs> to <fs1>.

else.

assign component 'B' of structure <fs> to <fs1>.

endif.

write <fs1>.

endloop.

Read only

Former Member
0 Likes
829

Hello Deepak,

you can use the following code,

DATA: BEGIN OF itab OCCURS 0,
      carrid LIKE spfli-carrid,
      connid LIKE spfli-connid,
   END OF itab.


FIELD-SYMBOLS: <fs> LIKE LINE OF itab,
               <fs_fld>.

<b>PARAMETERS: p_fld LIKE dd03l-fieldname</b>.

START-OF-SELECTION.
  SELECT carrid connid  INTO TABLE itab  FROM spfli.

END-OF-SELECTION.

  LOOP AT itab ASSIGNING <fs>.
    ASSIGN COMPONENT p_fld OF STRUCTURE <fs> TO <fs_fld>.
    IF sy-subrc = 0.
      WRITE: <fs_fld>.
    ENDIF.
  ENDLOOP.

hope it help U,

Rgds,

Mohan

@Deepak: Reward points if is helpful.