cancel
Showing results for 
Search instead for 
Did you mean: 

CRM_DATAEXCHG_BADI - Field not saving in CRMD_ORDERADM_H Table

Former Member
0 Kudos

Hi All,

I am facing an issue where the Posting Date from crmd_orderadmh table is clearing out for some of the Contract somewhere in the system during processing of the contract (Reason for this is unknown and probably it is clearing out in ISU System and root cause is being worked upon ).

So as a work around I am trying to fill the posting date in the BDOC. I am filling up the posting date from the 'creation date' of the contract by below code.

After the code fix I can see that the BUS_TRANS_MSG contains the posting date but it is not updating the CRMD_ORDERADM_H Table finally. I have written the code in BADI CRM_DATAEXCHG_BADI in method CRM_DATAEXCH_AFTER_MBDOC_FILL. I am not a middleware guy and have been suggested to write the code in this BADI.

Can anybody please help me out why the field is not getting updated into the table. Is the method correctly choosen. A quick help will be appriciated.


    DATA : lv_posting_date TYPE crmt_posting_date,
           lv_crm_guid     TYPE crmt_object_guid,
           ls_orderadm_h   TYPE bad_orderadm_h_mess,
           lv_created_at   TYPE comt_created_at_usr.
    TYPES :BEGIN OF lty_crmd_orderadm,
             guid         TYPE crmt_object_guid,
             posting_date TYPE crmt_posting_date,
             created_at   TYPE comt_created_at_usr,
           END OF lty_crmd_orderadm.

    CONSTANTS : lc_0 TYPE crmt_posting_date VALUE '00000000'.

    DATA : lt_ty_crmd_orderadm TYPE STANDARD TABLE OF lty_crmd_orderadm,
           ls_ty_crmd_orderadm TYPE lty_crmd_orderadm.

    CHECK ct_message_ext-orderadm_h[] IS NOT INITIAL.

    SELECT  guid created_at posting_date FROM crmd_orderadm_h INTO TABLE lt_ty_crmd_orderadm FOR ALL

ENTRIES IN ct_message_ext-orderadm_h
      WHERE guid EQ ct_message_ext-orderadm_h-orderadm_h_guid.
    IF sy-subrc  = 0.
      SORT lt_ty_crmd_orderadm BY guid.
    ENDIF.

    FIELD-SYMBOLS: <fs_orderadm_h>  TYPE bad_orderadm_h_mess.

    LOOP AT ct_message_ext-orderadm_h ASSIGNING <fs_orderadm_h>.
      IF <fs_orderadm_h>-posting_date EQ space OR <fs_orderadm_h>-posting_date EQ lc_0 .
        lv_crm_guid = <fs_orderadm_h>-orderadm_h_guid.

        READ TABLE lt_ty_crmd_orderadm INTO ls_ty_crmd_orderadm WITH KEY guid = lv_crm_guid BINARY SEARCH. "binary search
        IF sy-subrc = 0.
          lv_created_at = ls_ty_crmd_orderadm-created_at.
          CALL FUNCTION 'ADDR_CONVERT_TIMESTAMP_TO_DATE'
            EXPORTING
              iv_timestamp = lv_created_at
            IMPORTING
              ev_date      = lv_posting_date.

          <fs_orderadm_h>-posting_date = lv_posting_date.
        ENDIF.
      ENDIF.
    ENDLOOP.

Many Thanks,

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Can anybody please suggest something. Many Thanks

former_member202253
Participant
0 Kudos

Hello V Singh,

As per my understating, you want to update "CRMD_ORDERADM_H" when posting date is initial.

I don't think so, CRM_DATAEXCHG_BADI will help you to update table, the above code will help you when data is going to replicate in ECC.

I would suggest to use "ORDER_SAVE" BADI method "check_before_save", you can write your logic to check whether record has Posting Date or not if not the you can update buffer using either FM : CRM_ORDER_MAINTAIN or CRM_ORDERADM_H_CHANGE_OW.

Note: Make sure you should not "commit" into BADI and should not call FM:CRM_ORDER_SAVE as ORDER_SAVE BADI called from FM CRM_ORDER_SAVE

Hope this will help you...

Thanks & Regards,

Nikhil