UPLOAD XLS FILE TO SAP USING BDC(CALL TRANSACTION METHODS)
report ZNEEDTR
no standard page heading line-size 255.
TYPE-POOLS: truxs.
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME DEFAULT 'C:\Users\User86\Desktop\JK.xlsx'.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
*include bdcrecx1.
DATA: BEGIN OF IT OCCURS 0,
MATNR(18),
MBRSH(1),
MTART(4),
MAKTX(40),
MEINS(3),
END OF IT.
DATA: INDEX(5),
TEXT(50).
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE
.
start-of-selection.
DATA: I_TAB TYPE TRUXS_T_TEXT_DATA.
DATA: P_FILE1 TYPE STRING.
P_FILE1 = P_FILE.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = I_TAB
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT IT.
INDEX = SY-TABIX.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MBRSH'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MATNR'
IT-MATNR.
perform bdc_field using 'RMMG1-MBRSH'
IT-MBRSH.
perform bdc_field using 'RMMG1-MTART'
IT-MTART.
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)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
IT-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
IT-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
CALL TRANSACTION 'MM01' USING BDCDATA MODE 'A' UPDATE 'S' MESSAGES INTO MESSTAB.
IF SY-SUBRC NE 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
* ID = SY-MSGID
LANG = 'EN'
* NO = SY-MSGNO
* V1 = SY-MSGV1
* V2 = SY-MSGV2
* V3 = SY-MSGV3
* V4 = SY-MSGV4
IMPORTING
MSG = TEXT
* EXCEPTIONS
* NOT_FOUND = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CONCATENATE INDEX TEXT INTO TEXT SEPARATED BY '.'.
WRITE :/ TEXT.
ENDIF.
REFRESH BDCDATA.
ENDLOOP.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
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.
SAVE AND ACTIVE
RUN
MATERIAL WILL BE UPLOAD INTO SAP .
At our SAP MM Institute in Gurgaon, we believe in providing practical training that prepares you for real-world challenges. We offer training on live projects that simulate real-world scenarios, enabling you to gain practical experience and develop problem-solving skills. Our training methodology is designed to ensure that you not only learn the concepts but also apply them in real-world scenarios.
ReplyDelete