Make your own free website on Tripod.com
SAP ABAP Programming, Functional and Basis Components Books


Update Source List by Material Group - MM01

The SCREEN SEQUENCE FOLLOWS

4.6x.

***********************************************************************
* Update Source List by Material Group
* Blocking / Unblocking the Vendor
* The Vendor code is retrieve from the Purchasing Info Record
***********************************************************************

REPORT ZSOURCE.
TABLES: EORD,
        EINA,
        MARC.

* Batch Input Name
PARAMETERS P-BTCHSN(12)            DEFAULT 'ME01'.
* Vendor Code
PARAMETERS P-LIFNR LIKE LFA1-LIFNR DEFAULT 'XXXXX'.
* Material Group
PARAMETERS P-MATKL LIKE MARA-MATKL DEFAULT 'XXXXXXX'.
* Plants
PARAMETERS P-WERKS LIKE EORD-WERKS DEFAULT 'XX'.
* Tick Block/Untick Unblock
PARAMETERS P-NOTKZ LIKE EORD-NOTKZ DEFAULT 'X'.
* Auto / Manual run the Batch Input Program
PARAMETERS P-RUN   AS CHECKBOX     DEFAULT 'X'.

* INTERNAL TABLE FOR DATA
DATA:  BEGIN OF ULTAB OCCURS 50,
         MATNR LIKE EORD-MATNR,   "Material No.
         WERKS LIKE EORD-WERKS,   "Plants
         ZEORD LIKE EORD-ZEORD,   "NO
         LIFNR LIKE EINA-LIFNR,   "Vendor 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 EINA WHERE LIFNR = P-LIFNR
                     AND LOEKZ = SPACE.
  SELECT SINGLE * FROM MARC WHERE MATNR = EINA-MATNR
                              AND WERKS = P-WERKS.
  CHECK MARC-LVORM = SPACE.
  CLEAR ULTAB.
  SELECT * FROM EORD WHERE MATNR = EINA-MATNR
                       AND WERKS = P-WERKS
                       AND LIFNR = P-LIFNR.
     ULTAB-MATNR = EORD-MATNR.
     ULTAB-WERKS = EORD-WERKS.
     ULTAB-ZEORD = EORD-ZEORD.
     ULTAB-LIFNR = EORD-LIFNR.
     APPEND ULTAB.
  ENDSELECT.

  IF SY-SUBRC = 4.
     ULTAB-MATNR = EINA-MATNR.
     ULTAB-WERKS = P-WERKS.
     ULTAB-ZEORD = ''.
     ULTAB-LIFNR = EINA-LIFNR.
     APPEND ULTAB.
  ENDIF.
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 = 'SAPLMEOR'.
  IPUTTAB-DYNPRO  =  '200'.
  IPUTTAB-DYNBEGIN = 'X'.
  APPEND IPUTTAB.

* Source List : Material No.
  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-MATNR'.
  IPUTTAB-FVAL =  ULTAB-MATNR.
  APPEND IPUTTAB.

* Source List : Plants.
  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-WERKS'.
  IPUTTAB-FVAL =  ULTAB-WERKS.
  APPEND IPUTTAB.

ENDFORM.
***********************************************************************
* FORM        : SCREEN1                                               *
***********************************************************************
FORM SCREEN2.
* Modify screen for SOURCE LIST
  CLEAR IPUTTAB.
  IPUTTAB-PROGRAM = 'SAPLMEOR'.
  IPUTTAB-DYNPRO  =  '205'.
  IPUTTAB-DYNBEGIN = 'X'.
  APPEND IPUTTAB.

  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-VDATU(1)'.
  IPUTTAB-FVAL = '01.01.2001'.
  APPEND IPUTTAB.

  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-BDATU(1)'.
  IPUTTAB-FVAL = '31.12.9999'.
  APPEND IPUTTAB.

  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-LIFNR(1)'.
  IPUTTAB-FVAL = P-LIFNR.
  APPEND IPUTTAB.

  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-EKORG(1)'.
  IPUTTAB-FVAL = 'ALL'.
  APPEND IPUTTAB.

  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-NOTKZ(1)'.
  IPUTTAB-FVAL = P-NOTKZ.
  APPEND IPUTTAB.

  CLEAR IPUTTAB.
  IPUTTAB-FNAM = 'EORD-AUTET(1)'.
  IPUTTAB-FVAL = '1'.
  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 'ME01'
          USING  IPUTTAB
          MODE   'E'
          UPDATE 'S'
          MESSAGES INTO MESSTAB.
ELSE.
* Maual run the Batch Input Program
 CALL FUNCTION 'BDC_INSERT'
       EXPORTING
            TCODE     = 'ME01'
       TABLES
            DYNPROTAB = IPUTTAB.
ENDIF.

ENDFORM.

***********************************************************************
* FORM        : PRN-ULTAB                                             *
* DESCRIPTION : PRINT OK TABLE                                        *
***********************************************************************
FORM PRN_ULTAB.
  WRITE: / ULTAB-MATNR, ULTAB-WERKS, ULTAB-ZEORD, ULTAB-LIFNR.
  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.

Back to Previous

Return to SAP Hints and Tips on Configuration and ABAP/4 Programming