We propose you now to practice most of the tracing options we have discussed in this lesson. To make it easy, we provide the TRACTEST EXEC © procedure. This procedure is listed below. It has no other practical value than to learn about tracing. It uses variables, arrays, host commands, subroutines, loops, etc. to enable you to exercise the different trace options. The procedure should not contain errors.
The command format for the procedure is:
TRACTEST [t-parm]
where the t-parm is a valid tracing option.
These are the steps we suggest for this exercise:
This is the procedure:
/***********************************************************************/ /* Procedure TRACTEST */ /* Format : TRACTEST [tracing-option] */ /***********************************************************************/ address command parse upper arg traceopt . traceopt=check_parm(traceopt) trace value(traceopt) array.=0 /* initialize array to zero */ do i=1 to 6 by 2 /* odd elements */ array.i=i /* value of i */ j=i+1 array.j=i**2 end do i=1 to 6 by 2 call output i end exit /***********************************************************************/ /* Subroutine OUTPUT to produce an output on the terminal */ /***********************************************************************/ OUTPUT: parse arg parm elem=parm+1 'QUERY TIME (STACK' parse pull . . time . day date parse pull . say 'At' time 'on' day date ', the square of' parm 'is' array.elem return /***********************************************************************/ /* Subroutine EMSG and EXIT */ /***********************************************************************/ EXIT: EMSG: 'DROPBUF 0' parse source . . myname . parse arg retc,errmsg if errmsg<>'' then say myname':' errmsg exit retc /***********************************************************************/ /* Subroutine CHECK_PARM - checks validity of trace option given by */ /* the user. */ /***********************************************************************/ CHECK_PARM: c1=left(arg(1),1) if pos(c1,'?]')=0 then do;trpre='';tropt=c1;end else do;trpre=c1;tropt=substr(arg(1),2,1);end if pos(tropt,'ACEFILNORS ')=0 then call emsg 8,"Invalid trace option '"arg(1)"' specified" if tropt=' ' then tropt='N' /* default */ return trpre||tropt
As an optional exercise on tracing, perform the following:
Write a small procedure that reads a file, extracts some data, performs a calculation on the data and writes the result back to another file.
Don't spend too much time on this exercise. If you have too much difficulties with it, then our later lessons will definitely help you a lot, as we will learn how to read files.
Then, you could give the next exercise a try...
01-07 Partnumber 09-40 Description 42-50 List price
When you have coded your version, take the time to review our commented solutions.
Our final exercise lets you also read a file and manipulate the data in it. A brief introduction is however required.
You may already have seen so called one-lined procedures on some VM systems or packages. A one-lined procedure is a procedure where:
If you want to have an example, look at the file ONELINED XEDIT ©.
This technique had a few advantages:
These advantages have less importance nowadays, as:
Note: Comments and spaces can also be eliminated via the EXECUPDT procedure.
Now, before you code the procedure to manipulate such a file, try to answer these few questions:
Although CMS pipelines can do it in one command, as follows:
PIPE < ONELINED EXEC ! SPLIT ; ! > MULTILIN EXEC A
we propose you to write a procedure that converts a one-lined exec into a multi-lined exec. To that purpose, we provide the MULTILIN SKELETON © that you have to complete. This procedure uses EXECIO to read and write the files. Review the comments in the procedure to see what you have to do.
You could test your procedure on ONELINED XEDIT ©. but this file is rather large and if you have to trace your procedure, it would take you too long. We therefore also provide ONELINED EXEC © which contains only a few statements.
When you have coded your procedure, you can review our commented solutions.
This concludes the exercises for Lesson 2. Lesson 3 will discuss parsing and file I/O techniques.