Select language:

ABAP Routine

Use

With the transformation ABAP Routine, you can transform the data for an input table into an output table. You can implement any transformation with ABAP yourself.

Prerequisites

You need authorization for authorization object RSANPR and activity 36 (enhanced maintenance) to insert ABAP routines into an analysis process or to change them.

Features

You can access all rows in the input table in this ABAP routine. The output table can contain any number of rows. This makes the following calculations possible, for example:

  • Determining an ABC class

  • Determining a lifetime period

  • Statistic functions such as Number of Customers That Have Made Purchases per Period

You can use different types of fields in your ABAP routines:

  • Grouping fields:

    Grouping fields are available in the routine as input fields. They are output to the output table of the node unchanged.

    You use the grouping fields to define a group of data records. All data records with the same values in the group field form one group. The data in the input table for the node are also grouped according to grouping fields and the routine is only called with the data for each group. If, for example, determination of the ABC class is to be implemented per customer group, the partitioning of the data according to customer groups will already be done by the routine node. The routine is then called up multiple times with the data for each customer group.

  • Source fields:

    Source fields are available in the routine as input fields. However, they are not output to the output table of the node.

    You can transform source fields into other fields in the routine. If you want to output a source field unchanged into the output table of the node it has to be defined as a target field as well. All selected source fields are transferred to the list of target fields as a suggestion.

  • Target fields:

    Target fields are not available in the routine as input fields. However, they are only output to the output table of the node.

    You can use a target field, for example, to include an additional column in the output table. You define a target field by specifying a unique field name, a description and an InfoObject. The fields appear in the subsequent nodes with the field names and the description. The InfoObject is used to assign type properties to the field (type, field length, check table).

Implementing the Routine:

The grouping fields in a structure are available in the routine. They cannot be changed. Thus the fields are not contained in the output structure of the routine. The columns with the grouping fields are automatically enhances in the output table of the node afterwards.

The implementation of the data transformation occurs on the Routine tab page. Here you are implementing a subprogram that is called for each group of data records. Data transfer takes place using three parameters:

Parameter

Description

is_group

Contains the structure with the grouping fields

it_source

Contains the input table without the grouping fields

et_target

The output table for the routine. This table must be filled in the routine. After the routine has ended, the data in this table is enhanced with the columns with the grouping fields and the subsequent nodes are transferred.

The following restrictions apply:

  • The sequence of data records in the data package is not guaranteed. Before the transformation is called, the data is sorted according to grouping fields. Especially due to this sorting, a sequence that already existed from a previous transformation is often destroyed.

  • The sequence of the data package is not guaranteed.

  • Data for global variables may not be swapped between different calls of routines.

  • The sequence of fields in the data package is not guaranteed.

Activities
  1. Determine the grouping and source fields by filling the appropriate lists on the Source Fields tab page.

  2. Define the target fields on the Target Fields tab page by specifying a unique field name, a description and an InfoObject.

    If you have previously selected source fields from the Source Fields tab page, the fields are transferred to the list of target fields as a proposal. You can delete or enhance these fields.

  3. Implement the data transformation on the Routine tab page.

    Program code that copies the data for the input table into the data for the output table is generated as a proposal.