Skip to Content
Author's profile photo Former Member

Mass Production Version Creation

Basically this is Mass utility Z program to create Production version for given Material,Plant,BOM, and Routing information. 


A production version determines which alternative BOM is used together with which task list/master recipe to produce a material or create a master production schedule.

For one material, you can have several production versions for various validity periods and lot-size ranges.

Production versions are used both in discrete manufacturing and process manufacturing.

Production versions are used in Sales and Operations Planning (SOP), material requirements planning (MRP), process order creation, and product costing to select the most suitable task list or recipe and the corresponding material list.

You can also select a recipe and BOM without a production version. Note, however, that if you do so, material quantity calculation data is not copied.


Purpose :


Purpose of this program is to create production version from available alternate BOM and Routing combination. This program will be used for both Initial upload and further ongoing activities of production version. The Production version will be created for all FERT, HALB and ROH material. Program will use BDC methodology to create production version. Both BDC methods i.e. Session and Call Transaction options are available.


Pre-requisite :


BOM and Routings should be available in the system for the given Material & Plant combination.


Selection Parameter :

product1.JPG

Details :


Depending upon the selection criteria , program will create production versions. In program a Simulation mode and Update mode is provided.

User can check first in simulation mode the entries of production version which will be created and the update it through Update mode.

Also user have option to check for the Valid Production versions and Invalid production version to be created in Simulation Mode.

Criteria to decide for Valid or Invalid production version is that, program is checking for the available routings  and Material to BOM Link in Table MAPL and MAST respectively.


Output of Valid Production Version :

valid.JPG


Output of Invalid Production Version :

invalid.JPG

Output of actual Production Version created :

actual.JPG

List of the production version which are created in the system are shown in the ALV output with its Task list no, task list type ,Alternative BOM , Group counter etc.

Please find attached code of this program with this document.

Thanks.

Regrds,

Suniel Kulkarni.

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mark Lail
      Mark Lail

      Do you mind sharing the programs ZUTRPTLG and ZUTIN002?

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hello Mark,

      Thanks for showing interest in my program.

      Both the includes ZUTRPLTG and ZUTIN002 are used for the purpose to log the report execution. You can comment out these programs and use my code.

      Please let me know, if you require more info.

      Regards,

      Suniel K

      Author's profile photo Former Member
      Former Member

      Hi Sunil,
      where can I find your interesting programs?
      Regards
      Jorge

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Jorge,

      Thanks for showing interest in my program.
      Due to SAP SCN community web portal updation, my attachments are gone, so you will not be able to access the same. I will raise the query to SCN community for the same.

      Till time you can refer to the program code which i have added below.
      Please let me know if you need further assistance.

      Regards,
      Suniel K

      *&---------------------------------------------------------------------*
      *& Report  ZUTPP609
      *&
      *&---------------------------------------------------------------------*
      *&
      *&
      *&---------------------------------------------------------------------*
      
      REPORT ZUTPP609
             LINE-SIZE 200
             LINE-COUNT 200
             MESSAGE-ID ZZ
             NO STANDARD PAGE HEADING.
      ***********************************************************************
      * Program: Production Version Creation Utility Program                *
      *                                                                     *
      * Description: Basically this is Mass upload utility program to create*
      *              Production version for given Material,Plant,BOM, and   *
      *              Routing information.                                   *
      ***********************************************************************
      
      ***********************************************************************
      * T A B L E   D E C L A R A T I O N S                                 *
      ***********************************************************************
      TABLES : MAST,MAPL,MKAL,STKO,MARA,MARC.
      ***********************************************************************
      * D A T A   D E C L A R A T I O N S                                   *
      ***********************************************************************
      
      TYPE-POOLS: SLIS,TRUXS.
      
      DATA:EXIT.
      DATA: FCT TYPE SLIS_FIELDCAT_ALV,
            IT_FCT TYPE SLIS_T_FIELDCAT_ALV,
            LOUT TYPE SLIS_LAYOUT_ALV,
            HEAD TYPE SLIS_LISTHEADER,
            IT_HEAD TYPE SLIS_T_LISTHEADER.
      *** MATERIAL TO BOM LINK DATA
      TYPES: BEGIN OF TY_MAST,
              MATNR TYPE MAST-MATNR,
              WERKS TYPE MAST-WERKS,
              STLAN TYPE MAST-STLAN,
              STLNR TYPE MAST-STLNR,
              STLAL TYPE MAST-STLAL,
              LOSVN TYPE MAST-LOSVN,
              LOSBS TYPE MAST-LOSBS,
              ANDAT TYPE MAST-ANDAT,
            END OF TY_MAST.
      DATA : GT_MAST TYPE TABLE OF TY_MAST,
             GS_MAST LIKE LINE OF GT_MAST.
      *** ROUTING DATA
      TYPES: BEGIN OF TY_MAPL,
              MATNR TYPE MAPL-MATNR,
              WERKS TYPE MAPL-WERKS,
              PLNTY TYPE MAPL-PLNTY,
              PLNNR TYPE MAPL-PLNNR,
              PLNAL TYPE MAPL-PLNAL,
              ZKRIZ TYPE MAPL-ZKRIZ,
              ZAEHL TYPE MAPL-ZAEHL,
              DATUV TYPE MAPL-DATUV,
              LOEKZ TYPE MAPL-LOEKZ,
              ANDAT TYPE MAPL-ANDAT,
            END OF TY_MAPL.
      DATA : GT_MAPL TYPE TABLE OF TY_MAPL,
             GS_MAPL LIKE LINE OF GT_MAPL.
      *** BOM HEADER DATA
      TYPES: BEGIN OF TY_STKO,
              STLTY TYPE STKO-STLTY,
              STLNR TYPE STKO-STLNR,
              STLAL TYPE STKO-STLAL,
              STKOZ TYPE STKO-STKOZ,
              DATUV TYPE STKO-DATUV,
              LOEKZ TYPE STKO-LOEKZ,
              ANDAT TYPE STKO-ANDAT,
              STLST TYPE STKO-STLST,
            END OF TY_STKO.
      DATA : GT_STKO TYPE TABLE OF TY_STKO,
             GS_STKO LIKE LINE OF GT_STKO.
      TYPES: BEGIN OF TY_MARA,
              MATNR TYPE MARA-MATNR,
              SPART TYPE MARA-SPART,
             END OF TY_MARA.
      DATA : GT_MARA TYPE TABLE OF TY_MARA,
             GS_MARA LIKE LINE OF GT_MARA.
      TYPES: BEGIN OF TY_MARC,
              MATNR TYPE MARA-MATNR,
              WERKS TYPE MARC-WERKS,
              DISPO TYPE MARC-DISPO,
             END OF TY_MARC.
      DATA : GT_MARC TYPE TABLE OF TY_MARC,
             GS_MARC LIKE LINE OF GT_MARC.
      TYPES: BEGIN OF TY_MAKL,
              MATNR TYPE MKAL-MATNR,                     "material
              WERKS TYPE MKAL-WERKS,                     "plant
              VERID TYPE MKAL-VERID,                     "production version
              BDATU TYPE MKAL-BDATU,                     "valid from
              ADATU TYPE MKAL-ADATU,                     "valid to
              STLAL TYPE MKAL-STLAL,                     "Alternative bom
              STLAN TYPE MKAL-STLAN,                     "bom usage
              PLNTY TYPE MKAL-PLNTY,                     "task type
              PLNNR TYPE MKAL-PLNNR,                     "task list
              PLNAL TYPE MAPL-PLNAL,                     "group counter
              BSTMI TYPE MKAL-BSTMI,                     "lot size from
              BSTMA TYPE MKAL-BSTMA,                     "lot size to
              ALORT TYPE MKAL-ALORT,                     "receiving storage location   
              PRFG_F(10) TYPE C,                         "status
              TEXT1 TYPE MKAL-TEXT1,                     "text
              ICON(4)  TYPE C,                           "signal symbol
            END OF TY_MAKL.
      DATA : GT_MAKL TYPE TABLE OF TY_MAKL,
             GS_MAKL LIKE LINE OF GT_MAKL,
             GT_STATUS TYPE TABLE OF TY_MAKL,
             GS_STATUS LIKE LINE OF GT_STATUS.
      
      TYPES: BEGIN OF TY_FINAL,
              MATNR TYPE MAPL-MATNR,
              WERKS TYPE MAPL-WERKS,
              PLNTY TYPE MAPL-PLNTY,
              PLNNR TYPE MAPL-PLNNR,
              BDATU TYPE MKAL-BDATU,
              ADATU TYPE MKAL-ADATU,
              STLAL TYPE MKAL-STLAL,
              STLAN TYPE MKAL-STLAN,
              BSTMI TYPE MKAL-BSTMI,
              BSTMA TYPE MKAL-BSTMA,
              TEXT1 TYPE MKAL-TEXT1,
              PLNAL TYPE MAPL-PLNAL,
              VERID TYPE MKAL-VERID,
             END OF TY_FINAL.
      DATA : GT_FINAL TYPE TABLE OF TY_FINAL,
             GT_FINAL1 TYPE TABLE OF TY_FINAL,
             GS_FINAL LIKE LINE OF GT_FINAL.
      *DATA : BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
      INCLUDE BDCRECXY.
      DATA : P_MODE TYPE  CTU_PARAMS-DISMODE,
             LV_HEAD TYPE C.
      
      ***********************************************************************
      * S E L E C T - O P T I O N S / P A R A M E T E R S                   *
      ***********************************************************************
      SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
      PARAMETERS : P_TEST RADIOBUTTON GROUP R1 USER-COMMAND USR DEFAULT 'X',
                   P_UPDAT RADIOBUTTON GROUP R1.
      
      SELECTION-SCREEN END OF BLOCK B1.
      
      SELECTION-SCREEN BEGIN OF BLOCK B4 WITH FRAME TITLE TEXT-004.
      PARAMETERS : P_TRANS RADIOBUTTON GROUP R3 MODIF ID MD1 USER-COMMAND USR1 DEFAULT 'X',
                   P_SIM RADIOBUTTON GROUP R3 MODIF ID MD1,
      *             P_SIMRUN RADIOBUTTON GROUP R3 MODIF ID MD1,
                   P_MAP   TYPE APQI-GROUPID MODIF ID MD1 DEFAULT 'C223_VERS_UT'.
      SELECTION-SCREEN END OF BLOCK B4.
      
      SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.
      PARAMETERS : P_VALID RADIOBUTTON GROUP R2 MODIF ID MD2,
                   P_INVALD RADIOBUTTON GROUP R2 MODIF ID MD2.
      SELECTION-SCREEN END OF BLOCK B3.
      
      SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
      SELECT-OPTIONS : S_MATNR FOR MAST-MATNR,
                       S_WERKS FOR MAST-WERKS,
                       S_STLAL FOR STKO-STLAL,
                       S_PLNNR FOR MAPL-PLNNR,
                       S_ANDAT FOR STKO-ANDAT OBLIGATORY,
                       S_RODAT FOR MAPL-ANDAT OBLIGATORY,
                       S_ANNAM FOR MAPL-ANNAM,
                       S_DISPO FOR MARC-DISPO,
                       S_SPART FOR MARA-SPART.                     
      PARAMETER : C1 AS CHECKBOX,
                  P_ALORT TYPE MKAL-ALORT.
      
      SELECTION-SCREEN END OF BLOCK B2.
      
      AT SELECTION-SCREEN OUTPUT.
      
        LOOP AT SCREEN.
          IF P_TEST = 'X' AND SCREEN-GROUP1 = 'MD1'.
            SCREEN-ACTIVE = '0'.
            MODIFY SCREEN.
            CONTINUE.
      *    ELSEIF P_UPDAT = 'X' AND SCREEN-GROUP1 = 'MD2'.
      *      SCREEN-ACTIVE = '0'.
      *      MODIFY SCREEN.
      *      CONTINUE.
          ENDIF.
        ENDLOOP.
      
        IF P_TRANS = 'X'." AND SCREEN-GROUP1 = 'MD1'.
          LOOP AT SCREEN.
            IF SCREEN-NAME = 'P_MAP' OR SCREEN-NAME = '%_P_MAP_%_APP_%-TEXT'.
              SCREEN-ACTIVE = 0.
              SCREEN-INVISIBLE = 1.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ELSE.
          LOOP AT SCREEN.
            IF SCREEN-NAME = 'P_MAP'.
              SCREEN-INPUT = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
      
      
      ***********************************************************************
      * I N I T I A L I Z A T I O N                                         *
      ***********************************************************************
      INITIALIZATION.
        P_MODE = 'A'.
      ***********************************************************************
      * S T A R T - O F - S E L E C T I O N                                 *
      ***********************************************************************
      START-OF-SELECTION.
        IF P_UPDAT = 'X' AND P_INVALD = 'X'.
          MESSAGE S208(00) WITH 'select valid prod.vers option to update' DISPLAY LIKE 'E'.
          STOP.
        ENDIF.
        IF C1 = 'X' AND P_ALORT = ' '.
          MESSAGE S208(00) WITH 'Please input receiving storage location' DISPLAY LIKE 'E'.
          STOP.
        ENDIF.
        PERFORM GET_DATA_INPUT.                   " GET PRODUCTION VERSION DETAILS.
        PERFORM FINAL_DATA.                       " DATA PROCESSING FOR BDC
        IF P_TEST = 'X'.
          PERFORM REPORT.                         " GENERATE REPORT.
        ELSE.
          IF P_TRANS = 'X'.
            PERFORM START_BDC.                      " START BDC USING CALL TRANSACTION
          ELSE.
            PERFORM START_SESSION_BDC.            " START BDC USING CALL SESSION
          ENDIF.
          PERFORM STATUS_REPORT.                  " status after succesfull creation of production version
        ENDIF.
      
      
      
      ***********************************************************************
      * F O R M S                                                           *
      ***********************************************************************
      *&---------------------------------------------------------------------*
      *&      Form  GET_DATA_INPUT
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM GET_DATA_INPUT .
      
        IF S_MATNR[] IS NOT INITIAL.                                                           " Material given in input selection.
      
          SELECT MATNR SPART FROM MARA INTO TABLE GT_MARA
                 WHERE MATNR IN S_MATNR
      *           AND   SPART = P_SPART.                                                       
                 AND   SPART IN S_SPART.                                                      
          IF GT_MARA[] IS NOT INITIAL.
            IF S_DISPO[] IS INITIAL.                                                           " MRP controller is not given in selection.
              SELECT MATNR WERKS STLAN STLNR STLAL LOSVN LOSBS ANDAT FROM MAST                 " get material to BOM link
                     INTO TABLE GT_MAST FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   ANDAT IN S_ANDAT
                     AND   STLAL IN S_STLAL
                     AND   ANNAM IN S_ANNAM.
              SELECT MATNR WERKS PLNTY PLNNR PLNAL ZKRIZ ZAEHL DATUV LOEKZ ANDAT FROM MAPL     " Get Task list
                     INTO TABLE GT_MAPL FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   ANDAT IN S_RODAT
                     AND   PLNNR IN S_PLNNR
                     AND   LOEKZ = ' '
                     AND   PLNTY = 'N'
                     AND   ANNAM IN S_ANNAM.
            ELSE.                                                                              " MRP controller is in input selection.
              SELECT MATNR WERKS DISPO FROM MARC INTO TABLE GT_MARC
                     FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   DISPO IN S_DISPO.
              IF GT_MARC[] IS NOT INITIAL.
                SELECT MATNR WERKS STLAN STLNR STLAL LOSVN LOSBS ANDAT FROM MAST               " Get material to BOM link
                       INTO TABLE GT_MAST FOR ALL ENTRIES IN GT_MARC
                       WHERE MATNR = GT_MARC-MATNR
                       AND   WERKS = GT_MARC-WERKS
                       AND   STLAL IN S_STLAL
                       AND   ANDAT IN S_ANDAT
                       AND   ANNAM IN S_ANNAM.
                SELECT MATNR WERKS PLNTY PLNNR PLNAL ZKRIZ ZAEHL DATUV LOEKZ ANDAT FROM MAPL   " Get Task list
                       INTO TABLE GT_MAPL FOR ALL ENTRIES IN GT_MARC
                       WHERE MATNR = GT_MARC-MATNR
                       AND   WERKS = GT_MARC-WERKS
                       AND   PLNNR IN S_PLNNR
                       AND   ANDAT IN S_RODAT
                       AND   LOEKZ = ' '
                       AND   PLNTY = 'N'
                       AND   ANNAM IN S_ANNAM.
              ENDIF.
            ENDIF.
          ENDIF.
      
        ELSE.                                                                                  " Material not given in input selection
      
          IF S_DISPO[] IS NOT INITIAL.                                                         " MRP controller is in input selection.
            SELECT MATNR WERKS DISPO FROM MARC INTO TABLE GT_MARC
                   WHERE MATNR IN S_MATNR
                   AND   WERKS IN S_WERKS
                   AND   DISPO IN S_DISPO.
            IF GT_MARC[] IS NOT INITIAL.
              SELECT MATNR SPART FROM MARA INTO TABLE GT_MARA
                     FOR ALL ENTRIES IN GT_MARC
                     WHERE MATNR = GT_MARC-MATNR
      *               AND   SPART = P_SPART.                                                   
                     AND   SPART IN S_SPART.                                                  
            ENDIF.
            IF GT_MARA[] IS NOT INITIAL.
              SELECT MATNR WERKS STLAN STLNR STLAL LOSVN LOSBS ANDAT FROM MAST                  " get material to BOM link
                     INTO TABLE GT_MAST FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   ANDAT IN S_ANDAT
                     AND   STLAL IN S_STLAL
                     AND   ANNAM IN S_ANNAM.
              SELECT MATNR WERKS PLNTY PLNNR PLNAL ZKRIZ ZAEHL DATUV LOEKZ ANDAT FROM MAPL      " Get Task list
                     INTO TABLE GT_MAPL FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   ANDAT IN S_RODAT
                     AND   PLNNR IN S_PLNNR
                     AND   LOEKZ = ' '
                     AND   PLNTY = 'N'
                     AND   ANNAM IN S_ANNAM.
            ENDIF.
          ELSE.                                                                                 " MRP controller is not given in selection.
            SELECT MATNR SPART FROM MARA INTO TABLE GT_MARA
                   WHERE MATNR IN S_MATNR
      *             AND   SPART = P_SPART.                                                    
                   AND   SPART IN S_SPART.                                                     
            IF GT_MARA[] IS NOT INITIAL.
              SELECT MATNR WERKS STLAN STLNR STLAL LOSVN LOSBS ANDAT FROM MAST                  " get material to BOM link
                     INTO TABLE GT_MAST FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   ANDAT IN S_ANDAT
                     AND   STLAL IN S_STLAL
                     AND   ANNAM IN S_ANNAM.
              SELECT MATNR WERKS PLNTY PLNNR PLNAL ZKRIZ ZAEHL DATUV LOEKZ ANDAT FROM MAPL      " Get Task list
                     INTO TABLE GT_MAPL FOR ALL ENTRIES IN GT_MARA
                     WHERE MATNR = GT_MARA-MATNR
                     AND   WERKS IN S_WERKS
                     AND   ANDAT IN S_RODAT
                     AND   PLNNR IN S_PLNNR
                     AND   LOEKZ = ' '
                     AND   PLNTY = 'N'
                     AND   ANNAM IN S_ANNAM.
            ENDIF.
          ENDIF.
        ENDIF.
      
        IF GT_MAST[] IS NOT INITIAL.
          SELECT STLTY STLNR STLAL STKOZ DATUV LOEKZ ANDAT STLST FROM STKO
                 INTO TABLE GT_STKO FOR ALL ENTRIES IN GT_MAST
                 WHERE STLNR = GT_MAST-STLNR
                 AND   STLAL = GT_MAST-STLAL
                 AND   LOEKZ = ' '.
        ENDIF.
      
        IF GT_MARA[] IS NOT INITIAL.
      
          SELECT MATNR WERKS VERID BDATU ADATU STLAL STLAN PLNTY PLNNR ALNAL BSTMI BSTMA FROM MKAL
                 INTO TABLE GT_MAKL FOR ALL ENTRIES IN GT_MARA
                 WHERE MATNR = GT_MARA-MATNR
                 AND   WERKS IN S_WERKS
                 AND   STLAL IN S_STLAL
                 AND   PLNNR IN S_PLNNR.
        ENDIF.
      
      ENDFORM.                    " GET_DATA_INPUT
      *&---------------------------------------------------------------------*
      *&      Form  FINAL_DATA
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM FINAL_DATA .
        DATA : COUNT(4) TYPE N.
        SORT GT_MAKL ASCENDING BY MATNR WERKS STLAL PLNNR.
        SORT GT_MAST ASCENDING BY MATNR WERKS STLNR STLAL.
        SORT GT_MAPL ASCENDING BY MATNR WERKS PLNNR.
      
        LOOP AT GT_MAST INTO GS_MAST.
          READ TABLE GT_STKO INTO GS_STKO
          WITH KEY STLNR = GS_MAST-STLNR
                   STLAL = GS_MAST-STLAL.
      
          IF SY-SUBRC = 0.
            IF GS_STKO-DATUV <=  SY-DATUM.                " BOM SHOULD BE VALID FROM CURRENT DATE ONLY
              READ TABLE GT_MAKL INTO GS_MAKL
              WITH KEY MATNR = GS_MAST-MATNR
                       WERKS = GS_MAST-WERKS
                       STLAL = GS_MAST-STLAL.
              IF SY-SUBRC = 0.                           " BOM ALREADY USED.
      *          COUNT = GS_MAKL-VERID.                           
      *          AT END OF MATNR.
      *            AT END OF WERKS.
      *              CLEAR : COUNT.
      *            ENDAT.
      *          ENDAT.
                CONTINUE.
              ELSE.
                GS_FINAL-MATNR = GS_MAST-MATNR.
                GS_FINAL-WERKS = GS_MAST-WERKS.
      *          IF COUNT IS INITIAL.
      *            COUNT = '0001'.
      *          ELSE.
      *            COUNT = COUNT + 0001.
      *          ENDIF.
      
                GS_FINAL-BSTMI = '1'.                      "lot size from
                GS_FINAL-BSTMA = '999999'.                 "lot size to
                GS_FINAL-ADATU = SY-DATUM.                 "valid from production version
                GS_FINAL-BDATU = '99991231'.             "valid to production version
      
                GS_FINAL-VERID = GS_STKO-STLAL. "COUNT.                    "version counter
                GS_FINAL-STLAL = GS_STKO-STLAL.            "alternative bom
                GS_FINAL-STLAN = GS_MAST-STLAN.            "bom usage
                CONCATENATE 'Production Version' GS_STKO-STLAL INTO GS_FINAL-TEXT1 SEPARATED BY SPACE.
      
                READ TABLE GT_MAPL INTO GS_MAPL
                WITH KEY MATNR = GS_MAST-MATNR
                         WERKS = GS_MAST-WERKS.
                IF SY-SUBRC = 0.
                  GS_FINAL-PLNNR = GS_MAPL-PLNNR.         " routing
                  GS_FINAL-PLNTY = GS_MAPL-PLNTY.         " task list type
                  GS_FINAL-PLNAL = GS_MAPL-PLNAL.         " group counter
                  IF P_VALID = 'X'.
                    APPEND GS_FINAL TO GT_FINAL.
                    CLEAR :GS_FINAL.
                  ENDIF.
                ELSE.
                  IF P_INVALD = 'X'.
                    APPEND GS_FINAL TO GT_FINAL1.
                    CLEAR: GS_FINAL.
                  ENDIF.
                ENDIF.
      *          IF P_VALID = 'X'.
      *          APPEND GS_FINAL TO GT_FINAL.
      *          CLEAR :GS_FINAL.
      *          ENDIF.
                CLEAR :GS_FINAL.
              ENDIF.
      *        AT END OF MATNR.
      *          AT END OF WERKS.
      *            CLEAR : COUNT.
      *          ENDAT.
      *        ENDAT.
            ENDIF.
          ENDIF.
        ENDLOOP.
      
        IF SY-SUBRC <> 0.
          LOOP AT GT_MAPL INTO GS_MAPL.
      
            GS_FINAL-PLNNR = GS_MAPL-PLNNR.         " routing
            GS_FINAL-PLNTY = GS_MAPL-PLNTY.         " task list type
            GS_FINAL-PLNAL = GS_MAPL-PLNAL.         " group counter
            READ TABLE GT_MAST INTO GS_MAST
            WITH KEY MATNR = GS_MAPL-MATNR
                     WERKS = GS_MAPL-WERKS.
            IF SY-SUBRC = 0.
              READ TABLE GT_STKO INTO GS_STKO
                 WITH KEY STLNR = GS_MAST-STLNR
                          STLAL = GS_MAST-STLAL.
              IF SY-SUBRC = 0.
                IF GS_STKO-DATUV <=  SY-DATUM.                " BOM SHOULD BE VALID FROM CURRENT DATE ONLY
                  READ TABLE GT_MAKL INTO GS_MAKL
                  WITH KEY MATNR = GS_MAST-MATNR
                           WERKS = GS_MAST-WERKS
                           STLAL = GS_MAST-STLAL.
                  IF SY-SUBRC = 0.                           " BOM ALREADY USED.
                    CONTINUE.
                  ELSE.
                    GS_FINAL-MATNR = GS_MAST-MATNR.
                    GS_FINAL-WERKS = GS_MAST-WERKS.
                    GS_FINAL-BSTMI = '1'.                      "lot size from
                    GS_FINAL-BSTMA = '999999'.                 "lot size to
                    GS_FINAL-ADATU = SY-DATUM.                 "valid from production version
                    GS_FINAL-BDATU = '99991231'.             "valid to production version
                    GS_FINAL-VERID = GS_STKO-STLAL. "COUNT.                    "version counter
                    GS_FINAL-STLAL = GS_STKO-STLAL.            "alternative bom
                    GS_FINAL-STLAN = GS_MAST-STLAN.            "bom usage
                    CONCATENATE 'Production Version' GS_STKO-STLAL INTO GS_FINAL-TEXT1 SEPARATED BY SPACE.
                    IF P_VALID = 'X'.
                      APPEND GS_FINAL TO GT_FINAL.
                      CLEAR :GS_FINAL.
                    ENDIF.
                  ENDIF.
                ENDIF.
              ENDIF.
            ELSE.
              IF P_INVALD = 'X'.
                GS_FINAL-MATNR = GS_MAPL-MATNR.
                GS_FINAL-WERKS = GS_MAPL-WERKS.
                GS_FINAL-BSTMI = '1'.                      "lot size from
                GS_FINAL-BSTMA = '999999'.                 "lot size to
                GS_FINAL-ADATU = SY-DATUM.                 "valid from production version
                GS_FINAL-BDATU = '99991231'.             "valid to production version
                APPEND GS_FINAL TO GT_FINAL1.
                CLEAR: GS_FINAL.
              ENDIF.
            ENDIF.
          ENDLOOP.
        ENDIF.
        IF GT_FINAL[] IS INITIAL AND P_VALID = 'X'.
          MESSAGE I208(00) WITH 'No Prod.Versions will be created for selected data'.
          STOP.
        ELSEIF GT_FINAL1[] IS INITIAL AND P_INVALD = 'X'.
          MESSAGE I208(00) WITH 'No data found for selected data'.
          STOP.
        ENDIF.
      ENDFORM.                    " BDC
      *&---------------------------------------------------------------------*
      *&      Form  REPORT
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM REPORT .
      
        PERFORM BUILD_ALV.
      
      ENDFORM.                    " REPORT
      *&---------------------------------------------------------------------*
      *&      Form  BUILD_ALV
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM BUILD_ALV .
      
        FCT-SELTEXT_M = 'Plant'.
        FCT-SELTEXT_L = 'Plant'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'WERKS'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Material'.
        FCT-SELTEXT_L = 'Material'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'MATNR'.
        FCT-OUTPUTLEN = '18'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Production Version'.
        FCT-SELTEXT_L = 'Production Version'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'VERID'.
        FCT-OUTPUTLEN = '18'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Short text'.
        FCT-SELTEXT_L = 'Short text'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'TEXT1'.
        FCT-OUTPUTLEN = '18'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Lot-size from'.
        FCT-SELTEXT_L = 'Lot-size from '.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'BSTMI'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Lot-size to '.
        FCT-SELTEXT_L = 'Lot-size to'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'BSTMA'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Valid From'.
        FCT-SELTEXT_L = 'Valid From'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'ADATU'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Valid To'.
        FCT-SELTEXT_L = 'Valid To'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'BDATU'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Task List Type'.
        FCT-SELTEXT_L = 'Task List Type'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'PLNTY'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Task List'.
        FCT-SELTEXT_L = 'Task List'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'PLNNR'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Group Counter'.
        FCT-SELTEXT_L = 'Group Counter'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'PLNAL'.
        FCT-OUTPUTLEN = '18'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'Alternative BOM'.
        FCT-SELTEXT_L = 'Alternative BOM'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'STLAL'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
        FCT-SELTEXT_M = 'BOM Usage'.
        FCT-SELTEXT_L = 'BOM Usage'.
        IF P_VALID = 'X'.
          FCT-TABNAME = 'GT_FINAL'.
        ELSE.
          FCT-TABNAME = 'GT_FINAL1'.
        ENDIF.
        FCT-FIELDNAME = 'STLAN'.
        FCT-OUTPUTLEN = '12'.
        APPEND FCT TO IT_FCT.
        CLEAR FCT.
      
      
        IF P_VALID = 'X'.                                               " DISPLAY REPORT FOR VALID PRODUCTION VERSIONS.
      
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
      *   I_INTERFACE_CHECK                 = ' '
      *   I_BYPASSING_BUFFER                = ' '
      *   I_BUFFER_ACTIVE                   = ' '
             I_CALLBACK_PROGRAM                = 'ZUTPP609'
      *   I_CALLBACK_PF_STATUS_SET          = ' '
      *     I_CALLBACK_USER_COMMAND           = 'ALV_USER_COMMAND'
             I_CALLBACK_TOP_OF_PAGE            = 'TOP_PAGE'
      *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      *   I_CALLBACK_HTML_END_OF_LIST       = ' '
      *   I_STRUCTURE_NAME                  =
      *   I_BACKGROUND_ID                   = ' '
      *   I_GRID_TITLE                      =
      *   I_GRID_SETTINGS                   =
             IS_LAYOUT                         = LOUT
             IT_FIELDCAT                       = IT_FCT
      *   IT_EXCLUDING                      =
      *   IT_SPECIAL_GROUPS                 =
      *   IT_SORT                           =
      *   IT_FILTER                         =
      *   IS_SEL_HIDE                       =
             I_DEFAULT                         = 'X'
             I_SAVE                            = 'A'
      *   IS_VARIANT                        =
      *   IT_EVENTS                         =
      *   IT_EVENT_EXIT                     =
      *   IS_PRINT                          =
      *   IS_REPREP_ID                      =
      *   I_SCREEN_START_COLUMN             = 0
      *   I_SCREEN_START_LINE               = 0
      *   I_SCREEN_END_COLUMN               = 0
      *   I_SCREEN_END_LINE                 = 0
      *   I_HTML_HEIGHT_TOP                 = 0
      *   I_HTML_HEIGHT_END                 = 0
      *   IT_ALV_GRAPHICS                   =
      *   IT_HYPERLINK                      =
      *   IT_ADD_FIELDCAT                   =
      *   IT_EXCEPT_QINFO                   =
      *   IR_SALV_FULLSCREEN_ADAPTER        =
      * IMPORTING
      *   E_EXIT_CAUSED_BY_CALLER           =
      *   ES_EXIT_CAUSED_BY_USER            =
            TABLES
              T_OUTTAB                          = GT_FINAL[]
           EXCEPTIONS
             PROGRAM_ERROR                     = 1
             OTHERS                            = 2
                    .
          IF SY-SUBRC <> 0.
      * Implement suitable error handling here
          ENDIF.
        ELSE.
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
      *   I_INTERFACE_CHECK                 = ' '
      *   I_BYPASSING_BUFFER                = ' '
      *   I_BUFFER_ACTIVE                   = ' '
             I_CALLBACK_PROGRAM                = 'ZUTPP609'
      *   I_CALLBACK_PF_STATUS_SET          = ' '
      *     I_CALLBACK_USER_COMMAND           = 'ALV_USER_COMMAND'
             I_CALLBACK_TOP_OF_PAGE            = 'TOP_PAGE'
      *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      *   I_CALLBACK_HTML_END_OF_LIST       = ' '
      *   I_STRUCTURE_NAME                  =
      *   I_BACKGROUND_ID                   = ' '
      *   I_GRID_TITLE                      =
      *   I_GRID_SETTINGS                   =
             IS_LAYOUT                         = LOUT
             IT_FIELDCAT                       = IT_FCT
      *   IT_EXCLUDING                      =
      *   IT_SPECIAL_GROUPS                 =
      *   IT_SORT                           =
      *   IT_FILTER                         =
      *   IS_SEL_HIDE                       =
             I_DEFAULT                         = 'X'
             I_SAVE                            = 'A'
      *   IS_VARIANT                        =
      *   IT_EVENTS                         =
      *   IT_EVENT_EXIT                     =
      *   IS_PRINT                          =
      *   IS_REPREP_ID                      =
      *   I_SCREEN_START_COLUMN             = 0
      *   I_SCREEN_START_LINE               = 0
      *   I_SCREEN_END_COLUMN               = 0
      *   I_SCREEN_END_LINE                 = 0
      *   I_HTML_HEIGHT_TOP                 = 0
      *   I_HTML_HEIGHT_END                 = 0
      *   IT_ALV_GRAPHICS                   =
      *   IT_HYPERLINK                      =
      *   IT_ADD_FIELDCAT                   =
      *   IT_EXCEPT_QINFO                   =
      *   IR_SALV_FULLSCREEN_ADAPTER        =
      * IMPORTING
      *   E_EXIT_CAUSED_BY_CALLER           =
      *   ES_EXIT_CAUSED_BY_USER            =
            TABLES
              T_OUTTAB                          = GT_FINAL1[]
           EXCEPTIONS
             PROGRAM_ERROR                     = 1
             OTHERS                            = 2
                    .
          IF SY-SUBRC <> 0.
      * Implement suitable error handling here
          ENDIF.
        ENDIF.
      
      
      ENDFORM.                    " BUILD_ALV
      *&---------------------------------------------------------------------*
      *&      Form  BDC
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM START_BDC .
      
        IF GT_FINAL[] IS INITIAL.
          MESSAGE I208(00) WITH 'No Prod.Versions will be created for selected data'.
          STOP.
        ELSE.
      
          LOOP AT GT_FINAL INTO GS_FINAL.
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '1000'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=ENTE'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL-MATNR'.
      
            PERFORM BDC_FIELD       USING 'MKAL-WERKS'
                                          GS_FINAL-WERKS.         
            PERFORM BDC_FIELD       USING 'MKAL-MATNR'
                                          GS_FINAL-MATNR.         
            WRITE GS_FINAL-ADATU TO GS_FINAL-ADATU.
            PERFORM BDC_FIELD       USING 'MKAL_ADMIN-STTAG'
                                          GS_FINAL-ADATU.         
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '1000'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=CREA'.
      
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL-WERKS'.
      
            PERFORM BDC_FIELD       USING 'MKAL-WERKS'
                                          GS_FINAL-WERKS.      
            PERFORM BDC_FIELD       USING 'MKAL-MATNR'
                                          GS_FINAL-MATNR.           
            PERFORM BDC_FIELD       USING 'MKAL_ADMIN-STTAG'
                                          GS_FINAL-ADATU.            
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '2000'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL_EXPAND-STLAN'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=ENTE'.
      
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-MATNR'
                                          GS_FINAL-MATNR.            
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-VERID'
                                          GS_FINAL-VERID.         
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-TEXT1'
                                          GS_FINAL-TEXT1.            
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-BSTMI'
                                          '1'. "GS_FINAL-BSTMI.          
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-BSTMA'
                                          '999999'."GS_FINAL-BSTMA.          
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-ADATU'
                                          GS_FINAL-ADATU."'25.09.2013'.
            WRITE GS_FINAL-BDATU TO GS_FINAL-BDATU.
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-BDATU'
                                          GS_FINAL-BDATU.          
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-PLNTY'
                                          'N'.
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-PLNNR'
                                          GS_FINAL-PLNNR.          
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-ALNAL'
                                          GS_FINAL-PLNAL.         
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-STLAL'
                                          GS_FINAL-STLAL.         
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-STLAN'
                                          GS_FINAL-STLAN.         
      
            IF P_ALORT IS NOT INITIAL AND C1 = 'X'.
              PERFORM BDC_FIELD       USING 'MKAL_EXPAND-ALORT'
                                            P_ALORT.
            ENDIF.
      
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '2000'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL_EXPAND-VERID'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=PRFG'.
      
            PERFORM BDC_DYNPRO      USING 'SAPMSSY0' '0120'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=RW'.
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '2000'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL_EXPAND-VERID'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=CLOS'.
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '1000'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=SAVE'.
      
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL-WERKS'.
      
            CALL TRANSACTION 'C223' USING BDCDATA MODE 'N' UPDATE 'S'.
            CLEAR : BDCDATA.
            REFRESH : BDCDATA.
          ENDLOOP.
        ENDIF.
      
      ENDFORM.                    " START_BDC
      
      *&---------------------------------------------------------------------*
      *&      Form  TOP_PAGE
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      FORM TOP_PAGE.
      
        DATA: LV_DATE TYPE STRING,
              LINE TYPE I.
      
        CLEAR: IT_HEAD,LINE.
        HEAD-TYP = 'H'.
        IF LV_HEAD = 'X'.
          HEAD-INFO = 'Following Production versions are created'.
        ELSE.
          IF P_VALID = 'X'.
            HEAD-INFO = 'Valid records for Production version'.
          ELSE.
            HEAD-INFO = 'Invalid Records for Production version'.
          ENDIF.
        ENDIF.
        APPEND HEAD TO IT_HEAD.
      
        CONCATENATE SY-DATUM+6(2) '.'
                                      SY-DATUM+4(2) '.' SY-DATUM+0(4) INTO LV_DATE.
        CONDENSE LV_DATE.
      
        HEAD-TYP = 'S'.
        HEAD-KEY = 'Run Date'.
        HEAD-INFO = LV_DATE.
        APPEND HEAD TO IT_HEAD.
        CLEAR : LV_HEAD.
      
        IF P_VALID = 'X'.
          DESCRIBE TABLE GT_FINAL[] LINES LINE.
          HEAD-TYP = 'S'.
          HEAD-KEY = 'Total Records:'.
          HEAD-INFO = LINE.
          APPEND HEAD TO IT_HEAD.
          CLEAR : LINE.
        ELSE.
          DESCRIBE TABLE GT_FINAL1[] LINES LINE.
          HEAD-TYP = 'S'.
          HEAD-KEY = 'Total Records:'.
          HEAD-INFO = LINE.
          APPEND HEAD TO IT_HEAD.
          CLEAR : LINE.
        ENDIF.
      
        CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
          EXPORTING
            IT_LIST_COMMENTARY = IT_HEAD
      *     I_LOGO             =
      *     I_END_OF_LIST_GRID =
      *     I_ALV_FORM         =
          .
      
      
      
      ENDFORM.                    "TOP_PAGE
      
      *&---------------------------------------------------------------------*
      *&      Form  bdc_dynpro
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *      -->PROGRAM    text
      *      -->DYNPRO     text
      *----------------------------------------------------------------------*
      *FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      *  CLEAR BDCDATA.
      *  BDCDATA-PROGRAM = PROGRAM.
      *  BDCDATA-DYNPRO = DYNPRO.
      *  BDCDATA-DYNBEGIN = 'X'.
      *  APPEND BDCDATA.
      *ENDFORM. "BDC_DYNPRO
      **----------------------------------------------------------------------*
      ** Insert field *
      **----------------------------------------------------------------------*
      *FORM BDC_FIELD USING FNAM FVAL.
      *  CLEAR BDCDATA.
      *  IF FVAL <> SPACE.
      *    BDCDATA-FNAM = FNAM.
      *    BDCDATA-FVAL = FVAL.
      *    APPEND BDCDATA.
      *  ENDIF.
      *ENDFORM. "BDC_FIELD
      *&---------------------------------------------------------------------*
      *&      Form  STATUS_REPORT
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM STATUS_REPORT .
      
        DATA: FCT TYPE SLIS_FIELDCAT_ALV,
              IT_FCT TYPE SLIS_T_FIELDCAT_ALV,
              LOUT TYPE SLIS_LAYOUT_ALV,
              HEAD TYPE SLIS_LISTHEADER,
              IT_HEAD TYPE SLIS_T_LISTHEADER.
      
        CLEAR : IT_FCT[],IT_HEAD[].
      
        IF GT_FINAL[] IS NOT INITIAL.
      
          SELECT MATNR WERKS VERID BDATU ADATU STLAL STLAN PLNTY PLNNR ALNAL BSTMI BSTMA ALORT PRFG_F FROM MKAL
                 INTO TABLE GT_STATUS FOR ALL ENTRIES IN GT_FINAL
                 WHERE MATNR = GT_FINAL-MATNR
                 AND   WERKS = GT_FINAL-WERKS
                 AND   VERID = GT_FINAL-VERID.
        ENDIF.
      
        IF GT_STATUS[] IS NOT INITIAL.
          LV_HEAD = 'X'.
          LOOP AT GT_STATUS INTO GS_STATUS.
            CASE GS_STATUS-PRFG_F.
              WHEN '1'.
                MOVE: ICON_LED_GREEN  TO  GS_STATUS-ICON,
                      'OK' TO GS_STATUS-PRFG_F.
                MODIFY GT_STATUS FROM GS_STATUS TRANSPORTING ICON PRFG_F.
              WHEN '2'.
                MOVE: ICON_LED_YELLOW  TO  GS_STATUS-ICON,
                      'WARNING' TO GS_STATUS-PRFG_F.
                MODIFY GT_STATUS FROM GS_STATUS TRANSPORTING ICON PRFG_F.
              WHEN '3'.
                MOVE: ICON_LED_RED  TO  GS_STATUS-ICON,
                      'ERROR' TO GS_STATUS-PRFG_F.
                MODIFY GT_STATUS FROM GS_STATUS TRANSPORTING ICON PRFG_F.
            ENDCASE.
            READ TABLE GT_FINAL INTO GS_FINAL
            WITH KEY  MATNR = GS_STATUS-MATNR
                      WERKS = GS_STATUS-WERKS
                      STLAL = GS_STATUS-STLAL
                      PLNNR = GS_STATUS-PLNNR.
            IF SY-SUBRC = 0.
              GS_STATUS-TEXT1 = GS_FINAL-TEXT1.
              MODIFY GT_STATUS FROM GS_STATUS TRANSPORTING TEXT1.
            ENDIF.
          ENDLOOP.
      
          FCT-SELTEXT_M = 'Plant'.
          FCT-SELTEXT_L = 'Plant'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'WERKS'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Material'.
          FCT-SELTEXT_L = 'Material'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'MATNR'.
          FCT-OUTPUTLEN = '18'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Production Version'.
          FCT-SELTEXT_L = 'Production Version'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'VERID'.
          FCT-OUTPUTLEN = '18'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Short text'.
          FCT-SELTEXT_L = 'Short text'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'TEXT1'.
          FCT-OUTPUTLEN = '18'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Lot-size to'.
          FCT-SELTEXT_L = 'Lot-size to'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'BSTMI'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Lot-size from'.
          FCT-SELTEXT_L = 'Lot-size from'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'BSTMA'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Valid From'.
          FCT-SELTEXT_L = 'Valid From'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'ADATU'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Valid To'.
          FCT-SELTEXT_L = 'Valid To'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'BDATU'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Task List Type'.
          FCT-SELTEXT_L = 'Task List Type'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'PLNTY'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Task List'.
          FCT-SELTEXT_L = 'Task List'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'PLNNR'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Group Counter'.
          FCT-SELTEXT_L = 'Group Counter'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'PLNAL'.
          FCT-OUTPUTLEN = '18'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Alternative BOM'.
          FCT-SELTEXT_L = 'Alternative BOM'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'STLAL'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'BOM Usage'.
          FCT-SELTEXT_L = 'BOM Usage'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'STLAN'.
          FCT-OUTPUTLEN = '12'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
          FCT-SELTEXT_M = 'Status'.
          FCT-SELTEXT_L = 'Status'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'PRFG_F'.
          FCT-OUTPUTLEN = '10'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      *** Begin of +SK20141016
          FCT-SELTEXT_M = 'Rec.Storage Loc.'.
          FCT-SELTEXT_L = 'Rec.Storage Loc.'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'ALORT'.
          FCT-OUTPUTLEN = '15'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      *** End of +SK20141016
          FCT-SELTEXT_M = 'ICON'.
          FCT-SELTEXT_L = 'ICON'.
          FCT-TABNAME = 'GT_STATUS'.
          FCT-FIELDNAME = 'ICON'.
          FCT-OUTPUTLEN = '1'.
          APPEND FCT TO IT_FCT.
          CLEAR FCT.
      
      
      
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
      *   I_INTERFACE_CHECK                 = ' '
      *   I_BYPASSING_BUFFER                = ' '
      *   I_BUFFER_ACTIVE                   = ' '
              I_CALLBACK_PROGRAM                = 'ZUTPP609'
      *   I_CALLBACK_PF_STATUS_SET          = ' '
      *     I_CALLBACK_USER_COMMAND           = 'ALV_USER_COMMAND'
              I_CALLBACK_TOP_OF_PAGE            = 'TOP_PAGE'
      *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      *   I_CALLBACK_HTML_END_OF_LIST       = ' '
      *   I_STRUCTURE_NAME                  =
      *   I_BACKGROUND_ID                   = ' '
      *   I_GRID_TITLE                      =
      *   I_GRID_SETTINGS                   =
              IS_LAYOUT                         = LOUT
              IT_FIELDCAT                       = IT_FCT
      *   IT_EXCLUDING                      =
      *   IT_SPECIAL_GROUPS                 =
      *   IT_SORT                           =
      *   IT_FILTER                         =
      *   IS_SEL_HIDE                       =
              I_DEFAULT                         = 'X'
              I_SAVE                            = 'A'
      *   IS_VARIANT                        =
      *   IT_EVENTS                         =
      *   IT_EVENT_EXIT                     =
      *   IS_PRINT                          =
      *   IS_REPREP_ID                      =
      *   I_SCREEN_START_COLUMN             = 0
      *   I_SCREEN_START_LINE               = 0
      *   I_SCREEN_END_COLUMN               = 0
      *   I_SCREEN_END_LINE                 = 0
      *   I_HTML_HEIGHT_TOP                 = 0
      *   I_HTML_HEIGHT_END                 = 0
      *   IT_ALV_GRAPHICS                   =
      *   IT_HYPERLINK                      =
      *   IT_ADD_FIELDCAT                   =
      *   IT_EXCEPT_QINFO                   =
      *   IR_SALV_FULLSCREEN_ADAPTER        =
      * IMPORTING
      *   E_EXIT_CAUSED_BY_CALLER           =
      *   ES_EXIT_CAUSED_BY_USER            =
             TABLES
               T_OUTTAB                          = GT_STATUS[]
            EXCEPTIONS
              PROGRAM_ERROR                     = 1
              OTHERS                            = 2
                     .
          IF SY-SUBRC <> 0.
      * Implement suitable error handling here
          ENDIF.
        ENDIF.
      ENDFORM.                    " STATUS_REPORT
      
      *&---------------------------------------------------------------------*
      *&      Form  BDC_OPEN
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      
      FORM BDC_OPEN .
      
        CALL FUNCTION 'BDC_OPEN_GROUP'
         EXPORTING
           CLIENT                    = SY-MANDT
      *   DEST                      = FILLER8
           GROUP                     = P_MAP
      *   HOLDDATE                  = FILLER8
           KEEP                      = 'X'
           USER                      = SY-UNAME
      *   RECORD                    = FILLER1
      *   PROG                      = SY-CPROG
      *   DCPFM                     = '%'
      *   DATFM                     = '%'
      * IMPORTING
      *   QID                       =
         EXCEPTIONS
           CLIENT_INVALID            = 1
           DESTINATION_INVALID       = 2
           GROUP_INVALID             = 3
           GROUP_IS_LOCKED           = 4
           HOLDDATE_INVALID          = 5
           INTERNAL_ERROR            = 6
           QUEUE_ERROR               = 7
           RUNNING                   = 8
           SYSTEM_LOCK_ERROR         = 9
           USER_INVALID              = 10
           OTHERS                    = 11.
      
      ENDFORM.                    " BDC_OPEN
      *&---------------------------------------------------------------------*
      *&      Form  BDC_CLOSE
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM BDC_CLOSE .
      
        CALL FUNCTION 'BDC_CLOSE_GROUP'
          EXCEPTIONS
            NOT_OPEN    = 1
            QUEUE_ERROR = 2
            OTHERS      = 3.
      
      ENDFORM.                    " BDC_CLOSE
      *&---------------------------------------------------------------------*
      *&      Form  START_SESSION_BDC
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM START_SESSION_BDC .
      
        DATA : L_JOBNAME   TYPE TBTCJOB-JOBNAME,
                  L_JOBCOUNT  TYPE TBTCJOB-JOBCOUNT,
                  L_DEST      TYPE PRI_PARAMS-PDEST VALUE 'LOCL',
                  L_LINSZ     TYPE PRI_PARAMS-LINSZ VALUE '999999',
                  L_JOBSTATUS TYPE TBTCO-STATUS,
                  L_RQIDENT   TYPE TSP01-RQIDENT.
      
        IF GT_FINAL[] IS INITIAL.
          MESSAGE I208(00) WITH 'No Prod.Versions will be created for selected data'.
          STOP.
        ELSE.
          PERFORM BDC_OPEN.
          LOOP AT GT_FINAL INTO GS_FINAL.
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '1000'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=ENTE'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL-MATNR'.
      
            PERFORM BDC_FIELD       USING 'MKAL-WERKS'
                                          GS_FINAL-WERKS.      
            PERFORM BDC_FIELD       USING 'MKAL-MATNR'
                                          GS_FINAL-MATNR.          
            WRITE GS_FINAL-ADATU TO GS_FINAL-ADATU.
            PERFORM BDC_FIELD       USING 'MKAL_ADMIN-STTAG'
                                          GS_FINAL-ADATU.       
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '1000'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=CREA'.
      
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL-WERKS'.
      
            PERFORM BDC_FIELD       USING 'MKAL-WERKS'
                                          GS_FINAL-WERKS.        
            PERFORM BDC_FIELD       USING 'MKAL-MATNR'
                                          GS_FINAL-MATNR.            
            PERFORM BDC_FIELD       USING 'MKAL_ADMIN-STTAG'
                                          GS_FINAL-ADATU.           
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '2000'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL_EXPAND-STLAN'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=ENTE'.
      
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-MATNR'
                                          GS_FINAL-MATNR.            
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-VERID'
                                          GS_FINAL-VERID.        
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-TEXT1'
                                          GS_FINAL-TEXT1.           
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-BSTMI'
                                          '1'. "GS_FINAL-BSTMI.           
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-BSTMA'
                                          '999999'."GS_FINAL-BSTMA.           
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-ADATU'
                                          GS_FINAL-ADATU."'25.09.2013'.
            WRITE GS_FINAL-BDATU TO GS_FINAL-BDATU.
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-BDATU'
                                          GS_FINAL-BDATU.          
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-PLNTY'
                                          'N'.
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-PLNNR'
                                          GS_FINAL-PLNNR.           
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-ALNAL'
                                          GS_FINAL-PLNAL.         
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-STLAL'
                                          GS_FINAL-STLAL.        
            PERFORM BDC_FIELD       USING 'MKAL_EXPAND-STLAN'
                                          GS_FINAL-STLAN.        
      
            IF P_ALORT IS NOT INITIAL AND C1 = 'X'.
              PERFORM BDC_FIELD       USING 'MKAL_EXPAND-ALORT'
                                            P_ALORT.              
            ENDIF.
      
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '2000'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL_EXPAND-VERID'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=PRFG'.
      
            PERFORM BDC_DYNPRO      USING 'SAPMSSY0' '0120'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=RW'.
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '2000'.
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL_EXPAND-VERID'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=CLOS'.
      
            PERFORM BDC_DYNPRO      USING 'SAPLCMFV' '1000'.
            PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                          '=SAVE'.
      
            PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                          'MKAL-WERKS'.
      
      *      CALL TRANSACTION 'C223' USING BDCDATA MODE 'N' UPDATE 'S'.
            CALL FUNCTION 'BDC_INSERT'
              EXPORTING
                TCODE     = 'C223'
              TABLES
                DYNPROTAB = BDCDATA
              EXCEPTIONS
                OTHERS    = 1.
            CLEAR : BDCDATA.
            REFRESH : BDCDATA.
          ENDLOOP.
        ENDIF.
        PERFORM BDC_CLOSE.
      
      *  IF  P_SIMRUN = 'X'.
      **    L_JOBNAME = SY-REPID.
      **    CALL FUNCTION 'JOB_OPEN'
      **      EXPORTING
      **        JOBNAME          = L_JOBNAME
      **      IMPORTING
      **        JOBCOUNT         = L_JOBCOUNT
      **      EXCEPTIONS
      **        CANT_CREATE_JOB  = 1
      **        INVALID_JOB_DATA = 2
      **        JOBNAME_MISSING  = 3
      **        OTHERS           = 4.
      **    IF SY-SUBRC EQ 0.
      *
      *      COMMIT WORK AND WAIT.
      *      SUBMIT RSBDCSUB TO SAP-SPOOL WITHOUT SPOOL DYNPRO AND RETURN
      *       WITH MAPPE = P_MAP                " SESSION NAME
      *       WITH Z_VERARB = 'X'
      *       WITH FEHLER = ' '                 " NOT BATCH SESSION IN ERROR
      *       WITH LOGALL = 'X'.                " EXTENDED LOG
      *
      **      IF SY-SUBRC EQ 0.
      **
      **        CALL FUNCTION 'JOB_CLOSE'
      **          EXPORTING
      **            JOBCOUNT             = L_JOBCOUNT
      **            JOBNAME              = L_JOBNAME
      **            STRTIMMED            = 'X'
      **          EXCEPTIONS
      **            CANT_START_IMMEDIATE = 1
      **            INVALID_STARTDATE    = 2
      **            JOBNAME_MISSING      = 3
      **            JOB_CLOSE_FAILED     = 4
      **            JOB_NOSTEPS          = 5
      **            JOB_NOTEX            = 6
      **            LOCK_FAILED          = 7
      **            OTHERS               = 8.
      **
      **      ENDIF.
      **    ENDIF.
      *  ENDIF.
      
      
      
      
      ENDFORM.                    " START_SESSION_BDC