Posted: Wed Aug 20, 2008 9:40 am Post subject: Check / Change Accounting Period for Goods Movement
Code:
* Source Name is ZCHKPER
REPORT ZCHKPER.
* Author: Joe Mason - SAP Chicago
* Purpose: Check if Accounting Period (Period & Year) has Changed
* If CHANGED:
* -SUBMIT Function - to change Period in SAP Tables
* -Update Control Variables in Table TVARV
* Assumptions: - Company Codes are HARD Coded in Program
* (as Companies are ADDED/DELETED - this Program
* must Change)
* - CLOSING PERIODS are the SAME for ALL Companies
*
*
TABLES: TVARV, MARD, T001.
DATA: FISCAL_YEAR LIKE BAPI0002_4-FISCAL_YEAR.
DATA: FISCAL_PERIOD LIKE BAPI0002_4-FISCAL_PERIOD.
DATA: RETURN LIKE BAPIRETURN1.
DATA: CURRENT-PERIOD LIKE TVARV.
DATA: CURRENT-YEAR LIKE TVARV.
DATA: PREV-PERIOD LIKE TVARV.
DATA: PREV-YEAR LIKE TVARV.
PARAMETERS: PROCDATE LIKE SY-DATUM DEFAULT SY-DATUM OBLIGATORY.
* SELECTION TEXT *E* 'Processing Date'
PARAMETERS: PLUSONE AS CHECKBOX.
* SELECTION TEXT *E* 'Use Processing Date + 1'
DATA: FROMCOMPANY LIKE T001-BUKRS VALUE '1000'. "ABBOTT Specific
DATA: TOCOMPANY LIKE T001-BUKRS VALUE '1001'. "ABBOTT Specific
DATA: BEGIN OF TAB OCCURS 500,
BUKRS LIKE T001-BUKRS,
YEAR LIKE FISCAL_YEAR,
PERIOD LIKE FISCAL_PERIOD,
END OF TAB.
IF NOT PLUSONE IS INITIAL.
PROCDATE = PROCDATE + 1.
ENDIF.
SELECT * FROM T001.
* Validate that HARD Coded Company Codes are VALID
IF T001-BUKRS GE FROMCOMPANY
AND T001-BUKRS LE TOCOMPANY.
CLEAR TAB.
MOVE T001-BUKRS TO TAB-BUKRS.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* Determine Fiscal Year & Period BY Company
EXPORTING
COMPANYCODEID = TAB-BUKRS
POSTING_DATE = PROCDATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
RETURN = RETURN
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC NE 0.
MESSAGE A450(ZABBOTT) WITH 'Could NOT Determine PERIOD for Company'
TAB-BUKRS.
ENDIF.
MOVE FISCAL_YEAR TO TAB-YEAR.
MOVE FISCAL_PERIOD TO TAB-PERIOD.
APPEND TAB.
ENDIF.
ENDSELECT.
IF FISCAL_YEAR IS INITIAL
OR FISCAL_PERIOD IS INITIAL.
MESSAGE A450(ZABBOTT) WITH
'Could NOT Determine PERIOD for any Company'.
ENDIF.
LOOP AT TAB.
IF TAB-YEAR NE FISCAL_YEAR
OR TAB-PERIOD NE FISCAL_PERIOD.
MESSAGE I450(ZABBOTT) WITH
'Fiscal Year or Periods varies by Company'.
MESSAGE I450(ZABBOTT) WITH
'Cannot Use This Program'.
MESSAGE A450(ZABBOTT) WITH
'Must Manually Close PERIODs using Transaction MMPV'.
ENDIF.
ENDLOOP.
SELECT SINGLE FOR UPDATE * FROM TVARV
* Initially SET - CURRENT-PERIOD Parameter Value
WHERE NAME EQ 'CURRENT-PERIOD'
AND TYPE EQ 'P'
AND NUMB EQ '0000'.
IF SY-SUBRC NE 0.
CLEAR TVARV.
MOVE 'CURRENT-PERIOD' TO TVARV-NAME.
MOVE 'P' TO TVARV-TYPE.
MOVE '0000' TO TVARV-NUMB.
MOVE FISCAL_PERIOD TO TVARV-LOW.
INSERT TVARV.
ENDIF.
MOVE TVARV TO CURRENT-PERIOD.
MOVE TVARV TO PREV-PERIOD.
COMMIT WORK.
SELECT SINGLE FOR UPDATE * FROM TVARV
* Initially SET - CURRENT-YEAR Parameter Value
WHERE NAME EQ 'CURRENT-YEAR'
AND TYPE EQ 'P'
AND NUMB EQ '0000'.
IF SY-SUBRC NE 0.
CLEAR TVARV.
MOVE 'CURRENT-YEAR' TO TVARV-NAME.
MOVE 'P' TO TVARV-TYPE.
MOVE '0000' TO TVARV-NUMB.
MOVE FISCAL_YEAR TO TVARV-LOW.
INSERT TVARV.
ENDIF.
MOVE TVARV TO CURRENT-YEAR.
MOVE TVARV TO PREV-YEAR.
COMMIT WORK.
IF FISCAL_PERIOD NE CURRENT-PERIOD-LOW
* Determine IF in a New Period
OR FISCAL_YEAR NE CURRENT-YEAR-LOW.
PERFORM DO-CHANGES.
ELSE.
MESSAGE I450(ZABBOTT) WITH 'NOT TIME to Change Period'.
ENDIF.
*---------------------------------------------------------------------*
* FORM DO-CHANGES *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM DO-CHANGES.
* SUBMIT Routine to Change Accounting Dates in Material Record
SUBMIT RMMMPERI
WITH I_BBUKR = TOCOMPANY "To Company Code
* with i_datum = ' ' "Date
WITH I_LFGJA = FISCAL_YEAR "Fiscal Year
WITH I_LFMON = FISCAL_PERIOD "Period
WITH I_VBUKR = FROMCOMPANY "From Company Code
WITH I_XCOMP = 'X' "Check & Close Period
WITH I_XINCO = ' ' "Check Period Only
WITH I_XMOVE = ' ' "Close Period Only
WITH I_XNEGQ = 'X' "Allow NEG QTY Prev Period
WITH I_XNEGV = 'X' "Allow NEG VALS Prev Period
AND RETURN.
* Determine IF Routine Updated Material Records
SELECT * FROM MARD.
EXIT. "Get One Record
ENDSELECT.
IF SY-SUBRC NE 0
OR MARD-LFMON NE FISCAL_PERIOD
OR MARD-LFGJA NE FISCAL_YEAR.
MESSAGE A450(ZABBOTT) WITH 'PERIOD NOT CHANGED in Material Records'.
ENDIF.
* Set UP New Field Values
MOVE FISCAL_PERIOD TO CURRENT-PERIOD-LOW.
MOVE FISCAL_YEAR TO CURRENT-YEAR-LOW.
MOVE 'PREVIOUS-PERIOD' TO PREV-PERIOD-NAME.
MOVE 'PREVIOUS-YEAR' TO PREV-YEAR-NAME.
* Update New Field Values in Table TVARV
PERFORM UPDATE-TVARV USING PREV-YEAR.
PERFORM UPDATE-TVARV USING PREV-PERIOD.
PERFORM UPDATE-TVARV USING CURRENT-PERIOD.
PERFORM UPDATE-TVARV USING CURRENT-YEAR.
COMMIT WORK.
ENDFORM.
*---------------------------------------------------------------------*
* FORM UPDATE-TVARV *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> TEMP-TVARV *
*---------------------------------------------------------------------*
FORM UPDATE-TVARV USING TEMP-TVARV STRUCTURE TVARV.
* General Purpose Update Routine for Table TVARV
SELECT SINGLE FOR UPDATE * FROM TVARV
WHERE NAME EQ TEMP-TVARV-NAME
AND TYPE EQ TEMP-TVARV-TYPE
AND NUMB EQ TEMP-TVARV-NUMB.
MOVE TEMP-TVARV TO TVARV.
IF SY-SUBRC NE 0.
INSERT TVARV.
ELSE.
MODIFY TVARV.
ENDIF.
ENDFORM.
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.