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

how to store the grouped(sumed) value while processing internal table

Former Member
0 Likes
772

Hi all

I am very new to ABAP, i have a doubt on the following.

I have internal table like this

Material S Location Qty

C0001 TPIN 100

C0001 TAPS 200

C0001 CAFS 100

S1101 SCIN 25

S1101 SCOP 25

S1101 SCOP 125

I want to sum the qty by material wise and store in the variable.

The variable can be refered by another program.

Can anyone tell the solution for this.

Regards

Rajaram

8 REPLIES 8
Read only

Former Member
0 Likes
747

HII

U CAN USE COLLECT STATEMENT FOR SUM

COLLECT INTERNAL TABLE NAME.

HOPE UR PROBLEM WILL GET SOLVED , IF SO REWARDS EXPECTED

GAURAV

Read only

0 Likes
747

hi gaurav

Thank you very much for your instant reply.

We can use COLLECT statement, but S Location is there na,

We can't put COLLECT ,

before doing COLLECT, non-numeric field should contain same data.

but our case, S Location has different data,

so how can we process now.

Regards

Rajaram

Read only

Former Member
0 Likes
747

HI,

say your internal table name --ITAB and work area WA

lv_qty variable of type quantity

loop at ITAB into WA.

at end of matnr.

sum.

lv_qty = wa-qty.

Now you can export the material and quantity to another program..

endat.

endloop.

lv_aty contains the sum of quantity..

reward if useful

regards,

nazeer

Read only

0 Likes
747

hi nazeer

Thank your very much for your reply.

I don't think that by using this statement

at end of matnr.

sum.

we can sum the qty by material wise.

when we use this statement, our output would be

C001233 SLIN 25

SUM = 25

C001233 CLIN 130

SUM = 130

S3423 CCOP 100

SUM = 132

S3423 CCIN 232

Like this only, but our requirement is materiasl wise as follows

C001233 SLIN 25

C001233 CLIN 130

SUM = 155

S3423 CCOP 100

S3423 CCIN 232

SUM = 332

do you have idea of this. Anyway thank you very much for your response.

Regards

Rajaram

Read only

Former Member
0 Likes
747

hello raja ram.

use this sample code, exe it and see, i think it will be useful

copy the same code and execute u will get an idea....

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.

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.

Read only

0 Likes
747

hi Bharani

It is really nice, and thank you very much.

It is very helpful to me, thank you.

Now my problem solved.

Thank you all for giving me great support on this forum.

Regards

Rajaram

Read only

0 Likes
747

hello raja ram,

giv ur gmail id yaar

mine is bharanidaran.sb1@gmail.com

With Regards,

S.Barani

Read only

0 Likes
747

hi bharani

my mail id is

saprajaram@yahoo.com

Regards

Rajaram