CRM_ORDER_MAINTAIN, CRM_ORDER_READ

AS I am new to CRM I have simple doubt  CRM_ORDER_MAINTAIN, CRM_ORDER_READ are function modules or  BAPI's.
I know all BAPI 's are REMOTE enabled Function Modules.
In which situations we will use RFC and in which situation we will use BAPI's
Thanks,
vis

Hey Vis ,
Each Bapi Object has  Interface, Key Fields, Attributes,Methods and Events.  Bapi Function Modules can be attached to these Bapi objects .Function module has a single bound functionality  while a BAPI object can contain many functionalities.
So as far as possible try to use BAPI's if available. If you want to call the FM in R3 from any other system say CRM or SRM, in that case you need to use RFC.
Hope this will help to you.
Regards,
Nikhil

Similar Messages

  • Urgent please help me coding

    Hi SDN Team,
    I urgently required to develop a function module in CRM Billing order for rejecting the item line and creating a new line while copying the contents of the old line item into new one.
    We need to do this because, we need to handle the situation where, there was wrong date entered for the leasing contract period and at a later stage we will come to know the first entered date was wrong so we need to change the dates for the lease contract period for that particular item.
    With this creation of new line item, it generates a new billing plan for that particular line item.
    I need to perform this task by developing a function module. I'm given <b>crm_order_maintain & crm_order_read function modules</b> but i'm unable to create a new line item with those 2 function modules.
    Any one, kindly send me the coding and steps aswell please.
    If you need further clarification please email to [email protected]
    Thanks in Advance.
    Sincerely.
    KK

    Hi Tomasz,
    Thanks for the reply.  I'm new to this ABAP programming.  Could you please send me the coding and guide me the steps.
    Your earliest reply will be appreciated.
    Best Regards!
    KK

  • How to debug crm programs

    hi abapers i need to know how to debug the crm programs.

    Hi Rockey,
    IF u have the integration with CRM and R/3.Then u will use the Middle ware BADI's to copy the data from CRm to r/3 or R73 to CRM.
    You can debug that that BADI and u can see where u are going wrong.
    Mainly in CRM
    we will have the FM's.Through this function modules we ill do evrything in the CRM.
    CRM_ORDER_SAVE.
    CRM_ORDER_MAINTAIN
    CRM_ORDER_READ.
    IF we want to get the Data from R73 to CRM. then you can write RFC'S toget the data.
    There are so many ways are there.JUst put the breakpoints.In ur middle ware BADI's
    then i hope it may help you.
    Thanks

  • Change Pricing Condition for an item with CRM_ORDER_MAINTAIN

    Hi community,
    I try to change an existing condition with the function module crm_order_maintain.
    Everything looks fine, no error no dump, but no success
    The condition stays the same!
    Can anybody find a solution for this?
    Heres my report so far:
    *& Report  ZTEST_PRICING2
    REPORT  ztest_pricing2.
    DATA: lt_guid      TYPE crmt_object_guid_tab,
          lt_item      TYPE crmt_object_guid_tab,
          lt_saved     TYPE crmt_return_objects,
          lt_pridoc    TYPE crmt_pric_cond_t,
          ls_pridoc    TYPE crmt_pric_cond,
          lt_pricom    TYPE crmt_pridoc_comt,
          ls_pricom    TYPE crmt_pridoc_com,
          lt_header    TYPE crmt_orderadm_h_comt,
          lt_input     TYPE crmt_input_field_tab,
          ls_input     TYPE crmt_input_field,
          ls_input_fn  TYPE CRMT_INPUT_FIELD_NAMES,
          ls_cond_chg  TYPE prct_cond_external_change,
          ls_cond      TYPE PRCT_COND_DU,
          lt_pricing_i TYPE CRMT_PRICING_I_WRKT.
    PARAMETERS: lv_head TYPE crmt_object_guid DEFAULT 'C4C61C4E35DDF306E10000000A024089'.
    PARAMETERS: lv_item TYPE crmt_object_guid DEFAULT '09C71C4E35DDF306E10000000A024089'.
    PARAMETERS: lv_kbetr TYPE prct_cond_rate DEFAULT '100'.
    INSERT lv_head INTO TABLE lt_guid.
    INSERT lv_item INTO TABLE lt_item.
    CALL FUNCTION 'CRM_ORDER_READ'
      EXPORTING
        it_header_guid                    = lt_guid
        it_item_guid                      = lt_item
    *   IV_MODE                           =
    *   IV_ONLY_SPEC_ITEMS                =
    *   IT_REQUESTED_OBJECTS              =
    *   IV_NO_AUTH_CHECK                  =
    *   IT_ITEM_USAGE_RANGE               =
    *   IV_SUBITEM_DEPTH                  = -1
    *   IT_OBJECT_FILTER                  =
    *   IV_ONLY_CHANGED_OBJ               = FALSE
    *   IV_STATUS_H_CHECK_RELEVANCE       = FALSE
      IMPORTING
        et_pridoc                         = lt_pridoc
        et_pricing_i                      = lt_pricing_i
    * CHANGING
    *   CV_LOG_HANDLE                     =
    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.
    IF sy-subrc <> 0 AND lt_pridoc IS NOT INITIAL.
      WRITE: / 'ERROR'.
      EXIT.
    ENDIF.
    READ TABLE lt_pridoc INDEX 1 INTO ls_pridoc.
    IF sy-subrc <> 0.
      WRITE: / 'ERROR'.
      EXIT.
    ENDIF.
    READ TABLE ls_pridoc-pric_cond INTO ls_cond WITH KEY kschl = 'PB00'.
    IF sy-subrc <> 0.
      WRITE: / 'ERROR'.
      EXIT.
    ENDIF.
    ls_input-ref_guid   = lv_head.
    ls_input-ref_kind   = 'A'.
    ls_input-objectname = 'PRIDOC'.
    ls_input_fn-fieldname = 'WAERS'.
    INSERT ls_input_fn INTO TABLE ls_input-field_names.
    ls_input_fn-fieldname = 'KBETR'.
    INSERT ls_input_fn INTO TABLE ls_input-field_names.
    INSERT ls_input INTO TABLE lt_input.
    ls_pricom-ref_guid   = lv_head.
    ls_pricom-ref_kind   = 'A'.
    *ls_pricom-PRICING_TYPE  = 'B'.
    *ls_pricom-pricing_procedure = 'ZZMTA'.
    ls_pricom-pric_cond[] = ls_pridoc-pric_cond[].
    MOVE-CORRESPONDING ls_cond TO ls_cond_chg.
    ls_cond_chg-waers = 'EUR'.
    ls_cond_chg-kbetr = lv_kbetr.
    INSERT ls_cond_chg INTO TABLE ls_pricom-cond_change.
    APPEND ls_pricom TO lt_pricom.
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
      EXPORTING
        it_pridoc         = lt_pricom
      CHANGING
    *    ct_orderadm_h     = lt_header
        ct_input_fields   = lt_input
      EXCEPTIONS
        error_occurred    = 1
        document_locked   = 2
        no_change_allowed = 3
        no_authority      = 4
        OTHERS            = 5.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    CALL FUNCTION 'CRM_ORDER_SAVE'
      EXPORTING
        it_objects_to_save         = lt_guid
      IMPORTING
        et_saved_objects           = lt_saved
    *   ET_EXCEPTION               =
    *   ET_OBJECTS_NOT_SAVED       =
    EXCEPTIONS
       document_not_saved         = 1
       OTHERS                     = 2.
    IF sy-subrc EQ 0.
      COMMIT WORK AND WAIT.
    ELSE.
      ROLLBACK WORK.
    ENDIF.
    regards
    Markus

    Hello Jordi,
    The example below is whereby i was trying to copy all the pricing condition on one document to another and deleting what's not present on the source document.
    You can used this piece of code to adapt your requirement.
    CALL FUNCTION 'ZCRC_FM_COPY_PRICE_COND_ALL'
              EXPORTING
    id_object_guid_src    = <fs_el_con_guid>
    id_object_guid_dest = <fs_el_so_guid>
    id_commit                  = abap_false
              EXCEPTIONS
    not_allowed         = 1
    error_occured     = 2
    OTHERS                 = 3.
      PERFORM f_recup_donnees USING     id_object_guid_src
                                                              id_object_guid_dest.
    PERFORM f_modif_condition_prix USING id_object_guid_src
                                                                                      id_object_guid_dest.
    PERFORM f_header_copy_pricing using id_object_guid_src
                                                                            id_object_guid_dest.
    FORM f_recup_donnees   USING      pd_object_guid_src TYPE crmt_object_guid
                                                                           pd_object_guid_dest TYPE crmt_object_guid.
      DATA:
         lt_header_guid        TYPE crmt_object_guid_tab.
      INSERT pd_object_guid_src  INTO TABLE lt_header_guid.
      INSERT pd_object_guid_dest INTO TABLE  lt_header_guid.
      CLEAR: gt_orderadm_i, gt_doc_flow.
      CALL FUNCTION 'CRM_ORDER_READ'
        EXPORTING
          it_header_guid       = lt_header_guid
        IMPORTING
          et_doc_flow          = gt_doc_flow            
          et_orderadm_i        = gt_orderadm_i
        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.
      IF sy-subrc NE 0.
        RAISE error_occured.
      ENDIF.
    " F_RECUP_DONNEES
    FORM f_modif_condition_prix USING pd_guid_src TYPE crmt_object_guid
                                      pd_guid_dest TYPE crmt_object_guid.
      DATA : ld_pd_handle_src     TYPE prct_handle,
              ld_pd_handle_dest    TYPE prct_handle,
              lt_komv_print_src    TYPE prct_cond_print_t,
    lt_komv_print_dest   TYPE prct_cond_print_t,
              ls_komv_print_dest   LIKE LINE OF lt_komv_print_dest,
              ls_komv_print_src    LIKE LINE OF lt_komv_print_src,
              lt_cond_chg          TYPE prct_cond_print_t,
              lt_cond_chg_insert   TYPE prct_cond_print_t,
              ls_cond_chg          TYPE prct_cond_print,
              ls_cond_chg_tmp      TYPE prct_cond_print,
              ls_input_fields      TYPE crmt_input_field,
              lt_input_fields      TYPE crmt_input_field_tab.
      DATA : bal_log         TYPE balloghndl,
             lt_item_ret     TYPE prct_item_ret_t,
             lt_cond_ret     TYPE prct_cond_print_t,
             ld_data_changed TYPE xfeld,
             gv_decimal      TYPE usdefaults-dcpfm,
             ld_lines        TYPE i,
             ld_ajout_cond   TYPE abap_bool.
      FIELD-SYMBOLS : <fs_orderadm_i_dest>  TYPE crmt_orderadm_i_wrk,
    <fs_orderadm_i_src>   TYPE crmt_orderadm_i_wrk,
                      <fs_cond_chg>         TYPE prct_cond_print,
    <fs_cond_chg_insert>  TYPE prct_cond_print.
    * Début Ajout CD1K904313-001.
      DATA: ld_guid_src  TYPE crmt_object_guid.
      FIELD-SYMBOLS: <fs_doc_flow>  TYPE crmt_doc_flow_wrk.
    * Début Ajout CD1K904313-001.
    * Verrouillage des documents source et destinataire
      PERFORM f_lock_document USING pd_guid_src.
      PERFORM f_lock_document USING pd_guid_dest.
    *Récupérer le pricing handle des documents
    * Document source
      CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
        EXPORTING
    iv_header_guid             = pd_guid_src
        IMPORTING
    ev_pd_handle               = ld_pd_handle_src
        EXCEPTIONS
    error_occurred             = 1
    handle_determination_error = 2
          orgdata_error              = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.
    * Document destinataire
      CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
        EXPORTING
          iv_header_guid             = pd_guid_dest
        IMPORTING
          ev_pd_handle               = ld_pd_handle_dest
        EXCEPTIONS
          error_occurred             = 1
          handle_determination_error = 2
          orgdata_error              = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.
    * A ne pas traiter les postes de type ZPDF
      DELETE  gt_orderadm_i WHERE itm_type = 'ZPDF'.
      LOOP AT gt_orderadm_i ASSIGNING <fs_orderadm_i_dest> WHERE header = pd_guid_dest.
        REFRESH : lt_komv_print_src,
                  lt_komv_print_dest,
    lt_cond_chg,
    lt_cond_chg_insert.
    * Début Modif CD1K904313-001.
    * Récupérer le guid de l'item liée au item destinataire.
        READ TABLE gt_doc_flow ASSIGNING <fs_doc_flow> WITH KEY objkey_b = <fs_orderadm_i_dest>-guid.
        CHECK sy-subrc EQ 0.
        ld_guid_src = <fs_doc_flow>-objkey_a.
    *    READ TABLE gt_orderadm_i ASSIGNING <fs_orderadm_i_src> WITH KEY header = pd_guid_src
    * number_int = <fs_orderadm_i_dest>-number_int.
    * Fin Modif CD1K904313-001.
    * Récupérer les pricing document
        IF sy-subrc EQ 0.
    *     Document source
          CALL FUNCTION 'PRC_PD_ITEM_SHOW'
            EXPORTING
              iv_pd_handle        = ld_pd_handle_src
    *         iv_item_no          = <fs_orderadm_i_src>-guid    "Supression CD1K904313-001
              iv_item_no          = ld_guid_src                 "Addition CD1K904313-001
            IMPORTING
              et_komv_print       = lt_komv_print_src
            EXCEPTIONS
              non_existing_handle = 1
              non_existing_item   = 2
              ipc_error           = 3
              OTHERS              = 4.
        ENDIF.
    *   Document destinataire
        CALL FUNCTION 'PRC_PD_ITEM_SHOW'
          EXPORTING
            iv_pd_handle        = ld_pd_handle_dest
            iv_item_no          = <fs_orderadm_i_dest>-guid
          IMPORTING
    et_komv_print       = lt_komv_print_dest
          EXCEPTIONS
            non_existing_handle = 1
            non_existing_item   = 2
            ipc_error           = 3
            OTHERS              = 4.
    * Modification et Suppression des conditions de prix
        LOOP AT lt_komv_print_dest INTO ls_komv_print_dest .
          CLEAR: ls_cond_chg,
                 ls_komv_print_src.
          MOVE-CORRESPONDING ls_komv_print_dest TO ls_cond_chg.
    * Rechercher la condition sur le document source
          READ TABLE lt_komv_print_src INTO ls_komv_print_src WITH KEY kschl = ls_komv_print_dest-kschl
    zaehk = ls_komv_print_dest-zaehk. "CD1K904313
          IF sy-subrc EQ 0.
            ls_cond_chg-kbetr_prt = ls_komv_print_src-kbetr_prt.
            ls_cond_chg-kwert     = ls_komv_print_src-kwert.
            ls_cond_chg-kinak     = ls_komv_print_src-kinak.
          ELSEIF ls_cond_chg-kschl IS NOT INITIAL.
            CLEAR ls_cond_chg.
            CONTINUE.
          ENDIF.
    *     Format décimal
          CASE gv_decimal.
            WHEN space.       "format N.NNN,NN
              REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
            WHEN 'Y'.         "format N NNN NNN,NN
              REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
          ENDCASE.
          INSERT ls_cond_chg INTO TABLE lt_cond_chg.
          CLEAR ls_cond_chg.
        ENDLOOP.
    * Ajout des conditions de prix
        LOOP AT lt_komv_print_src INTO ls_komv_print_src WHERE kschl IS NOT INITIAL.
          CLEAR: ls_cond_chg, ld_lines, ls_komv_print_dest, ls_cond_chg_tmp, ld_ajout_cond.
    * Vérifier la présence de la condition sur le document destinataire
          READ TABLE lt_komv_print_dest INTO ls_komv_print_dest WITH KEY kschl = ls_komv_print_src-kschl
    zaehk = ls_komv_print_src-zaehk. "CD1K904313.
          IF sy-subrc EQ 0.
            CLEAR: ls_cond_chg, ls_komv_print_dest.
            CONTINUE.
          ELSE.
            DESCRIBE TABLE lt_cond_chg LINES ld_lines.
            READ TABLE lt_cond_chg INTO ls_cond_chg_tmp INDEX ld_lines.
            IF sy-subrc EQ 0.
              ld_ajout_cond = abap_true.
              MOVE-CORRESPONDING ls_komv_print_src TO ls_cond_chg.
              ls_cond_chg-knumv     = ls_cond_chg_tmp-knumv.
              ls_cond_chg-kposn     = ls_cond_chg_tmp-kposn.
              ls_cond_chg-stunr     = ls_cond_chg_tmp-stunr + 10.
            ELSE.
              CLEAR: ls_cond_chg, ld_lines, ls_komv_print_dest, ls_cond_chg_tmp.
              CONTINUE.
            ENDIF.
          ENDIF.
    *     Format décimal
          CASE gv_decimal.
            WHEN space.             "format N.NNN,NN
              REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
            WHEN 'Y'.               "format N NNN NNN,NN
              REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
          ENDCASE.
    * Récupérer les nouvelles conditions qui seront ajouté au document destinataire
          IF ld_ajout_cond EQ abap_true.
            INSERT ls_cond_chg INTO TABLE lt_cond_chg_insert.
          ENDIF.
          INSERT ls_cond_chg INTO TABLE lt_cond_chg.
          CLEAR ls_cond_chg.
        ENDLOOP.
        CALL FUNCTION 'PRC_INT_ITEM_INPUT'
          EXPORTING
            iv_pd_handle        = ld_pd_handle_dest
            iv_item_no          = <fs_orderadm_i_dest>-guid
            it_cond_prt         = lt_cond_chg
            iv_bal_log          = bal_log
            iv_req_ret          = abap_true
            iv_req_cond_prt     = abap_true
          IMPORTING
            et_item_ret         = lt_item_ret
            et_cond_prt         = lt_cond_ret
            ev_data_changed     = ld_data_changed
          EXCEPTIONS
            non_existing_handle = 1
            non_existing_item   = 2
            ipc_error           = 3.
        IF sy-subrc = 0.
    *     En cas d'ajout de nouvelles conditions de prix, appeler le MF PRC_INT_ITEM_INPUT
    *     avec les montants
          IF lt_cond_chg_insert IS NOT INITIAL.
            REFRESH lt_cond_chg[].
            lt_cond_chg[] = lt_cond_ret[].
            LOOP AT lt_cond_chg_insert ASSIGNING <fs_cond_chg_insert>.
              READ TABLE lt_cond_chg ASSIGNING <fs_cond_chg> WITH KEY kschl = <fs_cond_chg_insert>-kschl.
              IF sy-subrc EQ 0.
                <fs_cond_chg>-kwert     = <fs_cond_chg_insert>-kwert.
                <fs_cond_chg>-kbetr_prt = <fs_cond_chg_insert>-kbetr_prt.
              ENDIF.
            ENDLOOP.
            REFRESH lt_cond_ret[].
            CALL FUNCTION 'PRC_INT_ITEM_INPUT'
              EXPORTING
                iv_pd_handle        = ld_pd_handle_dest
                iv_item_no          = <fs_orderadm_i_dest>-guid
                it_cond_prt         = lt_cond_chg
                iv_bal_log          = bal_log
                iv_req_ret          = abap_true
                iv_req_cond_prt     = abap_true
              IMPORTING
                et_item_ret         = lt_item_ret
                et_cond_prt         = lt_cond_ret
                ev_data_changed     = ld_data_changed
              EXCEPTIONS
                non_existing_handle = 1
                non_existing_item   = 2
                ipc_error           = 3.
          ENDIF.
    *   Publish event afin de sauvegarder les conditions de prix
          CALL FUNCTION 'CRM_EVENT_PUBLISH_OW'
            EXPORTING
              iv_obj_name = 'PRIDOC'
              iv_guid_hi  = pd_guid_dest
              iv_kind_hi  = 'A'
              iv_event    = 'SAVE'
            EXCEPTIONS
              OTHERS      = 1.
    *   As no order_maintain will follow implicitly and therefore no
    *   exec times for the events will be set, call CRM_ORDER_MAINTAIN
    *   without any parameters
    *   Then the exec time 'end of document' will be set and with the
    *   group logic also all exec times before
    *   But at least one object is needed in input_fields
    *   --> use PRIDOC
          ls_input_fields-ref_guid   = <fs_orderadm_i_dest>-guid.
          ls_input_fields-ref_kind   = 'B'.
          ls_input_fields-objectname = 'PRIDOC'.
          INSERT ls_input_fields INTO TABLE lt_input_fields.
          CLEAR ls_input_fields.
          CALL FUNCTION 'CRM_ORDER_MAINTAIN'
            CHANGING
              ct_input_fields   = lt_input_fields
            EXCEPTIONS
              error_occurred    = 1
              document_locked   = 2
              no_change_allowed = 3
              no_authority      = 4
              OTHERS            = 5.
        ENDIF.
      ENDLOOP.
    " F_MODIF_CONDITION_PRIX
    *& Form  F_LOCK_DOCUMENT
    * Verrouillage d'un document
    FORM f_lock_document  USING pd_guid TYPE crmt_object_guid.
      CONSTANTS : lc_orderadm_h TYPE  crmt_object_name  VALUE 'ORDERADM_H',
                  lc_orderadm_i TYPE  crmt_object_name  VALUE 'ORDERADM_I'.
      DATA: lv_process_mode      TYPE crmt_mode,
            lv_order_initialized TYPE crmt_boolean,
            lv_process_type      TYPE crmt_process_type,
            lv_already_locked    TYPE abap_bool.
      DATA: ls_admin_ui_status  TYPE crmt_admin_ui_status,
            ls_item_usage_range TYPE crmt_item_usage_range.
      DATA: lt_objects_to_read   TYPE crmt_object_guid_tab,
            lt_requested_objects TYPE crmt_object_name_tab,
            lt_item_usage_range  TYPE crmt_item_usage_range_tab,
            lt_locked_contract   TYPE crmt_object_guid_tab.
      INSERT pd_guid INTO TABLE lt_objects_to_read.
      INSERT lc_orderadm_h INTO TABLE lt_requested_objects.
      INSERT lc_orderadm_i INTO TABLE lt_requested_objects.
      ls_item_usage_range-sign  = 'E'.
      ls_item_usage_range-value = '02'.
      INSERT ls_item_usage_range INTO TABLE lt_item_usage_range.
    * LAM: Financing Options should be viewed in a separate screen:
      ls_item_usage_range-sign  = 'E'.
      ls_item_usage_range-value = '05'.   "Financing options
      INSERT ls_item_usage_range INTO TABLE lt_item_usage_range.
    *-> read document in change mode
      CALL FUNCTION 'CRM_ORDER_READ'
        EXPORTING
          it_header_guid       = lt_objects_to_read
          iv_mode              = 'B'
          it_requested_objects = lt_requested_objects
          it_item_usage_range  = lt_item_usage_range
        EXCEPTIONS
          document_not_found   = 1
          error_occurred       = 2
          document_locked      = 3
          no_change_authority  = 4
          no_display_authority = 5
          OTHERS               = 6.
      PERFORM enqueue_order IN PROGRAM saplcrm_order_ow IF FOUND
        USING pd_guid
              abap_false
              abap_false
              abap_false
    CHANGING sy-subrc
              lv_already_locked
              lt_locked_contract.
    " F_LOCK_DOCUMENT
    * Fin Ajout CD1K904074-001
    FORM f_header_copy_pricing  USING   pd_guid_src
    pd_guid_dest.
      DATA : ld_pd_handle_src     TYPE prct_handle,
              ld_pd_handle_dest    TYPE prct_handle,
              lt_komv_print_src    TYPE prct_cond_print_t,
    lt_komv_print_dest   TYPE prct_cond_print_t,
              ls_komv_print_dest   LIKE LINE OF lt_komv_print_dest,
              ls_komv_print_src    LIKE LINE OF lt_komv_print_src,
              lt_cond_chg          TYPE prct_cond_print_t,
              ls_cond_chg          TYPE prct_cond_print,
              ls_input_fields      TYPE crmt_input_field,
              lt_input_fields      TYPE crmt_input_field_tab.
      DATA : bal_log         TYPE balloghndl,
             lt_cond_ret     TYPE prct_cond_print_t,
             ld_data_changed TYPE xfeld,
             gv_decimal      TYPE usdefaults-dcpfm.
    * Verrouillage des documents source et destinataire
      PERFORM f_lock_document USING pd_guid_src.
      PERFORM f_lock_document USING pd_guid_dest.
    *  Récupérer le pricing handle des documents
    * Document source
      CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
        EXPORTING
          iv_header_guid             = pd_guid_src
        IMPORTING
          ev_pd_handle               = ld_pd_handle_src
        EXCEPTIONS
          error_occurred             = 1
          handle_determination_error = 2
          orgdata_error              = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.
    * Document destinataire
      CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
        EXPORTING
          iv_header_guid             = pd_guid_dest
        IMPORTING
          ev_pd_handle               = ld_pd_handle_dest
        EXCEPTIONS
          error_occurred             = 1
          handle_determination_error = 2
          orgdata_error              = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.
    *  * Récupérer les pricing document
    *  Document Source
      CALL FUNCTION 'PRC_PD_HEAD_SHOW'
        EXPORTING
          iv_pd_handle        = ld_pd_handle_src
        IMPORTING
          et_komv_print       = lt_komv_print_src
        EXCEPTIONS
          non_existing_handle = 1
          ipc_error           = 2
          OTHERS              = 3.
      CHECK sy-subrc EQ 0.
    *  Document Destinataire
      CALL FUNCTION 'PRC_PD_HEAD_SHOW'
        EXPORTING
          iv_pd_handle        = ld_pd_handle_dest
        IMPORTING
    et_komv_print       = lt_komv_print_dest
        EXCEPTIONS
          non_existing_handle = 1
          ipc_error           = 2
          OTHERS              = 3.
      CHECK sy-subrc EQ 0.
    *  * Modification et Suppression des conditions de prix
      LOOP AT lt_komv_print_src INTO ls_komv_print_src .
        CLEAR: ls_cond_chg,
               ls_komv_print_dest.
        MOVE-CORRESPONDING ls_komv_print_src TO ls_cond_chg.
    * Rechercher la condition sur le document source
        READ TABLE lt_komv_print_dest INTO ls_komv_print_dest WITH KEY kschl = ls_komv_print_src-kschl
    zaehk = ls_komv_print_src-zaehk.
        IF sy-subrc EQ 0.
          IF ls_komv_print_src-kbetr NE ls_komv_print_dest-kbetr.
            ls_cond_chg-kbetr_prt = ls_komv_print_src-kbetr_prt.
            ls_cond_chg-kwert     = ls_komv_print_src-kwert.
            ls_cond_chg-kinak     = ls_komv_print_src-kinak.
            CASE gv_decimal.
              WHEN space.       "format N.NNN,NN
                REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
              WHEN 'Y'.         "format N NNN NNN,NN
                REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
            ENDCASE.
          ENDIF.
        ENDIF.
        CLEAR ls_cond_chg-krech.
        INSERT ls_cond_chg INTO TABLE lt_cond_chg.
        CLEAR ls_cond_chg.
      ENDLOOP.
      CALL FUNCTION 'PRC_INT_HEAD_INPUT'
        EXPORTING
          iv_pd_handle        = ld_pd_handle_dest
          iv_bal_log          = bal_log
          it_cond_prt         = lt_cond_chg
          iv_req_ret          = abap_true
          iv_req_cond_prt     = abap_true
        IMPORTING
          et_cond_prt         = lt_cond_ret
          ev_data_changed     = ld_data_changed
        EXCEPTIONS
          non_existing_handle = 1
          ipc_error           = 2
          not_allowed         = 3
          OTHERS              = 4.
      CHECK sy-subrc EQ 0.
    *    *   Publish event afin de sauvegarder les conditions de prix
      CALL FUNCTION 'CRM_EVENT_PUBLISH_OW'
        EXPORTING
          iv_obj_name = 'PRIDOC'
          iv_guid_hi  = pd_guid_dest
          iv_kind_hi  = 'A'
          iv_event    = 'SAVE'
        EXCEPTIONS
          OTHERS      = 1.
    *   As no order_maintain will follow implicitly and therefore no
    *   exec times for the events will be set, call CRM_ORDER_MAINTAIN
    *   without any parameters
    *   Then the exec time 'end of document' will be set and with the
    *   group logic also all exec times before
    *   But at least one object is needed in input_fields
    *   --> use PRIDOC
      ls_input_fields-ref_guid   = pd_guid_dest.
      ls_input_fields-ref_kind   = 'A'.
      ls_input_fields-objectname = 'PRIDOC'.
      INSERT ls_input_fields INTO TABLE lt_input_fields.
      CLEAR ls_input_fields.
      CALL FUNCTION 'CRM_ORDER_MAINTAIN'
        CHANGING
          ct_input_fields   = lt_input_fields
        EXCEPTIONS
          error_occurred    = 1
          document_locked   = 2
          no_change_allowed = 3
          no_authority      = 4
          OTHERS            = 5.
    ENDFORM.
    FORM f_header_copy_pricing  USING   pd_guid_src
    pd_guid_dest.
      DATA : ld_pd_handle_src     TYPE prct_handle,
              ld_pd_handle_dest    TYPE prct_handle,
              lt_komv_print_src    TYPE prct_cond_print_t,
    lt_komv_print_dest   TYPE prct_cond_print_t,
              ls_komv_print_dest   LIKE LINE OF lt_komv_print_dest,
              ls_komv_print_src    LIKE LINE OF lt_komv_print_src,
              lt_cond_chg          TYPE prct_cond_print_t,
              ls_cond_chg          TYPE prct_cond_print,
              ls_input_fields      TYPE crmt_input_field,
              lt_input_fields      TYPE crmt_input_field_tab.
      DATA : bal_log         TYPE balloghndl,
             lt_cond_ret     TYPE prct_cond_print_t,
             ld_data_changed TYPE xfeld,
             gv_decimal      TYPE usdefaults-dcpfm.
      PERFORM f_lock_document USING pd_guid_src.
      PERFORM f_lock_document USING pd_guid_dest.
    *  Récupérer le pricing handle des documents
    * Document source
      CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
        EXPORTING
          iv_header_guid             = pd_guid_src
        IMPORTING
          ev_pd_handle               = ld_pd_handle_src
        EXCEPTIONS
          error_occurred             = 1
          handle_determination_error = 2
          orgdata_error              = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.
    * Document destinataire
      CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
        EXPORTING
          iv_header_guid             = pd_guid_dest
        IMPORTING
          ev_pd_handle               = ld_pd_handle_dest
        EXCEPTIONS
          error_occurred             = 1
          handle_determination_error = 2
          orgdata_error              = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.
    *  * Récupérer les pricing document
    *  Document Source
      CALL FUNCTION 'PRC_PD_HEAD_SHOW'
        EXPORTING
          iv_pd_handle        = ld_pd_handle_src
        IMPORTING
          et_komv_print       = lt_komv_print_src
        EXCEPTIONS
          non_existing_handle = 1
          ipc_error           = 2
          OTHERS              = 3.
      CHECK sy-subrc EQ 0.
    *  Document Destinataire
      CALL FUNCTION 'PRC_PD_HEAD_SHOW'
        EXPORTING
          iv_pd_handle        = ld_pd_handle_dest
        IMPORTING
    et_komv_print       = lt_komv_print_dest
        EXCEPTIONS
          non_existing_handle = 1
          ipc_error           = 2
          OTHERS              = 3.
      CHECK sy-subrc EQ 0.
    *  * Modification et Suppression des conditions de prix
      LOOP AT lt_komv_print_src INTO ls_komv_print_src .
        CLEAR: ls_cond_chg,
               ls_komv_print_dest.
        MOVE-CORRESPONDING ls_komv_print_src TO ls_cond_chg.
    * Rechercher la condition sur le document source
        READ TABLE lt_komv_print_dest INTO ls_komv_print_dest WITH KEY kschl = ls_komv_print_src-kschl
    zaehk = ls_komv_print_src-zaehk.
        IF sy-subrc EQ 0.
          IF ls_komv_print_src-kbetr NE ls_komv_print_dest-kbetr.
            ls_cond_chg-kbetr_prt = ls_komv_print_src-kbetr_prt.
            ls_cond_chg-kwert     = ls_komv_print_src-kwert.
            ls_cond_chg-kinak     = ls_komv_print_src-kinak.
            CASE gv_decimal.
              WHEN space.       "format N.NNN,NN
                REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
              WHEN 'Y'.         "format N NNN NNN,NN
                REPLACE ALL OCCURRENCES OF '.' IN ls_cond_chg-kbetr_prt WITH ','.
            ENDCASE.
          ENDIF.
        ENDIF.
        CLEAR ls_cond_chg-krech.
        INSERT ls_cond_chg INTO TABLE lt_cond_chg.
        CLEAR ls_cond_chg.
      ENDLOOP.
      CALL FUNCTION 'PRC_INT_HEAD_INPUT'
        EXPORTING
          iv_pd_handle        = ld_pd_handle_dest
          iv_bal_log          = bal_log
          it_cond_prt         = lt_cond_chg
          iv_req_ret          = abap_true
          iv_req_cond_prt     = abap_true
        IMPORTING
          et_cond_prt         = lt_cond_ret
          ev_data_changed     = ld_data_changed
        EXCEPTIONS
          non_existing_handle = 1
          ipc_error           = 2
          not_allowed         = 3
          OTHERS              = 4.
      CHECK sy-subrc EQ 0.
      CALL FUNCTION 'CRM_EVENT_PUBLISH_OW'
        EXPORTING
          iv_obj_name = 'PRIDOC'
          iv_guid_hi  = pd_guid_dest
          iv_kind_hi  = 'A'
          iv_event    = 'SAVE'
        EXCEPTIONS
          OTHERS      = 1.
      ls_input_fields-ref_guid   = pd_guid_dest.
      ls_input_fields-ref_kind   = 'A'.
      ls_input_fields-objectname = 'PRIDOC'.
      INSERT ls_input_fields INTO TABLE lt_input_fields.
      CLEAR ls_input_fields.
      CALL FUNCTION 'CRM_ORDER_MAINTAIN'
        CHANGING
          ct_input_fields   = lt_input_fields
        EXCEPTIONS
          error_occurred    = 1
          document_locked   = 2
          no_change_allowed = 3
          no_authority      = 4
          OTHERS            = 5.

  • CRM_ORDER_MAINTAIN - in order_save BADI

    Hi Experts,
    I want to update my order. I have to add the account assignment group to my service order when the order is saved. How do I pass this value in the badi order_save. I want to use the function module crm_order_maintain. Can anyone please suggest how do I go about it.
    Warm Regards,
    Abdullah

    Hi Experts,
    This is how I code after I use CRM_ORDER_READ in the badi method change_before_update.
      select single *
        from zco003
        into wa_zco003
        where service_org_shor = v_sorg and
              process_type     = v_process_type.
      if sy-subrc = 0.
        iw_ac_assign-ref_guid = iv_guid.
        iw_ac_assign-ref_kind = 'A'.
        iw_ac_assign-ac_object_type = '01'.
        iw_ac_assign-ac_assignment = wa_zco003-aufnr.
        iw_ac_assign-ac_percentage = '0.00'.
        iw_ac_assign-mode = 'C'.
        append iw_ac_assign to it_ac_assign.
        cw_orderadm_h-guid = iv_guid.
        append cw_orderadm_h to ct_orderadm_h.
        cw_input_fields-ref_guid = iv_guid.
        cw_input_fields-ref_kind = 'A'.
        cw_input_fields-objectname = 'AC_ASSIGN'.
        cw_field_name-fieldname = 'AC_ASSIGNMENT'.
        cw_field_name-changeable = 'X'.
        append cw_field_name to ct_field_name.
        cw_field_name-fieldname = 'AC_OBJECT_TYPE'.
        cw_field_name-changeable = 'X'.
        append cw_field_name to ct_field_name.
        cw_field_name-fieldname = 'AC_PERCENTAGE'.
        cw_field_name-changeable = 'X'.
        append cw_field_name to ct_field_name.
        cw_field_name-fieldname = 'AC_TYPE_T'.
        cw_field_name-changeable = 'X'.
        append cw_field_name to ct_field_name.
        cw_field_name-fieldname = 'MODE'.
        cw_field_name-changeable = 'X'.
        append cw_field_name to ct_field_name.
        cw_input_fields-field_names[] = ct_field_name[].
        append cw_input_fields to ct_input_fields.
        loop at et_orderadm_i into ew_orderadm_i.
          clear cw_input_fields.
          cw_input_fields-ref_guid = ew_orderadm_i-guid.
          cw_input_fields-ref_kind = 'B'.
          cw_input_fields-objectname = 'AC_ASSIGN'.
          append cw_input_fields to ct_input_fields.
        endloop.
        clear cw_input_fields.
        cw_input_fields-ref_guid = iv_guid.
        cw_input_fields-ref_kind = 'A'.
        cw_input_fields-objectname = 'ORDERADM_H'.
        append cw_input_fields to ct_input_fields.
        loop at et_orderadm_i into ew_orderadm_i.
          cw_orderadm_i-guid = ew_orderadm_i-guid.
          append cw_orderadm_i to ct_orderadm_i.
          clear cw_orderadm_i.
        endloop.
        loop at et_orderadm_i into ew_orderadm_i.
          clear cw_input_fields.
          cw_input_fields-ref_guid = ew_orderadm_i-guid.
          cw_input_fields-ref_kind = 'B'.
          cw_input_fields-objectname = 'ORDERADM_I'.
          append cw_input_fields to ct_input_fields.
        endloop.
        call function 'CRM_ORDER_MAINTAIN'
         exporting
           it_ac_assign                  = it_ac_assign
         importing
           et_exception                  =  et_exception
         changing
    *       ct_orderadm_h                 = ct_orderadm_h
    *       ct_orderadm_i                 = ct_orderadm_i
           ct_input_fields               = ct_input_fields
           cv_log_handle                 = cv_log_handle
    *       ct_partner_attributes         =
    *       ct_doc_flow                   =
         exceptions
           error_occurred                = 1
           document_locked               = 2
           no_change_allowed             = 3
           no_authority                  = 4
           others                        = 5
        if sy-subrc <> 0.
    * message id sy-msgid type sy-msgty number sy-msgno
    *         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          message 'error in updating' type 'e'.
        endif.
    Can anyone please suggest what am I doing wrong
    Regards,
    Abdullah

  • CRM_ORDER_MAINTAIN - Appointments

    Hi all
    A client is using the CRM interaction centre (trxn. CIC0). When a date is set in a transaction within CIC0, they want that date copied to all the follow up activities as well when the user saves.
    We've already used BADI ORDER_SAVE and FM's CRM_ORDER_READ, CRM_ORDER_MAINTAIN, and CRM_ORDER_SAVE to achieve this for some customer fields that were added in on a customer screen within CIC0 but cannot seem to achieve the same thing for the standard dates (appointments). When testing, the dates don't get copied through and don't appear on the Bdoc's (getting them onto the Bdoc's is the main priority).
    Any guidance from ABAP developer's experienced with this area of CRM would be greatly appreciated.
    The relevant coding from within the BADI is below:- (for ease of reading I've removed the coding going through the document flow and building up the internal table of GUID's that need to have the date maintained)
    METHOD if_ex_order_save~prepare .
    TYPES: BEGIN OF t_guids,
    guid TYPE crmt_doc_flow_wrk-objkey_a,
    END OF t_guids.
    * Header GUID's.
    DATA: lt_header_guid TYPE crmt_object_guid_tab,
    ls_header_guid TYPE crmt_object_guid,
    * Read appointments.
    lt_appointment_wrk TYPE crmt_appointment_wrkt,
    ls_appointment_wrk TYPE crmt_appointment_wrk,
    * Update appointments.
    lt_appointment_com TYPE crmt_appointment_comt,
    ls_appointment_com TYPE crmt_appointment_com,
    * GUID's
    lt_guids TYPE TABLE OF t_guids,
    ls_guids TYPE t_guids,
    * Update fields.
    ls_input_fields TYPE crmt_input_field,
    lt_input_fields TYPE crmt_input_field_tab,
    ls_input_field_names TYPE crmt_input_field_names,
    lt_input_field_names TYPE crmt_input_field_names_tab,
    * Order header data.
    lt_orderadm_h TYPE crmt_orderadm_h_comt,
    * Objects to be updated.
    lt_objects_to_save TYPE crmt_object_guid_tab,
    * Exceptions.
    lt_exception TYPE crmt_exception_t,
    * Updated documents.
    lt_saved_objects TYPE crmt_return_objects,
    lt_objects_not_saved TYPE crmt_object_guid_tab,
    * Local update task.
    lv_update_task_local TYPE boolean.
    * Use a global variable to ensure this method is only called once per user save.
    IF gv_first IS INITIAL.
    gv_first = 'X'.
    * Get the dates for the current activity.
    ls_header_guid = iv_guid.
    INSERT ls_header_guid INTO TABLE lt_header_guid.
    CALL FUNCTION 'CRM_ORDER_READ'
    EXPORTING
    it_header_guid = lt_header_guid
    IMPORTING
    et_appointment = lt_appointment_wrk
    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.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    DELETE lt_appointment_wrk WHERE appt_type <> 'ZLSC00003'
    OR timestamp_from IS INITIAL.
    * Check if the conclusion date has been set (appointment type ZLSC00003).
    READ TABLE lt_appointment_wrk
    INTO ls_appointment_wrk
    WITH KEY appt_type = 'ZLSC00003'.
    IF sy-subrc = 0.
    * Coding removed here, build up the follow up GUID's from the document flow.
    * lt_header_guid now contains the parent GUID and the follow up activty GUID's
    * Get all of the date details for all of the documents.
    CALL FUNCTION 'CRM_ORDER_READ'
    EXPORTING
    it_header_guid = lt_header_guid
    IMPORTING
    et_appointment = lt_appointment_wrk
    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.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    * Get rid of date entries which aren't conclusion dates or aren't the same conclusion date.
    DELETE lt_appointment_wrk WHERE appt_type <> 'ZLSC00003'
    OR timestamp_from <> ls_appointment_wrk-timestamp_from.
    * Process each of the documents and, if they don't have a conclusion date with the same value,
    * set up the internal tables to update the document.
    LOOP AT lt_header_guid INTO ls_header_guid.
    * Check if it has a conclusion date with the correct value already.
    READ TABLE lt_appointment_wrk
    WITH KEY ref_guid = ls_header_guid
    TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
    DELETE lt_header_guid.
    CONTINUE.
    ENDIF.
    * Set up the fields to be updated.
    CLEAR lt_input_field_names.
    ls_input_field_names-fieldname = 'REF_KIND'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_field_names-fieldname = 'APPT_TYPE'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_field_names-fieldname = 'TIMESTAMP_FROM'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_field_names-fieldname = 'TIMEZONE_FROM'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_field_names-fieldname = 'TIMESTAMP_TO'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_field_names-fieldname = 'TIMEZONE_TO'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_field_names-fieldname = 'TIME_UNIT'.
    INSERT ls_input_field_names INTO TABLE lt_input_field_names.
    ls_input_fields-ref_handle = '0000000000'.
    ls_input_fields-ref_guid = ls_header_guid.
    ls_input_fields-objectname = 'APPOINTMENT'.
    ls_input_fields-field_names = lt_input_field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    * Set up the values for the fields to be updated.
    ls_appointment_com-ref_handle = '0000000000'.
    ls_appointment_com-ref_guid = ls_header_guid.
    ls_appointment_com-ref_kind = 'A'.
    ls_appointment_com-appt_type = 'ZLSC00003'.
    ls_appointment_com-timestamp_from = ls_appointment_wrk-timestamp_from.
    ls_appointment_com-timezone_from = ls_appointment_wrk-timezone_from.
    ls_appointment_com-timestamp_to = ls_appointment_wrk-timestamp_to.
    ls_appointment_com-timezone_to = ls_appointment_wrk-timezone_to.
    ls_appointment_com-time_unit = ls_appointment_wrk-time_unit.
    INSERT ls_appointment_com INTO TABLE lt_appointment_com.
    * Create an entry in the internal table used to determine which documents will be updated.
    INSERT ls_header_guid INTO TABLE lt_objects_to_save.
    ENDLOOP.
    * Change the values in the documents
    IF NOT lt_appointment_com IS INITIAL.
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
    it_appointment = lt_appointment_com
    IMPORTING
    et_exception = lt_exception
    CHANGING
    ct_orderadm_h = lt_orderadm_h
    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.
    EXIT.
    ENDIF.
    ENDIF.
    * Save the changed date values.
    IF NOT lt_objects_to_save IS INITIAL.
    CALL FUNCTION 'CRM_ORDER_SAVE'
    EXPORTING
    it_objects_to_save = lt_objects_to_save
    iv_update_task_local = lv_update_task_local
    IMPORTING
    et_saved_objects = lt_saved_objects
    et_exception = lt_exception
    et_objects_not_saved = lt_objects_not_saved
    EXCEPTIONS
    document_not_saved = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    ENDIF.
    ENDIF.
    CLEAR gv_first.
    ENDIF.
    ENDMETHOD.

    Hi All,
    I am currently trying to insert a date into DATE TYPE(APPT_TYPE) in Item Level. There are no errors in the code but the transaction is not updated. Can somebody help me out ? Thanx a lot...
    MOVE: gw_service_item_guid_ubb TO gw_appointment-       
          ref_guid,         
          'B' TO gw_appointment ref_kind,                         
          'CONTDISMAN' TO gw_appointment-appt_type,               
          '20060901220000' TO gw_appointment-timestamp_from,
          '20060901220000' TO gw_appointment-timestamp_to,
          'CET' TO gw_appointment-timezone_from,
          'CET' TO gw_appointment-timezone_to,
          'B' TO gw_appointment-mode.
    APPEND gw_appointment TO gt_appointment_ubb.
    gw_fname-fieldname = 'APPT_TYPE'.
    gw_fname-changeable = 'X'.
    insert gw_fname into table gt_fname.
    gw_fname-fieldname = 'TIMESTAMP_FROM'.
    gw_fname-changeable = 'X'.
    INSERT gw_fname INTO TABLE gt_fname.
    gw_fname-fieldname = 'TIMESTAMP_TO'.
    gw_fname-changeable = 'X'.
    INSERT gw_fname INTO TABLE gt_fname.
    gw_fname-fieldname = 'TIMEZONE_FROM'.
    gw_fname-changeable = 'X'.
    INSERT gw_fname INTO TABLE gt_fname.
    gw_fname-fieldname = 'TIMEZONE_TO'.
    gw_fname-changeable = 'X'.
    INSERT gw_fname INTO TABLE gt_fname.
    gw_input-ref_guid = gw_service_item_guid_ubb.
    gw_input-ref_kind = 'B'.
    gw_input-objectname = 'APPOINTMENT'.
    gw_input-logical_key = '0000'.
    gw_input-ref_handle = '0000000000'.
    gw_input-field_names = gt_fname.
    APPEND gw_input TO gt_input_fields.
    gw_item-guid = gw_service_item_guid_ubb.
    gw_item-header = '39CF8B702B8B334F90AF4B23CA991925'.
    gw_item-ITM_TYPE = gw_orderadm_i_ubb-itm_type.
    gw_item-mode = 'B'.
    APPEND gw_item TO gt_item.
    CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.
    CALL FUNCTION 'CRM_ORDER_INITIALIZE'
      EXPORTING
        iv_initialize_whole_buffer = true
      EXCEPTIONS
        OTHERS           = 2.
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
      EXPORTING
        it_appointment                = gt_appointment_ubb
        it_status                     = gt_status_maint
      CHANGING
        CT_ORDERADM_I                 = gt_item
        ct_input_fields               = gt_input_fields
    EXCEPTIONS
       error_occurred                = 1
       document_locked               = 2
       no_change_allowed             = 3
       no_authority                  = 4
       OTHERS                        = 5.
    CALL FUNCTION 'DIALOG_SET_WITH_DIALOG'.
    CALL FUNCTION 'CRM_ORDER_SAVE'
      EXPORTING
        it_objects_to_save   = gt_obj_guids
      IMPORTING
        et_saved_objects     = gt_saved_objects
        et_objects_not_saved = gt_objects_not_saved
      EXCEPTIONS
        document_not_saved   = 1
        OTHERS               = 2.
    IF sy-subrc EQ 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ENDIF.
    COMMIT WORK.
    Useful help will be awarded. : )

  • CRM - CRM_ORDER_MAINTAIN - Appointments

    Hi all
      A client is using the CRM interaction centre (trxn. CIC0). When a date is set in a transaction within CIC0, they want that date copied to all the follow up activities as well when the user saves.
      We've already used BADI ORDER_SAVE and FM's CRM_ORDER_READ, CRM_ORDER_MAINTAIN, and CRM_ORDER_SAVE to achieve this for some customer fields that were added in on a customer screen within CIC0 but cannot seem to achieve the same thing for the standard dates (appointments). When testing, the dates don't get copied through and don't appear on the Bdoc's (getting them onto the Bdoc's is the main priority).
      Any guidance from ABAP developer's experienced with this area of CRM would be greatly appreciated.
      The relevant coding from within the BADI is below:- (for ease of reading I've removed the coding going through the document flow and building up the internal table of GUID's that need to have the date maintained)
    METHOD if_ex_order_save~prepare .
      TYPES: BEGIN OF t_guids,
               guid TYPE crmt_doc_flow_wrk-objkey_a,
             END OF t_guids.
    Header GUID's.
      DATA: lt_header_guid       TYPE crmt_object_guid_tab,
            ls_header_guid       TYPE crmt_object_guid,
    Read appointments.
            lt_appointment_wrk   TYPE crmt_appointment_wrkt,
            ls_appointment_wrk   TYPE crmt_appointment_wrk,
    Update appointments.
            lt_appointment_com   TYPE crmt_appointment_comt,
            ls_appointment_com   TYPE crmt_appointment_com,
    GUID's
            lt_guids             TYPE TABLE OF t_guids,
            ls_guids             TYPE t_guids,
    Update fields.
            ls_input_fields      TYPE crmt_input_field,
            lt_input_fields      TYPE crmt_input_field_tab,
            ls_input_field_names TYPE crmt_input_field_names,
            lt_input_field_names TYPE crmt_input_field_names_tab,
    Order header data.
            lt_orderadm_h        TYPE crmt_orderadm_h_comt,
    Objects to be updated.
            lt_objects_to_save   TYPE crmt_object_guid_tab,
    Exceptions.
            lt_exception         TYPE crmt_exception_t,
    Updated documents.
            lt_saved_objects     TYPE crmt_return_objects,
            lt_objects_not_saved TYPE crmt_object_guid_tab,
    Local update task.
            lv_update_task_local TYPE boolean.
    Use a global variable to ensure this method is only called once per user save.
      IF gv_first IS INITIAL.
        gv_first = 'X'.
    Get the dates for the current activity.
        ls_header_guid = iv_guid.
        INSERT ls_header_guid INTO TABLE lt_header_guid.
        CALL FUNCTION 'CRM_ORDER_READ'
          EXPORTING
            it_header_guid       = lt_header_guid
          IMPORTING
            et_appointment       = lt_appointment_wrk
          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.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        DELETE lt_appointment_wrk WHERE appt_type      <> 'ZLSC00003'
                                     OR timestamp_from IS INITIAL.
    Check if the conclusion date has been set (appointment type ZLSC00003).
        READ TABLE lt_appointment_wrk
          INTO ls_appointment_wrk
          WITH KEY appt_type = 'ZLSC00003'.
        IF sy-subrc = 0.
    Coding removed here, build up the follow up GUID's from the document flow.
    lt_header_guid now contains the parent GUID and the follow up activty GUID's
    Get all of the date details for all of the documents.
          CALL FUNCTION 'CRM_ORDER_READ'
            EXPORTING
              it_header_guid       = lt_header_guid
            IMPORTING
              et_appointment       = lt_appointment_wrk
            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.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
    Get rid of date entries which aren't conclusion dates or aren't the same conclusion date.
          DELETE lt_appointment_wrk WHERE appt_type      <> 'ZLSC00003'
                                       OR timestamp_from <> ls_appointment_wrk-timestamp_from.
    Process each of the documents and, if they don't have a conclusion date with the same value,
    set up the internal tables to update the document.
          LOOP AT lt_header_guid INTO ls_header_guid.
    Check if it has a conclusion date with the correct value already.
            READ TABLE lt_appointment_wrk
              WITH KEY ref_guid = ls_header_guid
              TRANSPORTING NO FIELDS.
            IF sy-subrc = 0.
              DELETE lt_header_guid.
              CONTINUE.
            ENDIF.
    Set up the fields to be updated.
            CLEAR lt_input_field_names.
            ls_input_field_names-fieldname = 'REF_KIND'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_field_names-fieldname = 'APPT_TYPE'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_field_names-fieldname = 'TIMESTAMP_FROM'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_field_names-fieldname = 'TIMEZONE_FROM'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_field_names-fieldname = 'TIMESTAMP_TO'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_field_names-fieldname = 'TIMEZONE_TO'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_field_names-fieldname = 'TIME_UNIT'.
            INSERT ls_input_field_names INTO TABLE lt_input_field_names.
            ls_input_fields-ref_handle  = '0000000000'.
            ls_input_fields-ref_guid    = ls_header_guid.
            ls_input_fields-objectname  = 'APPOINTMENT'.
            ls_input_fields-field_names = lt_input_field_names.
            INSERT ls_input_fields INTO TABLE lt_input_fields.
    Set up the values for the fields to be updated.
            ls_appointment_com-ref_handle     = '0000000000'.
            ls_appointment_com-ref_guid       = ls_header_guid.
            ls_appointment_com-ref_kind       = 'A'.
            ls_appointment_com-appt_type      = 'ZLSC00003'.
            ls_appointment_com-timestamp_from = ls_appointment_wrk-timestamp_from.
            ls_appointment_com-timezone_from  = ls_appointment_wrk-timezone_from.
            ls_appointment_com-timestamp_to   = ls_appointment_wrk-timestamp_to.
            ls_appointment_com-timezone_to    = ls_appointment_wrk-timezone_to.
            ls_appointment_com-time_unit      = ls_appointment_wrk-time_unit.
            INSERT ls_appointment_com INTO TABLE lt_appointment_com.
    Create an entry in the internal table used to determine which documents will be updated.
            INSERT ls_header_guid INTO TABLE lt_objects_to_save.
          ENDLOOP.
    Change the values in the documents
          IF NOT lt_appointment_com IS INITIAL.
            CALL FUNCTION 'CRM_ORDER_MAINTAIN'
              EXPORTING
                it_appointment    = lt_appointment_com
              IMPORTING
                et_exception      = lt_exception
              CHANGING
                ct_orderadm_h     = lt_orderadm_h
                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.
              EXIT.
            ENDIF.
          ENDIF.
    Save the changed date values.
          IF NOT lt_objects_to_save IS INITIAL.
            CALL FUNCTION 'CRM_ORDER_SAVE'
              EXPORTING
                it_objects_to_save   = lt_objects_to_save
                iv_update_task_local = lv_update_task_local
              IMPORTING
                et_saved_objects     = lt_saved_objects
                et_exception         = lt_exception
                et_objects_not_saved = lt_objects_not_saved
              EXCEPTIONS
                document_not_saved   = 1
                OTHERS               = 2.
            IF sy-subrc <> 0.
              EXIT.
            ENDIF.
          ENDIF.
        ENDIF.
        CLEAR gv_first.
      ENDIF.
    ENDMETHOD.

    Hello Mark,
    did you know that there is also a Forum for SAP CRM: Webclient UI - Framework?
    Regards
    Gregor

  • Adding item data in Product tab for sales contract (crm_order_maintain)

    Hi, can I use crm_order_maintain to add line items under the product tab for a sales contract while creating or modifying an order. Is there any sample code to add the line items, I could look at.  I tried calling this FM from my custom tab and then called CRM_ORDER_SAVE but that did not add the line item. I guess I need to call it from the order_save badi and then call the crm_order_save FM as well from within the BADI. If someone could send me some sample code then I can double check if I am missing something.Am I on the right track to be using this FM for adding a line item under the product tab for the sales contract? Please help. thanks

    Hi, I've encountered the same problem while I was creating a Sub-Contract from a Master Contract.
    In my case the solution was:
    first create the Sub-Contract,
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
          CHANGING
            ct_orderadm_h     = i_ctorderadm_h
            ct_input_fields   = i_ctinput_fields
            ct_doc_flow       = i_ctdoc_flow
          EXCEPTIONS
            error_occurred    = 1
            document_locked   = 2
            no_change_allowed = 3
            no_authority      = 4
            OTHERS            = 5.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        READ TABLE i_ctorderadm_h INTO wa_ctorderadm_h INDEX 1.
        APPEND wa_ctorderadm_h-guid TO i_objects_to_save.
    in wa_ctorderadm_h-guid now we have the guid of the newly created Sub-Contract.
    SELECT SINGLE it_type_to
                 INTO  v_it_type_to    " --> target item type
                 FROM  crmc_it_copy_ma
                 WHERE it_type_from = wa_out_orderadm_i-itm_type.
         Prepare tables
            wa_ctorderadm_i-header =
            wa_out_orderadm_i-header.   "Retrieved from CRM_ORDER_READ
            wa_ctorderadm_i-handle = '0000000001'.
            wa_ctorderadm_i-number_int = '0000000001'.
            wa_ctorderadm_i-product = wa_out_orderadm_i-product.
            wa_ctorderadm_i-ordered_prod =
            wa_out_orderadm_i-ordered_prod.
            wa_ctorderadm_i-description = wa_out_orderadm_i-description.
            wa_ctorderadm_i-itm_type = v_it_type_to.
            wa_ctorderadm_i-order_date   = sy-datum.
            wa_ctorderadm_i-itm_language = sy-langu.
            wa_ctorderadm_i-mode = c_a.   "c_a = 'A'
            wa_ctorderadm_i-header = wa_ctorderadm_h-guid.
            APPEND wa_ctorderadm_i TO i_ctorderadm_i.
            wa_input_fields-ref_handle = '0000000001'.
            wa_input_fields-objectname = 'ORDERADM_I'.
            REFRESH i_input_field_names.
            wa_input_field_names-fieldname = 'DESCRIPTION'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'HEADER'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'ITM_TYPE'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'MODE'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'NUMBER_INT'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'ORDERED_PROD'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'ORDER_DATE'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_field_names-fieldname = 'PRODUCT'.
            APPEND wa_input_field_names TO i_input_field_names.
            wa_input_fields-field_names = i_input_field_names.
            APPEND wa_input_fields TO i_ctinput_fields.
    After that I've called function 'CRM_ORDER_MAINTAIN', to copy the Items from the Master Contract.
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
            EXPORTING
              it_sales          = i_sales
              it_schedlin_i     = i_schedlin_i
            CHANGING
              ct_orderadm_i     = i_ctorderadm_i
              ct_input_fields   = i_ctinput_fields
            EXCEPTIONS
              error_occurred    = 1
              document_locked   = 2
              no_change_allowed = 3
              no_authority      = 4
              OTHERS            = 5.
    Maybe if you're not working with Contracts, the procedure is not properly correct.
    I suggest to put a break-point into crm_order_maintain and try to add the Item manually.
    If you reproduce exactly the standard, I'm shure it will work.
    Lorenzo

  • CRM_ORDER_MAINTAIN and ACTIVE_SWITCH

    Hi experts,
    I am working as ABAP developers in CRM 5.0. We often use FM CRM_ORDER_MAINTAIN in our development, to create (or modify) several order types.
    I have heard about the ACTIVE_SWITCH input parameter of CRM_ORDER_MAINTAIN. It seems this parameter can optimize execution time, by avoiding some checks or determination (?).
    As anyone ever used the ACTIVE SWITCH or is there any documentation about it?
    I have searched on SDN forums and even on Google, but could not find anything about that...
    Thank you in advance.

    Hi Thomas!
    Never give up)
    Now seriously:
    if you are reading large amouts of data (10,000 orders or more, for example)
    then 2 things can help to do your program faster:
    1. Read orders by 100-200 GUIDS per one 'CRM_ORDER_READ' call.
    2. Periodically run FM 'CRM_ORDER_INITIALIZE' with IV_INIT_WHOLE_BUFFER = 'X' (this will initialize whole data buffer). For example, before every 'CRM_ORDER_READ' call. This will help because all readed data are being placed by CRM_ORDER functionality into standard internal tables, so you can see how slower & slower system works while reading large amounts of orders data without 'CRM_ORDER_INITIALIZE' call (in debugger).
    3. Call 'CRM_ORDER_READ' with IV_NO_AUTH_CHECK = 'X' if you are really do not need authorization checks.
    4. If possible do some SELECTs instead of CRM_ORDER_READ segment retreive.
    5. And the last but not least: periodically see SAP notes for 'CRM_ORDER_READ performance' because this one got lots of bugs yet.
    Hope it helps.
    Best regards,
    Alexander Kirillov

  • CRM_ORDER_MAINTAIN

    Hello.
    I'm trying to implement a solution using badi ORDER_SAVE and fm CRM_ORDER_MAINTAIN. I'm able to read some entries from organizational tree and add those entries to the order by doing something like this:
    LOOP AT lt_entries INTO ls_entries.
        ADD 1 TO counter.
        ls_new_partners-ref_guid = ls_orderadm_h-guid.
        ls_new_partners-ref_kind = 'A'.
        ls_new_partners-kind_of_entry = 'C'.
        ls_new_partners-ref_partner_handle = counter.
        ls_new_partners-partner_fct = gc_partner_fct_26.
        ls_new_partners-partner_no  = ls_entries-partner.
        ls_new_partners-display_type = 'BP'.
        ls_new_partners-no_type = 'BP'.
        INSERT ls_new_partners INTO TABLE lt_new_partners.
        CLEAR ls_input_fields.
        REFRESH ls_input_fields-field_names.
    *    ls_input_fields-ref_handle = ls_new_partners-ref_handle.
        ls_input_fields-ref_guid  = ls_orderadm_h-guid.
        ls_input_fields-ref_kind = 'A'.
        ls_input_fields-logical_key = ls_new_partners-ref_partner_handle.
        ls_input_fields-objectname = 'PARTNER'.
        ls_input_field_name-fieldname = 'PARTNER_FCT'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'NO_TYPE'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'DISPLAY_TYPE'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'PARTNER_NO'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'KIND_OF_ENTRY'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        INSERT ls_input_fields INTO TABLE lt_input_fields.
      ENDLOOP.
    * Update the order *
      CALL FUNCTION 'CRM_ORDER_MAINTAIN'
        EXPORTING
          it_partner        = lt_new_partners
        CHANGING
          ct_input_fields   = lt_input_fields
        EXCEPTIONS
          error_occurred    = 1
          document_locked   = 2
          no_change_allowed = 3
          no_authority      = 4
          OTHERS            = 5.
    Problem is that I'm loosing all the other manually added entries having different partner functions. I have tried to read the order using fm CRM_ORDER_READ and pass those partner entries to the fm CRM_ORDER_MAINTAIN by doing something like this:
    MOVE-CORRESPONDING ls_partner TO ls_new_partners.
    INSERT ls_new_partners INTO TABLE lt_new_partners.
    *    ls_input_fields-ref_handle = ls_new_partners-ref_handle.
        ls_input_fields-ref_guid  = ls_orderadm_h-guid.
        ls_input_fields-ref_kind = 'A'.
        ls_input_fields-logical_key = ls_new_partners-ref_partner_handle.
        ls_input_fields-objectname = 'PARTNER'.
        ls_input_field_name-fieldname = 'PARTNER_FCT'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'NO_TYPE'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'DISPLAY_TYPE'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'PARTNER_NO'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        ls_input_field_name-fieldname = 'KIND_OF_ENTRY'.
        INSERT ls_input_field_name INTO TABLE ls_input_fields-field_names.
        INSERT ls_input_fields INTO TABLE lt_input_fields.
    When I do this I loose all my entries.
    What am I missing here? How can I use this fm for maintaining/deleting entries?
    br, Johannes

    Hello Conrad,
    That is trully a weird problem.
    I´ve never have faced something similar.
    There is a report called CRM_DATAEXCHANGE_TOOLBOX where you can simulate a creation of an simple order.
    If you are in CRM 3.0 you must apply note 718322 to have this report.
    Another trick, insert a break-point inside this function and call transaction CRMD_ORDER, create the order filling the fields you are filling inside your program and see if the standard fills all the tables in the same way you are doing inside your program.
    Just to check out, to create an order you have to:
    1 - Call function CRM_ORDER_MAINTAIN
    2 - Call function CRM_ORDER_SAVE
    3 - Call function CRM_ORDER_INITIALIZE or CRM_ORDER_INIT_OW to clean up the memory and unlock the document you´ve just created.
    Regards,
    Mauricio

  • CRM_ORDER_MAINTAIN Documentation

    Good afternoon masters
    I 'm trying to use CRM_ORDER_MAINTAIN ... related functions. I 've been looking for documentation unsuccesfully.
    My problem is that I need to Copy Categorization from Interaction Record to Service Request.
    SAP says this scenario is not feasible now.
    We want to use, in CRM_COPY_BADI, the following sequence:
    CRM_ORDER_READ predeccessor
    CRM_ORDER_MAINTAIN on succesor
    Has anyone documentation of this FM?
    Any idea how to do it?
    Regards.
    P

    Hi Predro,
    Please remove the "D" in the beginning of the name.
    It's CRM_ORDER_READ in se37.
    To test it, you have to run the program with the same name in se38.
    You will find the categorization in the table ET_SERVICE_OS (go through the internal tables included) of CRM_ORDER_READ.
    Be aware that the categorization is modelized in a tricky way. In order to copy, the category, you need to copy the subject that is mapped with the categories.
    The easiest way to understand how works the function module is to put a break point in there and change the category. You will need to reproduce what the standard does.
    Hope this helps.
    Regards,
    Helder

  • Hour differences with CRM_ORDER_MAINTAIN

    Hi guys, I´m having troubles with some hour differences in some FM, all you know that the et_appointments dates can be set with the CRM_ORDER_MAINTAIN . . .
    I set the dates/hours ok in the timestamp_from, timestamp_to fields. The problem is that field TIME_FROM is the field that are show in the GUI and UI with some hour differences (Viewed with CRM_ORDER_READ), the system calculates in some way this field in combnation with the timezone.
    If I set the date manually in the GUI, the dates are set correctly. This is my code, note that is a local report only to test this issue with harcode .
    ls_appointment_t-ref_guid = 'E07692724B07E2F1886B005056960012'.
    ls_appointment_t-ref_kind = 'A'.
    ls_appointment_t-ref_handle = '0'.
    ls_appointment_t-timestamp_from = '20140317110000'.
    ls_appointment_t-timezone_from = 'CST'.
    ls_appointment_t-timestamp_to = '20140317110000'.
    ls_appointment_t-timezone_to = 'CST'.
    ls_appointment_t-appt_type = 'Z00000000036'.
    ls_appointment_t-duration = '0'.
    ls_appointment_t-rule_name = ''.
    INSERT ls_appointment_t INTO TABLE lt_appointment_t.
    CLEAR : lt_field_names[].
    ls_input_fields-ref_guid = 'E07692724B07E2F1886B005056960012'.
    ls_input_fields-ref_kind = 'A'.
    ls_input_fields-logical_key = 'Z00000000036'.
    ls_input_fields-ref_handle = '0'.
    ls_input_fields-objectname = 'APPOINTMENT'.
    ls_field_names-fieldname = 'DOMINANT'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname = 'DURATION'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname = 'RULE_NAME'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname = 'SHOW_LOCAL'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname = 'TIMESTAMP_FROM'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname = 'TIMESTAMP_TO'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname =  'TIMEZONE_FROM'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname =  'TIMEZONE_TO'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_field_names-fieldname =  'TIME_UNIT'.
    INSERT ls_field_names INTO TABLE lt_field_names.
    ls_input_fields-field_names = lt_field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_orderadm_h_t-guid = 'E07692724B07E2F1886B005056960012'.
    INSERT ls_orderadm_h_t INTO TABLE lt_orderadm_h_t.
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
      EXPORTING
        it_appointment    = lt_appointment_t
      IMPORTING
        et_exception      = lt_exception
      CHANGING
        ct_input_fields   = lt_input_fields
      EXCEPTIONS
        error_occurred    = 1
        document_locked   = 2
        no_change_allowed = 3
        no_authority      = 4
        OTHERS            = 5.
    with this code the hours are shown with some differences, if I set "ls_appointment_t-timestamp_from = '20140317110000'" in the GUI and UI the hour is set to 5:00
    Any clue about this !? or how can I resolve this with some code !?
    thanks

    I use the CONVERT DATE .... TIME . . . TIMEZONE instruction and leave the timezone of et_appointment blank. Thanks !!!

  • CRM_ORDER_MAINTAIN Partner is not deleted.

    Hi All,
    I wanted to remove "employee responsible" partner from Order via Z* program. Following is my code. But i m still not able to delete it. Can anybody have a look at code?
    lv_partner-ref_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    lv_partner-ref_handle = '0000000000'.
    lv_partner-ref_kind = 'A'.
    lv_partner-ref_partner_handle = '0000'.
    lv_partner-ref_partner_fct = '00000014'.
    lv_partner-ref_partner_no = '200010671'.
    lv_partner-ref_no_type = 'BP'.
    lv_partner-ref_display_type = 'BP'.
    lv_partner-partner_guid = 'DDCDB8C50DFC0CF19F94001E6849B4E8'.
    lv_partner-kind_of_entry = ''.
    lv_partner-partner_fct = '00000014'.
    lv_partner-partner_no = '200010671'.
    lv_partner-display_type = 'BP'.
    lv_partner-no_type = 'BP'.
    lv_partner-mainpartner = 'X'.
    INSERT lv_partner INTO TABLE lt_partner.
    data: l_key type CRMT_LOGICAL_KEY.
    ***Input Fields
    CONCATENATE '000000000014' '200010671' ' BPBP' INTO l_key.
    CLEAR lw_field.
    CLEAR lt_field.
    lw_field-ref_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    lw_field-ref_handle = '0000000000'.
    lw_field-ref_kind = 'A'.
    lw_field-objectname = 'PARTNER'.
    lw_field-logical_key = '000000000014200010671       BPBP'.
    lw_fp-fieldname = 'PARTNER_FCT'.
    INSERT lw_fp INTO TABLE lt_fp.
    lw_field-field_names = lt_fp.
    INSERT lw_field INTO TABLE lt_field.
    data: lt_mode type CRMT_ORDERADM_H_COMT,
          lv_mode type CRMT_ORDERADM_H_COM.
    lv_mode-guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    lv_mode-mode = 'D'.
    append lv_mode to lt_mode.
    * For BADI to change EMP Resp, Status, Text Note
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
         it_partner                    = lt_partner
    CHANGING
        CT_ORDERADM_H                  = lt_mode
        ct_input_fields                = lt_field
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    DATA: it_guid TYPE crmt_object_guid_tab.
    *      Lv_header_guid type crmt_object_guid.
    Lv_header_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    APPEND LV_HEADER_GUID TO IT_GUID.
    CALL FUNCTION 'CRM_ORDER_SAVE'
      EXPORTING
        it_objects_to_save         = it_guid
    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          =
    * IMPORTING
    *   RETURN        =

    Hi
    Following is my code look like after all the suggestions. But it does not remove the partner. Can you have a look at code?
    DATA: lt_activity TYPE crmt_activity_h_comt,
          lt_field TYPE crmt_input_field_tab ,
          lt_fp TYPE crmt_input_field_names_tab.
    DATA: lw_activity TYPE crmt_activity_h_com,
          lw_field TYPE crmt_input_field,
          lw_fp TYPE crmt_input_field_names.
    DATA: lt_guid TYPE crmt_object_guid_tab,
          lt_part  TYPE crmt_partner_external_wrkt,
          lv_partn TYPE crmt_partner_external_wrk,
          lv_header_guid TYPE crmt_object_guid.
    CALL FUNCTION 'CRM_ORDER_READ'
      EXPORTING
        it_header_guid = lt_guid
      IMPORTING
        et_partner     = lt_part.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    DATA: lt_partner TYPE crmt_partner_comt,
          lv_partner TYPE crmt_partner_com.
    lv_partner-ref_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    lv_partner-ref_handle = '0000000000'.
    lv_partner-ref_kind = 'A'.
    lv_partner-ref_partner_handle = '0000'.
    lv_partner-ref_partner_fct = '00000014'.
    lv_partner-ref_partner_no = '200010671'.
    lv_partner-ref_no_type = 'BP'.
    lv_partner-ref_display_type = 'BP'.
    lv_partner-partner_guid = 'DDCDB8C50DFC0CF19F94001E6849B4E8'.
    lv_partner-kind_of_entry = ''.
    ***lv_partner-partner_fct = '00000014'. " Only comment partner_fct
    lv_partner-partner_no = '200010671'.
    lv_partner-display_type = 'BP'.
    lv_partner-no_type = 'BP'.
    lv_partner-mainpartner = 'X'.
    INSERT lv_partner INTO TABLE lt_partner.
    *data: l_key type CRMT_LOGICAL_KEY.
    ****Input Fields
    *CONCATENATE '000000000014' '200010671' ' BPBP' INTO l_key.
    CLEAR lw_field.
    CLEAR lt_field.
    lw_field-ref_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    lw_field-ref_handle = '0000000000'.
    lw_field-ref_kind = 'A'.
    lw_field-objectname = 'PARTNER'.
    lw_fp-fieldname = 'PARTNER_FCT'.
    INSERT lw_fp INTO TABLE lt_fp.
    lw_fp-fieldname = 'PARTNER_NO'.
    INSERT lw_fp INTO TABLE lt_fp.
    lw_fp-fieldname = 'REF_PARTNER_FCT'.
    INSERT lw_fp INTO TABLE lt_fp.
    lw_fp-fieldname = 'REF_PARTNER_NO'.
    INSERT lw_fp INTO TABLE lt_fp.
    lw_fp-fieldname = 'REF_GUID'.
    INSERT lw_fp INTO TABLE lt_fp.
    lw_field-field_names = lt_fp.
    INSERT lw_field INTO TABLE lt_field.
    DATA: lt_mode TYPE crmt_orderadm_h_comt,
          lv_mode TYPE crmt_orderadm_h_com.
    lv_mode-guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    lv_mode-mode = 'D'.
    APPEND lv_mode TO lt_mode.
    DATA: it_guid TYPE crmt_object_guid_tab.
         Lv_header_guid type crmt_object_guid.
    lv_header_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
    APPEND lv_header_guid TO it_guid.
    CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.
    CALL FUNCTION 'CRM_ORDER_INITIALIZE'
      EXPORTING
        iv_initialize_whole_buffer = 'X'
      EXCEPTIONS
        OTHERS                     = 2.
    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
      EXPORTING
        it_partner      = lt_partner
      CHANGING
        ct_input_fields = lt_field.
    IF sy-subrc EQ 0.
      CALL FUNCTION 'CRM_STATUS_UPDATE_DIALOG'.
      lv_header_guid = 'DDCBF5EB8FA58FF19F94001E6849B4E8'.
      APPEND lv_header_guid TO it_guid.
      CALL FUNCTION 'CRM_ORDER_SAVE'
        EXPORTING
          it_objects_to_save = it_guid.
      IF sy-subrc = 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
      ENDIF.
    endif.

  • Crm_order_maintain  . create items.

    hi all.
    i have to update order using fm crm_order_maintian.
    i am able to update header but when i c order using crm_order_read there is no item data  now i have to craete items of header.
    please suggest how to create items  in order using crm_order_maintain....
    Message was edited by:
            gaurav jain

    Hi Gaurav,
    The following the  code i used to add  a product( Item ) to Service order.
    Service Contract Updating while Sales Order Creation
    FUNCTION zzomotc_sc_update.
    *"*"Local Interface:
    *"  IMPORTING
    *"     REFERENCE(IV_GUID) TYPE  CRMT_OBJECT_GUID
    *"  CHANGING
    *"     VALUE(CV_OWN_MESSAGE) TYPE  CRMT_BOOLEAN OPTIONAL
    ***&                             Constants                                             *
      CONSTANTS: c_stparty     TYPE comt_partner_fct VALUE '00000001'.     "Sold-To-Party
    *&                            Internal Tables  Declaration                           *
      DATA:i_orderadm_h        TYPE crmt_orderadm_h_wrkt,
           i_orderadm_i        TYPE crmt_orderadm_i_wrkt,
           i_orderadmsc_i      TYPE crmt_orderadm_i_wrkt,
           i_itemdet           TYPE crmt_orderadm_i_comt,
           i_product_i         TYPE crmt_product_i_wrkt,
           i_sales             TYPE crmt_sales_wrkt,
           i_orgman            TYPE crmt_orgman_wrkt,
           i_shipping          TYPE crmt_shipping_wrkt,
           i_schedlin          TYPE crmt_schedlin_wrkt,
           i_partner           TYPE crmt_partner_external_wrkt,
           i_guid_header       TYPE crmt_object_guid_tab,
           i_status            TYPE crmt_status_wrkt,
           i_text              TYPE crmt_text_wrkt,
           i_billing           TYPE crmt_billing_wrkt,
           i_service_contracts TYPE TABLE OF crmt_portal_resultlist,
           i_customer_h        TYPE crmt_customer_h_wrkt,
           i_customer_i        TYPE crmt_customer_i_wrkt,
           i_input_fields      TYPE crmt_input_field_tab,
           i_sales_sc          TYPE crmt_sales_comt,
           i_field_names       TYPE crmt_input_field_names_tab,
           i_guid_save         TYPE crmt_object_guid_tab.
    *&                 Local structure/Work Area Declaration                             *
      DATA:st_sales            TYPE crmt_sales_wrk,
           st_shipping         TYPE crmt_shipping_wrk,
           st_orderadm_i       TYPE crmt_orderadm_i_wrk,
           st_orderadmsc_i     TYPE crmt_orderadm_i_wrk,
           st_orderadmsc1_i    TYPE crmt_orderadm_i_wrk,
           st_partner          TYPE crmt_partner_external_wrk,
           st_billing          TYPE crmt_billing_wrk,
           st_customer_i       TYPE crmt_customer_i_wrk,
           st_service          TYPE crmt_portal_resultlist,
           st_input_fields     TYPE crmt_input_field,
           st_field_names      TYPE crmt_input_field_names,
           st_itemdet          TYPE crmt_orderadm_i_com.
    *&                         local Variables Declaration                               *
      DATA: l_guid            TYPE crmt_object_guid,
            l_flag            TYPE c VALUE ' ',
            l_partner_fct     TYPE crmt_portal_service_search-partner_fct,
            l_partner_no      TYPE crmt_portal_service_search-bu_partner.
      CHECK iv_guid IS NOT INITIAL.
      COLLECT iv_guid INTO i_guid_header.
      CALL FUNCTION 'CRM_ORDER_READ'
        EXPORTING
          it_header_guid       = i_guid_header
        IMPORTING
          et_orderadm_h        = i_orderadm_h
          et_orderadm_i        = i_orderadm_i
          et_product_i         = i_product_i
          et_customer_h        = i_customer_h
          et_customer_i        = i_customer_i
          et_sales             = i_sales
          et_orgman                = i_orgman
          et_shipping          = i_shipping
          et_billing           = i_billing
          et_schedlin          = i_schedlin
          et_partner           = i_partner
          et_text              = i_text
        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.
      IF sy-subrc <> 0.
    ** SO Order doesn't exists
      ENDIF.
    ***Get partner function as sold-to-party
      DELETE ADJACENT DUPLICATES FROM i_partner.
      READ TABLE i_partner WITH KEY partner_fct = c_stparty  INTO st_partner.
      LOOP AT i_orderadm_i INTO st_orderadm_i.
        IF ( st_orderadm_i-itm_type EQ 'ZTAP' ) OR  ( st_orderadm_i-itm_type EQ 'ZWVN' ) OR
           ( st_orderadm_i-itm_type EQ 'ZCPP' ) OR  ( st_orderadm_i-itm_type EQ 'YWVN' ).
    **    Search a valid Service contract based on customer i.e.sold-to-party and product combination
          l_partner_fct = c_stparty.
          l_partner_no  = st_partner-partner_no.
          CALL FUNCTION 'CRM_SERVICE_CONTRACTS_SEARCH'
            EXPORTING
              partner_function      = l_partner_fct
              partner_number        = l_partner_no
    *          product_id            = st_orderadm_i-ordered_prod
    *          to                    = sy-datum
            TABLES
              service_contract_list = i_service_contracts.
          IF i_service_contracts[] IS NOT INITIAL.
            LOOP AT i_service_contracts INTO st_service WHERE date_end GE sy-datum.
              REFRESH  i_guid_header.
              COLLECT st_service-guid INTO  i_guid_header.
              CALL FUNCTION 'CRM_ORDER_READ'
                EXPORTING
                  it_header_guid       = i_guid_header
                IMPORTING
                  et_orderadm_i        = i_orderadmsc_i
                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 i_orderadmsc_i INTO st_orderadmsc_i
                  WITH KEY ordered_prod = st_orderadm_i-ordered_prod.
              IF sy-subrc EQ 0.
                l_flag = 'X'.
                l_guid = st_service-guid.
                EXIT.
              ENDIF.
            ENDLOOP.
    ****    Deactivate the line item of existing service contract and add new service item to this contract
            IF  l_flag EQ 'X'.
              REFRESH : i_guid_header, i_orderadm_h, i_orderadmsc_i.
              COLLECT l_guid INTO  i_guid_header.
              CALL FUNCTION 'CRM_ORDER_READ'
                EXPORTING
                  it_header_guid       = i_guid_header
                IMPORTING
                  et_orderadm_h        = i_orderadm_h
                  et_orderadm_i        = i_orderadmsc_i
    *              et_pricing_i         = i_pricing_i
                  et_status            = i_status
                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 i_orderadmsc_i INTO st_orderadmsc_i INDEX sy-tabix.
              st_input_fields-ref_guid     = st_orderadmsc_i-guid.
              st_input_fields-ref_kind     = 'B'.
              st_input_fields-objectname   = 'ORDERADM_I'.
              st_field_names-fieldname     = 'MODE'.
              APPEND st_field_names TO i_field_names.
              st_field_names-fieldname     = 'ORDERED_PROD'.
              APPEND st_field_names TO i_field_names.
              st_input_fields-field_names   = i_field_names.
              APPEND st_input_fields TO i_input_fields.
              REFRESH i_field_names.
              st_input_fields-ref_guid     = st_orderadmsc_i-guid.
              st_input_fields-ref_kind     = 'B'.
              st_input_fields-objectname   = 'PRODUCT_I'.
              st_field_names-fieldname     = 'PROCESS_QTY_UNIT'.
              APPEND st_field_names TO i_field_names.
              st_input_fields-field_names   = i_field_names.
              APPEND st_input_fields TO i_input_fields.
              REFRESH i_field_names.
              st_input_fields-ref_guid     = st_orderadmsc_i-guid.
              st_input_fields-ref_kind     = 'B'.
              st_input_fields-objectname   = 'SCHEDLIN'.
              st_field_names-fieldname     = 'QUANTITY'.
              APPEND st_field_names TO i_field_names.
              st_input_fields-field_names   = i_field_names.
              APPEND st_input_fields TO i_input_fields.
              REFRESH i_field_names.
              MOVE-CORRESPONDING st_orderadmsc_i TO st_itemdet.
    *          st_orderadmsc1_i-header       =  st_orderadmsc_i-header.
    *          st_orderadmsc1_i-ordered_prod =  st_orderadm_i-ordered_prod.
              APPEND  st_itemdet TO i_itemdet.
              CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    *            EXPORTING
    **              it_pricing_i      = i_pricing_i
    *              it_product_i      = i_product_i
    *              it_schedlin_i     = i_schedlin_i
                CHANGING
                  ct_orderadm_i     = i_itemdet
                  ct_input_fields   = i_input_fields
                EXCEPTIONS
                  error_occurred    = 1
                  document_locked   = 2
                  no_change_allowed = 3
                  no_authority      = 4
                  OTHERS            = 5.
              IF sy-subrc EQ 0.
                COLLECT l_guid INTO i_guid_save.
                CALL FUNCTION 'CRM_ORDER_SAVE'
                  EXPORTING
                    it_objects_to_save = i_guid_save
                  EXCEPTIONS
                    document_not_saved = 1
                    OTHERS             = 2.
                CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
                REFRESH i_guid_save.
                l_flag = 'X'.
              ENDIF.
            ELSE.
              REFRESH: i_guid_header, i_orderadmsc_i.
              READ TABLE  i_service_contracts INTO st_service INDEX 1.
              COLLECT st_service-guid INTO  i_guid_header.
              CALL FUNCTION 'CRM_ORDER_READ'
                EXPORTING
                  it_header_guid       = i_guid_header
                IMPORTING
                  et_orderadm_h        = i_orderadm_h
                  et_orderadm_i        = i_orderadmsc_i
    *              et_pricing_i         = i_pricing_i
                  et_status            = i_status
                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 i_orderadmsc_i INTO st_orderadmsc_i INDEX sy-tabix.
              st_input_fields-ref_guid     = st_orderadmsc_i-guid.
              st_input_fields-ref_kind     = 'B'.
              st_input_fields-objectname   = 'ORDERADM_I'.
              st_field_names-fieldname     = 'MODE'.
              APPEND st_field_names TO i_field_names.
              st_field_names-fieldname     = 'ORDERED_PROD'.
              APPEND st_field_names TO i_field_names.
              st_input_fields-field_names   = i_field_names.
              APPEND st_input_fields TO i_input_fields.
              REFRESH i_field_names.
              st_input_fields-ref_guid     = st_orderadmsc_i-guid.
              st_input_fields-ref_kind     = 'B'.
              st_input_fields-objectname   = 'PRODUCT_I'.
              st_field_names-fieldname     = 'PROCESS_QTY_UNIT'.
              APPEND st_field_names TO i_field_names.
              st_input_fields-field_names   = i_field_names.
              APPEND st_input_fields TO i_input_fields.
              REFRESH i_field_names.
              st_input_fields-ref_guid     = st_orderadmsc_i-guid.
              st_input_fields-ref_kind     = 'B'.
              st_input_fields-objectname   = 'SCHEDLIN'.
              st_field_names-fieldname     = 'QUANTITY'.
              APPEND st_field_names TO i_field_names.
              st_input_fields-field_names   = i_field_names.
              APPEND st_input_fields TO i_input_fields.
              REFRESH i_field_names.
              st_orderadmsc1_i-header       =  st_orderadmsc_i-header.
              st_orderadmsc1_i-ordered_prod =  st_orderadm_i-ordered_prod.
              APPEND  st_orderadmsc1_i TO i_orderadmsc_i.
              MOVE-CORRESPONDING st_orderadmsc1_i TO st_itemdet.
              APPEND  st_itemdet TO i_itemdet.
              CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    *            EXPORTING
    **              it_pricing_i      = i_pricing_i
    *              it_product_i      = i_product_i
    *              it_schedlin_i     = i_schedlin_i
                CHANGING
                  ct_orderadm_i     = i_itemdet
                  ct_input_fields   = i_input_fields
                EXCEPTIONS
                  error_occurred    = 1
                  document_locked   = 2
                  no_change_allowed = 3
                  no_authority      = 4
                  OTHERS            = 5.
              IF sy-subrc EQ 0.
                COLLECT st_service-guid INTO i_guid_save.
                CALL FUNCTION 'CRM_ORDER_SAVE'
                  EXPORTING
                    it_objects_to_save = i_guid_save
                  EXCEPTIONS
                    document_not_saved = 1
                    OTHERS             = 2.
                CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
                REFRESH i_guid_save.
                l_flag = 'X'.
              ENDIF.
            ENDIF.
          ELSE.
    *** Create a new service contract for it and add line item to it.
            DATA: st_servicec_h TYPE crmt_iservice_baskethead_il,
                  st_servicec_i TYPE crmt_srv_webreq_item_il ,
                  st_screate_h  TYPE crmt_orderadm_h_com,
                  st_screate_i  TYPE crmt_orderadm_i_com.
            READ TABLE i_partner INTO st_partner WITH KEY partner_fct  =  '00000001'.
            st_servicec_h-handle          = '00001'.
            st_servicec_h-ref_handle      = '00001'.
            st_servicec_h-process_type    = 'ZSC'.
            st_servicec_h-description     = 'Service Contract'.
            st_servicec_h-descr_language  = 'E'.
            st_servicec_i-handle       = '00002'.
            st_servicec_i-ref_handle   = '00001'.
    *          st_servicec_i-ITM_TYPE     =
            st_servicec_i-ordered_prod = st_orderadm_i-ordered_prod.
    *          st_servicec_i-ORDER_QTY    =
    *        st_servicec_i-QTY_UNIT     =
            CALL FUNCTION 'CRM_SERVICE_ORDER_CREATE'
              EXPORTING
                is_service_baskethead  = st_servicec_h
                is_service_basketitem  = st_servicec_i
                iv_service_productguid = st_orderadm_i-product
                iv_partner_ag          = st_partner-partner_no
                iv_partn_fct_ag        = '00000001'
              IMPORTING
                es_orderadm_h          = st_screate_h
                es_orderadm_i          = st_screate_i
              EXCEPTIONS
                error_occured          = 1
                OTHERS                 = 2.
            IF sy-subrc EQ 0.
              COLLECT st_screate_h-guid INTO i_guid_save.
              CALL FUNCTION 'CRM_ORDER_SAVE'
                EXPORTING
                  it_objects_to_save = i_guid_save
                EXCEPTIONS
                  document_not_saved = 1
                  OTHERS             = 2.
              CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
              REFRESH i_guid_save.
              l_flag = 'X'.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDFUNCTION.
    Actually, this FM was created for updating the service contract while creation of sales order with serivce product as its line item. It search for valid SC for sold-to-Party and checks for the products if not there adds the same product as line item to SC. If SC not avaliable , Creates SC and adds the same product
    Hope it will help you.
    Regards,
    Arjun
    <b>Pl. Reward points</b>

  • Need to Create Line Items through CRM_ORDER_MAINTAIN

    Hi all,
    I need code for creating Line Items with product and Quantity through CRM_ORDER_MAINTAIN,
    I am able to create header and the partner data through CRM_ORDER_MAINTAIN.
    Suggest the solution.

    Since you have already used the function module CRM_ORDER_MAINTAIN for partners, it shouldn't be difficult for you to use it for more sets of data. Well, the idea is to know what is required to be filled in the input fields and keys. There is a report program CRM_ORDER_READ. Use this with an existing transaction that contains the type of data you want to know about. You will get lot of insight into the data required to for any set of data.
    Also, see this thread for some sample code
    Set item, partner data of sales order using BAPI_BUSPROCESSND_CREATEMULTI

Maybe you are looking for