‎2009 Jun 18 3:02 AM
Hi all,
I am using table COSP in my program. The requirement is i need to add the field values(SMEXXX) of this table structure until the period entered in seletion-screen.
i.e if the period is 005.
i need to add
SME001 UNTIL SME005 TO a variable.
if the period is 007 then
SME001 UNTIL SME007.
I need the logic to choose the no of field values dynamically? please help me.
Thanks,
aravind.
‎2009 Jun 18 5:00 PM
Hi,
Create ITAB as follows:
Fetch all the data from all the columns SME001 to SME016 in the respective columns in internal table itab.
Make use of field-symbol to add the value of the corresponding columns as follows:-
<FS1> as line type of ITAB
<fs2> type any.
Assume period selected is 007
LOOP AT ITAB ASSIGNING <FS1>
DO.
IF PERIOD = 000.
exit.
ENDIF.
Concatenate 'SME' period into LV_VARIABLE.
Assign component LV_VARIABLE of structure <FS1>
to <FS2>.
if <FS2> is assigned.
sum = sum + <FS2>
endif.
period = period - 1.
ENDDO.
ENDLOOP.So now sum will contain the sum of the values of SME001 to SME007.
I hope it is clear.
Regards,
Ankur Parab
‎2009 Jun 18 3:33 AM
Hi Aravind,
Here is a Sample code. Just look after It.!
DATA : I(3) TYPE N VALUE '001'.
DATA : TEST(15).
LOOP AT PERIOD.
IF I IN PERIOD.
CLEAR TEST.
CONCATENATE 'SME' I INTO TEST.
I = I + 1.
SELECT (TEST) FORM COSP INTO SME_VALUE....
FINAL_SMEVALUE = FINAL_SMEVALUE + SME_VALUE.
CLEAR : SME_VALUE
ENDSELECT.
ENDLOOP.
Thanks & regards,
Dileep .C
‎2009 Jun 18 5:00 PM
Hi,
Create ITAB as follows:
Fetch all the data from all the columns SME001 to SME016 in the respective columns in internal table itab.
Make use of field-symbol to add the value of the corresponding columns as follows:-
<FS1> as line type of ITAB
<fs2> type any.
Assume period selected is 007
LOOP AT ITAB ASSIGNING <FS1>
DO.
IF PERIOD = 000.
exit.
ENDIF.
Concatenate 'SME' period into LV_VARIABLE.
Assign component LV_VARIABLE of structure <FS1>
to <FS2>.
if <FS2> is assigned.
sum = sum + <FS2>
endif.
period = period - 1.
ENDDO.
ENDLOOP.So now sum will contain the sum of the values of SME001 to SME007.
I hope it is clear.
Regards,
Ankur Parab