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: 

how to select table fields dynamically?

Former Member
0 Kudos

Hi,

In a table i have 16 fields like a1,a2,----a16, based on user entry on selection screen, i hvae to fetch field.

Ex. If user enters 2 on selection screen i have to fetch 2nd field of the table,if it is 5 i have to fetch 5th field etc.

Is there any solution to get fields without using case and endcase.

Thnak u.

4 REPLIES 4

Former Member
0 Kudos

Hi,

You can use case or if statements..

Thanks

Shyja

naimesh_patel
Active Contributor
0 Kudos

Try like this:



DATA: L_FLD(30).

CONCATENATE 'FIELD_' P_NO INTO L_FIELD. " < FIELD_5

SELECT (L_FLD)
INTO L_VALUE
FROM ZTAB
WHERE COND = CONDITION.

Regards,

Naimesh Patel

kesavadas_thekkillath
Active Contributor
0 Kudos

if it is select options in your selection screen...just use "IN" in your query....

if u r entries r of parameters type.

declare it as select-options in this way

selection-options:<entry> for <reference-field> no-extension no intervals.

reward if usefull.

Former Member
0 Kudos

Hi,

Try like this:

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.

Regards,

Bhaskar