2011 Aug 08 6:32 PM
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!
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
2011 Aug 08 6:58 PM
Why bother? Select them all and use only the ones you need in your calculation.
Rob
2011 Aug 08 7:17 PM
ok...but how would i know which field to take for calculation if for example my period is from 2 to 12...
2011 Aug 08 7:20 PM
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
2011 Aug 08 7:25 PM
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?
2011 Aug 08 7:29 PM
You can use:
DO...VARYINGIt's documented.
Be careful though. Fiscal periods do not necessarily correspond to month numbers. I.E. MONAT = 1 is not necessarily January.
Rob
2011 Aug 08 8:34 PM
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
2011 Aug 09 2:20 PM
Hi Rob, i have never used DO VARYING can you please help me with the code?
Thank you!
2011 Aug 09 2:35 PM
Please check the help files first and then if you still have a problem, get back to the forum.
Rob
2011 Aug 09 4:03 PM
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
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |