BDC CALL TRANSACTION AND SESSION METHOD.
TCODE:-SHDB
TCODE:-SHDB
BDC using CALL TRANSACTION METHOD in
SAP ABAP
1)
B) click on “ NEW
RECORDING” u will get this window. Fill the name of recording in
the first , I have given name “DEMO1”. In the 2nd field i.e
transaction code give the name of the transaction which is to be
performed, I have given “MM01” which is for creating materials. Then click
“START RECORDING”.
I have selected the following. then press enter to move
to 2nd screen.
to 2nd screen.
Press enter. The recording will be generated. now Click on “ SAVE”
and then on “BACK” buttons at the top.
d) Now select the recording and click on “PROGRAM”.
e) Now give the name of a program(new one). And click on OK.
Give description of program and click on “ SOURCE CODE” at the bottom.
f) The Following code will get copied in the program.
BDC CALL TRANSACTION METHOD
*&---------------------------------------------------------------------*
*& Report ZMMP_05
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMMP_05.
*include bdcrecx1.
************************
* Type Declare Details *
************************
TYPES:BEGIN OF TY_EXCEL,
MBRSH TYPE MBRSH,
MTART TYPE MTART,
MAKTX TYPE MAKTX,
MATKL TYPE MATKL,
MEINS TYPE MEINS,
KZSEL TYPE XFELD,
END OF TY_EXCEL.
****************************
TYPES:BEGIN OF TY_MSG_REV,
MESSAGE TYPE STRING,
END OF TY_MSG_REV.
*******************************
* Internal Table Declare *
DATA:bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE.
DATA:messtab TYPE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA:gv_name TYPE rlgrap-filename.
DATA:git_upl TYPE TABLE OF TY_EXCEL.
DATA:gwa_upl TYPE TY_EXCEL.
DATA:GIT_MESS TYPE STANDARD TABLE OF bdcmsgcoll.
DATA:GWA_MESS TYPE bdcmsgcoll.
DATA:GIT_MES_RES TYPE TABLE OF TY_MSG_REV.
DATA:GWA_MES_RES TYPE TY_MSG_REV.
DATA:GV_MSG TYPE STRING.
DATA:GV_ROW_NUM TYPE CHAR2.
*******************************
TYPES:FS_STRUCT(4096) TYPE C OCCURS 0.
DATA:G_DAT TYPE FS_STRUCT.
*******************************
* Selection Screen Declare *
*******************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS:P_FILE TYPE IBIPPARMS-PATH.
SELECTION-SCREEN END OF BLOCK B1.
****************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*******************************************************************
* THIS IS FOR FILE UPLOAD *
*******************************************************************
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
AT SELECTION-SCREEN.
GV_NAME = P_FILE.
*******************************************************************
* THIS IS FOR CONVERT FILE XLS TP SAP *
*******************************************************************
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = G_DAT
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = GIT_UPL
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
START-OF-SELECTION.
LOOP AT GIT_UPL INTO GWA_UPL.
MOVE SY-TABIX TO GV_ROW_NUM.
REFRESH BDCDATA.
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-MBRSH'
GWA_UPL-MBRSH."record-MBRSH_001.
perform bdc_field using 'RMMG1-MTART'
GWA_UPL-MTART."record-MTART_002.
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)'
GWA_UPL-KZSEL."'x'."record-KZSEL_01_003.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MARA-MATKL'.
perform bdc_field using 'MARA-MEINS'
GWA_UPL-MEINS."record-MEINS_004.
perform bdc_field using 'MARA-MATKL'
GWA_UPL-MATKL."record-MATKL_005.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_dynpro using 'SAPLMGMM' '4300'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'SKTEXT-MAKTX(01)'.
perform bdc_field using 'SKTEXT-MAKTX(01)'
GWA_UPL-MAKTX."record-MAKTX_01_006.
REFRESH :GIT_MESS,GIT_MES_RES.
CALL TRANSACTION 'MM01' USING BDCDATA MODE 'N' UPDATE 'S' MESSAGES INTO GIT_MESS.
LOOP AT GIT_MESS INTO GWA_MESS.
CLEAR:GV_MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = GWA_MESS-MSGID
LANG = '-D'
NO = GWA_MESS-MSGNR
V1 = GWA_MESS-MSGV1
* V2 = SY-MSGV2
* V3 = SY-MSGV3
V4 = GWA_MESS-MSGV4
IMPORTING
MSG = GV_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
MOVE GV_MSG TO GWA_MES_RES-MESSAGE.
APPEND GWA_MES_RES TO GIT_MES_RES.
CLEAR:GWA_MES_RES,GWA_MESS.
ENDLOOP.
CONDENSE GV_ROW_NUM.
LOOP AT GIT_MES_RES INTO GWA_MES_RES.
WRITE: / 'RECORD-' ,GV_ROW_NUM,'|',GWA_UPL-MAKTX HOTSPOT ON, '|',GWA_MES_RES-MESSAGE COLOR 3.
HIDE GWA_UPL-MAKTX.
ENDLOOP.
CLEAR:GV_ROW_NUM,GWA_UPL.
ENDLOOP.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ' '."NODATA'.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
BDC SESSION METHOD
*&---------------------------------------------------------------------*
*& Report ZMMP_5_SESSSION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMMP_5_SESSSION.
************************
* Type Declare Details *
************************
TYPES:BEGIN OF TY_EXCEL,
MBRSH TYPE MBRSH,
MTART TYPE MTART,
MAKTX TYPE MAKTX,
MATKL TYPE MATKL,
MEINS TYPE MEINS,
KZSEL TYPE XFELD,
END OF TY_EXCEL.
****************************
TYPES:BEGIN OF TY_MSG_REV,
MESSAGE TYPE STRING,
END OF TY_MSG_REV.
*******************************
* Internal Table Declare *
*******************************
DATA:bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE.
DATA:messtab TYPE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA:gv_name TYPE rlgrap-filename.
DATA:git_upl TYPE TABLE OF TY_EXCEL.
DATA:gwa_upl TYPE TY_EXCEL.
DATA:GIT_MESS TYPE STANDARD TABLE OF bdcmsgcoll.
DATA:GWA_MESS TYPE bdcmsgcoll.
DATA:GIT_MES_RES TYPE TABLE OF TY_MSG_REV.
DATA:GWA_MES_RES TYPE TY_MSG_REV.
DATA:GV_MSG TYPE STRING.
DATA:GV_ROW_NUM TYPE CHAR2.
*******************************
TYPES:FS_STRUCT(4096) TYPE C OCCURS 0.
DATA:G_DAT TYPE FS_STRUCT.
*******************************
* Selection Screen Declare *
*******************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS:P_FILE TYPE IBIPPARMS-PATH.
SELECTION-SCREEN END OF BLOCK B1.
****************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*******************************************************************
* THIS IS FOR FILE UPLOAD *
*******************************************************************
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
AT SELECTION-SCREEN.
GV_NAME = P_FILE.
*******************************************************************
* THIS IS FOR CONVERT FILE XLS TP SAP *
*******************************************************************
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = G_DAT
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = GIT_UPL
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
START-OF-SELECTION.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'AKS'
KEEP = 'X'
USER = SY-UNAME
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
START-OF-SELECTION.
LOOP AT GIT_UPL INTO GWA_UPL.
MOVE SY-TABIX TO GV_ROW_NUM.
REFRESH BDCDATA.
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-MBRSH'
GWA_UPL-MBRSH."record-MBRSH_001.
perform bdc_field using 'RMMG1-MTART'
GWA_UPL-MTART."record-MTART_002.
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)'
GWA_UPL-KZSEL."'x'."record-KZSEL_01_003.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MARA-MATKL'.
perform bdc_field using 'MARA-MEINS'
GWA_UPL-MEINS."record-MEINS_004.
perform bdc_field using 'MARA-MATKL'
GWA_UPL-MATKL."record-MATKL_005.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_dynpro using 'SAPLMGMM' '4300'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'SKTEXT-MAKTX(01)'.
perform bdc_field using 'SKTEXT-MAKTX(01)'
GWA_UPL-MAKTX."record-MAKTX_01_006.
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.
REFRESH BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ' '."NODATA'.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
FILE
FORMAT
M1 ROH BDC
TEST 001 KG X
M1 ROH BDC
TEST 001 KG X
M1 ROH BDC
TEST 001 KG X
No comments:
Post a Comment