SAP BLOG Transformation Class Approach – Part 2: Implementation

SAP Blog

Kayıtlı Üye
Katılım
22 Ara 2017
Mesajlar
1,925
Tepki puanı
7
Puanları
6
Over time quite some ABAP coding is written in the context of Transformations. On one hand it is an enabler for implementing the most sophisticated requirements. On the other hand it can easily become a chaos without proper standards and guidelines. It can even become dangerous, uncontrolled and cumbersome to support having so much coding all over the place.

The “best practice” concept of Transformation Classes can help to better encapsulate, organize and maintain the source code. ABAP-OO (Object Oriented) programming principles are used – in accordance with official and de facto development standards as published by SAP SE.

In my previous blog Transformation Class Approach – Part 1: Introduction I introduced the concept of the Transformation Class approach. The purpose of this blog is to give step-by-step guidelines in creating Transformation Classes and embedding them in Transformations.

Reusable ABAP Objects


The Transformation Class approach comes along with few reusable ABAP objects. These objects should be created before you can start any Transformation Class implementation. This is a one-time action.

You can either use the respective transaction in the back-end system or use the ABAP Development Tools (ADT) in Eclipse. This is not further explained in detail.

The following Classes should be created (using t/code SE24 in the back-end system):

  • ZCL_TRFN_TEMPLATE_1
  • ZCL_TRFN_TEMPLATE_2

The following Include Programs should be created (using t/code SE38 in the back-end system):

  • ZI_TRFN_CLASS_START
  • ZI_TRFN_CLASS_END
  • ZI_TRFN_CLASS_EXPERT

Please have a look here to download the files with source code of the Classes and Include Programs. Copy and Paste the source code in the respective Class or Include Program.

Step-by-Step Guide for Regular Transformation


For the regular use case, the following steps are applicable:

  1. Create new Transformation Class
  • Copy template class ZCL_TRFN_TEMPLATE_1
  1. Change the newly created Transformation Class
  • Update Class-relevant Local Definitions
  • Implement logic in Method START_ROUTINE (if applicable)
  • Implement logic in Method END_ROUTINE (if applicable)
  • Add additional Methods (if required)
  • Activate Transformation Class
  1. Change Transformation
  • Maintain Global Data Declaration
  • Maintain Start Routine (if applicable)
  • Maintain End Routine (if applicable)
  • Activate Transformation
Step-by-Step Guide for Expert Routine Transformation


For the special use case of an Expert Routine Transformation, the following steps are applicable:

  1. Create new Transformation Class
  • Copy template class ZCL_TRFN_TEMPLATE_2
  1. Change the newly created Transformation Class
  • Update Class-relevant Local Definitions
  • Implement logic in Method EXPERT_ROUTINE
  • Add additional Methods (if required)
  • Activate Transformation Class
  1. Change Transformation
  • Maintain Global Data Declaration
  • Maintain Expert Routine
  • Activate Transformation
Naming Convention


Let’s define a naming convention to uniquely identify each Transformation Class. Keep in mind that the Class technical name cannot exceed 30 characters.

I propose to use the following naming convention: ZCL_TRFN_<target_iprov>_<seq_no>

The components of the naming convention are as follows:

  • Each Class has a fixed prefix: ZCL_TRFN_
  • <target_iprov> stands for target InfoProvider (e.g. Advanced DSO)
  • <seq_no> stands for a two-digit sequential number (e.g. 01)
Create New Transformation Class


You can either use the Class Builder (t/code SE24) in the back-end system or use the ABAP Development Tools (ADT) in Eclipse. The screenshots are showing the Class Builder.

Short instruction:

  • Enter an appropriate template Transformation Class (e.g. ZCL_TRFN_TEMPLATE_1)
  • Push button Copy
  • Compose a new Transformation Class name
  • Naming convention (suggestion): ZCL_TRFN_<target_iprov>_<seq_no>

Figure-1-Copy-Template-Transformation-Class.jpg


Figure 1: Copy an appropriate template Transformation Class

Change Transformation Class


You can either use the Class Builder (t/code SE24) in the back-end system or use the ABAP Development Tools (ADT) in Eclipse. The screenshots are showing the Class Builder.

Short instruction:

  • Properties tab: change the description in line with the Transformation
  • Class-relevant Local Definitions: maintain the Source Package and Result Package structures

Figure-2-Class-Relevant-Local-Definitions-1.jpg


Figure 2: Class-relevant local definitions (1)

Define in the Class-relevant Local Definitions the structure of Source Package and Result Package. Refer to the data declaration of the generated program and copy and paste the structures in the same way.

Figure-3-Class-Relevant-Local-Definitions-2.jpg


Figure 3: Class-relevant local definitions (2)

Display the generated program, copy the structures identified by _ty_s_sc_1 (Source Package) and _ty_s_tg_1 (Result Package) and paste the respective structure in the Class-relevant Local Definitions.

Figure-4-Example-Generated-Program.jpg


Figure 4: Example of generated program

Now you can go ahead with writing the required source code in Method START_ROUTINE and/or END_ROUTINE of your newly created Transformation Class.

Figure-5-Method-START_ROUTINE.jpg


Figure 5: Method START_ROUTINE

Figure-6-Method-END_ROUTINE.jpg


Figure 6: Method END_ROUTINE

Transformation – Global Data Declaration


Only one line of coding is required to declare the global data object. Note: always use Global and not 2nd part Global. The object name is always the same: G_R_TRFN. The reference is the newly created Transformation Class.

Figure-7-Global-Data-Declaration.jpg


Figure 7: Global data declaration

Transformation – Start Routine


Optional, i.e. only to be used if a Start Routine is applicable. One line of coding is required to call the Transformation Class. All required coding is taken care of by the Include Program ZI_TRFN_CLASS_START.

Figure-8-Start-Routine.jpg


Figure 8: Start Routine

Transformation – End Routine


Optional, i.e. only to be used if an End Routine is applicable. One line of coding is required to call the Transformation Class. All required coding is taken care of by the Include Program ZI_TRFN_CLASS_END.

Figure-9-End-Routine.jpg


Figure 9: End Routine

Conclusion


In this blog I focussed on the implementation of Transformation Classes. First, I explained that few reusable ABAP objects are required to get started. This is a one-time action. Afterwards, I discussed step-by-step guidelines in creating Transformation Classes and embedding them in Transformations. Feel free to enhance your Transformation Class with additional Methods to better organize or modularize complex coding.

Last but not least, remember that in the context of Transformation Routines certain design rules exist. Please refer to the following SAP Notes for more information:


Okumaya devam et...
 
Üst