Trigger MATMAS IDoc using BTE Function

SAP Material

Trigger MATMAS IDoc using BTE Function: this is a sample ABAP Program to generate a MATMAS IDoc for a Material Change using BTE event when a SAP Material is saved in MM02 / MM01.

Trigger MATMAS IDoc using BTE Function ABAP

First Step is to generate IDoc Control Record : EDIDC
The Second Step is to generate IDOC Data Table : EDIDD
The last step is to call the?MASTER_IDOC_DISTRIBUTE to generate the IDoc

This sample ABAP function code is a little particular to generate MATMAS IDoc using BTE Function ABAP. This is a enhanced copy of the standard Function SAMPLE_INTERFACE_00001250.

Find more resource about the?Most important Idocs Tcodes and Idocs Tables?and also .

FUNCTION ZMATMAS_INTERFACE_00001250.
  " Trigger MATMAS IDoc using BTE Function 
  " Copy of SAMPLE_INTERFACE_00001250 

  DATA : gt_idoc_data TYPE STANDARD TABLE OF edidd,
         ls_idoc_data TYPE edidd,
         ls_idoc_control LIKE edidc,
         gt_comm_idocs TYPE STANDARD TABLE OF edidc.

  DATA: ls_e1maram LIKE e1maram,
        ls_e1maktm LIKE e1maktm,
        ls_e1marcm LIKE e1marcm,
        ls_e1mardm LIKE e1mardm,
        ls_e1marmm LIKE e1marmm,
        ls_e1mbewm LIKE e1mbewm,
        ls_e1mvkem LIKE e1mvkem,
        ls_e1mlanm LIKE e1mlanm.
  
  DATA: ls_marm_new LIKE LINE OF LT_MARW_NEW,
ls_MAKT_new LIKE LINE OF LT_MAKT_NEW.

  
  "-----------------------------------------------"
  " Fill IDOC Control 
  "-----------------------------------------------"
  ls_idoc_control-mestyp = 'MATMAS'.
  ls_idoc_control-idoctp = 'MATMAS05'.
  ls_idoc_control-rcvpor = 'REC_PORT'. " Fill the receiver Port 
  ls_idoc_control-rcvprt = 'LS'.
  ls_idoc_control-rcvprn = 'RECEIVER'. " Fill the receiver system

The second step is to fill some Data into MATMAS Idoc such

  • E1MARAM : MARA
  • E1MAKTM : MAKT : Material Description Table
  • E1MARCM : MARC : Material Plant Data
  • E1MARDM : MARD : Material Storage Location Data
  • E1MARMM : MARM : Material Alternative Unit Table
  • E1MLANM : MLAN : Tax Classification for Material
  
"-----------------------------------------------"
  "Filling IDOC Data Table 
  "-----------------------------------------------"
  " E1MARAM : MARA 
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MARAM'.
  MOVE-CORRESPONDING i_mara_new TO ls_e1maram.
  MOVE ls_e1maram TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data.

  " E1MAKTM : MAKT : Material Description Table
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MAKTM'.
  MOVE-CORRESPONDING t_makt_new TO ls_e1maktm.
  MOVE ls_e1maktm TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data. 
  
  " E1MARCM : MARC : Material Plant Data 
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MARCM'.
  MOVE-CORRESPONDING i_marc_new TO ls_e1marcm.
  MOVE ls_e1marcm TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data.
  
  " E1MARDM : MARD : Material Storage Location Data 
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MARDM'.
  MOVE-CORRESPONDING i_mard_new TO ls_e1mardm.
  MOVE ls_e1mardm TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data.
  
  " E1MARMM : MARM : Material Alternative Unit Table  
  LOOP AT t_marm_new into ls_marm_new. 
CLEAR ls_idoc_data.
ls_idoc_data-segnam = 'E1MARMM'.
MOVE-CORRESPONDING t_marm_new TO ls_e1mardm.
MOVE ls_e1mardm TO ls_idoc_data-sdata.
APPEND ls_idoc_data TO gt_idoc_data.
  ENDLOOP. 
  
  " E1MBEWM : MBEW : Material Valuation Table 
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MBEWM'.
  MOVE-CORRESPONDING i_mbew_new TO ls_e1mardm.
  MOVE ls_e1mardm TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data.
  
  " E1MVKEM : MVKE : Sales Data for Material Data  
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MVKEM'.
  MOVE-CORRESPONDING i_mvke_new TO ls_e1mvkem.
  MOVE ls_e1mvkem TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data.

  " E1MLANM : MLAN : Tax Classification for Material
  CLEAR ls_idoc_data.
  ls_idoc_data-segnam = 'E1MLANM'.
  MOVE-CORRESPONDING i_MLAN_new TO ls_e1mlanm.
  MOVE ls_e1mlanm TO ls_idoc_data-sdata.
  APPEND ls_idoc_data TO gt_idoc_data.

The Last step is to generate the IDoc as following using MASTER_IDOC_DISTRIBUTE BAPI

  
  "-----------------------------------------------"
  " Generate MATMAS IDoc 
  "-----------------------------------------------"
  " Trigger MATMAS IDoc using BTE Function
  CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
    EXPORTING
      master_idoc_control                  = ls_idoc_control
    TABLES
      communication_idoc_control           = gt_comm_idocs
      master_idoc_data                     = gt_idoc_data
 EXCEPTIONS
   error_in_idoc_control                = 1
   error_writing_idoc_status            = 2
   error_in_idoc_data                   = 3
   sending_logical_system_unknown       = 4
   OTHERS                               = 5
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFUNCTION.  

Here it is the Idoc MATMAS should be created when a material is Saved ( if the ALE configuration is already set-up)