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: 

Convert Spool request to PDF format to your local drive

Former Member
0 Kudos

Hi,

How can we Convert Spool request to PDF format to your local drive?

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I am pasting the abap code that will help u to convert the pool request to pdf format to ur local dirve...

go throuth the program... this will help u out.. Please reward point if it is use ful.

Regards

Maneesh Chandran

PROGRAM.....

report Zbc_pdf_download

no standard page heading.

$$----


*

$$ Data definitions *

$$----


*

tables:

tsp01. " Spool requests

data:

gt_otf like itcoo occurs 100 with header line,

g_cancel type c,

gt_pdf like tline occurs 100 with header line,

gt_doctab like docs occurs 1 with header line,

g_numbytes type i,

g_arc_idx like toa_dara,

g_pdfspoolid like tsp01-rqident,

g_jobname like tbtcjob-jobname,

g_jobcount like tbtcjob-jobcount,

g_otf_format type c,

g_client like tst01-dclient,

g_name like tst01-dname,

g_objtype like rststype-type,

g_type like rststype-type,

g_filename type string,

g_path like rlgrap-filename,

g_mask(20) type c value ',.pdf ,.pdf. '.

data: v_file type string.

$$----


*

$$ Selection screen definition *

$$----


*

parameters:

p_splno like tsp01-rqident,

p_file like rlgrap-filename obligatory."Source file name

$$----


*

$$ Start of selection processing *

$$----


*

at selection-screen on value-request for p_file.

************************************************

perform dynp_getval using 'P_FILE' changing p_file.

perform get_filename changing p_file.

start-of-selection.

*... Verify spool number and get client, name and determine spool type

perform validate_spool_number.

*... Convert spool to PDF

perform convert_spool_to_pdf.

*... Physicaly download the file

perform download_pdf.

$$----


*

$$ FORMs *

$$----


*

form validate_spool_number.

*... Verify spool number and get client and name data

select single rqclient

rqo1name

into (g_client,

g_name )

from tsp01

where rqident eq p_splno.

  • Output error message if not found

if sy-subrc ne 0.

message i010(ad)

with 'Spool number'

p_splno

'could not be found'.

stop.

endif.

*... Ascertain spool object type

call function 'RSTS_GET_ATTRIBUTES'

exporting

authority = 'SP01'

client = g_client

name = g_name

part = 1

importing

type = g_type

objtype = g_objtype

exceptions

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

*... Set spool type

clear g_otf_format.

if g_objtype(3) eq 'OTF'.

move 'X' to g_otf_format.

endif.

endform. " VALIDATE_SPOOL_NUMBER

$$----


*

form convert_spool_to_pdf.

if g_otf_format eq 'X'.

  • OTF spool object conversion

call function 'CONVERT_OTFSPOOLJOB_2_PDF'

exporting

src_spoolid = p_splno

no_dialog = ' '

importing

pdf_bytecount = g_numbytes

pdf_spoolid = g_pdfspoolid

btc_jobname = g_jobname

btc_jobcount = g_jobcount

tables

pdf = gt_pdf

exceptions

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 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.

else.

  • ABAP list spool object conversion

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = p_splno

no_dialog = ' '

importing

pdf_bytecount = g_numbytes

pdf_spoolid = g_pdfspoolid

btc_jobname = g_jobname

btc_jobcount = g_jobcount

tables

pdf = gt_pdf

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.

endif.

*... Output error message if conversion failed

if sy-subrc ne 0.

message i010(ad)

with 'Cannot convert spool'

p_splno

'to PDF'.

stop.

endif.

endform. " CONVERT_SPOOL_TO_PDF

$$----


*

form download_pdf.

g_filename = p_file.

*... Download to presentation server file system

call function 'GUI_DOWNLOAD'

exporting

bin_filesize = g_numbytes

filename = g_filename

filetype = 'BIN'

  • importing

  • act_filename = g_filename

  • filesize = g_numbytes

  • cancel = g_cancel

tables

data_tab = gt_pdf

exceptions

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

others = 22.

*... Output success message

if sy-subrc = 0.

message i010(ad)

with 'PDF writen for spool number'

p_splno.

stop.

else.

message i010(ad) with 'Error creating file!'.

endif.

endform. " DOWNLOAD_PDF

&----


*& Form dynp_getval

&----


  • text

----


  • -->NAME text

  • -->VAL text

----


form dynp_getval using name

changing val.

data:

t_dval like dynpread occurs 0 with header line,

l_repid like sy-repid.

refresh t_dval.

move name to t_dval-fieldname.

append t_dval.

move sy-repid to l_repid.

call function 'DYNP_VALUES_READ'

exporting

dyname = l_repid

dynumb = sy-dynnr

tables

dynpfields = t_dval

exceptions

invalid_abapworkarea = 1

invalid_dynprofield = 2

invalid_dynproname = 3

invalid_dynpronummer = 4

invalid_request = 5

no_fielddescription = 6

invalid_parameter = 7

undefind_error = 8

double_conversion = 9

stepl_not_found = 10

others = 11.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

read table t_dval index 1.

move t_dval-fieldvalue to val.

endform. " dynp_getval

*----


*Opens a GUI dialog to search for the file name

*----


form get_filename changing file.

data: t_file like sdokpath occurs 0 with header line.

call function 'TMP_GUI_FILE_OPEN_DIALOG'

exporting

window_title = 'Open file for SAP program'(opn)

default_extension = '*.txt'

default_filename = file

tables

file_table = t_file

exceptions

cntl_error = 1

others = 2.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

check sy-subrc eq 0.

read table t_file index 1.

move t_file to file.

endform. "get_filename

4 REPLIES 4

Former Member
0 Kudos

Hi,

TRY THIS CODE

DATA: fm_name TYPE rs38l_fnam,control TYPE ssfctrlop, op TYPE ssfcompop,
      p_form TYPE tdsfname VALUE 'ZTAX_COMPU',
      errtab  TYPE tsferror,spoolid TYPE ssfcrescl.

DATA:t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
* Internal table to hold OTF data recd from the SMARTFORM
*T_OTF_FROM_FM TYPE SSFCRESCL,

* Internal table to hold the data from the FM CONVERT_OTF
t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA:

*w_form_name TYPE tdsfname VALUE 'ZSURESH_TEST',
w_fmodule TYPE rs38l_fnam,
w_cparam TYPE ssfctrlop,
w_outoptions TYPE ssfcompop,
w_bin_filesize TYPE i, " Binary File Size
w_file_name TYPE string,
w_file_path TYPE string,
w_full_path TYPE string,pnrno(8),ldate TYPE sy-datum.

 CALL FUNCTION fm_name
  EXPORTING
*     ARCHIVE_INDEX              =
*     ARCHIVE_INDEX_TAB          =
*     ARCHIVE_PARAMETERS         =
      control_parameters         = control
*     MAIL_APPL_OBJ              =
*     MAIL_RECIPIENT             =
*     MAIL_SENDER                =
      output_options             = op
      user_settings              = ' '
      emp_no                     = itab-emp_no
      proc_yyyymm                = procyymm
      category                   = itab-category
      sp1                        = wa
      sp2                        = wa1
      itexem                     = exem
    TABLES
      it_etc                     = it_etc
      it_f16                     = it_f16
      it_hrc                     = it_hrc
   EXCEPTIONS
     formatting_error           = 1
     internal_error             = 2
     send_error                 = 3
     user_canceled              = 4
     OTHERS                     = 5
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL FUNCTION 'SSF_CLOSE'
    IMPORTING
      job_output_info  = spoolid
    EXCEPTIONS
      formatting_error = 1
      internal_error   = 2
      send_error       = 3
      OTHERS           = 4.

  IF sy-subrc <> 0.
*   error handling
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  REFRESH : it_etc,it_f16,it_hrc.CLEAR : it_etc,it_f16,it_hrc.

  t_otf[] = spoolid-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     format                      = 'PDF'
     max_linewidth               = 10
   IMPORTING
     bin_filesize                = w_bin_filesize
*   BIN_FILE                    =
    TABLES
      otf                         = t_otf
      lines                       = t_pdf_tab
   EXCEPTIONS
     err_max_linewidth           = 1
     err_format                  = 2
     err_conv_not_possible       = 3
     err_bad_otf                 = 4
     OTHERS                      = 5
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  CLEAR:w_full_path.
  IF itab-pnrno NA sy-abcde.
    UNPACK itab-pnrno TO itab-pnrno.
  ENDIF.
  pnrno = itab-pnrno+2(8).
*  SHIFT pnrno LEFT DELETING LEADING '0'.
  CONCATENATE path '\' pnrno '.pdf' INTO w_full_path.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize = w_bin_filesize
      filename     = w_full_path
      filetype     = 'BIN'
    TABLES
      data_tab     = t_pdf_tab.
  CLEAR w_full_path.
  CONCATENATE 'Download completed for Employee - ' itab-emp_no  INTO w_full_path SEPARATED BY space.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
   EXPORTING
*         PERCENTAGE       = 0
     text             = w_full_path.
  CLEAR : t_otf,spoolid, t_pdf_tab,pnrno.
  REFRESH : t_otf, t_pdf_tab.

Regards,

V.Balaji

Reward if Usefull...

Former Member
0 Kudos

Hi,

I am pasting the abap code that will help u to convert the pool request to pdf format to ur local dirve...

go throuth the program... this will help u out.. Please reward point if it is use ful.

Regards

Maneesh Chandran

PROGRAM.....

report Zbc_pdf_download

no standard page heading.

$$----


*

$$ Data definitions *

$$----


*

tables:

tsp01. " Spool requests

data:

gt_otf like itcoo occurs 100 with header line,

g_cancel type c,

gt_pdf like tline occurs 100 with header line,

gt_doctab like docs occurs 1 with header line,

g_numbytes type i,

g_arc_idx like toa_dara,

g_pdfspoolid like tsp01-rqident,

g_jobname like tbtcjob-jobname,

g_jobcount like tbtcjob-jobcount,

g_otf_format type c,

g_client like tst01-dclient,

g_name like tst01-dname,

g_objtype like rststype-type,

g_type like rststype-type,

g_filename type string,

g_path like rlgrap-filename,

g_mask(20) type c value ',.pdf ,.pdf. '.

data: v_file type string.

$$----


*

$$ Selection screen definition *

$$----


*

parameters:

p_splno like tsp01-rqident,

p_file like rlgrap-filename obligatory."Source file name

$$----


*

$$ Start of selection processing *

$$----


*

at selection-screen on value-request for p_file.

************************************************

perform dynp_getval using 'P_FILE' changing p_file.

perform get_filename changing p_file.

start-of-selection.

*... Verify spool number and get client, name and determine spool type

perform validate_spool_number.

*... Convert spool to PDF

perform convert_spool_to_pdf.

*... Physicaly download the file

perform download_pdf.

$$----


*

$$ FORMs *

$$----


*

form validate_spool_number.

*... Verify spool number and get client and name data

select single rqclient

rqo1name

into (g_client,

g_name )

from tsp01

where rqident eq p_splno.

  • Output error message if not found

if sy-subrc ne 0.

message i010(ad)

with 'Spool number'

p_splno

'could not be found'.

stop.

endif.

*... Ascertain spool object type

call function 'RSTS_GET_ATTRIBUTES'

exporting

authority = 'SP01'

client = g_client

name = g_name

part = 1

importing

type = g_type

objtype = g_objtype

exceptions

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

*... Set spool type

clear g_otf_format.

if g_objtype(3) eq 'OTF'.

move 'X' to g_otf_format.

endif.

endform. " VALIDATE_SPOOL_NUMBER

$$----


*

form convert_spool_to_pdf.

if g_otf_format eq 'X'.

  • OTF spool object conversion

call function 'CONVERT_OTFSPOOLJOB_2_PDF'

exporting

src_spoolid = p_splno

no_dialog = ' '

importing

pdf_bytecount = g_numbytes

pdf_spoolid = g_pdfspoolid

btc_jobname = g_jobname

btc_jobcount = g_jobcount

tables

pdf = gt_pdf

exceptions

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 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.

else.

  • ABAP list spool object conversion

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = p_splno

no_dialog = ' '

importing

pdf_bytecount = g_numbytes

pdf_spoolid = g_pdfspoolid

btc_jobname = g_jobname

btc_jobcount = g_jobcount

tables

pdf = gt_pdf

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.

endif.

*... Output error message if conversion failed

if sy-subrc ne 0.

message i010(ad)

with 'Cannot convert spool'

p_splno

'to PDF'.

stop.

endif.

endform. " CONVERT_SPOOL_TO_PDF

$$----


*

form download_pdf.

g_filename = p_file.

*... Download to presentation server file system

call function 'GUI_DOWNLOAD'

exporting

bin_filesize = g_numbytes

filename = g_filename

filetype = 'BIN'

  • importing

  • act_filename = g_filename

  • filesize = g_numbytes

  • cancel = g_cancel

tables

data_tab = gt_pdf

exceptions

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

others = 22.

*... Output success message

if sy-subrc = 0.

message i010(ad)

with 'PDF writen for spool number'

p_splno.

stop.

else.

message i010(ad) with 'Error creating file!'.

endif.

endform. " DOWNLOAD_PDF

&----


*& Form dynp_getval

&----


  • text

----


  • -->NAME text

  • -->VAL text

----


form dynp_getval using name

changing val.

data:

t_dval like dynpread occurs 0 with header line,

l_repid like sy-repid.

refresh t_dval.

move name to t_dval-fieldname.

append t_dval.

move sy-repid to l_repid.

call function 'DYNP_VALUES_READ'

exporting

dyname = l_repid

dynumb = sy-dynnr

tables

dynpfields = t_dval

exceptions

invalid_abapworkarea = 1

invalid_dynprofield = 2

invalid_dynproname = 3

invalid_dynpronummer = 4

invalid_request = 5

no_fielddescription = 6

invalid_parameter = 7

undefind_error = 8

double_conversion = 9

stepl_not_found = 10

others = 11.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

read table t_dval index 1.

move t_dval-fieldvalue to val.

endform. " dynp_getval

*----


*Opens a GUI dialog to search for the file name

*----


form get_filename changing file.

data: t_file like sdokpath occurs 0 with header line.

call function 'TMP_GUI_FILE_OPEN_DIALOG'

exporting

window_title = 'Open file for SAP program'(opn)

default_extension = '*.txt'

default_filename = file

tables

file_table = t_file

exceptions

cntl_error = 1

others = 2.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

check sy-subrc eq 0.

read table t_file index 1.

move t_file to file.

endform. "get_filename

Former Member
0 Kudos

Hi,

use the program RSTXPDFT4.

Regards,

Morris Bond.

Reward Points if Helpful.

Former Member
0 Kudos

Hi,

After sending your ABAP List or SAP Scripts to the spool request (SP01), you can use the SAP standard spool PDF conversion program.

RSTXPDFT4 - Convert ABAP List and SAP Script to PDF files

Reawarvd if helpfull..

Cheers,

vasavi.