cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Workflow - Send mail PDF file corrupted

justin_santhanam
Active Contributor
0 Kudos

Good Evening,

I have some issues in generating PDF files and sending as an email through Workflow. It's working sometimes and sometime the files seems corrupted. I'm not sure if I need to add anything on my code to avoid this, Again I just wanted to insist, that it's not an permanent issue, it's sporadic.

Can you please point me out, if I have to add anything , here?

Scenaro: Workflow Send Mail step, has an exit which calls the Smartforrms and make as an attachment to the email.

Workflow Exit Code:


method IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED.

* data type decleration for task element

   data:

         lv_task_id        type  sww_wiid,                               " task id number

         lv_taskhdr_id          type swr_wihdr,

         lv_task_container type ref to if_swf_ifs_parameter_container.   " container

* data type for document attachment

   datalv_doc_info        type sofolenti1,

          lv_object_header   type standard table of solisti1,

          lv_soxobjcont      type soxobj,

          lv_exception       type ref to cx_swf_cnt_container,

          lv_document_data   type sodocchgi1,

          lv_folder_id_1     type soodk,

          lv_folder_id_2     type soobjinfi1-object_id,

          lv_objtype         type swo_objtyp ,

          lv_objkey          type swo_typeid,

          lv_sofm            type swo_objhnd,

          lv_obj_record      type obj_record,

          lv_swotreturn      type swotreturn,

          it_solix_tab       type solix_tab,

          lv_qmnum           type qmnum,

          lt_simple          type table of swr_cont,

          lt_all_objects     type table of swr_cont,

          lv_container_line  type swr_cont,

          lv_return_code     type syst-subrc,

          lv_extn(5)         type c.

* read task id

   call method  im_workitem_context->get_header

     receiving

       re_workitem_header =    lv_taskhdr_id " structure for transferring work item to wlc

     .

  call method  im_workitem_context->get_workitem_id

     receiving

       re_workitem = lv_task_id.

* read container

   call method  im_workitem_context->get_wi_container

     receiving

       re_container = lv_task_container.

call function 'sap_wapi_read_container'

   exporting

     workitem_id                    = lv_task_id

*    language                       = sy-langu

*    user                           = sy-uname

*    buffered_access                = 'x'

  importing

    return_code                    = lv_return_code

*   ifs_xml_container              =

*   ifs_xml_container_schema       =

  tables

    simple_container               = lt_simple

*   message_lines                  =

*   message_struct                 =

*   subcontainer_bor_objects       =

    subcontainer_all_objects       = lt_all_objects.

           .

*    if lv_return_code ne 0.

*        raise not_found.

*      endif.

    loop at  lt_simple into lv_container_line

         where element = 'NOTIF_NUM'.

     endloop.

   if sy-subrc = 0.

         write lv_container_line-value to lv_qmnum.

    endif" sy-subrc = 0.

if lv_qmnum is not initial.

"get adobe form

     me->get_pdf_xstring(

       exporting

         iv_event     =   im_event_name  " field length 18

         iv_qmnum     =   lv_qmnum " notification no

       importing

         ev_pdf_solix =   it_solix_tab  " gbt: solix as table type

     ).

* identify the folder id

     call function 'so_folder_root_id_get'

       exporting

         owner     = sy-uname

         region    = 'B'

       importing

         folder_id = lv_folder_id_1.

* convert the field format acceptable by function module  so_document_insert_api1

     lv_folder_id_2 = lv_folder_id_1.

* prepare object header

      lv_soxobjcont-objkey  = lv_qmnum.

      append lv_soxobjcont to lv_object_header.

*prepare document data- contain description and sensitivity

     lv_document_data-obj_name = 'INITIAL'.

     lv_document_data-sensitivty = 'O'.

     lv_extn = '.PDF'.

     concatenate lv_qmnum lv_extn into lv_document_data-obj_descr.

    " lv_document_data-obj_descr = lv_qmnum.

     call function 'so_document_insert_api1'

       exporting

         folder_id                  = lv_folder_id_2

         document_data              = lv_document_data

         document_type              = 'EXT'

       importing

         document_info              = lv_doc_info

       tables

         object_header              = lv_object_header

         contents_hex               = it_solix_tab

       exceptions

         folder_not_exist           = 1

         document_type_not_exist    = 2

         operation_no_authorization = 3

         parameter_error            = 4

         x_error                    = 5

         enqueue_error              = 6

         others                     = 7.

     if sy-subrc <> 0.

       message id sy-msgid type sy-msgty number sy-msgno

               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     endif.

* populate object type and object key for create an instance

     lv_objtype = 'SOFM'.

     lv_objkey = lv_doc_info-doc_id.

* create an instance

     call function 'swo_create'

       exporting

         objtype           = lv_objtype

         objkey            = lv_objkey

       importing

         object            = lv_sofm

         return            = lv_swotreturn

       exceptions

         no_remote_objects = 1

         others            = 2.

     if sy-subrc <> 0.

       message id sy-msgid type sy-msgty number sy-msgno

               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     endif.

* prepare for attaching the object to container

     lv_obj_record-header = 'OBJH'.

     lv_obj_record-type = 'SWO'.

     lv_obj_record-handle = lv_sofm.

     call method lv_task_container->set

       exporting

         name  = '_ATTACH_OBJECTS'

         value = lv_obj_record.

     call method lv_task_container->set

       exporting

         name  = 'ATTACHMENTS'

         value = lv_obj_record.

*commit the changes

      call method im_workitem_context->do_commit_work.

   endif.

endmethod.

Code to call the Smart forms and convert to SOLIX_TAB:


method GET_PDF_XSTRING.

data:

  l_fm_name         TYPE rs38l_fnam,

  l_formname        TYPE fpname ,

  fp_docparams      TYPE sfpdocparams,

  fp_formoutput     TYPE fpformoutput,

  fp_outputparams   TYPE sfpoutputparams.

data:

  im_notif_long_txt type zpm_notif_longtext_tt,

  im_notif_hdr      type bapi2080_nothdre,

  im_notif_hdr_txt  type bapi2080_nothdtxte,

  im_notif_item     type zpm_notif_item_tt.

data:

  lv_event(18)  type c.

"Get the notification details.

call method zcl_pm_notification=>get_notification_detail

  exporting

      i_qmnum = iv_qmnum

   importing

      e_notification_long_txt = im_notif_long_txt

      e_notification_hdr      = im_notif_hdr

      e_notification_hdr_txt  = im_notif_hdr_txt

      e_notification_item     = im_notif_item.

"Send the notification event to FORM

if iv_event cs 'NOTIFCREATE'.

   lv_event = 'NEW'.

elseif iv_event cs 'CLOSED'.

   lv_event = 'FINAL'.

else.

   lv_event = 'DELAYED'.

endif.

  l_formname = c_form_name.

*&---------------------------------------------------------------------*

*& Get Function Module Name

*&---------------------------------------------------------------------*

  CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

    EXPORTING

      i_name     = l_formname

    IMPORTING

      e_funcname = l_fm_name.

  fp_outputparams-nodialog = 'X'.

  fp_outputparams-getpdf   = 'X'.

*&---------------------------------------------------------------------*

*& Open Job

*&---------------------------------------------------------------------*

  CALL FUNCTION 'FP_JOB_OPEN'

    CHANGING

      ie_outputparams = fp_outputparams

    EXCEPTIONS

      cancel          = 1

      usage_error     = 2

      system_error    = 3

      internal_error  = 4

      OTHERS          = 5.

  IF sy-subrc <> 0.

    CASE sy-subrc.

      WHEN OTHERS.

    ENDCASE.                           " CASE sy-subrc

  ENDIF.

  fp_docparams-langu = 'X'.

  fp_docparams-country = 'US'.

  fp_docparams-fillable = 'X'.

*&---------------------------------------------------------------------*

*& Get the PDF

*&---------------------------------------------------------------------*

  CALL FUNCTION l_fm_name

    EXPORTING

      /1BCDWB/DOCPARAMS            = fp_docparams

      NOTIFICATION_HEADERTXT       = im_notif_hdr_txt

      NOTIFICATION_TEXT            = im_notif_long_txt

      NOTIFICATION_HEADER          = im_notif_hdr

      NOTIFICATION_ITEM            = im_notif_item

      NOTIF_EVENT                  = lv_event

   IMPORTING

     /1BCDWB/FORMOUTPUT           = FP_FORMOUTPUT

   EXCEPTIONS

     USAGE_ERROR                  = 1

     SYSTEM_ERROR                 = 2

     INTERNAL_ERROR               = 3

     OTHERS                       = 4

            .

  IF SY-SUBRC <> 0.

* Implement suitable error handling here

  ENDIF.

*&---------------------------------------------------------------------*

*& Close Job

*&---------------------------------------------------------------------*

  CALL FUNCTION 'FP_JOB_CLOSE'

*   IMPORTING

*     E_RESULT             = result

   EXCEPTIONS

     usage_error          = 1

     system_error         = 2

     internal_error       = 3

     OTHERS               = 4

             .

  IF sy-subrc <> 0.

    CASE sy-subrc.

      WHEN OTHERS.

    ENDCASE.                           " CASE sy-subrc

  ENDIF.                               " IF sy-subrc <> 0.

*&---------------------------------------------------------------------*

*& Convert Xstring to SOLIX Tab

*&---------------------------------------------------------------------*

call method cl_document_bcs=>xstring_to_solix

   exporting

     ip_xstring =    fp_formoutput-pdf " XSTRING

   receiving

     rt_solix   =    ev_pdf_solix " SOLIX Table

   .

endmethod.

Thanks for your help!

-Justin

Accepted Solutions (1)

Accepted Solutions (1)

Tomas_Buryanek
Active Contributor
0 Kudos

I think you should specify DOCUMENT_DATA-DOC_SIZE parameter in SO_DOCUMENT_INSERT_API1. Value will be xstrlen( fp_formoutput-pdf  ).

justin_santhanam
Active Contributor
0 Kudos

Hello Tomas,

Thank you and I have added that value. But I can't able to really replicate the issue before or after changing the code. It happens only sometimes. I tried running the process 5-10 times but no luck, it worked all the time successfully (before changing and after changing the code). So I can'table to ascertain if it's still a problem or not. Anyways, I'm closing this thread at this point and if the issue still persists while we do the UAT, then I'll post a new thread.

Thank you for your help!

-Justin

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Any inputs?

Thank you,

Justin.