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: 

Attachments in SAP Inbox from Workflow?

Former Member
0 Kudos

Hi,

I am sending mail to sap inbox by using workflow. Is it Possible to make attchment with mail from workflow? How?

6 REPLIES 6

Former Member
0 Kudos

plase go through the below logic for making attach file .... here we are sending the salary of employee through mail to his mail id ..... he will get the salary slip as PDF attach file ...with morethat 3 pages of data (like salary brak-up, tax dedcution , form16a detals ,etc) ....

DATA W_OPTIONS LIKE ITCPO OCCURS 0 WITH HEADER LINE.
  DATA : z_itcpp LIKE itcpp OCCURS 0 WITH HEADER LINE.

  DATA : otfdt like ITCOO OCCURS 0 WITH HEADER LINE.
  DATA : pdfdt like TLINE OCCURS 0 with header line.
   DATA: NUMBYTES TYPE I.

  DATA: OBJPACK   LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
  DATA: OBJHEAD   LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
  DATA: OBJBIN    LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
  DATA: OBJTXT    LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
  DATA: RECLIST   LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
  DATA: DOC_CHNG  LIKE SODOCCHGI1.
  DATA: TAB_LINES LIKE SY-TABIX.
  
  DATA: Begin of i_errors occurs 0,
        type(1) type c,
        descr(100) type c,
       End of i_errors.

    w_options-tdprinter = 'POSTSCPT'.
    W_options-TDRDIDEV = 'XP45'.
    W_options-TDGETOTF = 'X'.
    APPEND W_options.

    call function 'OPEN_FORM'
        exporting
              device                      = 'PRINTER'
              dialog                      = ' '
              form                        = 'ZHRPAYSLIP'
              language                    =  sy-langu
              options                     =  w_options
*      IMPORTING
*         LANGUAGE                    =
*         NEW_ARCHIVE_PARAMS          =
*         RESULT                      =
       exceptions
             canceled                    = 1
             device                      = 2
             form                        = 3
             options                     = 4
             unclosed                    = 5
             mail_options                = 6
             archive_error               = 7
             invalid_fax_number          = 8
             more_params_needed_in_batch = 9
             others                      = 10 .


CALL FUNCTION 'CLOSE_FORM'
*    IMPORTING
*
*         RDI_RESULT               =
    TABLES
         OTFDATA                  = otfdt
      EXCEPTIONS
           UNOPENED                 = 1
           BAD_PAGEFORMAT_FOR_PRINT = 2
           SEND_ERROR               = 3
           OTHERS                   = 4.
    EXPORT otfdt TO MEMORY ID 'PDFT'.

CALL FUNCTION 'CONVERT_OTF'
 EXPORTING
   FORMAT                      = 'PDF'
*   MAX_LINEWIDTH               = 132
*   ARCHIVE_INDEX               = ' '
*   COPYNUMBER                  = 0
*   ASCII_BIDI_VIS2LOG          = ' '
*   PDF_DELETE_OTFTAB           = ' '
 IMPORTING
   BIN_FILESIZE                = NUMBYTES
*   BIN_FILE                    =
  TABLES
    otf                         = otfdt
    lines                       = pdfdt
* EXCEPTIONS
*   ERR_MAX_LINEWIDTH           = 1
*   ERR_FORMAT                  = 2
*   ERR_CONV_NOT_POSSIBLE       = 3
*   ERR_BAD_OTF                 = 4
*   OTHERS                      = 5
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF .

Refresh OBJTXT. clear OBJTXT.
  Refresh OBJPACK. clear OBJPACK.
  Refresh objbin. clear objbin.
  Refresh OBJHEAD. clear OBJHEAD.
  Refresh RECLIST. Clear RECLIST.


* Creation of the document to be sent
* File Name
  DOC_CHNG-OBJ_NAME = 'PAYSLIP'.
* Mail Subject
  DOC_CHNG-OBJ_DESCR = 'Payslip'.
* Mail Contents
  OBJTXT = 'This e-mail was sent from an automated system...'.
  APPEND OBJTXT.
  OBJTXT = 'Do not reply to this message.'.
  APPEND OBJTXT.
  OBJTXT = 'Please open the attachment to view the Payslip'.
  APPEND OBJTXT.

  OBJTXT = ''.
  APPEND OBJTXT.

  if not msgtxt1 is initial.
  OBJTXT = msgtxt1.
  APPEND OBJTXT.
  endif.

  if not msgtxt2 is initial.
  OBJTXT = msgtxt2.
  APPEND OBJTXT.
  endif.

  if not msgtxt3 is initial.
  OBJTXT = msgtxt3.
  APPEND OBJTXT.
  endif.

  DESCRIBE TABLE OBJTXT LINES TAB_LINES.
  READ TABLE OBJTXT INDEX TAB_LINES.
  DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

* Creation of the entry for the compressed document
  CLEAR OBJPACK-TRANSF_BIN.
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM = 0.
  OBJPACK-BODY_START = 1.
  OBJPACK-BODY_NUM = TAB_LINES.
  OBJPACK-DOC_TYPE = 'RAW'.
  APPEND OBJPACK.

* Creation of the document attachment

CALL FUNCTION 'QCE1_CONVERT'
   TABLES
     t_source_tab         = pdfdt
     t_target_tab         = objbin
   EXCEPTIONS
     convert_not_possible = 1
     OTHERS               = 2.

describe table objbin lines tab_lines.
OBJHEAD = 'Payslip.PDF'.
APPEND OBJHEAD.

** Creation of the entry for the compressed attachment
  OBJPACK-TRANSF_BIN = 'X'.
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM = 1.
  OBJPACK-BODY_START = 1.
  OBJPACK-BODY_NUM = TAB_LINES.
  OBJPACK-DOC_TYPE = 'PDF'.
  OBJPACK-OBJ_NAME = 'Payslip'.
  OBJPACK-OBJ_DESCR = 'Payslip'.
  OBJPACK-DOC_SIZE = TAB_LINES * 255.
  APPEND OBJPACK.

* Completing the recipient list
*  Read table i_pa0105 with key pernr = pernr-pernr binary search.
  loop at i_pa0105 where pernr = pernr-pernr and USRTY = '0010'.
  endloop.
  if sy-subrc = 0.
      RECLIST-RECEIVER = i_pa0105-USRID_LONG.
      RECLIST-REC_TYPE = 'U'.
      APPEND RECLIST.
  endif.
  if RECLIST[] is initial.
      loop at i_pa0105 where pernr = pernr-pernr and USRTY = 'MAIL'.
      endloop.
      if sy-subrc = 0.
          RECLIST-RECEIVER = i_pa0105-USRID.
          RECLIST-REC_TYPE = 'U'.
          APPEND RECLIST.
      endif.
  endif.

   if not RECLIST[] is initial.
* Sending the document
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
       DOCUMENT_DATA = DOC_CHNG
       PUT_IN_OUTBOX = ''
       COMMIT_WORK = 'X'

    TABLES
       PACKING_LIST = OBJPACK
       OBJECT_HEADER = OBJHEAD
       CONTENTS_BIN = OBJBIN
       CONTENTS_TXT = OBJTXT
       RECEIVERS = RECLIST
    EXCEPTIONS
       TOO_MANY_RECEIVERS = 1
       DOCUMENT_NOT_SENT = 2
       OPERATION_NO_AUTHORIZATION = 4
    OTHERS = 99.

    CASE SY-SUBRC.
       WHEN 0.
               LOOP AT RECLIST.
*                   Concatenate pernr-pernr '-'  RECLIST-RECEIVER(48) 
into error1.
                   IF RECLIST-RETRN_CODE = 0.
*                     Concatenate error1 ': The document was sent' into 
error1.
                     i_errors-descr = pernr-pernr.
                     i_errors-type = 'S'.
                     append i_errors.
                   ELSE.
                     Concatenate error1 ': The document could not be 
sent' into error1.
                     i_errors-descr = error1.
                     i_errors-type = 'E'.
                     append i_errors.
                   ENDIF.
               ENDLOOP.

        WHEN 1.
           Concatenate pernr-pernr '-'  RECLIST-RECEIVER(48) into 
error1.
           Concatenate error1 ': No authorization for sending to the 
recipients' into error1.
           i_errors-descr = error1.
           i_errors-type = 'E'.
           append i_errors.

        WHEN 2.

           Concatenate pernr-pernr '-'  RECLIST-RECEIVER(48) into 
error1.
           Concatenate error1 ': Document could not be sent to the 
recipient' into error1.
           i_errors-descr = error1.
           i_errors-type = 'E'.
           append i_errors.

        WHEN 4.
           Concatenate pernr-pernr '-'  RECLIST-RECEIVER(48) into 
error1.
           Concatenate error1 ': No send authorization' into error1.
           i_errors-descr = error1.
           i_errors-type = 'E'.
           append i_errors.

        WHEN OTHERS.
           Concatenate pernr-pernr '-'  RECLIST-RECEIVER(48) into 
error1.
           Concatenate error1 ': Error occurred while sending' into 
error1.
           i_errors-descr = error1.
           i_errors-type = 'E'.
           append i_errors.

    ENDCASE.
  else.
    error1 = pernr-pernr.
*    Concatenate error1 ': Maintain Infotype 0105.' into error1.
    i_errors-descr = error1.
    i_errors-type = 'M'.
    append i_errors.
  endif.

girish

0 Kudos

Hi Grish,

Thank you,

But I want to send attachment from my Workflow..

Former Member
0 Kudos

In the binding you need to bind the &attach_object with attachment.

In the user decision under the control tab, click on Binding.

In the task container -> workflow container, do the following binding.

AttachObjects -> &_ATTACH_OBJECTS&

By doing this it will automatically carry forward the attached objects.

Former Member
0 Kudos

Hi,

Yes,It is Possible.In SAP Business WorkPlace after giving Sen Mail Icon it will show one screen.In that screen there is one Icon 'Create Attachment' near by the 'Send' Icon.

Regards,

Padmam.

0 Kudos

I Have to attach a from my workflow itslef. Then only receiver will receives the attachement

0 Kudos

hi ram,

Yes, it is possible. Start workflow using FM 'SAP_WAPI_START_WORFKLOW' get the exporting parameter work item.

Then Add attachment to work item using FM 'SAP_WAPI_ATTACHMENT_ADD'

regards

goudham