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

Internal table sum

Former Member
0 Likes
458

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
421

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

2 REPLIES 2
Read only

former_member194669
Active Contributor
0 Likes
421

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®

Read only

Former Member
0 Likes
422

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