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: 

Using CONVERT_OTFSPOOLJOB_TO_PDF

Former Member
0 Kudos

Hello,

I would like to use the function module CONVERT_OTFSPOOLJOB_TO_PDF through a RFC connection.

in order to create a PDF file from a the spool !

Am I right ? or have I to do in an other way ?

But the PDF output seems to be bad.

Regards,

Smoltok

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

it is CONVERT_OTFSPOOLJOB_2_PDF and you cannot call it per RFC, since it is a normal function module. You have to create a function of type remote-enabled function with the same parameters and in the code you just call the original one:

call function CONVERT_OTFSPOOLJOB_2_PDF

when you call your new function you do it like this:

call function CONVERT_OTFSPOOLJOB_2_PDF destination abc

4 REPLIES 4

Former Member
0 Kudos

Hi,

it is CONVERT_OTFSPOOLJOB_2_PDF and you cannot call it per RFC, since it is a normal function module. You have to create a function of type remote-enabled function with the same parameters and in the code you just call the original one:

call function CONVERT_OTFSPOOLJOB_2_PDF

when you call your new function you do it like this:

call function CONVERT_OTFSPOOLJOB_2_PDF destination abc

0 Kudos

I have created a RFC function which called the CONVERT_OTFSPOOLJOB_TO_PDF with good parameters.

How can I download the PDf in a browser now ? Through GUI_DOWNLOAD ?

0 Kudos

No, not through RFC you can't. If you're calling the function remotely though, why don't you return the PDF data in an XSTRING and handle it in the calling application?

Former Member
0 Kudos

Here is the function module I made to resolve my question :

FUNCTION Z_CONVERT_OTFSPOOLJOB_2_PDF.
*"----------------------------------------------------------------------
*"*"Interface locale :
*"  IMPORTING
*"     VALUE(NO_BC) TYPE  BAPIMEPOHEADER-PO_NUMBER
*"     VALUE(EMAIL_FROM) TYPE  SOMLRECI1-RECEIVER
*"     VALUE(EMAIL_TO) TYPE  SOMLRECI1-RECEIVER
*"----------------------------------------------------------------------

DATA : titre like tsp01-rqtitle,
       wa_rqident like tsp01-rqident.
DATA: it_tsp02 TYPE STANDARD TABLE OF tsp01 WITH HEADER LINE .

CONCATENATE 'Edition du bon de commande original' no_bc INTO titre SEPARATED BY SPACE.


*selecting the spool request using the above consructed varibale
  SELECT * FROM tsp01 INTO TABLE it_tsp02
          WHERE rqtitle = titre.
*sorting the interbla table
  SORT  it_tsp02 BY rqcretime DESCENDING .
*reading the first spool request
  FIELD-SYMBOLS <fs> LIKE LINE OF it_tsp02.
  loop at it_tsp02 assigning <fs>.
  wa_rqident = <fs>-rqident.
  endloop.

DATA: it_pdf LIKE tline OCCURS 0 WITH HEADER LINE .

   DATA:  spoolno LIKE tsp01-rqident.
  DATA : p_repid LIKE sy-repid .
  DATA: v_len  TYPE i , v_len1  TYPE i .
  DATA: v_temp(8) TYPE c .
  DATA: p_uname LIKE sy-uname .
  DATA: it_tsp01 TYPE STANDARD TABLE OF tsp01 WITH HEADER LINE .
*  DATA: it_pdf LIKE tline OCCURS 0 WITH HEADER LINE .
  TABLES: tsp01.
  data: var  type c .
*-- STRUCTURES
  DATA:
    lc_rq2name LIKE tsp01-rq2name.
  DATA:
    mstr_print_parms LIKE pri_params,
    mc_valid(1)      TYPE c,
    mi_bytecount     TYPE i,
    mi_length        TYPE i,
    mi_rqident       LIKE tsp01-rqident.
*-- INTERNAL TABLES
  DATA:
    mtab_pdf    LIKE tline OCCURS 0 WITH HEADER LINE,
    mc_filename LIKE rlgrap-filename.
*-- SELECTION SCREEN
  DATA:
    p_linsz LIKE sy-linsz VALUE 132, " Line size
    p_paart LIKE sy-paart VALUE 'X_65_132'.  " Paper Format
*-- Setup the Print Parmaters
  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      authority              = space
      copies                 = '1'
      cover_page             = space
      data_set               = space
      department             = space
      destination            = space
      expiration             = '1'
      immediately            = space
      new_list_id            = 'X'
      no_dialog              = 'X'
      user                   = sy-uname
    IMPORTING
      out_parameters         = mstr_print_parms
      valid                  = mc_valid
    EXCEPTIONS
      archive_info_not_found = 1
      invalid_print_params   = 2
      invalid_archive_params = 3
      OTHERS                 = 4.
*-- Explicitly set line width, and output format so that
*-- the PDF conversion comes out OK
  mstr_print_parms-linsz = p_linsz.
  mstr_print_parms-paart = p_paart.
* importing variable value set at first time to restrict the infinite loop .
  IMPORT var FROM MEMORY ID 'abc' .
   var = var + 1 .
  p_uname = sy-uname .
  p_repid = sy-repid .
*checking variable to restricted scecond time exction of this block of code
  IF var = 1 .
*    v_memid = 1 .
    EXPORT var TO MEMORY ID 'abc' .
  ENDIF.

*selecting the spool request using the above consructed varibale
  SELECT * FROM tsp01 INTO TABLE it_tsp01
          WHERE rq2name = wa_rqident .
*sorting the interbla table
  SORT  it_tsp01 BY rqcretime DESCENDING .
*reading the first spool request
  READ TABLE it_tsp01 INDEX 1.




CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
     EXPORTING
          src_spoolid              = wa_rqident
        TABLES
          pdf                      = it_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
          OTHERS                   = 12.


DATA: gd_spool_nr LIKE tsp01-rqident,
      gd_destination LIKE rlgrap-filename,
      gd_bytecount LIKE tst01-dsize,
      gd_buffer TYPE string.
 DATA:  w_recsize TYPE i.
DATA: gd_recsize TYPE i.
 DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.
 data:     gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.
data: v_flag type c VALUE '1' .

* Transfer the 132-long strings to 255-long strings
  LOOP AT it_pdf.
    TRANSLATE it_pdf USING ' ~'.
    CONCATENATE gd_buffer it_pdf INTO gd_buffer.
  ENDLOOP.
   TRANSLATE gd_buffer USING '~ '.
   DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.



perform process_email tables it_mess_att using email_to email_from.

ENDFUNCTION.

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

*&---------------------------------------------------------------------*
*&      Form  SEND_MAIL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SEND_eMAIL tables PDF using email_to email_from.


DATA: it_pdf LIKE tline OCCURS 0 WITH HEADER LINE .
* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
      gd_destination LIKE rlgrap-filename,
      gd_bytecount LIKE tst01-dsize,
      gd_buffer TYPE string.
 DATA:  w_recsize TYPE i.
DATA: gd_recsize TYPE i.
 DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.
 data:     gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.
data: v_flag type c VALUE '1' .
*************************************************

 REFRESH it_mess_bod.
* Default subject matter
  gd_subject         = 'Sujet'.
  gd_attachment_desc = 'Devis'.
*  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
  it_mess_bod        = 'Voici le devis joint'.
  APPEND it_mess_bod.
  it_mess_bod        = 'Cordialement.'.
  APPEND it_mess_bod.
* If no sender specified - default blank
  IF email_from EQ space.
    gd_sender_type  = space.
  ELSE.
    gd_sender_type  = 'INT'.
  ENDIF.
* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_mess_bod
                                      PDF
                                using email_to
                                      'Devis SIFAC'
                                      'PDF'
                                      gd_attachment_name
                                      gd_attachment_desc
                                      email_from
                                      gd_sender_type
                             changing gd_error
                                      gd_reciever.
   ENDFORM.                    " SEND_MAIL
*---------------------------------------------------------------------*
*       FORM process_email                                            *
*---------------------------------------------------------------------*
FORM process_email tables it_mess_att using email_to email_from.
 DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.
 data:     gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.
      DATA: gd_recsize TYPE i.
data: v_flag type c VALUE '1' .
*************************************************

  DESCRIBE TABLE it_mess_att LINES gd_recsize.
  CHECK gd_recsize > 0.
  PERFORM send_email tables it_mess_att using email_to email_from .

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables it_message
                                          it_attach
                                    using email_to
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          email_from
                                          p_sender_addres_type
                                 changing p_error
                                          p_reciever.
    DATA: ld_error    TYPE sy-subrc,
        ld_reciever TYPE sy-subrc,
        ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_email LIKE  somlreci1-receiver,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des ,
        ld_sender_address LIKE  soextreci1-receiver,
        ld_sender_address_type LIKE  soextreci1-adr_typ,
        ld_receiver LIKE  sy-subrc.
 data:   t_packing_list like sopcklsti1 occurs 0 with header line,
        t_contents like solisti1 occurs 0 with header line,
        t_receivers like somlreci1 occurs 0 with header line,
        t_attachment like solisti1 occurs 0 with header line,
        t_object_header like solisti1 occurs 0 with header line,
        w_cnt type i,
        w_sent_all(1) type c,
        w_doc_data like sodocchgi1 .
    ld_email   = email_to.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = email_from.
  ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
  w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].
* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.
* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.
   DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.
* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.
   CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
            document_data              = w_doc_data
            put_in_outbox              = 'X'
            sender_address             = ld_sender_address
            sender_address_type        = ld_sender_address_type
            commit_work                = 'X'
       IMPORTING
            sent_to_all                = w_sent_all
       TABLES
            packing_list               = t_packing_list
            contents_bin               = t_attachment
*            CONTENTS_HEX               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
       EXCEPTIONS
            too_many_receivers         = 1
            document_not_sent          = 2
            document_type_not_exist    = 3
            operation_no_authorization = 4
            parameter_error            = 5
            x_error                    = 6
            enqueue_error              = 7
            OTHERS                     = 8.

if sy-subrc = 0.
SUBMIT RSCONN01 WITH MODE = 'INT'.
* this is for pushing mails., normally a background job will run., if u want to force "push use this statement
endif.


* Populate zerror return code
  ld_error = sy-subrc.
  stop .
* Populate zreceiver return code
*  LOOP AT t_receivers.
*    ld_receiver = t_receivers-retrn_code.
*  ENDLOOP.
ENDFORM.