I have been asked by private message to discuss something that I said in one of my posts:
Quote:
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.
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
Just a thought.
If I were to spend the time necessary to fully develop this concept, then personally I'd contact the CBT Tape folks and talk to them about adding it to the CBT Tape shareware distribution.
Or, I'd offer the code on my own website for a flat fee via PayPal.
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:
Code:
ID DIVISION.
PROGRAM-ID. &PROGNAME..
WORKING-STORAGE SECTION.
01 LENGTH-OF-COPY PIC S9(4) COMP VALUE &CPYLNG..
will appear as:
Code:
ID DIVISION.
PROGRAM-ID. PGMPPXXX.
WORKING-STORAGE SECTION.
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.
After this rather long introduction, it's time to start to think about our REXX program.
There are still many points to explore, but we now have enough information to start some coding.
The program will do the following:
Show a panel to collect the copybook name, the libraries (where the COPY is, where to save the program)
and maybe an option (EDIT, SAVE or SUBMIT (to Endevor), for example).
Check all these values.
Load the copybook and analyse it. Keeping the copybook fields in a formatted way will allow us to populate some ISPF tables.
That's what we do now: populate the ISPF tables, but also other variables used in the skeleton.
Run the File Tailoring and decide what to do with the generated program.
All this in a loop, until the user hits PF3.
To those who follow my lucubrations, ISPF Tables, skeletons and File Tailoring subjects should be clear.
Here we go...
Code:
/* rexx */
Call Housekeeping_Begin
Do forever
"DISPLAY PANEL(mainpnl)"
If RC <> 0 Then Leave
If Validate_Panel_Values() = False Then Iterate
Call Load_Copybook
Call Load_ISPF_Tables
Call Generate_Program
End
Call Housekeeping_End
Exit
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.
Joined: 20 Feb 2009 Posts: 108 Location: Kansas City
What is the goal exactly? Generate a Cobol program that converts a dataset to or from an xml representation using the copybook layout?
If so, how will you handle display fields? Will the fields in the xml output be formatted as per the PICTURE clause?
One problem I see going from xml to dataset: xml is not required to have all fields, so if a field is not present it must be set to default value in the output dataset.
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.
Code:
Validate_Panel_Values:
CopyDSN = "'"CopyLib"("CopyName")'" /* 01 */
If SYSDSN(CopyDSN) <> 'OK' Then Do /* 02 */
"SETMSG MSG(TRM0001A)"
Return(False)
End
If SYSDSN("'"ProgLib"'") <> 'OK' Then Do /* 03 */
"SETMSG MSG(TRM0002A)"
Return(False)
End
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
"REMPOP"
If (Ret <> 0) | (X <> 'Y') Then Do /* 07 */
"SETMSG MSG(TRM0002B)"
Return(False)
End
End
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:
Code:
)BODY WINDOW(30,4)
_ZCMD +
%The program already exists.+
%Enter Y to override: _X+ +
)INIT
&ZCMD = &Z
&ZWINTTL = 'Question'
)PROC
VER(&X,NB,LIST,Y,N)
)END
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.