cancel
Showing results for 
Search instead for 
Did you mean: 

Create CRM ORDER through CRM_ORDER_MAINTAIN

marcelom_bovo
Participant
0 Kudos

Hi people,

I am trying to copy a operation(from CRMD_ORDER) through function CRM_ORDER_MAINTAIN.

I'm having sucess on copping th order, but other thing I want is to insert some other values on this new operation, such as REFERENCE NUMBER.

But it is not working, the reference number is always blank.

here is the code




  wa_adm_h_comt-handle = '0000000001' .
  wa_adm_h_comt-process_type = <fs_adm_h>-process_type .
  wa_adm_h_comt-mode = 'A' .
  APPEND wa_adm_h_comt TO it_adm_h_comt .
  CLEAR wa_adm_h_comt .

  wa_predecessor-pred_guid =  <fs_adm_h>-guid .
  wa_predecessor-handle    =  '0000000001' .
  APPEND wa_predecessor TO it_predecessor .

  wa_input_fields-ref_handle = '0000000001'.
  wa_input_fields-ref_kind   = 'A'.
  wa_input_fields-objectname = 'ORDERADM_H'.

  wa_field_names-fieldname = 'MODE'.
  APPEND wa_field_names TO wa_input_fields-field_names .

  wa_field_names-fieldname = 'PROCESS_TYPE'.
  APPEND wa_field_names TO wa_input_fields-field_names .


  APPEND wa_input_fields TO it_input_fields .
  CLEAR wa_input_fields.


  ls_EXT_REF-HANDLE = '0000000001'.
  ls_EXT_REF-ref_kind   = 'A'.
  ls_EXT_REF-REFERENCE_MODE   = 'A'.
  ls_EXT_REF-REFERENCE_NUMBER = <fs_adm_h>-object_id.
  APPEND ls_EXT_REF to it_EXT_REF.

* Preparar a cópia
  CALL FUNCTION 'CRM_COPY_PROCESS_PREPARE'
    EXPORTING
      it_orderadm_h   = it_adm_h_comt
      it_predecessor  = it_predecessor
      iv_vona_kind    = 'D'
    IMPORTING
      ET_DOC_FLOW     = lt_doc_flow
      ET_ORDERADM_I   = it_adm_i_comt
      ET_ORDERADM_H   = it_adm_h_comt
    CHANGING
      ct_input_fields = it_input_fields
    EXCEPTIONS
      error_occurred  = 1
      OTHERS          = 2.

  CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
      IT_EXT_REF      = IT_EXT_REF
*      it_partner      = lt_partner
*      it_active_switch = lt_active_switch
    CHANGING
      ct_orderadm_h   = it_adm_h_comt
      ct_orderadm_i   = it_adm_i_comt
      ct_input_fields = it_input_fields
      ct_doc_flow     = lt_doc_flow
    EXCEPTIONS
      OTHERS          = 99.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
            RAISING error_occurred.
  ENDIF.


* fill interaction layer
  CLEAR ls_adm_h_comt.
  READ TABLE it_adm_h_comt INTO ls_adm_h_comt INDEX 1.
  IF NOT ls_adm_h_comt-guid IS INITIAL.
    CALL FUNCTION 'CRM_INTLAY_PUT_ALL_GUIDS'
      EXPORTING
        iv_buffer_refresh = 'X'
        iv_header_guid    = ls_adm_h_comt-guid.
    CALL FUNCTION 'CRM_INTLAY_PUT_INFO_APPLOG'
      EXPORTING
        iv_put_first_call = 'X'
        iv_first_call     = 'X'.

    INSERT ls_adm_h_comt-guid INTO TABLE IT_OBJECTS_TO_SAVE.

    CALL FUNCTION 'CRM_ORDER_SAVE'
      EXPORTING
        IT_OBJECTS_TO_SAVE         = IT_OBJECTS_TO_SAVE
        IV_UPDATE_TASK_LOCAL       = 'X'
* IMPORTING
*   ET_SAVED_OBJECTS           =
*   ET_EXCEPTION               =
*   ET_OBJECTS_NOT_SAVED       =
* CHANGING
*   CV_LOG_HANDLE              =
     EXCEPTIONS
       DOCUMENT_NOT_SAVED         = 1
       OTHERS                     = 2
              .
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT = 'X'.

* vERIFICA SE FOI GRAVADO CORRETAMENTO
    SELECT COUNT(*)
      FROM CRMD_ORDERADM_H
      WHERE guid = ls_adm_h_comt-guid.

    IF SY-SUBRC IS INITIAL.

      wa_cham_copy-mandt = sy-mandt .
      wa_cham_copy-object_id = <fs_adm_h>-object_id .
*      MODIFY zrjr_cham_copy FROM wa_cham_copy.
      CLEAR wa_cham_copy .


    ENDIF.


  ENDIF.

tks

Accepted Solutions (0)

Answers (1)

Answers (1)

marcelom_bovo
Participant
0 Kudos

I managed to update reference_number field(it was on another structure)...

but now I have another problem...

I want to update the field REASON.

I fill the entire service_os table, but it didnt update.

Then I tried another approach.

I saved the the operation then tried to modify using CRM_ORDER_MAINTAIN too, but it gives me a DUMP.

I try to insert in OSSET table on COMMIT(duplicating lines).

tks