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 Statement..

Former Member
0 Kudos
97

Haii..All

I am writing down some code of my program here..the problem is that when i run the program i should get all the linetems combined..for example i have just two records in the development system where values of DMBTR are 12,57 and 80,00 resp. for a documenting no 243000044, so in the final list i should get only one record for this document no with dmbtr as 82,57. i am using the collect statement but i get only the record with 80,00 as dmbtr.

<b>FORM get_data_nolineitems CHANGING P_ITAB P_jTAB.

select belnr bukrs hkont zuonr waers dmbtr budat bldat shkzg into itab

from bsis

where bukrs in x_bukrs

and hkont in x_hkont

and budat in x_budat

and bldat in x_bldat

and zuonr in x_zuonr.

move-corresponding itab to jtab.

*collect jtab.

if itab-shkzg = 'H'.

<fs_dmbtr> = itab-dmbtr * ( -1 ).

move <fs_dmbtr> to jtab-dmbtr.

<fs_vbeln> = itab-zuonr+0(9).

concatenate '0' <fs_vbeln> into <fs_vbeln>.

move <fs_vbeln> to jtab-vbeln.

modify jtab INDEX sy-tabix transporting dmbtr vbeln.

else.

<fs_dmbtr> = itab-dmbtr.

move <fs_dmbtr> to jtab-dmbtr.

<fs_vbeln> = itab-zuonr+0(9).

concatenate '0' <fs_vbeln> into <fs_vbeln>.

move <fs_vbeln> to jtab-vbeln.

modify jtab INDEX sy-tabix transporting dmbtr vbeln.

endif.

select single * into <fs_vbak> from vbak where vbeln = <fs_vbeln>.

if sy-subrc = 0.

move <fs_vbak>-kunnr to x_kunnr.

move <fs_vbak>-erdat to jtab-erdat.

move <fs_vbak>-ernam to jtab-ernam.

modify jtab INDEX sy-tabix transporting erdat ernam.

select single * into <fs_kna1> from kna1 where kunnr = x_kunnr.

move <fs_kna1>-name1 to jtab-name1.

modify jtab INDEX sy-tabix transporting name1.

endif.

collect jtab.

endselect.

ENDFORM. " get_data_nolineitems</b>

Structure of jtab is:

belnr-----belnr_d-bsis

bukrs----bukrs---bsis

hkont----hkont--bsis

vbeln----dzuonr-bsis

waers--waers--bsis

dmbtr---dmbtr--bsis

budat---budat-bsis

bldat----bldat--bsis

name1--name1_gp-kna1

erdat----erdat_rf--vbak

ernam---ernam_rf---vbak.

3 REPLIES 3

0 Kudos
59

Hi,

Did you make Documenting Number as the KEY of the internal table JTAB?

Make this as the KEY of the internal table and then use COLLECT.

<b>COLLECT will sum up all the numeric fields where the value of KEY is same.</b>

Regards,

Sesh

varma_narayana
Active Contributor
0 Kudos
59

Hi Ramakrishna...

You cannot use COLLECT in this case bcoz it will compare all the Non Numeric fields.

So try this code .. it should work.. Little changes may be required as per ur need.

Declare a Separate internal table with the Same structure as ITAB named ITAB_TEMP.

Code:

SELECT

BSISbelnr BSISbukrs BSIShkont BSISdzuonr

BSISwaers BSISdmbtr BSISbudat BSISbldat BSIS~shkzg

vbakerdat vbakernam

KNA1~NAME1

from bsis

inner Join VBAK

on BSISdzuonr = VBAKVBELN

INNER JOIN KNA1

ON VBAKKUNNR = KNA1KUNNR

INTO TABLE ITAB

where <Conditions>.

DATA: WA LIKE LINE OF ITAB.

LOOP AT ITAB.

WA = ITAB.

AT END OF BELNR.

SUM.

WA-DMBTR = ITAB-DMBTR.

APPEND WA TO ITAB_TEMP.

ENDAT.

ENDLOOP.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

0 Kudos
59

haii..this select statement doesnt work because bsis-zuonr and vbak-vbeln are not the same...actually the first 9 digits of zuonr is equal to vbak-vbeln.

and how can i give vbeln as a key for my internal table jtab.

i have declared jtab as follows:

data: begin of jtab occurs 0.

include structure ystr1_wrkpanz.

data: end of jtab.