Skip to Content
avatar image
Former Member

SAP Recordsmanagement, store document in the KPRO

Hi,

I'm developing an extension of the SAP Case Management. The requirement is to store a WordDoc or PPT in in the knowledge provider. Can somebody give me some advice how to do this?

Thanks

M.Sigal,

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 16, 2005 at 10:42 PM

    Thanks,

    that works. But the next problem came up immediately.

    How can I retreive the documents again which have been written into the KPRO?

    M.Sigal

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 16, 2005 at 09:36 PM

    Hi M.,

    Please have a look at the following example. It contains a little bit more but especially the function modules

    SRM_DOCUMENT_CREATE and

    SRM_DOCUMENT_CHECKIN_VIA_TAB

    are the important ones

    Regards,

    Ruediger

    FUNCTION UDM_BD_CREATE_ATTACHMENT.
    *"----------------------------------------------------------------------
    *"*"Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(I_GUID) TYPE  SCMG_CASE_GUID
    *"     REFERENCE(I_CASE) TYPE REF TO  IF_SCMG_CASE_API
    *"     REFERENCE(I_TESTRUN) TYPE  TESTRUN
    *"  TABLES
    *"      BIN_CONTENT STRUCTURE  BAPICONTEN
    *"      COMPONENTS STRUCTURE  BAPIDOCCOMP
    *"  CHANGING
    *"     REFERENCE(ES_RETURN) TYPE  BAPIRET2
    *"  RAISING
    *"      CX_SRM_INITIALIZATION
    *"      CX_SRM_SP_RECORD_ELEMENT
    *"      CX_SRM_SP_RECORD
    *"      CX_SRM_SK
    *"      CX_SRM_FRAMEWORK
    *"----------------------------------------------------------------------
    
      DATA:
    
        ANCHOR TYPE  STRINGVAL,
        SPS_ID TYPE  STRINGVAL,
        SP_ID  TYPE  STRINGVAL,
        RMS_ID TYPE  STRINGVAL,
        SRM_LIST TYPE  SRM_LIST_POID,
        lref_rec TYPE REF TO if_srm_sp_record,
        lref_element TYPE REF TO if_srm_sp_record_element,
        lref_ele     TYPE REF TO if_srm_sp_record_elem_instance,
        lt_sp_poid TYPE srm_list_poid,
        ls_sp_poid TYPE srmpoid,
        lo_bor_poid TYPE REF TO if_srm_poid,
        okay type c,
        lref_api TYPE REF TO if_scmg_case_api
    
        .
    
      DATA: l_docid TYPE bapidocid,
          l_objid TYPE bapiguid,
          l_docclass TYPE bapidclass
          .
    
    
      DATA:
          lt_filename TYPE filetable,
          ls_filename TYPE file_table,
          l_rc        TYPE i,
          file_tab   TYPE TABLE OF bapidocfiles,
    
          l_fname     TYPE string,
          l_path      TYPE string,
          lt_tab      TYPE STANDARD TABLE OF string,
          l_lines     TYPE i.
    
      DATA:
          i_toadd_line      TYPE toadd,
          wa_file    TYPE bapidocfiles,
          l_mime            TYPE string,
          i_toadd           TYPE STANDARD TABLE OF toadd,
          l_extension TYPE string.
    
      data:
            ls_components type BAPIDOCCOMP,
            lt_COMPONENTS type table of BAPIDOCCOMP,
            lt_bin_content type table of BAPICONTen.
    
    
      lt_COMPONENTS = components[].
      lt_bin_content = bin_content[].
      loop at lt_components into ls_components.
        exit.
      endloop.
    
    
      CALL FUNCTION 'UDM_GET_DOCUMENT_DATA'
        EXPORTING
          I_GUID     = I_GUID
          I_CASE     = I_CASE
        IMPORTING
          E_ANCHOR   = ANCHOR
          E_SPS_ID   = SPS_ID
          E_SP_ID    = SP_ID
          E_RMS_ID   = RMS_ID
          E_SRM_LIST = SRM_LIST.
    
    
      if i_case is initial.
        CALL METHOD cl_scmg_case_api=>get_case
          EXPORTING
            im_case_guid = i_guid
            im_enqueue   = 'X'
          RECEIVING
            re_case      = lref_api
          EXCEPTIONS
            failed       = 1
            invalid_guid = 2.
        IF sy-subrc EQ 1.
          CALL FUNCTION 'UDM_GEN_PREPARE_RETURN'
            EXPORTING
              i_number  = '009'
            IMPORTING
              es_return = es_return.
          EXIT.
        ELSEIF sy-subrc EQ 2.
          CALL FUNCTION 'UDM_GEN_PREPARE_RETURN'
            EXPORTING
              i_number     = '038'
              i_message_v1 = i_guid
            IMPORTING
              es_return    = es_return.
          EXIT.
        ENDIF.
        if 1 = 2.        "for cross reference
                  MESSAGE E009(UDM_MSG).
        endif.
        if 1 = 2.        "for cross reference
                  MESSAGE E038(UDM_MSG) with i_guid.
        endif.
        .
    
      else.
        lref_api = i_case.
      endif.
    
    
      CONCATENATE sy-datum sy-uzeit sp_id INTO l_docid.
    
      data description type BAPIDESCR.
      data tmprmsid type BAPIRMSID.
      data tmpspsid type BAPISPSID.
      tmprmsid = RMS_ID.
      tmpspsid = SPS_ID.
      description = ls_components-comp_id.
      l_fname = description.
      CALL FUNCTION 'SRM_DOCUMENT_CREATE'
        EXPORTING
          RMS_ID                  = tmprmsid
          SPS_ID                  = tmpspsid
          DOCUMENTID              = l_docid
          DESCRIPTION             =      description
          DO_COMMIT               = 'X'
    *      DOC_CONTEXT             =
        IMPORTING
          RETURN                  = es_return
          OBJECTID                = l_objid
          DOCUMENTCLASS           = l_docclass
       EXCEPTIONS
         INTERNAL_ERROR          = 1
         PARAMETER_ERROR         = 2
         DOC_ID_NOT_UNIQUE       = 3
         NOT_AUTHORIZED          = 4
         CUSTOMIZING_ERROR       = 5
         OTHERS                  = 6
                .
      IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    * no handling necessary because error is passed through es_return
        exit.
      ENDIF.
    
    
    
      SELECT * FROM toadd INTO TABLE i_toadd
               WHERE  mimetype = ls_components-mimetype.
    
      IF sy-subrc ne 0.
    
        l_mime = ls_components-mimetype.
    
      ELSE.
    
        l_mime = 'text/x-doctype'.                              "#EC NOTEXT
    
      ENDIF.
      wa_file-comp_count = 1.
      wa_file-comp_id = ls_components-comp_id.
      wa_file-directory = l_path.
      wa_file-filename = l_fname.
      wa_file-mimetype = l_mime.
      wa_file-comp_num = 1.
      APPEND wa_file TO file_tab.
    
      if i_testrun is initial.
        CALL FUNCTION 'SRM_DOCUMENT_CHECKIN_VIA_TAB'
          EXPORTING
            OBJECTID                = l_objid
            DOCUMENTCLASS           = l_docclass
    *     AS_NEW_VERSION          =
    *     DO_COMMIT               =
    *     DOC_CONTEXT             =
    *   IMPORTING
    *     X_NEW_DOC_CREATED       =
    *     RETURN                  =
          TABLES
            COMPONENTS              = lt_components
    *     ASCII_CONTENT           =
            BIN_CONTENT             = lt_bin_content
        EXCEPTIONS
         INTERNAL_ERROR          = 1
         PARAMETER_ERROR         = 2
         NOT_AUTHORIZED          = 3
         DOC_NOT_FOUND           = 4
         YET_LOCKED              = 5
         OTHERS                  = 6
                  .
        IF SY-SUBRC <> 0.
          CALL FUNCTION 'UDM_GEN_PREPARE_RETURN'
            EXPORTING
              i_number     = '166'
              i_message_v1 = i_guid
            IMPORTING
              es_return    = es_return.
          EXIT.
    
        ENDIF.
        if 1 = 2.        "for cross reference
                  MESSAGE E166(UDM_MSG) with i_guid.
        endif.
    
    
        CALL METHOD lref_api->get_backend_record
          RECEIVING
            re_record_backend = lref_rec
          EXCEPTIONS
            failed            = 1
            OTHERS            = 2.
        IF sy-subrc <> 0.
          CALL FUNCTION 'UDM_GEN_PREPARE_RETURN'
            EXPORTING
              i_number     = '167'
              i_message_v1 = i_guid
            IMPORTING
              es_return    = es_return.
        ENDIF.
        if 1 = 2.        "for cross reference
                  MESSAGE E167(UDM_MSG) with i_guid.
        endif.
    
        CALL METHOD lref_rec->element_create
          RECEIVING
            element = lref_element.
        lref_element->DESCRIPTION_SET( l_fname ).
        lref_ele ?= lref_element.
    
    
        REFRESH lt_sp_poid.
        ls_sp_poid-id    = 'DOC_ID'.
        CONCATENATE l_docclass l_objid INTO ls_sp_poid-value SEPARATED BY space.
    *ls_sp_poid-value = l_docid.
        INSERT ls_sp_poid INTO TABLE lt_sp_poid.
        ls_sp_poid-id    = 'VARIANT'.
        ls_sp_poid-value = '0'.
        INSERT ls_sp_poid INTO TABLE lt_sp_poid.
        ls_sp_poid-id    = 'VERSION'.
        ls_sp_poid-value = '0'.
        INSERT ls_sp_poid INTO TABLE lt_sp_poid.
    
        lo_bor_poid = cl_scmg_case_api=>g_client_service->poid_get_instance(
                                     im_sps_id  = sps_id
                                     im_rms_id  = rms_id
                                     im_sp_poid = lt_sp_poid ).
    
        CALL METHOD lref_ele->poid_set
          EXPORTING
            poid = lo_bor_poid.
        lref_element->type_set( if_srm_sp_record_element=>type_instance ).
    
        try.
    
            CALL METHOD lref_rec->element_add_by_anchor
              EXPORTING
                anchor  = 'BDATT'
                element = lref_element.
    
          catch CX_SRM_SP_RECORD.
            CALL METHOD lref_rec->element_add_by_anchor
              EXPORTING
                anchor  = '#INITIAL#'
                element = lref_element.
        endtry.
    
    
    **>>>> workaround because LREF_API->SAVE does not save the
    **     records backend
    *    TRY.
    *        CALL METHOD LREF_REC->SAVE
    *          EXPORTING
    *            NEW_VERSION = space.
    *      CATCH CX_SRM_SP_RECORD .
    *      CATCH CX_SRM_GSP_BACK .
    *    ENDTRY.
    **<<<<<<<<
    *
    **    lref_api->save( ).
    **    g_d_att_not_yet_saved = 'X'.
    *    CALL METHOD LREF_API->SAVE
    *       EXPORTING
    *         IM_DEQUEUE     = SPACE
    **        IM_NEW_VERSION = SPACE
    **      IMPORTING
    **        EX_MESSAGES    =
    *       EXCEPTIONS
    *         FAILED         = 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.
    *    else.
    *      message ID 'UDM_MSG'
    *      TYPE 'S'
    *      NUMBER 157
    *            .
    *    ENDIF.
    
    
      endif.
    
    *  CALL METHOD LREF_API->DEQUEUE
    *    RECEIVING
    *      RE_OKAY = okay
    *    EXCEPTIONS
    *      FAILED  = 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.
    
    
    
    ENDFUNCTION.
    

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Ruediger ,

      Can you please tell how can I upload an image file from XI to KPro.

      Actually the requirement is like this:

      The users will be scanning documents and will be saving it into a particular folder on which java program is written. This Java program will give the image file to XI. Now i have to take the file from XI to KPro.

      If you can provide any diffent method of doing this, I would be thankful.

      Thanks And Regards

      Rajiv Roshan