Skip to Content
0
Former Member
Jun 04, 2008 at 06:18 PM

regarding combining the 2 codes

25 Views

hi,

i had deveoped a code in which i am displaying that these are the open items and close items. i had used the tables :- BSIK,BSAK.

I am able to create it in 2 different code but now i want to combine it .main data is in ITAB2 n itab3.

plzz help me in delepoing dis code,i will be very thankful to you all:-

here's d code:-

report ZNEW01

no standard page heading line-size 255.

******************************BEGIN OF OPEN ITEMS*******************************

TABLES: RSEG.

DATA: BEGIN OF ITBKPF OCCURS 0,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWKEY LIKE BKPF-AWKEY,

BUDAT LIKE BKPF-BUDAT,

XBLNR LIKE BKPF-XBLNR,

AWTYP LIKE BKPF-AWTYP,

END OF ITBKPF.

DATA: BEGIN OF ITAB2 OCCURS 0,

BUKRS LIKE BSIK-BUKRS,

GJAHR LIKE BSIK-GJAHR,

BELNR LIKE BSIK-BELNR,

WRBTR LIKE BSIK-WRBTR,

LIFNR LIKE BSIK-LIFNR,

END OF ITAB2.

DATA: BEGIN OF ITDEMO OCCURS 0,

BELNR LIKE RSEG-BELNR,

GJAHR LIKE RSEG-GJAHR,

LFBNR LIKE RSEG-LFBNR,

XBLNR LIKE RSEG-XBLNR,

END OF ITDEMO.

DATA: BEGIN OF ITFINAL OCCURS 0,

LFBNR LIKE RSEG-LFBNR,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWKEY LIKE BKPF-AWKEY,

WRBTR LIKE BSIK-WRBTR,

LIFNR LIKE BSIK-LIFNR,

END OF ITFINAL.

*SELECT-OPTIONS: S_MBLNR FOR MKPF-MBLNR.

SELECT-OPTIONS: P_LFBNR FOR RSEG-LFBNR.

START-OF-SELECTION.

  • BKPF

SELECT BUKRS BELNR GJAHR AWKEY BUDAT XBLNR AWTYP

FROM BKPF

INTO (ITBKPF-BUKRS,ITBKPF-BELNR,ITBKPF-GJAHR,

ITBKPF-AWKEY,ITBKPF-BUDAT,ITBKPF-XBLNR,ITBKPF-AWTYP)

WHERE AWTYP EQ 'MKPF' OR AWTYP EQ 'RMRP'.

  • MKPF

***********BEGIN OF TRY CODE***********

ITDEMO-BELNR = ITBKPF-AWKEY(10).

ITDEMO-GJAHR = ITBKPF-AWKEY+10(4).

ITDEMO-XBLNR = ITBKPF-XBLNR.

SELECT LFBNR FROM RSEG INTO

(ITDEMO-LFBNR) WHERE

BELNR EQ ITBKPF-AWKEY(10) AND

GJAHR EQ ITBKPF-AWKEY+10(4) AND

XBLNR EQ ITBKPF-XBLNR AND LFBNR > 0.

  • AND LFBNR > 0.

***********END OF TRY CODE**************

CHECK SY-SUBRC EQ 0 AND ITDEMO-LFBNR IN P_LFBNR.

  • BSIK

ITAB2-BUKRS = ITBKPF-BUKRS.

ITAB2-GJAHR = ITBKPF-GJAHR.

ITAB2-BELNR = ITBKPF-BELNR.

SELECT WRBTR LIFNR FROM BSIK

INTO (ITAB2-WRBTR, ITAB2-LIFNR)

WHERE BUKRS EQ ITBKPF-BUKRS

AND GJAHR EQ ITBKPF-GJAHR

AND BELNR EQ ITBKPF-BELNR.

APPEND ITAB2.

EXIT.

ENDSELECT.

  • CHECK sy-subrc EQ 0?

APPEND ITDEMO.

EXIT.

ENDSELECT.

APPEND ITBKPF.

ENDSELECT.

  • Fields Found?

READ TABLE ITBKPF TRANSPORTING NO FIELDS INDEX 1.

IF sy-subrc NE 0.

MESSAGE i000(zmm1) WITH 'No documents found!'.

ENDIF.

  • Prepare Output

LOOP AT ITBKPF.

CLEAR ITAB2.

READ TABLE ITAB2

WITH KEY BUKRS = ITBKPF-BUKRS

BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR.

READ TABLE ITDEMO

WITH KEY BELNR = ITBKPF-AWKEY(10).

ITFINAL-LFBNR = ITDEMO-LFBNR.

ITFINAL-BUKRS = ITBKPF-BUKRS.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

ITFINAL-WRBTR = ITAB2-WRBTR.

ITFINAL-LIFNR = ITAB2-LIFNR.

APPEND ITFINAL.

CLEAR ITFINAL.

DELETE ITFINAL WHERE WRBTR = 0.

ENDLOOP.

****************************************

  • END-OF-SELECTION

****************************************

END-OF-SELECTION.

*DELETE ITFINAL WHERE WRBTR = 0.

  • Output

LOOP AT ITFINAL.

WRITE: / ITFINAL-LFBNR,ITFINAL-BELNR, ITFINAL-GJAHR,ITFINAL-AWKEY, ITFINAL-WRBTR, ITFINAL-LIFNR.

ENDLOOP.

************************END OF OPEN ITEMS******************************

*****************************BEGIN OF CLEARED ITEMS*******************************

*TABLES: RSEG.

*

*DATA: BEGIN OF ITBKPF OCCURS 0,

  • BUKRS LIKE BKPF-BUKRS,

  • BELNR LIKE BKPF-BELNR,

  • GJAHR LIKE BKPF-GJAHR,

  • AWKEY LIKE BKPF-AWKEY,

  • BUDAT LIKE BKPF-BUDAT,

  • XBLNR LIKE BKPF-XBLNR,

  • AWTYP LIKE BKPF-AWTYP,

  • END OF ITBKPF.

*

*DATA: BEGIN OF ITAB3 OCCURS 0,

  • BUKRS LIKE BSAK-BUKRS,

  • GJAHR LIKE BSAK-GJAHR,

  • BELNR LIKE BSAK-BELNR,

  • WRBTR LIKE BSAK-WRBTR,

  • LIFNR LIKE BSAK-LIFNR,

  • AUGBL LIKE BSAK-AUGBL,

  • AUGDT LIKE BSAK-AUGDT,

  • XBLNR LIKE BSAK-XBLNR,

  • END OF ITAB3.

*

*DATA: BEGIN OF ITDEMO OCCURS 0,

  • BELNR LIKE RSEG-BELNR,

  • GJAHR LIKE RSEG-GJAHR,

  • LFBNR LIKE RSEG-LFBNR,

  • XBLNR LIKE RSEG-XBLNR,

  • END OF ITDEMO.

*

*DATA: BEGIN OF ITFINAL OCCURS 0,

  • LFBNR LIKE RSEG-LFBNR,

  • BUKRS LIKE BKPF-BUKRS,

  • BELNR LIKE BKPF-BELNR,

  • GJAHR LIKE BKPF-GJAHR,

  • AWKEY LIKE BKPF-AWKEY,

  • WRBTR LIKE BSAK-WRBTR,

  • LIFNR LIKE BSAK-LIFNR,

  • AUGBL LIKE BSAK-AUGBL,

  • AUGDT LIKE BSAK-AUGDT,

  • END OF ITFINAL.

*

*SELECT-OPTIONS: P_LFBNR FOR RSEG-LFBNR.

*

*

*START-OF-SELECTION.

*

  • BKPF

*

  • SELECT BUKRS BELNR GJAHR AWKEY BUDAT XBLNR AWTYP

  • FROM BKPF

  • INTO (ITBKPF-BUKRS,ITBKPF-BELNR,ITBKPF-GJAHR,

  • ITBKPF-AWKEY,ITBKPF-BUDAT,ITBKPF-XBLNR,ITBKPF-AWTYP)

  • WHERE AWTYP EQ 'MKPF' OR AWTYP EQ 'RMRP'.

*

  • MKPF

*

*****************BEGIN OF TRY CODE****************

*

  • ITDEMO-BELNR = ITBKPF-AWKEY(10).

  • ITDEMO-GJAHR = ITBKPF-AWKEY+10(4).

  • ITDEMO-XBLNR = ITBKPF-XBLNR.

*

  • SELECT LFBNR FROM RSEG INTO

  • (ITDEMO-LFBNR) WHERE

  • BELNR EQ ITBKPF-AWKEY(10) AND

  • GJAHR EQ ITBKPF-AWKEY+10(4) AND

  • XBLNR EQ ITBKPF-XBLNR AND LFBNR > 0.

*

  • CHECK SY-SUBRC EQ 0 AND ITDEMO-LFBNR IN P_LFBNR.

*

****************END OF TRY CODE*******************

  • BSAK

*

*

  • ITAB3-BUKRS = ITBKPF-BUKRS.

  • ITAB3-GJAHR = ITBKPF-GJAHR.

  • ITAB3-BELNR = ITBKPF-BELNR.

*

*

  • SELECT WRBTR LIFNR AUGBL AUGDT

  • FROM BSAK

  • INTO (ITAB3-WRBTR,ITAB3-LIFNR,ITAB3-AUGBL,ITAB3-AUGDT)

  • WHERE BUKRS EQ ITBKPF-BUKRS

  • AND GJAHR EQ ITBKPF-GJAHR

  • AND BELNR EQ ITBKPF-BELNR.

*

  • APPEND ITAB3.

  • EXIT.

  • ENDSELECT.

*

  • CHECK sy-subrc EQ 0?

*

  • APPEND ITDEMO.

  • EXIT.

  • ENDSELECT.

*

  • APPEND ITBKPF.

  • ENDSELECT.

*

*SORT ITBKPF BY BELNR.

*SORT ITAB3 BY BELNR.

*

  • Fields Found?

*

  • READ TABLE ITBKPF TRANSPORTING NO FIELDS INDEX 1.

  • IF sy-subrc NE 0.

  • MESSAGE i000(zmm1) WITH 'No documents found!'.

  • ENDIF.

*

  • Prepare Output

*

  • LOOP AT ITBKPF.

*

  • CLEAR ITAB3 .

*

  • READ TABLE ITAB3

  • WITH KEY BUKRS = ITBKPF-BUKRS

  • BELNR = ITBKPF-BELNR

  • GJAHR = ITBKPF-GJAHR. .

*

  • READ TABLE ITDEMO

  • WITH KEY BELNR = ITBKPF-AWKEY(10).

*

  • ITFINAL-LFBNR = ITDEMO-LFBNR.

  • ITFINAL-BUKRS = ITBKPF-BUKRS.

  • ITFINAL-BELNR = ITBKPF-BELNR.

  • ITFINAL-GJAHR = ITBKPF-GJAHR.

  • ITFINAL-AWKEY = ITBKPF-AWKEY.

  • ITFINAL-WRBTR = ITAB3-WRBTR.

  • ITFINAL-LIFNR = ITAB3-LIFNR.

  • ITFINAL-WRBTR = ITAB3-WRBTR.

  • ITFINAL-AUGBL = ITAB3-AUGBL.

  • ITFINAL-AUGDT = ITAB3-AUGDT.

*

  • APPEND ITFINAL.

  • CLEAR ITFINAL.

  • DELETE ITFINAL WHERE WRBTR = 0.

*

  • ENDLOOP.

*

  • SORT ITFINAL BY BELNR.

*

*****************************************

  • END-OF-SELECTION

*****************************************

*END-OF-SELECTION.

*

  • Output

*

  • LOOP AT ITFINAL.

  • WRITE: / ITFINAL-LFBNR,ITFINAL-BELNR,ITFINAL-AUGBL,ITFINAL-AUGDT,ITFINAL-GJAHR,ITFINAL-BUKRS,ITFINAL-AWKEY,ITFINAL-WRBTR,ITFINAL-LIFNR.

  • ENDLOOP.