Within a report, messages can be output to the screen for a variety of reasons. The two main reasons are error messages and progress messages output during the course of a program run.
Error messages can be output prior to starting the actual selection of data after the user has entered the parameters, or at the END-OF-SELECTION.
These type of messages are output using the MESSAGE statement and can have a variety of effects. Messages are divided into a series of classes depending on severity and include Error messages, Warning messages and Informational messages. They are output using the MESSAGE statement. Messages can be entered into a database (SE38->GOTO->MESSAGES).
Code: Select all
MESSAGE E001 WITH P_MATNR.
To identify the specific messages you are using, a Message ID or class is specified which applies to all messages referenced in your code. This is specified either in the REPORT statement like so:
Code: Select all
Report Z_Extend_Material Message-id ZST Line-Size 80 Line-Count 0 No Standard Page Heading.
Set up the Message database by double clicking on the name of the message id specified in the Message-id clause.
Enter the short text for the message class and then click the Messages tab.
For each message that you enter there can be upto 4 replaceable parameters and some associated long text. For convenience I always set message number 000 to '& & & &', where '&' denotes the replacable parameters used in the Message statement. This allows me to display a message with any text that I please should the need arise.
Below is the Message definition screen:
Note that each message is assigned a number via which it is referenced by the Message statement. Also, there is a check box titled "Self-Explanat'y". Normally this check box is checked, which is the default, but by unchecking the box and clicking the 'Long Text' button at the top of the screen, a fuller explanation of the message can be entered:
When the system issues a message that has the 'Self explanatory' check box cleared, the user is able to display the log text should they so wish to by clicking the 'HELP' key on the popup or double clicking the message on the status line:
See topic 0024 - Managing User Input for the effects on user input screens that the Message statement has.
Messages referring to Input Parameters.
It makes good programming sense to validate the users input parameters as much as possible because this prevents wasted processor time and frustrated users. These validations can occur in the AT SELECTION-SCREEN ON event.
This is an event that is processed for each parameter on the input screen if present. It is processed when the user presses the enter key or clicks the process button.
Validations can be expensive in terms of computer time. Validations that are not 'instantaneous' should only be carried out when the user clicks the process button. This is signified by SY-UCOMM having a value of 'ONLI'. Long running validations should only be used if they are shorter than the actual selection process.
Code: Select all
At Selection-Screen on p_bukrs. * Data w_butxt like t001-butxt. * If sy-ucomm = 'ONLI'. Select single butxt into w_butxt from t001 where bukrs = p_bukrs. If sy-subrc <> 0. Message E000 with text-008 p_bukrs text-009. EndIf. EndIf.
Messages At The End-Of-Selection event.
There is really only one error message that should be displayed here and that is if the Selection Event did not return any data. This can be checked by using sy-subrc if you use SELECT-ENDSELECT (a no no any way), or by checking that there is at least one line in the table by using
Code: Select all
Read Table t_table index 1 transporting no fields. If sy-subrc = 0. Perform processing. Else. Message E000 with 'No records match your criteria'. EndIf.
Messages displayed using the message command have different effects on the program depending on where they are displayed. Below is a colour coded table that identifies the action of each message type in each event of an ABAP Report program or Module Pool:
The colours refer to the following actions:
1. The message is displayed in a dialog box. After exiting the dialog box, the program terminates, the system returns to the call position of the first program of the current call sequence and all internal sessions of the call sequence are deleted.
2. The message is displayed in the status bar. PAI processing terminates and the system returns to the current screen without triggering the event PBO. By default, the message is displayed in the status bar of the current window. When sending the error message in a dialog module that is called in the dynpro flow logic outside a processing chain defined by CHAIN behind a FIELD statement, the only field that is ready for input is the input field specified behind FIELD. When sending the error message in a dialog module that is called inside a processing chain defined by CHAIN, all input fields in the processing chain that are specified behind FIELD are ready for input. After a user action, the PAI processing continues at the position described under Handling of Messages for Event PAI.
3. The message is displayed in a dialog box. After exiting the dialog box, the program continues using the statement that follows MESSAGE.
4. The program continues using the statement that follows MESSAGE. In the next screen, the message is displayed in the status bar of the current window.
5. The PAI processing is interrupted and the system returns to the current screen without triggering the event PBO. By default, the message is displayed in the status bar of the current window. The fields decribed under item 2 are ready for input. If the user confirms the current field contents using the Enter key without entering new values, the program continues with the statement that follows MESSAGE. If the user enters one or more new values, the processing continues after a user action as described under item 2.
6. The program terminates with the runtime error MESSAGE_TYPE_X, and the system displays its short dump which contains the message-ID and the short and long text of the message.
7. During the POH processing, the POV processing, and the handling of the a function code of the type "E", the sending of error messages or warnings is not allowed. An exception that cannot be handled is raised.
8. The selection screen processing is interrupted and the system return to the current selection screen with triggering the event AT SELECTION-SCREEN OUTPUT. By default, the message is displayed in the status bar of the current window. The input fields of the selection screen that have been specified using the additions of the statement AT SELECTION-SCREEN of the current event block are ready for input. The selection screen processing continues after a user action using the current selection screen event. Previous selection screen events are not triggered.
9. The selection screen processing is interrupted and the system returns to the current selection screen without triggering the event AT SELECTION-SCREEN OUTPUT. By default, the message is displayed in the status bar of the current window. The fields decribed under item 8 are ready for input. If the user confirms the current field contents using the Enter key without entering new values, the program continues with the statement that follows MESSAGE. If the user enters one or more new values, the processing continues after a user action as described under item 8.
10. The event block of the current list event is interrupted and the display of the list level on which the list event was triggered remains. By default, the message is displayed in the status bar of the current window.
11. The program is interrupted and an empty screen with an empty GUI status is displayed. By default, the message is displayed in the status bar of the current window. The system returns to the call position of the program after a user action
These are output using the function module SAPGUI_PROGRESS_INDICATOR, which is wrapped up in the routine SHOW_PROGRESS. These messages do not halt processing and can be used to display a stopwatch showing the percentage of the progress that has completed:
Code: Select all
Describe table t_postings lines w_max. Loop at t_Postings. Move sy-tabix to w_cur. Clear g_report_line. Move-Corresponding t_Postings to g_report_line. If t_Postings-DrCrk = 'H'. Compute g_Report_Line-Credit = Abs( t_Postings-Hsl ). Else. Compute g_Report_Line-Debit = Abs( t_Postings-Hsl ). EndIf. Perform CheckBreaks using g_report_line. Perform WriteLine using g_report_line Col_Normal. * * End of page when printing ? * If sy-linct = 64 and sy-linno = 63. Perform TableLine. EndIf. Perform Show_Progress using Text-030 w_max w_cur 5. EndLoop.
Code: Select all
Form Show_Progress using pu_text type NaTxt pu_max type i pu_done type i pu_diff type i. * Statics s_prcnt type p decimals 2. * Data: w_text type natxt, w_prcnt type Decimal_Value, w_max type Decimal_Value, w_done type Decimal_Value, w_diff type Decimal_Value. * Move 0 to w_prcnt. If pu_max <> 0. Move pu_max to w_max. Move pu_done to w_done. Compute w_prcnt = ( w_done / w_max ) * 100. Write w_prcnt to w_text decimals 2. Condense w_text. Concatenate pu_text w_text '% Complete' into w_text separated by ' '. Else. Move pu_text to w_text. EndIf. If w_prcnt < s_prcnt. Move 0 to s_prcnt. EndIf. Compute w_diff = w_prcnt - s_prcnt. If w_diff > pu_diff or pu_diff = 0. Move w_prcnt to s_prcnt. Call Function 'SAPGUI_PROGRESS_INDICATOR' Exporting PERCENTAGE = w_prcnt TEXT = w_text Exceptions OTHERS = 0. EndIf. EndForm.