![](/cvo_files/imgs_sap_abap/logos/logo_cvo_academy_it.png)
✒️ABAP El evento AT SELECTION-SCREEN y los tipos de mensajes
ABAP El evento AT SELECTION-SCREEN y los tipos de mensajes
![ABAP El evento AT SELECTION-SCREEN y los tipos de mensajes ABAP El evento AT SELECTION-SCREEN y los tipos de mensajes](https://www.cvosoft.com/cvo_files/imgs_sap_abap/og-images/287.jpg)
Message Types
Messages in ABAP can be pop-ups appearing in the GUI or displayed at the bottom, informing the user about entered data. They can be of the following types:
- S: Success - green checkmark icon
- I: Information - on-screen dialog window; program execution continues after closure
- E: Error - terminates selection screen processing
- W: Warning - similar to error message but user can skip using the enter key
- A: Termination - displayed in a dialog window and ends the program
- X: Dump or runtime error - interrupts the program at the occurrence moment due to incomplete program logic
IF v_input_value = v_expected_value.
MESSAGE s001(ZMESSAGE_CLASS) WITH 'Validation successful'.
ENDIF
Message Classes
To work with messages in ABAP programs, we first need to create a message class. A message class is an ABAP object used to store all messages related to a SAP project or transaction, created through transaction SE91. Messages have a code, are created separately from the main program, need activation, and inclusion in objects. In the code, the MESSAGE statement is used as follows:
MESSAGE e001(ZMESSAGE_CLASS) WITH 'Parameter1' 'Parameter2' ... 'ParameterN'.
The 'e' in 'e001' denotes the message type, '001' is the message number, and what's in parentheses (ZMESSAGE_CLASS) is the message class. Subsequently, different optional parameters follow the WITH keyword.
IF v_input_value < v_expected_value.
MESSAGE e001(ZMESSAGE_CLASS) WITH 'Date must be greater or equal to the current date'.
ENDIF
Messages with variable content can be created using '&' symbols. Each '&' can hold up to 50 characters, and messages can have a maximum of 4 variables. To use '&' as text, write '&&'. Each message class can store up to 999 messages.
IF v_input_value < v_expected_value.
MESSAGE e001(ZTEST_CLASS) WITH 'Date must be greater or equal to the date &', sy-datum.
ENDIF
AT SELECTION-SCREEN Event
To validate input parameters, we use the AT SELECTION-SCREEN event. If an error message is issued within this event, the program waits for the user to re-enter a value for the selection screen parameter. To prevent the program from restarting on error, declare an AT SELECTION-SCREEN ON event for each parameter to be validated.
PARAMETERS: p_input_date LIKE sy-datum,
p_name(10) TYPE c.
AT SELECTION-SCREEN ON p_input_date.
IF NOT p_input_date IS INITIAL AND p_input_date < sy-datum.
MESSAGE e001(ZTEST_CLASS) WITH 'Entered date is earlier than today'.
ENDIF.
AT SELECTION-SCREEN ON p_name.
IF NOT p_name IS INITIAL AND p_name CA '012345678'.
MESSAGE e001(ZTEST_CLASS) WITH 'Name cannot contain numbers'.
ENDIF.
If an error occurs in a START-OF-SELECTION event, a DUMP will occur, preventing further interaction with the program. To avoid this, use the DISPLAY LIKE clause at the end of messages, followed by the message type.
IF v_error_condition.
MESSAGE e001(ZTEST_CLASS) WITH 'Error occurred' DISPLAY LIKE 'E'.
ENDIF
E.g.
*&---------------------------------------------------------------------*
*& Report ZTEST_ABAP_JEGA_7
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_abap_jega_7.
*---------------------------------------------------------------------*
* Declaración de variables
*---------------------------------------------------------------------*
DATA: v_flag(1) TYPE c,
v_nombre(10) TYPE c.
*---------------------------------------------------------------------*
* Pantalla de selección
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(66) TEXT-002.
PARAMETERS p_fecha LIKE sy-datum OBLIGATORY DEFAULT sy-datum.
SELECTION-SCREEN END OF LINE.
PARAMETERS p_nombre TYPE string.
SELECTION-SCREEN END OF BLOCK b1.
*---------------------------------------------------------------------*
INITIALIZATION.
*---------------------------------------------------------------------*
CLEAR v_flag.
*---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
*---------------------------------------------------------------------*
IF p_fecha <= sy-datum.
v_flag = 'X'.
LOOP AT SCREEN.
IF screen-name EQ 'P_NOMBRE' OR screen-name EQ '%_P_NOMBRE_%_APP_%-TEXT'.
" El parámetro Nombre no se visualiza
screen-input = '0'.
screen-active = '0'.
screen-invisible = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*---------------------------------------------------------------------*
IF p_fecha < sy-datum.
MESSAGE s003(z_prueba) WITH 'La Fecha debe ser mayor o igual a la fecha actual' DISPLAY LIKE 'E'.
ENDIF.
*---------------------------------------------------------------------*
START-OF-SELECTION.
*---------------------------------------------------------------------*
IF v_flag IS INITIAL.
WRITE:/(10) 'Nombre', p_nombre.
ENDIF.
WRITE:/(10) 'Fecha:', p_fecha.
 
 
 
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