cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with BADI ORDER_SAVE

Former Member
0 Kudos

Hi,

at the moment I want to extend the BADI ORDER_SAVE (method PREPARE) to fill some fields while the new activity is saved. I don't have a problem to read the temporary activity object and fill the fields, but how can I put back this changed data in the standard saving process? As the BADI only has the GUID as interface parameter I don't know how I should do it. I hope you can help me.

If you have other suggestions how I could fill field of an activity when you click on SAVE, I would appreciate it.

Thanks in advance.

Bye,

Timo

Accepted Solutions (1)

Accepted Solutions (1)

former_member182350
Active Contributor
0 Kudos

Hi Timo,

You can follow steps:

1. Check the process type by get Process type using FM: CRM_INTLAY_GET_PROCESS_TYPE

2. Read data using iv_guid with help of CRM_ORDER_READ.

3.Change the values and pass to CRM_ORDER_MAINTAIN. No need to call save.as its order_save badi

The folowing is the Code for reference used for put blocks in Sales Order while creation:

 
**Constants declaration
CONSTANTS:
       lc_kind_h          TYPE c         VALUE 'A',      "Adminstrative or header level
       lc_kind_i          TYPE c         VALUE 'B',      "For Item level
       lc_status          TYPE string    VALUE 'E0003',
       lc_type            TYPE zgcc_type VALUE 'ORDER_TYPE'.

** Variablesinternal tablelocal structure declaration
  DATA:lv_gcc_field       TYPE zgcc_field,
       lv_process_type    TYPE crmt_process_type,
       lv_object_id       TYPE crmt_object_id,
       lt_status_n        TYPE crmt_status_comt,
       ls_status_n        TYPE crmt_status_com,
       lt_billing         TYPE crmt_billing_comt,
       ls_billing         TYPE crmt_billing_com,
       lt_orderadm_i      TYPE crmt_orderadm_i_wrkt,
       ls_orderadm_i_wrk  TYPE crmt_orderadm_i_wrk,
       lt_input_fields    TYPE crmt_input_field_tab,
       ls_input_fields    TYPE crmt_input_field,
       ls_field_names     TYPE crmt_input_field_names,
       lt_field_names     TYPE crmt_input_field_names_tab,
       lt_shipping        TYPE crmt_shipping_comt,
       ls_shipping        TYPE crmt_shipping_com,
       lt_guid_header     TYPE crmt_object_guid_tab,
       lv_block_re_code   TYPE zgcc_value2,
       lv_block           TYPE c LENGTH 100,
       lt_lookup          TYPE TABLE OF zgccgl_s_lookuptbl,
       ls_lookup          TYPE zgccgl_s_lookuptbl,
       lt_status_old      TYPE crmt_status_wrkt,
       ls_status_old      TYPE crmt_status_wrk.

    IF  iv_guid IS NOT INITIAL.
      CALL FUNCTION 'CRM_ORDERADM_H_READ_OW'
        EXPORTING
          iv_orderadm_h_guid = iv_guid
        IMPORTING
          ev_process_type    = lv_process_type
          ev_object_id       = lv_object_id.
    ENDIF.
** Filter for new creation of the sales orders
    IF lv_object_id IS INITIAL.
      APPEND iv_guid TO lt_guid_header.
      CALL FUNCTION 'CRM_ORDER_READ'
        EXPORTING
          it_header_guid       = lt_guid_header
        IMPORTING
          et_orderadm_i        = lt_orderadm_i
          et_status            = lt_status_old
        EXCEPTIONS
          document_not_found   = 1
          error_occurred       = 2
          document_locked      = 3
          no_change_authority  = 4
          no_display_authority = 5
          no_change_allowed    = 6
          OTHERS               = 7.
      READ TABLE lt_orderadm_i INDEX sy-tabix INTO ls_orderadm_i_wrk.
      READ TABLE lt_status_old INDEX sy-tabix INTO ls_status_old.
      lv_gcc_field = lv_process_type.

** Get type of block from 'ZGCC_LOOKUPTBL' table for T_type
      CALL FUNCTION 'ZGCC_FM_LOOKUPTABLE_FIND'
        EXPORTING
          iv_type      = lc_type
          iv_field     = lv_gcc_field
        TABLES
          lt_lookuptbl = lt_lookup.

      READ TABLE lt_lookup INDEX sy-tabix INTO ls_lookup.
      lv_block         = ls_lookup-value1.
      lv_block_re_code = ls_lookup-value2.

** Check for type of block
      CASE lv_block.
        WHEN 'BLOCK_BILLING'.
          ls_status_n-ref_guid       = iv_guid.
          ls_status_n-ref_kind       = lc_kind_h.
          ls_status_n-status         = lc_status.
          ls_status_n-user_stat_proc = ls_status_old-user_stat_proc.
          ls_status_n-activate       = 'X'.
          APPEND ls_status_n TO lt_status_n.

          ls_input_fields-ref_guid     = ls_orderadm_i_wrk-guid.
          ls_input_fields-ref_kind     = lc_kind_i.
          ls_input_fields-objectname   = 'BILLING'.

          ls_field_names-fieldname     = 'BILLING_BLOCK'.
          APPEND ls_field_names TO lt_field_names.

          ls_input_fields-field_names   = lt_field_names.
          APPEND ls_input_fields TO lt_input_fields.
          REFRESH lt_field_names.

          ls_input_fields-ref_guid     = iv_guid.
          ls_input_fields-ref_kind     = lc_kind_h.
          ls_input_fields-objectname   = 'STATUS'.
*          ls_input_fields-logical_key  = lc_lkey_grf.

          ls_field_names-fieldname     = 'ACTIVATE'.
          APPEND ls_field_names TO lt_field_names.

          ls_input_fields-field_names   = lt_field_names.
          APPEND ls_input_fields TO lt_input_fields.
          REFRESH lt_field_names.

          ls_billing-ref_guid      = ls_orderadm_i_wrk-guid.
          ls_billing-ref_kind      = lc_kind_i.
          ls_billing-billing_block = lv_block_re_code.
          APPEND ls_billing TO lt_billing.

          CALL FUNCTION 'CRM_ORDER_MAINTAIN'
            EXPORTING
              it_billing        = lt_billing
              it_status         = lt_status_n
            CHANGING
              ct_input_fields   = lt_input_fields
            EXCEPTIONS
              error_occurred    = 1
              document_locked   = 2
              no_change_allowed = 3
              no_authority      = 4
              OTHERS            = 5.
          IF sy-subrc <> 0.
          ENDIF.
        WHEN 'BLOCK_DELIVERY'.
          ls_status_n-ref_guid       = iv_guid.
          ls_status_n-ref_kind       = lc_kind_h.
          ls_status_n-status         = lc_status.
          ls_status_n-user_stat_proc = ls_status_old-user_stat_proc.
          ls_status_n-activate       = 'X'.
          APPEND ls_status_n TO lt_status_n.

          ls_input_fields-ref_guid     = ls_orderadm_i_wrk-guid.
          ls_input_fields-ref_kind     = lc_kind_i.
          ls_input_fields-objectname   = 'SHIPPING'.

          ls_field_names-fieldname     = 'DELIVERY_BLOCK'.
          APPEND ls_field_names TO lt_field_names.

          ls_input_fields-field_names   = lt_field_names.
          APPEND ls_input_fields TO lt_input_fields.
          REFRESH lt_field_names.

          ls_input_fields-ref_guid     = iv_guid.
          ls_input_fields-ref_kind     = lc_kind_h.
          ls_input_fields-objectname   = 'STATUS'.
*          ls_input_fields-logical_key  = lc_lkey_gloc.

          ls_field_names-fieldname     = 'ACTIVATE'.
          APPEND ls_field_names TO lt_field_names.

          ls_input_fields-field_names   = lt_field_names.
          APPEND ls_input_fields TO lt_input_fields.
          REFRESH lt_field_names.

          ls_shipping-ref_guid       = ls_orderadm_i_wrk-guid.
          ls_shipping-ref_kind       = lc_kind_i.
          ls_shipping-delivery_block = lv_block_re_code.
          APPEND ls_shipping TO lt_shipping.

          CALL FUNCTION 'CRM_ORDER_MAINTAIN'
            EXPORTING
              it_shipping       = lt_shipping
              it_status         = lt_status_n
            CHANGING
              ct_input_fields   = lt_input_fields
            EXCEPTIONS
              error_occurred    = 1
              document_locked   = 2
              no_change_allowed = 3
              no_authority      = 4
              OTHERS            = 5.
          IF sy-subrc <> 0.
          ENDIF.
      ENDCASE.
  ENDIF.

Let me know u have any issues.

<b>Please, Do reward points</b>

Regards,

Arjun

Answers (1)

Answers (1)

Former Member
0 Kudos

My understanding is to use the FM: COM_PARTNER_PUT_SINGLE_OB or CRM_ORDER_MAINTAIN

Thanks

<b>Allot points if this helps!</b>