Lesson 3. Exercises.

Before we give the exercise assignments, we suggest you review Appendix C: REXX Goodies.  These tools may help you when you code your procedures.

Play REXX interpreter

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.

Question 23
 /*  */ /* DESSERT EXEC */
 /* 1*/ Parse source . . myname mytype . syn .
 /* 2*/ Parse arg args
 /* 3*/ Parse value translate(diag(8,'Q SET'),' ',','!!'15'X) ,
 /* 4*/       with  a b c d e emsg .
 /* 5*/ parse value 0    0   1   (emsg^='OFF' ) '*' ,
 /* 6*/       with  zero nok ok  emsg           fmode .
 /* 7*/ Say 'Hi there, you called' myname mytype 'by typing:'
 /* 8*/ Say '   'syn args
 /* 9*/ if emsg then Say 'You will see eventual errormessages.'
 /*10*/         else Say 'Aha you want to hide the errors you make.'
 /*11*/
 /*12*/ do until ok
 /*13*/    Say 'Do you want to see something or just be lazy ?'
 /*14*/    Say '   anwser   Y   or   N   or  FILELIST * * fmode'
 /*15*/    Parse upper pull answer
 /*16*/    ok=1 /* Suppose Answer is OK */
 /*17*/    if answer='' then answer='Y'  /* get the lazy at work */
 /*18*/    parse var anwser with w1 w2 w3 w4 .
 /*19*/    select
 /*20*/      when abbrev(NO,w1) then exit
 /*21*/      when abbrev('YES',w1,1) then 'FILELIST * *' fmode
 /*22*/      when abbrev(FILELIST,w1,1) then 'FILELIST' w2 w3 w4
 /*23*/      Otherwise
 /*24*/        Say 'Can''t you read ?, please give a valid answer.'
 /*25*/        ok=0
 /*26*/    End
 /*27*/ End
 /*28*/ Exit

This is a complementary question:

Question 24

What is the best form of PARSE to ask the user for a reply to a question ?

Practice parsing by counting filetypes

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.

Practice parsing by analyzing a file

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.