7.70.3 MESSAGE Examples
Issuing Multiple Messages During an Abort
Issuing Messages with Dynamically Constructed Text
Issuing Messages with an *MTXT Variable as the Text
Issuing Messages with Substituted Variables
Using Messages to Instruct and Notify the User
This example shows how to issue a text message that will be shown on the user's screen:
MESSAGE MSGTXT('Welcome to the LANSA system')
Issuing Multiple Messages During an Abort
This example shows how to issue multiple messages during an abort sequence:
MESSAGE MSGTXT('=============================================')
MESSAGE MSGTXT('== EMPLOYEE DETAILS NOT FOUND IN PSLMST ==')
MESSAGE MSGTXT('=============================================')
MESSAGE MSGTXT('== FATAL ERROR - CONTACT YOUR SUPERVISOR ==')
ABORT MSGTXT('=============================================')
Issuing Messages with Dynamically Constructed Text
This subroutine demonstrates how to dynamically construct a message with all the relevant details at the time that it needs to be issued:
SUBROUTINE NAME(MESSAGE) PARMS((#MSGTXT1 *RECEIVED) (#MSGTXT2 *RECEIVED) (#MSGTXT3 *RECEIVED))
DEFINE FIELD(#MSGTXT1) TYPE(*CHAR) LENGTH(40) DECIMALS(0)
DEFINE FIELD(#MSGTXT2) REFFLD(#MSGTXT1)
DEFINE FIELD(#MSGTXT3) REFFLD(#MSGTXT1)
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132) DECIMALS(0)
USE BUILTIN(BCONCAT) WITH_ARGS(#MSGTXT1 #MSGTXT2 #MSGTXT3) TO_GET(#MSGDTA)
ABORT MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
ENDROUTINE
The subroutine can then be used to issue messages like this:
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS('Details for employee' #EMPNO 'saved to file')
Or this:
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS(#DEPTMENT ' department has been created' *BLANKS)
Issuing Messages with an *MTXT Variable as the Text
In multilingual applications you sometimes need to issue messages that contain *MTXT variables as their message text. This subroutine shows one way of doing this.
SUBROUTINE NAME(MTXTMESSGE) PARMS((#MSGDTA *RECEIVED))
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132) DECIMALS(0)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
ENDROUTINE
The subroutine can then be used to send messages as follows;
EXECUTE SUBROUTINE(MTXTMESSGE) WITH_PARMS(*MTXTDEMEMPLO05501)
Issuing Messages with Substituted Variables
This example shows how a message wording can be defined in a message file and the required details substituted as variables when the message is issued. The message would be defined like this:
|
Then the message is issued like this:
GROUP_BY NAME(#XG_EMPLOY) FIELDS(#EMPNO #GIVENAME #SURNAME #SALARY)
REQUEST FIELDS(#EMPNO)
FETCH FIELDS(#XG_EMPLOY) FROM_FILE(PSLMST) WITH_KEY(#EMPNO)
IF_STATUS IS(*OKAY)
MESSAGE MSGID(MSG0002) MSGF(MYMSGF) MSGDTA(#XG_EMPLOY)
ELSE
MESSAGE MSGTXT('Details for employee can not be found')
ENDIF
Using Messages to Instruct and Notify the User
This example demonstrates how to use messages to both instruct the user on what they should do next and notify the user about what the program is currently doing. The example gives some input instructions then begins a cycle of requesting input, notifying the user of the various processing steps as it executes them and then finally notifies the user of the completion of processing before asking for the next input.
MESSAGE MSGTXT('Input instructions appear here. Press Enter')
BEGIN_LOOP
REQUEST FIELDS(#STD_TEXT)
MESSAGE MSGTXT('Processing Step 1. Please wait.') TYPE(*STATUS)
EXECUTE SUBROUTINE(WAIT)
MESSAGE MSGTXT('Processing Step 2. Please wait.') TYPE(*STATUS)
EXECUTE SUBROUTINE(WAIT)
MESSAGE MSGTXT('Processing Step 3. Please wait.') TYPE(*STATUS)
EXECUTE SUBROUTINE(WAIT)
MESSAGE MSGTXT('Processing has completed. Please input next')
END_LOOP
SUBROUTINE NAME(WAIT)
BEGIN_LOOP TO(20000000)
END_LOOP
ENDROUTINE
If the TYPE parameter of the *STATUS messages was changed to *INFO then the messages would not appear until after the processing had been completed and the next REQUEST command is executed. The messages would then remain until the next REQUEST command is executed.
This example demonstrates how messages can be used to format variables and text into concatenated text without the need to convert data types or concatenate strings. The following messages definitions are created:
|
|
|
Then, these messages are issued with the appropriate variables. The GET_MESSAGES BIF is used in the subroutine to copy the messages to a browse list to be displayed on the screen and, if the user wants, to lines of a report for printing:
DEFINE FIELD(#PRINT) TYPE(*CHAR) LENGTH(1) LABEL('PRINT?') DEFAULT(N)
DEFINE FIELD(#EMPTXT) TYPE(*CHAR) LENGTH(78)
DEFINE FIELD(#RETCODE) TYPE(*CHAR) LENGTH(2)
DEF_LIST NAME(#EMPBROWSE) FIELDS(#EMPTXT)
DEF_LINE NAME(#EMPLOYEE) FIELDS(#EMPTXT)
REQUEST FIELDS(#PRINT)
CLR_LIST NAMED(#EMPBROWSE)
SELECT FIELDS(*ALL) FROM_FILE(PSLMST1)
MESSAGE MSGID(MSG0004) MSGF(MYMSGF) MSGDTA(#EMPNO #GIVENAME #SURNAME)
MESSAGE MSGID(MSG0005) MSGF(MYMSGF) MSGDTA(#EMPNO #DEPTMENT #SECTION)
MESSAGE MSGID(MSG0006) MSGF(MYMSGF) MSGDTA(#EMPNO #SALARY)
IF COND('#TERMDATE *NE 0')
MESSAGE MSGID(MSG0003) MSGF(MYMSGF) MSGDTA(#EMPNO #GIVENAME #SURNAME)
ENDIF
ENDSELECT
EXECUTE SUBROUTINE(SHOWMSGS)
DISPLAY BROWSELIST(#EMPBROWSE)
SUBROUTINE NAME(SHOWMSGS)
USE BUILTIN(GET_MESSAGE) TO_GET(#RETCODE #EMPTXT)
DOWHILE COND('#RETCODE = OK')
ADD_ENTRY TO_LIST(#EMPBROWSE)
IF COND('#PRINT *NE N')
PRINT LINE(#EMPLOYEE)
ENDIF
USE BUILTIN(GET_MESSAGE) TO_GET(#RETCODE #EMPTXT)
ENDWHILE
ENDROUTINE
The wording of the messages in the message file can be changed or even translated into another language without the need to change or recompile the program.