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

Re : Internal tables

Former Member
0 Likes
1,573

Hi experts,

i am hanig the internal table which having the fields custno ,cutname,amount,curr etc..

if i want the data like this..

{ CUST NO CUST NAME AMOUnt curr

100 KIRAN 100 MYR

100 KIRAN 200 MYR

100 KIRAN 100 SGD

100 KIRAN 200 SGD

*100 KIRAN 300 MYR ( 100 MYR + 200 mYR ) SUBTOTAL

*100 KIRAN 300 SGD ( 100 SGD + 200 SGD ) SUBTOTAL

101 RAM 100 MYR

101 RAM 200 MYR

101 RAM 100 SGD

101 RAM 200 SGD

*101 RAM 300 MYR ( SUB TOTAL )

*101 RAM 300 SGD ( SUB TOTAL )

-


      • TOATL 600 MYR ( 300 MYR OF KIRAN + 300 MYR OF RAM )

600 SGD ( 300 SGD OF KIRAN + 300 SGD OF RAM )

-


}

what i have to do..

can any one please tell me hot to do...

Thanks & Best Regards,

Praveen.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,540

Hi Praveen Rao,

Let say u have

100 KIRAN 100 MYR

100 KIRAN 200 MYR

100 KIRAN 100 SGD

100 KIRAN 200 SGD

101 RAM 100 MYR

101 RAM 200 MYR

101 RAM 100 SGD

101 RAM 200 SGD in it_1 and loop this it_1 by using collect statement in to it_2 then you will get

100 KIRAN 300 MYRL

100 KIRAN 300 SGD

101 RAM 300 MYR

101 RAM 300 SGD this in it_2.

Thats it rite???

Regards,

SG.

Hi Praveen Rao,

Let say u have

100 KIRAN 100 MYR

100 KIRAN 200 MYR

100 KIRAN 100 SGD

100 KIRAN 200 SGD

101 RAM 100 MYR

101 RAM 200 MYR

101 RAM 100 SGD

101 RAM 200 SGD in it_1 and loop this it_1 by using collect statement in to it_2 then you will get

100 KIRAN 300 MYRL

100 KIRAN 300 SGD

101 RAM 300 MYR

101 RAM 300 SGD this in it_2.

Thats it rite???

Regards,

SG.

12 REPLIES 12
Read only

Former Member
0 Likes
1,540

Hi,

You can loop at the internal table and in that use

AT END OF cust_no.

ENDAT.

Study the usage of this through F1 help.. and proceed...

Hope this helps..

Read only

Former Member
0 Likes
1,540

Hi praveen,

COLLECT wa INTO itab [result].

for example :

DATA: BEGIN OF seats, 
        carrid   TYPE sflight-carrid, 
        connid   TYPE sflight-connid, 
        seatsocc TYPE sflight-seatsocc, 
      END OF seats. 

DATA seats_tab LIKE HASHED TABLE OF seats 
               WITH UNIQUE KEY carrid connid. 

SELECT carrid connid seatsocc 
       FROM sflight 
       INTO seats. 
  COLLECT seats INTO seats_tab. 
ENDSELECT.

Hope this will help you:)

Regards,

sreenivasa sarma K

Read only

Former Member
0 Likes
1,540

First Sort The internal Table exactly the same sequence as the component of its line type - that is, first in accordance with the first component, then in accordance with the second component, and so on.

Then Use LOOP-ENDLOOP.

In control level processing , use statement SUM to add together the numeric components.

Read only

Former Member
0 Likes
1,541

Hi Praveen Rao,

Let say u have

100 KIRAN 100 MYR

100 KIRAN 200 MYR

100 KIRAN 100 SGD

100 KIRAN 200 SGD

101 RAM 100 MYR

101 RAM 200 MYR

101 RAM 100 SGD

101 RAM 200 SGD in it_1 and loop this it_1 by using collect statement in to it_2 then you will get

100 KIRAN 300 MYRL

100 KIRAN 300 SGD

101 RAM 300 MYR

101 RAM 300 SGD this in it_2.

Thats it rite???

Regards,

SG.

Read only

0 Likes
1,540

HI sunil,

thats correct for subtotal...

and i want totals also...

like

total 600 MYR

600 SGD

can u please help me..

Thanks & Best Regards,

Praveen.

Read only

0 Likes
1,540

Hi Praveen ,

I understood now.. let me know in a while.

Regards,

sg.

Read only

0 Likes
1,540

Have you solved the prg if not just go thru this code...

PROGRAM ZHIDE NO STANDARD PAGE HEADING.

TYPES: BEGIN OF type_tab,

custno TYPE KNA1-KUNNR,

cutname TYPE KNA1-NAME1,

amount TYPE BSEG-DMBTR,

curr TYPE KNA1-UWAER,

END OF type_tab.

DATA: wa_tab1 type type_tab,

tbl_tab1 type table of type_tab,

tbl_tab2 type table of type_tab,

tbl_tab3 type table of type_tab,

wa_tab2 type type_tab..

*Let say in tbl_tab1 u have this much records

wa_tab1-custno = '100'.

wa_tab1-cutname = 'KIRAN'.

wa_tab1-amount = '150'.

wa_tab1-curr = 'MYR'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '100'.

wa_tab1-cutname = 'KIRAN'.

wa_tab1-amount = '200'.

wa_tab1-curr = 'MYR'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '100'.

wa_tab1-cutname = 'KIRAN'.

wa_tab1-amount = '100'.

wa_tab1-curr = 'SGD'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '100'.

wa_tab1-cutname = 'KIRAN'.

wa_tab1-amount = '200'.

wa_tab1-curr = 'SGD'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '101'.

wa_tab1-cutname = 'RAM'.

wa_tab1-amount = '100'.

wa_tab1-curr = 'MYR'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '101'.

wa_tab1-cutname = 'RAM'.

wa_tab1-amount = '200'.

wa_tab1-curr = 'MYR'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '101'.

wa_tab1-cutname = 'RAM'.

wa_tab1-amount = '100'.

wa_tab1-curr = 'SGD'.

APPEND wa_tab1 to tbl_tab1.

wa_tab1-custno = '101'.

wa_tab1-cutname = 'RAM'.

wa_tab1-amount = '200'.

wa_tab1-curr = 'SGD'.

APPEND wa_tab1 to tbl_tab1.

Loop at tbl_tab1 into wa_tab1.

collect wa_tab1 into tbl_tab2.

clear wa_tab1.

endloop.

tbl_tab3[] = tbl_tab2[].

SORT tbl_tab2 by curr.

delete adjacent DUPLICATES FROM tbl_tab2 COMPARING curr.

Loop at tbl_tab2 into wa_tab1.

clear wa_tab1-amount.

loop at tbl_tab3 into wa_tab2 WHERE curr = wa_tab1-curr.

wa_tab1-amount = wa_tab1-amount + wa_tab2-amount.

endloop.

modify tbl_tab2 from wa_tab1.

endloop.

Loop at tbl_tab2 into wa_tab1.

WRITE 😕 wa_tab1-custno, wa_tab1-cutname, wa_tab1-amount, wa_tab1-curr.

clear wa_tab1.

endloop.

Edited by: Suneel Kumar Gopisetty on Mar 25, 2009 1:36 PM

Read only

0 Likes
1,540

Hi Praveen,

Have you manage to get desired output ???

Regards,

Suneel G

Read only

Former Member
0 Likes
1,540

Hi,

Follow the below steps

1.To get the total of the curr as per the custno.

Sort the table based on the custno(so table will be sort 100 then 101 and so on)
loop at internal table
at new custno
sum "this will result in the sum of the amnt for every custno
end at.
endloop.

.

2.for subtotal

sort the table first on the basis of cust no then on the curr
loop at itab 
on change of curr.
add the amnt for the same curr.
end at.
enloop.

hope this help you.

Pooja

Read only

Former Member
0 Likes
1,540

Hi Praveen

check this out,

TYPES: BEGIN OF type_tab

custno TYPE -

cutname TYPE -

amount TYPE -

curr TYPE -

END OF type_tab.

DATA: wa_tab1 type type_tab,

tbl_tab1 type table of type_tab,

tbl_tab2 type table of type_tab.

Let say in tbl_tab1 u have this much records

100 KIRAN 100 MYR

100 KIRAN 200 MYR

100 KIRAN 100 SGD

100 KIRAN 200 SGD

101 RAM 100 MYR

101 RAM 200 MYR

101 RAM 100 SGD

101 RAM 200 SGD

Use

Loop at tbl_tab1 into wa_tab1.

collect wa_tab1 into tbl_tab2.

endloop.

then in tbl_tab2 we will have this much records

100 KIRAN 300 MYRL

100 KIRAN 300 SGD

101 RAM 300 MYR

101 RAM 300 SGD

Regards

SG.

Read only

Former Member
0 Likes
1,540

Dear Pravin Roa

Collect statement adds all your amount & quantity fields for the same customer fields..

Say customer 100 has 200 & 300 amounts in two separate records..after using collect statement this will be added and shown as 500 for the 100 customer. If I'm not wrong this is your requirement.

The best way to achieve this is - Create a new internal table same as the table having these split values or multiple records, loop at the first internal table. Pass all the values to the newly created internal table. At the end use collect itab_new. You will have the required results.

(But kindly Note while using COLLECT Statement your first field of the internal table has to be of TYPE C, character type. Also the type of internal table also does matter)

Regards Ajai

Edited by: Ajay Ranjan on Mar 25, 2009 7:03 AM

Read only

Former Member
0 Likes
1,540

Hi,

You can use this logic:

SORT tbl_tab1 BY custno cutname curr.

LOOP AT tbl_tab1 INTO wa_tab1.

sum_fin = sum_fin + wa_tab1-amount.

AT END OF custno.

wa_tab2-amount = sum_fin.

APPEND wa_tab2 to tbl_tab2.

sum_fin = 0.

ENDAT.

COLLECT wa_tab1 INTO tbl_tab3.

MOVE-CORRESPONDING wa_tab1 to wa_tab2.

CLEAR: wa_tab2-curr, wa_tab1.

ENDLOOP.