cancel
Showing results for 
Search instead for 
Did you mean: 

DMS(Database Management System) in HANA While trying to upload Document using BAPI. File is not open

03-28-2024 6:37 AM
yashi2002 Discoverer
700 views 0 comments
0 Likes
SAP Managed Tags
Subscribe

Step1- Firstly, there is one Report Program which is created that is ZPM_DMS_AIRDIT.                     

yashi2002_0-1711603416867.png

 

Inside this we have called two Function Modules which is-

  1. BAPI_DOCUMENT_CREATE2
  2. CVAPI_DOC_CHECKIN

Here, we are uploading the Document through the Report Program and the same Document we are trying to open in CV03N T-code.

Step2-

yashi2002_1-1711603416868.png

 

yashi2002_2-1711603416876.png

 

 

While clicking on the F4 we are getting Pop-up for attaching the file from the PC.

 

yashi2002_3-1711603416877.png

 

Step3- Once uploading the file from the F4.

yashi2002_4-1711603416877.png

 

After executing the Report Program, we are getting the Document Number.

                                        

yashi2002_5-1711603416878.png

 

Step4- The same Document Number Once we will execute in the T-code CV03N.

                       

yashi2002_6-1711603416882.png

 

Step5-   Once, Opening the above document->

Once we are trying to open the file in Browser it is not opening. The error which is coming is-

yashi2002_7-1711603416884.png

The Program is-> 

REPORT zpm_dms_airdit.

PARAMETERS:p_file TYPE localfile.

DATA:ls_documentdata TYPE bapi_doc_draw2,
lt_text TYPE STANDARD TABLE OF bapi_doc_drat,
lt_files TYPE STANDARD TABLE OF bapi_doc_files2,
lt_objectlinks TYPE TABLE OF bapi_doc_drad,
lt_binary_tab TYPE TABLE OF sdokcntbin,
lt_drao TYPE TABLE OF drao,
lt_file TYPE TABLE OF cvapi_doc_file,
ls_file TYPE cvapi_doc_file,
ls_xstring TYPE xstring,
lv_length TYPE i,
lv_filename TYPE string,
lv_doctype TYPE dokar VALUE 'ZIP',
lv_docnum TYPE doknr,
lv_docpart TYPE doktl_d VALUE '000',
lv_docver TYPE dokvr VALUE '00',
ls_return TYPE bapiret2,
ls_file1 TYPE bapi_doc_files2,
lt_file1 TYPE TABLE OF bapi_doc_files2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file.
lv_filename = p_file.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename
IMPORTING
filelength = lv_length
TABLES
data_tab = lt_binary_tab
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.

ls_file-filename = 'test_dms.pdf'.
ls_file-storage_cat = 'ZCDV'.
ls_file-dappl = 'PDF'.
ls_file-description = 'Measuring Document'.
ls_file-checked_in = 'X'.
ls_file-dttrg = 'Default'.
ls_file-langu = sy-langu.
ls_file-active_version = 'X'.
ls_file-created_at = sy-datum.
ls_file-created_by = sy-uname.
ls_file-updateflag = ' '.
APPEND ls_file TO lt_file.

lt_text = VALUE #( ( language = sy-langu language_iso = sy-langu description = 'Measuring Document' ) ).

lt_objectlinks = VALUE #( ( objecttype = 'IMRG' objectkey = '00000000000000000532' ) ).

ls_documentdata-documenttype = 'ZIP'.
ls_documentdata-documentpart = '000'.
ls_documentdata-documentversion = '00'.
ls_documentdata-createdate = sy-datum.
ls_documentdata-createdate = sy-datum.
ls_documentdata-username = sy-uname.
ls_documentdata-description = 'Measuring Document'.
ls_documentdata-wsapplication1 = 'PDF'.
ls_documentdata-wsapplication2 = 'PDF'.
ls_documentdata-statusextern = 'CR'.


CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
documentdata = ls_documentdata
IMPORTING
documentnumber = lv_docnum
documentpart = lv_docpart
documenttype = lv_doctype
documentversion = lv_docver
return = ls_return
TABLES
objectlinks = lt_objectlinks
documentdescriptions = lt_text.

IF ls_return-type = 'E'.
ROLLBACK WORK.
ELSE.
COMMIT WORK.
ENDIF.

DATA:ls_api_cntl TYPE cvapi_api_control,
ls_msg TYPE messages,
ls_status TYPE cvapi_doc_status.
ls_api_cntl-no_update_task = 'X'.
ls_api_cntl-commit_flag = 'X'.
ls_api_cntl-save_flag = 'X'.
ls_api_cntl-load_flag = 'X'.
ls_api_cntl-init_text = 'X'.
ls_api_cntl-bapi_flag = 'X'.
ls_status-dokst = 'CR'.

LOOP AT lt_binary_tab INTO DATA(ls_binary_tab).
DATA(ls_drao) = VALUE drao( dokar = lv_doctype
doknr = lv_docnum " This will create DIR Number
dokvr = lv_docver
doktl = lv_docpart
appnr = '1'
zaehl = sy-tabix
orblk = ls_binary_tab-line
orln = lv_length
orbkl = 2550
).
APPEND ls_drao TO lt_drao.
CLEAR: ls_drao.
ENDLOOP.

IF lv_docnum IS NOT INITIAL.
CALL FUNCTION 'CVAPI_DOC_CHECKIN'
DESTINATION 'NONE'
EXPORTING
pf_dokar = lv_doctype
pf_doknr = lv_docnum
pf_dokvr = lv_docver
pf_doktl = lv_docpart
ps_doc_status = ls_status
pf_ftp_dest = 'SAPFTPA'
pf_http_dest = 'SAPHTTPA'
pf_hostname = 'DEFAULT'
ps_api_control = ls_api_cntl
pf_replace = 'X'
pf_content_provide = 'TBL' "TBL – takes data from a table of binary data (lt_binary_tab)
IMPORTING
psx_message = ls_msg
TABLES
pt_files_x = lt_file
pt_content = lt_drao.

IF ls_msg-msg_type CA 'EA'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.

ENDIF.
ENDIF.
write : 'Document number :', lv_docnum.

 

0 Likes

Accepted Solutions (0)

Answers (0)