CALL FUNCTION 'CVAPI_DOC_VIEW'
EXPORTING
pf_dokar = <Doc Type>
pf_doknr = <Doc Number>
pf_dokvr = <Doc Version>
pf_doktl = <Doc Part>
pf_apptp = '3' " app type print = 3
pf_parent = blank
IMPORTING
pfx_file = lv_filename "File path
EXCEPTIONS
error = 1
not_found = 2
no_auth = 3
no_original = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document = <File path with filename to print>
synchronous = 'X' "until user closes acrobat application further processing does not happen
operation = 'PRINT'
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10.
IF sy-subrc NE 0.
* Implement suitable error handling here
ENDIF.
DATA: it_pdf TYPE STANDARD TABLE OF tline,
lt_lines TYPE STANDARD TABLE OF tline,
lt_binary TYPE STANDARD TABLE OF raw255,
ls_pdf TYPE tline,
ls_binary TYPE raw255,
lv_content TYPE xstring,
lv_length TYPE sy-tabix,
lv_raw TYPE rsrd_rawstring,
lv_spool_id TYPE rspoid,
lv_partname TYPE adspart,
lv_fname_spool TYPE char256,
lv_dest TYPE rspopname,
lv_spool_handle TYPE sytabix.
FIELD-SYMBOLS <fs_x> TYPE x.
*upload the file: could be local system or shared folders
*lv_filename contains the file path with name . this can be found in DRAW table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename
filetype = 'BIN'
IMPORTING
filelength = lv_length
TABLES
data_tab = it_pdf.
*concatenate all data into one string
LOOP AT it_pdf INTO ls_pdf.
ASSIGN ls_pdf TO <fs_x> CASTING.
CONCATENATE lv_content <fs_x> INTO lv_content IN BYTE MODE.
ENDLOOP.
*convert form xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_binary.
LOOP AT lt_binary INTO ls_binary.
ASSIGN ls_binary TO <fs_x> CASTING.
CONCATENATE lv_raw <fs_x> INTO lv_raw IN BYTE MODE.
ENDLOOP.
*Open Spool
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = 'LCPD' " // your output device
doctype = 'ADSP'
immediate_print = 'X'
auto_delete = 'X'
IMPORTING
handle = lv_spool_handle
spoolid = lv_spool_id
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
wrong_devicetype = 5
OTHERS = 6.
IF sy-subrc NE 0.
ENDIF.
*Reads the content of a part file of an ADS spool
CALL FUNCTION 'ADS_GET_PARTFILE_NAME'
EXPORTING
rqident = lv_spool_id
partnumber = 1
IMPORTING
partname = lv_partname.
CONCATENATE lv_partname '.pdf' INTO lv_fname_spool.
*write binary content to spool
CALL FUNCTION 'ADS_WRITE_TO_FILE'
EXPORTING
filename = lv_fname_spool
buffer = lv_raw
EXCEPTIONS
cannot_open_file = 1
open_dataset_no_authority = 2
open_dataset_internal_error = 3
open_dataset_too_many_files = 4
dataset_cant_close = 5
close_dataset_internal_error = 6
cannot_close_file = 7
cannot_transfer_data = 8
transfer_internal_error = 9
dataset_write_error = 10
OTHERS = 11.
*Write a line in an open ADS spool request
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = lv_spool_handle
partname = lv_partname
size = lv_length
pages = 1
IMPORTING
new_partname = lv_partname
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
*close the spool request
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = lv_spool_handle
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
WAIT UP TO 10 SECONDS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |