Hallo zusammen,
es hat nun geklappt.
Anbei ein Testprogramm ohne vernünftige Fehlerbehandlung usw.
Es ermöglicht das Anhängen eines PDF-Originals an einen Doku-Info-Satz von einer Datei auf dem Applikationsserver oder von einem Spoolauftrag.
**********************************************************************************
REPORT zrt_spool_to_dms.
PARAMETERS P_spool TYPE tsp01-rqident.
PARAMETERS P_file TYPE text255.
PARAMETERS p_dokar TYPE dokar OBLIGATORY.
PARAMETERS p_doknr TYPE doknr OBLIGATORY.
PARAMETERS p_dokvr TYPE dokvr OBLIGATORY.
PARAMETERS p_doktl TYPE doktl_D OBLIGATORY.
CLASS lcx_failure DEFINITION INHERITING FROM cx_static_check FINAL.
" Only for demonstration - use your own error classes
ENDCLASS.
CLASS lcl_doku_info_record DEFINITION FINAL.
PUBLIC SECTION.
TYPES svt_file_with_path TYPE text255.
METHODS constructor
IMPORTING iv_dokar TYPE dokar
iv_doknr TYPE doknr
iv_dokvr TYPE dokvr
iv_doktl TYPE doktl_d.
METHODS add_pdf_from_appl_server
IMPORTING iv_file_with_path TYPE svt_file_with_path
iv_filename TYPE filep
iv_description TYPE cV_FILE_DESCRIPTION
iv_storage_cat TYPE cv_storage_cat
RAISING lcx_failure.
METHODS add_pdf_from_spoolid
IMPORTING iv_spoolid TYPE rspoid
iv_filename TYPE filep
iv_description TYPE cV_FILE_DESCRIPTION
iv_storage_cat TYPE cv_storage_cat
RAISING lcx_failure.
PRIVATE SECTION.
DATA av_dokar TYPE dokar.
DATA av_doknr TYPE doknr.
DATA av_dokvr TYPE dokvr.
DATA av_doktl TYPE doktl_d.
METHODS read_app_file_into_xstring
IMPORTING iv_file_with_path TYPE svt_file_with_path
RETURNING VALUE(rv_result) TYPE xstring.
METHODS add_xstring_as_pdf
IMPORTING iv_xstring TYPE xstring
iv_filename TYPE filep
iv_description TYPE cV_FILE_DESCRIPTION
iv_storage_cat TYPE cv_storage_cat
RAISING lcx_failure.
METHODS read_spool_into_xstring
IMPORTING iv_spoolid TYPE rspoid
RETURNING VALUE(rv_result) TYPE xstring
RAISING lcx_failure.
ENDCLASS.
CLASS lcl_doku_info_record IMPLEMENTATION.
METHOD constructor.
av_dokar = iv_dokar. av_doknr = iv_doknr. av_dokvr = iv_dokvr. av_doktl = iv_doktl.
ENDMETHOD.
METHOD add_pdf_from_appl_server.
add_xstring_as_pdf( iv_xstring = read_app_file_into_xstring( iv_file_with_path = iv_file_with_path )
iv_filename = iv_filename
iv_description = iv_description
iv_storage_cat = iv_storage_cat ).
ENDMETHOD.
METHOD read_app_file_into_xstring.
OPEN DATASET iv_file_with_path FOR INPUT IN BINARY MODE.
READ DATASET iv_file_with_path INTO rv_result.
CLOSE DATASET iv_file_with_path.
ENDMETHOD.
METHOD add_xstring_as_pdf.
TYPES: BEGIN OF ls_orblk,
orblk TYPE orblk,
END OF ls_orblk,
ztype_orblk TYPE STANDARD TABLE OF ls_orblk WITH EMPTY KEY.
DATA lv_length TYPE i.
DATA lt_binary TYPE ztype_orblk.
DATA ls_content TYPE drao.
DATA lt_content TYPE dms_tbl_drao.
DATA ls_message TYPE messages.
" Conversion
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = iv_xstring
" APPEND_TO_TABLE = ' '
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_binary.
ls_content = VALUE #( dokar = p_dokar
doknr = p_doknr
dokvr = p_dokvr
doktl = p_doktl
appnr = '1'
orbkl = 2550 ) ##NUMBER_OK.
LOOP AT lt_binary[] ASSIGNING FIELD-SYMBOL().
ls_content-orblk = -orblk.
ls_content-zaehl = sy-tabix.
ls_content-orln = lv_length.
INSERT ls_content INTO TABLE lt_content[].
ENDLOOP.
" add content as a pdf original
DATA(lt_files_x) = VALUE cvapi_tbl_doc_files( ( storage_cat = iv_storage_cat
dappl = 'PDF'
description = iv_description
updateflag = abap_true
filename = iv_filename
appnr = '1'
active_version = abap_true
checked_in = abap_true ) ).
CALL FUNCTION 'CVAPI_DOC_CHECKIN'
EXPORTING
pf_dokar = av_dokar
pf_doknr = av_doknr
pf_dokvr = av_dokvr
pf_doktl = av_doktl
" PS_DOC_STATUS =
" PF_FTP_DEST = ' '
" PF_HTTP_DEST = ' '
" PF_HOSTNAME = ' '
" PS_API_CONTROL =
" PF_REPLACE = ' '
pf_content_provide = 'TBL'
IMPORTING
psx_message = ls_message
TABLES
pt_files_x = lt_files_x
" PT_COMP_X =
pt_content = lt_content[].
IF ls_message IS NOT INITIAL.
RAISE EXCEPTION TYPE lcx_failure.
* ELSE.
" NOP
ENDIF.
ENDMETHOD.
METHOD add_pdf_from_spoolid.
add_xstring_as_pdf( iv_xstring = read_spool_into_xstring( iv_spoolid = iv_spoolid )
iv_filename = iv_filename
iv_description = iv_description
iv_storage_cat = iv_storage_cat ).
ENDMETHOD.
METHOD read_spool_into_xstring.
CLEAR rv_result.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = iv_spoolid
no_dialog = abap_true
get_size_from_format = abap_true
pdf_destination = 'X' " stream
IMPORTING
bin_file = rv_result
EXCEPTIONS
OTHERS = 99.
IF sy-subrc IS NOT INITIAL.
RAISE EXCEPTION TYPE lcx_failure.
* ELSE.
" NOP
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
PERFORM s_o_s.
FORM s_o_s.
DATA lo_dir TYPE REF TO lcl_doku_info_record.
lo_dir = NEW #( iv_dokar = p_dokar
iv_doknr = p_doknr
iv_dokvr = p_dokvr
iv_doktl = p_doktl ).
IF p_fILE IS NOT INITIAL.
TRY.
lo_dir->add_pdf_from_appl_server( iv_file_with_path = p_file
iv_filename = |{ 'C:\temp\File_Attached' }{ '.pdf' }|
iv_description = |{ sy-uzeit } { 'File-Demo' }| ##NO_TEXT
iv_storage_cat = 'DMS_GRZ' ).
CATCH lcx_failure.
WRITE / 'Failure in ADD_PDF_FROM_APPL_SERVER' ##NO_TEXT.
ENDTRY.
* ELSE.
" NOP
ENDIF.
IF p_spool IS NOT INITIAL.
TRY.
lo_dir->add_pdf_from_spoolid( iv_spoolid = p_spool
iv_filename = |{ 'C:\temp\Spool_Attached' }{ '.pdf' }|
iv_description = |{ sy-uzeit } { 'Spool-Demo' }| ##NO_TEXT
iv_storage_cat = 'DMS_GRZ' ).
CATCH lcx_failure.
WRITE / 'Failure in ADD_PDF_FROM_SPOOLID' ##NO_TEXT.
ENDTRY.
* ELSE.
" NOP
ENDIF.
WRITE / 'End-Of-Demo' ##NO_TEXT.
ENDFORM.
**********************************************************************************
MfG
Thomas R.