Skip to Content

Hi Guys,

     I am inspired by my friends (Himanshu and Biswajit – though not from SAP world) to write blog and this is my first blog, therefore please bear with me and help me to improve with your valuable suggestions and feedback.

Reason for Development – Before approving the Trip, manager view the trip summary which open as HTML GUI from the UWL, which is very slow. It takes long time to scroll the page. Therefore it is a better approach to create an html page for the trip summary and attach the page  to the workflow. It mean that when the attachment will be review by the manager it will be plane HTML Page which is very easy to load and dosenot interact with the SAP, where earlier it was HTML GUI and I believe it was interacting with SAP on each interaction and therefore was very slow (Depending on the bandwith, It was fast if you are directly connected to the network, but if you are remotly by citrix then this problem creep up.)

Design/Implementation aspect

Function Module BAPI_TRIP_GET_FROM_HTML takes the employee number and trip number and provides you with the HTML page with the Trip summary. Then the new office document is created using this page and pass it to the workflow as an attachment.

I achieved this by writing a class in programming exit and then later I found that there is a blog in SDN which talk about the attachment but it requires extra background step (Please find the link), though it is simple and easy to implement and use classic buniess object method but it seems that you have to modify the workflow template with extra step and you are attaching your document to the workflow task and then importing the attached document to that particular step. Therefore I thought that creating attachment using OO ABAP will be easier and less cumbersome and fast/effecient. I also came across a blog about the programming exit, which I believe is worth reading (Link).My blog also answers how to create SOFM object in class asked by many people.

Exercise in action

Step 1:- Go to SE24 and create a class as per your company naming standard (I have created ZCL_SWF_IFS_WORKITEM_EXIT). You have to implement interface IF_SWF_IFS_WORKITEM_EXIT, method EVENT_RAISED.

Class Creation

 

Please find the code implemented for the enhancement.

* Data type decleration for Task Element

  data: lv_pernr          type p_pernr,                                 ” Personnal Number

        lv_tripno         type REINR,                                   ” Trip Number

        lv_task_id        type  SWW_WIID,                               ” Task Id number

        lv_taks_container type ref to IF_SWF_IFS_PARAMETER_CONTAINER.   ” Container

 

* Data type for document attachment

  Data:  lv_html          type standard table of bapihtml,

         lv_html1         type standard table of SOLISTI1,

         lv_html_xstring  type xstring,

         lv_html_string   type string,

         lv_user_data     type soudatai1,

         lv_doc_info      type sofolenti1,

         lv_object_header type standard table of solisti1,

         lv_soxobjcont    type soxobj,

         lv_user          type SOUDNAMEI1,

         lv_docid         type OBJ_RECORD,

         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_sofm_read     type ref to sofm,

         lv_OBJ_RECORD    type OBJ_RECORD,

         lv_objects       TYPE sibflporbt,

         lv_SWOTRETURN    type SWOTRETURN.

* Read task ID which

  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_taks_container.

* Read Variable in container – Employee Number

  call method lv_taks_container->get

    EXPORTING

      NAME  = ‘Empno’

    IMPORTING

      value = lv_pernr.

* Read Variable in container – Trip Number

  call method lv_taks_container->get

    EXPORTING

      NAME  = ‘Tripno’

    IMPORTING

      value = lv_tripno.

* Read atttachment to confirm that there is no duplication

  clear lv_obj_record.

  call method lv_taks_container->get

    EXPORTING

      Name  = ‘_ATTACH_OBJECTS’

    IMPORTING

      Value = lv_objects.

  if lv_objects is initial.

*Retreive the Trip info in html format for an employee

    CALL FUNCTION ‘BAPI_TRIP_GET_FORM_HTML’

      EXPORTING

        employeenumber = lv_pernr

        tripnumber     = lv_tripno

        DISPLAY_FORM   = ‘X’

        EINKOPF        = ‘X’

      TABLES

        tripform_html  = lv_html.

* convert the table format acceptable by function module  SO_DOCUMENT_INSERT_API1

    lv_html1[] = lv_html[].

* 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-objtype = ‘ZBUS2089’.

    concatenate lv_pernr lv_tripno into lv_soxobjcont-objkey.

    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’.

    Concatenate ‘Display Trip Result:’ lv_tripno into lv_document_data-obj_descr separated by space.

    CALL FUNCTION ‘SO_DOCUMENT_INSERT_API1’

      EXPORTING

        FOLDER_ID                  = lv_folder_id_2

        DOCUMENT_DATA              = lv_document_data

        DOCUMENT_TYPE              = ‘HTM’

      IMPORTING

        DOCUMENT_INFO              = lv_doc_info

      TABLES

        OBJECT_HEADER              = lv_object_header

        OBJECT_CONTENT             = lv_html1

      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_taks_container->set

      EXPORTING

        Name  = ‘_ATTACH_OBJECTS’

        Value = lv_obj_record.

* Commit the changes

    CALL METHOD IM_WORKITEM_CONTEXT->DO_COMMIT_WORK.

  endif.

Step 2:- Attach this class to your workflow task where you want to create the attachment.

Assign class to task

Step 3:- Do not forget to remove the _adhoc_objects assignment to the task else it will display two attachments, one for HTML GUI  and another attachment created by your class.

Task Binding

Step 4:- Execute the scenario and see the result J

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply