Spend Management Blogs by Members
Check out community member blog posts about spend management and SAP Ariba, SAP Fieldglass, and SAP Concur solutions. Post or comment about your experiences.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member184111
Active Contributor

Scenario: You want to transfer PR header attachment from ERP to SRM Shopping Cart.

This blog shows how to transfer header attachments from PR to SRM SC when--

1.PR header attachments are Service(GOS) and NOT DMS.

2.Report BBP_EXTREQ_TRANSFER is used to send PR to SRM.

Since there is no concept of attachment at SC header we will attache the PR header attachments to first item of SC.

Step1--> Fetch the attachment data in ERP system as explained below.

Create a RFC enabled function module in back end system with following interface:

Importing Parameters:


Exporting Parameters:


Source Code of Function Module:

**conversion declaration

  DATA: lv_codep TYPE cpnormcp,

        lo_conu  TYPE REF TO cl_abap_conv_uc_number.

  DATA: lt_asci_list TYPE TABLE OF solisti1 WITH HEADER LINE,

        lt_conhex TYPE solix OCCURS 1 WITH HEADER LINE,

        lv_inp TYPE string,

        lv_ous TYPE xstring,

        lv_len TYPE i.

**End

  DATA: lo_is_object_a TYPE sibflporb.

  DATA: lt_rel TYPE obl_t_relt,

        wa_rel LIKE LINE OF lt_rel.

  DATA: lt_links TYPE obl_t_link,

        lw_links TYPE obl_s_link,

        lv_document_id TYPE so_entryid,

        ls_data TYPE sofolenti1.

  DATA lt_content TYPE swuoconttab.

  lo_is_object_a-typeid = 'BUS2105'.

  lo_is_object_a-catid  = 'BO'     .

  lo_is_object_a-instid = p_bo_id  .

  wa_rel-sign   = 'I'.

  wa_rel-option = 'EQ'.

  wa_rel-low    = 'ATTA' .

  APPEND wa_rel TO lt_rel.

  TRY.

      CALL METHOD cl_binary_relation=>read_links

        EXPORTING

          is_object           = lo_is_object_a

          it_relation_options = lt_rel

        IMPORTING

          et_links            = lt_links.

    CATCH cx_obl_parameter_error .

    CATCH cx_obl_internal_error .

    CATCH cx_obl_model_error .

  ENDTRY.

*  DESCRIBE TABLE lt_links LINES ev_records.

*  LT_LINKS contains one record for each attachment at header

* Read all attachments one by one

* In case of text files table it_solix(binary) is initial after below FM call but lt_asci_list is populated with CHAR format string passing this directly as *export/table parameter to the calling system(SRM)causes dump PARAMETER_CONVERSION_ERROR in calling system so alwasy convert the *CHAR strinh into Binary data before sending to calling system

  READ TABLE lt_links INTO lw_links INDEX iv_read_index.

  IF sy-subrc = 0.

    lv_document_id = lw_links-instid_b .

    CALL FUNCTION 'SO_DOCUMENT_READ_API1'

      EXPORTING

        document_id                = lv_document_id

      IMPORTING

        document_data              = ls_data

      TABLES

        object_content             = lt_asci_list

        contents_hex               = it_solix

      EXCEPTIONS

        document_id_not_exist      = 1

        operation_no_authorization = 2

        x_error                    = 3

        OTHERS                     = 4.

    es_data = ls_data.

* In case converting CHAR string to Binary data for sending to calling system

    IF NOT lt_asci_list[] IS INITIAL.

      CALL FUNCTION 'SYSTEM_CODEPAGE'     "get the current code page

        IMPORTING

         codepage   =  lv_codep

.

      CREATE OBJECT lo_conu            "instantiate cl_abap_conv_uc_number

      EXPORTING

           im_source_codepage        = lv_codep

      EXCEPTIONS

           converter_creation_failed = 1

           OTHERS                    = 2.

      LOOP AT lt_asci_list.

        WRITE cl_abap_char_utilities=>cr_lf TO lt_asci_list-line+253.  "to put linefeed at end

        MOVE lt_asci_list-line TO lv_inp.  "move char to input string

        CALL METHOD lo_conu->convert_char_stream   "call method to convert

        EXPORTING

           im_stream        = lv_inp

        IMPORTING

           ex_stream        = lv_ous

           ex_stream_len    = lv_len

        EXCEPTIONS

          conversion_error = 1

           OTHERS           = 2.

        IF sy-subrc <> 0.

          CONTINUE.   "if error in conversion than do no append to table

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

        ELSE.

          MOVE lv_ous TO lt_conhex-line.  "move the binary string to binary table

          APPEND lt_conhex.

        ENDIF.

      ENDLOOP.

      it_content[] = lt_conhex[].

    ENDIF.

  ELSE.

    ev_exit = 'X'.

  ENDIF.

*  ENDLOOP.

ENDFUNCTION.

Step2--> Changes on SRM Side

Create a new function module in SRM as shown below:

Importing Parameter:


Exporting Parameter:

Source Code of Function Module:

DATA: is_data       TYPE  sofolenti1,

        it_content    TYPE tabtype_solix,

        it_solix      TYPE tabtype_solix,

        ls_attach     TYPE bbps_pdext_attach,

        ls_sdokfext_c TYPE sdokfext_c,

        ls_sdokfext   TYPE sdokfext .

  DATA: lv_pr_no      TYPE char10  ,

        lv_logsys     TYPE char10,

        iv_exit       TYPE flag,

        ev_read_index TYPE i VALUE 1,

        lv_xstring    TYPE xstring.

  FIELD-SYMBOLS: <fs_hdr>    TYPE any,

                 <fs_pr_no>  TYPE any,

                 <fs_logsys> TYPE any.

* Get PR no.

  ASSIGN i_header TO <fs_hdr>.

  ASSIGN COMPONENT 'EXT_DEMID' OF STRUCTURE

                 <fs_hdr> TO <fs_pr_no>.

  lv_pr_no = <fs_pr_no>.

* Get Logical system

  ASSIGN COMPONENT 'EXT_DEM_LOGSYS' OF STRUCTURE

                <fs_hdr> TO <fs_logsys>.

  lv_logsys = <fs_logsys>.

  WHILE iv_exit IS INITIAL.

**Fetch header attachments from Backend System

    CALL FUNCTION 'RFC_CREATED_IN_BE_SYSTEM' DESTINATION lv_logsys

      EXPORTING

        p_bo_id       = lv_pr_no

        iv_read_index = ev_read_index

      IMPORTING

        es_data       = is_data

        it_content    = it_content

        it_solix      = it_solix

        ev_exit       = iv_exit.

    ev_read_index = ev_read_index + 1.

    IF NOT is_data IS INITIAL.

      ls_attach-guid          =  lv_pr_no.

      ls_attach-p_guid        = '0001'.

      ls_attach-description   = is_data-obj_descr.

* Get and set mime type

      TRANSLATE is_data-obj_type TO LOWER CASE.

      ls_attach-phio_ext      = is_data-obj_type.

* Searching in customer defined mime types

      CLEAR ls_sdokfext_c .

      SELECT SINGLE * FROM sdokfext_c

        INTO  ls_sdokfext_c

        WHERE extension = is_data-obj_type.

      IF sy-subrc NE 0 OR ls_sdokfext_c-type IS INITIAL.

* Searching in default mime types

        CLEAR ls_sdokfext .

        SELECT SINGLE * FROM sdokfext

          INTO  ls_sdokfext

          WHERE extension = is_data-obj_type.

        IF sy-subrc NE 0 OR ls_sdokfext-type IS INITIAL.

* no mime type found - assigning default mime type

          ls_attach-phio_mime = 'application/octetstream'.

        ELSE.

          ls_attach-phio_mime = ls_sdokfext-type.

        ENDIF.

      ELSE.

        ls_attach-phio_mime = ls_sdokfext_c-type.

      ENDIF.

      ls_attach-phio_fname    = is_data-obj_descr.

      ls_attach-phio_ps_mime  = is_data-obj_descr.

      ls_attach-phio_fsize    = is_data-doc_size.

      ls_attach-phio_fsize    = is_data-doc_size.

**convert SOLIX to XSTRING

      IF NOT it_solix IS INITIAL.

        CALL METHOD cl_bcs_convert=>solix_to_xstring

          EXPORTING

            it_solix   = it_solix

*           iv_size    =

          RECEIVING

            ev_xstring = lv_xstring.

      ELSEIF NOT  it_content IS INITIAL."for text files it_solix is initial and it_content has converted binary data

        CALL METHOD cl_bcs_convert=>solix_to_xstring

          EXPORTING

            it_solix   = it_content

*           iv_size    =

          RECEIVING

            ev_xstring = lv_xstring.

      ENDIF.

      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

        EXPORTING

          buffer     = lv_xstring

        TABLES

          binary_tab = ls_attach-phio_content.

      APPEND ls_attach TO et_attach.

    ENDIF.

  ENDWHILE.

ENDFUNCTION.

Standard function module BBP_BD_PDDOC_FROM_BAPI_MAPS is called on SRM side when transferring PR using BBP_EXTREQ_TRANSFER

Enhance function module BBP_BD_PDDOC_FROM_BAPI_MAPS at end.


We check the call stack to ensure that the FM is called by BBP_EXTREQ_TRANSFER only and not in any other process.

IF SY_SUBRC = 0.

   CALL FUNCTION 'FM_CREATED_IN_SRM_SYSTEM'

          EXPORTING

               I_HEADER     =   IS_HEADER  <--Already there in FM BBP_BD_PDDOC_FROM_BAPI_MAPS

               IT_ITEMS       =   IT_ITEMS      <--Already there in FM BBP_BD_PDDOC_FROM_BAPI_MAPS

          IMPORTING

               ET_ATTACH  = ET_ATTACH     <--Already there in FM BBP_BD_PDDOC_FROM_BAPI_MAPS

ENDIF.



2 Comments