Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

problem in adding field values?

Former Member
0 Likes
526

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
464

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

2 REPLIES 2
Read only

Former Member
0 Likes
464

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

Read only

Former Member
0 Likes
465

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