I have been asked by private message to discuss something that I said in one of my posts:
Can i know about the rexx prog u have which collect the xml information and convert it to cobol running programs.(the copybook that generate (and compile) automatically a cobol program and performs XML to COPY or COPY to XML conversion.
If I remember well, I also wrote that it's not a finished project.
Anyway, I ask myself what to do about this request?
Getting involved into something like this requires a lot of time (most difficult).
On another side, it is an interesting problem.
It could be an excellent occasion to share some knowledge.
Anyway, XML files start to be popular, even on the mainframe. Something should be done about that!
The knowledge necessary to complete the task is wide:
ISPF Tables and File Tailoring are a very big must.
Some Panels knowledge is required (that's the easy part).
Good knowledge of XML is required as well.
in-depth COBOL of course,
and REXX to make everything work together.
Did I forgot TSO? Well, some TSO too.
File Tailoring (an ISPF feature) is mostly used to prepare some JCL that is usually edited or submitted.
But, as everybody should know, FT is not limited to jobs. The "skeleton" can be almost anything.
So, the big idea behind the whole process is to use FT with the skeleton of a COBOL program.
The output of the FT process, instead of being submitted, will be saved as a fully functional program, ready to be compiled.
FT in itself is very easy to use. There are mostly 2 things that can be done:
That was the easy part... Now about the skeleton...
It is the base that will allow FT to create our COBOL program.
As such, it must contain all the COBOL statements that are necessary to cover all the cases we will encounter during the process.
In the skeleton, variables are replaced by their values. The skeleton:
01 LENGTH-OF-COPY PIC S9(4) COMP VALUE &CPYLNG..
will appear as:
01 LENGTH-OF-COPY PIC S9(4) COMP VALUE 247.
Some COBOL statements will be triggered (or not) by means of Control Statements.
We will make use of almost all the Control Statements available.
Among them, the )DOT is interesting because it uses ISPF Tables.
The piece of code within the )DOT - )ENDDOT pair will be repeated for each row in the ISPF table.
The fields of the table are used as variables in the skeleton or in other Control Statements.
Please do not post questions here unless you are an experienced programmer.
I wish to keep this thread concentrated on the subject.
And I hope it will be interesting and instructing.
Just a note about the Address I've been using in my examples.
Writing nothing didn't seem right, as I have an example with both TSO and ISPF commands, so I copied and pasted the address.
In a real program, it doesn't need to be like this.
You have here 4 commands: Address TSO twice, one DELETE and one ALLOC.
The second Address TSO is useless. When used alone on a line, it means "from now on, send commands to TSO"
When used followed by a command, it means "send this command to TSO".
The correct way to write could be:
Between the )DOT and )ENDDOT, you can have a single line (like in my example) or a pack of lines: JCL, COBOL or whatever.
If you add )SEL commands (preferably on one of the Table fields), you can generate different pieces of code, as we will see later.
The panel, as I said, contains 4 fields:
* the library where the COPY is.
* the copybook name.
* the library where to save the program.
* an option: EDIT, SAVE or SUBMIT.
If the program name cannot be derived from the copy name, then it is necessary to ask for it in the panel.
Most fields are validated within the panel, so the Validate_Panel_Values paragraph only needs to:
- check that the copybook member exists in the copybook library.
- check if the program already exists and ask if it's OK to replace it.
And one more thing to think about: maybe some day we will like to run this REXX program in a batch environment.
In that case, we will have to bypass the panel and the "OK to replace" question.
To briefly answer mtaylor questions, I want to generate a sub-program that converts a single copy to or from its xml representation.
Conversion to xml is fully handled by the XML GENERATE command, so most PIC and USAGE formats are taken care of.
The other way around is more complex. So much that it is worth investing in a "rexx tool" that does it automagically (that's my opinion).
I've talked about the tools needed, shown some examples and started to write some code.
I've tried to give some "tips and tricks" too. I hope somebody found something useful.
This topic starts to be quite long, and I haven't reached the COBOL part yet. Also, all the code must be truly running, otherwise it is useless (there is one mistake in my rexx. Somebody found it?). That means writing and testing, for which I haven't much time. May I ask for a volunteer?
However, I am glad to present now another piece of code. ISPF programmers will be interested in the way I handle the "Are you sure?" question.
CopyDSN = "'"CopyLib"("CopyName")'" /* 01 */
If SYSDSN(CopyDSN) <> 'OK' Then Do /* 02 */
If SYSDSN("'"ProgLib"'") <> 'OK' Then Do /* 03 */
ProgName = Overlay('P',CopyName,3) /* 04 */
ProgDSN = "'"ProgLib"("ProgName")'" /* 05 */
If SYSDSN(ProgDSN) = 'OK' Then Do /* 06 */
X = 'N'
"ADDPOP ROW(12) COLUMN(22)"
"DISPLAY PANEL(TRPX2COV) CURSOR(X)"
Ret = RC
If (Ret <> 0) | (X <> 'Y') Then Do /* 07 */
Return(True) /* 08 */
Make the full copy name. Values have been VERified in the panel. I put quotes once and for all, so I don't have to worry about the TSO PROF settings.
Check that the copybook really exists. If not, set message and return. 'False' is looking much better than '1'
Check the output library. same error handling.
Make up the program name. Could be almost anything, if it cannot be guessed then it must be collected from the panel.
And make the full name of the program.
Check if the program already exists. If yes, show the pop-up saying "Are you sure?"
- Set default answer,
- open a pop-up,
- show the panel,
- collect the return code and
- close the pop-up.
If PF3 was hit or override was denied, just set message and return.
If all controls passed, return with good news.
The panel looks like this:
%The program already exists.+
%Enter Y to override: _X+ +
&ZCMD = &Z
&ZWINTTL = 'Question'
Usually, I hate using variables like 'X'. This time I was just too lazy to use a .ZVARS.
Experiment with the ROW and COLUMN values in the ADDPOP, and the WINDOW values in the )BODY, too improve my poor design.