SAP4TECH

SAP and ABAP Free Tutorials
Menu
  • SAP Technical
    • ABAP Code Snippets
    • ABAP WebDynPro
    • SAP GW
    • SAP IDOC (ALE)
    • SAP PI (XI)
    • SAP Screen Personas
    • SAP Workflow
  • SAP Functional
    • SAP FI
    • SAP FSCM
    • SAP HR
    • SAP SD & SAP MM
    • SAP PM
    • SAP PP
    • SAP PS
    • SAP QM
    • SAP VIM
    • SAP WM
  • SAP Fiori
  • SAP HANA
  • SAP BW
  • SAP CRM
  • SAP SRM
  • SAP4TECH
    • About Us
    • Contact Us
    • Terms & Conditions
    • Privacy and Cookie Policy

SAP4TECH » Trigger MATMAS IDoc using BTE Function

ABAP Tutorials

Trigger MATMAS IDoc using BTE Function

March 9, 2016 John

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 .

Generate IDOC using BTE Event on Material Save
ABAP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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

Generate IDOC using BTE Event on Material Save 2
ABAP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"-----------------------------------------------"
  "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 IDOC using BTE Event on Material Save 2
ABAP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  "-----------------------------------------------"
  " 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)

Prev Article
Next Article
Tags:ABAP Sample SAP IDOC SAP Transaction Codes

Related Articles

SAP Material Unit of Mesure
This code will update characteristic value in SAP. First, it …

Update Characteristic Value for SAP Customer with Sample ABAP Code

SAP Purchase Order
What is a SAP Purchase Orders ? The SAP Purchase …

All what you need to know about SAP Purchase Order

Search on SAP4TECH

The Most Populars

  • The Most Important SAP ISU Tables
    The Most Important SAP ISU Tables
  • SAP Users Tables
    SAP Users Tables (for Personal, Logon, and Address Data)
  • List of SAP Purchase Order Tables in SAP MM SAP PO Tables
    SAP Purchase Order Tables: Main PO tables in SAP MM – SAP PO Tables
  • Full list of SAP Movement Types
    SAP Good Movement Types – Full list of SAP Movement Types
  • The Main SAP GL Account Tcodes SAP GL Account Tables
    The Main SAP G/L Account Tcodes & SAP GL Account Tables
  • SAP BOM Tables
    SAP BOM Tables for BOM Header, Items and components and Category

Related Posts

  • SAP Batch Management 1
    SAP Batch Management Tcodes, Tables and Customizing (SAP Batch Management)
  • SAP SD
    SAP SD Tcodes (Transaction Tcodes) in Sales and Distribution
  • Core Data Services e1460549614588
    Core Data Services (CDS) on SAP HANA – Overview
  • binary 208216 1920 e1460535901166
    Step-step Guide how to SAP remote table comparison with ABAP Code
  • FIXATOR Errors and Fix e1455293383379
    How to check and hide SAP IDOC entries in tRFC Queue in BD87 ?

SAP4TECH

SAP and ABAP Free Tutorials

Trending Posts

  • The Most Important SAP ISU Tables
  • SAP Users Tables (for Personal, Logon, and Address Data)
  • SAP Purchase Order Tables: Main PO tables in SAP MM – SAP PO Tables
  • SAP Good Movement Types – Full list of SAP Movement Types
  • The Main SAP G/L Account Tcodes & SAP GL Account Tables
  • SAP BOM Tables for BOM Header, Items and components and Category

The Most Recents

  • The Most Important SAP ISU Tables
  • SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd Lecture
  • The Main SAP Dunning Transaction Codes
  • SAP Accounts Payable Tcodes & Accounts Receivable Tcodes ( SAP AP Tcodes & SAP AR Tcodes)
  • The Most Important SAP Payment Terms Tables (ZTERM, Text…)

Search

SAP Tutorials by Topics

  • SAP Tables
  • SAP Tcodes
  • SAP BAPI
  • ABAP Snippets
  • Top SAP Courses
  • Top SAP Books
Copyright © 2021 SAP4TECH

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
This website uses cookies to improve your experience. We'll assume you accept this policy as long as you are using this websiteAcceptView Policy