Before we give the exercise assignments, we suggest you review Appendix C: REXX Goodies. These tools may help you when you code your procedures.
The first exercise is a paper exercise, whereby it is your turn to comment on our procedure. Next piece of coding contains some errors and bad coding techniques. Don't search only for bugs, but also for lines that could be coded better.
This is a complementary question:
|
What is the best form of PARSE to ask the user for a reply to a question ? |
Now, we propose you to write a procedure where parse will be useful. The exercise is not so easy, though it is possible to do it in less than 20 statements...
Write a procedure that lists the different filetypes found on an accessed disk or SFS directory, and also displays the frequency at which they are found. The output we expect is thus something like this:
There are 7 files with filetype EXEC on your B-disk There are 13 files with filetype XEDIT on your B-disk ...
The procedure should accept a filemode as parameter (so don't hard-code a filemode !). We also explicitly ask you not to use CMS Pipelines but to search for the best solution using REXX logic (this is a very good exercise to practice the possibilities of REXX).
Test your procedure with a disk containing only a few files so that you can easily verify your results via a FILELIST. But then, stress test it on a larger disk (e.g. the Y-disk).
You can then review our commented solution.
And finally, an exercise on File I/O.
Write a procedure that lists the logical shared segments (LSEGMENT) that are part of the physical shared segment (PSEGMENT) (for example CMSFILES). The procedure should also display the size in bytes for each logical segment, and calculate the remaining free space in the physical segment.
The information can be found in file SYSTEM SEGID S2. The records that you have to extract look like these:
PSEGMENT CMSFILES 01C00000 00190000 02/17/94 13:42:33 LSEGMENT xxxxxx 01C00000 000C64E8 LSEGMENT yyyyyy 01CC6528 000C31B0
The fourth column indicates the sizes in hexadecimal notation. So the remaining free space is the size of the PSEGMENT minus the sum of the LSEGMENT members. Your output should resemble to this:
Physical segment CMSFILES contains following logical segments : DMSDAC size 812264 bytes DMSSAC size 799152 bytes Space remaining in physical segment = 26984 bytes
Choose any of the methods described in the lesson. EXECIO, XEDIT or CMS Pipelines are the most appropriate as they have options or functions to find the correct records. LINEIN doesn't have the options, so that you have to put a bit more logic in the procedure. Allow for the name of the physical segment to be passed as parameter.
You can then review our commented solution.
Lesson 4 (chapter 14) will now go into a lot more details about file I/O.