Application Development 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: 

collect

Former Member
0 Kudos

Hi Expertz,

my data is somthing like this

1234 em 1 12.20 2 34.50 1 23.10 1 12.20

1234 em 1 32.34 3 34.21 0 20.10 1 10.10

1234 sm 1 10.10 1 20.10 1 30.10 1 21.10

after running this bit of code below

LOOP AT gt_output.

AT NEW schemecode.

gt_output3-storeno = gt_output-sno.

gt_output3-schemecode = gt_output-scode.

  • APPEND gt_output3.

ENDAT.

gt_output3-tddreq = gt_output-tddreq.

gt_output3-tddvalue = gt_output-tddvalue.

gt_output3-tunpaiddds = gt_output-tunpaiddds.

gt_output3-tvunpaiddds = gt_output-tvunpaiddds.

gt_output3-tothers = gt_output-tothers.

gt_output3-tothersvalue = gt_output-tothersvalue.

gt_output3-trefunds = gt_output-trefunds.

gt_output3-trefundsvalue = gt_output-trefundsvalue.

COLLECT gt_output3.

ENDLOOP.

im expecting my output as :

1234 em 2 44.54 2 68.71 1 43.20 2 30.30

1234 sm 1 10.10 1 20.10 1 30.10 1 21.10

But its not happening...could you please where im going wrong.

thanks

14 REPLIES 14

Former Member
0 Kudos

schemecode shoud be the first field of internal table

otherwise at new statement not work

em 234 1 12.20 2 34.50 1 23.10 1 12.20

em 1234 1 32.34 3 34.21 0 20.10 1 10.10

sm 1234 1 10.10 1 20.10 1 30.10 1 21.10

it shoud be like that

regards,

Alpesh

Former Member
0 Kudos

LOOP AT gt_output.

gt_output3-tddreq = gt_output-tddreq.

gt_output3-tddvalue = gt_output-tddvalue.

gt_output3-tunpaiddds = gt_output-tunpaiddds.

gt_output3-tvunpaiddds = gt_output-tvunpaiddds.

gt_output3-tothers = gt_output-tothers.

gt_output3-tothersvalue = gt_output-tothersvalue.

gt_output3-trefunds = gt_output-trefunds.

gt_output3-trefundsvalue = gt_output-trefundsvalue.

COLLECT gt_output3.

AT END schemecode.

gt_output3-storeno = gt_output-sno.

gt_output3-schemecode = gt_output-scode.

APPEND gt_output3.

ENDAT.

ENDLOOP.

Former Member
0 Kudos

check this way...no need to use control break statments.

LOOP AT gt_output.

gt_output3-storeno = gt_output-sno.

gt_output3-schemecode = gt_output-scode.

gt_output3-tddreq = gt_output-tddreq.

gt_output3-tddvalue = gt_output-tddvalue.

gt_output3-tunpaiddds = gt_output-tunpaiddds.

gt_output3-tvunpaiddds = gt_output-tvunpaiddds.

gt_output3-tothers = gt_output-tothers.

gt_output3-tothersvalue = gt_output-tothersvalue.

gt_output3-trefunds = gt_output-trefunds.

gt_output3-trefundsvalue = gt_output-trefundsvalue.

COLLECT gt_output3.

ENDLOOP.

0 Kudos

sort internal table by all the character feilds fields that u want to collect than use collect

Former Member
0 Kudos

Hi

Is the structure of gt_output and gt_output3 same ?

If yes

try the below code

LOOP AT gt_output.

gt_output3-storeno = gt_output-sno.

gt_output3-schemecode = gt_output-scode.

gt_output3-tddreq = gt_output-tddreq.

gt_output3-tddvalue = gt_output-tddvalue.

gt_output3-tunpaiddds = gt_output-tunpaiddds.

gt_output3-tvunpaiddds = gt_output-tvunpaiddds.

gt_output3-tothers = gt_output-tothers.

gt_output3-tothersvalue = gt_output-tothersvalue.

gt_output3-trefunds = gt_output-trefunds.

gt_output3-trefundsvalue = gt_output-trefundsvalue.

COLLECT gt_output3.

ENDLOOP.

Regards

MD

Former Member
0 Kudos

Hi GUyz,

Thanks for quick replies..but nothing working..anymore ideas..

thanks

Former Member
0 Kudos

SORT gt_output BY sno scode tddreq.

LOOP AT gt_output INTO wa_output.

COLLECT wa_output INTO gt_output3.

ENDLOOP.

Hope you achevie your output , if not pls place your o/p for the above code .

0 Kudos

Nothing changes the records are same in both gt_output and gt_output3.

Thanks

0 Kudos

i would like to see both the table declaration part !!!

0 Kudos

hi there

declaration part

DATA: BEGIN OF gt_output OCCURS 0,

storeno TYPE ad_sort2,

schemecode TYPE matnr,

totalddreq(10) TYPE c,

totalddvalue(10) TYPE c, "wrbtr,

totalunpaiddds(10) TYPE c,

tvunpaiddds(10) TYPE c, "wrbtr,

totalothers(10) TYPE c,

totalothersvalue(10) TYPE c, "wrbtr,

totalrefunds(10) TYPE c,

totalrefundsvalue(10) TYPE c, "wrbtr,

END OF gt_output.

DATA : wa_output LIKE gt_output.

DATA:gt_output3 LIKE TABLE OF gt_output WITH HEADER LINE.

Thanks

0 Kudos

Change the declaration like below and my above code will work

DATA: BEGIN OF gt_output OCCURS 0,

storeno TYPE ad_sort2,

schemecode TYPE matnr,

totalddreq(10) TYPE c,

totalddvalue(10) TYPE WRBTR, "wrbtr,

totalunpaiddds(10) TYPE WRBTR,

tvunpaiddds(10) TYPE WRBTR, "wrbtr,

totalothers(10) TYPE WRBTR,

totalothersvalue(10) TYPE WRBTR, "wrbtr,

totalrefunds(10) TYPE WRBTR,

totalrefundsvalue(10) TYPE WRBTR, "wrbtr,

END OF gt_output.

DATA : wa_output LIKE gt_output.

DATA:gt_output3 LIKE TABLE OF gt_output WITH HEADER LINE.

As collect statement will not some character's , since you are using a currency field i have given the DE wrbtr ref .

Former Member
0 Kudos

HI,

use below code,

data : flag type c.

data : flag_e type c.

LOOP AT gt_output.

AT NEW schemecode.

flag = 'X'.

ENDAT.

AT END OF schemecode.

flag_e = 'X'.

ENDAT.

gt_output3-tddreq = gt_output-tddreq.

gt_output3-tddvalue = gt_output3-tddvalue + gt_output-tddvalue.

gt_output3-tunpaiddds = gt_output3-tunpaiddds + gt_output-tunpaiddds.

gt_output3-tvunpaiddds = gt_output3-tvunpaiddds + gt_output-tvunpaiddds.

gt_output3-tothers = gt_output3-tothers + gt_output-tothers.

gt_output3-tothersvalue = gt_output3-tothersvalue + gt_output-tothersvalue.

gt_output3-trefunds = gt_output3-trefunds + gt_output-trefunds.

gt_output3-trefundsvalue = gt_output3-trefundsvalue + gt_output-trefundsvalue.

if flag = 'X'.

gt_output3-storeno = gt_output-sno.

gt_output3-schemecode = gt_output-scode.

endif.

if flag_e = 'X'.

APPEND gt_output3.

clear gt_output3.

endif.

clear: flag, flag_e

ENDLOOP.

hope it will work for you...

Regards,

Meet

0 Kudos

Hi Meet

do i have to use collect statements somewhere in your logic? its not adding them up.

0 Kudos

Hi,

in my code you dont need to use collect.

i think it should be work for you.

declare your internal table as per karthik's sudgession and use my code.

Regards,

Meet