<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: BDC code for MM01 Transaction in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549246#M853903</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The below code is using the Session Method&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report ZDS_BDC_MM01
       no standard page heading line-size 255.

include bdcrecx1.

*parameters: dataset(132) lower case.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***
data: begin of record OCCURS 0,
* data element: MATNR
        MATNR_001(018),
* data element: MBRSH
        MBRSH_002(001),
* data element: MTART
        MTART_003(004),
* data element: XFELD
        KZSEL_01_004(001),
* data element: XFELD
        KZSEL_02_005(001),
* data element: MAKTX
        MAKTX_006(040),
* data element: MEINS
        MEINS_007(003),
* data element: MAKTX
        MAKTX_008(040),
      end of record.

*** End generated data section ***

start-of-selection.

*perform open_dataset using dataset.
perform open_group.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      ='C:\DHRUV.TXT'
   FILETYPE                      = 'DAT'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = RECORD
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


*do.
LOOP AT record.
*read dataset dataset into record.
if sy-subrc &amp;lt;&amp;gt; 0. exit. endif.

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MATNR'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RMMG1-MATNR'
                              record-MATNR_001.
perform bdc_field       using 'RMMG1-MBRSH'
                              record-MBRSH_002.
perform bdc_field       using 'RMMG1-MTART'
                              record-MTART_003.
perform bdc_dynpro      using 'SAPLMGMM' '0070'.
perform bdc_field       using 'BDC_CURSOR'
                              'MSICHTAUSW-DYTXT(02)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'
                              record-KZSEL_01_004.
perform bdc_field       using 'MSICHTAUSW-KZSEL(02)'
                              record-KZSEL_02_005.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_006.
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'
                              record-MEINS_007.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'BDC_CURSOR'
                              'MAKT-MAKTX'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_008.
perform bdc_dynpro      using 'SAPLSPO1' '0300'.
perform bdc_field       using 'BDC_OKCODE'
                              '=YES'.
perform bdc_transaction using 'MM01'.

*enddo.
ENDLOOP.
perform close_group.
*perform close_dataset using dataset.

*Text elements
*----------------------------------------------------------
* E00 Error opening dataset, return code:
* I01 Session name
* I02 Open session
* I03 Insert transaction
* I04 Close Session
* I05 Return code =
* I06 Error session created
* S01 Session name
* S02 User
* S03 Keep session
* S04 Lock date
* S05 Processing Mode
* S06 Update Mode
* S07 Generate session
* S08 Call transaction
* S09 Error sessn
* S10 Nodata indicator
* S11 Short log


*Messages
*----------------------------------------------------------
*
* Message class: MS
*613   Please enter a session name and user name



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;P&gt;The Below is the coding for the Call Transaction...&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;PRE&gt;&lt;CODE&gt;

report ZDS_BDC_MM01_2
       no standard page heading line-size 255.

*include bdcrecx1.

*parameters: dataset(132) lower case.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***
data: begin of record OCCURS 0,
* data element: MATNR
        MATNR_001(018),
* data element: MBRSH
        MBRSH_002(001),
* data element: MTART
        MTART_003(004),
* data element: XFELD
        KZSEL_01_004(001),
* data element: MAKTX
        MAKTX_005(040),
* data element: MEINS
        MEINS_006(003),
* data element: MTPOS_MARA
        MTPOS_MARA_007(004),
      end of record.
DATA: FLNAME TYPE STRING.
*** End generated data section ***
DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.

*** MESSAGE******
DATA: BEGIN OF MESSTAB OCCURS 0.
        INCLUDE STRUCTURE BDCMSGCOLL.
        DATA: MATNR TYPE MARA-MATNR,
      END OF MESSTAB.
****END OF MESSAGE****

PARAMETERS: FILENAME TYPE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAME.
  CALL FUNCTION 'F4_FILENAME'
   IMPORTING
     FILE_NAME           = FILENAME.

start-of-selection.

*perform open_dataset using dataset.
perform open_group.

FLNAME = FILENAME.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = FLNAME
    FILETYPE                      = 'DAT'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = record

 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT record.

  DATA:
    CNT TYPE I.
    CNT = CNT + 1.
    REFRESH BDCDATA.

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MTART'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RMMG1-MATNR'
                              record-MATNR_001.
perform bdc_field       using 'RMMG1-MBRSH'
                              record-MBRSH_002.
perform bdc_field       using 'RMMG1-MTART'
                              record-MTART_003.
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)'
                              record-KZSEL_01_004.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_005.
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'
                              record-MEINS_006.
perform bdc_field       using 'MARA-MTPOS_MARA'
                              record-MTPOS_MARA_007.
perform bdc_dynpro      using 'SAPLSPO1' '0300'.
perform bdc_field       using 'BDC_OKCODE'
                              '=YES'.
*perform bdc_transaction using 'MM01'.

CALL TRANSACTION 'MM01' USING BDCDATA
                        MODE 'N'
                        UPDATE 'A'
                        MESSAGES INTO MESSTAB.

READ TABLE MESSTAB INTO MESSTAB INDEX CNT.
   IF MESSTAB-MSGTYP = 'E'.
     MESSTAB-MATNR = RECORD-MATNR_001.
     MODIFY MESSTAB INDEX CNT FROM MESSTAB. " TRANSPORTING MATNR.
   ENDIF.

ENDLOOP.

FORM OPEN_GROUP.

  CALL FUNCTION 'BDC_OPEN_GROUP'
         EXPORTING  CLIENT   = SY-MANDT
                    GROUP    = 'MM01'
                    USER     = SY-UNAME
                    KEEP     = 'X'.

ENDFORM.

FORM BDC_INSERT.
  CALL FUNCTION 'BDC_INSERT'
   EXPORTING
     TCODE                  = 'MM01'
*     POST_LOCAL             = NOVBLOCAL
*     PRINTING               = NOPRINT
*     SIMUBATCH              = ' '
*     CTUPARAMS              = ' '
    TABLES
      DYNPROTAB              = BDCDATA
   EXCEPTIONS
     INTERNAL_ERROR         = 1
     NOT_OPEN               = 2
     QUEUE_ERROR            = 3
     TCODE_INVALID          = 4
     PRINTING_INVALID       = 5
     POSTING_INVALID        = 6
     OTHERS                 = 7
            .
  IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM.

END-OF-SELECTION.

LOOP AT MESSTAB.
    IF MESSTAB-MSGTYP = 'E'.
      WRITE:/ 'ERROR OCCURED ON MATNR = ',MESSTAB-MATNR , 'MESSAGE : MATNR ALREADY EXISTS IN MARA!!!'.
    ENDIF.
  ENDLOOP.

perform close_group.

*perform close_dataset using dataset.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  close_group
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --&amp;gt;  p1        text
*  &amp;lt;--  p2        text
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
 EXCEPTIONS
   NOT_OPEN          = 1
   QUEUE_ERROR       = 2
   OTHERS            = 3
          .
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM.                    " close_group
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  bdc_dynpro
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --&amp;gt;P_0270   text
*      --&amp;gt;P_0271   text
*----------------------------------------------------------------------*
FORM bdc_dynpro  USING PROGRAM DYNPRO.

  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.

ENDFORM.                    " bdc_dynpro
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  bdc_field
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --&amp;gt;P_0275   text
*      --&amp;gt;P_0276   text
*----------------------------------------------------------------------*
FORM bdc_field  USING  FNAM FVAL.

  IF FVAL &amp;lt;&amp;gt; ' '.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
  ENDIF.

ENDFORM.                    " bdc_field

*Text elements
*----------------------------------------------------------
* E00 Error opening dataset, return code:
* I01 Session name
* I02 Open session
* I03 Insert transaction
* I04 Close Session
* I05 Return code =
* I06 Error session created
* S01 Session name
* S02 User
* S03 Keep session
* S04 Lock date
* S05 Processing Mode
* S06 Update Mode
* S07 Generate session
* S08 Call transaction
* S09 Error sessn
* S10 Nodata indicator
* S11 Short log



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dhruv Shah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Mar 2008 10:12:48 GMT</pubDate>
    <dc:creator>dhruv_shah3</dc:creator>
    <dc:date>2008-03-31T10:12:48Z</dc:date>
    <item>
      <title>BDC code for MM01 Transaction</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549245#M853902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,,&lt;/P&gt;&lt;P&gt;             Please give Entire BDC code for MM01 Transaction.&lt;/P&gt;&lt;P&gt;i will change as per my requirement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think this is already done by some ABAP Consultants.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;plz dont give answers like do recording for that transaction MM01. I know recording...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For time constraiint, I have to complete soon.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BestRegards,&lt;/P&gt;&lt;P&gt;Anil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2008 10:05:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549245#M853902</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-31T10:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: BDC code for MM01 Transaction</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549246#M853903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The below code is using the Session Method&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report ZDS_BDC_MM01
       no standard page heading line-size 255.

include bdcrecx1.

*parameters: dataset(132) lower case.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***
data: begin of record OCCURS 0,
* data element: MATNR
        MATNR_001(018),
* data element: MBRSH
        MBRSH_002(001),
* data element: MTART
        MTART_003(004),
* data element: XFELD
        KZSEL_01_004(001),
* data element: XFELD
        KZSEL_02_005(001),
* data element: MAKTX
        MAKTX_006(040),
* data element: MEINS
        MEINS_007(003),
* data element: MAKTX
        MAKTX_008(040),
      end of record.

*** End generated data section ***

start-of-selection.

*perform open_dataset using dataset.
perform open_group.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      ='C:\DHRUV.TXT'
   FILETYPE                      = 'DAT'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = RECORD
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


*do.
LOOP AT record.
*read dataset dataset into record.
if sy-subrc &amp;lt;&amp;gt; 0. exit. endif.

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MATNR'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RMMG1-MATNR'
                              record-MATNR_001.
perform bdc_field       using 'RMMG1-MBRSH'
                              record-MBRSH_002.
perform bdc_field       using 'RMMG1-MTART'
                              record-MTART_003.
perform bdc_dynpro      using 'SAPLMGMM' '0070'.
perform bdc_field       using 'BDC_CURSOR'
                              'MSICHTAUSW-DYTXT(02)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'
                              record-KZSEL_01_004.
perform bdc_field       using 'MSICHTAUSW-KZSEL(02)'
                              record-KZSEL_02_005.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_006.
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'
                              record-MEINS_007.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'BDC_CURSOR'
                              'MAKT-MAKTX'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_008.
perform bdc_dynpro      using 'SAPLSPO1' '0300'.
perform bdc_field       using 'BDC_OKCODE'
                              '=YES'.
perform bdc_transaction using 'MM01'.

*enddo.
ENDLOOP.
perform close_group.
*perform close_dataset using dataset.

*Text elements
*----------------------------------------------------------
* E00 Error opening dataset, return code:
* I01 Session name
* I02 Open session
* I03 Insert transaction
* I04 Close Session
* I05 Return code =
* I06 Error session created
* S01 Session name
* S02 User
* S03 Keep session
* S04 Lock date
* S05 Processing Mode
* S06 Update Mode
* S07 Generate session
* S08 Call transaction
* S09 Error sessn
* S10 Nodata indicator
* S11 Short log


*Messages
*----------------------------------------------------------
*
* Message class: MS
*613   Please enter a session name and user name



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;P&gt;The Below is the coding for the Call Transaction...&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;PRE&gt;&lt;CODE&gt;

report ZDS_BDC_MM01_2
       no standard page heading line-size 255.

*include bdcrecx1.

*parameters: dataset(132) lower case.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***
data: begin of record OCCURS 0,
* data element: MATNR
        MATNR_001(018),
* data element: MBRSH
        MBRSH_002(001),
* data element: MTART
        MTART_003(004),
* data element: XFELD
        KZSEL_01_004(001),
* data element: MAKTX
        MAKTX_005(040),
* data element: MEINS
        MEINS_006(003),
* data element: MTPOS_MARA
        MTPOS_MARA_007(004),
      end of record.
DATA: FLNAME TYPE STRING.
*** End generated data section ***
DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.

*** MESSAGE******
DATA: BEGIN OF MESSTAB OCCURS 0.
        INCLUDE STRUCTURE BDCMSGCOLL.
        DATA: MATNR TYPE MARA-MATNR,
      END OF MESSTAB.
****END OF MESSAGE****

PARAMETERS: FILENAME TYPE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAME.
  CALL FUNCTION 'F4_FILENAME'
   IMPORTING
     FILE_NAME           = FILENAME.

start-of-selection.

*perform open_dataset using dataset.
perform open_group.

FLNAME = FILENAME.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = FLNAME
    FILETYPE                      = 'DAT'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = record

 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT record.

  DATA:
    CNT TYPE I.
    CNT = CNT + 1.
    REFRESH BDCDATA.

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MTART'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RMMG1-MATNR'
                              record-MATNR_001.
perform bdc_field       using 'RMMG1-MBRSH'
                              record-MBRSH_002.
perform bdc_field       using 'RMMG1-MTART'
                              record-MTART_003.
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)'
                              record-KZSEL_01_004.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'MAKT-MAKTX'
                              record-MAKTX_005.
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'
                              record-MEINS_006.
perform bdc_field       using 'MARA-MTPOS_MARA'
                              record-MTPOS_MARA_007.
perform bdc_dynpro      using 'SAPLSPO1' '0300'.
perform bdc_field       using 'BDC_OKCODE'
                              '=YES'.
*perform bdc_transaction using 'MM01'.

CALL TRANSACTION 'MM01' USING BDCDATA
                        MODE 'N'
                        UPDATE 'A'
                        MESSAGES INTO MESSTAB.

READ TABLE MESSTAB INTO MESSTAB INDEX CNT.
   IF MESSTAB-MSGTYP = 'E'.
     MESSTAB-MATNR = RECORD-MATNR_001.
     MODIFY MESSTAB INDEX CNT FROM MESSTAB. " TRANSPORTING MATNR.
   ENDIF.

ENDLOOP.

FORM OPEN_GROUP.

  CALL FUNCTION 'BDC_OPEN_GROUP'
         EXPORTING  CLIENT   = SY-MANDT
                    GROUP    = 'MM01'
                    USER     = SY-UNAME
                    KEEP     = 'X'.

ENDFORM.

FORM BDC_INSERT.
  CALL FUNCTION 'BDC_INSERT'
   EXPORTING
     TCODE                  = 'MM01'
*     POST_LOCAL             = NOVBLOCAL
*     PRINTING               = NOPRINT
*     SIMUBATCH              = ' '
*     CTUPARAMS              = ' '
    TABLES
      DYNPROTAB              = BDCDATA
   EXCEPTIONS
     INTERNAL_ERROR         = 1
     NOT_OPEN               = 2
     QUEUE_ERROR            = 3
     TCODE_INVALID          = 4
     PRINTING_INVALID       = 5
     POSTING_INVALID        = 6
     OTHERS                 = 7
            .
  IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM.

END-OF-SELECTION.

LOOP AT MESSTAB.
    IF MESSTAB-MSGTYP = 'E'.
      WRITE:/ 'ERROR OCCURED ON MATNR = ',MESSTAB-MATNR , 'MESSAGE : MATNR ALREADY EXISTS IN MARA!!!'.
    ENDIF.
  ENDLOOP.

perform close_group.

*perform close_dataset using dataset.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  close_group
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --&amp;gt;  p1        text
*  &amp;lt;--  p2        text
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
 EXCEPTIONS
   NOT_OPEN          = 1
   QUEUE_ERROR       = 2
   OTHERS            = 3
          .
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM.                    " close_group
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  bdc_dynpro
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --&amp;gt;P_0270   text
*      --&amp;gt;P_0271   text
*----------------------------------------------------------------------*
FORM bdc_dynpro  USING PROGRAM DYNPRO.

  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.

ENDFORM.                    " bdc_dynpro
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  bdc_field
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --&amp;gt;P_0275   text
*      --&amp;gt;P_0276   text
*----------------------------------------------------------------------*
FORM bdc_field  USING  FNAM FVAL.

  IF FVAL &amp;lt;&amp;gt; ' '.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
  ENDIF.

ENDFORM.                    " bdc_field

*Text elements
*----------------------------------------------------------
* E00 Error opening dataset, return code:
* I01 Session name
* I02 Open session
* I03 Insert transaction
* I04 Close Session
* I05 Return code =
* I06 Error session created
* S01 Session name
* S02 User
* S03 Keep session
* S04 Lock date
* S05 Processing Mode
* S06 Update Mode
* S07 Generate session
* S08 Call transaction
* S09 Error sessn
* S10 Nodata indicator
* S11 Short log



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dhruv Shah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2008 10:12:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549246#M853903</guid>
      <dc:creator>dhruv_shah3</dc:creator>
      <dc:date>2008-03-31T10:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: BDC code for MM01 Transaction</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549247#M853904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;see this program &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;report ZBDC_MM01_TEST&lt;/P&gt;&lt;P&gt;       no standard page heading line-size 255.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;include bdcrecx1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of wa_mm01,&lt;/P&gt;&lt;P&gt;      mbrsh like RMMG1-MBRSH,&lt;/P&gt;&lt;P&gt;      mtart like RMMG1-MTART,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     type(2),&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      maktx like makt-maktx,&lt;/P&gt;&lt;P&gt;      meins like mara-meins,&lt;/P&gt;&lt;P&gt;       end of wa_mm01.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: i_mm01 like table of wa_mm01.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start-of-selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'UPLOAD'&lt;/P&gt;&lt;P&gt; EXPORTING&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  CODEPAGE                      = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILENAME                      = ' '&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;   FILETYPE                      = 'DAT'&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  ITEM                          = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILEMASK_MASK                 = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILEMASK_TEXT                 = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILETYPE_NO_CHANGE            = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILEMASK_ALL                  = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILETYPE_NO_SHOW              = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  LINE_EXIT                     = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  USER_FORM                     = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  USER_PROG                     = ' '&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  SILENT                        = 'S'&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  FILESIZE                      =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  CANCEL                        =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  ACT_FILENAME                  =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  ACT_FILETYPE                  =&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  TABLES&lt;/P&gt;&lt;P&gt;    data_tab                      = i_mm01&lt;/P&gt;&lt;P&gt; EXCEPTIONS&lt;/P&gt;&lt;P&gt;   CONVERSION_ERROR              = 1&lt;/P&gt;&lt;P&gt;   INVALID_TABLE_WIDTH           = 2&lt;/P&gt;&lt;P&gt;   INVALID_TYPE                  = 3&lt;/P&gt;&lt;P&gt;   NO_BATCH                      = 4&lt;/P&gt;&lt;P&gt;   UNKNOWN_ERROR                 = 5&lt;/P&gt;&lt;P&gt;   GUI_REFUSE_FILETRANSFER       = 6&lt;/P&gt;&lt;P&gt;   OTHERS                        = 7&lt;/P&gt;&lt;P&gt;          .&lt;/P&gt;&lt;P&gt;IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt; MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;P&gt;         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;perform open_group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_mm01 into wa_mm01.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;perform bdc_dynpro      using 'SAPLMGMM' '0060'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_CURSOR'&lt;/P&gt;&lt;P&gt;                              'RMMG1-MATNR'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_OKCODE'&lt;/P&gt;&lt;P&gt;                              '/00'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'RMMG1-MBRSH'&lt;/P&gt;&lt;P&gt;                               wa_mm01-mbrsh.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'RMMG1-MTART'&lt;/P&gt;&lt;P&gt;                              wa_mm01-mtart.&lt;/P&gt;&lt;P&gt;perform bdc_dynpro      using 'SAPLMGMM' '0070'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_CURSOR'&lt;/P&gt;&lt;P&gt;                              'MSICHTAUSW-DYTXT(01)'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_OKCODE'&lt;/P&gt;&lt;P&gt;                              '=ENTR'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'MSICHTAUSW-KZSEL(02)'&lt;/P&gt;&lt;P&gt;                              'X'.&lt;/P&gt;&lt;P&gt;perform bdc_dynpro      using 'SAPLMGMM' '4004'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_OKCODE'&lt;/P&gt;&lt;P&gt;                              '/00'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'MAKT-MAKTX'&lt;/P&gt;&lt;P&gt;                               wa_mm01-maktx.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_CURSOR'&lt;/P&gt;&lt;P&gt;                              'MARA-SPART'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'MARA-MEINS'&lt;/P&gt;&lt;P&gt;                               wa_mm01-meins.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'MARA-SPART'&lt;/P&gt;&lt;P&gt;                              '00'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'MARA-MTPOS_MARA'&lt;/P&gt;&lt;P&gt;                              'LEIS'.&lt;/P&gt;&lt;P&gt;perform bdc_dynpro      using 'SAPLSPO1' '0300'.&lt;/P&gt;&lt;P&gt;perform bdc_field       using 'BDC_OKCODE'&lt;/P&gt;&lt;P&gt;                              '=YES'.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;perform bdc_transaction using 'MM01'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;perform close_group.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2008 10:16:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549247#M853904</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-31T10:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: BDC code for MM01 Transaction</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549248#M853905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dhruv Shah,&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt; Thanks a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have given Points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BestRegards,&lt;/P&gt;&lt;P&gt;S.Anilkumar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2008 10:40:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bdc-code-for-mm01-transaction/m-p/3549248#M853905</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-31T10:40:27Z</dc:date>
    </item>
  </channel>
</rss>

