http://wiki.sdn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+ABAP+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 ekko-ebeln.MOVE mmpur_po_process TO ls_document-process.MOVE 'V' TO ls_document-trtyp. " edit mode of PoMOVE p_ebeln TO ls_document-doc_key(10).MOVE mmpur_initiator_call TO ls_document-initiator-initiator.* Create Object of Purchase Order Class *CREATE OBJECT zcl_poEXPORTINGim_po_number = p_ebelnEXCEPTIONSfailure = 1OTHERS = 2.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.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(EXPORTINGim_tcode = 'ME22N'im_trtyp = ls_document-trtypim_aktyp = ls_document-trtypim_po_number = p_ebelnim_document = ls_documentIMPORTINGex_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_items-item.Zcl_item->my_parent ?= zcl_po..* -------------------------------------------------** Extract PO Item Conditions ** --------------------------------------------------*CALL METHOD zcl_item->IF_PURCHASE_ORDER_ITEM_MM~GET_CONDITIONS(IMPORTINGex_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_conditions-kwert = '1234'.MODIFY lt_conditions FROM ls_conditions TRANSPORTING kwert.ENDLOOP.* set parameters for conditionszcl_po->my_ibs_firewall_on = mmpur_yes.CALL METHOD zcl_item->IF_PURCHASE_ORDER_ITEM_MM~SET_CONDITIONS(EXPORTINGim_conditions = lt_conditions ).** Add the Instance to the Generic MM Model Objectls_model-model ?= zcl_item.APPEND ls_model TO lt_models.ENDIF.ENDLOOP.IF lt_models[] IS NOT INITIAL.CALL METHOD ZCL_PO->IF_FLUSH_TRANSPORT_MM~STARTEXPORTINGIM_MODELS = lt_models[]EXCEPTIONSILLEGAL_CALL = 1ERROR = 2OTHERS = 3.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.ENDIF .CALL METHOD ZCL_PO->PO_POSTEXPORTINGIM_UNCOMPLETE = MMPUR_NOIM_NO_COMMIT = MMPUR_NOIM_COMMIT_WAIT = MMPUR_yesEXCEPTIONSFAILURE = 1OTHERS = 2.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.CALL METHOD ZCL_PO->PO_CLOSE.ENDIF.ENDIF.
No comments:
Post a Comment