04-06-2009 7:14 AM
Dear Friends,
I need a simple logic but I am not getting it how to do.
I am having a Z table with 12 fields like Fld1 Fld2 Fld3 .......Fld12.
I have taken the all fields data into one internal table ( ITAB ).
In my selection screen parameter If I have given 1 then I need to take the Fld1 values from my ITAB for some calculations.
If I taken 3 then 3rd field data....like that.
I am looping the ITAB.
assume like this : if selection screen parameter value is 1.
Loop at Itab.
cal_total = ITAB-field1.
Endloop.
I know we can do it with Case - ENDCASE.
but is there any better way to do this?
Thanks,
Sridhar Reddy.
04-06-2009 7:21 AM
You can do it using Field symbols dynamically...
1: Declare FS of type char
2: gv a generalised name to ur fields like F1,F2,...F12.
3: now Concatenate the Parameter to 'F'... like Concatenate 'F' p_fld into <FS>.
4: Use this FS in ur loop.
I am quite sure u can do generate the details code now....
regards,
ags.
04-06-2009 7:25 AM
Hi,
Try with field symbols concept
In selection screen give the field name, not the column position.
PARAMETERS : p_fieldname(15) TYPE c.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN p_fieldname TO <fs>.
LOOP AT itab.
cal_total = itab-<fs>.
ENDLOOP.
Regards
Bala Krishna
04-06-2009 7:29 AM
Hi:
Do like this
PARAMETERS : p_fname TYPE char15.
data: lv_field type char15
FIELD-SYMBOLS <fs> TYPE ANY.
Concatenate 'FLD' p_fname into lv_field
ASSIGN lv_field TO <fs>.
LOOP AT itab.
cal_total = itab-<fs>.
ENDLOOP.
Regards
Shashi
04-06-2009 7:39 AM
Hi,
Thanks for the reply,
I did the same way but its throuing me the syntax error saying :
cal_total = itab-<FS>.
ITAB does not have the component called <FS>.
Thanks,
Sridhar
04-06-2009 7:45 AM
Hi,
Use ASSIGN statement in LOOP and ENDLOOP.
PARAMETERS : p_field(15) TYPE c.
FIELD-SYMBOLS <fs> TYPE ANY.
LOOP AT itab.
ASSIGN p_field TO <fs>. " use here
cal_total = itab-<fs>.
ENDLOOP.
Try the below code
DATA:
t_likp TYPE TABLE OF likp,
cal_total(20) TYPE c,
name(25).
PARAMETERS : p_field(15) TYPE c.
CONCATENATE 'LIKP-' p_field INTO name.
LOOP AT t_likp INTO likp.
cal_total = name.
ENDLOOP.
Regards
Bala Krishna
Edited by: Bala Krishna on Apr 6, 2009 12:16 PM
Edited by: Bala Krishna on Apr 6, 2009 12:27 PM