[Tutor] Script to generate statements

Alan Gauld alan.gauld at btinternet.com
Sat Mar 16 01:53:17 CET 2013


On 15/03/13 19:42, Charles Leviton wrote:

> Given a list of DBRM members create a JCL which has a series of bind
> statements for each DBRM.

Ah, the joys of JCL.
I haven't read a JCL script in about 15 years! :-)

> This is the tack I took.  I have 3 input files
> a_ contains the fixed part of the JCL
> b_ contains the template for the bind statement.
> c_ contains the list of DBRMs

Yep, that's fine.

> This is the script I came up with...Would you critique it and let me
> know how I could have done it better?

> #create a series of bind statements
> fo = open('i:/text/jclout.txt', 'w')
> fi = open('i:/text/bindjclfirstpart.txt','rU')
> fibindjclvar = open('i:/text/bindjclvariable.txt','rU')
> filistofdbrms= open('i:/text/bindjcldbrmlist.txt','rU')
>
> varlines =[]

You don't need this since the next line initialises the list anyway.
Python rarely requires initialising to null values, you can usually 
initialise to the actual data directly.

> varlines = fibindjclvar.readlines()
> for line in fi: #write out all the lines in the first part of JCL
>      fo.write(line)
> fo.write('\n')
> varline = ''

Again you don't need this since you always initialise varline below.

> for dbrm in filistofdbrms:
>      fo.write('\n')
>      for index in range(0,9):
>          if varlines[index].find('member') > 0:
>              varline = varlines[index] + '('+ dbrm + ')' + ' -'
>          else:
>              varline = varlines[index]
>          fo.write(varline)
>
> fo.close()
> fi.close()
> fibindjclvar.close()
> filistofdbrms.close()

And that's all, the rest looks fine to me.

PS.
Note to Hugo. JCL = Job Control language.
Its like a Unix shell script that specifically used to set up a programs 
runtime environment (how much disk, RAM, CPU it's allowed to consume, 
start/end times etc etc.) One of the most powerful things about a 
mainframe that makes them so much more robust than Unix boxes is the 
fine grained control offered by JCL...


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list