BDC Call Transaction For Material Master MM01 - Batch Data Communication - SAPNuts

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.

html

1 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

SAPNMAT1 P FERT KGS BDC Test1


SAPNMAT2 P FERT KGS BDC Test2
SAPNMAT3 P FERT KGS BDC Test3
SAPNMAT4 P FERT KGS BDC Test4
SAPNMAT5 P FERT KGS BDC Test5
SAPNMAT6 P FERT KGS BDC Test6
SAPNMAT7 P FERT KGS BDC Test7
SAPNMAT8 P FERT KGS BDC Test8
SAPNMAT9 P FERT KGS BDC Test9
SAPNMAT10 P FERT KGS BDC Test10

2 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

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

3 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

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

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.

4 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

5 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

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 m
ode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EQ 0.

6 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

WRITE :/ WA_MARA-MATNR, 'submitted to BDC'.


ENDIF.

ENDLOOP.

7 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

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'.

8 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

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 m
ode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EQ 0.
WRITE :/ WA_MARA-MATNR, 'submitted to BDC'.
ENDIF.

9 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

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.

10 of 11 9/7/2017, 11:43 AM
BDC Call transaction for Material Master MM01 - Batch Data Communication | SAPNuts.com https://www.sapnuts.com/courses/core-abap/bdc/bdc-call-transaction-mm01.html

11 of 11 9/7/2017, 11:43 AM

You might also like