Entering content frameMessage Handling in Table Modules Locate the document in its SAP Library structure

If you want to send user messages from table modules, you must first have defined messages for the individual modules in the Modules table. The system cannot output a message for a table module where none is defined, but will simply reset the corresponding dependent values.

When you query dependent data from context instances using the DEMAND statement, you can decide whether the system should handle the user message or whether you want to handle it yourself in the program.

Message Handling - System

If you want the system to handle the message, use the basic form of the DEMAND statement without the MESSAGES option. The system will then behave as though the following statement occurred after the DEMAND statement:

MESSAGE ID 'Message Id' TYPE 'T' NUMBER 'Number'
WITH 'Variable 1' .... 'Variable 4'.

The system takes the arguments for the MESSAGE statement from the corresponding entries in the Modules table. Note that the system reaction to the various message types depends on the current user dialog (dialog screen, selection screen or list).

Message Handling - Program

If you want to catch the message in your program, use the DEMAND statement using the option MESSAGES INTO <itab>. To do this, you need to define an internal table <itab> with the structure SYMSG. The system deletes the contents of <itab> table at the beginning of the DEMAND statement. Whilst it is processing the context, the system does not output or react to any messages, but writes their ID to <itab>. If there are messages in <itab> following the DEMAND statement, the system sets the return code SY-SUBRC to a value unequal to zero.

This enables you to prevent automatic message handling with contexts and allows you to program your own using the entries in <itab>. This is important, for example, if you want to make particular fields on an entry screen ready for input again. In this case, you must base your message handling on the fields (using the FIELDS statement in screen flow logic, or the ABAP statement AT SELECTION-SCREEN for selection screens), and not on fields in the context.

Example

Suppose the Modules table in context DOCU_TEST1 (see Using Tables as Modules) contained the following entries for module SPFLI:

This graphic is explained in the accompanying text

To demonstrate system message handling, execute the following program:

REPORT  RSGCON02.

DATA: C_FROM LIKE SPFLI-CITYFROM,
      C_TO   LIKE SPFLI-CITYTO.

CONTEXTS DOCU_TEST1.

DATA: CONTEXT_INST TYPE CONTEXT_DOCU_TEST1.

SUPPLY CARRID = 'XX'
       CONNID = '400'
       TO CONTEXT CONTEXT_INST.

DEMAND CITYFROM = C_FROM
       CITYTO   = C_TO
       FROM CONTEXT CONTEXT_INST.

WRITE: / C_FROM, C_TO.

The program terminates with the following error message:

No entries found for key XX 0400

To demonstrate program message handling, execute the following program:

REPORT  RSGCON03.

DATA: C_FROM LIKE SPFLI-CITYFROM,
      C_TO   LIKE SPFLI-CITYTO.

DATA ITAB LIKE SYMSG OCCURS 0 WITH HEADER LINE.

CONTEXTS DOCU_TEST1.

DATA: CONTEXT_INST TYPE CONTEXT_DOCU_TEST1.

SUPPLY CARRID = 'XX'
       CONNID = '400'
       TO CONTEXT CONTEXT_INST.

DEMAND CITYFROM = C_FROM
       CITYTO   = C_TO
       FROM CONTEXT CONTEXT_INST MESSAGES INTO ITAB.

WRITE: / C_FROM, C_TO.

LOOP AT ITAB.
  WRITE: / ITAB-MSGTY, ITAB-MSGID, ITAB-MSGNO,
           ITAB-MSGV1, ITAB-MSGV2.
ENDLOOP.

The program outputs the following:

E  AT  107  XX  0400

Instead of terminating with an error message, the program stores the message in the internal table ITAB, where it is available for you to process further.

 

 

 

Leaving content frame