![](/cvo_files/imgs_sap_abap/logos/logo_cvo_academy_it.png)
✒️ABAP La creación de una clase global
ABAP La creación de una clase global
![ABAP La creación de una clase global ABAP La creación de una clase global](https://www.cvosoft.com/cvo_files/imgs_sap_abap/og-images/9.jpg)
Creating a Global Class
To make our class usable in any program we create, we'll go through the Class Constructor corresponding to transaction SE24.
- Entering Transaction SE24:
- Navigate to transaction SE24.
- In the Object Type field, type 'Z_CL_VEHICLE' and create.
- Selecting Class Option:
- In the next window, select the 'Class' option and proceed.
- Setting Description:
- In the subsequent window, input the description "Global class for vehicles", then save and create a local object.
- Defining Class Attributes:
- Now, let's define the attributes of the class in their respective tab.
- Defining Methods:
- For the method 'DISPLAY_WRITE', let's create parameters.
- Establishing Exceptions:
- For the same method, set exceptions by clicking on 'Exceptions'.
- Creating Events:
- In the Events tab, create the event.
- Creating Types:
- Under the Types tab, create the types for use within our global class.
- Save and Activate:
- Finally, save and activate the class.
E.g
CLASS z_cl_vehiculo DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES marca_vehiculo TYPE char30 .
DATA speed TYPE i .
DATA max_speed TYPE i .
DATA stop TYPE i .
DATA write TYPE i .
EVENTS cambio_estado_vehiculo .
METHODS increase_speed .
METHODS calculate_stop .
METHODS display_write
IMPORTING
!p_parametro TYPE p
!p_resultado TYPE p
EXCEPTIONS
vehiculo_no_existe .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS z_cl_vehiculo IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method Z_CL_VEHICULO->CALCULATE_STOP
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD calculate_stop.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method Z_CL_VEHICULO->DISPLAY_WRITE
* +-------------------------------------------------------------------------------------------------+
* | [--->] P_PARAMETRO TYPE P
* | [--->] P_RESULTADO TYPE P
* | [EXC!] VEHICULO_NO_EXISTE
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD display_write.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method Z_CL_VEHICULO->INCREASE_SPEED
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD increase_speed.
ENDMETHOD.
ENDCLASS.
 
 
 
Sobre el autor
Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.
Jaime Eduardo Gomez Arango
Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C
✒️Autor de: 149 Publicaciones Académicas
🎓Egresado de los módulos:
- Carrera Consultor en SAP Fiori
- Carrera Consultor ABAP Nivel Avanzado
- Carrera Consultor ABAP Nivel Inicial
Disponibilidad Laboral: FullTime
Presentación:
Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.
Certificación Académica de Jaime Gomez