0% found this document useful (0 votes)
481 views5 pages

If SWF Ifs Workitem Exit

This document describes methods used to attach documents to a workflow work item in SAP. It converts a string to an XSTRING and SOLIX table to store in the SAP document management system. When a work item is completed, it checks for attachments, inserts a new document into the document table, creates a reference object, and adds the attachment to the work item container and attachment list.

Uploaded by

Sandeep Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
481 views5 pages

If SWF Ifs Workitem Exit

This document describes methods used to attach documents to a workflow work item in SAP. It converts a string to an XSTRING and SOLIX table to store in the SAP document management system. When a work item is completed, it checks for attachments, inserts a new document into the document table, creates a reference object, and adds the attachment to the work item container and attachment list.

Uploaded by

Sandeep Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

IF_SWF_IFS_WORKITEM_EXIT

IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED
method IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED.

  DATA: lv_id TYPE sww_wiid,
        lv_container TYPE REF TO if_swf_ifs_parameter_container,
        lv_attach TYPE TABLE OF obj_record, lv_folder_id TYPE soodk,
        lv_str TYPE string, lv_size TYPE so_obj_len,
        wa_document_info TYPE sofolenti1,
        lv_data TYPE sodocchgi1,
        lv_objtype TYPE swotobjid-objtype,
        lv_objkey TYPE swotobjid-objkey,
        lv_return TYPE swotreturn,
        lv_sofm TYPE swotrtime-object,
        lv_objject TYPE obj_record,
        tb_obj TYPE TABLE OF obj_record,
        it_solix_tab1 TYPE solix_tab.
  DATA ob TYPE REF TO CL_DOCUMENT_BCS.
  CREATE OBJECT ob.

  CHECK im_event_name = 'CREATED'.
* FETCH the workflow WORK item ID
  CALL METHOD im_workitem_context->get_workitem_id
  RECEIVING re_workitem = lv_id.
* FETCH Container
  CALL METHOD im_workitem_context->get_wi_container
  RECEIVING re_container = lv_container.
* READ attachment TO confirm that there IS NO duplication
*CLEAR LV_OBJ_RECORD.
  TRY.
    CALL METHOD lv_container->get
    EXPORTING name = '_ATTACH_OBJECTS'
      IMPORTING VALUE = lv_attach.
    CATCH: cx_swf_cnt_elem_not_found,
      cx_swf_cnt_elem_type_conflict,
      cx_swf_cnt_unit_type_conflict,
      cx_swf_cnt_container.
  ENDTRY.
  IF lv_attach IS INITIAL.
    CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
    EXPORTING
      owner = sy-uname
      region = 'B'
      IMPORTING
        folder_id = lv_folder_id.
* CREATE AND SET document
    DO 5 TIMES.
    CONCATENATE lv_str 'Hello' ',' 'my' ',' 'friend!'
    cl_abap_char_utilities=>cr_lf INTO lv_str.
    ENDDO.
*---you can use CL_DOCUMENT_BCS CLASS FOR this purpose
    CALL METHOD me->string_to_solix
    EXPORTING
      iv_string = lv_str
      iv_codepage = '4110'
      IMPORTING
        et_solix = it_solix_tab1
        ev_size = lv_size.

    lv_data-obj_name = 'Test Sending Attachments'.
    lv_data-obj_descr = 'Attachment 1'.
    lv_data-obj_langu = sy-langu.
    lv_data-sensitivty = 'P'.
    lv_data-doc_size = lv_size.

    CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
    EXPORTING
      folder_id = lv_folder_id
      document_data = lv_data
      document_type = 'XLS'
      IMPORTING
        document_info = wa_document_info
         TABLES
           contents_hex = it_solix_tab1
           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.
* Populate object TYPE AND object KEY FOR CREATE an instance
    lv_objtype = 'SOFM'.
    lv_objkey = wa_document_info-doc_id.
    CALL FUNCTION 'SWO_CREATE'
    EXPORTING
      objtype = lv_objtype
      objkey = lv_objkey
      IMPORTING
        object = lv_sofm
        RETURN = lv_return
        EXCEPTIONS
          no_remote_objects = 1
          OTHERS = 2.
* Prepare FOR attaching the object TO container
    lv_objject-HEADER = 'OBJH'.
    lv_objject-TYPE = 'SWO'.
    lv_objject-handle = lv_sofm.
    APPEND lv_objject TO tb_obj.
*---can be used FOR other workitems
    CALL METHOD lv_container->set
    EXPORTING
      name = '_ATTACH_OBJECTS'
      VALUE = tb_obj[].
*--this will ADD the attachment TO email
    CALL METHOD lv_container->set
    EXPORTING
      name = 'ATTACHMENTS'
      VALUE = tb_obj[].
* COMMIT the changes
    CALL METHOD im_workitem_context->do_commit_work.

  ENDIF.
endmethod.

STRING_TO_XSTRING

IV_STRING Importing Type STRING

IV_CONVERT_CP Importing Type OS_BOOLEAN 'X'

IV_CODEPAGE Importing Type ABAP_ENCOD

IV_ADD_BOM Importing Type OS_BOOLEAN

EV_XSTRING Returning Type XSTRING

method STRING_TO_XSTRING.
  DATA lo_conv TYPE REF TO cl_abap_conv_out_ce.
  DATA lv_bom TYPE xstring.
  DATA lv_xbuf TYPE xstring.
  DATA lv_cp TYPE abap_encod.

  TRY.
    IF iv_convert_cp IS INITIAL.
      EXPORT p = iv_string TO DATA BUFFER lv_xbuf.
      IMPORT p = ev_xstring FROM DATA BUFFER lv_xbuf IN CHAR-TO-HEX MODE.
      ELSE.
        IF iv_codepage IS INITIAL.
          lv_cp = cl_sx_mime_singlepart=>get_sx_node_codepage( ).
          ELSE.
            lv_cp = iv_codepage.
             ENDIF.
* convert string to xstring using class cl_abap_conv_out_ce
* in this form available also in 620
             lo_conv = cl_abap_conv_out_ce=>create( encoding = lv_cp ignore
_cerr = 'X' ).
             lo_conv->write( data = iv_string ).

             ev_xstring = lo_conv->get_buffer( ).
* add the byte order mark
             IF iv_add_bom = 'X'.
               CASE lv_cp.
                 WHEN '4110'. "UTF-8
                   lv_bom = cl_abap_char_utilities=>byte_order_mark_utf8.
                   WHEN '4102'. "UTF-16BE
                     lv_bom = cl_abap_char_utilities=>byte_order_mark_big.
                     WHEN '4103'. "UTF-16LE
                       lv_bom = cl_abap_char_utilities=>byte_order_mark_lit
tle.
                       ENDCASE.

                       IF lv_bom IS NOT INITIAL.
                         CONCATENATE lv_bom ev_xstring INTO ev_xstring IN B
YTE MODE.
                         ENDIF.
                         ENDIF.
                         ENDIF.
                         CATCH cx_root. "#EC*
 RAISE EXCEPTION TYPE cx_bcs EXPORTING error_type = cx_bcs=>creation_failed
.
 ENDTRY.

endmethod.

XSTRING_TO_SOLIX

IV_XSTRING Importing Type XSTRING

ET_SOLIX Returning Type SOLIX_TAB

METHOD xstring_to_solix.
  DATA : lv_size TYPE i,
         lv_off  TYPE i,
         ls_solox TYPE solix,
         lv_rows TYPE i,
         lv_last_row_len TYPE i,
         lv_row_len TYPE i.

  DESCRIBE TABLE et_solix.
  lv_row_len = sy-tleng.
  lv_size = xstrlen( iv_xstring ).
  lv_rows = lv_size DIV lv_row_len.
  lv_last_row_len = lv_size MOD lv_row_len.
  DO lv_rows TIMES.
    ls_solox-line = iv_xstring+lv_off(lv_row_len).
    APPEND ls_solox TO et_solix.
    ADD lv_row_len TO lv_off.
  ENDDO.
  IF lv_last_row_len > 0.
    ls_solox-line = iv_xstring+lv_off(lv_last_row_len).
    APPEND ls_solox TO et_solix.

  ENDIF.
ENDMETHOD.

STRING_TO_SOLIX

IV_STRING Importing Type STRING

IV_CONVERT_CP Importing Type OS_BOOLEAN 'X'

IV_CODEPAGE Importing Type ABAP_ENCOD

IV_ADD_BOM Importing Type OS_BOOLEAN

ET_SOLIX Exporting Type SOLIX_TAB

EV_SIZEExporting Type SO_OBJ_LEN

method STRING_TO_SOLIX.

  DATA: lv_xstring TYPE xstring.
  lv_xstring = STRING_TO_xstring(
  iv_string     = iv_string
  iv_codepage   = iv_codepage
  iv_add_bom    = iv_add_bom ).

  et_solix = xstring_to_solix( lv_xstring ).
  ev_size  = xstrlen( lv_xstring ).
endmethod.

You might also like