UPLOAD FLAT FILE TO SAP USING BDC(CALL TRANSACTION METHODS)
report ZMATREIAL
no standard page heading line-size 255.
parameters: p_file type rlgrap-filename.
data: messtab like bdcmsgcoll occurs 0 with header line.
data: bdcdata type bdcdata occurs 0 with header line .
data: begin of itab occurs 0,
matnr(18),
mbrsh(1),
mtart(4),
maktx(40),
meins(3),
end of itab.
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: p_file1 type string.
p_file1 = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = p_file1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'x'
* 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 = itab
* 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 <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*include bdcrecx1.
LOOP AT itab.
index = sy-tabix.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MATNR'
itab-matnr.
perform bdc_field using 'RMMG1-MBRSH'
itab-mbrsh.
perform bdc_field using 'RMMG1-MTART'
itab-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'
itab-maktx.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
itab-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
THEN UPLOAD FILE DATA INTO SAP BY BDC METHOD.
report ZMATREIAL
no standard page heading line-size 255.
parameters: p_file type rlgrap-filename.
data: messtab like bdcmsgcoll occurs 0 with header line.
data: bdcdata type bdcdata occurs 0 with header line .
data: begin of itab occurs 0,
matnr(18),
mbrsh(1),
mtart(4),
maktx(40),
meins(3),
end of itab.
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: p_file1 type string.
p_file1 = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = p_file1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'x'
* 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 = itab
* 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 <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*include bdcrecx1.
LOOP AT itab.
index = sy-tabix.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MATNR'
itab-matnr.
perform bdc_field using 'RMMG1-MBRSH'
itab-mbrsh.
perform bdc_field using 'RMMG1-MTART'
itab-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'
itab-maktx.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
itab-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
THEN UPLOAD FILE DATA INTO SAP BY BDC METHOD.
Comments
Post a Comment