Professional Documents
Culture Documents
Extracting Pricing Conditions
Extracting Pricing Conditions
on Purchase Order in BI
Applies to:
SAP BW3.5, BI7.0. For more information, visit the Business Intelligence homepage.
Summary
This document gives a method to extract pricing condition data on purchase order in BI.
Authors: Tej Trivedi,and Kartik Ravi
Company: L&T Infotech
Created on: 22 December 2009
Author Bio
Tej Trivedi is a SAP BI/BO Consultant currently working in Larsen & Toubro Infotech Ltd. He
has over 4+years of core experience in various BW/BI Implementation, Migration, Rollout,
Support Pack Upgrade and Support Projects. The experience includes 1 year experience on
BO Platform.
Kartik Ravi is a SAP BI and Business Objects (BOBJ) Consultant with 4 years experience
in SAP and Datawarehousing technology.
Table of Contents
Introduction ......................................................................................................................................................... 3
Business Scenario .............................................................................................................................................. 3
Steps to view pricing condition data on purchase order ................................................................................. 3
Pricing table Navigation .................................................................................................................................. 4
Step by Step Method to create Data source ................................................................................................... 4
Appendix: Source Code to extract pricing data for Purchase Order .................................................................. 9
Include Declaration ......................................................................................................................................... 9
Function module code ................................................................................................................................... 11
Related Content ................................................................................................................................................ 17
Disclaimer and Liability Notice .......................................................................................................................... 18
Introduction
A purchase order is created by a Buyer to procure material or commodities from the vendor. Pricing
Condition data on a purchase order gives an overview of different components involved in arriving at the Net
value of the purchase order. For example, components like Freight prices that were incurred in shipping a
quantity, discounts given by vendor on the quantity ordered, etc. Every component is assigned a condition
type. All this components are responsible to arrive at the net value of a purchase order. Standard purchase
order data sources do not extract pricing condition data on purchase order. This document will explain the
steps needed to create a data source that extracts pricing condition data on a purchase order.
Business Scenario
You want to extract pricing condition data on a purchase order for which there is no standard data source
provided by SAP business content.
3. From the “item” menu , select “Conditions” as shown in the screenshot below.
4. Below screenshot displays the pricing condition data for purchase order item.
2. We will create a generic data source using a function module. The logic used in the function module
is as follows:
a. Define a table “i_ekko_ekpo” as defined in the TOP include “<L<Function group
name>TOP> “. This table will be filled in the function module based on the fields EKKO-
AEDAT, EKPO-AEDAT, EKKO-BUKRS, EKKO-EBELN, EKPO-EBELP, EKPO-EMATN,
EKKO-LIFNR, and EKPO-MATNR. In other words, the table should be filled with all the fields
which are marked as “Selection” fields in the data source except for AEDAT from EKKO and
EKPO.
b. Define a table “i_konv“as defined in the TOP include “<L<Function group name>TOP> “.
This table will be filled in function module based on KONV-KNUMV and KONV-KPOSN by
equating them with the corresponding fields of table “i_ekko_ekpo”. In addition there will be a
filter KONV-KAPPL = “M” to make sure we are reading only Purchasing relevant records.
One can use condition type while reading the table KONV if it is marked in the “Selection”
field in the data source.
c. Define a work area “lwa_data” of type “e_t_data”.
d. Loop at the table “i_ekko_ekpo”. We will have a nested loop on table “i_konv“by equating
KNUMV and KPOSN. Fill all purchase order header and item information from the table
“i_ekko_ekpo” to relevant fields of “lwa_data”. Fill all the purchase order condition data from
the table “i_konv“to relevant fields of “lwa_data”.
e. For more details on any of the above points, refer the Appendix section.
3. Go to t-code “RSO2” to create a generic data source using the function module created in step 2.
Select the data source type and assign a technical name to it. Choose Create. The screen to create
generic data source appears.
4. Choose application component as “MM”. Provide short, medium and long description. Enter the
name of the function module and structure.
5. Choose “Generic Delta” to specify the delta specific field. Select “Time stamp” radio button and
choose “AEDAT” as a field for generic delta. Select the radio button “New Status for Changed
Records” to ensure that an After Image is delivered by the generic data source.
Note: In the function module we are comparing AEDAT with the AEDAT in EKKO as well as EKPO. This is to ensure that
we take care of creation as well as changes to purchase orders. When a purchase order is created, AEDAT in
EKKO is populated. When a purchase order is changed, AEDAT in EKPO is populated. One has to check this
feature prior to data source creation by creating a purchase order as well as changing pricing condition data on a
purchase order.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" VALUE(I_REMOTE_CALL) TYPE SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE < Extract Structure Name > OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
* counter
s_counter_datapakid LIKE sy-tabix,
* cursor
s_cursor TYPE cursor.
* Select ranges
RANGES: l_r_aedat FOR ekko-aedat,
l_r_bukrs FOR ekko-bukrs,
l_r_ebeln FOR ekko-ebeln,
l_r_ebelp FOR ekpo-ebelp,
l_r_ematn FOR ekpo-ematn,
l_r_kschl FOR konv-kschl,
l_r_lifnr FOR ekko-lifnr,
l_r_matnr FOR ekpo-matnr.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
************************************************************************
* Data transfer: First Call OPEN CURSOR + FETCH
* Following Calls FETCH only
************************************************************************
* Fill range tables BW will only pass down simple selection criteria
* of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm = 'AEDAT'.
MOVE-CORRESPONDING l_s_select TO l_r_aedat.
l_r_aedat-sign = 'I'.
l_r_aedat-option = 'GE'.
CLEAR l_r_aedat-high.
APPEND l_r_aedat.
ENDLOOP.
*-- Fetch Purchase Order data from Database Tables EKKO and EKPO
ekpo~loekz
ekko~bedat
ekko~lifnr
ekko~statu
ekko~reswk
ekko~bsart
ekko~waers
ekpo~menge
ekpo~meins
FROM ekko AS ekko
INNER JOIN ekpo AS ekpo
ON ekko~ebeln = ekpo~ebeln
WHERE ( ( ekko~aedat IN l_r_aedat
OR ekpo~aedat IN l_r_aedat )
AND ekko~bukrs IN l_r_bukrs
AND ekko~ebeln IN l_r_ebeln
AND ekpo~ebelp IN l_r_ebelp
AND ekpo~ematn IN l_r_ematn
AND ekko~lifnr IN l_r_lifnr
AND ekpo~matnr IN l_r_matnr ).
IF sy-subrc <> 0.
CLOSE CURSOR s_cursor.
RAISE no_more_data.
ELSE.
IF i_ekko_ekpo[] IS NOT INITIAL.
LOOP AT i_ekko_ekpo ASSIGNING <fs_ekko_ekpo>.
MOVE <fs_ekko_ekpo>-ebelp TO <fs_ekko_ekpo>-kposn.
ENDLOOP.
* Populating LWA_DATA with pricing condition for each Purchase order based on “Number
of * the document condition” (i.e. EKKO- KNUMV) and “Item Number of Purchasing
Document” * (i.e. EKPO-EBELP).
SELECT knumv
kposn
kschl
kappl
kdatu
zaehk
kinak
koaid
kherk
kntyp
kstat
kwert
kkurs
varcond
stunr
kvarc
FROM konv
INTO TABLE i_konv
FOR ALL ENTRIES IN i_ekko_ekpo
WHERE knumv EQ i_ekko_ekpo-knumv
AND kposn EQ i_ekko_ekpo-kposn
AND kappl EQ 'M'
AND kschl IN l_r_kschl.
CLEAR lwa_data.
IF <fs_ekko_ekpo>-aedat1 IS INITIAL.
MOVE <fs_ekko_ekpo>-aedat TO lwa_data-aedat.
ELSE.
MOVE <fs_ekko_ekpo>-aedat1 TO lwa_data-aedat.
ENDIF.
lwa_data-bwapplnm = 'MM'.
s_counter_datapakid = s_counter_datapakid + 1.
ENDFUNCTION.
Related Content
SAP BI Generic Extraction Using a Function Module
Functional Understanding of Pricing
For more information, visit the Business Intelligence homepage.