Educational Consultancy in Batch File Scripting and z/OS JCL

Longstanding Consultancy Expertise

Code Migration and Scripting

Programming Languages Training Sitemap

Submit Programming Language Questions Knowledge Transfer Programming Language Schedule
Definition of Service Delivery Medium Web-based Training Services

z/OS JCL to PC Batch Files

Mainframe and Client/Server Infrastructure

Operational Challenge Client Requirements Courseware for Learning and Reference
Guidelines and Best Practices: Testing and Debugging Guidelines and Best Practices: Documentation and Maintenance Guidelines and Best Practices: Programming Techniques
Copyright Acknowledgement

Operational Challenge

Organizational enterprise is being challenged to update its information technology infrastructure and convert z/OS JCL files to PC batch files.

Issues which need to be addressed include:

1. The removal of statements from mainframe JCL which were no longer needed and unnecessary in Windows jobs.
2. Identifying PROCS missing in jobs on the mainframe.
3. PROCS which had SORT parm files with incorrect file names and parameters which did not resolve.
4. The GDG being set up to use generation data groups in the MS Windows environment.
5. PROCS containing code from other jobs which in all likelihood had been erroneously copied into it.
6. COBOL program SELECT statements which did not contain ORGANIZATION IS LINE SEQUENTIAL, this is needed for controlling card files with multiple records.
7. The error handling in SQL load and unload programs being changed to allow for more robust error code returns; the modification of reload statements to force server-side commit statements.

Client Requirements

A New York state based healthcare provider required a specialized course with client-specific exercises. Industry standard subject matter and accompanying examples were to be included in a student handout: DOS commands, batch-file scripting techniques, help command and wild card characters, system paths, variables, calls to .bat files, and debugging techniques. Two .bat files were provided by the client for development into in-class exercises.

The instruction had to be delivered at the client location for a class size of 16 students inclusive of a distance-learning option for employees located in different areas of the state. In conjunction with the presentation of subject matter, expertise and guidance with coding and debugging scripts was needed.

Written guidelines are required for debugging scripts, implementing standards, and developing efficient code.

Courseware for Learning and Reference

Given the scarcity of up to date textbooks in hybrid areas of information technology a tailored student handout was developed.

In addition to the student handout, the training aids have been organized into a courseware as learning center format. It is available for review and utilization in an advertising free environment.

Guidelines and Best Practices - Testing and Debugging

1. Debugging Recommendation:

Watch for an initialization of a variable with an extra space.

For example: SET VAR=value▌.

If the ▌ character is the space, it is used in the value of the field and can be difficult to debug. Use the end key in the editor to move the cursor to the end of the line to visualize the space. The extra space also can be at the beginning of the string.

2. Insert a debugging breakpoint into a program with an ECHO and PAUSE statement.
3. Turn on tracing by setting the ECHO ON statement.
4. If there is a requirement to distribute batch files, ensure that there is sufficient error checking.
5. Normal batch files will need to contain the finish and cleanup label segments. This is necessary to ensure that the variables will be set and cleaned up when their use is over. This framework will facilitate searching for the sections in a large bat file.

Guidelines and Best Practices - Documentation and Maintenance

1. A small script of 1 to 2 pages in length will be easy to trace through and understand the program logic. However, large .BATs and multiple .BATs can be difficult to work with.

A cross reference list is an important aid for reviewing code, documentation, and debugging. A .bat script does not provide a cross reference report; however, C#, Perl, Access, VB or any language with character manipulation can be used to code one. The system will read all the BATs, extract symbolic variables, program names, token location, CALL routine locations and initialization statements. The results can be sorted and a cross reference displayed and printed.

Reports that can be produced include: variable cross reference, call routines usage, variable initialization locations, dataset locations, program execution locations, and ERRORLEVEL values.

2. Create a logfile to indicate the steps processed and error conditions.
3. For commonly used batch files which are accessed frequently, create a directory such as c:\bats\ and place it in the PATH to make all the batch files available from any directory.
4. All batch file names should start with a capital letter followed by small letters; each word thereafter should then be capitalized.

Guidelines and Best Practices - Programming Techniques

1. SETLOCAL and ENDLOCAL need to be used carefully.
2. Check ERRORLEVEL after every CALL and program execution.
3. Before using a file, check if it exists.
4. Be vigilant in looking for comparison and case sensitive strings.
5. Identify utilities that ignore case (i.e. Windows SORT).
6. There are some programmers that will capitalize all labels and keywords - if, for, exist, etc. Most .bat programmers do not utilize indentation; therefore, making it difficult to maintain the code. Indention makes the code more readable.
7. Standards should be developed for coding comments, change logs, and system flow documentation.
8. In IF statements comparisons, delimit the comparison string with a character such as or {.
9. Whenever possible use environment variables as scratch variables. This is preferred to hard-coding values; it will be easier to change an environment variable reference in one place than to perform a find and replace operation. This also will keep the code more readable.
10. Always make @echo off the first line of finished batch files. In most situations, it will not be a requirement for the user to be aware of the batch file commands batch file commands while a program is executing.
11. Initialize all temporary variables at the beginning of the batch file and clear them at the end.

set _foo=0
set _bar=temp.dat

set _foo=
set _bar=

12. Prefix temporary batch-specific variables with an underscore character to avoid name clashes. This practice can be extended to temporary text files that are created by batch files.
13. Take full advantage of variables specified on the command line; it is preferred to setting variables interactively. It will be efficient when used in unattended batch sessions and when batch files call each other.
14. Do not place terse cryptic comments inside the file; document the batch file with a text file with the same basename when related documents are required. For example, mybat.bat should have documentation in mybat.doc.
15. When identical commands are used repeatedly used in a file, the recommended practice is to move that code into another batch file and then call the code into the main file.
16. Instead of placing parameters in a global variable that multiple batch files will have access to, command-line parameters will be passed to batch files.
17. When placing multiple statements after the if, else, or do clauses, indent the commands in parenthesis with a fixed number of spaces. The recommended practice is to use three spaces. Do not use tabs; the size of the indentation will vary based upon the text editor being used.
18. The recommended practice is to use "SetupEnv.bat" for setting up the global variables and ending the batch file execution by calling "CleanupEnv.bat".  If they do not already exist, both files will need to be created. This will limit the changes that occur to the global variables to a single file; it will facilitate future editing.
19. All batch file names should start with a capital letter followed by small letters; each word thereafter should then be capitalized.

Copyright Acknowledgement
z/OS JCL is a registered trademark of IBM Corporation.