09-18-2008 10:41 AM
Hello,
i need a dynamical select on a table... The table is "COSL" and includes following fields:
LST001,LST002,LST003,LST004,LST005,LST006,LST007,LST008,LST009,LST010,LST011,
LST012,LST013,LST014,LST015,LST016
Now i have two input parameters "begin" and "end". The value can be from 001 to 016.
If the user entery for espacialy 4 i only need the value of LST004, but if he enters 3-7 i need the values of LST003,LST004,LST005,LST006,LST007. Is it possible the handle this situation with abap?
Thank you
09-18-2008 10:46 AM
Hi,
You can get the values by using
DO VArying from <field1> to <field2>
Enddo.
This may help.
Regards
Sumit Agarwal
09-18-2008 10:49 AM
09-18-2008 10:51 AM
You could get clever with using a dynamic field list, and RTTS to have a dynamically defined table with the correct number and name of columns. But I'd just select everything, and use the selection provided to drive the logic later in the program.
Why make it complicated? Just ignore the data you don't want.
What are you doing with the data after you've selected it?
09-18-2008 10:53 AM
Yes you should be able to code logic based off the user entry to build a dynamic search string using the following clause on your select statement: WHERE (source_text)
There is F1 on help on that which is useful
Assuming all fields are the same domain you could select into a generic work area containing 16 fields (or more to account for scalability). After your select statement you can use similar logic from the user entry to determine which actual fields were retrieved and how to process them.
Hope this helps for starters
09-18-2008 10:55 AM
Or as Matthew says
Just select all the fields but only process the ones based off the user entry by concatenating LST + number and using a field symbol
09-18-2008 11:03 AM
Hi,
Try like this code.....
if not beginfieldvalue is initial
wa-fieldnum = beginfieldvalue.
append wa to itab.
endif.
if not endfieldvalue is initial and not beginfieldvalue is initial.
lv_difference = endfieldvalue - beginfieldvalue.
loop at lv_difference times.
wa-fieldnum = beginfieldvalue + 1.
append wa to itab.
endloop.
endif.
loop at itab into wa.
case wa-fieldnum.
WHEN : 1.
CONCATENATE 'lst001' lv_selectionfield
INTO lv_selectionfield SEPARATED BY space.
WHEN : 2.
CONCATENATE 'lst002' lv_selectionfield
INTO lv_selectionfield SEPARATED BY space.
WHEN : 3.
CONCATENATE 'lst003' lv_selectionfield
INTO lv_selectionfield SEPARATED BY space.
WHEN : 4.
CONCATENATE 'lst004' lv_selectionfield
INTO lv_selectionfield SEPARATED BY space.
WHEN : 5.
CONCATENATE 'lst005' lv_selectionfield
INTO lv_selectionfield SEPARATED BY space.
endloop.
*select lv_selectionfield from cosl where <condition>*
Hope it will helps
09-18-2008 11:52 AM
Hello,
i think field symblols sounds good. I haven´t done something like that.
Please can you help me:
field-SYMBOLS: .
But this doesn´t work.
09-18-2008 11:55 AM
try
> ASSIGN 'w_cosel-lst001' to <fs> CASTING.
> test = <fs>.
type C is probably not the correct one for <fs> though, better use ANY or one that fits w_cosel-lst001.
09-18-2008 12:17 PM
Hello,
this also doesn´t work.
There is an error that say: w_cosl doesn´t have a component with the name
09-18-2008 12:29 PM
Serves me right for jumping late into ongoing discussions. Can't even try out now since my sandbox here is down.
>ASSIGN ('w_cosel-lst001') to <fs>
might work better. Also look at the ASSIGN COMPONENT ... OF STRUCTURE ... statement, there is very extensive ABAP online help available.
Thomas
09-18-2008 12:44 PM
I could be wrong, but don't the field names have to be in UPPER-CASE?
i.e. ASSIGN ('W_COSEL-LST001') to <fs>
matt
09-18-2008 12:59 PM
Hello, exactly
now it works... than you for your help... i hope the points are ok:
Here is the code if someone is interessted:
data string1(6) type c.
string1 = 'LST001'.
DATA string2 type LSTXX.
field-SYMBOLS:
<fs> TYPE C,
<fa> TYPE LSTXX,
<ft> type cosl.
data test TYPE string.
DATA wa_cosel TYPE cosl .
LOOP at t_cosel into wa_cosel.
ASSIGN string2 to <fa>.
ASSIGN string1 to <fs>.
ASSIGN COMPONENT <fs> of STRUCTURE wa_cosel to <fa>.
09-18-2008 1:23 PM
Just tried (box is back hurray), both variants work. Upper case looks tidier though.
Thomas