Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

I have found many time these queries so decided to write a blog.

loop at table in whch you have PO no.s and you want to update price and do the following.

  if you want to change the deleivery date, account assignment data you can follow the same process and update it.

* Updating net price

      lw_item-po_item      = lw_output-ebelp.

      lw_item-net_price    = lw_output-netpr.

      APPEND lw_item TO lt_item.

      lw_itemx-po_item     = lw_output-ebelp.

      lw_itemx-po_itemx    = 'X'.

      lw_itemx-net_price   = 'X'.

      APPEND lw_itemx TO lt_itemx.

* call BAPI to change PO

      CALL FUNCTION 'BAPI_PO_CHANGE'

        EXPORTING

          purchaseorder = lw_output-ebeln

        TABLES

          return        = lt_return

          poitem        = lt_item

          poitemx       = lt_itemx.

* The program doesn't update the data. Therefore a commit work must be

* called.

      IF p_test EQ 'X'.

        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      ELSE.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            wait = 'X'.

      ENDIF.

    ENDIF.

For changing net price of CONTRACT

           

   CALL FUNCTION 'BAPI_CONTRACT_GETDETAIL'

        EXPORTING

          purchasingdocument = lw_contract-ebeln

          condition_data     = 'X'

        TABLES

          item_cond_validity = lt_condition_v

          item_condition      = lt_condition.

  it is always safe to get the old details when updating contract as Price determination is done based on various condition.

no only keep the conditions you want

  DELETE lt_condition WHERE item_no   NE lw_contract-ebelp

                               OR cond_type NE your_value.

* Read the one record left in lt_condition

        CLEAR lw_condition.

        SORT lt_condition BY serial_id DESCENDING.

        CLEAR: lw_condition,lv_serial_id.

        LOOP AT lt_condition INTO lw_condition.

          IF sy-tabix EQ 1.

            lw_condition-cond_value  = lw_contract-nnetpr.

            lw_condition-cond_p_unt  = lw_contract-npeinh.

            MODIFY lt_condition FROM lw_condition

                        TRANSPORTING cond_value

                                     cond_p_unt

                               WHERE item_no EQ lw_condition-item_no.

            lv_serial_id  = lw_condition-serial_id.

          ELSE.

            DELETE lt_condition.

          ENDIF.

        ENDLOOP.

        lw_conditionx-item_no    = lw_contract-ebelp.

        lw_conditionx-serial_id  = lv_serial_id.

        lw_conditionx-cond_value = 'X'.

        lw_conditionx-cond_p_unt = 'X'.

        APPEND lw_conditionx TO lt_conditionx.

* If successful

        IF sy-subrc EQ 0.

          DELETE lt_condition_v WHERE serial_id NE lv_serial_id.

        ENDIF.

        LOOP AT lt_condition_v INTO lw_condition_v.   

          lw_condition_v-valid_from = lw_contract-kdatb.

          lw_condition_v-valid_to   = lw_contract-kdate.

          MODIFY lt_condition_v FROM lw_condition_v

                        TRANSPORTING valid_from

                                     valid_to

                               WHERE serial_id = lv_serial_id.

        ENDLOOP.

* Pass BAPI parameters than needs to be change

        lw_cond_validityx-item_no    = lw_contract-ebelp.

        lw_cond_validityx-valid_from = 'X'.

        lw_cond_validityx-valid_to   = 'X'.

        APPEND lw_cond_validityx TO lt_cond_validityx.

        CALL FUNCTION 'BAPI_CONTRACT_CHANGE'

          EXPORTING

            purchasingdocument  = lw_contract-ebeln

          TABLES

            item_cond_validity  = lt_condition_v

            item_cond_validityx = lt_cond_validityx

            item_condition      = lt_condition

            item_conditionx     = lt_conditionx

            return              = lt_return.

      ENDIF.

* Rollback

      IF p_test EQ 'X'.

        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      ELSE.

* Commit

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            wait = 'X'.

      ENDIF.

    ENDIF. " No error befor calling BAPI

Thanks,

Rahul

2 Comments
Labels in this area