3051 Readings
ABAP
SAP for 12 years
Posted by Yann MORINEAU
7 years ago
Modified 7 years ago


Licence Creative Commons Attribution - Pas d'Utilisation Commerciale - Pas de Modification 4.0 International.

Partager — copier, distribuer et communiquer le matériel par tous moyens et sous tous formats

Contants class

One of my previous tutorials was the creation of a group of types to avoid reporting the same types or constants in differents programs, functions, BAdIs...

Mickaël T, SAPtoolBOX's member, had specified  :

"In an OO environment as BI / BPC the most coherent remains to do exactly the same things but in a class. See even handle constants and type in a useful class development. The group of types was used with the groups of functions, the groups of programs, etc... In OO abap using classes keeps all homogeneous."

That is why I suggest you today setting up this management of constants or types by using a class.

At first we shall create a class containing our constants and in the second, a REPORT program  using them.

 

1.Class and constant creation

1.1.Class creation

Start the SE24.

img

 

Enter a name..

img

Click the button img

 

Add a description.

img

Leave the options marked by default. The class must be "Public".

Click on img 

 

For the example, we do not generate "OT" so click on  img

 

1.2.Constant creation

In the tab "Attributes", it is enough to add the constant.

img

It is necessary to set "Public" for the constant visibility to be used by any program.

 

Activate by clicking on img

 img, the class is active.

 

2.Program creation and use of constant.

2.1.Program creation

Start the SE80.

img

 

Enter a name.

img

Click on img.

img

Click on the button img

 

img

For example, I uncheck "With TOP INCL." and I agree img

 

img

To create a report, select "Executable program" and save img.

 

As for the class I create a local object.

img

Click on img

 

The program is ready.

img

 

2.2.Use of constant

img

 

The autocomplete ensures accessibility elements of the class, here the constant.

img

 

The example code

REPORT Z_YMO_TEST3.

*Data déclaration

DATA v_value TYPE string.

*Value constant to the variable

V_VALUE = ZCL_MY_CLASS=>CO_MY_CONSTANT.

*Value display

WRITE V_VALUE.

 

The result

img

 

To remember

  • In an environment OO, it is more coherent to declare his constants in a class rather than in a group of types.
  • Declare a public class to be available in any program.

Pub

Sign in or Sign up to ask questions.

Latest tutorials from the same author

imgBPC

Déboguer un package

Astuce pour déboguer un package ...

Posted 6 years ago
Modified 6 years ago
6157
imgBPC

BPC BI and Source system

BPC Overview ...

Posted 6 years ago
Modified 6 years ago
6923
imgBPC

Vider le cache BPC

Vider le cache BPC avec UJA_REFRESH_DIM_CACHE ...

Posted 6 years ago
Modified 6 years ago
5277
imgBPC

BPC, BI et Système source

Vue d'ensemble de BPC ...

Posted 6 years ago
Modified 6 years ago
5966