CL Programming Restrictions Only five *FILE per program –Display file or Database File Can’t update Database Files Can’t create reports
File Commands DCLF - Declares a File e.g. DCLF FILE(STUDENTS) RCVF - Reads a record from a screen or database file SNDRCVF is used only with display files, NOT database files! SNDPGMMSG – Send Program Message –Sends a message to the calling program
Example Write a CL program which reads the student file, calculates the total Feesowed and total Finesowed displays it to the user.
Pseudo Code Initialize variables Receive information Do while not end of file Update account balance total Receive information End of file: format the message to display the total account balance
Monitoring for messages When something unusual happens, the system sends a message back to the program. It is up to the program to ‘trap’ the message if necessary and take the appropriate action. e.g. an end-of-file condition (msg CPF0864)
Monitor Message Example RCVF MONMSG MSGID(CPF0864) + EXEC(GOTO CMDLBL(ENDIT))
FSPEC Review File name – name of file File Type – C for a Display file I, U, or O for Database Objects O, for Printer Files (reports) File Format – E for Externally Described Record Address Type – K if the object has a sort Device – Disk for Database Object Workstn for display files Printer for reports
RPG Verbs and Functions Read filename; –reads a record from a database object %EOF(filename) –Checks for End of File
Programming tasks Create a display file that uses all of the fields from the Student file. All of the fields should be output only. Feesowed and Finesowed should have the attribute Reverse Image (RI) conditioned by an indicator Write an RPG program that displays each record in the Student file using the above display file. Feesowed and Finesowed should be displayed in Reverse Image if they are greater than zero.
Pseudo Code Initialize variables Receive information Do while not end of file Display the screen Receive information End of file: exit program