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

Dynamic select with select-opitons

Former Member
0 Likes
1,126

Hi all,

i have a selction screen with a Select-options : S_monat for bkpf-monat.

Depending on what the user has entered in that selection i need to select the field WOG001 to WOG016 from table COSP.

for example if user has entered Period '01' to Period '12' , then i should do SELECT ( WOG001 to WOG012) from COSP. How to program that dynamic select fields??

Cann anyone help???

Thanks!

9 REPLIES 9
Read only

Former Member
0 Likes
1,038

Why bother? Select them all and use only the ones you need in your calculation.

Rob

Read only

Former Member
0 Likes
1,038

ok...but how would i know which field to take for calculation if for example my period is from 2 to 12...

Read only

0 Likes
1,038

If you don't know which fields to use in the calculation, then how would you know which fields to retrieve if you tried the original SELECT?

Rob

Read only

Former Member
0 Likes
1,038

i know which field i will use if my select option goes from 1 to 12 then i would choose WOG001 to WOG012 but how do i define that range?

Read only

0 Likes
1,038

You can use:

DO...VARYING

It's documented.

Be careful though. Fiscal periods do not necessarily correspond to month numbers. I.E. MONAT = 1 is not necessarily January.

Rob

Read only

Former Member
0 Likes
1,038

I hope this will solve your porblem.

{

SELECt-OPTIONS: monat for bkpf-monat OBLIGATORY.

DATA: BEGIN OF ITAB,

WTG001 TYPE COSP-WTG001,

WTG002 TYPE COSP-WTG002,

WTG003 TYPE COSP-WTG003,

END OF ITAB.

BREAK-POINT.

LOOP AT monat.

if monat-LOW = '01' AND MONAT-HIGH IS INITIAL.

select SINGLE WTG001 FROM cosp INTO CORRESPONDING FIELDS OF ITAB where kstar = '0007110102' and vrgng eq 'COIN' AND BEKNZ = 'H'.

elseif monat-LOW = '01' AND MONAT-HIGH eq '01'.

select SINGLE WTG001 FROM cosp INTO CORRESPONDING FIELDS OF ITAB where kstar = '0007110102' and vrgng eq 'COIN' AND BEKNZ = 'H'.

ELSEIF MONAT-HIGH = '02'.

select SINGLE WTG001 WTG002 INTO CORRESPONDING FIELDS OF ITAB FROM cosp where kstar = '0007110102' and vrgng eq 'COIN' AND BEKNZ = 'H'.

ELSEIF MONAT-HIGH = '03'.

select SINGLE WTG001 WTG002 WTG003 INTO CORRESPONDING FIELDS OF ITAB FROM cosp where kstar = '0007110102' and vrgng eq 'COIN' AND BEKNZ = 'H'.

ENDIF.

ENDLOOP.}

Edited by: ZAHID HAMEED on Aug 9, 2011 12:35 AM

Edited by: ZAHID HAMEED on Aug 9, 2011 12:38 AM

Read only

0 Likes
1,038

Hi Rob, i have never used DO VARYING can you please help me with the code?

Thank you!

Read only

0 Likes
1,038

Please check the help files first and then if you still have a problem, get back to the forum.

Rob

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,038

Hi,

You can check Rob's suggestion first.

Also check the ADD...UNTIL...THEN statement. Select all the fields from the COSP table

Then based on the Input ( MONAT ) ..concatenate 'WOG' and create the fields to be considered.

Check this statement


  add lwa_all_cost-wkg012 then  lwa_all_cost-wkg013 until lwa_all_cost-wkg016 to gwa_final_costs-prd_12_cost.

In your case (lwa_all_cost-field) will be dynamic.

Please check it. I think it will work out.

Kesav