REPORT ZREC1800 LINE-SIZE 100.
*----------------------------------------------------------------------*
CONSTANTS:
DBCNT LIKE SY-DBCNT VALUE 50.
*----------------------------------------------------------------------*
TABLES:
T001, RF048, BFOD_A, BFOK_A, BKPF, BSEG, BSID, BSAD, BSIK, BSAK.
*----------------------------------------------------------------------*
PARAMETERS:
BUKRS LIKE BKPF-BUKRS OBLIGATORY,
GJAHR LIKE BKPF-GJAHR OBLIGATORY,
MONAT LIKE BKPF-MONAT OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK BL2 WITH FRAME TITLE TEXT-BL2.
PARAMETERS:
XKUNNR AS CHECKBOX DEFAULT 'X'.
SELECT-OPTIONS:
R_KUNNR FOR BSID-KUNNR.
PARAMETERS:
XLIFNR AS CHECKBOX DEFAULT 'X'.
SELECT-OPTIONS:
R_LIFNR FOR BSIK-LIFNR.
SELECTION-SCREEN END OF BLOCK BL2.
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1.
SELECT-OPTIONS:
R_BLART FOR BKPF-BLART,
R_BELNR FOR BKPF-BELNR.
SELECTION-SCREEN END OF BLOCK BL1.
SELECTION-SCREEN BEGIN OF BLOCK BL4 WITH FRAME TITLE TEXT-BL4.
PARAMETERS:
XTEST AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK BL4.
SELECTION-SCREEN BEGIN OF BLOCK BL3 WITH FRAME TITLE TEXT-BL3.
PARAMETERS:
DMMIN LIKE BSEG-DMBTR DEFAULT '1000.00'.
SELECTION-SCREEN END OF BLOCK BL3.
*----------------------------------------------------------------------*
DATA:
TBSEG LIKE BSEG OCCURS 0,
TBSIAD LIKE BSID OCCURS 0 WITH HEADER LINE,
TBSIAK LIKE BSIK OCCURS 0 WITH HEADER LINE,
TBFOD_A LIKE BFOD_A OCCURS 0,
TBFOK_A LIKE BFOK_A OCCURS 0.
DATA:
BEGIN OF BLG,
BELNR LIKE BSEG-BELNR,
GJAHR LIKE BSEG-GJAHR,
BUZEI LIKE BSEG-BUZEI,
HKONT LIKE BSEG-HKONT,
SHKZG LIKE BSEG-SHKZG,
DMBTR LIKE BSEG-DMBTR,
END OF BLG,
BEGIN OF BTRTAB OCCURS 50,
HKONT LIKE BSEG-HKONT,
GSBER LIKE BSEG-GSBER,
SHKZG LIKE BSEG-SHKZG,
DMBTR LIKE BSEG-DMBTR,
END OF BTRTAB,
BEGIN OF BELTAB OCCURS 0,
HKONT LIKE BSEG-HKONT,
GJAHR LIKE BSEG-GJAHR,
BELNR LIKE BSEG-BELNR,
BUZEI LIKE BSEG-BUZEI,
SHKZG LIKE BSEG-SHKZG,
DMBTR LIKE BSEG-DMBTR,
END OF BELTAB,
BEGIN OF CORTAB OCCURS 0,
BELNR LIKE BSEG-BELNR,
GJAHR LIKE BSEG-GJAHR,
END OF CORTAB,
OGTAG TYPE D,
DMMIM LIKE BSEG-DMBTR,
DM0 LIKE BSEG-DMBTR.
*----------------------------------------------------------------------*
START-OF-SELECTION.
* Debitoren
IF XKUNNR = 'X'.
SELECT * FROM BSID INTO TABLE TBSIAD PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR = GJAHR
AND MONAT <= MONAT
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND KUNNR IN R_KUNNR.
PERFORM DIFF_D.
ENDSELECT.
SELECT * FROM BSID INTO TABLE TBSIAD PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR < GJAHR
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND KUNNR IN R_KUNNR.
PERFORM DIFF_D.
ENDSELECT.
SELECT * FROM BSAD INTO TABLE TBSIAD PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR = GJAHR
AND MONAT <= MONAT
AND AUGDT > OGTAG
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND KUNNR IN R_KUNNR.
PERFORM DIFF_D.
ENDSELECT.
SELECT * FROM BSAD INTO TABLE TBSIAD PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR < GJAHR
AND AUGDT > OGTAG
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND KUNNR IN R_KUNNR.
PERFORM DIFF_D.
ENDSELECT.
ENDIF.
* Kreditoren
IF XLIFNR = 'X'.
SELECT * FROM BSIK INTO TABLE TBSIAK PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR = GJAHR
AND MONAT <= MONAT
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND LIFNR IN R_LIFNR.
PERFORM DIFF_K.
ENDSELECT.
SELECT * FROM BSIK INTO TABLE TBSIAK PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR < GJAHR
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND LIFNR IN R_LIFNR.
PERFORM DIFF_K.
ENDSELECT.
SELECT * FROM BSAK INTO TABLE TBSIAK PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR = GJAHR
AND MONAT <= MONAT
AND AUGDT > OGTAG
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND LIFNR IN R_LIFNR.
PERFORM DIFF_K.
ENDSELECT.
SELECT * FROM BSAK INTO TABLE TBSIAK PACKAGE SIZE DBCNT
WHERE BUKRS = BUKRS
AND GJAHR < GJAHR
AND AUGDT > OGTAG
AND BSTAT = SPACE
AND BLART IN R_BLART
AND BELNR IN R_BELNR
AND LIFNR IN R_LIFNR.
PERFORM DIFF_K.
ENDSELECT.
ENDIF.
* Korrektur
CHECK XTEST = SPACE.
LOOP AT CORTAB.
SUBMIT SAPF180C AND RETURN EXPORTING LIST TO MEMORY
WITH S_BUKRS = BUKRS
WITH S_BELNR = CORTAB-BELNR
WITH S_GJAHR = CORTAB-GJAHR
WITH XTEST = SPACE.
ENDLOOP.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM DIFF_D.
SELECT * FROM BFOD_A INTO TABLE TBFOD_A FOR ALL ENTRIES IN TBSIAD
WHERE BUKRS = BUKRS
AND BELNR = TBSIAD-BELNR
AND GJAHR = TBSIAD-GJAHR
AND BUZEI = TBSIAD-BUZEI.
LOOP AT TBSIAD INTO BSID.
CLEAR BLG.
MOVE-CORRESPONDING BSID TO BLG.
PERFORM CHECK_RF048.
CHECK SY-SUBRC <> 0.
LOOP AT TBFOD_A INTO BFOD_A WHERE BELNR = BSID-BELNR
AND GJAHR = BSID-GJAHR
AND BUZEI = BSID-BUZEI.
IF BFOD_A-SHKZG <> BSID-SHKZG.
ADD BFOD_A-DMBTR TO BLG-DMBTR.
ELSE.
SUBTRACT BFOD_A-DMBTR FROM BLG-DMBTR.
ENDIF.
ENDLOOP.
PERFORM COLLECT_DMBTR.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM DIFF_K.
SELECT * FROM BFOK_A INTO TABLE TBFOK_A FOR ALL ENTRIES IN TBSIAK
WHERE BUKRS = BUKRS
AND BELNR = TBSIAK-BELNR
AND GJAHR = TBSIAK-GJAHR
AND BUZEI = TBSIAK-BUZEI.
LOOP AT TBSIAK INTO BSIK.
CLEAR BLG.
MOVE-CORRESPONDING BSIK TO BLG.
PERFORM CHECK_RF048.
CHECK SY-SUBRC <> 0.
LOOP AT TBFOK_A INTO BFOK_A WHERE BELNR = BSIK-BELNR
AND GJAHR = BSIK-GJAHR
AND BUZEI = BSIK-BUZEI.
IF BFOK_A-SHKZG <> BSIK-SHKZG.
ADD BFOK_A-DMBTR TO BLG-DMBTR.
ELSE.
SUBTRACT BFOK_A-DMBTR FROM BLG-DMBTR.
ENDIF.
ENDLOOP.
PERFORM COLLECT_DMBTR.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM CHECK_RF048.
SELECT * FROM RF048 UP TO 1 ROWS WHERE BUKRS = BUKRS
AND BELNR = BLG-BELNR
AND GJAHR = GJAHR
AND XBEARB = SPACE.
ENDSELECT.
ENDFORM.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM COLLECT_DMBTR.
CHECK BLG-DMBTR <> DM0.
IF BLG-SHKZG = 'H'.
MULTIPLY BLG-DMBTR BY -1.
ENDIF.
MOVE-CORRESPONDING BLG TO BTRTAB.
COLLECT BTRTAB.
IF ( BLG-DMBTR >= DMMIN OR BLG-DMBTR <= DMMIM ).
MOVE-CORRESPONDING BLG TO BELTAB.
APPEND BELTAB.
ENDIF.
CHECK XTEST = SPACE.
MOVE-CORRESPONDING BLG TO CORTAB.
COLLECT CORTAB.
ENDFORM.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
AT LINE-SELECTION.
CHECK NOT BELTAB-BELNR IS INITIAL.
SET PARAMETER ID 'BUK' FIELD BUKRS.
SET PARAMETER ID 'BLN' FIELD BELTAB-BELNR.
SET PARAMETER ID 'GJR' FIELD BELTAB-GJAHR.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
*----------------------------------------------------------------------*
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.