cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a header pricing condition type in CRM Quotation

Former Member
0 Kudos

Dear Experts,

   I have a requirement to add a new condition type by taking average of the item conditions when a quotation is created. I tried achieving it using CRMV_EVENT call back routine with the help of function modules " CRM_ORDER_MAINTAIN , CRM_ORDER_MAINTAIN_MULTIPLE_OW and even pricing function module CRM_PRIDOC_MAINTAIN_MUL_OW ". But nothing seems working and i got the below error after using the order maintain and multiple_ow function modules.

It failed saying "Recursive call of function module 'CRM_ORDER_MAINTAIN'".

How to go ahead in achieving this?? Also I need to update the same PRICING COND type with the new value whenever a quotation is changed.

Do I need to use ORDER_SAVE badi to achieve this. if yes in which BADI methods (PREPARE, CHANGE_BEFORE_UPDATE, CHECK_BEFORE_SAVE ) should i try this one?? I have pasted my code below. Please advice me on this one.

  DATA: IT_HEADER_GUID TYPE CRMT_OBJECT_GUID_TAB,

          IT_PRIDOC TYPE CRMT_PRIC_COND_T,

          WA_PRIDOC LIKE LINE OF IT_PRIDOC,

          IT_PRIC_COND TYPE PRCT_COND_DU_TAB,

          WA_PRIC_COND LIKE LINE OF IT_PRIC_COND,

          LV_COUNT TYPE I,

          LV_KBETR TYPE KBETR.

    CLEAR: IT_HEADER_GUID, IT_PRIDOC[], LV_COUNT, LV_KBETR.

    APPEND LV_GUID TO IT_HEADER_GUID.

*Read the Pricing Document Conditions FROM CRM_ORDER_READ

*USING EXPORT PARAMETER ET_PRIDOC

 

    CALL FUNCTION 'CRM_ORDER_READ'

      EXPORTING

        IT_HEADER_GUID       = IT_HEADER_GUID

      IMPORTING

        ET_PRIDOC            = IT_PRIDOC

      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.

* Implement suitable error handling here

    ENDIF.

    LOOP AT IT_PRIDOC INTO WA_PRIDOC.

      LOOP AT WA_PRIDOC-PRIC_COND INTO WA_PRIC_COND

              WHERE KSCHL = 'YAMP' AND

                    KBETR IS NOT INITIAL.

        LV_KBETR = LV_KBETR + WA_PRIC_COND-KBETR.

        LV_COUNT = LV_COUNT + 1.

       ENDLOOP.

    ENDLOOP.

*Calculating the Average Mark up 'ZAMP' From YAMP item conditions

  LV_KBETR = LV_KBETR / LV_COUNT.

  data: IT_PRI_DOC   type CRMT_PRIDOC_COMT,

        ls_cond_h   type CRMT_PRIDOC_COM,

        IT_COND_ADD   type PRCT_COND_EXTERNAL_INPUT_T,

        WA_COND_ADD LIKE LINE OF IT_COND_ADD,

        lt_input_fields type CRMT_INPUT_FIELD_TAB,

        ls_input_fields type CRMT_INPUT_FIELD,

        IT_SAVED_OBJ TYPE CRMT_RETURN_OBJECTS,

        IT_HEAD TYPE CRMT_ORDERADM_H_COMT,

        WA_HEAD TYPE LINE OF CRMT_ORDERADM_H_COMT,

        IT_FIELD_NAMES TYPE crmt_input_field_names_tab,

        WA_FIELD_NAMES TYPE crmt_input_field_names.

*Populate new condition rate

   CLEAR: ls_cond_h, WA_COND_ADD, LS_COND_H-COND_ADD,

         IT_PRI_DOC[].

  ls_cond_h-ref_guid = LV_GUID.

  ls_cond_h-ref_kind = 'A'.

  WA_COND_ADD-kschl = 'ZAMP'.

  WA_COND_ADD-KBETR = LV_KBETR.

  INSERT WA_COND_ADD INTO TABLE  LS_COND_H-COND_ADD.

  INSERT LS_COND_H INTO TABLE  IT_PRI_DOC.

  REFRESH LT_INPUT_FIELDS.

  CLEAR: LS_INPUT_FIELDS, LS_INPUT_FIELDS-FIELD_NAMES,

         WA_FIELD_NAMES, IT_FIELD_NAMES[].

  WA_FIELD_NAMES-FIELDNAME = 'KSCHL'.

  INSERT WA_FIELD_NAMES INTO TABLE IT_FIELD_NAMES.

  LS_INPUT_FIELDS-REF_GUID = LV_GUID.

  LS_INPUT_FIELDS-REF_KIND = 'A'.

  LS_INPUT_FIELDS-OBJECTNAME = 'PRIDOC'.

  LS_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

  INSERT LS_INPUT_FIELDS INTO TABLE LT_INPUT_FIELDS.

  CLEAR: WA_HEAD, IT_HEAD[].

  WA_HEAD-GUID = LV_GUID.

  WA_HEAD-OBJECT_ID = LV_OBJECT_ID.

  WA_HEAD-PROCESS_TYPE = LV_PROCESS_TYPE.

  APPEND WA_HEAD TO IT_HEAD.

*  CALL FUNCTION 'CRM_ORDER_MAINTAIN'

*   EXPORTING

*      IT_PRIDOC         = IT_PRI_DOC

**    IMPORTING

**      ET_EXCEPTION      = GT_EXCEPTION

*    CHANGING

*      CT_ORDERADM_H     = IT_HEAD

*      CT_INPUT_FIELDS   = LT_INPUT_FIELDS

**      CV_LOG_HANDLE     = LV_LOGHNDL

*    EXCEPTIONS

*      ERROR_OCCURRED    = 1

*      DOCUMENT_LOCKED   = 2

*      NO_CHANGE_ALLOWED = 3

*      NO_AUTHORITY      = 4

*      OTHERS            = 5.

*

*  CALL FUNCTION 'CRM_ORDER_SAVE'

*    EXPORTING

*     IT_OBJECTS_TO_SAVE         = IT_HEADER_GUID

*   IMPORTING

*     ET_SAVED_OBJECTS           = IT_SAVED_OBJ

*   EXCEPTIONS

*     DOCUMENT_NOT_SAVED         = 1

*     OTHERS                     = 2

*            .

*  IF SY-SUBRC <> 0.

** Implement suitable error handling here

*  ENDIF.

*

*  COMMIT WORK.

*CALL FUNCTION 'CRM_ORDER_MAINTAIN_MULTIPLE_OW'

*  EXPORTING

*   IT_PRIDOC                     = IT_PRI_DOC

*   IV_COLLECT_EXCEPTIONS         = 'X'

** IMPORTING

**   ET_EXCEPTION                  =

*  CHANGING

*    CT_ORDERADM_H                 = IT_HEAD

**   CT_ORDERADM_I                 =

*    CT_INPUT_FIELDS               = LT_INPUT_FIELDS

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

          .

   DATA: IT_TRUST TYPE CRMT_GUID_HANDLE_TAB,

         WA_TRUST TYPE LINE OF CRMT_GUID_HANDLE_TAB.

   CLEAR: WA_TRUST, IT_TRUST[].

   WA_TRUST-GUID = LV_GUID.

   INSERT WA_TRUST INTO TABLE IT_TRUST.

   CALL FUNCTION 'CRM_PRIDOC_MAINTAIN_MUL_OW'

     EXPORTING

       IT_TRUSTED_ITEMS       = IT_TRUST

       IT_PRIDOC              = IT_PRI_DOC

*    EXCEPTIONS

*      ERROR_OCCURRED         = 1

*      OTHERS                 = 2

             .

   IF SY-SUBRC <> 0.

* Implement suitable error handling here

   ENDIF.

Thank and Regards,

Arun V.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Arun,

I hope you found a solution to this problem as it is very old..Could you please post the solution here..

I have similar requirement of adding pricing condition at Item level and changing the same condition based on some checks.

Appreciate your help..

Regards

Krishna

kakshat
Advisor
Advisor
0 Kudos

Hi Arun,

Did you already check my response on this thread - http://scn.sap.com/thread/3329314?

I think CRM_PRIDOC_MAINTAIN_MUL_OW should do the trick for you.

Regards,

Akshat

Former Member
0 Kudos

Hi Kumar,

Yes i have checked it. I need to add the pricing condition in the header level. I couldnt get a clarity in the SDN on this. I'm not sure if i use the func mod u have specified, will it add in the header level?? So could you please confirm me the exact object should i use in CT_INPUT_FIELDS.

     ls_cond_h-ref_guid = LV_GUID.

     ls_cond_h-ref_kind = 'A'.

     WA_COND_ADD-kschl = 'ZAMP'.

     WA_COND_ADD-KBETR = LV_KBETR.

     INSERT WA_COND_ADD INTO TABLE  LS_COND_H-COND_ADD.

     INSERT LS_COND_H INTO TABLE  IT_PRI_DOC.

     REFRESH LT_INPUT_FIELDS.

     CLEAR: LS_INPUT_FIELDS, LS_INPUT_FIELDS-FIELD_NAMES,

            WA_FIELD_NAMES, IT_FIELD_NAMES[].

     WA_FIELD_NAMES-FIELDNAME = 'KSCHL'.

     WA_FIELD_NAMES-CHANGEABLE = 'X'.

     INSERT WA_FIELD_NAMES INTO TABLE IT_FIELD_NAMES.

     CLEAR: WA_FIELD_NAMES.

     WA_FIELD_NAMES-FIELDNAME = 'KBETR'.

     WA_FIELD_NAMES-CHANGEABLE = 'X'.

     INSERT WA_FIELD_NAMES INTO TABLE IT_FIELD_NAMES.

     LS_INPUT_FIELDS-REF_GUID = LV_GUID.

     LS_INPUT_FIELDS-REF_HANDLE = 0000000001.

     LS_INPUT_FIELDS-REF_KIND = 'A'.

     LS_INPUT_FIELDS-OBJECTNAME = 'PRIDOC'." IS this correct???

      INSERT LS_INPUT_FIELDS INTO TABLE LT_INPUT_FIELDS.

     CLEAR: WA_PARTNER.

     WA_PARTNER-REF_GUID = LV_GUID.

      WA_PARTNER-REF_KIND = 'A'.

     INSERT WA_PARTNER INTO TABLE IT_PARTNER.

     CLEAR: WA_HEAD, IT_HEAD[].

     WA_HEAD-GUID = LV_GUID.

     WA_HEAD-OBJECT_ID = LV_OBJECT_ID.

     WA_HEAD-PROCESS_TYPE = LV_PROCESS_TYPE.

     APPEND WA_HEAD TO IT_HEAD.

Thanks and Regards,

Arun V.

kakshat
Advisor
Advisor
0 Kudos

I think it should work for header level as well. I think all you should need to do is pass the header GUID wherever the item GUID is being passed. In the code I posted, I don't see the INPUT_FIELDS table being passed to the *PRIDOC_MAINTAIN* FM. So, maybe it's not even required.

To check whether the object name you've used is a valid one in CRM or not, you can check the entries in table CRMC_OBJECTS.

Former Member
0 Kudos

Ok Kumar....I will do the changes and update u mate....Cheers...

Thanks for your reply

Former Member
0 Kudos

Hi Arun,

I am a CRM functional consultant. Just implemented simmliar requirement by the same way.

You should call the following function.

    CALL FUNCTION 'CRM_PRIDOC_MAINTAIN_MUL_OW'
      EXPORTING
        IT_TRUSTED_ITEMS = LT_GUID_HANDLE
        IT_PRIDOC        = LTM_PRIDOC_COMT
      EXCEPTIONS
        ERROR_OCCURRED   = 1
        OTHERS           = 2.

Liu Bo