Application Development 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: 

Dynamic select

Former Member
0 Kudos

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

13 REPLIES 13

Former Member
0 Kudos

Hi,

You can get the values by using

DO VArying from <field1> to <field2>

Enddo.

This may help.

Regards

Sumit Agarwal

Former Member
0 Kudos

Hi,

check this link...

[;

matt
Active Contributor
0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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.

0 Kudos

Hello,

this also doesn´t work.

There is an error that say: w_cosl doesn´t have a component with the name

0 Kudos

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

matt
Active Contributor
0 Kudos

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

0 Kudos

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>.

0 Kudos

Just tried (box is back hurray), both variants work. Upper case looks tidier though.

Thomas