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

Hi need a logic

Former Member
0 Kudos
374

Hi all,

I have an internal table like below.

line no r-code item1 item2 amount

1 101

2 102

3 103

4 Z00 1 3

in loop if r-code is Z00 i have take item1 (value 1) and item2 (value 3) for Z00

and then i need sum up the amount field from 1 to 3(line no field) and i have to put it in Z00 amount field.

what can i do.

Thanks

Saravana

6 REPLIES 6
Read only

Former Member
0 Kudos
350

Hai,

Use <b>COLLECT</b> Statement.

Regards,

Padmam.

Read only

anversha_s
Active Contributor
0 Kudos
350

hi,

data : loc_tabix like sy-tabix.

loop at itab.
loc_tabix = sy-tabix.
itab-amount = itab-item1 + itab-item2.
modify itab index loc_tabix.
clear loc_tabix.
endloop.

Regards

Anversha

Read only

Former Member
0 Kudos
350

Hi

do like this

Loop at r_code.

if kschl = 'Z00'.

r_code-amount = r_code-item1 +r_code-item2 + r_code-item3.

endif.

modify r_code index sy-tabix transporting amount.

endloop.

Reward points if useful

Regards

Anji

Read only

Former Member
0 Kudos
350

Hi,

loop at itab where r_code = 'Z00'.

itab-amount = itab-item1 + itab-item2.

modify itab.

endloop.

rgds,

bharat.

Read only

Former Member
0 Kudos
350

hi,

execute this program & it will be useful

CODE FOR SUMMING VAL FOR SAME PERNR

**************************************

REPORT ZY_TEST1.

TYPES : BEGIN OF TY_ITAB,

PERNR TYPE PA0001-PERNR,

HRS(3) TYPE N,

WKS(3) TYPE N,

END OF TY_ITAB.

DATA : ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE.

DATA : ITAB2 TYPE TABLE OF TY_ITAB WITH HEADER LINE.

DATA : WF_HRS(3) TYPE N,

WF_WKS(3) TYPE N,

WA TYPE TY_ITAB .

ITAB-PERNR = '1'.

ITAB-HRS = '5'.

ITAB-WKS = '1'.

APPEND ITAB.

ITAB-PERNR = '1'.

ITAB-HRS = '6'.

ITAB-WKS = '2'.

APPEND ITAB.

ITAB-PERNR = '1'.

ITAB-HRS = '7'.

ITAB-WKS = '3'.

APPEND ITAB.

ITAB-PERNR = '2'.

ITAB-HRS = '5'.

ITAB-WKS = '4'.

APPEND ITAB.

ITAB-PERNR = '2'.

ITAB-HRS = '5'.

ITAB-WKS = '5'.

APPEND ITAB.

ITAB-PERNR = '3'.

ITAB-HRS = '5'.

ITAB-WKS = '1'.

APPEND ITAB.

ITAB-PERNR = '4'.

ITAB-HRS = '5'.

ITAB-WKS = '1'.

APPEND ITAB.

ITAB-PERNR = '4'.

ITAB-HRS = '7'.

ITAB-WKS = '8'.

APPEND ITAB.

LOOP AT ITAB. " note : comparing field should be the first field

WA = ITAB.

WF_HRS = WF_HRS + WA-HRS.

WF_WKS = WF_WKS + WA-WKS.

AT END OF PERNR.

CLEAR: ITAB2.

ITAB2-PERNR = WA-PERNR.

ITAB2-HRS = WF_HRS.

ITAB2-WKS = WF_WKS.

APPEND ITAB2.

CLEAR: WF_HRS, WF_WKS .

ENDAT.

ENDLOOP.

WRITE 😕 'BEFORE'.

LOOP AT ITAB.

WRITE 😕 ITAB-PERNR, 10 ITAB-HRS, 20 ITAB-WKS.

ENDLOOP.

SKIP 2.

WRITE 😕 'AFTER'.

loop at itab2.

WRITE 😕 ITAB2-PERNR, 10 ITAB2-HRS, 20 ITAB2-WKS.

ENDLOOP.

With Regards,

S.Barani

Read only

Former Member
0 Kudos
350

hi,

sort itab by line.

loop at itab.

at end of r-code.

itab-amount = itab-item1 + itab-item2.

move itab-amount itab-rcode.

endloop.

if helpful reward some points.

with regards,

suresh babu aluri.