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

Concept of variable

Former Member
0 Likes
843

Hi,

I have a scenario wherein i ge the table name from a select query in a variable and then i have to do another select query on this new table. But because this table name is stored in variable, i'm not gettign how to do a select query on it.

Regards

Aadil

Thanks for help!!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
810

You can do a dynamic selection .

Check out this link:

http://www.sapfans.com/forums/viewtopic.php?t=74847

Regards

Neha

6 REPLIES 6
Read only

Former Member
0 Likes
810

search using Dynamic Select

Read only

0 Likes
810

Thanks solved the prob...u're right...i just needed to put a bracket in front of the variable name in select query...

Thanks

Read only

Former Member
0 Likes
811

You can do a dynamic selection .

Check out this link:

http://www.sapfans.com/forums/viewtopic.php?t=74847

Regards

Neha

Read only

0 Likes
810

Can i define a data type also like that based on the table name which i just stored in variable...

Regards

Read only

0 Likes
810

Hi

Try this :

1-To assign a variable a type at runtime, use the ABAP statement ASSIGN with the option TYPE. For instance:

DATA: D_TYPE,

D_FIELD(35).

DATA: D_TEST TYPE P.

FIELD-SYMBOLS: <F>.

D_FIELD = 'D_TEST'.

D_TYPE = 'P'.

ASSIGN (D_FIELD) TO <F> TYPE D_TYPE.

Additionally you can use the option DECIMALS of the ASSIGN statement if your type is 'P'. You can even change the type at runtime of previously assigned field symbol like

ASSIGN <F> TO <F> TYPE 'C'.

One more thing for dynamic programing. With the following coding you can access every DDIC table with the key you want:

SELECT SINGLE * FROM (DF_TNAME) INTO S_TMP WHERE (IF_KEY).

2-FIELD-SYMBOLS:

<fieldname> TYPE ANY, "Name of field

<line> TYPE ANY, "Line structure for table

<fieldvalue> TYPE ANY. "Value of field

DATA: l_shorttext LIKE dd03m-ddtext.

DATA: wa_dd03l LIKE dd03l.

SELECT * FROM dd03l INTO wa_dd03l

WHERE tabname = 'ZHR_INTER_PA1_DL'.

  • Assign name of field

ASSIGN COMPONENT 2 OF STRUCTURE wa_dd03l TO <fieldname>.

  • Assign structure for internal table

ASSIGN wa_pa1_delta TO <line>.

  • Assign field value from structure

ASSIGN COMPONENT <fieldname> OF STRUCTURE <line> TO <fieldvalue>.

  • Find DD text for field

SELECT SINGLE ddtext

FROM dd03m

INTO l_shorttext

WHERE tabname = 'ZHR_INTER_PA1_DL' AND

fieldname = <fieldname> AND

ddlanguage = 'EN'.

WRITE: / <fieldname>, l_shorttext, ' : ', <fieldvalue>.

ENDSELECT.

Regards

Neha

Read only

0 Likes
810

Hey Neha,

Thanks alot for help!!! Actually I'm in BI and just playing around with diff concepts of ABAP to make my life easier in BI...

Thanks once again...