cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to Add/Create a Pricing Condition for a specific Item in an Order

Former Member
0 Kudos
3,004

I'm relatively new to CRM ABAP and am looking for a way to add a line to the pricing conditions table for a specific item.
In the CRM_UI for a service order quotation, in a line item, under the pricing details tab you see a list like this:

And to add a new “Detail” you can select the “add” button and pick one from this list:

I want to add both these items to my list of pricing details for this line item, but I want to do it through ABAP.


I’ve done a lot of work with CRM_ORDER_MAINTAIN, but when I put a break point in there to see what fields were populated I found that the et_pridoc table was empty – so where were these details added? Using what FM call?


I’ve tried to do the update using crm_order_maintain anyway (as this seems logial to me!) using this code (ev_item_guid is the guid of the line item that I want this pricing for):

  data: lt_pridoc type  crmt_pridoc_comt
        ,ls_pridoc type  crmt_pridoc_com
        ,lt_pric_cond type prct_cond_du_tab
        ,ls_pric_cond type prct_cond_du.


*      ls_pric_cond-knumv = ? I don’t know the document number...
    ls_pric_cond-kposn = ev_item_guid.
    ls_pric_cond-kschl = 'ZMDP'.
    ls_pric_cond-kbetr = ‘59’.
    ls_pric_cond-kmein = 'PC'.
    append ls_pric_cond to lt_pric_cond.

    ls_pridoc-ref_handle = ref_handle.
    ls_pridoc-PRIC_COND = lt_pric_cond.
    append ls_pridoc to lt_pridoc.

*    ls_nametab = 'KBETR'.
*    append ls_nametab to lt_nametab.
*    ls_nametab = 'KMEIN'.
*    append ls_nametab to lt_nametab.
*    ls_nametab = 'KSCHL'.
*    append ls_nametab to lt_nametab.

    ls_input_fields-ref_handle = ref_handle. "But there's no ref handle in the pri-doc table..
    ls_input_fields-ref_kind = 'A'. "Is this correct??
    ls_input_fields-objectname = 'PRIDOC'.
*    ls_input_fields-field_names = lt_nametab.
    append ls_input_fields to lt_input_fields.

Then I’d call the crm_order_maintain.

But is it possible to do it this way?
What would I populate the field_names table with? (If anything?)

The Results should look like this (from crm_order_read - in et_pridoc-pric_cond):


If not, what FM/BAPI should I be using?

Any advice anyone can give me on populating values in this pricing table will be rewarded with points!

Please help - many answers I've found online don't help!

View Entire Topic
Former Member
0 Kudos

Hi Lindsay Stanger,

I am also facing the same problem as you have.

Have to get the answer for this ? If yes please suggest me how you rectified this.

Thanks and Regards

Mani

Former Member
0 Kudos

In the end this is the code I used to create a new pricing condition:

Signature:

IV_HDR_GUID TYPE CRMT_OBJECT_GUID

IV_ITEM_GUID TYPE CRMT_OBJECT_GUID

IV_KSCHL TYPE PRCT_COND_TYPE

IV_KBETR TYPE PRCT_COND_RATE

VALUE( RV_SUCCESS ) TYPE CRMT_BOOLEAN

method PRC_COND_CREATE.
  include crm_mode_con.

  data lv_pd_handle type prct_handle.
  data lt_komv_print type prct_cond_print_t.
  data ls_komv_print like line of lt_komv_print.
  data lt_cond_chg type prct_cond_external_change_t.
  data ls_cond_chg like line of lt_cond_chg.
  data lt_item_ret type prct_item_ret_t.
  data lt_cond_ret type prct_cond_print_t.
  data lv_data_changed type xfeld.

  rv_success = abap_false.

  "1 Get pricing handle
  call function 'CRM_PRIDOC_GET_HANDLE_OW'
    exporting
      iv_header_guid             = iv_hdr_guid
    importing
      ev_pd_handle               = lv_pd_handle
    exceptions
      error_occurred             = 1
      handle_determination_error = 2
      orgdata_error              = 3
      others                     = 4.

  if sy-subrc <> 0.
    return.
  endif.

  "2 Read pricing document
  call function 'PRC_PD_ITEM_SHOW'
    exporting
      iv_pd_handle        = lv_pd_handle
      iv_item_no          = iv_item_guid
    importing
      et_komv_print       = lt_komv_print
    exceptions
      non_existing_handle = 1
      non_existing_item   = 2
      ipc_error           = 3
      others              = 4.

  "3 Look for the condition type
  read table lt_komv_print into ls_komv_print
                           with key kschl = iv_kschl.
  if sy-subrc <> 0.
    return.
  endif.

  "4 Change condition type
  clear ls_cond_chg.
  move-corresponding ls_komv_print to ls_cond_chg.
  ls_cond_chg-kbetr = iv_kbetr.

  ls_cond_chg-kwert = iv_kbetr * 10.

  insert ls_cond_chg into table lt_cond_chg.

  call function 'PRC_PD_ITEM_CHANGE_COND'
    exporting
      iv_pd_handle        = lv_pd_handle
      iv_item_no          = iv_item_guid
      it_cond_change      = lt_cond_chg
    importing
      et_item_ret         = lt_item_ret
      et_cond_prt         = lt_cond_ret
      ev_data_changed     = lv_data_changed
    exceptions
      non_existing_handle = 1
      non_existing_item   = 2
      ipc_error           = 3
      not_allowed         = 4
      others              = 5.

  if sy-subrc = 0.
    rv_success = abap_true.
    return.
  endif.

endmethod.

***************************

Followed by a commit.

I hope this helps.

Former Member
0 Kudos

Thanks Lindsay Stranger..Thanks for your valuable information.

It's working...

Thanks & Regards

Mani

Former Member
0 Kudos

Hi Landsay,

Please help me, I have a similar issue i. e add a condition type in the pricing tab.

I am able to create new pricing condition type by using your code mentioned above but problem is that price is not updating in the item level And i used followed by commit also.

Please find the attachment for your reference.

Please help me out, Thanks in advance.

Thanks and Regards,

Santosh.

uday_sunkara3
Explorer
0 Kudos

its working

thanks a lot

Former Member
0 Kudos

Hello Santosh,

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.

  1. " 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'    EXPORTINGiv_header_guid             = pd_guid_src    IMPORTINGev_pd_handle               = ld_pd_handle_src    EXCEPTIONSerror_occurred             = 1handle_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      IMPORTINGet_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-kschlzaehk = 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-kschlzaehk = 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.

  1. " 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_falseCHANGING sy-subrc          lv_already_locked          lt_locked_contract.

  1. " F_LOCK_DOCUMENT

* Fin Ajout CD1K904074-001*FORM f_header_copy_pricing  USING   pd_guid_srcpd_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    IMPORTINGet_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-kschlzaehk = 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.

  1. 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.

nagarajan_ramudu
Active Participant
0 Kudos

I got the IPC error.

Can you please help me?

Former Member
0 Kudos

Please can you exapnd on this? Which code did you use/run and what was the exact error message?

Please could you include screen shots so it is easier for me to try to help?

Thanks,

Lindsay