cancel
Showing results for 
Search instead for 
Did you mean: 

How to add / Change pricing condition for item in SAP CRM

Former Member
0 Kudos

Hi Experts,

I am facing problem in adding pricing condition at item level. Tried all the ways to add. gone through previous threads but no help.

I have used the CRM_ORDER_MAINTAIN.. The transaction is saved but the pricing condition is not added to the item.

The pricing condition manual entries option is "Not possible to process manually".  Is this condition possible to add through CRM_ORDER_MAINTAIN?

Below is the code. Please let me know what i'm missing.

ls_cond_add-KSCHL = 'ZP30'.
*ls_cond_add-WAERS = '%'.
ls_cond_add-KBETR = lv_kbetr.
*ls_cond_add-KPEIN = ''.
*ls_cond_add-KMEIN = ''.
*ls_cond_add-KBETR_INITIAL = ''.
ls_cond_add-KWERT = lv_kbetr.
*ls_cond_add-KWERT_INITIAL = 'X'.
ls_cond_add-KRECH = 'B'.
*ls_cond_add-KWAEH = ''.
ls_cond_add-KNUMH = lv_item.
*ls_cond_add-KOTABNR = ''.
ls_cond_add-KAWRT = lv_kbe_B.
*ls_cond_add-KAWRT_INITIAL = 'X'.
*ls_cond_add-KRUEK = ''.

APPEND ls_cond_add to lt_cond_add.
CLEAR ls_cond_Add.

ls_pricom-ref_guid = lv_item.
ls_pricom-ref_KIND = 'B'.
*ls_pricom-PRICING_PROCEDURE = 'ZBRPRD'.
ls_pricom-cond_Add[] = lt_cond_add.

ls_input-ref_guid   = lv_item.
ls_input-ref_kind   = 'B'.
ls_input-objectname = 'PRIDOC'.


ls_input_fn-fieldname = 'REF_GUID'.
INSERT ls_input_fn INTO TABLE ls_input-field_names.
ls_input_fn-fieldname = 'REF_KIND'.
INSERT ls_input_fn INTO TABLE ls_input-field_names.
*ls_input_fn-fieldname = 'REF_KIND'.
*INSERT ls_input_fn INTO TABLE ls_input-field_names.

ls_input_fn-fieldname = 'KRECH'.
INSERT ls_input_fn INTO TABLE ls_input-field_names.
ls_input_fn-fieldname = 'KNUMH'.
INSERT ls_input_fn INTO TABLE ls_input-field_names.
ls_input_fn-fieldname = 'KSCHL'.
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.
ls_input_fn-fieldname = 'KAWRT'.
INSERT ls_input_fn INTO TABLE ls_input-field_names.

ls_input_fn-fieldname = 'KWERT'.
INSERT ls_input_fn INTO TABLE ls_input-field_names.
INSERT ls_input INTO TABLE lt_input.

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.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
           .


ELSE.
   ROLLBACK WORK.
ENDIF.

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member182606
Participant
0 Kudos

Hi Guys,

Refer the below link it has lots of code reference for this issue.

Regards,

Chella.

0 Kudos

Hello Krishna,

it is possible to the so, i have been able to do it using the following code, it might be useful to you:

in my case i was copying pricing condition from one document to another, you can adapt it in your scenario.


TYPES: BEGIN OF ts_prcc_cond_ct,
kschl
TYPE prcc_cond_ct-kschl,
kkopf
TYPE prcc_cond_ct-kkopf,
kposi
TYPE prcc_cond_ct-kposi,
END OF ts_prcc_cond_ct.



DATA ld_pd_handle_src     TYPE prct_handle,
ld_pd_handle_dest   
TYPE prct_handle,
ld_guid_pridoc      
TYPE prct_cond_print-knumv,
lt_komv_print_src   
TYPE prct_cond_print_t,
lt_komv_print_dest  
TYPE prct_cond_print_t,
lt_komv_tmp_src     
TYPE prct_cond_print_t
lt_prcc_cond_ct     
TYPE STANDARD TABLE OF ts_prcc_cond_ct
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_item_ret         
TYPE prct_item_ret_t,
ld_ajout_cond       
TYPE abap_bool,
lt_cond_chg_insert  
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.

FIELD-SYMBOLS: <fs_cond_chg_insert>  TYPE prct_cond_print,
<fs_orderadm_i_dest> 
TYPE crmt_orderadm_i_wrk,
<fs_cond_chg>        
TYPE prct_cond_print.

** 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_dest INTO ls_komv_print_dest .

CLEAR: ls_cond_chg,
ls_komv_print_src
.


*    "proceed only if the condition is at header level only
*    "if condition is at both header and item level, it is being copied in the perfom f_item_copy_pricing


IF ld_guid_pridoc IS INITIAL.
ld_guid_pridoc
= ls_komv_print_dest-knumv.
ENDIF.

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.

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.

ls_cond_chg
-waers     = ls_komv_print_src-waers.
ls_cond_chg
-waerk     = ls_komv_print_src-waerk.
ls_cond_chg
-koein     = ls_komv_print_src-koein.
ls_cond_chg
-koei1     = ls_komv_print_src-koei1.

ENDIF.

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.

CLEAR ls_cond_chg-krech.
INSERT ls_cond_chg INTO TABLE lt_cond_chg.
CLEAR ls_cond_chg.

ENDLOOP.


*Ajout des nouveaux conditions de prix

LOOP AT lt_komv_print_src INTO ls_komv_print_src WHERE kschl IS NOT INITIAL.

CLEAR: ls_cond_chg, ls_komv_print_dest,ld_ajout_cond.

*     Vérifier la présence de la condition sur le document destinataire
READ TABLE lt_komv_print_dest TRANSPORTING NO FIELDS WITH KEY kschl = ls_komv_print_src-kschl.

IF sy-subrc EQ 0.

CLEAR: ls_cond_chg, ls_komv_print_dest.
CONTINUE.

ELSE.

ld_ajout_cond
= abap_true.
MOVE-CORRESPONDING ls_komv_print_src TO ls_cond_chg.
ls_cond_chg
-knumv     = ld_guid_pridoc.

ls_cond_chg
-kposn     = ls_komv_print_src-kposn.
*  stunr will be differant in destination, so let SAP determine in creation

CLEAR ls_cond_chg-stunr.

CLEAR ls_cond_chg-krech.

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.


"Proceed with header copy of pricing conditions
CHECK lt_cond_chg IS NOT INITIAL.

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.


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

<fs_cond_chg>
-waers     = <fs_cond_chg_insert>-waers.
<fs_cond_chg>
-waerk     = <fs_cond_chg_insert>-waerk.
<fs_cond_chg>
-koein     = <fs_cond_chg_insert>-koein.
<fs_cond_chg>
-koei1     = <fs_cond_chg_insert>-koei1.

ENDIF.

ENDLOOP.

REFRESH lt_cond_ret[].

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.


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


kavindra_joshi
Active Contributor
0 Kudos

Did this work ? I am curious

~Kavindra

former_member182421
Active Contributor
0 Kudos

If no one change the configuration, I would be highly surprised

devashish_bhattacharya
Active Participant
0 Kudos

Hi Krishna,

Did you try using function CRM_PRIDOC_MAINTAIN_MUL_OW?

This needs to be used whenever we need to do some pricing condition changes.

Hope it helps.

Regards,

Devashish

krishnendu_laha
Active Contributor
0 Kudos

Hello Krishna,

In my knowledge price is maintained in ECC system which is replicated to CRM so it is not possible to change anything in CRM

2nd thing if price condition is not for manual change it can not be changed through crm*order*main* FM as price should come through configuration.

Thanks,

Krish

Former Member
0 Kudos

Hi Krishnendu,

Thanks for the reply.

I am able to add a pricing condition with (No restrictions) using CRM_ORDER_MAINTAIN, but the same code is not working for price condition with "Not possible to process manually".


I have no idea what could be the reason. How can we add these price conditions through code?

My requirement is based on some condition ( z field value ). This pricing condition should be added to item.

Please let me know if there is any other way to add this type of pricing condition.

Regards

Krishna

kavindra_joshi
Active Contributor
0 Kudos

Hi Krishna ,

Create a order manually in WebUI or CRMD_ORDER and then try to change the pricing condition. If you are able to do so , then you can change the condition through the program as well , if not then check the customizing of the pricing condition. Check if the field Manual Entry is ticked for it or not ?

~Kavindra

Former Member
0 Kudos

Hi Kavindra,

Thanks for the reply

The the manual enrty is not possible for this pricing condition as its of type "Not possible to process manually".

But there are other pricing conditions already added to item which are of same type. I want this new pricing condition to be added along with them. But I am unable to figure out how the other pricing conditions of type (Not possible to process manually) are added.

Please let me know if there is any other way.

Regards

Krishna

kavindra_joshi
Active Contributor
0 Kudos

Hi Krishna ,

It is not possible to add pricing conditions at the item/header level if they are not manual pricing conditions. If you have being given this as a requirement this is a flawed requirement.

You have to understand how a pricing condition is getting determined in a document. It may be possible that you can change a parameter based on which it would get triggered. Go to the pricing procedure and check the requirement formula and then check the same in the pricing trace it should be fulfilled ( b/w 600-999 is the custom formula implemented) and calculation value formula and then check the same in the pricing trace it should be fulfilled ( b/w 600-999 is the value formula implemented ).

Regards,

Kavindra

Former Member
0 Kudos

Hi Kavindra,

Thanks for the info..

So we cannot add pricing conditions of type "Not possible to process manually".

but Is it possible to change the already existing pricing record of type  "Not possible to process manually".

I have couple of pricing conditions of type Not possible to process manually, i want to change one of them through code.



Please let me know the way if any.


Regards

Krishna

kavindra_joshi
Active Contributor
0 Kudos

"Not possible to process manually" means you can't change it manually. Plain and simple. Only way to change it is to change the document and make relevant changes to the document so that the pricing is re triggered and your condition appears.