You are on page 1of 5

Purchase Order Data Extraction using ABAP Classes - ABAP Development - SCN Wiki

Getting Started

Welcome, Guest

Login

Register

Pgina 1 de 5

Newsletters Store

Search the Community

Products

Services & Support

About SCN

Downloads

Industries

Training & Education

Partnership

Developer Center

Lines of Business

University Alliances

Events & Webinars

Innovation

We are improving! Due to further refinements, our original planned dates for no new content of September 4th through September 7th have been moved.
The SCN wiki will not be available for new content submission starting September 4th 6PM CET until September 7 6PM CET. Please plan your SCN wiki tasks accordingly.

ABAP Development / ABAP Development

Purchase Order Data Extraction using ABAP Classes


Added by Vinod Kumar, last edited by Keshav.T on Nov 06, 2012

Purchase Order Data Extraction using ABAP Classes

Useful Information
Purchase Order Data Extraction using ABAP Classes

Link to Content's target Space :


http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Development+and+Programming.

Applies to:
Sample Program Developed in ECC 5.0

Summary
This post narrates the use of ABAP Classes for Extracting Purchase Order Details.

Author(s): Vinod Kumar T


Company:

NIIT Technologies Limited

Created on:

16.11.2010

Author(s) Bio
Vinod Kumar is an ABAP Consultant working with NIIT Technologies LImited
Table of Contents
Purchase Order Data Extraction using ABAP Classes
Link to Content's target Space :
Applies to:
Summary
Author(s): Vinod Kumar T
Class & Methods Used
Contents in Sample Code
Comments
Sample Code
Related Content

Class & Methods Used


Class

Interface / Method

Description

CL_PO_HEADER_HANDLE_MM

SET_STATE

Set the Current State


of Purchase Order

CL_PO_HEADER_HANDLE_MM

PO_INITIALIZE

Initialize/Refresh PO
Environment

CL_PO_HEADER_HANDLE_MM

PO_READ

Read Purchase Order

CL_PO_HEADER_HANDLE_MM

IF_PURCHASE_ORDER_MM~GET_DATA

Get PO Header Data

CL_PO_HEADER_HANDLE_MM

IF_PURCAHSING_DOCUMENT~GET_PARTNERS

Get PO Header
Partners

CL_PO_HEADER_HANDLE_MM

IF_LONGTEXTS_MM~GET_TEXTOBJECT

Get Header Long


Text Object

CL_PO_HEADER_HANDLE_MM

IF_LONGTEXTS_MM~GET_TYPES

Get Header Long


Text IDs

http://wiki.scn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+A...

20/08/2015

Purchase Order Data Extraction using ABAP Classes - ABAP Development - SCN Wiki

Class

Interface / Method

Description

CL_PO_HEADER_HANDLE_MM

IF_LONGTEXTS_MM~GET_TEXT

Get Header Long

Pgina 2 de 5

Text
CL_PO_HEADER_HANDLE_MM

IF_PURCHASE_ORDER_MM~GET_ITEMS

Get PO Line items


Instance

CL_PO_ITEM_HANDLE_MM

IF_PURCHASE_ORDER_ITEM_MM~GET_DATA

Get PO Line items


data

CL_PO_ITEM_HANDLE_MM

IF_PURCHASE_ORDER_ITEM_MM~GET_SCHEDULES

Get PO Item
Schedule instance

CL_PO_SCHEDULE_HANDLE_MM

IF_PURCAHSE_ORDER_SCHEDULE_MM~GET_DATA

Get PO Item
Schedule data

CL_PO_ITEM_HANDLE_MM

IF_PURCHASE_ORDER_ITEM_MM~GET_ACCOUNTINGS

Get PO Acct
Assignment Instance

CL_PO_ACCOUNTING_HANDLE_MM

IF_PURCHASE_ORDER_ACCOUNT_MM~GET_DATA

Get PO Acct
Assingment data

CL_PO_ITEM_HANDLE_MM

IF_PURCHASE_ORDER_ITEM_MM~GET_CONDITIONS

Get PO Item Pricing


Conditions

CL_PO_ITEM_HANDLE_MM

IF_LONGTEXTS_MM~GET_TYPES

Get PO Line Long


text IDs

CL_PO_ITEM_HANDLE_MM

IF_LONGTEXTS_MM~GET_TEXT

Get PO LIne Long


text Data

CL_PO_ITEM_HANDLE_MM

IF_PURCHASE_ORDER_ITEM_MM~GET_HISOTRY

Get PO History
(Document Flow)

Contents in Sample Code


Sample code is used to extract the Purchase Order Information using the ABAP Classes. Following Information is extracted using the
Classes.
Purcahse Order Header Data
PO Header Partner Information
PO Header Long texts
PO Line item Information
PO Line item Delivery Schedule Information
PO Line item Account assingment information
PO Line item Long texts
PO History (Line Item wise Document Flow)

Comments
The code written here stores the data in internal tables. Further processing of internal tables or Display of the contents are not
mentioned in the sample code.

Sample Code
&--------------------------------------------------------------------*& Report ZVK_CL_PO
&--------------------------------------------------------------------*& Report to Extract Purchase Order details
&--------------------------------------------------------------------REPORT zvk_cl_po.
TABLES : ekko.
TYPE-POOLS : mmpur, abap.
DATA : zcl_po TYPE REF TO cl_po_header_handle_mm.
* Definition for header *
DATA : ls_document TYPE mepo_document,
lv_result TYPE mmpur_bool,
ls_mepoheader TYPE mepoheader.
* Definition for Item *
DATA : lt_items
ls_items

TYPE purchase_order_items,
TYPE purchase_order_item,

http://wiki.scn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+A...

20/08/2015

Purchase Order Data Extraction using ABAP Classes - ABAP Development - SCN Wiki

Pgina 3 de 5

lt_mepoitem TYPE STANDARD TABLE OF mepoitem,


ls_mepoitem TYPE mepoitem.
* Definition for Delivery Schedule *
DATA : lt_schedules TYPE purchase_order_schedules,
ls_schedules TYPE purchase_order_schedule,
lt_meposchd TYPE STANDARD TABLE OF meposchedule,
ls_meposchd TYPE meposchedule.
* Definition for Account assignments *
DATA : lt_accounting TYPE purchase_order_accountings,
ls_accounting TYPE purchase_order_accounting,
lt_mepoacct TYPE STANDARD TABLE OF mepoaccounting,
ls_mepoacct TYPE mepoaccounting.
* Definition for Item Conditions *
DATA : lt_conditions TYPE mmpur_tkomv,
ls_conditions TYPE komv,
lt_mepocond TYPE mmpur_tkomv.
* Definition for Header Partners *
DATA : lt_partners TYPE mmpur_partner_all_tab,
ls_partners TYPE mmpur_partner_all.
* Defintion for Header Text Object*
DATA : lv_tdobject TYPE tdobject,
lv_metafield TYPE mmpur_metafield.
* Definition for Header Text IDs *
DATA : lt_h_txttypes TYPE mmpur_t_texttypes,
ls_h_txttypes TYPE mmpur_texttypes.
* Definition for Header Text Data *
DATA : lt_h_txtlines TYPE mmpur_t_textlines,
lt_h_textdata TYPE mmpur_t_textlines,
ls_h_txtlines TYPE mmpur_textlines,
lv_h_format TYPE mmpur_bool.
* Defintion for Item Text Object*
DATA : lv_i_tdobject TYPE tdobject,
lv_i_metafield TYPE mmpur_metafield.
* Definition for Item Text IDs *
DATA : lt_i_txttypes TYPE mmpur_t_texttypes,
ls_i_txttypes TYPE mmpur_texttypes.
* Definition for Item Text Data *
DATA : lt_i_txtlines TYPE mmpur_t_textlines,
lt_i_textdata TYPE mmpur_t_textlines,
ls_i_txtlines TYPE mmpur_textlines,
lv_i_format TYPE mmpur_bool.
* Definition for Purchase Order History *
DATA : ls_indicator TYPE mepo_were,
lt_item_total TYPE me_ekbes,
lt_total_sum TYPE me_ekbes,
lt_item_del TYPE me_ekbnk,
lt_del_sum

TYPE me_ekbnk,

lt_grir_det TYPE me_ekbez,


lt_grir_sum TYPE me_ekbez,
lt_history

TYPE me_ekbe,

lt_hist_sum TYPE me_ekbe,


lt_del_hist TYPE me_ekbz,
lt_dh_sum

TYPE me_ekbz.

PARAMETERS : p_ebeln TYPE ekko-ebeln.


MOVE mmpur_po_process TO ls_document-process.
MOVE 'A' TO ls_document-trtyp.
MOVE 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_po
EXPORTING
im_po_number = p_ebeln
EXCEPTIONS
failure = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

http://wiki.scn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+A...

20/08/2015

Purchase Order Data Extraction using ABAP Classes - ABAP Development - SCN Wiki

Pgina 4 de 5

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 ).
* Initialize the environment *
zcl_po->po_initialize( im_document = ls_document ).
* Read PO document *
zcl_po->po_read(
EXPORTING
im_tcode
im_trtyp

= 'ME23N'
= ls_document-trtyp

im_aktyp

= ls_document-trtyp

im_po_number = p_ebeln
im_document = ls_document
IMPORTING
ex_result

= lv_result ).

IF lv_result = abap_true.
* --------------------------------------------------*
* Extract PO Header Information *
* --------------------------------------------------*
CLEAR : ls_mepoheader.
ls_mepoheader = zcl_po->if_purchase_order_mm~get_data( ).
* --------------------------------------------------*
* Extract PO Header Partners *
* --------------------------------------------------*
REFRESH : lt_partners.
lt_partners = zcl_po->if_purchasing_document~get_partners( ).
* --------------------------------------------------*
* Extract Header Text Object Details *
* --------------------------------------------------*
CLEAR : lv_tdobject, lv_metafield.
zcl_po->if_longtexts_mm~get_textobject(
IMPORTING
ex_tdobject = lv_tdobject
ex_metafield = lv_metafield ).
* --------------------------------------------------*
* Extract Header Text ID information *
* --------------------------------------------------*
REFRESH : lt_h_txttypes.
zcl_po->if_longtexts_mm~get_types(
IMPORTING
ex_texttypes = lt_h_txttypes ).
* --------------------------------------------------*
* Extract Header Text Informaton *
* --------------------------------------------------*
REFRESH : lt_h_textdata.
LOOP AT lt_h_txttypes INTO ls_h_txttypes.
zcl_po->if_longtexts_mm~get_text(
EXPORTING
im_tdid

= ls_h_txttypes-tdid

IMPORTING
ex_textlines

= lt_h_txtlines

ex_text_formatted = lv_h_format ).
APPEND LINES OF lt_h_txtlines TO lt_h_textdata.
ENDLOOP.
* --------------------------------------------------*
* Extract PO Item Information *
* --------------------------------------------------*
REFRESH : lt_items.
lt_items = zcl_po->if_purchase_order_mm~get_items( ).
LOOP AT lt_items INTO ls_items.
** ls_items-item returns the type Interface : IF_PURCHASE_ORDER_ITEM_MM
** which is part of the class : CL_PO_ITEM_HANDLE_MM
** Call the Interface method GET_DATA to get the Item details related to
** the Purchase Order. Item details data are passed to the structure
** ls_mepoitem and appended to the internal table lt_mepoitem.
ls_mepoitem = ls_items-item->get_data( ).
APPEND ls_mepoitem TO lt_mepoitem.
* --------------------------------------------------*
* Extract PO delivery schedule *
* --------------------------------------------------*
REFRESH : lt_schedules.
lt_schedules = ls_items-item->get_schedules( ).
LOOP AT lt_schedules INTO ls_schedules.

http://wiki.scn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+A...

20/08/2015

Purchase Order Data Extraction using ABAP Classes - ABAP Development - SCN Wiki

Pgina 5 de 5

** ls_schedules-schedule returns the type Interface : IF_PURCHASE_ORDER_SCHEDULE_MM


** which is part of the class : CL_PO_SCHEDULE_HANDLE_MM
** Call the interface method GET_DATA to get the delivery schedule related to
** to the PO Line Item. Schedule line details are passed to the strcuture
** ls_meposchd and appended to the internal table lt_meposchd.
ls_meposchd = ls_schedules-schedule->get_data( ).
APPEND ls_meposchd TO lt_meposchd.
ENDLOOP.
* --------------------------------------------------*
** Extract PO Account Assignments
* --------------------------------------------------*
REFRESH : lt_accounting.
lt_accounting = ls_items-item->get_accountings( ).
LOOP AT lt_accounting INTO ls_accounting.
** ls_accounting-accounting returns the type Interface : IF_PURCHASE_ORDER_ACCOUNT_MM
** which is part of the class : CL_PO_ACCOUNTING_HANDLE_MM
** Call the interface method GET_DATA to get the delivery schedule related to
** to the PO line item. Account assignment details are passed to the structure
** ls_mepoacct and appended to the internal table lt_mepoacct.
ls_mepoacct = ls_accounting-accounting->get_data( ).
APPEND ls_mepoacct TO lt_mepoacct.
ENDLOOP.
* --------------------------------------------------*
* Extract PO Item Conditions *
* --------------------------------------------------*
ls_items-item->get_conditions(
IMPORTING
ex_conditions = lt_conditions ).
APPEND LINES OF lt_conditions TO lt_mepocond.
* --------------------------------------------------*
* Extract PO Item Text Data *
* --------------------------------------------------*
REFRESH : lt_i_txttypes.
ls_items-item->if_longtexts_mm~get_types(
IMPORTING
ex_texttypes = lt_i_txttypes ).
LOOP AT lt_i_txttypes INTO ls_i_txttypes.
ls_items-item->if_longtexts_mm~get_text(
EXPORTING
im_tdid

= ls_i_txttypes-tdid

IMPORTING
ex_textlines

= lt_i_txtlines ).

APPEND LINES OF lt_i_txtlines TO lt_i_textdata.


ENDLOOP.
* --------------------------------------------------*
** Get Purchase Order Item History
* --------------------------------------------------*
REFRESH : lt_item_total, lt_item_del,lt_grir_det,
lt_history, lt_del_hist.
ls_items-item->get_history(
IMPORTING
ex_indicators

= ls_indicator

ex_item_totals

= lt_item_total

ex_item_totals_delivery = lt_item_del
ex_grir_assignment
ex_history

= lt_grir_det

= lt_history

ex_history_delivery

= lt_del_hist ).

APPEND LINES OF lt_item_total TO lt_total_sum.


APPEND LINES OF lt_item_del TO lt_del_sum.
APPEND LINES OF lt_grir_det TO lt_grir_sum.
APPEND LINES OF lt_history TO lt_hist_sum.
APPEND LINES OF lt_del_hist TO lt_dh_sum.
ENDLOOP.
ENDIF.
ENDIF.

Related Content
cl_po
Contact Us
Privacy

SAP Help Portal


Terms of Use

Legal Disclosure

cl_po_header_handle_mm

cl_po_item_handle_mm

Copyright

http://wiki.scn.sap.com/wiki/display/ABAP/Purchase+Order+Data+Extraction+using+A...

Follow SCN

20/08/2015

You might also like