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: 

Merge Smartform and Script into one pdf

Former Member
0 Kudos

Hi

I know this subject has been discussed a lot, but I can't find a solution that solve my problem.

I have an output in script, and an output in smartform - and want to merge those two outputs into one pdf file (and then download it to my server).

The spool numbers is known, but I can't figure out how to merge the spools into one pdf.

First I use RSPO_RETURN_SPOOLJOB, but can I use that FM to both Script and Smartforms?

The table output from the FM is buffer and buffer_pdf - do I collect those data from spool 1 into spool 2 data?

Would the final FM be CONVERT_OTF_2_PDF, where I use the collected data (OTF or PDF)?

Sorry for all the questions.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ,

Please try the following

- Get the OTF for smartform

- Get the OTF for SAPScript

- Merge the two OTF internal table into one internal table using following trcks.

For every Smartform output in its OTF equivalent, TDPRINTCOM begins and ends with u2018//u2019. So the final OTF table that should be sent as PDF output should contain only one pair of u2018//u2019 to mark the beginning and end of the table. TDPRINTCOM value for end-of-page will be u2018EPu2019. So if you want to combine multiple Smartforms into one OTF table, the beginning and end markers (u2018//u2019) for subsequent smartforms should be removed and appended after u2018EPu2019 command in the OTF table.

Hope this will help.

Regards,

Debaraj

6 REPLIES 6

kesavadas_thekkillath
Active Contributor
0 Kudos

The basic idea behind this is both sap script and smartforms returns otf data.

In sapscript in open form mark get otf as X, then in close form get your otf data.

In smartform the imprting parameter job_output_info will give you the otf data.

get the otf data of script append it to a itab, then get otf data of smart form append it to the same itab.

later convert this otf data to pdf like,


CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth         = 132
    IMPORTING
      bin_filesize          = v_len_in
    TABLES
      otf                   = i_otf   "<---should hold all the otf data of both script and smart form
      lines                 = i_tline
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      OTHERS                = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

0 Kudos

* Convert PDF from 132 to 255.
  LOOP AT i_tline.
* Replacing space by ~
    TRANSLATE i_tline USING ' ~'.
    CONCATENATE w_buffer i_tline INTO w_buffer.
  ENDLOOP.

* Replacing ~ by space
  TRANSLATE w_buffer USING '~ '.
  DO.
    i_record = w_buffer.
* Appending 255 characters as a record
    APPEND i_record.
    SHIFT w_buffer LEFT BY 255 PLACES.
    IF w_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.


 DATA:lv_dash(1)         TYPE c VALUE '-'.
  DATA:lv_xtn(4)          TYPE c VALUE '.pdf'.
  CONSTANTS:lv_esacpe     TYPE so_escape  VALUE 'U'.
  CONSTANTS:lv_so_obj_tp  TYPE so_obj_tp  VALUE 'PDF'.
  CONSTANTS:lv_so_obj_tp1 TYPE so_obj_tp  VALUE 'RAW'.
  CONSTANTS:lv_so_obj_sns TYPE so_obj_sns VALUE 'F'.

* Get Email ID's
  SELECT * INTO TABLE gt_address[] FROM adr6
  WHERE addrnumber = gw_kna1-adrnr.

  REFRESH:i_reclist,
          i_objtxt,
          i_objbin,
          i_objpack.

  CLEAR w_objhead.

0 Kudos

* Object with PDF.
  i_objbin[] = i_record[].

  DESCRIBE TABLE i_objbin[] LINES v_lines_bin.

* Object with main text of the mail.
  i_objtxt = text-002.
  APPEND i_objtxt.

  DESCRIBE TABLE i_objtxt LINES v_lines_txt.

* Document information.
  w_doc_chng-obj_name = text-005.
  w_doc_chng-expiry_dat = sy-datum + 10.

  IF gw_flg = 'T'.
    w_doc_chng-obj_descr = text-003.
  ELSE.
    w_doc_chng-obj_descr = text-004.
  ENDIF.

  CONCATENATE w_doc_chng-obj_descr lv_dash v_vbeln INTO w_doc_chng-obj_descr.

  w_doc_chng-sensitivty = lv_so_obj_sns. "Functional object
  w_doc_chng-doc_size = v_lines_txt * 255.

* Pack to main body as RAW.
* Obj. to be transported not in binary form
  CLEAR i_objpack-transf_bin.

0 Kudos

* Start line of object header in transport packet
  i_objpack-head_start = 1.

* Number of lines of an object header in object packet
  i_objpack-head_num = 0.

* Start line of object contents in an object packet
  i_objpack-body_start = 1.

* Number of lines of the object contents in an object packet
  i_objpack-body_num = v_lines_txt.

* Code for document class
  i_objpack-doc_type = lv_so_obj_tp1.

  APPEND i_objpack.

* Packing as PDF.
  i_objpack-transf_bin = gv_abaptrue.
  i_objpack-head_start = 1.
  i_objpack-head_num = 1.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lines_bin.
  i_objpack-doc_type = lv_so_obj_tp.
  i_objpack-obj_name = text-005.


  CONCATENATE w_doc_chng-obj_descr lv_xtn INTO i_objpack-obj_descr.
  i_objpack-doc_size = v_lines_bin * 255.
  APPEND i_objpack.

* Document information.
  CLEAR i_reclist.

* e-mail receivers.
  LOOP AT gt_address INTO gw_adr6.
    i_reclist-receiver = gw_adr6-smtp_addr.
    i_reclist-express =  gv_abaptrue.
    i_reclist-rec_type = lv_esacpe. "Internet address
    APPEND i_reclist.
  ENDLOOP.


  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_doc_chng
      put_in_outbox              = ' '
    TABLES
      packing_list               = i_objpack[]
      object_header              = w_objhead[]
      contents_bin               = i_objbin[]
      contents_txt               = i_objtxt[]
      receivers                  = i_reclist[]
    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.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  COMMIT WORK.

Edited by: Keshav.T on Aug 19, 2010 11:06 PM

0 Kudos

*--declarations

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

i_tline TYPE TABLE OF tline WITH HEADER LINE,

i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,

i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

*************Work Area declarations**********************

w_objhead TYPE soli_tab,

w_ctrlop TYPE ssfctrlop,

w_compop TYPE ssfcompop,

w_return TYPE ssfcrescl,

w_doc_chng TYPE sodocchgi1,

w_data TYPE sodocchgi1,

w_buffer TYPE string."To convert from 132 to 255

data: v_len_in TYPE sood-objlen,

v_len_out TYPE sood-objlen,

v_len_outn TYPE i,

v_lines_txt TYPE i,

v_lines_bin TYPE i.

Former Member
0 Kudos

Hi ,

Please try the following

- Get the OTF for smartform

- Get the OTF for SAPScript

- Merge the two OTF internal table into one internal table using following trcks.

For every Smartform output in its OTF equivalent, TDPRINTCOM begins and ends with u2018//u2019. So the final OTF table that should be sent as PDF output should contain only one pair of u2018//u2019 to mark the beginning and end of the table. TDPRINTCOM value for end-of-page will be u2018EPu2019. So if you want to combine multiple Smartforms into one OTF table, the beginning and end markers (u2018//u2019) for subsequent smartforms should be removed and appended after u2018EPu2019 command in the OTF table.

Hope this will help.

Regards,

Debaraj