Skip to Content

Purchase Order Modifications using Classes

I found a document on scn which used Classes to  get Purchase order details here

http://wiki.sdn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+ABAP+Classes

On the same line, I have created a program which shows how to modify Item Conditions using classes.

Same concept can be applied to modify other data.

***&———————————————————————*

***& Report  ZPO_CHANGE

***&

***&———————————————————————*

***&

***&

***&———————————————————————*

**

REPORT ZPO_CHANGE

**

TABLES : ekko.

TYPE-POOLS : mmpur, abap.

DATA : zcl_po TYPE REF TO cl_po_header_handle_mm.

DATA : zcl_item TYPE REF TO CL_PO_ITEM_HANDLE_MM.

DATA : ord_changed type mmpur_bool.

* Definition for header *

DATA : ls_document TYPE mepo_document,

        lv_result   TYPE mmpur_bool,

        ls_mepoheader TYPE mepoheader.

* Definition for Item *

DATA : lt_items      TYPE purchase_order_items,

        ls_items      TYPE purchase_order_item,

        lt_mepoitem   TYPE STANDARD TABLE OF mepoitem,

        ls_mepoitem   TYPE mepoitem.

DATA : l_item_conditions_changed TYPE mmpur_bool.

* Definition for Item Conditions *

DATA : lt_conditions TYPE mmpur_tkomv,

       lt_conditions1 TYPE mmpur_tkomv,

        ls_conditions TYPE komv,

        lt_mepocond   TYPE mmpur_tkomv.

DATA : lt_models    TYPE mmpur_models,

       ls_model     LIKE LINE OF lt_models.

PARAMETERS : p_ebeln TYPE ekkoebeln.

MOVE mmpur_po_process TO ls_documentprocess.

MOVE ‘V’ TO ls_documenttrtyp. ” edit mode of Po

MOVE p_ebeln TO ls_documentdoc_key(10).

MOVE mmpur_initiator_call TO ls_documentinitiatorinitiator.

* Create Object of Purchase Order Class *

CREATE OBJECT zcl_po

   EXPORTING

     im_po_number = p_ebeln

   EXCEPTIONS

     failure = 1

     OTHERS  = 2.

IF sysubrc <> 0.

   MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

              WITH symsgv1 symsgv2 symsgv3 symsgv4.

ENDIF.

IF zcl_po IS NOT INITIAL.

* Set the state to existing Purchase Order *

   zcl_po->set_state( im_state = cl_po_header_handle_mm=>c_available ).

   MOVE mmpur_yes TO zcl_po->for_bapi.

* Initialize the environment *

   zcl_po->po_initialize( im_document = ls_document ).

* Read PO document *

   zcl_po->po_read(

     EXPORTING

       im_tcode     = ‘ME22N’

       im_trtyp     = ls_documenttrtyp

       im_aktyp     = ls_documenttrtyp

       im_po_number = p_ebeln

       im_document  = ls_document

     IMPORTING

       ex_result    = lv_result ).

   IF lv_result = abap_true.

* ————————————————–*

* Extract PO Item Information *

* ————————————————–*

     REFRESH : lt_items.

     lt_items = zcl_po->if_purchase_order_mm~get_items( ).

     LOOP AT lt_items INTO ls_items .

      zcl_item ?= ls_itemsitem.

      Zcl_item->my_parent ?= zcl_po.

  .

* ————————————————-*

* Extract PO Item Conditions *

* ————————————————–*

       CALL METHOD zcl_item->IF_PURCHASE_ORDER_ITEM_MM~GET_CONDITIONS(

         IMPORTING

           ex_conditions = lt_conditions ).

*Here if you delete a condition from the internal table it will get deleted in the PO as well.

       LOOP AT lt_conditions INTO ls_conditions WHERE KSCHL = ‘YFR1’.

         ls_conditionskwert = ‘1234’.

         MODIFY lt_conditions FROM ls_conditions TRANSPORTING kwert.

       ENDLOOP.

*     set  parameters for conditions

       zcl_po->my_ibs_firewall_on = mmpur_yes.


            CALL METHOD zcl_item->IF_PURCHASE_ORDER_ITEM_MM~SET_CONDITIONS(

               EXPORTING

               im_conditions = lt_conditions ).

** Add the Instance to the Generic MM Model Object

ls_modelmodel ?= zcl_item.

APPEND ls_model TO lt_models.

       ENDIF.

    ENDLOOP.

    

IF lt_models[] IS NOT INITIAL.

       CALL METHOD ZCL_PO->IF_FLUSH_TRANSPORT_MM~START

           EXPORTING

             IM_MODELS    = lt_models[]

           EXCEPTIONS

             ILLEGAL_CALL = 1

             ERROR        = 2

             OTHERS       = 3

              .

      IF SYSUBRC <> 0.

       MESSAGE ID SYMSGID TYPE SYMSGTY NUMBER SYMSGNO

                  WITH SYMSGV1 SYMSGV2 SYMSGV3 SYMSGV4.

      ENDIF.

    ENDIF         .

               CALL METHOD ZCL_PO->PO_POST

                 EXPORTING

                   IM_UNCOMPLETE  = MMPUR_NO

                   IM_NO_COMMIT   = MMPUR_NO

                   IM_COMMIT_WAIT = MMPUR_yes

                 EXCEPTIONS

                   FAILURE        = 1

                   OTHERS         = 2

                       .

               IF SYSUBRC <> 0.

                MESSAGE ID SYMSGID TYPE SYMSGTY NUMBER SYMSGNO

                           WITH SYMSGV1 SYMSGV2 SYMSGV3 SYMSGV4.

               ENDIF.

              CALL METHOD ZCL_PO->PO_CLOSE

               .

   ENDIF.

   ENDIF.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply