Skip to Content
0
Former Member
May 28, 2013 at 07:07 PM

OPEN_FORM empty-spoolid issue. Help!

114 Views

Hello everyone, I seem to be having an issue getting a spoolid to save a .pdf file to an application. Below is my code, it should return an id for the program process the file upload, but instead it's returning 0. Any help would be greatly appreciated. Thanks!!

FORM open_sapscript.

IMPORT c_rfc FROM MEMORY ID 'RFC'.

IF sy-subrc = 0.

itcpo-tdimmed = space.
itcpo-tdlifetime = '1'. " verfalltage
itcpo-tdprogram = sy-repid.
itcpo-tdnewid = 'X'.
itcpo-tddataset = 'Orden Pago'.
itcpo-tddest = 'LPDF'.

CALL FUNCTION 'OPEN_FORM' " open form for output
EXPORTING form = s_form
dialog = space
OPTIONS = itcpo
device = 'PRINTER'.

ELSE.

itcpo-tdimmed = '*'. " kz sofort drucken
itcpo-tddelete = '*'. " kz freigbe nach Druck
itcpo-tdlifetime = '7'. " verfalltage
itcpo-tdpreview = 'X'. " druckansicht

CALL FUNCTION 'OPEN_FORM' " open form for output
EXPORTING form = s_form
dialog = 'X'
OPTIONS = itcpo
device = 'PRINTER'.

ENDIF.

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

IMPORT c_rfc FROM MEMORY ID 'RFC'.

IF sy-subrc = 0.

CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = RESULT.

IF result-tdspoolid NE space.

v_device = result-tddevice.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = result-tdspoolid
no_dialog = 'X'
dst_device = v_device
TABLES
pdf = it_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
OTHERS = 12.

IF sy-subrc = 0.

SELECT SINGLE valor
FROM zpctabmm001
INTO v_filename
WHERE objeto = 'FI'
AND idobjeto1 = 'PATH'.

CONCATENATE v_filename '/'
br_belnr-low '-'
br_gjahr-low '.pdf' INTO v_filename.


OPEN DATASET v_filename FOR OUTPUT IN BINARY MODE.

IF sy-subrc = 0.
LOOP AT it_pdf.
TRANSFER it_pdf TO v_filename.
ENDLOOP.
ENDIF.

CLOSE DATASET v_filename.

ENDIF.

ENDIF.

ELSE.

CALL FUNCTION 'CLOSE_FORM'.

ENDIF.