Skip to Content
Author's profile photo shamsudheen k

Mail attachment from PDF Spool request in SAP Workflow

Requirement : Once the release of the  PO is completed ( after released all level ) the PDF output of the particular PO has to send the PR creator and department head  as attachment.

spool.PNG

The code for getting the spool request is as follows

*fetching the spool request.

select single rqident

from TSP01

into l_rqident

where rqtitle = object-key-purchaseorder.

if sy-subrc = 0.

spool_generate = ‘X’.

endif.

SWC_SET_ELEMENT CONTAINER ‘spool_generate’ SPOOL_GENERATE.

Step 2 : As the spool request generation will take some time , put the wait step with condition that until spool is getting generated ( &spool_generate& = ‘X’. )

Step 3 : Create step ( activity ) for attaching the PO.

The code is as below.

begin_method pomail_attach changing container.

DATA:

   po_number TYPE ekkoebeln,

   mail_id   TYPE TABLE OF adr6smtp_addr.

swc_get_element container ‘PO_NUMBER’ po_number.

swc_get_table container ‘MAIL_ID’ mail_id.

CALL FUNCTION ‘ZMM_PO_EMAIL_ATTACHMENT’

   EXPORTING

     i_ebeln = po_number

   TABLES

     i_email = mail_id. ” mail id  of PR creator and dept. head.


   end_method.

Find the detailed code of above FM.


FUNCTION zmm_po_email_attachment.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     VALUE(I_EBELN) TYPE  EKKO-EBELN OPTIONAL

*”  TABLES

*”      I_EMAIL STRUCTURE  ZMM_MAILID

*”———————————————————————-

   TABLES: tsp01.

   “————————————————————

   ” Constants Declarations

   “————————————————————

   CONSTANTS: lc_pdf        TYPE char3      VALUE ‘PDF’,

              lc_obj_name   TYPE so_obj_nam VALUE ‘PDF’, “‘SCRIPT’,

              lc_express    TYPE char1      VALUE ‘X’,

              lc_rec_type   TYPE char1      VALUE ‘U’,

              lc_sensitivty TYPE so_obj_sns VALUE ‘F’,

              lc_doc_type   TYPE so_obj_tp  VALUE ‘RAW’,

              lc_in_out     TYPE sonvflag  VALUE ‘X’,

              lc_no(1)      TYPE c          VALUE ‘ ‘,

              lc_device(4TYPE c          VALUE ‘LOCL’.

   “————————————————————

   ” Internal Tables Declarations

   “————————————————————

   DATA : lint_objpack    TYPE TABLE OF sopcklsti1,

          lint_objbin     TYPE TABLE OF solisti1,

          lint_objtxt     TYPE TABLE OF solisti1,

          lint_reclist    TYPE TABLE OF somlreci1,

          lint_pdf_output TYPE TABLE OF tline.

*         lint_mess_att   TYPE TABLE OF solisti1.

   “————————————————————

   ” Work Area Declarations

   “————————————————————

   DATA : lfs_objpack    TYPE sopcklsti1,

          lfs_objbin     TYPE solisti1,

          lfs_objtxt     TYPE solisti1,

          lfs_reclist    TYPE somlreci1,

          lfs_doc_chng   TYPE sodocchgi1,

          lfs_tsp01      TYPE tsp01,

          lfs_pdf_output TYPE tline,

          lfs_mess_att   TYPE solisti1.

   “————————————————————

   ” Local Varaibles Declarations

   “————————————————————

   DATA : lwf_lines_txt TYPE i,

          lwf_lines_bin TYPE i,

          lwf_buffer    TYPE string,

          p_spoolid     TYPE rspoid,

          p_partnum     TYPE adsnum VALUE ‘1’,

          p_pdf         TYPE fpcontent,

          p_pages       TYPE i,

          so_solixtab   TYPE solix_tab,

          p_pdf_file    TYPE string.

   “————————————————————

   ” Logic started..

   “————————————————————

   IF i_ebeln IS NOT INITIAL

   AND i_email[] IS NOT INITIAL.

** To get the spool no from the purchase document number..

     SELECT SINGLE *

       FROM tsp01

       INTO lfs_tsp01

       WHERE rqtitle = i_ebeln.

     IF sysubrc = 0.

       p_spoolid = lfs_tsp01rqident.

       PERFORM create_pdf_from_spool  IN PROGRAM saplfpcomp  USING p_spoolid

                                           p_partnum

                                  CHANGING p_pdf

                                           p_pages

                                           p_pdf_file.

       IF sysubrc = 0.

*—>Convert xstrin to solix

         so_solixtab = cl_bcs_convert=>xstring_to_solix( p_pdf ).

       ENDIF.

       “——————————————————–

       ”  To add the recipients email address

       “———————————————————

       LOOP AT i_email .

         lfs_reclistreceiver = i_email.

         lfs_reclistexpress  = lc_express.

         lfs_reclistrec_type = lc_rec_type.

         APPEND lfs_reclist TO lint_reclist.

         CLEAR  lfs_reclist.

       ENDLOOP.

       “——————————————————–

       ” Mail Content

       “——————————————————–

** for Header

       lfs_objtxt = ‘Dear User,’.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For content

       CONCATENATE ‘Purchase order : ‘ i_ebeln ‘, has been approved.’ INTO lfs_objtxt.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For footer

       lfs_objtxt = ‘This is an auto generated email, please do not reply.’.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

       “————————————————————

       ” Mail Header

       “————————————————————

       DESCRIBE TABLE lint_objtxt LINES lwf_lines_txt.

       lfs_doc_chngobj_name   = lc_obj_name.

       lfs_doc_chngobj_langu  = sylangu.

       CONCATENATE ‘Purchase order: ‘ i_ebeln ‘, has been approved’ INTO lfs_doc_chngobj_descr.

       lfs_doc_chngsensitivty = lc_sensitivty.

       lfs_doc_chngdoc_size   = 1.

       “————————————————————

       ” Pack to main body as RAW.

       “————————————————————

       CLEAR lfs_objpacktransf_bin.

       lfs_objpackhead_start = 1.

       lfs_objpackhead_num   = 0.

       lfs_objpackbody_start = 1.

       lfs_objpackbody_num   = lwf_lines_txt.

       lfs_objpackdoc_type   = lc_doc_type.

       APPEND lfs_objpack TO lint_objpack.

       “————————————————————

       ” Packing as PDF.

       “————————————————————

       CLEAR lwf_lines_bin.

**      DESCRIBE TABLE lint_mess_att LINES lwf_lines_bin.

       DESCRIBE TABLE so_solixtab LINES lwf_lines_bin.

       lfs_objpacktransf_bin = abap_true.

       lfs_objpackhead_start = 1.

       lfs_objpackhead_num   = 1.

       lfs_objpackbody_start = 1.

       lfs_objpackbody_num   = lwf_lines_bin.

       lfs_objpackdoc_type   = lc_pdf.

       CONCATENATE ‘Purchase order: ‘ i_ebeln ‘, has been approved’ INTO lfs_objpackobj_name.

       CONCATENATE ‘Purchase order’ ‘:’ i_ebeln INTO lfs_objpackobj_descr.

**

       lfs_objpackdoc_size = lwf_lines_bin * 255.

       APPEND lfs_objpack TO lint_objpack.

       “————————————————————

       ” To send the smartform as attachment in Mail to the above receipent

       “————————————————————

       CALL FUNCTION ‘SO_NEW_DOCUMENT_ATT_SEND_API1’

         EXPORTING

           document_data              = lfs_doc_chng

           put_in_outbox              = lc_in_out

         TABLES

           packing_list               = lint_objpack

           contents_hex               = so_solixtab

           contents_txt               = lint_objtxt

           receivers                  = lint_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 sysubrc = 0.

         COMMIT WORK.

       ENDIF.

     ENDIF.

   ENDIF.

ENDFUNCTION.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.