Simplify SAP R/3 development with Excel VBA/VB RFC  
Home> UserExit>COPA0001



CO-PA: User Exits
Enhancements for deriving characteristic values

Profitability Analysis lets you use SAP enhancement COPA0001 to enhance the standard functions for deriving characteristic values by programming your own derivation steps.

You can insert the enhancements in the derivation strategy, wherever you choose and as often as required.

Check to make sure that you really need it to define the desired derivation logic. You can achieve a lot by sorting the derivation steps correctly and using step and field attributes along with temporary fields.

As with the other types of derivation step, you can specify the source and target fields that you want to use in the enhancement.

In function module EXIT_SAPLKEAA_001, you can define your own source code in include ZXKKEU011. There you can use:

  • The fields (which you specified in the derivation step) in the parameters I_COPA_ITEM and I_GLOBAL,
  • The name of the operating concern in I_OPERATING_CONCERN,
  • The derivation date in I_DERIVATION_DATE, and
  • (if desired) a step ID in I_STEP_ID with which to identify your enhancement steps if you use more than one strategy.

The CO-PA characteristic values for the source fields specified in the derivation step are transferred in I_COPA_ITEM in the form "CE0xxxx structure", whereby xxxx corresponds to the name of the operating concern. To access the individual fields, you first need to assign this parameter to a variable with a matching structure (as described in the example below).

In the structure I_GLOBAL, some global information can also be transferred, as well as the temporary work fields USERTEMP1 through USERTEMP8. For example, you can make the source code dependent on whether derivation is called up in planning or for actual data (field PLIKZ) or called up within the realignments (field REALIGNMENT_MODE).


The source code you write is stored in an include file. The following include file is provided for this function module:

Components 001 and 002 for derivation using COPA0001 are no longer available from Release 4.0 onward. If you upgrade your system from an earlier release, however, the system can still access these components, and thus they still function. When you make the upgrade, the system automatically checks whether this customer enhancement was active. If so, derivation steps that use these components are automatically created at the beginning and the end of the derivation strategy.

Check whether the code programmed in the exit still works in the new release.

For more information, see the section on derivation in the online documentation for CO-PA.

  1. Only use these enhancements if it is absolutely necessary. This can help you avoid unnecessary modifications following upgrades.
  2. In the enhancement step, only enter those source and target fields actually defined in the enhancement. If you want to define several logically independent derivation steps in an enhancement, you should separate these into separate enhancement steps. This makes it possible for the system to recognize the logical dependencies in the enhancement automatically, and use this to optimize processing.
Important Information

Characteristic derivation is called up in a number of different places in the system, both online and in the background. Some of the programs that call up derivation are located in critical places, such as the integrated data update in the Financials applications. This places some additional requirements and restrictions on the source code of your enhancements.

  • No COMMITs

No database COMMITs can be carried out in your source code because this would jeopardize the consistency of the data updated in the different applications. In particular, this means that you cannot issue error messages, since these implicitly force a COMMIT.

  • No "hard" error messages

If you identify error situations in the enhancement, use a MESSAGE ... RAISING DERIVATION_FAILED to tell the calling program that an error has occurred, or simply set the return parameter E_FAILED to "X". In both cases, the derivation processor performing the callup then treats the message as an error and passes it on.

  • No interactive functions

User-interaction - such as using dialog boxes - is not allowed.

Special characteristics of source and target fields

  • Only source values specified in I_COPA_ITEM and I_GLOBAL are available

The source and target fields of the enhancement are defined in Customizing. Only the values in the source and target fields defined there are transferred in the transfer structures I_COPA_ITEM and I_GLOBAL . All other values are blank or undefined.

  • Enhancement is not always called up

When you specify source and target fields for the enhancement in Customizing, the system sets the field attributes "Initial value not allowed" for the source fields and "Do not overwrite" for the target fields. This means that the enhancement is only called up if all the source fields contain values (other than zero) and at least one target field is blank. Of the values entered in the return structure E_COPA_ITEM, only those that were not already filled are transferred. If you want to change this logic, change the attributes of the source and target fields so that the source fields can be initial and/or the target fields can be overwritten.


Derivation of the SOP product group using an enhancement step

Operating concern Z001 contains a user-defined characteristic WWSOP ("SOP product group"). You would like to transfer the SOP product group to this user-defined characteristic.

tables: pgmi.
data: ce0_z001 like ce0z001.
data: begin of sop_work_area,
prgrp like pgmi-prgrp,
date like pgmi-datum,
end of sop_work_area.

Note that, once you have created and activated an enhancement, it becomes active in all operating concerns. For this reason, you need to include a line in your code that asks for the operating concern name.

case i_operating_concern.
when 'Z001'.

You need to tell the calling program that you have stored a user exit code for this operating concern. It is important to do this because the derivation processor will no longer call up the user exit in future (within the same transaction or report) if you fail to do so.

e_exit_is_active = 'X'.

Move the unstructured data field to one in structure CE0xxxx. Then the fields of the operating concern can be addressed directly.

ce0_z001 = i_copa_item.

Customer's own code: transfer SOP product group to the user-defined characteristic WWSOP.

case i_step_id.
when 'SOP'.

The step ID is "SOP". In this case, the SOP group should be read.

select prgrp min( datum ) up to 1 rows
into sop_work_area
from pgmi
where nrmit = ce0_z001-artnr
and wemit = ce0_z001-werks
and datum >= i_derivation_date
group by prgrp.
ce0_z001 = sop_work_area-prgrp.

If no value is found in table PGMI, derivation has failed. This is communicated to the main program by the value "X" for e_failed.

if sy-subrc <> 0.
e_failed = 'X'.
* Issue error message:
* 'No SOP group found for & in plant &'
message s900(zz) with ce0_z001-artnr ce0_z001-werks

Do not forget to send the result of the derivation to the main program:

e_copa_item = ce0_z001.

Allowed source fields
  • All user-defined characteristics
  • All characteristics copied from SAP tables
  • Customer number (KNDNR)
  • Product number (ARTNR)
  • Billing type (FKART)
  • Sales order number (KAUFN)
  • Sales order item number (KDPOS)
  • Company code (BUKRS)
  • Controlling area (KOKRS)
  • Business area (GSBER)
  • Profit center (PRCTR)
  • Sales organization (VKORG)
  • Distribution channel (VTWEG)
  • Division (SPART)
  • Cost object (KSTRG)
  • WBS element (PSPNR)
  • Plant (WERKS)
  • All quantity unit fields
  • All fields in GLOBAL
Allowed target fields
  • All user-defined characteristics
  • All characteristics copied from SAP tables
  • Customer number (KNDNR)
  • Product number (ARTNR)
  • Business area (GSBER)
  • Profit center (PRCTR)
  • Sales organization (VKORG)
  • Distribution channel (VTWEG)
  • Division (SPART)
  • Plant (WERKS)
  • All quantity unit fields
  • Temporary fields

Technical fields and fixed characteristics in your operating concern

  • EXIT_SAPLKEAA_001: Up to Release 3.1: Exit at the Start of Characteristic Derivation
  • EXIT_SAPLKEAA_002: Up to Release 3.1: Exit at the End of Characteristic Derivation
  • EXIT_SAPLKEDRCOPA_001: From Release 4.0: Exit in Characteristic Derivation