Auto Disallowed Back Posting to Previous Period

***********************************************************************
* AUTO DISALLOWED BACK POSTING TO PREVIOUS PERIOD
***********************************************************************

REPORT ZBDCMMRV.
TABLES: MARV.

* Batch Input Name
PARAMETERS P-BTCHSN(12)            DEFAULT 'MMRVCHANGE'.
* Company Code
PARAMETERS P-BUKRS LIKE MARV-BUKRS.
* Auto / Manual run the Batch Input Program
PARAMETERS P-RUN   AS CHECKBOX     DEFAULT 'X'.

* INTERNAL TABLE FOR DATA
DATA:  BEGIN OF ULTAB OCCURS 50,
         BUKRS LIKE MARV-BUKRS,   "Company Code
       END OF ULTAB.

* INTERNAL TABLE FOR BATCH INPUT DATA
DATA: BEGIN OF IPUTTAB OCCURS 50.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF IPUTTAB.

* INTERNAL TABLE FOR BATCH INPUT ERROR MESSAGE.
DATA: BEGIN OF MESSTAB OCCURS 50.
        INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF MESSTAB.

DATA: C_TAXKM LIKE MG03STEUER-TAXKM VALUE '1',
      W-LINE-NO TYPE I.

REFRESH ULTAB.
SELECT * FROM MARV WHERE BUKRS = P-BUKRS.
     ULTAB-BUKRS = MARV-BUKRS.
     APPEND ULTAB.

ENDSELECT.

* CHECK WHETHER TABLE IS EMPTY
IF ULTAB[] is initial.
   WRITE: / 'TABLE EMPTY'.
ENDIF.

* Create Batch session
  PERFORM CRE-BATCH-SESS.

** LOOP TABLE TO CREATE SCREEN INPUT
SORT.
LOOP AT ULTAB.
  REFRESH IPUTTAB.
  PERFORM SCREEN1.
  PERFORM SCREEN2.
  PERFORM PRN_ULTAB.
  PERFORM CLOSE-SESS.
ENDLOOP.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

* END OF MAIN PROGRAM

FORM SCREEN1.
* SCREEN #1: INITAL SCREEN FOR MAINTAINING SOURCE LIST
  CLEAR IPUTTAB.
  IPUTTAB-PROGRAM = 'SAPMM03Y'.
  IPUTTAB-DYNPRO  =  '100'.
  IPUTTAB-DYNBEGIN = 'X'.
  APPEND IPUTTAB.

* MMRV ENQUIRY BY COMPANY CODE
  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'MARV-BUKRS'.
  IPUTTAB-FVAL =  ULTAB-BUKRS.
  APPEND IPUTTAB.

ENDFORM.
***********************************************************************
* FORM        : SCREEN1                                               *
***********************************************************************
FORM SCREEN2.
* MODIFY SCREEN IN MMRV
  CLEAR IPUTTAB.
  IPUTTAB-PROGRAM = 'SAPMM03Y'.
  IPUTTAB-DYNPRO  =  '110'.
  IPUTTAB-DYNBEGIN = 'X'.
  APPEND IPUTTAB.

* UNTICK ALLOWED POSTING TO PREVIOUS PERIOD
  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'MARV-XRUEM'.
  IPUTTAB-FVAL = ' '.
  APPEND IPUTTAB.

* DISALLOWED BACKPOSTING GENERALLY
  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'MARV-XRUEV'.
  IPUTTAB-FVAL = 'X'.
  APPEND IPUTTAB.

* Specify that we are now done with this screen (Save it with F11)
  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'BDC_OKCODE'.
  IPUTTAB-FVAL = '/11'.
  APPEND IPUTTAB.
ENDFORM.

***********************************************************************
* FORM        : CLOSE-SESS                                            *
* DESCRIPTION : CLOSE THE SESSION                                     *
***********************************************************************
FORM CLOSE-SESS.
* closing the session.
IF P-RUN = 'X'.
* Auto run the Batch Input Program
 CALL TRANSACTION 'MMRV'
          USING  IPUTTAB
          MODE   'E'
          UPDATE 'S'
          MESSAGES INTO MESSTAB.
ELSE.
* Maual run the Batch Input Program
 CALL FUNCTION 'BDC_INSERT'
       EXPORTING
            TCODE     = 'MMRV'
       TABLES
            DYNPROTAB = IPUTTAB.
ENDIF.

ENDFORM.

***********************************************************************
* FORM        : PRN-ULTAB                                             *
* DESCRIPTION : PRINT OK TABLE                                        *
***********************************************************************
FORM PRN_ULTAB.
  WRITE: / ULTAB-BUKRS.
  W-LINE-NO = W-LINE-NO + 1.
WRITE: '      RECORD# ', W-LINE-NO.
ENDFORM.

***********************************************************************
* FORM        : CRE-BATCH-SESS                                        *
* DESCRIPTION : CREATE BATCH SESSION                                  *
***********************************************************************
FORM CRE-BATCH-SESS.
** Create BTCI session **
CALL FUNCTION 'BDC_OPEN_GROUP'
     EXPORTING
          CLIENT = SY-MANDT
          GROUP  = P-BTCHSN
          USER   = SY-UNAME
          KEEP   = 'X'.
ENDFORM.

Questions
Do you have a ABAP Question?

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.