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

Dynamically identifying a field

Former Member
0 Likes
536

Hi SAP gurus,

I need to perform a select query on my DB table.

The "where" criteria of this query will access a field of this DB table which is generated dynamically.

The table is not dynamically generated but the field is..

How do I write my query?

Regards,

Gayathri

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
512

hi,

here is a simple program which gets the table field name dynamically...

for spfli table .... table name is fixed here

PARAMETERS:p_input(20) TYPE c,

p_input1(20) TYPE c,

p_input2(20) TYPE c.

FIELD-SYMBOLS <fs> TYPE ANY.

FIELD-SYMBOLS <fs1> TYPE ANY.

FIELD-SYMBOLS <fs2> TYPE ANY.

DATA:BEGIN OF fs_struct,

input(20) TYPE c,

input1(20) TYPE c,

input2(20) TYPE c,

END OF fs_struct.

DATA:t_spfli LIKE TABLE OF spfli WITH HEADER LINE.

fs_struct-input = p_input.

fs_struct-input1 = p_input1.

fs_struct-input2 = p_input2.

SELECT (fs_struct)

INTO CORRESPONDING FIELDS OF

table t_spfli FROM spfli.

write:/ p_input,p_input1,p_input2.

LOOP AT t_spfli.

ASSIGN COMPONENT p_input OF STRUCTURE t_spfli TO <fs>.

ASSIGN COMPONENT p_input1 OF STRUCTURE t_spfli TO <fs1>.

ASSIGN COMPONENT p_input2 OF STRUCTURE t_spfli TO <fs2>.

IF <fs> IS ASSIGNED OR <fs1> IS ASSIGNED OR <fs2> IS ASSIGNED.

WRITE: / <fs>,24 <fs1>, 45 <fs2>.

ENDIF.

ENDLOOP.

Regards,

priya

Edited by: Banupriya R on Apr 16, 2008 8:02 AM

4 REPLIES 4
Read only

Former Member
0 Likes
512

Hi,

The solution to your problem is that you will have to work with FIELD-SYMBOLS

Regards

Read only

Former Member
0 Likes
512

hi

can u plz provide the code that at which point the dynamic field is geting generated

Read only

Former Member
0 Likes
513

hi,

here is a simple program which gets the table field name dynamically...

for spfli table .... table name is fixed here

PARAMETERS:p_input(20) TYPE c,

p_input1(20) TYPE c,

p_input2(20) TYPE c.

FIELD-SYMBOLS <fs> TYPE ANY.

FIELD-SYMBOLS <fs1> TYPE ANY.

FIELD-SYMBOLS <fs2> TYPE ANY.

DATA:BEGIN OF fs_struct,

input(20) TYPE c,

input1(20) TYPE c,

input2(20) TYPE c,

END OF fs_struct.

DATA:t_spfli LIKE TABLE OF spfli WITH HEADER LINE.

fs_struct-input = p_input.

fs_struct-input1 = p_input1.

fs_struct-input2 = p_input2.

SELECT (fs_struct)

INTO CORRESPONDING FIELDS OF

table t_spfli FROM spfli.

write:/ p_input,p_input1,p_input2.

LOOP AT t_spfli.

ASSIGN COMPONENT p_input OF STRUCTURE t_spfli TO <fs>.

ASSIGN COMPONENT p_input1 OF STRUCTURE t_spfli TO <fs1>.

ASSIGN COMPONENT p_input2 OF STRUCTURE t_spfli TO <fs2>.

IF <fs> IS ASSIGNED OR <fs1> IS ASSIGNED OR <fs2> IS ASSIGNED.

WRITE: / <fs>,24 <fs1>, 45 <fs2>.

ENDIF.

ENDLOOP.

Regards,

priya

Edited by: Banupriya R on Apr 16, 2008 8:02 AM

Read only

GayathriRR
Product and Topic Expert
Product and Topic Expert
0 Likes
512

Hi Banupriya,

Thanks..it was useful.

Regards,

Gayathri