SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Check Subsequent BA/PrCtr1



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> FI
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Fri Apr 11, 2008 11:26 pm    Post subject: Check Subsequent BA/PrCtr1 Reply with quote

Code:
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.

* Initialisierung
  DMMIM = -1 * DMMIN.
  SELECT SINGLE * FROM T001 WHERE BUKRS = BUKRS.
  CHECK SY-SUBRC = 0.
  CALL FUNCTION 'PERIOD_DAY_DETERMINE'
       EXPORTING
            I_GJAHR              = GJAHR
            I_MONAT              = MONAT
            I_PERIV              = T001-PERIV
       IMPORTING
            E_LDAY               = OGTAG
       EXCEPTIONS
            OTHERS               = 1.
  CHECK SY-SUBRC = 0.

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

* Ausgabe
  SORT: BTRTAB, BELTAB.
  LOOP AT BTRTAB.
    AT FIRST.
      WRITE: / BUKRS, GJAHR, MONAT.
      SKIP.
      WRITE / TEXT-001.
      SKIP.
      WRITE: /2 TEXT-002,
             15 TEXT-003.
    ENDAT.
    WRITE: /2 BTRTAB-HKONT,
           14 BTRTAB-SHKZG,
           18 BTRTAB-DMBTR.
    AT END OF HKONT.
      SUM.
      WRITE: /2 BTRTAB-HKONT,
             14 BTRTAB-SHKZG,
             18 BTRTAB-DMBTR.
      SKIP.
    ENDAT.
  ENDLOOP.
  NEW-PAGE.
  LOOP AT BELTAB.
    AT FIRST.
      WRITE: / BUKRS, GJAHR, MONAT.
      SKIP.
      WRITE: / TEXT-004, (12) DMMIN, ':'.
      SKIP.
      WRITE: /2 TEXT-002,
             /7 TEXT-005.
    ENDAT.
    AT NEW HKONT.
      WRITE: /2 BELTAB-HKONT.
    ENDAT.
    WRITE: /7 BELTAB-GJAHR, BELTAB-BELNR, BELTAB-BUZEI,
              BELTAB-SHKZG, BELTAB-DMBTR.
    HIDE: BELTAB-BELNR, BELTAB-GJAHR.
  ENDLOOP.

* 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.
*----------------------------------------------------------------------*
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> FI All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.