Skip to Content

Introduction

APO interactive transactions for multiple products don’t usually have all the options for selection that the business may need. This article explains how to use ABAP Query functionality to extend and customize the selection for these transactions.

The article shows – as an example – how the receipts view can be selected by the ABC indicator of the products; a field not present in the standard selection screen. The technical details are explained so it should be easy to adjust the query for other fields and more complex selection requirements.

ABAP query is a powerful functionality that allows complex reporting. It can include ABAP code without the need for a developer key. In this example we combine the query selection with a transaction screen called directly from within the query.

Queries can be exported and shared easily. You can download a file with the definition of the query in this article in the original post in my professional blog (see my profile). You will also find instructions on how to load it into your system.

Interactive transactions

/wp-content/uploads/2014/01/menu_373824.jpg

  • Receipt view                      (/SAPAPO/RRP4)
  • Requirement view              (/SAPAPO/RRP1)
  • Product planning Table     (/SAPAPO/PPT1)
  • Product overview               (/SAPAPO/POV1)

These are APO transactions that use the same selection screen. As you can see below the selection options are limited, even if we consider the additional tabs.

Selection screen of /SAPAPO/RRP4

fig 1.png

“Other” tab in /SAPAPO/RRP4 selection screen

fig 2.png

This is enough in most cases but the user may need a different selection field or approach.

Using the product-location free attributes fields in this way can be particularly useful as these fields can be populated with specific parameters from ECC not available in standard APO.

In the example presented the selection screen will look as follows and includes the ABC indicator as a selection option. The output result will depend on the interactive transaction extended. In this example it will be the receipts list for those product-locations matching the query selection.

fig 3.png

Technical details of the interactive transactions

The transactions indicated in the previous chapter all have a similar internal structure. The transaction calls a program include that does the following:

  1. Calls function /SAPAPO/PT_SELSCREEN: This function encapsulates the selection screen and brings back a selection of pegging areas that will be used in the report. Some additional conditions – like the date range – are also returned. All 4 transactions call the same function passing only a different title in a variable so that it shows at the top of the selection screen.
  2. Some manipulation of the selection parameters is performed: For example converting dates into timestamps.
  3. A function is called to display the transaction main screen: This can be just the order list or more complex functionality like the production planning table. This function takes as input the list of pegging areas from the function in point 1.

The following table shows for the 4 transactions the program include where the functions are called and the function used to run the main transaction.

Report

Transaction

Program Include

Function to run/display

Receipt view

/SAPAPO/RRP4

/SAPAPO/SAPRRP_RECEIPTS_ENTRY

/SAPAPO/RRP_SHOW_RECEIPTS

Requirement view

/SAPAPO/RRP1

/SAPAPO/SAPRRP_REQMTS_ENTRY

/SAPAPO/RRP_SHOW_REQMTS

Product planning Table

/SAPAPO/PPT1

/SAPAPO/SAPRRP_PT_ENTRY

/SAPAPO/RRP_PLANNING_TABLE

Product overview

/SAPAPO/POV1

/SAPAPO/POV_ENTRY

/SAPAPO/RRP_POV_SHOW

Implementing the query

The query selection substitutes the first function call with a customized extraction of the pegging areas that is then feed to the function that runs the transaction. In this way, we can make the selection much more complex, adding any field available in the product-location master data tables and filtering the combinations before calling the transaction.

For this article we are going to use a simplified selection of product, location and ABC indicator.

First of all we create an infoset by joining the tables indicated below.


fig+4.png

Then select the fields to be used in the query.

Fig+5.png

The “from” and “to” dates are important parameters to reduce processing time. These transactions are usually slow even for a small set of materials and any additional restriction will help performance. Create them as parameters in the query infoset.

Additional selection parameters in query


Fig 6.png


Definitions for date and time fields

Fig 7.png

Fig 8.png

Query Code

ABAP code is required to call the transaction function with the parameters determined by the query.

The following is an explanation of the code logic by sections in the query code tab.

DATA

In this section the data variables and structures are defined.

DATA:
lt_pegarea  
TYPE /sapapo/pegid_tab,
ls_selection
TYPE /sapapo/rrp_pt_selection,
ls_pegarea  
TYPE /sapapo/pegid,
lv_time_from
TYPE timestamp,
lv_time_to  
TYPE timestamp,
lv_simid    
TYPE /sapapo/vrsioid,
lv_confr_sel
TYPE REF TO /sapapo/cl_confr_sel.

Record Processing

This is the code that is executed for each of the records returned by the query select of the data.

The query returns a list of pegging areas in table /SAPAPO/PEGKEY for those product-locations included in the selection. Each pegging area ID is copied and appended to the temporary tablelt_pegarea.

*
* Append the pegging area returned by the query
* in /SAPAPO/PEGKEY into temporary table lt_pegarea
*
ls_pegarea
= /SAPAPO/PEGKEYPEGID.
APPEND ls_pegarea TO lt_pegarea.

END-OF-SELECTION (Before List)

After the query has collected the pegging areas for the product-locations in the selection, the function that runs the transaction is called.

In addition to the pegging areas, the FROM and TO date timestamps and the active version (000) are passed to the function.

*
* Fill selection for all order types
*
Data: ls_sel TYPE /sapapo/ordtype_rstr.
ls_sel
option = ‘CP’.
ls_sel
low = ‘*’.
ls_sel
sign = ‘I’.
APPEND ls_sel TO ls_selectionorder_type_rtab.
*
* Convert the FROM date and time in the selection
* into a timestamp format
*
CALL FUNCTION ‘/SAPAPO/DATE_CONVERT_TIMESTAMP’
EXPORTING
iv_date     
= dtsta
iv_time     
= utimest
IMPORTING
ev_timestamp
= lv_time_from.
*
* Convert the TO date and time in the selection
* into a timestamp format
*
CALL FUNCTION ‘/SAPAPO/DATE_CONVERT_TIMESTAMP’
EXPORTING
iv_date     
= dtend
iv_time     
= utimend
IMPORTING
ev_timestamp
= lv_time_to.
*
* Active version 000 is set as default
*
lv_simid
= ‘000’.
*
* Call the transaction function using the
* pegging area table collected by the query
* and other parameters
*
CALL FUNCTION ‘/SAPAPO/RRP_SHOW_RECEIPTS’
EXPORTING
iv_simid            
= lv_simid
it_locno_source_rtab
= ls_selectionsource_locno_rtab
it_pegid            
= lt_pegarea
it_resnam_rtab      
= ls_selectionresnam_rtab
it_prio_rtab        
= ls_selectionprio_rtab
it_order_type_rtab  
= ls_selectionorder_type_rtab
iv_confr_sel        
= lv_confr_sel
iv_time_from        
= lv_time_from
iv_time_to          
= lv_time_to
iv_internal_call    
= ‘X’.

Query definition

The query itself (SQ01) is straightforward. The selection screen shows the parameters defined in the infoset. Add the others parameters as selection. This query will not have any list displayed as the transaction will be called first. Include the fields in the display anyway to make sure the code is executed.

Fig+9.png


It is also important that the query is set as ABAP List to make sure the code in the END-OF-SELECTION section is included and used in the query.

Fig 10.png

Stepping beyond

This basic query can be extended in different ways, for example:

  • Additional fields from the product-location can be added as well as complex checks to exclude pegging areas not needed. Even if the field is included in the transaction list and can be hidden with a layout; it is much more efficient to exclude it in the selection screen.
  • The planning version is hardcoded here to 000 but it can be part of the selection to allow the use of other planning versions.
  • You can have 4 different queries for the 4 different transactions or a single query with a radio button in the selection screen to choose.

Have fun.

(This post was first published on the author’s professional blog, see profile)


To report this post you need to login first.

1 Comment

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

Leave a Reply