Application Development and Automation 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: 
Read only

Error in opening pdf file

Former Member
0 Likes
1,388

HI,

Iam uploading a text file and it has to convert to pdf file and download to local system. I used hte following program.

REPORT ZABAPSPOOL.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

DATA : handle LIKE sy-tabix.

DATA : spoolid LIKE tsp01-rqident.

DATA : rc(10) ,

errmsg LIKE tsp01-rqtitle.

DATA : file_name TYPE string.

*----


Screen.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

*----


Start of Selection.

file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'ASC'

has_field_separator = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = t001

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*----


For spool

*----


CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'

EXPORTING

dest = 'LOCL'

IMPORTING

handle = handle

spoolid = spoolid

rc = rc

errmessage = errmsg.

.

WRITE errmsg.

loop at t001.

CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'

EXPORTING

handle = handle

text = t001-bukrs

IMPORTING

rc = rc

errmessage = errmsg

EXCEPTIONS

handle_not_valid = 1

OTHERS = 2.

endloop.

*----


WRITE errmsg.

CALL FUNCTION 'RSPO_CLOSE_SPOOLREQUEST'

EXPORTING

handle = handle

IMPORTING

rc = rc

errmessage = errmsg

EXCEPTIONS

handle_not_valid = 1

OTHERS = 2.

WRITE errmsg.

WRITE spoolid.

From the above prg i will be getting the spoolid and giving the spoolid number to the following program.

PARAMETERS:

SPOOLNO LIKE TSP01-RQIDENT,

DOWNLOAD AS CHECKBOX DEFAULT 'X',

P_FILE LIKE RLGRAP-FILENAME DEFAULT 'd:\sri\srifile.pdf'. "#EC NOTEXT

DATA otf like itcoo occurs 100 with header line.

DATA CANCEL.

DATA PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.

DATA DOCTAB LIKE DOCS OCCURS 1 WITH HEADER LINE.

DATA: NUMBYTES TYPE I,

ARC_IDX LIKE TOA_DARA,

pdfspoolid like tsp01-rqident,

jobname like tbtcjob-jobname,

jobcount like tbtcjob-jobcount,

is_otf.

data: client like tst01-dclient,

name like tst01-dname,

objtype like rststype-type,

type like rststype-type.

tables: tsp01.

select single * from tsp01 where rqident = spoolno.

if sy-subrc <> 0.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_negative.

exit.

endif.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

AUTHORITY = 'SP01'

CLIENT = client

NAME = name

PART = 1

IMPORTING

  • CHARCO =

  • CREATER =

  • CREDATE =

  • DELDATE =

  • MAX_CREDATE =

  • MAX_DELDATE =

  • NON_UNIQ =

  • NOOF_PARTS =

  • RECTYP =

  • SIZE =

  • STOTYP =

TYPE = type

OBJTYPE = objtype

EXCEPTIONS

FB_ERROR = 1

FB_RSTS_OTHER = 2

NO_OBJECT = 3

NO_PERMISSION = 4.

if objtype(3) = 'OTF'.

is_otf = 'X'.

else.

is_otf = space.

endif.

if is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = spoolno

NO_DIALOG = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = numbytes

PDF_SPOOLID = pdfspoolid

  • OTF_PAGECOUNT =

BTC_JOBNAME = jobname

BTC_JOBCOUNT = jobcount

TABLES

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

case sy-subrc.

when 0.

WRITE: / 'Funktion CONVERT_OTFSPOOLJOB_2_PDF erfolgreich'(001)

COLOR COL_POSITIVE.

when 1.

WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)

COLOR COL_negative.

exit.

when 2.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_negative.

exit.

when 3.

WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)

COLOR COL_negative.

exit.

when others.

WRITE: / 'Fehler bei Funktion CONVERT_OTFSPOOLJOB_2_PDF'(005)

COLOR COL_negative.

exit.

endcase.

else.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = spoolno

NO_DIALOG = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = numbytes

PDF_SPOOLID = pdfspoolid

  • LIST_PAGECOUNT =

BTC_JOBNAME = jobname

BTC_JOBCOUNT = jobcount

TABLES

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

case sy-subrc.

when 0.

WRITE: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich'(006)

COLOR COL_POSITIVE.

when 1.

WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)

COLOR COL_negative.

exit.

when 2.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_negative.

exit.

when 3.

WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)

COLOR COL_negative.

exit.

when others.

WRITE: / 'Fehler bei Funktion CONVERT_ABAPSPOOLJOB_2_PDF'(007)

COLOR COL_negative.

exit.

endcase.

endif.

                              • download PDF file ***********

check download = 'X'.

if not ( jobname is initial ).

WRITE: / 'Konvertierung per Hintergrundjob'(008)

COLOR COL_normal,

jobname, jobcount.

exit.

endif.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

BIN_FILESIZE = NUMBYTES

FILENAME = P_FILE

FILETYPE = 'BIN'

IMPORTING

ACT_FILENAME = P_FILE

FILESIZE = NUMBYTES

CANCEL = CANCEL

TABLES

DATA_TAB = PDF.

if cancel = space.

WRITE: / NUMBYTES, 'Bytes heruntergeladen in Datei'(009), P_FILE.

endif.

Wheni execute the program and enter the spoolid number the file will be downloaded but when i try to open the file it is giving the following error:

<b></b>There was an error opening this

document. This file cannot be opened

because it has no pages.

<b></b>.

Please help me out.

Thanks,

Pavan.

HI,

Iam uploading a text file and it has to convert to pdf file and download to local system. I used hte following program.

REPORT ZABAPSPOOL.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

DATA : handle LIKE sy-tabix.

DATA : spoolid LIKE tsp01-rqident.

DATA : rc(10) ,

errmsg LIKE tsp01-rqtitle.

DATA : file_name TYPE string.

*----


Screen.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

*----


Start of Selection.

file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'ASC'

has_field_separator = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = t001

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*----


For spool

*----


CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'

EXPORTING

dest = 'LOCL'

IMPORTING

handle = handle

spoolid = spoolid

rc = rc

errmessage = errmsg.

.

WRITE errmsg.

loop at t001.

CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'

EXPORTING

handle = handle

text = t001-bukrs

IMPORTING

rc = rc

errmessage = errmsg

EXCEPTIONS

handle_not_valid = 1

OTHERS = 2.

endloop.

*----


WRITE errmsg.

CALL FUNCTION 'RSPO_CLOSE_SPOOLREQUEST'

EXPORTING

handle = handle

IMPORTING

rc = rc

errmessage = errmsg

EXCEPTIONS

handle_not_valid = 1

OTHERS = 2.

WRITE errmsg.

WRITE spoolid.

From the above prg i will be getting the spoolid and giving the spoolid number to the following program.

PARAMETERS:

SPOOLNO LIKE TSP01-RQIDENT,

DOWNLOAD AS CHECKBOX DEFAULT 'X',

P_FILE LIKE RLGRAP-FILENAME DEFAULT 'd:\sri\srifile.pdf'. "#EC NOTEXT

DATA otf like itcoo occurs 100 with header line.

DATA CANCEL.

DATA PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.

DATA DOCTAB LIKE DOCS OCCURS 1 WITH HEADER LINE.

DATA: NUMBYTES TYPE I,

ARC_IDX LIKE TOA_DARA,

pdfspoolid like tsp01-rqident,

jobname like tbtcjob-jobname,

jobcount like tbtcjob-jobcount,

is_otf.

data: client like tst01-dclient,

name like tst01-dname,

objtype like rststype-type,

type like rststype-type.

tables: tsp01.

select single * from tsp01 where rqident = spoolno.

if sy-subrc <> 0.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_negative.

exit.

endif.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

AUTHORITY = 'SP01'

CLIENT = client

NAME = name

PART = 1

IMPORTING

  • CHARCO =

  • CREATER =

  • CREDATE =

  • DELDATE =

  • MAX_CREDATE =

  • MAX_DELDATE =

  • NON_UNIQ =

  • NOOF_PARTS =

  • RECTYP =

  • SIZE =

  • STOTYP =

TYPE = type

OBJTYPE = objtype

EXCEPTIONS

FB_ERROR = 1

FB_RSTS_OTHER = 2

NO_OBJECT = 3

NO_PERMISSION = 4.

if objtype(3) = 'OTF'.

is_otf = 'X'.

else.

is_otf = space.

endif.

if is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = spoolno

NO_DIALOG = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = numbytes

PDF_SPOOLID = pdfspoolid

  • OTF_PAGECOUNT =

BTC_JOBNAME = jobname

BTC_JOBCOUNT = jobcount

TABLES

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

case sy-subrc.

when 0.

WRITE: / 'Funktion CONVERT_OTFSPOOLJOB_2_PDF erfolgreich'(001)

COLOR COL_POSITIVE.

when 1.

WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)

COLOR COL_negative.

exit.

when 2.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_negative.

exit.

when 3.

WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)

COLOR COL_negative.

exit.

when others.

WRITE: / 'Fehler bei Funktion CONVERT_OTFSPOOLJOB_2_PDF'(005)

COLOR COL_negative.

exit.

endcase.

else.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = spoolno

NO_DIALOG = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = numbytes

PDF_SPOOLID = pdfspoolid

  • LIST_PAGECOUNT =

BTC_JOBNAME = jobname

BTC_JOBCOUNT = jobcount

TABLES

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

case sy-subrc.

when 0.

WRITE: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich'(006)

COLOR COL_POSITIVE.

when 1.

WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)

COLOR COL_negative.

exit.

when 2.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_negative.

exit.

when 3.

WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)

COLOR COL_negative.

exit.

when others.

WRITE: / 'Fehler bei Funktion CONVERT_ABAPSPOOLJOB_2_PDF'(007)

COLOR COL_negative.

exit.

endcase.

endif.

                              • download PDF file ***********

check download = 'X'.

if not ( jobname is initial ).

WRITE: / 'Konvertierung per Hintergrundjob'(008)

COLOR COL_normal,

jobname, jobcount.

exit.

endif.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

BIN_FILESIZE = NUMBYTES

FILENAME = P_FILE

FILETYPE = 'BIN'

IMPORTING

ACT_FILENAME = P_FILE

FILESIZE = NUMBYTES

CANCEL = CANCEL

TABLES

DATA_TAB = PDF.

if cancel = space.

WRITE: / NUMBYTES, 'Bytes heruntergeladen in Datei'(009), P_FILE.

endif.

Wheni execute the program and enter the spoolid number the file will be downloaded but when i try to open the file it is giving the following error:

<b></b>There was an error opening this

document. This file cannot be opened

because it has no pages.

<b></b>.

Please help me out.

Thanks,

Pavan.

5 REPLIES 5
Read only

FredericGirod
Active Contributor
0 Likes
1,135

Hi,

you would like to rewrite an existing program, check your program with this standard program : RSTXPDFT4

Rgd

Frédéric

Read only

0 Likes
1,135

In the SAP standard program RSTXPDFT it will take only the text not the entire file contents so i am using the above program to get the spoolid and i am passing the spoolid number and then I am generating and downloading the PDF file.

Thanks,

Pavan.

Read only

0 Likes
1,135

DO you have check the program RSTXPDFT4 ?

from a spool id they create a PDF

Fred

Read only

0 Likes
1,135

Hi,

I executed the program RSTXPDFT4, I gave the spoolid number in the spool request parameter than also when i download the file and try to open the file the same error is comming "The file cannot be opened because it has no pages".

Please help me out in this issue.

Thanks,

Pavan.

Read only

0 Likes
1,135

Hey I am facing same issue.

Please suggest.

Even using RSTXPDFT4, same error is coming.