0
Former Member
Nov 13, 2007 at 08:26 AM

56 Views

i have to fetch belnr from bkpf table, and tax amount(fwste) from bset table.

if for a particular belnr suppose if this belnr 1700000000 has 5 line items in bset table than i need tax amount for all those 5 line items it means i need addition of that tax amount in output

for eg in bset table

belnr fwste lifnr curr

17000000000 0.00 0002300000 usd

2.00

0.00

4.00

in ouput i should get only subtotal has

1700000000 6.00 00023000000 usd

below is the code

SELECT bukrs

belnr

gjahr

xblnr

waers

budat

usnam

tcode

awkey

FROM bkpf

INTO TABLE gt_bkpf

WHERE bukrs IN s_bukrs

AND gjahr IN s_gjahr

AND tcode EQ 'MIRO'.

SELECT bukrs

belnr

gjahr

buzei

koart

lifnr

zlspr

FROM bseg

INTO TABLE gt_bseg

FOR ALL ENTRIES IN gt_bkpf

WHERE bukrs EQ gt_bkpf-bukrs

AND belnr EQ gt_bkpf-belnr

AND gjahr EQ gt_bkpf-gjahr

AND lifnr IN s_lifnr

AND zlspr IN s_zlspr

and koart eq 'K'.

• AND bschl EQ '31'.

gt_bseg1[] = gt_bseg[].

SORT gt_bseg1[] BY lifnr.

DELETE ADJACENT DUPLICATES FROM gt_bseg1[] COMPARING lifnr.

*

IF gt_bseg1[] IS NOT INITIAL.

SELECT lifnr

name1

FROM lfa1

INTO TABLE gt_lfa1

FOR ALL ENTRIES IN gt_bseg1

WHERE lifnr EQ gt_bseg1-lifnr.

• and lifnr eq s_lifnr.

ENDIF.

IF gt_bkpf[] IS NOT INITIAL.

SELECT belnr

gjahr

tcode

WAERS

zuonr

FROM rbkp

INTO TABLE gt_rbkp

FOR ALL ENTRIES IN gt_bkpf

WHERE gjahr EQ gt_bkpf-gjahr

AND tcode EQ gt_bkpf-tcode

AND belnr EQ gt_bkpf-awkey+0(10).

• tax amount

SELECT bukrs

belnr

gjahr

buzei

fwste

FROM bset

INTO TABLE gt_bset

FOR ALL ENTRIES IN gt_bkpf

WHERE bukrs EQ gt_bkpf-bukrs

AND belnr EQ gt_bkpf-belnr

AND gjahr EQ gt_bkpf-gjahr.

• and fwste ne 0 .

ENDIF.

IF gt_rbkp[] IS NOT INITIAL.

SELECT belnr

gjahr

buzei

cobl_nr

wrbtr

menge

mwskz

meins

FROM rbco

INTO TABLE gt_rbco

FOR ALL ENTRIES IN gt_rbkp

WHERE belnr EQ gt_rbkp-belnr.

ENDIF.

SELECT ebeln

ernam

FROM ekko

INTO TABLE gt_ekko

FOR ALL ENTRIES IN gt_rbkp

WHERE ebeln EQ gt_rbkp-zuonr+0(10).

IF gt_ekko[] IS NOT INITIAL.

SELECT banfn

bnfpo

ernam

ebeln

FROM eban

INTO TABLE gt_eban

FOR ALL ENTRIES IN gt_ekko

WHERE ebeln EQ gt_ekko-ebeln.

ENDIF.

ENDFORM. " RETRIEVE_DATA

&----

*& Form MODIFY_DATA

&----

• text

----

• --> p1 text

• <-- p2 text

----

FORM modify_data .

*Sorting all Internal Tables .

SORT gt_bseg BY bukrs belnr gjahr.

SORT gt_bkpf BY bukrs belnr gjahr.

SORT gt_lfa1 BY lifnr.

SORT gt_rbkp BY belnr.

SORT gt_rbco BY belnr.

SORT gt_ekko BY ebeln.

SORT gt_bset BY belnr.

• SORT gt_bset

SORT gt_eban BY ebeln.

*

• SORT gt_bkpf .

• SORT gt_bseg .

• SORT gt_lfa1 .

• SORT gt_rbkp .

• SORT gt_rbco .

• SORT gt_ekko .

• SORT gt_bset.

• SORT gt_eban .

LOOP AT GT_BSEG WHERE BELNR NE ' '.

• MOVE gt_bseg-pswsl TO gt_final-pswsl.

MOVE gt_bseg-lifnr TO gt_final-lifnr.

MOVE gt_bseg-zlspr TO gt_final-zlspr.

READ TABLE GT_BKPF WITH KEY BELNR = GT_BSEG-BELNR BINARY SEARCH.

IF SY-SUBRC = 0.

MOVE gt_bkpf-bukrs TO gt_final-bukrs.

MOVE gt_bkpf-belnr TO gt_final-belnr.

MOVE gt_bkpf-xblnr TO gt_final-xblnr.

MOVE gt_bkpf-budat TO gt_final-budat.

MOVE gt_bkpf-usnam TO gt_final-usnam.

ENDIF.

READ TABLE gt_lfa1 WITH KEY lifnr = gt_bseg-lifnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE gt_lfa1-name1 TO gt_final-name1.

ENDIF.

READ TABLE gt_rbkp WITH KEY belnr = gt_bkpf-awkey+0(10)

gjahr = gt_bkpf-gjahr

BINARY SEARCH.

IF sy-subrc = 0.

MOVE gt_rbkp-belnr TO gt_final-rbelnr.

MOVE gt_rbkp-waers TO gt_final-waers.

MOVE gt_rbkp-zuonr TO gt_final-zuonr.

endif.

READ TABLE gt_rbco WITH KEY belnr = gt_rbkp-belnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE gt_rbco-buzei TO gt_final-buzei.

MOVE gt_rbco-wrbtr TO gt_final-wrbtr.

MOVE gt_rbco-menge TO gt_final-menge.

MOVE gt_rbco-meins TO gt_final-meins.

MOVE gt_rbco-mwskz TO gt_final-mwskz.

endif.

READ TABLE gt_ekko WITH KEY ebeln = gt_rbkp-zuonr+0(10) BINARY SEARCH.

IF sy-subrc = 0.

MOVE gt_ekko-ernam TO gt_final-ernam.

endif.

READ TABLE gt_eban WITH KEY ebeln = gt_ekko-ebeln BINARY SEARCH.

IF sy-subrc = 0.

MOVE gt_eban-ernam TO gt_final-ernam.

ENDIF.

• READ TABLE GT_BSET WITH KEY BELNR = GT_BKPF-BELNR BINARY SEARCH.

• IF SY-SUBRC = 0.

• MOVE GT_BSET-FWSTE TO GT_FINAL-FWSTE.

• ENDIF.

APPEND gt_final.

endloop.