cancel
Showing results for 
Search instead for 
Did you mean: 

BADI ORDER_SAVE custom field not getting updated

0 Kudos

I have ZZFLD00001U date field which I need to update when user places YES/NO first time in field ZZFLD00001T in ORDERADM_H. Field ZZFLD00001U is added using AET and not visible on web ui. I have implemented BADI ORDER_SAVE to populate this field but it is not getting updated. I have written following code:

method if_ex_order_save~change_before_update.

  data: ls_orderadm_h_old         type crmt_orderadm_h_wrk,

        ls_orderadm_h_new         type crmt_orderadm_h_wrk,

        lv_order_on_database      type crmt_boolean,

        lt_input_field_names      type crmt_input_field_names_tab,

        ls_input_field_names      type crmt_input_field_names,

        lt_input_fields           type crmt_input_field_tab,

        ls_input_fields           type crmt_input_field,

        ls_orderadm_h_mod         type crmt_orderadm_h_com,

        lt_orderadm_h_mod         type crmt_orderadm_h_comt.

* check if BUS2000120 is used

  call function 'CRM_ORDERADM_H_READ_OW'

    exporting

      iv_orderadm_h_guid     = iv_guid

    importing

      es_orderadm_h_wrk      = ls_orderadm_h_new

    exceptions

      admin_header_not_found = 1

      others                 = 2.

  check sy-subrc = 0 and

        ls_orderadm_h_new-object_type = 'BUS2000120'.

* check if order exist in the CRM database.

  call function 'CRM_ORDERADM_H_ON_DATABASE_OW'

    exporting

      iv_orderadm_h_guid  = iv_guid

    importing

      ev_on_database_flag = lv_order_on_database.

  if lv_order_on_database = 'X'.

** Necessary to have order_read to read the products and conditions..

*    SELECT SINGLE * FROM  crmd_orderadm_h

*             INTO ls_orderadm_h_old

*             WHERE guid = iv_guid.

*    IF sy-subrc <> 0.

** Should never happen...

**      rp_status = sppf_status_error.

*    ENDIF.

  else.

    if ls_orderadm_h_new-zzfld00001t <> ''.

      clear: ls_orderadm_h_mod, lt_orderadm_h_mod.

      move-corresponding ls_orderadm_h_new to ls_orderadm_h_mod.

      ls_orderadm_h_mod-zzfld00001u = sy-datum.

      append ls_orderadm_h_mod to lt_orderadm_h_mod.

      clear: ls_input_field_names, lt_input_field_names.

      ls_input_field_names-fieldname  = 'ZZFLD00001U'.

      ls_input_field_names-changeable = ' '.

      ls_input_field_names-inactive   = 'X'.

      append ls_input_field_names to lt_input_field_names.

      clear: ls_input_fields, lt_input_fields.

      ls_input_fields-ref_guid    = ls_orderadm_h_mod-guid.

      ls_input_fields-ref_kind    = 'A'.

      ls_input_fields-objectname  = 'ORDERADM_H'.

      ls_input_fields-logical_key = ls_orderadm_h_mod-guid.

      ls_input_fields-field_names = lt_input_field_names.

      append ls_input_fields to lt_input_fields.

      call function 'CRM_ORDER_MAINTAIN'

        changing

          ct_orderadm_h                 = lt_orderadm_h_mod

          ct_input_fields               = lt_input_fields

        exceptions

          error_occurred                = 1

          document_locked               = 2

          no_change_allowed             = 3

          no_authority                  = 4

          others                        = 5.

  call function 'CRM_ORDERADM_H_READ_OW'

    exporting

      iv_orderadm_h_guid     = iv_guid

    importing

      es_orderadm_h_wrk      = ls_orderadm_h_new

    exceptions

      admin_header_not_found = 1

      others                 = 2.

    endif.

  endif.

endmethod.

Here I am getting new value for the field but it is not getting saved in ORDERADM_H table. I have tried everything like:

CRM_ORDER_INITIALIZE

CRM_ORDER_SAVE

CRM_ORDER_SAVE_PREPARE_SING_OW

CRM_ORDERADM_H_UPDATE_DU

CRM_ORDERADM_H_MAINTAIN_OW

BAPI_TRANSACTION_COMMIT

Is there any other solution to update this field like EH_ONSAVE, etc.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

I have also tried below code but it is also not working:

METHOD if_ex_order_save~change_before_update.
   data: lo_core       type ref to cl_crm_bol_core,
         lo_entity     type ref to cl_crm_bol_entity.

   lo_core = cl_crm_bol_core=>get_instance( ).
   try.
     lo_entity ?= lo_core->get_root_entity( iv_object_name = 'BTOrder'
                                            iv_object_guid = iv_guid ).
     lo_entity = lo_entity->get_related_entity( 'BTOrderHeader' ).
     CHECK lo_entity->get_property_as_string( 'OBJECT_TYPE' ) = 'BUS2000120'.
     if lo_entity->lock( ) = abap_true.
       lo_entity->switch_to_change_mode( ).
       lo_entity->set_property( iv_attr_name = 'ZZFLD00001U'
                                iv_value     = sy-datum ).
       lo_core->modify( ).
     endif.
   catch cx_root.
   endtry.

ENDMETHOD.

former_member182421
Active Contributor
0 Kudos

This is a wrong approach, don't mix bol programming with API programming, the order_save badi is in the lowest level of the oneorder framework...

0 Kudos

Dear Luis,

I am trying to create complaint with component BT120H_CPL.

Can I be able to use EH_ONSAVE event from BT120H_CPL/OVViewSet view to fulfill my requirement?

Regards,

Rohan

former_member182421
Active Contributor
0 Kudos

Please don't mix topics, the topic on your question was ORDER_SAVE, if you changed your approach and your placed you code on the WebUI, It would be helpful if you specified that in the question, otherwise, we don't have any idea where you put the code...

Answering your question, NO, if you want to prevent the save, you should do the validation on the ORDE_SAVE badi.

Former Member
0 Kudos

Hi Rohan,

If you are creating the complaint from Web UI only then you can use the event 'EH_ONSAVE' of BT120H_CPL/OVViewSet view.

Before super save get entity and update the attribute.

Regards,

Ankit Gupta

0 Kudos

Dear Ankit,

I have written below code in EH_ONSAVE but still the result is same modifies value in buffer but not getting updated in table

method eh_onsave.

  data: lv_cucompl        type ref to cl_bt120h_c_bspwdcomponen_impl,
        lr_coll_wr        type ref to cl_bsp_wd_collection_wrapper,
        lr_entity          type ref to cl_crm_bol_entity,
        lr_core            type ref to cl_crm_bol_core,
        lr_col            type ref to if_bol_bo_col,
        lr_tx              type ref to if_bol_transaction_context,
        lr_entity_task    type ref to cl_crm_bol_entity,
        lr_coll_wr_task    type ref to cl_bsp_wd_collection_wrapper,
        lv_cucotask        type ref to cl_bt120h_c_cucotask_impl,
        lr_cucoitemtask    type ref to cl_bt120h_c_cucoitemtask_impl,
        lr_msg_srv        type ref to cl_bsp_wd_message_service,
        lr_cn_btadminh    type ref to cl_bsp_wd_context_node,
        lr_controller      type ref to cl_bsp_wd_appl_controller,
        lv_object_type    type        swo_objtyp,
        lv_process_type    type        crmt_process_type,
        lv_result          type        crmt_boolean,
        lv_deact_asyn_save type        char10.

********************************************************************************************************
  DATA: lv_guid            TYPE crmt_genil_object_guid.
  TRY.
    lr_cn_btadminh = me->get_context_node( gc_cn_btadminh ).
    IF lr_cn_btadminh IS BOUND.
      lr_entity ?= lr_cn_btadminh->collection_wrapper->get_current( ).
      lr_entity->get_property_as_value( EXPORTING iv_attr_name = 'OBJECT_TYPE'
                                        IMPORTING ev_result    = lv_object_type ).
      lr_entity->get_property_as_value( EXPORTING iv_attr_name = 'PROCESS_TYPE'
                                        IMPORTING ev_result    = lv_process_type ).
      IF lv_object_type = 'BUS2000120' AND lv_process_type = 'ZRMC'.
        IF lr_entity->lock( ) = abap_true.
          lr_entity->switch_to_change_mode( ).
          lr_entity->set_property( iv_attr_name = 'ZZFLD00001U'
                                    iv_value    = sy-datum ).
        ENDIF.
      ENDIF.
    ENDIF.
  CATCH cx_root.
  ENDTRY.
********************************************************************************************************

  lv_cucompl ?= me->comp_controller.
  lr_coll_wr = lv_cucompl->typed_context->btadminh->get_collection_wrapper( ).

  check lr_coll_wr is bound.
  lr_entity ?= lr_coll_wr->get_current( ).
  check lr_entity is bound.

  if cl_crm_uiu_bt_partner_popup=>get_quick_create_status( ) = abap_true.
*  Save business partner-accounts and related objects (contacts, conditions,..)
    cl_crm_uiu_bp_tools=>save( ).
    cl_crm_uiu_bt_partner_popup=>set_quick_create_status( exporting iv_quick_create = abap_false ).
  endif.

* cancel save because of mandatory fiels
  lr_controller ?= comp_controller->m_parent.
  lr_msg_srv ?= me->view_manager->get_message_service( ).
  if cl_crm_uiu_bt_tools=>mandatory_flds_no_save_allowed( ir_controller = lr_controller
                                                          ir_msg_srv    = lr_msg_srv    ) = abap_true.
    exit.
  endif.

  lr_tx = lr_entity->get_transaction( ).
  if ( ( lr_tx->check_save_needed( eq abap_true ) and
      ( lr_tx->check_save_possible( ) eq abap_true ) ) or
      lv_cucompl->force_save = abap_true.

    lv_cucompl->force_save = abap_false.
    save_tasks( ).

* get user parameter
    get parameter id 'CRM_1OSAVE' field lv_deact_asyn_save. " to deactivate async. save !!!
    if lv_deact_asyn_save = abap_true.
      cl_crm_uiu_bt_tools=>save( lv_cucompl->typed_context->btadminh ).
    else.
* Get current AdminH-Entity
      lr_cn_btadminh = me->get_context_node( gc_cn_btadminh ).
      if lr_cn_btadminh is bound.
        lr_entity ?= lr_cn_btadminh->collection_wrapper->get_current( ).
* determine save mode (sync. or async.)
        lr_entity->get_property_as_value( exporting iv_attr_name = 'OBJECT_TYPE'
                                          importing ev_result    = lv_object_type ).
        lr_entity->get_property_as_value( exporting iv_attr_name = 'PROCESS_TYPE'
                                          importing ev_result    = lv_process_type ).
        call method cl_crm_uiu_bt_tools=>is_obj_reg_for_asyn_and_noinit
          exporting
            iv_object_type  = lv_object_type
            iv_process_type = lv_process_type
            iv_check_switch = abap_true
          receiving
            rv_result      = lv_result.
      else.
        lv_result = abap_false.
      endif.
      cl_crm_uiu_bt_tools=>save( exporting ir_node = me->typed_context->btorder
                                            iv_asynchronous = lv_result ).
    endif.

* prefetch order data after save
    try.

        if lv_cucompl->typed_context->btorder->collection_wrapper->size( ) > 0.
          lr_core = cl_crm_bol_core=>get_instance( ).

          lr_entity ?= lv_cucompl->typed_context->btorder->collection_wrapper->get_current( ).
          if lr_entity is bound.
            create object lr_col
              type
              cl_crm_bol_bo_col.
            lr_col->add( lr_entity ).
            lr_core->prefetch_view( iv_bo_collection = lr_col
                                    iv_view_name    = if_crm_uiu_bol_views_const=>gc_cpl_header ).
          endif.
        endif.

        if lv_cucompl->typed_context->btadminh->collection_wrapper->size( ) > 0.
          lr_core = cl_crm_bol_core=>get_instance( ).
          lr_col = lv_cucompl->typed_context->btadminh->collection_wrapper->get_copy( ).
          lr_core->prefetch_view( iv_bo_collection = lr_col
                                  iv_view_name    = if_crm_uiu_bol_views_const=>gc_items_service ).
        endif.

      catch cx_root.
* if something fails during prefetch: do not care, as it is just for performance improvement
* and does not have any functional effects
    endtry.

    lv_cucompl->typed_context->btorder->collection_wrapper->publish_current( ).

* Do default sorting
    if lv_cucompl->typed_context->btadmini->collection_wrapper->size( ) > 0.
      lv_cucompl->typed_context->btadmini->collection_wrapper->sort( 'NUMBER_INT' ).
    endif.

  else.
*~*~*~*~*~*~*~*~This piece of code is never called*~*~*~*~*~*~*~*~*
****in case of check save raises an exception.
***    IF ( lr_tx->check_save_needed( )  = abap_true ) AND
***          ( lr_tx->check_save_possible( ) = abap_true ).
***
****  revert tasks
***    lv_cucotask ?= me->get_custom_controller( 'BT120H_CPL/CuCoTask' ).
***    IF lv_cucotask IS BOUND.
***      lr_coll_wr_task = lv_cucotask->typed_context->btadminh->get_collection_wrapper( ).
***      lr_entity_task ?= lr_coll_wr_task->get_first( ).
***      WHILE lr_entity_task IS BOUND.
***        cl_crm_uiu_bt_tools=>revert( lv_cucotask->typed_context->btadminh ).
***        lr_entity_task ?= lr_coll_wr_task->get_next( ).
***      ENDWHILE.
***      lr_coll_wr_task = lv_cucotask->typed_context->btorder->get_collection_wrapper( ).
***      lr_coll_wr_task->clear_collection( ).
***    ENDIF.
***  ENDIF.
* also release locks if a "save" is done from
* on an unchanged business transaction
    if lr_tx->check_save_needed( ) = abap_false.
      lr_tx->revert( iv_suppress_buffer_sync = 'X' ).
*      return.
    endif.


*  remove and add entity in order to refresh all context nodes (selections, etc.)
*  and lock registration is done
    lr_coll_wr->remove( lr_entity ).
    lr_coll_wr->add( iv_entity    = lr_entity
                      iv_set_focus = abap_true ).

    return.

  endif.

endmethod.

0 Kudos

Dear Ankit,

I solved the issue as follows:


method eh_onsave.

   data: lv_cucompl         type ref to cl_bt120h_c_bspwdcomponen_impl,
         lr_coll_wr         type ref to cl_bsp_wd_collection_wrapper,
         lr_entity          type ref to cl_crm_bol_entity,
         lr_core            type ref to cl_crm_bol_core,
         lr_col             type ref to if_bol_bo_col,
         lr_tx              type ref to if_bol_transaction_context,
         lr_entity_task     type ref to cl_crm_bol_entity,
         lr_coll_wr_task    type ref to cl_bsp_wd_collection_wrapper,
         lv_cucotask        type ref to cl_bt120h_c_cucotask_impl,
         lr_cucoitemtask    type ref to cl_bt120h_c_cucoitemtask_impl,
         lr_msg_srv         type ref to cl_bsp_wd_message_service,
         lr_cn_btadminh     type ref to cl_bsp_wd_context_node,
         lr_controller      type ref to cl_bsp_wd_appl_controller,
         lv_object_type     type        swo_objtyp,
         lv_process_type    type        crmt_process_type,
         lv_result          type        crmt_boolean,
         lv_deact_asyn_save type        char10.

********************************************************************************************************
   TRY.
     lr_cn_btadminh = me->get_context_node( gc_cn_btadminh ).
     IF lr_cn_btadminh IS BOUND.
       lr_entity ?= lr_cn_btadminh->collection_wrapper->get_current( ).
       lr_entity->get_property_as_value( EXPORTING iv_attr_name = 'OBJECT_TYPE'
                                         IMPORTING ev_result    = lv_object_type ).
       lr_entity->get_property_as_value( EXPORTING iv_attr_name = 'PROCESS_TYPE'
                                         IMPORTING ev_result    = lv_process_type ).
       IF lv_object_type = 'BUS2000120' AND lv_process_type = 'ZRMC'.
         IF lr_entity->lock( ) = abap_true.
           lr_entity->switch_to_change_mode( ).
           lr_entity->activate_sending( abap_true ).
           lr_entity->set_property( iv_attr_name = 'ZZFLD00001U'
                                    iv_value     = sy-datum ).
           lr_core = cl_crm_bol_core=>get_instance( ).
           lr_core->modify( ).
         ENDIF.
       ENDIF.
     ENDIF.
   CATCH cx_root.
   ENDTRY.
********************************************************************************************************

   lv_cucompl ?= me->comp_controller.
   lr_coll_wr = lv_cucompl->typed_context->btadminh->get_collection_wrapper( ).

   check lr_coll_wr is bound.
   lr_entity ?= lr_coll_wr->get_current( ).
   check lr_entity is bound.

   if cl_crm_uiu_bt_partner_popup=>get_quick_create_status( ) = abap_true.
*   Save business partner-accounts and related objects (contacts, conditions,..)
     cl_crm_uiu_bp_tools=>save( ).
     cl_crm_uiu_bt_partner_popup=>set_quick_create_status( exporting iv_quick_create = abap_false ).
   endif.

* cancel save because of mandatory fiels
   lr_controller ?= comp_controller->m_parent.
   lr_msg_srv ?= me->view_manager->get_message_service( ).
   if cl_crm_uiu_bt_tools=>mandatory_flds_no_save_allowed( ir_controller = lr_controller
                                                           ir_msg_srv    = lr_msg_srv     ) = abap_true.
     exit.
   endif.

   lr_tx = lr_entity->get_transaction( ).
   if ( ( lr_tx->check_save_needed( )   eq abap_true ) and
      ( lr_tx->check_save_possible( ) eq abap_true ) ) or
      lv_cucompl->force_save = abap_true.

     lv_cucompl->force_save = abap_false.
     save_tasks( ).

* get user parameter
     get parameter id 'CRM_1OSAVE' field lv_deact_asyn_save. " to deactivate async. save !!!
     if lv_deact_asyn_save = abap_true.
       cl_crm_uiu_bt_tools=>save( lv_cucompl->typed_context->btadminh ).
     else.
* Get current AdminH-Entity
       lr_cn_btadminh = me->get_context_node( gc_cn_btadminh ).
       if lr_cn_btadminh is bound.
         lr_entity ?= lr_cn_btadminh->collection_wrapper->get_current( ).
* determine save mode (sync. or async.)
         lr_entity->get_property_as_value( exporting iv_attr_name = 'OBJECT_TYPE'
                                           importing ev_result    = lv_object_type ).
         lr_entity->get_property_as_value( exporting iv_attr_name = 'PROCESS_TYPE'
                                           importing ev_result    = lv_process_type ).
         call method cl_crm_uiu_bt_tools=>is_obj_reg_for_asyn_and_noinit
           exporting
             iv_object_type  = lv_object_type
             iv_process_type = lv_process_type
             iv_check_switch = abap_true
           receiving
             rv_result       = lv_result.
       else.
         lv_result = abap_false.
       endif.
       cl_crm_uiu_bt_tools=>save( exporting ir_node = me->typed_context->btorder
                                            iv_asynchronous = lv_result ).
     endif.

* prefetch order data after save
     try.

         if lv_cucompl->typed_context->btorder->collection_wrapper->size( ) > 0.
           lr_core = cl_crm_bol_core=>get_instance( ).

           lr_entity ?= lv_cucompl->typed_context->btorder->collection_wrapper->get_current( ).
           if lr_entity is bound.
             create object lr_col
               type
               cl_crm_bol_bo_col.
             lr_col->add( lr_entity ).
             lr_core->prefetch_view( iv_bo_collection = lr_col
                                     iv_view_name     = if_crm_uiu_bol_views_const=>gc_cpl_header ).
           endif.
         endif.

         if lv_cucompl->typed_context->btadminh->collection_wrapper->size( ) > 0.
           lr_core = cl_crm_bol_core=>get_instance( ).
           lr_col = lv_cucompl->typed_context->btadminh->collection_wrapper->get_copy( ).
           lr_core->prefetch_view( iv_bo_collection = lr_col
                                   iv_view_name     = if_crm_uiu_bol_views_const=>gc_items_service ).
         endif.

       catch cx_root.
* if something fails during prefetch: do not care, as it is just for performance improvement
* and does not have any functional effects
     endtry.

     lv_cucompl->typed_context->btorder->collection_wrapper->publish_current( ).

* Do default sorting
     if lv_cucompl->typed_context->btadmini->collection_wrapper->size( ) > 0.
       lv_cucompl->typed_context->btadmini->collection_wrapper->sort( 'NUMBER_INT' ).
     endif.

   else.
*~*~*~*~*~*~*~*~This piece of code is never called*~*~*~*~*~*~*~*~*
****in case of check save raises an exception.
***    IF ( lr_tx->check_save_needed( )   = abap_true ) AND
***          ( lr_tx->check_save_possible( ) = abap_true ).
***
****   revert tasks
***    lv_cucotask ?= me->get_custom_controller( 'BT120H_CPL/CuCoTask' ).
***    IF lv_cucotask IS BOUND.
***      lr_coll_wr_task = lv_cucotask->typed_context->btadminh->get_collection_wrapper( ).
***      lr_entity_task ?= lr_coll_wr_task->get_first( ).
***      WHILE lr_entity_task IS BOUND.
***        cl_crm_uiu_bt_tools=>revert( lv_cucotask->typed_context->btadminh ).
***        lr_entity_task ?= lr_coll_wr_task->get_next( ).
***      ENDWHILE.
***      lr_coll_wr_task = lv_cucotask->typed_context->btorder->get_collection_wrapper( ).
***      lr_coll_wr_task->clear_collection( ).
***    ENDIF.
***   ENDIF.
* also release locks if a "save" is done from
* on an unchanged business transaction
     if lr_tx->check_save_needed( ) = abap_false.
       lr_tx->revert( iv_suppress_buffer_sync = 'X' ).
*      return.
     endif.


*   remove and add entity in order to refresh all context nodes (selections, etc.)
*   and lock registration is done
     lr_coll_wr->remove( lr_entity ).
     lr_coll_wr->add( iv_entity    = lr_entity
                      iv_set_focus = abap_true ).

     return.

   endif.

endmethod.

0 Kudos

Thank you guys...

Thanks to you all...

Answers (2)

Answers (2)

former_member182421
Active Contributor
0 Kudos

An easier approach can be enhance the CUSTOMER_H segment and use the CUSTOMER_H corresponding BADI, which is meant for that, to check and update values. Is that possible for your scenario? I mean change the location of the ZZ* field to the CUSTOMER_H segment instead of the ORDERADM_H segment?

Cheers!

Luis

0 Kudos

Dear Luis,

I have already created ZZ* field in order header and I am not getting any data in CUSTOMER_H using CRM_ORDER_READ. I am getting data in ORDERADM_H.

Can you please elaborate on this or do you have any example.

Regards,

Rohan

former_member182421
Active Contributor
0 Kudos

How did you enhanced the field? via AET? EEWB? Manually (doing an append on the dictionary structure) ? and more important is this field already in production?

0 Kudos

Dear Luis,

I have enhanced field via AET and it is for Account Management=>Complaint=>Header.

Regards,

Rohan

former_member182421
Active Contributor
0 Kudos

While using the AET wizard did you see the option to enhance CUSTOMER_H? Is this field already in production?

0 Kudos

Dear Luis,

CUSTOMER_H segment is for Account Master and I want to add this to Service Complaint Header ORDERADM_H.

Regards,

Rohan

former_member182421
Active Contributor
0 Kudos

You just killed me, are you sure CUSTOMER_H is for account master? Please, search before posting. If we sum up the Faisal's answers and mines, you should have a clearer idea of what to do or at least what to search/investigate. I'm done here

0 Kudos

Dear Luis,

I tried enhancing CUSOMER_H but when I try to add field to configuration it doesn't show this field in Available Fields.

Regards,

Rohan

former_member182421
Active Contributor
0 Kudos

Depens on the component you will need to add the BOL node CUSTOMER_H and/or adapt the corresponding design layer to include the object/field, you can find more information about this in the WebUI subspace.

faisal_pc
Active Contributor
0 Kudos

Hi Rohan,

You are not supposed to CRM_ORDER_MAINTAIN in order_save BADI. Your requirement can be achieved with CRM_ORDERADM_H_MAINTAIN_OW. What was the code you written when you tried with CRM_ORDERADM_H_MAINTAIN_OW?.

Thanks,

Faisal

0 Kudos

Dear Faisal,

I have tried below code which resulted in short dump:


METHOD if_ex_order_save~change_before_update.
DATA: ls_orderadm_h_old         TYPE crmt_orderadm_h_wrk,
         ls_orderadm_h_new         TYPE crmt_orderadm_h_wrk,
         lv_order_on_database      TYPE crmt_boolean,
         lt_input_field_names      TYPE crmt_input_field_names_tab,
         ls_input_field_names      TYPE crmt_input_field_names,
         lt_input_fields           TYPE crmt_input_field_tab,
         ls_input_fields           TYPE crmt_input_field,
         ls_orderadm_h_mod         TYPE crmt_orderadm_h_com,
         lt_orderadm_h_mod         TYPE crmt_orderadm_h_comt.

* check if BUS2000120 is used
   CALL FUNCTION 'CRM_ORDERADM_H_READ_OW'
     EXPORTING
       iv_orderadm_h_guid     = iv_guid
     IMPORTING
       es_orderadm_h_wrk      = ls_orderadm_h_new
     EXCEPTIONS
       admin_header_not_found = 1
       OTHERS                 = 2.
   CHECK sy-subrc = 0 AND
         ls_orderadm_h_new-object_type = 'BUS2000120'.

* check if order exist in the CRM database.
   CALL FUNCTION 'CRM_ORDERADM_H_ON_DATABASE_OW'
     EXPORTING
       iv_orderadm_h_guid  = iv_guid
     IMPORTING
       ev_on_database_flag = lv_order_on_database.
   IF lv_order_on_database = 'X'.
** Necessary to have order_read to read the products and conditions..
*    SELECT SINGLE * FROM  crmd_orderadm_h
*             INTO ls_orderadm_h_old
*             WHERE guid = iv_guid.
*    IF sy-subrc <> 0.
** Should never happen...
**      rp_status = sppf_status_error.
*    ENDIF.
   ELSE.
     IF ls_orderadm_h_new-zzfld00001t <> ''.
       CLEAR: ls_orderadm_h_mod, lt_orderadm_h_mod.
       MOVE-CORRESPONDING ls_orderadm_h_new TO ls_orderadm_h_mod.
       ls_orderadm_h_mod-zzfld00001u = sy-datum.
       APPEND ls_orderadm_h_mod TO lt_orderadm_h_mod.

       CLEAR: ls_input_field_names, lt_input_field_names.
       ls_input_field_names-fieldname  = 'ZZFLD00001U'.
       ls_input_field_names-changeable = ' '.
       ls_input_field_names-inactive   = 'X'.
       APPEND ls_input_field_names TO lt_input_field_names.
CALL FUNCTION 'CRM_ORDERADM_H_MAINTAIN_OW'
         EXPORTING
           is_orderadm_h_com    = ls_orderadm_h_mod
         CHANGING
           ct_input_field_names = lt_input_field_names
         EXCEPTIONS
           header_create_error  = 1
           header_change_error  = 2
           parameter_error      = 3
           process_type_error   = 4
           deletion_not_allowed = 5
           no_authority         = 6
           OTHERS               = 7.

       CALL FUNCTION 'CRM_ORDERADM_H_READ_OW'
         EXPORTING
           iv_orderadm_h_guid     = iv_guid
         IMPORTING
           es_orderadm_h_wrk      = ls_orderadm_h_new
         EXCEPTIONS
           admin_header_not_found = 1
           OTHERS                 = 2.
     ENDIF.
   ENDIF.
ENDMETHOD.



faisal_pc
Active Contributor
0 Kudos

Hi Rohan,

Try the following code.

       ls_orderadm_h_mod-zzfld00001u = sy-datum.

       ls_orderadm_h-mode = 'B'.

       CLEAR: ls_input_field_names, lt_input_field_names.
       ls_input_field_names-fieldname  = 'ZZFLD00001U'.     
       APPEND ls_input_field_names TO lt_input_field_names.


CALL FUNCTION 'CRM_ORDERADM_H_MAINTAIN_OW'
         EXPORTING
           is_orderadm_h_com    = ls_orderadm_h_mod
         CHANGING
           ct_input_field_names = lt_input_field_names
         EXCEPTIONS
           header_create_error  = 1
           header_change_error  = 2
           parameter_error      = 3
           process_type_error   = 4
           deletion_not_allowed = 5
           no_authority         = 6
           OTHERS               = 7.

Thanks,

Faisal

0 Kudos

Dear Faisal,


MOVE-CORRESPONDING ls_orderadm_h_new TO ls_orderadm_h_mod.


already adds,


ls_orderadm_h_mod-mode = 'B'.



Regards,

Rohan

faisal_pc
Active Contributor
0 Kudos

Hi Rohan,

Do you get the dump if you write the above code as it's (except mode)?. I took it from a working example.

Thanks,

Faisal

0 Kudos

Dear Faisal,

I have also tried below code as said by you:

       ls_orderadm_h_mod-zzfld00001u = sy-datum.

       ls_orderadm_h-mode = 'B'.

But this is also giving me same dump.

Also using my code with CRM_ORDER_MAINTAIN I am able to modify ORDERADM_H in buffer i.e., if I try to read zzfld00001u using CRM_ORDERADM_H_READ_OW I get new value, but it is not getting reflected in table.

I have searched posts they said use CRM_ORDER_SAVE and BAPI_TRANSACTION_COMMIT. But CRM_ORDER_SAVE also gives dump.

Regards,

Rohan

faisal_pc
Active Contributor
0 Kudos

Hi Rohan,

Please keep in mind that you are writing the code in a BADI where you are not supposed to use a COMMIT in any ways. BAPI_TRANSACTION_COMMIT or CRM_ORDER_SAVE/CRM_ORDER_MAINTAIN will call the commit or get called recursively. So refrain from those practices.

I just have created a custom field in orderadm_h which is as you said, created in complaints.  And the code I wrote in CRM_ORDERADM_H_BADI badi method CRM_ORDERADM_H_MERGE is as below.

cs_orderadm_h_badi-zzfld00002p = 'Faisal'.


That;s it. It gets saved in DB.



Note: This BADI will get triggered always when you make some changes in header. So keep proper restrictions for your changes with conditions.


Thanks,

Faisal

former_member182421
Active Contributor
0 Kudos

I went for the CUSTOMER_H approach, but using the CRM_ORDERADM_H_BADI is also a good approach, I didn't remeber about this one!

Cheers!

Luis

0 Kudos

Hi Faisal,

I know I must not use COMMIT in BADI since it does premature commit. But still I was trying to figure out what is going wrong.

As said by you CRM_ORDERADM_H_BADI badi method CRM_ORDERADM_H_MERGE triggers if I do any changes in ORDERADM_H. On Save point it doesn't trigger. I don't want data to be saved at this point.

The same functionality I can do using enhancing getters/setters for the field but I don't want data to be saved at this point.

ORDER_SAVE method triggers on save point but I am not able to solve my issue using this don't understand why?

Still I solved my issue using BOL approach enhancing EH_ONSAVE event from BT120H_CPL/OVViewSet view by setting property for that entity and modifying core.

Thanks,

Rohan