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

Field name while fetching its content from db table dynamically.

Former Member
0 Likes
777

Hi Experts,

I am new to ABAP and I have a situation as follows.

I have a table say ztable where there are seven fields monday,tuesday,wednesday,thursday,friday and saturday.

Depending on the current calender day i have to fetch the content.

Suppose for monday, i have to fetch ztable-monday.

Is there any other way other than using if statements 7 times ? Like i wanna capture the day and substitute it in the place of z_table-"day".

Please help.

Thanks,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
741

Hi,

In the below code you can pass any field of the table in W_FIELD.... It will fetch the particular field from the table....

w_block should be of same data element of your field in W_FIELD

PARAMETER : w_field TYPE NAME_FELD.

DATA w_block(1) TYPE c.

Select single (w_field) FROM RSEG INTO w_block
  WHERE belnr EQ '5105701294'.

  IF sy-subrc EQ 0.

    WRITE / w_block.

  ENDIF.

Thanks and regards,

Senthil Kumar Anantham.

Edited by: Senthil Kumar on Jul 2, 2010 5:37 PM

Hi Experts,

I am new to ABAP and I have a situation as follows.

I have a table say ztable where there are seven fields monday,tuesday,wednesday,thursday,friday and saturday.

Depending on the current calender day i have to fetch the content.

Suppose for monday, i have to fetch ztable-monday.

Is there any other way other than using if statements 7 times ? Like i wanna capture the day and substitute it in the place of z_table-"day".

Please help.

Thanks,

5 REPLIES 5
Read only

Former Member
0 Likes
741

Hey ,

yes there is.

You can write a Dynamic select query and it will solve your problem.

Search on SDN for 'Dynamic Select query'.

Hope this is helpful.

Regards,

Uma Dave

Read only

Former Member
0 Likes
742

Hi,

In the below code you can pass any field of the table in W_FIELD.... It will fetch the particular field from the table....

w_block should be of same data element of your field in W_FIELD

PARAMETER : w_field TYPE NAME_FELD.

DATA w_block(1) TYPE c.

Select single (w_field) FROM RSEG INTO w_block
  WHERE belnr EQ '5105701294'.

  IF sy-subrc EQ 0.

    WRITE / w_block.

  ENDIF.

Thanks and regards,

Senthil Kumar Anantham.

Edited by: Senthil Kumar on Jul 2, 2010 5:37 PM

Read only

Former Member
0 Likes
741

There is a solution with FIELD-SYMBOLS:


 FIELD-SYMBOLS <FS>.
  DATA: WWFIELDN(100).
  DATA: wwday(20).

  wwday = 'monday'.

  CONCATENATE 'z_table-'  wwday INTO WWFIELDN.
  ASSIGN (WWFIELDN) TO <FS>.


  MOVE 100 TO <FS>.

There is another solution using DO ... VARYING.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
741

Why not create seven select options and execute a single query ?

Is this what you want ?

data:r1 type range of z-monday.

data:r2 type range of z-tuesday.

data:r3 type range of z-wednesday.

data:r4 type range of z-thursday.

data:r5 type range of z-friday.

data:r6 type range of z-saturday.

data:r7 type range of z-sunday.

Populate the required ranges as required depending on your current calenadar day and leave others blank.

then select * from ztable where

monday in r1 and

tuesday in r2 and

wednesday in r3 and

thursday in r4 and

friday in r5 and

saturday in r6 and

friday in r7.

Read only

Former Member
0 Likes
741

Thanks one and all.