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

General

Former Member
0 Likes
767

Hey folks,

I have a requirement

itab

a 1

b 2

c 3

d 4

I want to modify this

itab

a 1

b 3

c 6

d 10

How would i achieve this

I have to add the previous value

7 REPLIES 7
Read only

Former Member
0 Likes
751

You can use below logic:

data : begin of itab occurs 0,

fld1 type c,

fld2 type i,

end of itab.

data itab1 like itab occurs 0 with header line.

data : v_fld type i.

start-of-selection.

itab-fld1 = 'a'.

itab-fld2 = 1.

append itab.

clear itab.

itab-fld1 = 'b'.

itab-fld2 = 2.

append itab.

clear itab.

itab-fld1 = 'c'.

itab-fld2 = 3.

append itab.

clear itab.

itab-fld1 = 'd'.

itab-fld2 = 4.

append itab.

clear itab.

loop at itab.

move itab-fld1 to itab1-fld1.

v_fld = v_fld + itab-fld2.

move v_fld to itab1-fld2.

append itab1.

clear itab1.

clear itab.

endloop.

loop at itab1.

write:/ itab1-fld1,itab1-fld2.

endloop.

Thanks

Seshu

Read only

Former Member
0 Likes
751

Hi ,

Try this.

DATA : lv_value TYPE i.

LOOP AT itab.

itab-field2 = itab-field2 + lv_value.

modify itab.

lv_value = lv_value + itab-field2.

ENDLOOP.

Regards,

Sudhir Atluru

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Feb 7, 2008 2:25 PM

Read only

0 Likes
751

Hey folks,

I want to sum up all the values but without using collect how would I do tat.

Regards

Rock

Read only

0 Likes
751

Did you check the my logic ,i did not use collect statement :

loop at itab.

move itab-fld1 to itab1-fld1.

v_fld = v_fld + itab-fld2.

move v_fld to itab1-fld2.

append itab1.

clear itab1.

clear itab.

endloop.

loop at itab1.

write:/ itab1-fld1,itab1-fld2.

endloop.

Thanks

Seshu

Read only

0 Likes
751

Totla/ sum without using Collect

DATA : BEGIN OF itab OCCURS 0,
fld1 TYPE c,
fld2 TYPE i,
END OF itab.

DATA itab1 LIKE itab OCCURS 0 WITH HEADER LINE.
DATA : v_fld TYPE i.

START-OF-SELECTION.

  itab-fld1 = 'a'.
  itab-fld2 = 1.
  APPEND itab.
  CLEAR itab.

  itab-fld1 = 'b'.
  itab-fld2 = 2.
  APPEND itab.
  CLEAR itab.

  itab-fld1 = 'c'.
  itab-fld2 = 3.
  APPEND itab.
  CLEAR itab.

  itab-fld1 = 'd'.
  itab-fld2 = 4.
  APPEND itab.
  CLEAR itab.

  LOOP AT itab.

    MOVE itab-fld1 TO itab1-fld1.
    MOVE itab-fld2 TO itab1-fld2.
    v_fld = v_fld + itab-fld2.
    APPEND itab1.

    AT LAST.
      MOVE 'SUM' TO itab1-fld1.
      MOVE v_fld TO itab1-fld2.
      APPEND itab1.
    ENDAT.

    CLEAR itab1.
    CLEAR itab.

  ENDLOOP.

  LOOP AT itab1.
    WRITE:/ itab1-fld1,itab1-fld2.
  ENDLOOP.

Read only

0 Likes
751

Hey Seshu,

I want to sum and modify the same table itself.

How wud i do this.

I am creating a field by name qty in the same table i_resb , I want the summed up values to be in this field.

i have written the code like this but its not working cud u please correct me if i am wrong

loop at i_resb1 into wa_resb.

read table i_mara into wa_mara with key matnr = wa_resb-matnr binary search.

if wa_mara-meins is initial and i_resb-bdter LE condition_date.

N4 = wa_resb-erfmg.

ELSE.

N4 = wa_resb-erfmg / ( wa_mara-umrez / wa_mara-umren ).

wa_resb-qty = wa_resb-qty + N4.

ENDIF.

modify i_resb1 from wa_resb.

endloop.

regards

Rock

Read only

former_member156446
Active Contributor
0 Likes
751
field-symbols: <fs> like line of itab1.

loop at itab assigning <fs>.

move <fs>-fld1 to itab1-fld1.
v_fld = v_fld + <fs>-fld2.
Assign v_fld to <fs>-fld2.
" you can remove the append statement
endloop.