Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_CUSTOMERQUOTATION_CHANGE

Former Member
0 Kudos

Hi Guru's,

I am using BAPI BAPI_CUSTOMERQUOTATION_CHANGE to change pricing condition price for packaing amount at header level .

but its not updating the percentage. instead of that it takes previous percentage + present percentage and it is calculating.

that condition is active in standard tcode.

Here is my code

METHOD change_quot.

  DATA: lv_item_no        TYPE  posnr_va,

        lv_flag           TYPE  char01,

        lv_updt_flg       TYPE  char01,

        ls_shdr_old       TYPE  zst_inqhdr,

        ls_qterms_old     TYPE  zst_quoterms_pr,

        ls_header         TYPE  bapisdh1,

        ls_headerx        TYPE  bapisdh1x,

        ls_item           TYPE  bapisditm,

        ls_itemx          TYPE  bapisditmx,

        ls_schedule       TYPE  bapischdl,

        ls_schedulex      TYPE  bapischdlx,

        ls_partner_chng   TYPE  bapiparnrc,

        ls_return         TYPE  bapiret2,

        lt_return         TYPE  bapiret2_t,

        ls_salesitem      TYPE  zst_salesitem,

        ls_sales_item_old TYPE  zst_salesitem,

        lt_sales_item_old TYPE  ztt_salesitem,

        ls_cond           TYPE  bapicond,

        ls_condx          TYPE  bapicondx,

        ls_logic_switch   TYPE bapisdls,

        lt_partner_chngs  TYPE STANDARD TABLE OF  bapiparnrc,

        lt_items          TYPE STANDARD TABLE OF  bapisditm,

        lt_itemsx         TYPE STANDARD TABLE OF  bapisditmx,

        lt_schedule       TYPE STANDARD TABLE OF  bapischdl,

        lt_schedulex      TYPE STANDARD TABLE OF  bapischdlx,

        lt_cond           TYPE STANDARD TABLE OF  bapicond,

        lt_condx          TYPE STANDARD TABLE OF  bapicondx.

*

  CLEAR:   ls_shdr_old , ls_qterms_old, ls_header, ls_headerx, ls_return, ls_partner_chng, ls_salesitem,

           ls_sales_item_old, ls_item, ls_itemx, ls_schedule,ls_schedulex, lv_item_no, lv_updt_flg, ls_cond, ls_condx.

*

  REFRESH: lt_return, lt_partner_chngs, lt_items, lt_itemsx,lt_sales_item_old, lt_schedule,lt_schedulex, lt_cond, lt_condx.

*

* Get the Unchanged values for the Quotation

  CALL METHOD me->display_salesdoc

    EXPORTING

      iv_vbeln       = iv_vbeln

      iv_doctype     = c_qt

    IMPORTING

      es_saleshdr    = ls_shdr_old

      es_quoterms_pr = ls_qterms_old

      et_salesitem   = lt_sales_item_old.

*

* Set BAPI Header change fields

* Order reason

  IF iv_augru NE ls_qterms_old-ord_reason.

    ls_header-ord_reason = iv_augru.

    ls_headerx-ord_reason = 'X'.

    lv_updt_flg = 'X'.

  ENDIF.



    IF ls_header-QT_VALID_T NE ls_shdr_old-QT_VALID_T.

    ls_header-QT_VALID_T = is_saleshdr-QT_VALID_T.

    ls_headerx-QT_VALID_T = 'X'.

    lv_updt_flg = 'X'.

    ENDIF.

* Partner

  IF iv_parnr NE ls_shdr_old-sales_rep.

    lv_updt_flg = 'X'.

    ls_partner_chng-p_numb_old = ls_shdr_old-sales_rep.

    ls_partner_chng-document    = iv_vbeln.

    ls_partner_chng-updateflag  = 'U'.

    ls_partner_chng-partn_role  = c_zb.

    ls_partner_chng-p_numb_new  = iv_parnr.

    APPEND ls_partner_chng TO lt_partner_chngs.

  ENDIF.

*   Set Customer currency

  CALL METHOD me->set_currency

    EXPORTING

      is_inqhdr = is_saleshdr.

*

* Check if the Sales items were changed

  IF  lt_sales_item_old[] NE it_salesitem[].

    LOOP AT it_salesitem INTO ls_salesitem.

      CLEAR lv_flag.

      lv_updt_flg = 'X'.

      lv_item_no = lv_item_no + 10.

      READ TABLE lt_sales_item_old INTO ls_sales_item_old WITH KEY item_no = lv_item_no.

      IF sy-subrc EQ 0.                                           " Change the item

        ls_item-itm_number = ls_salesitem-item_no.

        CHECK ls_salesitem NE ls_sales_item_old.

        lv_flag = 'X'.

        CHECK lv_flag = 'X'.

        IF ls_salesitem-quantity NE ls_sales_item_old-quantity.   " Change only Quantity

          ls_item-target_qty   = ls_salesitem-quantity.

          ls_itemx-target_qty = 'X'.

        ENDIF.

* Build Schedule line items

        ls_schedule-itm_number = ls_item-itm_number.

        ls_schedule-sched_line =  0001.

        ls_schedule-req_date   = sy-datum.

        ls_schedule-req_qty    = ls_salesitem-quantity.

        APPEND ls_schedule TO lt_schedule.

* Set flags for Schedule line data

        ls_schedulex-itm_number = ls_item-itm_number.

        ls_schedulex-sched_line = 0001.

        ls_schedulex-updateflag = 'U'.

        ls_schedulex-req_qty    = 'X'.

        ls_schedule-req_date    = 'X'.

        APPEND ls_schedulex TO lt_schedulex.

***********

        IF ls_salesitem-price NE ls_sales_item_old-price.





*     Basic Price

        ls_cond-itm_number = ls_item-itm_number.

        ls_cond-cond_type  = c_pr00.

        ls_cond-cond_value = ls_salesitem-price.

        ls_cond-currency   = gv_currency.

        ls_cond-calctypcon = 'B'.                         "Fixed Amount

        APPEND ls_cond TO lt_cond.



*     PR00 condition price should be updated

        ls_condx-itm_number = ls_item-itm_number.

        ls_condx-updateflag = 'U'.

        ls_condx-cond_type  = ls_cond-cond_type.

        ls_condx-cond_value = 'X'.

        ls_condx-currency   = 'X'.

        APPEND ls_condx TO lt_condx.

        ENDIF.



***********

*

        IF ls_item IS NOT INITIAL.

          ls_itemx-itm_number  = ls_item-itm_number.

          ls_itemx-updateflag   = 'U'.

          APPEND ls_item  TO lt_items.

          APPEND ls_itemx TO lt_itemsx.

        ENDIF.

      ELSE.                                              " Add new item

        lv_flag = 'X'.

        IF ls_salesitem-item_no EQ space.

          ls_item-itm_number  = lv_item_no.

        ELSE.

          ls_item-itm_number  = ls_salesitem-item_no.

        ENDIF.

*

        ls_item-itm_number  = ls_item-itm_number.

        ls_item-material    = ls_salesitem-material.

        ls_item-target_qty  = ls_salesitem-quantity.

        ls_item-plant       = ls_salesitem-plant.

        ls_item-sales_unit  = ls_salesitem-sales_unit.

*

        ls_itemx-itm_number = ls_item-itm_number.

        ls_itemx-updateflag = 'I'.

        ls_itemx-material   = 'X'.

        ls_itemx-plant      = 'X'.

        ls_itemx-target_qty = 'X'.

        ls_itemx-target_qu  = 'X'.

        ls_itemx-sales_unit = 'X'.

*

* Build Item level Pricing Conditions

* Basic Price

        ls_cond-itm_number = ls_item-itm_number.

        ls_cond-cond_type  = c_pr00.

        ls_cond-cond_value = ls_salesitem-price.

        ls_cond-currency   = gv_currency.

        ls_cond-calctypcon = 'B'.                         "Fixed Amount

        APPEND ls_cond TO lt_cond.



*     PR00 condition price should be updated

        ls_condx-itm_number = ls_item-itm_number.

        ls_condx-updateflag = 'U'.

        ls_condx-cond_type  = ls_cond-cond_type.

        ls_condx-cond_value = 'X'.

        ls_condx-currency   = 'X'.

        APPEND ls_condx TO lt_condx.

*Customer Discount

        IF ls_salesitem-discount IS NOT INITIAL.

          CLEAR ls_cond.

          ls_cond-itm_number = ls_item-itm_number.

          ls_cond-cond_type  = c_zcus.

          ls_cond-cond_value = ls_salesitem-discount * 10.

          ls_cond-currency   = gv_currency.

          ls_cond-calctypcon = 'A'.                              "Percentage

          APPEND ls_cond TO lt_cond.

        ENDIF.

*  Warranty allowance - Only for Export channel '92'

        IF  ls_salesitem-warranty IS NOT INITIAL

        AND is_saleshdr-distr_chan = '92'.

          CLEAR ls_cond.

          ls_cond-itm_number = ls_item-itm_number.

          ls_cond-cond_type  = c_zwar.

          ls_cond-cond_value = ls_salesitem-warranty.

          ls_cond-currency   = gv_currency.

          ls_cond-calctypcon = 'A'.                              "Percentage

          APPEND ls_cond TO lt_cond.

        ENDIF.

* Set flags for Pricing Condition fields

        ls_condx-itm_number = ls_item-itm_number.

        ls_condx-cond_type  = ls_cond-cond_type.

        ls_condx-updateflag = 'I'.

        ls_condx-cond_value = 'X'.

        ls_condx-currency   = 'X'.

        APPEND ls_condx TO lt_condx.

*

* Build Schedule line items

        ls_schedule-itm_number = ls_item-itm_number.

        ls_schedule-sched_line =  0001.

        ls_schedule-req_qty    = ls_salesitem-quantity.

        ls_schedule-req_date   = sy-datum.

        APPEND ls_schedule TO lt_schedule.

* Set flags for Schedule line data

        ls_schedulex-itm_number = ls_item-itm_number.

        ls_schedulex-sched_line = 0001.

        ls_schedulex-updateflag = 'I'.

        ls_schedulex-req_qty    = 'X'.

        ls_schedule-req_date    = 'X'.

        APPEND ls_schedulex TO lt_schedulex.

*

        IF ls_item IS NOT INITIAL.

          ls_itemx-itm_number  = ls_item-itm_number.

          ls_itemx-updateflag  = 'I'.

          APPEND ls_item  TO lt_items.

          APPEND ls_itemx TO lt_itemsx.

        ENDIF.

      ENDIF.

*

      CLEAR: ls_salesitem, ls_sales_item_old, ls_item, ls_itemx, ls_schedule, ls_schedulex, ls_cond, ls_condx.

    ENDLOOP.

    CLEAR: lv_item_no.

  ENDIF.

*

*

* Build Header level Pricing Conditions

*   Packing Amount

    IF  ls_qterms_old-ZPAC_VAL ne is_quot_pr-ZPAC_VAL.

      CLEAR LS_COND.

      LS_COND-COND_TYPE  = C_ZPAC.

      LS_COND-COND_VALUE = IS_QUOT_PR-ZPAC_VAL * 10.

      LS_COND-CURRENCY   = GV_CURRENCY.

      LS_COND-CALCTYPCON = 'A'.

      LS_COND-COND_UPDAT  = 'U'.

      APPEND LS_COND TO LT_COND.

    ENDIF.

*

*     Insurance %

    IF  ls_qterms_old-ZINS_PER ne is_quot_pr-ZINS_PER.

      CLEAR LS_COND.

      LS_COND-COND_TYPE  = C_ZINS.

      LS_COND-COND_VALUE = IS_QUOT_PR-ZINS_PER * 10.

      LS_COND-CURRENCY   = GV_CURRENCY.

      LS_COND-CALCTYPCON = 'A'.

      APPEND LS_COND TO lT_COND.

    ENDIF.

* Freight Charge

      IF  ls_qterms_old-ZFRE_VAL ne is_quot_pr-ZFRE_VAL.

      CLEAR LS_COND.

      LS_COND-COND_TYPE  = C_ZFRE.

      LS_COND-COND_VALUE = IS_QUOT_PR-ZFRE_VAL.

      LS_COND-CURRENCY   = GV_CURRENCY.

      LS_COND-CALCTYPCON = 'B'.

      APPEND LS_COND TO lT_COND.

    ENDIF.

* Cash Discount %

      IF  ls_qterms_old-ZCAS_PER ne is_quot_pr-ZCAS_PER.

      CLEAR LS_COND.

      LS_COND-COND_TYPE  = C_ZCAS.

      LS_COND-COND_VALUE = IS_QUOT_PR-ZCAS_PER * 10.

      LS_COND-CURRENCY   = GV_CURRENCY.

      LS_COND-CALCTYPCON = 'A'.

      APPEND LS_COND TO lT_COND.

    ENDIF.

*  Bank Charges - Only for Export channel '92'

        IF  ls_qterms_old-ZBAN_VAL ne is_quot_pr-ZBAN_VAL

    AND IS_SALESHDR-DISTR_CHAN = '92'.

      CLEAR LS_COND.

      LS_COND-COND_TYPE  = C_ZBAN.

      LS_COND-COND_VALUE = IS_QUOT_PR-ZBAN_VAL.

      LS_COND-CURRENCY   = GV_CURRENCY.

      LS_COND-CALCTYPCON = 'B'.

      APPEND LS_COND TO lT_COND.

    ENDIF.

*    * Set flags for Pricing Condition fields - Header level

    LS_CONDX-COND_TYPE  = 'X'.

    LS_CONDX-UPDATEFLAG = 'U'.

    LS_CONDX-COND_VALUE = 'X'.

    LS_CONDX-CURRENCY   = 'X'.

    APPEND LS_CONDX TO lT_CONDX.



*

  IF lv_updt_flg NE 'X'. .

    ls_return-type = 'E'.

    ls_return-id   = 'ZMC_OMS'.

    ls_return-number = '026'.

    MESSAGE ID 'ZMC_OMS' TYPE 'E' NUMBER '026' INTO ls_return-message.

    APPEND ls_return TO et_return.

  ELSE.

    ls_headerx-updateflag = 'U'.

*    To update existing pricing condition

*    ls_logic_switch-pricing = 'C'.

*

    CALL FUNCTION 'BAPI_CUSTOMERQUOTATION_CHANGE'

      EXPORTING

        salesdocument        = iv_vbeln

        quotation_header_in  = ls_header

        quotation_header_inx = ls_headerx

*        logic_switch         = ls_logic_switch

      TABLES

        return               = lt_return

        quotation_item_in    = lt_items

        quotation_item_inx   = lt_itemsx

        schedule_lines       = lt_schedule

        schedule_linesx      = lt_schedulex

        conditions_in        = lt_cond

        conditions_inx       = lt_condx

        partnerchanges       = lt_partner_chngs.

*

* Collect the Termination or Error messages, if any

    LOOP AT lt_return INTO ls_return

      WHERE ( type = 'A'

      OR      type = 'E' ).

      APPEND ls_return TO et_return.

      CLEAR ls_return.

    ENDLOOP.

*

* If there are no error messages, check if the Quotation is changed and then commit the BAPI

    IF et_return[] IS INITIAL.

      READ TABLE lt_return INTO ls_return WITH KEY type = 'S'.

      IF sy-subrc EQ 0.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            wait = 'X'.

      ENDIF.

    ENDIF.

  ENDIF.

ENDMETHOD.

Thanks & Regards,

Meenachi.R

1 REPLY 1

Sijin_Chandran
Active Contributor
0 Kudos

Hi Meenachi ,

Is it working correctly for all other Condition Types ( i.e C_ZINS , C_ZCAS etc )

Check the below area of your code as well.

IF  ls_qterms_old-ZPAC_VAL ne is_quot_pr-ZPAC_VAL.


      CLEAR LS_COND.


      LS_COND-COND_TYPE  = C_ZPAC.


      LS_COND-COND_VALUE = IS_QUOT_PR-ZPAC_VAL * 10.


      LS_COND-CURRENCY   = GV_CURRENCY.


      LS_COND-CALCTYPCON = 'A'.


      LS_COND-COND_UPDAT  = 'U'.       " Also check this part also  



      APPEND LS_COND TO LT_COND.


    ENDIF.

Refer the below link  and see Birendra's suggestion.

http://scn.sap.com/thread/1708275

You need to edit the above like this

LS_COND-ITM_NUMBER  = (Value of item number)

LS_COND-COND_ST_NO = (Value of Condition count Step Number)

LS_COND-COND_COUNT = (Value of condition counter)

LS_COND-COND_TYPE = 'C_ZPAC'.

LS_COND-COND_VALUE = (Changed value)

LS_COND-CURRENCY = (Currency)

LS_COND-COND_UPDAT = 'X'.

APPEND LS_COND TO LT_COND.