Sample Code

The sample code for adding a new segment and new fields is illustrated below:

Sample Code for Adding a New Segment

The customer has created a new table and a corresponding BDoc segment, and performs the mapping in user exit methods and sets task and sendbits.

Definition of the method

method IF_EX_CRM_30A_USER_EXITS~USER_EXIT_DOWNLOAD_SERVICE

IS_BUS_TRANS_MSG   Importing    Type   BAD_BUS_TRANSN_MESSAGE

IU_SRVSET_WRITE    Importing    Type   /1CRMG0/SRV_WRITE    

ET_SRVSET_WRITE    Changing Type   /1CRMG0/SRV_WRITE

User exit Implementation

Method if_ex_crm_30a_user_exits~user_exit_download_service .

*    Declare Work areas for the new structure.

    data: l_zzsmokna1 type /crmgec/zzsmokna1002,

          l_cdbd_partner type /1crmg0/cdbd_partner002.

    loop at et_srvset_write-cdbd_partner into l_cdbd_partner.

      l_zzsmokna1-zzsfakna1   =    l_cdbd_partner-partner_guid.

      l_zzsmokna1-zzmandt     =   l_cdbd_partner-client.  

      l_zzsmokna1-zzsfaadrc   =    l_cdbd_partner-rootseg_guid.

      l_zzsmokna1-zztest     =    'CUST1'.

*      Set the task (2 stands for Insert)

      l_zzsmokna1-task        = 2.

*      Generate the Senbits for all the fields in the segment

     Call function 'COM_SENDBITS_FETCH_SERVICE'

        Exporting

          is_structure = '/CRMGEC/ZZSMOKNA1002'

        Importing

          ev_sendbits   = l_zzsmokna1-sendbits.

*      Append this data to the BDoc segment

      Append l_zzsmokna1 to et_srvset_write-zzsmokna1.

      Clear l_zzsmokna1.

    endloop.

  endmethod. "IF_EX_CRM_30A_USER_EXITS~USER_EXIT_DOWNLOAD_SERVICE

Sample Code for Adding New Fields

The customer adds two fields (NEW_FIELD_1 and NEW_FIELD_2) to the already existing table cdbd_orderadm_Iand adds mapping for these fields in the user exits. The customer then generates sendbits for the newly added fields and combines it with the standard sendbits for the segment.

Definition of the method

Method IF_EX_CRM_30A_USER_EXITS~USER_EXIT_DOWNLOAD_SERVICE .

IS_BUS_TRANS_MSG   Importing    Type   BAD_BUS_TRANSN_MESSAGE

IU_SRVSET_WRITE    Importing    Type   /1CRMG0/SRV_WRITE    

ET_SRVSET_WRITE    Changing Type   /1CRMG0/SRV_WRITE

User exit Implementation

Method if_ex_crm_30a_user_exits~user_exit_download_service .

* Declare workarea for the CRM and CDB item segments

DATA: L_CDBD_ORDERADM_I TYPE /1CRMG0/CDBD_ORDERADM_I003,

           L_CRMD_ORDERADM_I TYPE BAD_ORDERADM_I_MESS.

* Declare Structure of the BDoc segment and

* a local internal table of structure somg_sfldn.

DATA: IS_STRUCTURE TYPE DDOBJNAME.

DATA: LT_SFIELD     TYPE TABLE OF SMOG_SFLDN.

DATA: L_TABIX TYPE SYST-TABIX.

* Declaration for Sendbits

DATA: EV_SENDBITS_USEREXITS TYPE SMOG_SINC-SENDBITS.

      IS_STRUCTURE = '/1CRMG0/CDBD_ORDERADM_I003'.

   L_TABIX = 0.

* Repeat mapping for each item.

LOOP AT ET_SRVSET_WRITE-CDBD_ORDERADM_I INTO L_CDBD_ORDERADM_I.

L_TABIX = L_TABIX + 1.

*    If the item is inserted or updated.

  IF L_CDBD_ORDERADM_I-TASK = 1 OR L_CDBD_ORDERADM_I-TASK = 2 .

*      Read the corresponding item segment in the CRM BDoc type

        READ TABLE IS_BUS_TRANS_MSG-ORDERADM_I INTO   L_CRMD_ORDERADM_I

    WITH KEY GUID = L_CDBD_ORDERADM_I-ORDERADM_I_GUID.

*      Implement your logic

    IF L_CRMD_ORDERADM_I-ITM_TYPE = 'SRVP'.

           MOVE 'SERVICE' TO L_CDBD_ORDERADM_I-NEW_FIELD_1.

      MOVE 'PRODUCT' TO L_CDBD_ORDERADM_I-NEW_FIELD_2.

    ELSE.

      MOVE 'SALES' TO L_CDBD_ORDERADM_I- NEW_FIELD_1.

      MOVE '' TO L_CDBD_ORDERADM_I- NEW_FIELD_2.

    ENDIF.

*      Generate the sendbits for the newly added fields.

             CLEAR: EV_SENDBITS_USEREXITS.

        REFRESH: LT_SFIELD.

             APPEND 'NEW_FIELD_1' TO LT_SFIELD.

        APPEND 'NEW_FIELD_2' TO LT_SFIELD.

     CALL FUNCTION 'SMO_SNDBITS_SETX'

             EXPORTING

              STRUCTURENAME        = IS_STRUCTURE

              DDIC                 = 'X'

              TABLES

              SFIELDS              = LT_SFIELD

              CHANGING

              SNDBITS              = EV_SENDBITS_USEREXITS

              EXCEPTIONS

              STRUCTURE_NOT_FOUND = 1

              WRONG_FIELDNAME      = 2

           OTHERS               = 3.

*      Combine the standard sendbits and the sendbits generated by user exits.

        L_CDBD_ORDERADM_I-SENDBITS =

 L_CDBD_ORDERADM_I-SENDBITS BIT-OR EV_SENDBITS_USEREXITS.

*      Modify the item segment with the new fields

        MODIFY ET_SRVSET_WRITE-CDBD_ORDERADM_I

        FROM L_CDBD_ORDERADM_I INDEX L_TABIX

     TRANSPORTING NEW_FIELD_1 NEW_FIELD_2 SENDBITS.

     ENDIF.

ENDLOOP.

Endmethod. "IF_EX_CRM_30A_USER_EXITS~USER_EXIT_DOWNLOAD_SERVICE

* SAMPLE OUTPUT

*

* Standard sendbits 06140000000000000000000000000000000000000

*

* User Exit sendbits 01E30000000000000000000000000000000000000

*

* Final sendbits 07F70000000000000000000000000000000000000