Quantcast
Viewing all articles
Browse latest Browse all 7775

Adding a header pricing condition type in CRM Quotation

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.


Viewing all articles
Browse latest Browse all 7775

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>