Introduction: For deleting PO History we can use a BAPI 'BAPI_PO_DELETE_HISTORY'. EKBE is the PO history table, the entries that are to be changed must be transferred to the BAPI structure BAPIEKBE. Function module MAP2E_EKBE_TO_BAPIEKBE is available for getting data into BAPI structure BAPIEKBE. Below is the code that takes list of purchase orders from selection screen to be processed for history deletion. *&-----------------------------------------------------------------------* *& Report : ZMPMM038 *& DATE : 28th Jan 2009 * *& AUTHOR : Krishna Chauhan (Sparta Consulting) * *& DEVELOPMENT : Deleting PO History * *&----------------------------------------------------------------------* REPORT ZMPMM038 NO STANDARD PAGE HEADING LINE-SIZE 140 MESSAGE-ID zm. *------Tables--------------------------------------------------------------* TABLES: ekbe. "History per Purchasing Document *******Data Declaration***************************************************** DATA: it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE, it_phist LIKE bapiekbe OCCURS 0 WITH HEADER LINE, wa_phist LIKE LINE OF it_phist, it_tref LIKE csl_tr_exs OCCURS 0 WITH HEADER LINE, w_po LIKE bapiekko-po_number, it_ekbe LIKE ekbe OCCURS 0 WITH HEADER LINE, wa_ekbe LIKE LINE OF it_ekbe. ****Selection screen definition******************************** SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. SELECT-OPTIONS : s_docno FOR ekbe-ebeln OBLIGATORY. SELECTION-SCREEN END OF BLOCK b1. ******Start of Selection**************************************** START-OF-SELECTION. *Pick the data and process it for deleteing PO History. PERFORM process_data. *&---------------------------------------------------------------------* *& Form process_data *&---------------------------------------------------------------------* FORM process_data . CLEAR it_ekbe. REFRESH it_ekbe. SELECT * FROM ekbe INTO TABLE it_ekbe WHERE ebeln IN s_docno. check sy-subrc eq 0. SORT it_ekbe BY ebeln. LOOP AT it_ekbe INTO wa_ekbe. CLEAR: w_po, wa_phist, it_return, it_tref. w_po = wa_ekbe-ebeln. *---fun mod to get 'bapiekbe' for passing it to BAPI history deetel CALL FUNCTION 'MAP2E_EKBE_TO_BAPIEKBE' EXPORTING ekbe = wa_ekbe CHANGING bapiekbe = wa_phist EXCEPTIONS error_converting_curr_amount = 1 OTHERS = 2. APPEND wa_phist TO it_phist. CLEAR it_phist. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. AT END OF ebeln. CALL FUNCTION 'BAPI_PO_DELETE_HISTORY' EXPORTING purchaseorder = w_po TABLES return = it_return poitemhistory = it_phist tokenreference = it_tref. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. " IF sy-subrc = 0. *---clear it_phist to Transfer Structure for PO History REFRESH it_phist. ENDAT. ENDLOOP. ENDFORM. " process_data Output can be checked in ME23N transaction, after execution of the prog it will not show any PO History for the respective PO. Entries will also be deleted from EKBE table. output:
采购订单历史删除
最新推荐文章于 2024-01-25 14:45:43 发布