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

sort table content

Former Member
0 Likes
939

Hi Gurus,

I have a internal table which has these content in store

ITEM VENDOR PAYMENT DATE TAX RATE AMOUNT

001 810000 01.07.2008 1% 2500

002 810000 01.07.2008 1% 3600

003 810000 01.07.2008 2% 3000

004 810000 02.07.2008 2% 320

005 810000 02.07.2008 2% 900

006 810000 02.07.2008 3% 2000

007 810001 02.07.2008 2% 4000

008 810001 02.07.2008 2% 1000

If the table content has the same vendor , payment date and tax rate. the content of these records should be combined. and others dont need. the content for new internal table should be

ITEM VENDOR PAYMENT DATE TAX RATE AMOUNT

001 810000 01.07.2008 1% 6100

002 810000 01.07.2008 2% 3000

003 810000 02.07.2008 2% 320

004 810000 02.07.2008 2% 900

005 810000 02.07.2008 3% 2000

006 810001 02.07.2008 2% 5000

the first 2 rows are combined and the amount is calculated to the total amount of item 1 and 2. same as the last 2 rows.

can anyone tell me how to achieve it?

regards,

Samson

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
916

Hi Samson,

Please understand and change the fields according to your requirement. This will get the issue resolved. This is for one field which I have done. For three fields declare three temporary variables.

LOOP AT t_customer INTO fs_customer.
  IF   w_temp ne fs_customer-cusnum.
    WRITE :/ fs_customer-cusnum  UNDER text-001,
             fs_customer-cusname UNDER text-002.
    w_amt = fs_customer-amount.

  ELSE.
    w_amt = w_amt + fs_customer-amount.
    WRITE: 45 w_amt.
  ENDIF.                               " IF W_TEMP <> FS_CUSTOMER-...
  w_temp = fs_customer-cusnum.

ENDLOOP.                               " LOOP AT T_CUSTOMER....

Regards,

Swapna.

8 REPLIES 8
Read only

bpawanchand
Active Contributor
0 Likes
916

Hi

You can use the COLLECT statement to get this

Regards

pavan

Read only

0 Likes
916

Thanks, how can set the key words of the internal table?

Read only

Former Member
0 Likes
916

Hi

We can use the COLLECT statment

Ex:

here the Cusotmer number is same -

CLEAR fs_customer. " Clears Header line

fs_customer-num = 'C002'.

fs_customer-name = 'MIKE'.

fs_customer-amount = 2000.

APPEND fs_customer TO t_customer. " Adds a record to Internal table

**Record 3**

CLEAR fs_customer.

fs_customer-num = 'C003'.

fs_customer-name = 'ARNOLD'.

fs_customer-amount = 2000.

APPEND fs_customer TO t_customer.

**Record 4**

CLEAR fs_customer. " Clears Header line

fs_customer-num = 'C002'.

fs_customer-name = 'MIKE'.

fs_customer-amount = 2000.

COLLECT fs_customer INTO t_customer. " Adds Data to Existing Field

Thanks & Regards,

Chandralekha.

Read only

Former Member
0 Likes
916

hi,

COLLECT statement can be used only when all non key fileds are numeric. It adds all the non key numeric fields.

Regards

Sumit Agarwal

Read only

Former Member
0 Likes
916

Hi,

just do m2 steps

step 1: make sure that your 1st and 2nd col are of datatype c

or p or n.

step2 use COLLECT STATEMENT.

For details check the link

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/content.htm

Regards,

Anirban

Read only

Former Member
0 Likes
916

If U don't have the field ITEM(first field) then U can use

COLLECT statement ..

Read only

Former Member
0 Likes
916

hi

frist sort the table like this

let tha table is ITAB

the n

sort ITAB by field vendor , payment date and tax rate.

now apply loop on this internal table and

inside this loop

use AT NEW or ON change Statement on fields vendor , payment date and tax rate.

Hope this will lead u to solution

Cheers

Snehi

Read only

Former Member
0 Likes
917

Hi Samson,

Please understand and change the fields according to your requirement. This will get the issue resolved. This is for one field which I have done. For three fields declare three temporary variables.

LOOP AT t_customer INTO fs_customer.
  IF   w_temp ne fs_customer-cusnum.
    WRITE :/ fs_customer-cusnum  UNDER text-001,
             fs_customer-cusname UNDER text-002.
    w_amt = fs_customer-amount.

  ELSE.
    w_amt = w_amt + fs_customer-amount.
    WRITE: 45 w_amt.
  ENDIF.                               " IF W_TEMP <> FS_CUSTOMER-...
  w_temp = fs_customer-cusnum.

ENDLOOP.                               " LOOP AT T_CUSTOMER....

Regards,

Swapna.