Wednesday, 1 November 2023

Create new CO-PA Margin Analysis characteristic with existing table as code list

Introduction


In S/4HANA OP2022 there are several ways to create customer specific characteristics for Margin Analysis. While using transaction KEA5 might seem like the most intuitive and classic way to create new characteristics it will make it very hard to use those with any Fiori applications.

The “new” Fiori enabled way to create characteristics would be by using the Fiori app F1481 “Custom Fields” with the “Market Segment” business context.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Using this method, CO-PA fields can be created as text, numerical text (which means just numbers) or with a predefined code list. This code list however, must be manually defined in the Fiori app as well and cannot reference any existing tables in the system.

To achieve that – using an existing standard or custom table – as value help for a custom CO-PA characteristic a third option is available. As CO consultant in one of my customer’s projects, I was faced with implementing that third way. Because it proved to be quite tricky at times, I want to share my findings in this blog.

Disclaimer: I am not involved in the development of any functionalities regarding this topic and can therefore not guarantee the correctness of the information given nor provide insights into future developments. All my findings are based on S/4HANA OnPremise 2022 “Initial Shipment Stack” (OP2022 FPS0)

Prerequisites


Authorization

You’ll need access to the Fiori apps

  • F1481 – Custom Fields
  • F1589 – Register Extensions for Transport
  • F1590 – Configure Software Packages

which are all included in the SAP_BASIS_BC_EXT business catalog.

Additionally, you’ll need to have developer privileges in the backend system and the required authorization to access the S/4HANA System via the ABAP Development Tools (Eclipse) IDE. (In case of connection issues later, check transaction SU53 for missing authorizations.)

Tools

To create custom CDS Views for your value help, you’ll need to access the system with the ABAP Development Tools IDE.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Basis Configuration

SAP Basis needs to setup the so-called adoption transport organizer in with transaction S_ATO_SETUP. If you’ve got authorization, you can also check if it is configured in that transaction:

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Implementation of custom characteristic


Append new field to ACDOCA Include

As a first step using transaction SE11 you’ll need to create your new custom field in the INCL_EEW_MARKET_SEGMENT_PS include view.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

After opening the view, you can click “Append Structure…”. If no additional structure has been created yet, you’ll directly get the option to input the append name. Otherwise, you’ll see an overview of appends where you need to click the “create” icon.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

The name of your append structure must comply with the prefix or namespace configured in the adoption transport organizer (S_ATO_SETUP). In this case “ZZ1_”

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

In the field “Component” define your fields name. The component type should match the type used for the corresponding field in your value table.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

By clicking the key symbol, you can maintain the check table.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Here you’ll need to reference your existing table you want to use to validate the characteristic values.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

After the foreign key was successfully applied, you can activate your append structure using the wand symbol. Note: This step can (and probably will) take a few minutes.

Activate Fields for use in the Custom Fields app


If you’ve successfully saved and activated the append structure, you can now publish your field into the Custom Fields Fiori app. To do that, start transaction SCFD_EUI and select table ACDOCA and all fields complying to your previously created field.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

You should now see a list of all fields that “Can Be Enabled” which hopefully includes yours. If it does, select it and click “Enable”

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

In the resulting pop-up window select “Generate Value Help”. This will generate the required CDS View code for the Value Help View. Important: Only the text will be generated for you to manually created the required views in ADT. This button does not directly create any development objects.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

To actually create the required CDS views create two new Data Definitions in your previously selected package using ADT. Here you can paste the generated text from both the “Code View” and “Text View” tabs. Only adjust/replace the text printed in bold. The Fiori display name of your field is determined by the data element of your key field.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

As you might not be able to activate the CDS Views individually due to circular references, use the activate all button.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

If you are not using a language differentiation for your Text View, you can not remove the language key! Instead uncomment the “key $session.system_language as Language” statement.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Once your CDS Views are activated, you can insert the Code View as Value Help View and continue activating your custom field. Make sure to select the same development package used earlier.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Note: There might be an error displaying the use of a wrong ABAP Language Version. Do NOT change your packages language version! Language version Standard must be used.

After entering a transport, activation of the field might take a few minutes.

Configure your field in the custom fields app


If activated successfully, transaction SCFD_EUI should now display the field with status “Enabled”

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Additionally, it should now be visible in the Custom Fields Fiori application. By adding the “Origin” field via the settings, you can see, that your field origin is “ABAP Development”. Fields created directly in the app will display “Custom Fields” as origin.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Add your field to the operating concern


As a last step to use your new characteristic properly, you’ll need to add it to your operating concern’s data structure. This can be done in the classical way with transaction KEA0.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Congratulations! After generating the operating concern’s new structure you’re all done and can use your custom CO-PA characteristic.

Troubleshooting


As I’ve encountered some issues along the way, I want to also share some troubleshooting hints.

Transaction SCFD_FIELDVIEWER

The most important tool when troubleshooting any issues with custom fields is the transaction SCFD_FIELDVIEWER:

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

Here all your custom fields are listed, and several options are available to recover failed activations, deep dive into error and change logs and run the “Repair Fields” assistant.

Custom characteristic and Universal Allocation

If you want to use your characteristic for allocations in the “Manage Allocation” app with context market segment, you might encounter the issue, that despite being able to select specific fields as receiver, no values are displayed when trying to assign the receiver basis. If this happens, check out SAP note 3105083 https://me.sap.com/notes/3105083. Your field might not have been generated in the T800D table. In this case you can create an entry into the maintenance view V_T800D via transaction SM30 which looks like the following screenshot only with an adjusted field name:

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials

No comments:

Post a Comment