IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

XML to COPY or COPY to XML conversion


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue May 05, 2009 2:13 am
Reply with quote

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.

Should I go on?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 05, 2009 2:21 am
Reply with quote

Yes. . . icon_smile.gif

I suspect that many could benefit from such specifics icon_wink.gif

d
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue May 05, 2009 2:24 am
Reply with quote

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.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri May 08, 2009 2:18 am
Reply with quote

Let's give it a try and see where it leads.

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:
Code:
Address ISPEXEC "FTOPEN TEMP"
Address ISPEXEC "FTINCL <skelname>"
Address ISPEXEC "FTCLOSE"
or
Code:
Address TSO "ALLOC FI(ISPFILE) DATASET(<datasetmember>) SHR"
Address ISPEXEC "FTOPEN"
Address ISPEXEC "FTINCL <skelname>"
Address ISPEXEC "FTCLOSE"
The 1st one creates a temporary file, the 2nd one a permanent file (or member).
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri May 08, 2009 2:45 am
Reply with quote

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.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri May 08, 2009 3:34 am
Reply with quote

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.

I always tick when I see a REXX program with:
Code:
Address TSO
   "DELETE '"OUT_FIL"'"
Address TSO               /* wrong way */
   "ALLOC DATASET('"OUT_FIL"') ..."

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:
Code:
Address TSO,
   "DELETE '"OUT_FIL"'"
Address TSO,              /* correct way #1 */
   "ALLOC DATASET('"OUT_FIL"') ..."

or

   Address TSO              /* correct way #2 */
   "DELETE '"OUT_FIL"'"
   "ALLOC DATASET('"OUT_FIL"') ..."

If you want to be politically correct, you can use "Address" only, to restore the previous environment.
I do this a lot when I use DB2:
Code:
Call Read_From_DB2_Table
.
.
.
Read_From_DB2_Table:
Address DSNREXX
/* do here all my DB2 stuff */
Address
Return
The 2nd Address will restore whatever environment was active when the previous Address was issued.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed May 13, 2009 3:09 am
Reply with quote

Now, to finish with the FT and Tables thing, here is a small example.

Here is the skeleton:
Code:
)SET DDN = 'INPUT'
)DOT TBINPUT
//&DDN   DD   DISP=SHR,DSN=&FLName
)SET DDN = '     '
)ENDDOT
and the REXX program:
Code:
Address ISPEXEC
"TBCREATE TBInput NAMES(FLNames)"     /* create a table */
FLNames = 'HLQ.DATA.D090511'          /* populate it with 3 lines */
"TBADD TBInput"
FLNames = 'HLQ.DATA.D090512'          /* (very simplified code) */
"TBADD TBInput"
FLNames = 'HLQ.DATA.D090513'
"TBADD TBInput"
"TBCLOSE TBInput"                     /* close the table */

"FTOPEN TEMP"                         /* do the File Tailoring */
"FTINCL myskel"
"FTCLOSE"

"TBERASE TBInput"                     /* delete the table */

"VGET (ZTEMPF)"
"EDIT DATASET('"ZTEMPF"')"            /* edit the file */
Address
The result will be:
Code:
//INPUT   DD   DISP=SHR,DSN=HLQ.DATA.D090511
//        DD   DISP=SHR,DSN=HLQ.DATA.D090512
//        DD   DISP=SHR,DSN=HLQ.DATA.D090513


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.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed May 13, 2009 3:15 pm
Reply with quote

As I wrote the previous message at home, I couldn't verify the code I wrote.
The skeleton should be:
Code:
)SET DDN = INPUT                   
)DOT TBINPUT                       
//&DDN   DD   DISP=SHR,DSN=&FLNAMES
)SETF DDN = &LEFT(,5)             
)ENDDOT                           
The result will be just as displayed before.

In the REXX program, I added the REPLACE parameter to the TBCREATE command, that's all.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed May 20, 2009 2:33 am
Reply with quote

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
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed May 20, 2009 3:11 am
Reply with quote

Some paragraphs can be easily put away.

Code:
Housekeeping_Begin:
   Address ISPEXEC                           /* 1 */
   True = (1=1)                              /* 2 */
   False = /True
   "LIBDEF ISPPLIB..."                       /* 3 */
   "VGET (mainsave) PROFILE"                 /* 4 */
   Parse Var mainsave COPYNAME COPYLIB PROGLIB OPT .
Return
Housekeeping_End:
   "LIBDEF ISPPLIB"                          /* 5 */
   mainsave = COPYNAME COPYLIB PROGLIB OPT   /* 6 */
   "VPUT (mainsave) PROFILE"
Return

  1. As we will use plenty of ISPF services, lets make it the default environment.
  2. I showed this trick here. I think it's convenient.
  3. Optionally, you may need some LIBDEF (for ISPTABL?). It shouldn't be necessary.
  4. This is how panels "remember" the last values entered. They were saved as an ISPF variable in the profile.
  5. For removing the LIBDEF if it was necessary.
  6. And this is where the last values entered are saved.
    Note how I squeeze them into only one variable and split them back.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sun May 24, 2009 1:46 am
Reply with quote

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.
Back to top
View user's profile Send private message
mtaylor

Active User


Joined: 20 Feb 2009
Posts: 108
Location: Kansas City

PostPosted: Sun May 24, 2009 9:23 am
Reply with quote

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.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun May 24, 2009 9:42 am
Reply with quote

Hello,

Please re-post your questions in a separate topic referring to this one.

Continuity will be better if the presentation is not interspersed with questions and observations.

Thanks icon_smile.gif

I may be behind times and the information already complete. . . I'll ask and adjust my post here accordingly icon_redface.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Jun 08, 2009 3:44 am
Reply with quote

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 */

  1. 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.
  2. Check that the copybook really exists. If not, set message and return. 'False' is looking much better than '1'
  3. Check the output library. same error handling.
  4. Make up the program name. Could be almost anything, if it cannot be guessed then it must be collected from the panel.
  5. And make the full name of the program.
  6. 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.
  7. If PF3 was hit or override was denied, just set message and return.
  8. 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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts VB to VB copy - Full length reached SYNCSORT 8
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts Need COBOL COPY Help in MVS Environment COBOL Programming 4
No new posts file manager is doing string conversion IBM Tools 3
Search our Forums:

Back to Top