*&---------------------------------------------------------------------*
*& Report Z_ABAP_TEST_BDC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_ABAP_TEST_BDC.
TABLES: MARA,MAKT.
TYPES:BEGIN OF TP_LINE,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MBRSH LIKE MARA-MBRSH,
MEINS LIKE MARA-MEINS,
MAKTX LIKE MAKT-MAKTX,
END OF TP_LINE.
TYPES: TP_TAB TYPE TP_LINE.
DATA: WA_LINE TYPE TP_LINE.
DATA:IT_TAB TYPE TP_TAB OCCURS 0.
TYPES:BEGIN OF TP_LINE_LOG,
MSGTYP(1) TYPE C,
MSGTXT(100) TYPE C,
END OF TP_LINE_LOG.
TYPES: TP_TAB_LOG TYPE TP_LINE_LOG.
DATA: WA_LINE_LOG TYPE TP_LINE_LOG.
DATA:IT_TAB_LOG TYPE TP_TAB_LOG OCCURS 0.
DATA:COUNTER TYPE I,
CHAR_COUNTER TYPE C,
FLG_DBC TYPE C.
START-OF-SELECTION.
CLEAR COUNTER.
REFRESH IT_TAB.
DO 5 TIMES.
COUNTER = COUNTER + 1 .
CLEAR CHAR_COUNTER.
CHAR_COUNTER = COUNTER.
CLEAR WA_LINE.
CONCATENATE 'SIHM' SY-UZEIT CHAR_COUNTER INTO WA_LINE-MATNR SEPARATED BY '-'.
WA_LINE-MEINS = 'D'.
CONCATENATE WA_LINE-MATNR 'DESCRIPTIONSIHWJ' INTO WA_LINE-MAKTX.
WA_LINE-MTART = 'VKHM'.
WA_LINE-MBRSH = '3'.
WA_LINE-MEINS = 'CCM'.
APPEND WA_LINE TO IT_TAB.
ENDDO.
REFRESH IT_TAB_LOG.
LOOP AT IT_TAB INTO WA_LINE.
CLEAR FLG_DBC.
PERFORM FRM_CREATE_MASTERIAL USING WA_LINE CHANGING FLG_DBC.
IF FLG_DBC = 'X'.
CLEAR WA_LINE_LOG.
WA_LINE_LOG-MSGTYP = 'E'.
CONCATENATE WA_LINE-MTART 'CREATE FAILED' INTO WA_LINE_LOG-MSGTXT SEPARATED BY SPACE .
APPEND WA_LINE_LOG TO IT_TAB_LOG.
ELSE.
CLEAR WA_LINE_LOG.
WA_LINE_LOG-MSGTYP = 'S'.
CONCATENATE WA_LINE-MTART 'CREATE SUCESSFULLY' INTO WA_LINE_LOG-MSGTXT SEPARATED BY SPACE.
APPEND WA_LINE_LOG TO IT_TAB_LOG.
ENDIF.
ENDLOOP.
LOOP AT IT_TAB_LOG INTO WA_LINE_LOG.
WRITE: / WA_LINE_LOG-MSGTYP,WA_LINE_LOG-MSGTXT.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_MASTERIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->WA_LINE text
* -->PV_FLAG text
*----------------------------------------------------------------------*
FORM FRM_CREATE_MASTERIAL USING WA_LINE TYPE TP_LINE CHANGING PV_FLAG TYPE C.
DATA:BEGIN OF BDC_TAB OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'MM01_BDC'
USER = SY-UNAME
KEEP = 'X'.
CLEAR BDC_TAB.
REFRESH BDC_TAB.
PERFORM FRM_DYNPRO TABLES BDC_TAB USING:
'SAPLMGMM' '0060' 'X' '' '',
'' '' '' 'BDC_CURSOR' 'RMMG1-MATNR',
'' '' '' 'BDC_OKCODE' '/00',
'' '' '' 'RMMG1-MATNR' WA_LINE-MATNR,
'' '' '' 'RMMG1-MBRSH' WA_LINE-MBRSH,
'' '' '' 'RMMG1-MTART' WA_LINE-MTART,
'' '' '' 'BDC_SUBSCR' 'SAPLMGV_MATERIAL_SPEC 0200SUB1',
'' '' '' 'BDC_SUBSCR' 'SAPLMGV_MATERIAL_SPEC 0001SUB1',
'SAPLMGMM' '0070' 'X' '' '',
'' '' '' 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)',
'' '' '' 'BDC_OKCODE' '=ENTR',
'' '' '' 'MSICHTAUSW-KZSEL(01)' 'X',
'SAPLMGMM' '4004' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=BU',
'' '' '' 'BDC_SUBSCR' 'SAPLMGMM 2004TABFRA1',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 1002SUB1',
'' '' '' 'MAKT-MAKTX' WA_LINE-MAKTX,
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 2001SUB2',
'' '' '' 'BDC_CURSOR' 'MARA-MEINS',
'' '' '' 'MARA-MEINS' WA_LINE-MEINS,
'' '' '' 'MARA-MTPOS_MARA LEER' '',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 2561SUB3',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 2007SUB4',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 2005SUB5',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 2011SUB6',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 2033SUB7',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 0001SUB8',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 0001SUB9',
'' '' '' 'BDC_SUBSCR' 'SAPLMGD1 0001SUB10'.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
CALL TRANSACTION 'MM01' USING BDC_TAB MODE 'N'.
IF SY-SUBRC = 0 .
PV_FLAG = 'X'.
ENDIF.
CLEAR BDC_TAB.
REFRESH BDC_TAB.
ENDFORM. "FRM_CREATE_MASTERIAL
*&---------------------------------------------------------------------*
*& Form FRM_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_DBC_TAB text
* -->PT_PROGRAM text
* -->PT_DYNPRO text
* -->PT_DYNBEGIN text
* -->PT_NAME text
* -->PT_VALUE text
*----------------------------------------------------------------------*
FORM FRM_DYNPRO TABLES PT_DBC_TAB STRUCTURE BDCDATA USING PT_PROGRAM PT_DYNPRO PT_DYNBEGIN PT_NAME PT_VALUE .
CLEAR PT_DBC_TAB.
IF PT_DYNBEGIN = 'X'.
MOVE: 'X' TO PT_DBC_TAB-DYNBEGIN ,
PT_PROGRAM TO PT_DBC_TAB-PROGRAM,
PT_DYNPRO TO PT_DBC_TAB-DYNPRO.
APPEND PT_DBC_TAB.
ELSE.
MOVE: PT_NAME TO PT_DBC_TAB-FNAM,
PT_VALUE TO PT_DBC_TAB-FVAL.
APPEND PT_DBC_TAB.
ENDIF.
ENDFORM. "FRM_DYNPRO