Skip to end of metadata
Go to start of metadata

In the below example it has been shown how the attachments in Services for Object can be attached in WorlItem that are to be sent to SAP Inbox.

Function Module 'BDS_ALL_CONNECTIONS_GET' gets all the document ids of attachments when no_gos_docs is given as space instead of 'X'. From document ids, we can get attachment data through FM 'SO_DOCUMENT_READ_API1'. The hexadecimal content is to be converted as binary file which can then be attached to Woritem through FM 'SAP_WAPI_ATTACHMENT_ADD'.

This FM is to be called through some zmethod in Business Object BUS2089. And in standard task, we need to call this method with proper binding.

  FUNCTION ztest_service_atta.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IV_WORKITEMID) TYPE  SWW_WIID OPTIONAL
*"     REFERENCE(IV_PERNR) TYPE  PERSNO
*"     REFERENCE(IV_REINR) TYPE  REINR
*"  TABLES
*"      T_ATTA STRUCTURE  SWR_ATT_ID
*"  EXCEPTIONS
*"      ATTACH_FAILED
*"----------------------------------------------------------------------

  DATA: gs_att_header TYPE swr_att_header.

  DATA: ls_lpor TYPE sibflporb,
  lt_lpor TYPE TABLE OF sibflporb,
  ls_option TYPE obl_s_relt,
  lt_option TYPE obl_t_relt,
  ls_rol_op TYPE obl_s_rolt,
  lt_rol_op TYPE obl_t_rolt,
  ls_links TYPE obl_s_link,
  lt_links TYPE obl_t_link,
  ls_folder TYPE soodk,
  ls_object TYPE soodk,
  ls_obj_hd TYPE sood2,
  lt_object_content_l TYPE TABLE OF solisti1,
  ls_object_content_l TYPE solisti1,
  lt_obj_cont TYPE TABLE OF soli,
  lt_conn TYPE TABLE OF bdn_con,
  ls_conn TYPE bdn_con,
  ls_atta TYPE swr_att_id,
  gv_file TYPE char255.

  DATA: lt_hex_cont TYPE TABLE OF solix,
        ls_hex_cont TYPE solix,
        gv_string TYPE string,
        gv_file_ext(3).

* Work areas
  DATA: lwa_doc_data        LIKE sodocchgi1,
        lwa_document_data   LIKE sofolenti1,
        lv_document_id      TYPE sofolenti1-doc_id,
        lwa_links           LIKE LINE OF lt_links,
        lwa_object          TYPE borident,
        ev_binfile TYPE xstring.

  FIELD-SYMBOLS <p> TYPE x.

  CONCATENATE iv_pernr iv_reinr INTO ls_lpor-instid.
  ls_lpor-typeid = 'BUS2089'.
  ls_lpor-catid = 'BO'.
  APPEND ls_lpor TO lt_lpor.

  ls_option-sign = 'I'.
  ls_option-option = 'EQ'.
  ls_option-low = 'ATTA'.
  APPEND ls_option TO lt_option.

  ls_rol_op-sign = 'I'.
  ls_rol_op-option = 'EQ'.
  ls_rol_op-low = 'GOSAPPLOBJ'.
  APPEND ls_rol_op TO lt_rol_op.

  CALL FUNCTION 'BDS_ALL_CONNECTIONS_GET'
    EXPORTING
      classname        = 'BUS2089'
      classtype        = 'BO'
      objkey           = ls_lpor-instid
      all              = 'X'
      no_gos_docs      = ''
    TABLES
      all_connections  = lt_conn
    EXCEPTIONS
      no_objects_found = 1
      error_kpro       = 2
      internal_error   = 3
      not_authorized   = 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.

* Process the attachment list
  LOOP AT lt_conn INTO ls_conn.
    lv_document_id = ls_conn-loio_id.
    CLEAR lt_hex_cont[].
* Read the data
    CALL FUNCTION 'SO_DOCUMENT_READ_API1'
      EXPORTING
        document_id                = lv_document_id
      IMPORTING
        document_data              = lwa_document_data
      TABLES
        contents_hex               = lt_hex_cont
      EXCEPTIONS
        document_id_not_exist      = 1
        operation_no_authorization = 2
        x_error                    = 3
        OTHERS                     = 4.
    CLEAR ev_binfile.
    LOOP AT lt_hex_cont INTO ls_hex_cont.
      ASSIGN ls_hex_cont TO <p> CASTING.
      CONCATENATE ev_binfile <p> INTO ev_binfile IN BYTE MODE.
    ENDLOOP.

    IF ev_binfile IS NOT INITIAL AND iv_workitemid IS NOT INITIAL.
      gv_file_ext = ls_conn-docuclass.
      TRANSLATE gv_file_ext TO UPPER CASE.
      gs_att_header-file_type       = 'B'.
      gs_att_header-file_extension  = gv_file_ext.
      CONCATENATE 'Scanned Atta.' gv_file_ext INTO gs_att_header-file_name.
      gs_att_header-language        = 'EN'.
      CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
        EXPORTING
          workitem_id = iv_workitemid
          att_header  = gs_att_header
          att_bin     = ev_binfile
          do_commit   = 'X'
        IMPORTING
*        return_code = ev_return_code
          att_id      = ls_atta.

      IF ls_atta IS INITIAL.
        RAISE attach_failed.
      ENDIF.
      APPEND ls_atta TO t_atta.
      CLEAR ls_atta.
    ENDIF.
  ENDLOOP.

ENDFUNCTION.

  • No labels