cancel
Showing results for 
Search instead for 
Did you mean: 

OPEN_FORM empty-spoolid issue. Help!

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks Arindam and Karthik for the replies.

Still I haven't been able to retrieve the spoolid after executing the FM.

Apparently this number is assigned when executing the funcion CLOSE_FORM.

Below is my code

CALL FUNCTION 'CLOSE_FORM'
      IMPORTING
        RESULT                         = RESULT
*       RDI_RESULT                     =
*     TABLES
*       OTFDATA                        = gs_itcpp
      EXCEPTIONS
        UNOPENED                       = 1
        BAD_PAGEFORMAT_FOR_PRINT       = 2
        SEND_ERROR                     = 3
        SPOOL_ERROR                    = 4
        CODEPAGE                       = 5
        OTHERS                         = 6
               .
     IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.

***

sy-subrc is in this case 0, and since the OPEN_FORM function does not seem to return the spoolid,  my guess is that CLOSE_FORM generates the id. Anyone can confirm this?

I looked into user permissions in order to verify if this had anything to do with authorizations, but to no avail. i also checked the value of the sy-spono variable and it also equals 0.

Any suggestions will be greatly appreciated. thanks in advance.

Former Member
0 Kudos

Hi Juan,

The below discussion would be helpful;

http://scn.sap.com/thread/1540787

https://scn.sap.com/thread/1596051

As per the first link, you should probably write your Start_form and write_form in between Open and close form.

As per the second link check whether you have given all print parameters properly.

Regards,

Karthik Dharmarajan

arindam_m
Active Contributor
0 Kudos

Hi,

You have not checked any existing exceptions for the FM 'OPEN_FORM', can you please include that in your code and check which exception is being set during debug. Should help us ti understand the issue better.

The list of exceptions as available:

CANCELED

DEVICE

FORM

OPTIONS

UNCLOSED

MAIL_OPTIONS

ARCHIVE_ERROR

INVALID_FAX_NUMBER

MORE_PARAMS_NEEDED_IN_BATCH

SPOOL_ERROR

CODEPAGE

Cheers,

Arindam