cancel
Showing results for 
Search instead for 
Did you mean: 

Report to print (production order) documents from Transaction CV03N

peterpiry
Explorer
0 Kudos

Hi,

we attach documents to the material in transaction CV01N/CV02N.

I wrote a report, to print out the documents by entering the number of a production order.

My problem is that attached PDFs are printed as text, I have some hundred pages on the printer. The real content of the PDF is not printed. It's the correct PDF, I can see the correct characters.

Here is the report. Does anyone know where my problem is?

*&---------------------------------------------------------------------*
*& Report ZZPP_FERTAUF_DRUCK_DOK
*&
*&---------------------------------------------------------------------*

REPORT zzpp_fertauf_druck_dok.

PARAMETERS: p_aufnr TYPE afdld-aufnr,
p_dokar TYPE afdld-dokar.


DATA: lt_afdld TYPE afdld_tab,
ls_afdld LIKE afdld.


DATA: lv_bapi_doctype TYPE bapi_doc_aux-doctype,
lv_bapi_docnumber TYPE bapi_doc_aux-docnumber,
lv_bapi_docpart TYPE bapi_doc_aux-docpart,
lv_bapi_docversion TYPE bapi_doc_aux-docversion,
ls_documentfile TYPE bapi_doc_files2,
lv_docpath TYPE bapi_doc_aux-filename,
lt_documentfiles TYPE TABLE OF bapi_doc_files2,
lt_docfiles TYPE TABLE OF bapi_doc_files2,
ls_docfile TYPE bapi_doc_files2.



*DATA: lv_docfile TYPE filep.
DATA: lv_docfile(200) TYPE c.

DATA: lv_handle TYPE sy-tabix,
lv_spoolid TYPE tsp01-rqident,
lv_partname TYPE adspart.

DATA: ev_retcode TYPE sy-subrc.

DATA: lv_globaldir TYPE string.
DATA: c_path TYPE string.

DATA: lv_file_exists TYPE flag.

DATA: lv_dstfile TYPE string,
lv_filename TYPE string.

DATA: lv_data TYPE x.


DATA: ls_cvddockey TYPE cvddockey.
DATA: ls_rcrepfile TYPE rcgrepfile,
lt_rcrepfile TYPE TABLE OF rcgrepfile.


*DATA: ls_pdf TYPE tline,
* lt_pdf TYPE standard TABLE OF tline.

DATA: lv_content TYPE xstring.
FIELD-SYMBOLS <fs_x> TYPE x.


DATA: ls_binary TYPE raw255,
lt_binary TYPE STANDARD TABLE OF raw255,
lv_length TYPE sy-tabix,
lv_raw TYPE rsrd_rawstring.

DATA: lv_spool_id TYPE rspoid,
lv_spool_handle TYPE sytabix.

DATA: lv_fname_spool TYPE char256.



DATA: lv_filesize TYPE i,
lv_pages TYPE i.


DATA: BEGIN OF lt_file OCCURS 0,
field(255),
END OF lt_file.

* get all document info records
CALL FUNCTION 'CO_DM_AFDLD_READ_KEY'
EXPORTING

i_aufnr

= p_aufnr
TABLES
et_afdld = lt_afdld.


c_path = 'C:\TEMP\'.

* Identify the documents by dokar
LOOP AT lt_afdld INTO ls_afdld WHERE dokar = p_dokar.

lv_bapi_doctype = ls_afdld-dokar.
lv_bapi_docnumber = ls_afdld-doknr.
lv_bapi_docpart = ls_afdld-doktl.
lv_bapi_docversion = ls_afdld-dokvr.
ls_documentfile-wsapplication = 'PDF'.

CONCATENATE c_path sy-sysid '\' INTO lv_docpath.



* temporary download of document, works
CALL FUNCTION 'BAPI_DOCUMENT_CHECKOUTVIEW2'
EXPORTING
documenttype = lv_bapi_doctype
documentnumber =

lv_bapi_docnumber

documentpart = lv_bapi_docpart
documentversion = lv_bapi_docversion
documentfile = ls_documentfile
originalpath = lv_docpath
TABLES
documentfiles = lt_documentfiles.

APPEND LINES OF lt_documentfiles TO lt_docfiles.
CLEAR lt_documentfiles.


* get Byte-Stream
ls_cvddockey-dokar = ls_afdld-dokar.
ls_cvddockey-doknr = ls_afdld-doknr.
ls_cvddockey-doktl = ls_afdld-doktl.
ls_cvddockey-dokvr = ls_afdld-dokvr.
CALL FUNCTION 'C14S_DOCUMENT_ORIGINAL_COPY'
EXPORTING
i_dockey = ls_cvddockey
* I_APPNO = 1
* I_DAPPL =
* IMPORTING
* E_FILESIZE =
* E_APPNO =
TABLES
e_repfile = lt_rcrepfile
* E_EXTERROR_TAB =
* EXCEPTIONS
* CHECKOUT_ORIG_FAILED = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.



* concatenate all data into one string
LOOP AT lt_rcrepfile INTO ls_rcrepfile.
ASSIGN ls_rcrepfile 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 = 'WI70' " // 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.




ENDLOOP.


SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S31 { font-style: italic; color: #808080; }.L0S32 { color: #3399FF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }

Accepted Solutions (0)

Answers (0)