Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to convert spool output to PDF file properly

Former Member
0 Kudos

Hi guys,

i have got spool which contains russian characters which needs to be converted to PDF file.

Note: ******Assuming user enters only one spool in S_Spool*******

I am using following code to do this:

**---- Get Spool ID Details from TSP01

select * from tsp01 into table i_tsp01 where rqident eq s_spool.

**---- Sort Table in Ascending order based on Spool Id

sort i_tsp01 by rqident.

**---- Get information about Multiple spools

loop at i_tsp01.

**---- Get Multiple Spool information

call function 'RSPO_RETURN_SPOOLJOB'

exporting

rqident = i_tsp01-rqident

tables

buffer = i_spool_table

exceptions

no_such_job = 1

job_contains_no_data = 2

selection_empty = 3

no_permission = 4

can_not_access = 5

read_error = 6

type_no_match = 7

others = 8.

if sy-subrc = 0.

endif.

**---- Get the Last line index (Number of Lines)

describe table i_spool_table lines v_lines.

i_otf[] = i_spool_table[].

endloop.

**---- Convert the OTF information to PDF.

call function 'CONVERT_OTF_2_PDF'

importing

bin_filesize = v_size

tables

otf = i_otf

doctab_archive = i_doc

lines = i_pdf

exceptions

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

others = 3.

if sy-subrc <> 0.

message i002(sy) with 'Cannot convert to PDF, exiting....'.

leave program.

endif.

DATA: v_numbytes TYPE i.

DATA : v_return1(128).

CONCATENATE 'C:\' 'F_spool' '.pdf' INTO v_return1.

CONDENSE v_return1.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = v_size

filename = v_return1

filetype = 'BIN'

IMPORTING

filelength = v_numbytes

TABLES

data_tab = i_pdf

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10 .

IF sy-subrc NE 0.

EXIT.

ENDIF.

i have already tried standard pgm : RSTXPDFT4. But it does not work.

Suitable answers will be rewarded.

Thanks,

GURU

8 REPLIES 8

messier31
Active Contributor
0 Kudos

Hi,

RSTXPDFT4 is a standard program which converts spool request into pdf download. You may try converting your spool using this standard program.

If it works correctly you can refer the logic from this program.

Enjoy SAP.

Pankaj Singh.

Former Member
0 Kudos

Hi guys,

i have already tried standard pgm : RSTXPDFT4. But it does not work.

Regards,

GURU

Former Member
0 Kudos

Hi Guru,

Use FM 'CONVERT_ABAPSPOOLJOB_2_PDF'.

Refer this code:

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

IMPORTING

pdf_bytecount = gd_bytecount

TABLES

pdf = it_pdf_output

EXCEPTIONS

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

OTHERS = 12.

CHECK sy-subrc = 0.

  • Transfer the 132-long strings to 255-long strings

LOOP AT it_pdf_output.

TRANSLATE it_pdf_output USING ' ~'.

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

ENDLOOP.

TRANSLATE gd_buffer USING '~ '.

DO.

it_mess_att = gd_buffer.

APPEND it_mess_att.

SHIFT gd_buffer LEFT BY 255 PLACES.

IF gd_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

Regards,

Hemant

0 Kudos

What is the use of following code ? Type of gd_buffer?

  • Transfer the 132-long strings to 255-long strings

LOOP AT it_pdf_output.

TRANSLATE it_pdf_output USING ' ~'.

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

ENDLOOP.

TRANSLATE gd_buffer USING '~ '.

Regards,

GURU

0 Kudos

Hi Guru,

You can skip that code.

Actually I have pasted that code from one of my code.

Regards,

Hemant

0 Kudos

No..It does not work with FM

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'.

Regards,

GURU

former_member223537
Active Contributor
0 Kudos

Hi,

Please refer following sample program:

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

It is very well commented & self explanatory.

Best regards,

Prashant

0 Kudos

Hi guys,

Any update on the above issue?