BDC Call transaction for Material Master MM01

BDC call transaction method for migrating Material Master data using MM01 transaction

+ -
Requirement: Create a BDC program with Call Transaction method to migrate(create) material master basic data using a flat file(.txt with tab delimited).

Requirement analysis: To fulfil the above requirement we need to create recording for MM01 t-code using SHDB transaction, upload flat file data to a internal table, process using BDC.

Flat file format.

Note:For better understanding, create a material in MM01 with basic data(basic view1 only), refer Creating material in SAP

Follow the below steps to create a BDC form Material

Create recording for MM01 transaction

Create recording for material master MM01 with material basic data i:e basic view1, copy the code to create a new program MM01 recording with material basic data , the below code will be generated.Try to understand the below code (explained)

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MTART'. 
perform bdc_field       using 'BDC_OKCODE'
                              'ENTR'.
perform bdc_field       using 'RMMG1-MATNR'
                              record-MATNR_001. "pass material no
perform bdc_field       using 'RMMG1-MBRSH'
                              record-MBRSH_002. "pass industry sector
perform bdc_field       using 'RMMG1-MTART'
                              record-MTART_003. "pass material type
perform bdc_dynpro      using 'SAPLMGMM' '0070'.
perform bdc_field       using 'BDC_CURSOR'
                              'MSICHTAUSW-DYTXT(01)'.
perform bdc_field       using 'BDC_OKCODE'  "enter
                              '=ENTR'.
perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'
                              record-KZSEL_01_004. "basic view1 pass 'X'
perform bdc_dynpro      using 'SAPLMGMM' '4004'. "calling second screen (basic view1)
perform bdc_field       using 'BDC_OKCODE'
                              '=BU'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_005. "material description
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.  "base unit of meassure
perform bdc_field       using 'MARA-MEINS'
                              record-MEINS_006.
perform bdc_transaction using 'MM01'.  "finally calling transaction

Add data declerations

Add required data declerations for material data as per flat file

TYPES: BEGIN OF TY_MARA, "user defined types as per flat file
       MATNR TYPE MARA-MATNR,
       MBRSH TYPE MARA-MBRSH,
       MTART TYPE MARA-MTART,
       MEINS TYPE MARA-MEINS,
       MAKTX TYPE MAKT-MAKTX,
       END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
       WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message table
DATA:FILE TYPE STRING. "file name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME. "input parameter for file upload

Upload data from flat file

Upload data into a internal table from a flat file using GUI_UPLOAD, all BDC performs are available in standard programs, simpley double click on each perform and copy from standard program, paste at the bottom.

    FILE = P_FILE.
    CALL FUNCTION 'GUI_UPLOAD' "upload flat file
      EXPORTING
        FILENAME            = FILE "file name
        FILETYPE            = 'ASC' "file type
        HAS_FIELD_SEPARATOR = 'X' "is tab delimited
      TABLES
        DATA_TAB            = IT_MARA.
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.

Process records one by one to BDC

Loop through internal table and pass records to BDC call transaction.
LOOP AT IT_MARA INTO WA_MARA. "loop all records and pass one by one to BDC
    PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0060'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'RMMG1-MTART'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  'ENTR'.
    PERFORM BDC_FIELD       USING 'RMMG1-MATNR'
                                  WA_MARA-MATNR. "pass material no
    PERFORM BDC_FIELD       USING 'RMMG1-MBRSH'
                                  WA_MARA-MBRSH. "pass indistry sector
    PERFORM BDC_FIELD       USING 'RMMG1-MTART'
                                  WA_MARA-MTART. "pass material type
    PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0070'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'MSICHTAUSW-DYTXT(01)'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM BDC_FIELD       USING 'MSICHTAUSW-KZSEL(01)'  "select basic view1
                                  'X'.
    PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '4004'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=BU'.
    PERFORM BDC_FIELD       USING 'MAKT-MAKTX'
                                  WA_MARA-MAKTX. "pass material description
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'MARA-MEINS'.
    PERFORM BDC_FIELD       USING 'MARA-MEINS'
                                  WA_MARA-MEINS. "pass base unit oe meassure

    CALL TRANSACTION 'MM01' USING IT_BDCDATA "call transaction
                          MODE 'N' "N-no screen mode, A-all screen mode, E-error screen mode
                          UPDATE 'A' "A-assynchronous, S-synchronous
                          MESSAGES INTO  BDCMSG. "messages
    IF SY-SUBRC EQ 0.
      WRITE :/  WA_MARA-MATNR, 'submitted to BDC'.
    ENDIF.

  ENDLOOP.

The filnal BDC for migrating Material Master basic data is below

REPORT ZSAPN_BDC
       NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPES: BEGIN OF TY_MARA, "user defined types as per flat file
       MATNR TYPE MARA-MATNR,
       MBRSH TYPE MARA-MBRSH,
       MTART TYPE MARA-MTART,
       MEINS TYPE MARA-MEINS,
       MAKTX TYPE MAKT-MAKTX,
       END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
       WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message table
DATA:FILE TYPE STRING. "file name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME. "input parameter for file upload

START-OF-SELECTION.
  IF P_FILE IS NOT INITIAL.
    FILE = P_FILE.
    CALL FUNCTION 'GUI_UPLOAD' "upload flat file
      EXPORTING
        FILENAME            = FILE "file name
        FILETYPE            = 'ASC' "file type
        HAS_FIELD_SEPARATOR = 'X' "is tab delimited
      TABLES
        DATA_TAB            = IT_MARA.
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.

  ENDIF.
  LOOP AT IT_MARA INTO WA_MARA. "loop all records and pass one by one to BDC
    PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0060'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'RMMG1-MTART'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  'ENTR'.
    PERFORM BDC_FIELD       USING 'RMMG1-MATNR'
                                  WA_MARA-MATNR. "pass material no
    PERFORM BDC_FIELD       USING 'RMMG1-MBRSH'
                                  WA_MARA-MBRSH. "pass indistry sector
    PERFORM BDC_FIELD       USING 'RMMG1-MTART'
                                  WA_MARA-MTART. "pass material type
    PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0070'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'MSICHTAUSW-DYTXT(01)'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM BDC_FIELD       USING 'MSICHTAUSW-KZSEL(01)'  "select basic view1
                                  'X'.
    PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '4004'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=BU'.
    PERFORM BDC_FIELD       USING 'MAKT-MAKTX'
                                  WA_MARA-MAKTX. "pass material description
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'MARA-MEINS'.
    PERFORM BDC_FIELD       USING 'MARA-MEINS'
                                  WA_MARA-MEINS. "pass base unit oe meassure

    CALL TRANSACTION 'MM01' USING IT_BDCDATA "call transaction
                          MODE 'N' "N-no screen mode, A-all screen mode, E-error screen mode
                          UPDATE 'A' "A-assynchronous, S-synchronous
                          MESSAGES INTO  BDCMSG. "messages
    IF SY-SUBRC EQ 0.
      WRITE :/  WA_MARA-MATNR, 'submitted to BDC'.
    ENDIF.

  ENDLOOP.

  DATA : WA_BDCMSG LIKE LINE OF BDCMSG.
  IF BDCMSG IS NOT INITIAL. "display messages
    LOOP AT BDCMSG INTO WA_BDCMSG.
      WRITE:/ WA_BDCMSG-TCODE, WA_BDCMSG-MSGTYP, WA_BDCMSG-MSGV1, WA_BDCMSG-FLDNAME .
      CLEAR WA_BDCMSG.
    ENDLOOP.
  ENDIF.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR WA_BDCDATA.
  WA_BDCDATA-PROGRAM  = PROGRAM. "program
  WA_BDCDATA-DYNPRO   = DYNPRO. "screen
  WA_BDCDATA-DYNBEGIN = 'X'. "begin
  APPEND WA_BDCDATA TO IT_BDCDATA..
ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.
*  IF FVAL <> NODATA.
  CLEAR WA_BDCDATA.
  WA_BDCDATA-FNAM = FNAM. "field name ex: matnr
  WA_BDCDATA-FVAL = FVAL. "field value ex: testmat001
  APPEND WA_BDCDATA TO IT_BDCDATA.
*  ENDIF.
ENDFORM.
Download flat file format

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 66 People out of 67 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Lesson → Open SQL Statements in SAP ABAP