‎2007 Jun 15 11:42 AM
Dear All,
My function module downloads the content of a document into a path specified
(For example E drive). My requirement is to convert the document(textfile) to a pdf and then upload the data. All of this should be done automatically ( i mean no manual intervention, background task of a workflow should do that)
Any suggestions?
Thanks,
nsp.
‎2007 Jun 15 11:44 AM
See the example code :
DATA: it_otf TYPE STANDARD TABLE OF itcoo,
it_docs TYPE STANDARD TABLE OF docs,
it_lines TYPE STANDARD TABLE OF tline,
st_job_output_info TYPE ssfcrescl,
st_document_output_info TYPE ssfcrespd,
st_job_output_options TYPE ssfcresop,
st_output_options TYPE ssfcompop,
st_control_parameters TYPE ssfctrlop,
v_len_in TYPE so_obj_len,
v_language TYPE sflangu VALUE 'E',
v_e_devtype TYPE rspoptype,
v_bin_filesize TYPE i,
v_name TYPE string,
v_path TYPE string,
v_fullpath TYPE string,
v_filter TYPE string,
v_uact TYPE i,
v_guiobj TYPE REF TO cl_gui_frontend_services,
v_filename TYPE string,
v_fm_name TYPE rs38l_fnam.
CONSTANTS c_formname TYPE tdsfname VALUE 'ZTEST'.
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language = v_language
i_application = 'SAPDEFAULT'
IMPORTING
e_devtype = v_e_devtype.
st_output_options-tdprinter = v_e_devtype.
*st_output_options-tdprinter = 'locl'.
st_control_parameters-no_dialog = 'X'.
st_control_parameters-getotf = 'X'.
*.................GET SMARTFORM FUNCTION MODULE NAME.................*
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_formname
IMPORTING
fm_name = v_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
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 SMARTFORM............................*
CALL FUNCTION v_fm_name
EXPORTING
control_parameters = st_control_parameters
output_options = st_output_options
IMPORTING
document_output_info = st_document_output_info
job_output_info = st_job_output_info
job_output_options = st_job_output_options
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.
ELSE.
*.........................CONVERT TO OTF TO PDF.......................*
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = v_bin_filesize
TABLES
otf = st_job_output_info-otfdata
doctab_archive = it_docs
lines = it_lines
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*........................GET THE FILE NAME TO STORE....................*
CONCATENATE 'smrt' '.pdf' INTO v_name.
CREATE OBJECT v_guiobj.
CALL METHOD v_guiobj->file_save_dialog
EXPORTING
default_extension = 'pdf'
default_file_name = v_name
file_filter = v_filter
CHANGING
filename = v_name
path = v_path
fullpath = v_fullpath
user_action = v_uact.
IF v_uact = v_guiobj->action_cancel.
EXIT.
ENDIF.
*..................................DOWNLOAD AS FILE....................*
MOVE v_fullpath TO v_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_bin_filesize
filename = v_filename
filetype = 'BIN'
TABLES
data_tab = it_lines
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.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
Vasanth
‎2007 Jun 15 12:56 PM
My requirement is to convert the file stored in desktop or on application server to a pdf
‎2007 Jun 15 1:17 PM
Hi nsp,
try this:
DATA: DATEI_PC TYPE STRING.
*
DATA: BEGIN OF ITAB OCCURS 0,
TEXT(72),
END OF ITAB.
Länge der PDF-Datei in Byte
DATA: PDF_FILESIZE TYPE I.
DATA: BIN_FILESIZE TYPE I.
Druckparameter mit Gültigkeit
DATA: PARAMS LIKE PRI_PARAMS,
VALID TYPE C.
Spoolnummer
DATA: SPOOL_NR LIKE TSP01-RQIDENT,
SPOOL_NR_DEL LIKE TSP01_SP0R-RQID_CHAR.
PDF Ausgabetabelle
DATA: BEGIN OF PDF_OUTPUT OCCURS 0.
INCLUDE STRUCTURE TLINE.
DATA: END OF PDF_OUTPUT.
*
START-OF-SELECTION.
*
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY
CHANGING
DESKTOP_DIRECTORY = DATEI_PC.
*
CALL METHOD CL_GUI_CFW=>FLUSH.
*
CONCATENATE DATEI_PC 'TEST.PDF' INTO DATEI_PC.
*
fill internal table
READ REPORT 'ZGRO_ITAB_PDF_SPOOL' INTO ITAB.
*
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
DESTINATION = 'LOCA'
LINE_SIZE = 080
IMMEDIATELY = ' '
NO_DIALOG = 'X'
IMPORTING
OUT_PARAMETERS = PARAMS
VALID = VALID.
*
CHECK VALID <> SPACE.
*
Ausgabe der internen Tabelle mit den Druckparametern.
NEW-PAGE PRINT ON PARAMETERS PARAMS NO DIALOG NO-TITLE NO-HEADING.
*
LOOP AT ITAB.
WRITE:/ ITAB.
ENDLOOP.
*
NEW-PAGE PRINT OFF.
Spoolnummer besorgen
SPOOL_NR = SY-SPONO.
Konvertierung der Ausgabe nach PDF
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = SPOOL_NR
IMPORTING
PDF_BYTECOUNT = PDF_FILESIZE
TABLES
PDF = PDF_OUTPUT.
*
SPOOL_NR_DEL = SPOOL_NR.
Spool wieder löschen
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
SPOOLID = SPOOL_NR_DEL.
*
BIN_FILESIZE = PDF_FILESIZE.
*
Download der Spools
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = BIN_FILESIZE
FILENAME = DATEI_PC
FILETYPE = 'BIN'
CHANGING
DATA_TAB = PDF_OUTPUT[].
*
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
DOCUMENT = DATEI_PC.
*
END-OF-SELECTION.
Regards, Dieter
‎2007 Jun 15 4:09 PM
Thanks, I get an error "spool request 0 does not exist"
Anyway, Iam using the following code for which i get the error
"convertor not installed" (for the FM RSPO_CONVERT_AND_PRINT_PCDOCS)
So, At the end I get the error "sap script does not contain data"
***************************************************************************
*&----
*
*& Report ZRSPO0068
*&
*&----
*
*&
*&
*&----
*
REPORT ZRSPO0068 line-size 132.
*
test BC-XDC interface:
create spoolrequest with single *.DOC document,
convert it to PCL or PS using RSPO_CONVERT_AND_PRINT_PCDOCS
*
16.10.2002 filename, driver, doctype into spoolreqname
*
parameters: docfile LIKE RLGRAP-FILENAME DEFAULT
'c: emp est.doc',
doctype(4) default 'DOC',
dest like tsp03-padest,
immed as checkbox,
delete as checkbox.
data: doctab like rspolpbi occurs 100 with header line.
data: cnvtab like rspolpbi occurs 100 with header line.
data: bytecount type i,
cancel,
msg(80),
spoolhandle type i,
rqdoctype like tsp01-rqdoctype,
spoolreq like tsp01-rqident,
status,
sponame like tsp01-rq0name,
suffix1 like tsp01-rq1name,
suffix2 like tsp01-rq2name,
numlines like sy-tabix.
data: begin of path occurs 2,
c(40),
end of path.
tables: tsp03, tsp0a.
DATA : gd_bytecount LIKE tst01-dsize .
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
select single * from tsp03 where padest = dest.
if sy-subrc <> 0.
write: / 'Bitte geben Sie einen gültigen Drucker an'(009).
exit.
endif.
select single * from tsp0a where patype = tsp03-patype.
case tsp0a-driver.
when 'POST'. suffix1 = 'POST'.
when 'HPL2'. suffix1 = 'PCL5'.
when 'PDF1'. suffix1 = 'PDF '.
endcase.
sponame = doctype.
lade *.DOC
perform upload tables doctab
using docfile
'BIN'
bytecount
cancel.
write: / 'Hochgeladene Datei:'(001),
/2 docfile color col_normal.
if cancel = 'X'.
write: / 'Upload wurde abgebrochen'(002) color col_negative.
exit.
else.
write: / bytecount color col_total,
'Bytes von Datei eingelesen'(003).
endif.
create spoolrequest with DOC
rqdoctype = doctype.
split docfile at '' into table path.
describe table path lines numlines.
read table path index numlines.
suffix2 = path-c.
CALL FUNCTION 'RSPO_SR_OPEN'
EXPORTING
DEST = dest
name = sponame
suffix1 = suffix1
suffix2 = suffix2
IMMEDIATE_PRINT = ' '
AUTO_DELETE = ' '
DOCTYPE = rqdoctype
IMPORTING
HANDLE = spoolhandle
spoolid = spoolreq
EXCEPTIONS
others = 1.
IF SY-SUBRC = 0.
write: / 'Neuer Spoolauftrag='(004),
spoolreq color col_key.
else.
write: / 'FEHLER beim Öffnen des Spoolauftrags'(005)
color col_negative,
sy-subrc.
exit.
ENDIF.
write data
CALL FUNCTION 'RSPO_SR_TABLE_WRITE_BINARY'
EXPORTING
HANDLE = spoolhandle
CODEPAGE =
TOTAL = bytecount
TABLES
LINES = doctab
EXCEPTIONS
HANDLE_NOT_VALID = 1.
IF SY-SUBRC <> 0.
write: / 'FEHLER beim Schreiben in Spoolauftrag'(006)
color coL_negative,
sy-subrc.
exit.
ENDIF.
schliesse
CALL FUNCTION 'RSPO_SR_CLOSE'
EXPORTING
HANDLE = spoolhandle
FINAL = 'X'
exceptions
HANDLE_NOT_VALID = 1
OPERATION_FAILED = 2.
IF SY-SUBRC <> 0.
write: / 'FEHLER beim Schließen des Spoolauftrags'(007)
color col_negative,
sy-subrc.
exit.
ENDIF.
*
CALL FUNCTION 'RSPO_CONVERT_AND_PRINT_PCDOCS'
EXPORTING
COMP_SPOOLREQ = spoolreq
IMMED_PRINT = immed
DELETE_AFTER_PRINT = delete
ZERO_CONV_ERRORS = 'X'
EXCEPTIONS
CONVERTER_ERROR = 1
CONVERTER_NOT_INSTALLED = 2
RFC_ERROR = 3
INTERNAL_ERROR = 4
COMP_SPOOLREQ_NESTED = 5
COMP_SPOOLREQ_NOT_FOUND = 6
COMP_SPOOLREQ_PRINTING = 7
COMP_SPOOLREQ_NOT_FINAL = 8
NO_COMP_SPOOLREQ = 9
PRINTFORMAT_NOT_SUPPORTED = 10.
write: / 'RSPO_CONVERT_AND_PRINT_PCDOCS' "#EC notext
color col_heading.
case sy-subrc.
when 0. write 'OK' color col_positive. "#EC notext
when 1. write 'CONVERTER_ERROR' color col_negative. "#EC notext
when 2. write 'CONVERTER_NOT_INSTALLED' color col_negative.
when 3. write 'RFC_ERROR' color col_negative.
when 4. write 'INTERNAL_ERROR' color col_negative.
when 5. write 'COMP_SPOOLREQ_NESTED' color col_negative.
when 6. write 'COMP_SPOOLREQ_NOT_FOUND' color col_negative.
when 7. write 'COMP_SPOOLREQ_PRINTING' color col_negative.
when 8. write 'COMP_SPOOLREQ_NOT_FINAL' color col_negative.
when 9. write 'NO_COMP_SPOOLREQ' color col_negative.
when 10. write 'PRINTFORMAT_NOT_SUPPORTED' color col_negative.
endcase.
if sy-subrc = 0.
write: / 'Prüfe Status der Konvertierung für'(008),
spoolreq.
CALL FUNCTION 'RSPO_QUERY_CONVSTATUS'
EXPORTING
SPOOLREQUEST = spoolreq
IMPORTING
STATUS = status
STATUSMSG = msg
EXCEPTIONS
CONVERTER_NOT_INSTALLED = 1
RFC_ERROR = 2
SPOOLREQUEST_UNKNOWN = 3.
case sy-subrc.
when 0.
case status.
when '0'.
write: /
'Spool request is being processed by XDC'. "#EC notext
when '1'.
write: /
'Spool request is unknown to XDC'. "#EC notext
when '2'.
write: /
'Spool request was already returned as DONE by XDC'. "#EC notext
when '3'.
write: /
'Spool request could not be converted by XDC'. "#EC notext
when '4'.
write: msg.
when others.
write: /
'Illegal status value:', status. "#EC notext
endcase.
when 1.
write: / 'Converter not installed' color col_negative. "#EC notext
when 2.
write: / 'RFC error' color col_negative. "#EC notext
when 3.
write: / 'Spoolrequest unknown' color col_positive. "#EC notext
endcase.
endif.
*
WRITE : / spoolreq .
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolreq
NO_DIALOG = ''
DST_DEVICE = 'LOCL'
PDF_DESTINATION =
IMPORTING
PDF_BYTECOUNT = gd_bytecount
PDF_SPOOLID = spoolreq
OTF_PAGECOUNT =
BTC_JOBNAME =
BTC_JOBCOUNT =
TABLES
PDF = it_pdf_output
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
OTHERS = 12
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write / spoolreq .
form upload tables datatab
using filename like rlgrap-filename
mode type c
bin_filesize type i
cancel type c.
data: name type string,
filetype type char10,
filetable type filetable,
filter type string,
rc type i,
guiobj type ref to cl_gui_frontend_services,
uact type i.
if mode <> 'ASC' and mode <> 'BIN'.
sy-subrc = 1. exit.
endif.
filetype = mode.
name = filename.
clear cancel.
create object guiobj.
filter = '(.)|.|)'.
call method guiobj->file_open_dialog
exporting default_filename = name
file_filter = filter
changing file_table = filetable
rc = rc
user_action = uact
exceptions file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3.
if uact = guiobj->action_cancel.
cancel = 'X'. exit.
endif.
read table filetable index 1 into name.
check sy-subrc = 0.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING FILENAME = name
FILETYPE = FILETYPE
IMPORTING FILELENGTH = bin_filesize
TABLES DATA_TAB = datatab
EXCEPTIONS FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
INVALID_TYPE = 3
NO_BATCH = 4
OTHERS = 5.
filename = name.
endform.