Quantcast
Channel: SCN : Discussion List - SAP CRM: Sales
Viewing all articles
Browse latest Browse all 1559

Opportunity Coding

$
0
0

I don't understand why my code is not working, can someone help me? It's meant to update the closing date of an opportunity:

 

set_closing_date

METHOD set_closing_date.

  DATA: lv_header_guid TYPE crmt_object_guid.

  lv_header_guid = zcl_one_order=>get_header_guid_for_id( iv_order_id = iv_opp_id
                                                          iv_bus_type = 'BUS2000111' ).

  set_opportunity_data(
    iv_header_guid  = lv_header_guid
    iv_closing_date = iv_closing_date
  ).

  IF iv_commit = 'X'.
    COMMIT WORK.
  ENDIF.

ENDMETHOD.

 

 

I call it with the ID of the Opportunity, the date, e.g. 13012014 and X for commit.

 

The "get_header_guid_for_id" works correctly, I see in the debugger, it returns the GUID of the right opportunity.

 

This is the code of the called set_opportunity_data method - the thing is, from another program it works fine (in that program new opportunities are generated, not existing ones modified):

 

set_opportunity_data

METHOD set_opportunity_data.

  DATA: ls_input_field_names TYPE crmt_input_field_names,
      lt_input_field_names TYPE crmt_input_field_names_tab,
      ls_input_fields      TYPE crmt_input_field,
      lt_input_fields      TYPE crmt_input_field_tab,
      ls_opport_h          TYPE crmt_opport_h_com,
      lt_opport_h          TYPE crmt_opport_h_comt,
      ls_opport_h_read     TYPE crmt_opport_h_wrk,
      lt_opport_h_read     TYPE crmt_opport_h_wrkt,
      lt_header_guid       TYPE crmt_object_guid_tab.

  APPEND iv_header_guid TO lt_header_guid.

  CALL FUNCTION 'CRM_ORDER_READ'
    EXPORTING
      it_header_guid = lt_header_guid
    IMPORTING
      et_opport_h    = lt_opport_h_read.

  READ TABLE lt_opport_h_read INTO ls_opport_h_read INDEX 1.
  MOVE-CORRESPONDING ls_opport_h_read TO ls_opport_h.

  ls_opport_h-ref_guid   = iv_header_guid. " because -guid vs. ref_guid

  IF iv_closing_date IS SUPPLIED.
    ls_opport_h-expect_end  = iv_closing_date.
    ls_input_field_names-fieldname  = 'EXPECT_END'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
  ENDIF.
  IF iv_expected_sales_volume IS SUPPLIED.
    ls_opport_h-exp_revenue = iv_expected_sales_volume.
    ls_input_field_names-fieldname  = 'EXP_REVENUE'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
  ENDIF.
  IF iv_sales_stage IS SUPPLIED.
    ls_opport_h-curr_phase = iv_sales_stage.
    ls_input_field_names-fieldname  = 'CURR_PHASE'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
  ENDIF.

  APPEND ls_opport_h TO lt_opport_h.

  ls_input_fields-ref_guid    = iv_header_guid.
  ls_input_fields-ref_kind    = 'A'.
  ls_input_fields-objectname  = 'OPPORT_H'.
  ls_input_fields-field_names = lt_input_field_names.
  INSERT ls_input_fields INTO TABLE lt_input_fields.

  CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
      it_opport_h       = lt_opport_h
    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.
* TODO handle error
    EXIT.
  ENDIF.

ENDMETHOD.

 

I have debugged it, it appears just fine (so apparently I didn't debug deep enough into the bowels of CRM_ORDER_MAINTAIN).

 

Does anyone see what I'm doing wrong? Why would the code work for a newly created, not yet saved opportunity, but fail for modifying an existing opportunity?


Viewing all articles
Browse latest Browse all 1559

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>