I had tried my hand a little bit at C language. I think all of you who have even a little knowledge of C must be familiar about the CLRSCR function. The CLRSCR function in C i.e. Clear Screen function in a C program clears the previous interactive display for you and throws a fresh blank screen when the program is called again.
I always wanted to simulate that on iSeries and wondered whether it was possible on iSeries. The answer is YES it is possible. On the iSeries, that interactive display is the "Display Program Messages" screen.
Suppose, you are running a RPG program and you want to check whether the control is reaching at a particular subroutine/statement no in your program or not. You can check it by using DSPLY opcode in the RPG program. The DSPLY opcode shows you the value of a particular variable on "Display Program Messages" screen.
Suppose you have a PF called EMPINF with record format REC and is having data as shown below.
EACCT ENAME ESEX 000001 231 XXX M 000002 452 RAWAT M 000003 383 PARAG F 000004 862 KKK M 000005 769 HARRY M 000006 298 PARKER M
Then, you have a RPG program REMP that reads the records from this file. You just want to check that whether your program is reading all the records from EMPINF file. For this you can use DSPLY opcode with Employee name field (ENAME) in factor 1 in Do While loop as shown below.
FEMPINF IF E DISK F* C* C CALL 'CLRSCR' 12 C *IN23 DOWNE *ON C READ REC 23 C *IN23 IFEQ *ON C LEAVE C ENDIF C ENAME DSPLY C ENDDO C MOVE *ON *INLR
CLRSCR is a CL program as shown below :
PGM RMVMSG PGMQ(*EXT) CLEAR(*ALL) ENDPGM
First of all, comment out the statement CALL 'CLRSCR' 12 in RPG program and then compile and run the program. You'll see that the names of all the employees are being shown from physical file EMPINF on the "Display Program Messages" screen. Now, run the RPG Program once more. You'll notice that again the names of all the employees are being shown from physical file EMPINF on the "Display Program Messages" screen but the values shown by the previous call to RPG program are still present on the "Display Program Messages" screen.
But you want that each time your program is called, the "Display Program Messages" screen should be refreshed i.e. it should be cleared and should not have any values or messages thrown by previous program calls.
How do you do this?
Just uncomment the statement CALL 'CLRSCR' 12 in RPG Program & then compile and run the program. Now, every time you run the program, the "Display Program Messages" screen will be refreshed first, i.e. no previous values or messages in it and you'll see the names of all the employees are being shown from the physical file EMPINF for your current program call.
The CL program CLRSCR clears the "Display Program Messages" screen. Actually, "Display Program Messages" screen is having all the values and messages which are sent to your job's (i.e. the session in which you are logged in) External message queue which is *EXT. When CL program CLRSCR is called from RPG Program REMP, it clears your job's External message queue and hence every time a Fresh "Display Program Messages" screen is shown.
Please note that the RMVMSG command used in CL Program can not be entered on command line as it is not allowed to enter it interactively. That's why I have made this 3-line CL program.
I hope this clear screen in the iSeries works for all of you and especially for those of you who are C fans!
This was first published in January 2003