2016 Jun 20 12:08 PM
Dear experts,
I really need some help for my issue. Currently my task is to create a new DMS document and upload image. I am able to create the document and upload the image. But the image i upload is kind of incorrect. Please find in the attachment. Really appreciate for the help.
I'm using this to upload the picture from my PC.
cl_gui_frontend_services=>file_open_dialog(
CHANGING
file_table = lt_file " Table Holding Selected Files
rc = lv_rc ). " Return Code, Number of Files or -1 If Error Occurred
READ TABLE lt_file INTO ls_file INDEX 1.
IF sy-subrc = 0.
lv_filename = ls_file-filename.
ENDIF.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_filename " Name of file
filetype = 'BIN'
IMPORTING
filelength = lv_length2 " File length
CHANGING
data_tab = lt_data " Transfer table for file contents
EXCEPTIONS
OTHERS = 19 ).
Then I'm directly creating the document and uploading the image to DMS .
* Data for create document
wa_doc_data-documenttype = lv_doc_type.
wa_doc_data-documentversion = '00'.
wa_doc_data-documentpart = '000'.
wa_doc_data-description = i_desc.
wa_doc_data-userdefined1 = i_plant.
wa_doc_data-userdefined2 = i_notif_no.
wa_doc_data-userdefined3 = i_pln_grp.
wa_doc_data-userdefined4 = i_pln_sec.
* Description
wa_drat-language = 'EN'.
wa_drat-description = i_desc.
APPEND wa_drat TO i_tab_drat.
*Conversion for workorder and notification number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_ord_no
IMPORTING
output = i_ord_no.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_notif_no
IMPORTING
output = i_notif_no.
* Object link – connection to PM object notification & Work Order
CLEAR wa_drad.
wa_drad-objecttype = 'AFIH'. "Order number
wa_drad-objectkey = i_ord_no."Number of work order
APPEND wa_drad TO i_tab_drad.
CLEAR wa_drad.
wa_drad-objecttype = 'PMQMEL'. "Notification
wa_drad-objectkey = i_notif_no."Number of notification
APPEND wa_drad TO i_tab_drad.
SPLIT lv_filename AT '.' INTO file_name lv_suffix.
TRANSLATE lv_suffix TO UPPER CASE.
wa_originals-dappl = lv_suffix. " Application type 'JPG'
wa_originals-filename = lv_filename. "'IMAGE.JPG'. "filename
wa_originals-description = i_desc. "description
* wa_originals-active_version = 'X'.
wa_originals-checked_in = 'X' .
wa_originals-storage_cat = 'ZDMS_SC'. " storage category
wa_originals-appnr = 1.
APPEND wa_originals TO i_tab_originals .
* Create new DMS document and link it PMorder and notification
* CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
* EXPORTING
* documentdata = wa_doc_data
* IMPORTING
* documenttype = lv_doc_type
* documentnumber = lv_doc_num
* return = wa_return
* TABLES
* documentdescriptions = i_tab_drat
* objectlinks = i_tab_drad
*
* IF wa_return-type CA 'EA'.
* ROLLBACK WORK.
* lv_subrc = 8.
* MOVE-CORRESPONDING wa_return1 TO e_message.
* ELSE.
* COMMIT WORK.
* ENDIF.
lv_count = 0.
* LOOP AT lt_bindata INTO ls_bindata .
* ADD 1 TO lv_count.
wa_drao-orblk = 2550 ."ls_bindata-line."binary data
wa_drao-orln = lv_length. "file length
wa_drao-doknr = lv_doc_num. "number of dms inforecord
wa_drao-dokar = lv_doc_type .
wa_drao-dokvr = '00'.
wa_drao-doktl = '000'.
wa_drao-appnr = '1'.
* wa_drao-zaehl = lv_count .
* APPEND wa_drao TO i_tab_drao .
LOOP AT i_tab_bin_data INTO wa_bin_data .
ADD 1 TO lv_count.
wa_drao-orblk = wa_bin_data.
wa_drao-zaehl = lv_count.
APPEND wa_drao TO i_tab_drao .
ENDLOOP.
** Adding to the JPEG document
* wa_api_ctrl-save_flag = 'X'.
* wa_api_ctrl-api_mode = 'X'.
* wa_api_ctrl-bapi_flag = 'X'.
* wa_api_ctrl-tcode = 'CV01N'.
*Adding image to the DMs document created
IF lv_subrc IS INITIAL.
CALL FUNCTION 'CVAPI_DOC_CHECKIN'
EXPORTING
pf_dokar = lv_doc_type "document type
pf_doknr = lv_doc_num "document number
pf_dokvr = wa_doc_data-documentversion "document version
pf_doktl = wa_doc_data-documentpart "part of document
* pf_ftp_dest = '' "'SAPFTPA'
* pf_http_dest = '''SAPHTTPA'
* pf_hostname = 'DEFAULT'
* ps_api_control = wa_api_ctrl
* pf_replace = 'X'
pf_content_provide = 'TBL' "tbl – takes data FROM a table of binary data (i_tab_drao).
IMPORTING
psx_message = wa_return1
TABLES
pt_files_x = i_tab_originals
pt_content = i_tab_drao.
IF wa_return1-msg_type CA 'EA'.
ROLLBACK WORK.
lv_subrc = 8.
MOVE-CORRESPONDING wa_return1 TO e_message.
ELSE.
COMMIT WORK.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.
Thanks and Regards
Shankar
2016 Jun 20 1:05 PM
You only need to pass the file name and path to the BAPI_DOCUMENT_* function modules, which will do the upload themselves (cf 504692 - Document BAPIs, Checkin - checkout special cases)
Dear experts,
I really need some help for my issue. Currently my task is to create a new DMS document and upload image. I am able to create the document and upload the image. But the image i upload is kind of incorrect. Please find in the attachment. Really appreciate for the help.
I'm using this to upload the picture from my PC.
cl_gui_frontend_services=>file_open_dialog(
CHANGING
file_table = lt_file " Table Holding Selected Files
rc = lv_rc ). " Return Code, Number of Files or -1 If Error Occurred
READ TABLE lt_file INTO ls_file INDEX 1.
IF sy-subrc = 0.
lv_filename = ls_file-filename.
ENDIF.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_filename " Name of file
filetype = 'BIN'
IMPORTING
filelength = lv_length2 " File length
CHANGING
data_tab = lt_data " Transfer table for file contents
EXCEPTIONS
OTHERS = 19 ).
Then I'm directly creating the document and uploading the image to DMS .
* Data for create document
wa_doc_data-documenttype = lv_doc_type.
wa_doc_data-documentversion = '00'.
wa_doc_data-documentpart = '000'.
wa_doc_data-description = i_desc.
wa_doc_data-userdefined1 = i_plant.
wa_doc_data-userdefined2 = i_notif_no.
wa_doc_data-userdefined3 = i_pln_grp.
wa_doc_data-userdefined4 = i_pln_sec.
* Description
wa_drat-language = 'EN'.
wa_drat-description = i_desc.
APPEND wa_drat TO i_tab_drat.
*Conversion for workorder and notification number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_ord_no
IMPORTING
output = i_ord_no.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_notif_no
IMPORTING
output = i_notif_no.
* Object link – connection to PM object notification & Work Order
CLEAR wa_drad.
wa_drad-objecttype = 'AFIH'. "Order number
wa_drad-objectkey = i_ord_no."Number of work order
APPEND wa_drad TO i_tab_drad.
CLEAR wa_drad.
wa_drad-objecttype = 'PMQMEL'. "Notification
wa_drad-objectkey = i_notif_no."Number of notification
APPEND wa_drad TO i_tab_drad.
SPLIT lv_filename AT '.' INTO file_name lv_suffix.
TRANSLATE lv_suffix TO UPPER CASE.
wa_originals-dappl = lv_suffix. " Application type 'JPG'
wa_originals-filename = lv_filename. "'IMAGE.JPG'. "filename
wa_originals-description = i_desc. "description
* wa_originals-active_version = 'X'.
wa_originals-checked_in = 'X' .
wa_originals-storage_cat = 'ZDMS_SC'. " storage category
wa_originals-appnr = 1.
APPEND wa_originals TO i_tab_originals .
* Create new DMS document and link it PMorder and notification
* CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
* EXPORTING
* documentdata = wa_doc_data
* IMPORTING
* documenttype = lv_doc_type
* documentnumber = lv_doc_num
* return = wa_return
* TABLES
* documentdescriptions = i_tab_drat
* objectlinks = i_tab_drad
*
* IF wa_return-type CA 'EA'.
* ROLLBACK WORK.
* lv_subrc = 8.
* MOVE-CORRESPONDING wa_return1 TO e_message.
* ELSE.
* COMMIT WORK.
* ENDIF.
lv_count = 0.
* LOOP AT lt_bindata INTO ls_bindata .
* ADD 1 TO lv_count.
wa_drao-orblk = 2550 ."ls_bindata-line."binary data
wa_drao-orln = lv_length. "file length
wa_drao-doknr = lv_doc_num. "number of dms inforecord
wa_drao-dokar = lv_doc_type .
wa_drao-dokvr = '00'.
wa_drao-doktl = '000'.
wa_drao-appnr = '1'.
* wa_drao-zaehl = lv_count .
* APPEND wa_drao TO i_tab_drao .
LOOP AT i_tab_bin_data INTO wa_bin_data .
ADD 1 TO lv_count.
wa_drao-orblk = wa_bin_data.
wa_drao-zaehl = lv_count.
APPEND wa_drao TO i_tab_drao .
ENDLOOP.
** Adding to the JPEG document
* wa_api_ctrl-save_flag = 'X'.
* wa_api_ctrl-api_mode = 'X'.
* wa_api_ctrl-bapi_flag = 'X'.
* wa_api_ctrl-tcode = 'CV01N'.
*Adding image to the DMs document created
IF lv_subrc IS INITIAL.
CALL FUNCTION 'CVAPI_DOC_CHECKIN'
EXPORTING
pf_dokar = lv_doc_type "document type
pf_doknr = lv_doc_num "document number
pf_dokvr = wa_doc_data-documentversion "document version
pf_doktl = wa_doc_data-documentpart "part of document
* pf_ftp_dest = '' "'SAPFTPA'
* pf_http_dest = '''SAPHTTPA'
* pf_hostname = 'DEFAULT'
* ps_api_control = wa_api_ctrl
* pf_replace = 'X'
pf_content_provide = 'TBL' "tbl – takes data FROM a table of binary data (i_tab_drao).
IMPORTING
psx_message = wa_return1
TABLES
pt_files_x = i_tab_originals
pt_content = i_tab_drao.
IF wa_return1-msg_type CA 'EA'.
ROLLBACK WORK.
lv_subrc = 8.
MOVE-CORRESPONDING wa_return1 TO e_message.
ELSE.
COMMIT WORK.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.
Thanks and Regards
Shankar
2016 Jun 20 1:05 PM
You only need to pass the file name and path to the BAPI_DOCUMENT_* function modules, which will do the upload themselves (cf 504692 - Document BAPIs, Checkin - checkout special cases)
2016 Jun 21 7:56 AM
Hi Sandra,
Thanks . I manage to found solution for the issue.
Regards
Shankar
2021 Jul 12 1:12 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |