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

Can Data Declaration be dynamic?

Former Member
0 Likes
1,152

Halo ,

I am trying to build dynamic select clause for a report . I pass all the select options from the report to Class.

In class I have an attribute my_ranges (type table of ref to data).

In the method build_dynamic_clause I write


data: l_range_1 type ref to data,
         l_range_2 type ref to data,
        like that til l_range_10.

*now i read table my_ranges with index addition to this individual variables*
read table my_ranges assigning l_range_1 index 1
like that till 10th index.

*Now I use this individual range variables in select like*
select * from (l_table_name) where field1 in l_range->*
and field2 in l_range_2->* 

Like that

.

The problem is I dont know how many select options is passed from the report . Currently the report is handling only up to 10 select options . I want to make that dynamic by declaring variables (l_range_1 to l_range_n ).

Depending on the my_ranges number of entries ,EACH variables should be declared dynamically and then we can use it in dynamic select .

Is that possible?

Regards

Kallu

8 REPLIES 8
Read only

huseyindereli
Active Contributor
0 Likes
1,049

Hi ,

Check this blog.

Read only

0 Likes
1,049

Actually [this blog|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/15837] [original link is broken] [original link is broken]; (also by Horst Keller) might be more appropriate.

Cheers

Graham Robbo

Read only

MarcinPciak
Active Contributor
0 Likes
1,049

As you pass your ranges in table like parameter, I think you don't need any dynamic ranges defined inside the class. Simply loop at your ranges and build [dynamic where condition|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_DYNAMIC.htm] by concatenating each line. Then pass it to your select clause.

Regards

Marcin

Read only

0 Likes
1,049

Halo Marcin,

Thanks for the reply . But its not that easy.

There are 400 to 500 select options in the report . I dont want to declare this many select option ranges inside the class.

Moreover I am reusing the attributes to build the selection clause.

Is there any way to declare this local variables inside the class method dynamcially( l_range_1 to l_range_n ).

Regards

Kallu

Read only

0 Likes
1,049

Hi,

You can check my reply here for creating ranges dynamically inside the program

You say that the number of ranges in the parameter is not predictable, but the fields in the select query are fixed right.

In the select query create a where clause with all fields have a range parameter. Fill the range table when an entry comes in parameter.

Ex:


select * from abc where f1 in r1 "<--if r1 is required then populate it, else leave it blank
                                 and f2 in r2 "<--if r2 is required then populate it, else leave it blank

Still I am bit confused with your question

Kesav

Read only

0 Likes
1,049

Halo Keshav,

I dont want to declare ranges attributes(400-500) inside the class because there are so many of them which are passed to the class from the report . ie y I build up the my_ranges type ref to table of data inside the class for each select options in the report.

In a way my reqment is similar with the Indrajit in link that you gave me

The code snippet provided by you will cause the field symbol <fs> changed in each loop pass and point to a different range

The reason I need separate range names (or pointers l_range_1 to l_range_n) is because I will use the same to populate 'where' clause of a select statement that gets executed after

the loop is over. So when the select statement gets executed, all the ranges should exist in class and be declared, else dynamic select clause will be syntactically incorrect

I guess dynamic declaration of variables is not possible in ABAP

Regards

Kallu

Edited by: KALLU MANACAUD on Nov 28, 2011 9:57 AM

Moderator message : Code tags removed

Edited by: Vinod Kumar on Nov 28, 2011 4:14 PM

Read only

0 Likes
1,049

This message was moderated.

Read only

0 Likes
1,049

halo rshankar,

the answer is no where related to the question that i asked.

Takeing your own data declaration.


DATA: prog TYPE string,
mess TYPE string,
sid TYPE string. 

suppose i have an itab which contains this variable names ('prog',sid','mess').

I shud be able to do something like

loop at itab into wa.

data:(the value inside wa = >prog) type string.

endloop.

Regards

Kallu

Edited by: KALLU MANACAUD on Dec 2, 2011 9:43 AM