‎2009 May 13 7:55 PM
Dear all,
i have a internal table which i fill with data from the table MVER (total consupmtion for a material).
I have a query which a parameter for the month. Now i want if i enter a 03 for the parameter that i
get the sum for the first 3 month.
Can everybody say me the right code for this.
I can do it intricately with "case" but i want to do it in a nicer way.
Thanks for every help.
‎2009 May 13 8:08 PM
Hi
U can use the field-symbols:
PARAMETERS: P_MONTH(2) TYPE N.
TABLES MVER.
DATA: T_MVER TYPE TABLE OF MVER.
DATA: FIELDNAME(30) TYPE C.
DATA: TOT TYPE MVER-GSV01.
DATA: COUNT(2) TYPE N.
FIELD-SYMBOLS: <FS_GSV> TYPE ANY.
LOOP AT T_MVER INTO MVER.
DO P_MONTH TIMES.
FIELDNAME = 'GSV&'.
MOVE SY-INDEX TO COUNT.
REPLACE '&' WITH COUNT INTO FIELDNAME.
ASSIGN COMPONENT FIELDNAME OF STRUCTURE MVER TO <FS_GSV>.
TOT = TOT + <FS_GSV>.
ENDDO.
ENDLOOP.Max
‎2009 May 13 8:07 PM
Try this way
v_month = " is the parameter value
data : v_no(2) type c.
loop at i_mver.
v_no = 1.
do.
unpack v_no into v_no. " This will add 0 before v_no
concatenate 'I_MVER-GSV' v_no into v_field.
condense v_field no-gaps,
write ( v_field ) to v_val.
v_total = v_total + v_val.
if v_month = v_no.
move i_mver-matnr to i_output-matnr.
move v_total to i_output-total.
append i_output.
clear : i_output, v_total, v_no.
exit.
endif.
v_no = v_no + 1.
enddo.
endloop.
After this loop your i_output table contains the material with total of value
a®
‎2009 May 13 8:08 PM
Hi
U can use the field-symbols:
PARAMETERS: P_MONTH(2) TYPE N.
TABLES MVER.
DATA: T_MVER TYPE TABLE OF MVER.
DATA: FIELDNAME(30) TYPE C.
DATA: TOT TYPE MVER-GSV01.
DATA: COUNT(2) TYPE N.
FIELD-SYMBOLS: <FS_GSV> TYPE ANY.
LOOP AT T_MVER INTO MVER.
DO P_MONTH TIMES.
FIELDNAME = 'GSV&'.
MOVE SY-INDEX TO COUNT.
REPLACE '&' WITH COUNT INTO FIELDNAME.
ASSIGN COMPONENT FIELDNAME OF STRUCTURE MVER TO <FS_GSV>.
TOT = TOT + <FS_GSV>.
ENDDO.
ENDLOOP.Max