2014 Jan 31 12:33 PM
Dear All,
Below is my requirement and I need ur advice on this,
Selection Screen :
Fiscal year :
Period (Select Option)
Table name : ABC
| SALE_01 | SALE_02 | .......to | SALE_12 | COST_01 | COST_02 | ......to | COST_12 | Department | XYZ |
|---|---|---|---|---|---|---|---|---|---|
If the Period is 01.01.2014 TO 31.03.2014 then I should collect SUM of SALE_01 to SALE_03 fields AND COST_01 to COST_03 with Department , XYZ
If the Period is 01.04.2014 TO 31.12.2014 then I should collect SUM of SALE_04 to SALE_12 fields AND COST_04 to COST_12 with Department , XYZ columns;
table could be either standard table or Internal table...
How can I achieve this with less effort..
Thank you all in advance...
2014 Jan 31 12:48 PM
for thats u have write code with few logic,
U can select dynamic fields and than u have to check with selection screen and populate table
Code Reference :
TYPES : BEGIN OF y_fieldname ,
fieldname(10) TYPE c ,
END OF y_fieldname .
data t_fieldname TYPE STANDARD TABLE OF y_fieldname .
DO p_monat TIMES.
clear w_count .
MOVE sy-index TO w_count
IF sy-index LE c_9.
CONCATENATE c_hsl
c_0
w_count
INTO e_fieldname-fieldname.
APPEND e_fieldname TO t_fieldname.
ELSE.
CONCATENATE c_hsl
w_count
INTO e_fieldname-fieldname.
APPEND e_fieldname TO t_fieldname.
ENDIF.
ENDDO.
SELECT (t_fieldname)
FROM glt0
INTO TABLE t_glto_with_saknr
FOR ALL ENTRIES IN t_bukrs
WHERE rldnr EQ c_00
AND rrcty EQ c_0
AND rvers EQ c_001
AND bukrs EQ t_bukrs-bukrs
AND ryear EQ p_gjahr
AND racct IN r_saknr.
Else select all fields and than populate as per selection screen.
For reference u can check below link also.
http://www.saptechnical.com/Tutorials/ABAP/DynamicSelect/Code.htm
http://www.erpgreat.com/abap/how-can-we-give-dynamic-table-name-in-select-statement.htm
Thanks
Tarak
2014 Jan 31 12:48 PM
for thats u have write code with few logic,
U can select dynamic fields and than u have to check with selection screen and populate table
Code Reference :
TYPES : BEGIN OF y_fieldname ,
fieldname(10) TYPE c ,
END OF y_fieldname .
data t_fieldname TYPE STANDARD TABLE OF y_fieldname .
DO p_monat TIMES.
clear w_count .
MOVE sy-index TO w_count
IF sy-index LE c_9.
CONCATENATE c_hsl
c_0
w_count
INTO e_fieldname-fieldname.
APPEND e_fieldname TO t_fieldname.
ELSE.
CONCATENATE c_hsl
w_count
INTO e_fieldname-fieldname.
APPEND e_fieldname TO t_fieldname.
ENDIF.
ENDDO.
SELECT (t_fieldname)
FROM glt0
INTO TABLE t_glto_with_saknr
FOR ALL ENTRIES IN t_bukrs
WHERE rldnr EQ c_00
AND rrcty EQ c_0
AND rvers EQ c_001
AND bukrs EQ t_bukrs-bukrs
AND ryear EQ p_gjahr
AND racct IN r_saknr.
Else select all fields and than populate as per selection screen.
For reference u can check below link also.
http://www.saptechnical.com/Tutorials/ABAP/DynamicSelect/Code.htm
http://www.erpgreat.com/abap/how-can-we-give-dynamic-table-name-in-select-statement.htm
Thanks
Tarak
2014 Jan 31 1:22 PM
field symbols ,
if you know you have fixed no of fields in your table .
say 12 for sale and 12 for cost.
its totally 24.
than create a field symbol of that work area type . say <fs_wa>. and a field symbol for field say <fs_field> keep it type any.
then you have to get the range , say you want sale from 3rd(say lv_a) month through 12(say lv_b) month then .
lv_start = lv_a.
do (lv_b minus lv_a ) times
assign componet lv_start of <fs_wa> to <fs_field>.
lv_start = +1.
lv_sum = lv_sum + <fs_field>.
enddo.
for multiple rows do this in a loop.
1 to 12 is for sale is straight
but 13 to 24 is for cost ( you have to use a mod or somthing to callculate )
if you are calculating for cost
then if you are doing it of 4 to 8 on cost .
then its actually 12+4 to 12+8.