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

Regarding collect

Former Member
0 Likes
1,005

hi ,

i have to take these details from tabel bseg

in bseg i have bukrs belnr gjahr buzei shkzg hkont Dmbtr wrbtr from here i have to take data into final o/p tabel.it_final

in it_final has fields bukrs hkont debitAmt CreditAmt

now i need to collect for each gl debit amount and credit amount.

how can i do

thanks ,

satish

hi ,

i have to take these details from tabel bseg

in bseg i have bukrs belnr gjahr buzei shkzg hkont Dmbtr wrbtr from here i have to take data into final o/p tabel.it_final

in it_final has fields bukrs hkont debitAmt CreditAmt

now i need to collect for each gl debit amount and credit amount.

how can i do

thanks ,

satish

8 REPLIES 8
Read only

Former Member
0 Likes
970

Hi,

If you want to sum up amounts then use collect statement.

reward if useful.

Regards

Susheel

Read only

Former Member
0 Likes
970

hi

if shkzg = 'H' it is credit amt , or else it is debit amount ... Move it accordingly

Reward Points if useful.

Regards

Raj.D

Read only

Former Member
0 Likes
970

Hi,

if the field shkzg = 'H' ,then it is a credit amount ,

otherwise it is debit amount.

so,put a loop at internal table and check the condition shkzg for each loop pass and then move the records to the fields accordingly i.e. credit or debit , and then modify the internal table.

after doing these , if you want to add up those field then you can use collect statement for these two fields.

If any iussue you can get back to me.

Read only

former_member491305
Active Contributor
0 Likes
970

Hi ,

Check out the following code,

data:begin of wa_bseg1,

bukrs type bukrs,

hkont type hkont,

shkzg type shkzg,

dmbtr type dmbtr,

end of wa_bseg1,

it_bseg1 like standard table of wa_bseg1.

loop at it_besg into wa_bseg.

move-corresponding wa_bseg to wa_bseg1.

append wa_bseg1 to it_bseg1.

Endloop.

sort it_bseg1 by hkont shkzg.

loop at it_bseg1 into wa_bseg1.

wa_final-hkont = wa_bseg1-hkont.

wa_final-bukrs = wa_bseg1-bukrs.

at end of shkzg.

SUM.

if v_prev_hkont ne wa_bseg1-hkont.

if wa_bseg1-shkzg = 'H'.

wa_final-credit_Amt = wa_bseg1-wrbtr.

elseif wa_bseg1-shkzg = 'S'.

wa_final-debit_Amt = wa_bseg1-wrbtr.

endif.

append wa_final to it_final.

else.

if wa_bseg1-shkzg = 'H'.

wa_final-credit_Amt = wa_bseg1-wrbtr.

modify it_final from wa_final where hkont = wa_bseg1-hkont

transporting credit_Amt.

elseif wa_bseg1-shkzg = 'S'.

wa_final-debit_Amt = wa_bseg1-wrbtr.

modify it_final from wa_final where hkont = wa_bseg1-hkont

transporting debit_Amt.

endif.

endif.

v_prev_hkont = wa_bseg1-hkont.

endat.

endloop.

Regards,

Vigeswaran S

Read only

Former Member
0 Likes
970

Hi,

Try this.

if wa_bsid-shkzg = 'H'.

wa_data-dmbtr = wa_data-dmbtr * - 1.

endif.

*

collect wa_data into i_data.

Thanks...

Rams

Edited by: ramesh on Jun 13, 2008 7:12 AM

Read only

Former Member
0 Likes
970

Using COLLECT statement

Syntax

COLLECT [<wa> INTO] <itab>.

Note:

Use COLLECT statement for tables having unique standard keys.

Incase of tables with header line omit INTO option.

If an entry with same standard key exists new line is not appended but adds the numeric fields to existing contents.

Else collect acts in a similar way as append.

Sy-tabix contains the index of the processed line.

Example:

Data: Begin of itab occurs 3,

column1(3) type C,

column2(2) type N,

column3 type I,

End of itab.

itab-column1 = u2018abcu2019.

itab-column2 = u201912u2019.

itab-column3 = 3.

collect itab.

write /sy-tabix.

itab-column1 = u2018defu2019.

itab-column2 = u201934u2019.

itab-column3 = 5.

collect itab.

write/sy-tabix.

itab-column1 = u2018abcu2019.

itab-column2 = u201912u2019.

itab-column3 = 7.

collect itab.

write /sy-tabix.

Loop at itab.

write :/itab-column1,

itab-column2,

itab-column3.

Endloop.

Result:

1

2

1

abc 12 10

def 34 5

Read only

Former Member
0 Likes
970

Collect statement works on all the numeric and integer fields.

So if your do collect on the internal table type all the number valued fields will get summed up for each unique combination of text/charecter fields.

Please check the types of the your fields and check collect will suit your requirement.

Read only

Former Member
0 Likes
970

Hi satish,

1. We have to write like this.

(some special if condition for debit and credit)

2. Assuming we have the required data in internal table BSEG.

Loop at BSEG.

clear it_final.

It_final-bukrs = bseg-bukrs.

It_final-hkong = bseg-hkont.

if bseg-SHKZG = 'S'.

it_final-debitAmt = bseg-WRBTR.

endif.

if bseg-SHKZG = 'H'.

it_final-creditAmt = bseg-WRBTR.

endif.

COLLECT IT_FINAL.

EndLoop.

regards,

amit m.