Mainframes 360
The one stop destination for System Z professionals

Saturday, April 3, 2010

Updating Records in VSAM File

Q. What are the COBOL Instructions for randomly updating a KSDS File?
The REWRITE statement in COBOL is used to change the records in a KSDS File. You have to merely supply new values for the record-fields, and the record in the KSDS file gets updated. How does the REWRITE statement achieve this magnificent feat?

The ingredients that make up a RE-WRITE statement are (i) REad followed by (ii)WRITE. When a REWRITE statement is executed, what happens is this. Initially, it REads the record(you intend to modify) from the file into a temporary scratch-pad area or rough-work area. You specify the record you intend to modify, by mentioning its key-value. The modifications(new values) that you supply, are applied to the record that’s brought into the scratch-pad area. The old-values are wiped out(erased off), and the new values take their place. It finally WRITEs the updated record back to the file.
Q. What is the procedure to update records in a VSAM File?
I wish to update the Records in the Employee-Master File which is a VSAM File, shown in the picture below.

Image342
The copy-book EMPMAST contains the Record-Format of the EMPLOYEE-MASTER-FILE, is shown in this snap.

Image343

1. Pick-up the Record : First of all, you need to tell, which record in this VSAM File is to be modified? What you do is, just MOVE the key of the record to be changed in RECORD KEY field. Say, if I would like update data about RAKESH, I would MOVE 55 to the Key-Field EMP-ID. And, then I do a READ on the EMPLOYEE-MASTER-FILE. Behind the scenes, what it does is, the record '55 RAKESH 35 1650000 20080217' is searched in the file, it is read in, and brought into the COBOL Storage Area EMPLOYEE-MASTER-RECORD.
 
MOVE 55 TO EMP-ID.
READ EMPLOYEE-MASTER-FILE

2. Make the Changes : Now, that the record-to-be-updated 055 RAKESH 1650000 20080217 is stored in EMP-ID, EMP-NAME, EMP-AGE, EMP-SALARY and EMP-JDATE Fields, you supply the new values for the fields that you want to change. Say, I want to increase Rakesh's salary to 17.5k, so I just change the EMP-SALARY Value. I MOVE 1750000 to EMP-SALARY. This makes my new record 055 RAKESH 1750000 20080217, leaving the rest fields undisturbed.

MOVE 1750000 TO EMP-SALARY

3. REWRITE Back to the File on top of the Old Record : I have now prepared, constructed the new record, which is to replace the Old Record off the VSAM File. What remains to be done is, to overlay this brand-new record on top of the old-one in the file. To write this new employee-record back into the VSAM File, I do a REWRITE EMPLOYEE-MASTER-RECORD.
Q. How do you code this in COBOL?
I have written a COBOL Program, to update the Records in a VSAM File. The Program Master File-Data based on the Transactions from the Transaction-File. Here is the Program Header.

Image346

A Transactions-File contains the List of Transactions that need to be updated in the Master-File. 

Image344 
The Copy-Book TRANSREC containing the File-Layout for Transactions File is shown below.

Image345 
I have defined the Employee Master File containing Employee Records, and the Transactions file containing Transactions as follows.

Image347

Working-Storage Areas :
FILE-STATUS-CODES COBOL Variable, stores the two-digit status code indicating success or failure of any File Operation such as OPEN, READ, REWRITE, CLOSE performed on the VSAM File.


I used a Switch END-OF-TRANSACTIONS-FILE that can toggle between YES or NO. While reading records from the Transaction File, I am gonna check this flag -  to make sure, its set to NO, and I have not reach the End of the The File. Once, I reach the End of the File, I turn the Flag to YES, which is indicator to stop any more processing of the File.

I have also used the Debug-Switch to control and turn the DISPLAY's in the COBOL Program on or off.  

Image348

The Procedure of updating records in Employee-Master File has been broken down into 3 Tasks – 1000-HOUSEKEEPING, 2000-PROCESS-DATA and 3000-CLEANUP.
   
Image349

On Line 94, the 1000-HOUSEKEEPING Paragraph OPENs the Employee Master File in I-O Mode. The I-O Mode is used to update data in a File(Read and then Write). The Transactions File is OPEN'ed in INPUT and the transactions are read from this file sequentially one-by-one.

Image350 
The task of Processing the Data is further broken down into two paragraphs -2400-READ-TRANS-REC that reads a Transaction record from the Transactions file and updating it in Master File 2800-UPDATE-MASTER.

Image351

The 2400-READ-TRANS-REC Paragraph attempts to READ one transaction from the Transactions File. When the READ is successful, the Data read from the Transactions-File will be stored in TRANSACTION-RECORD COBOL Storage Area.
One-by-one, after all the Transactions have been read, and you do one more extra-Read, the AT END Special Condition becomes true, and the Block-of-Instructions inside the AT END, Lines 125-126  will be executed. I set the AT-END-OF-FILE Flag to TRUE(Turn it On). This will stop any further processing. Moreover, the GO TO statement causes the control to directly jump to the 2800-UPDATE-MASTER EX-IT Para.

Image352

The 2800-UPDATE MASTER Paragraph performs the function of looking-up a Matching record in the Master File, and if found, updates the Salary-Field of the Employee. Take a look.

Image353

On the Line 127, the Employee-ID read from the Transactions-File(and stored in the 05-Level Field TRANS-EMP-ID) is MOVEd to the EMP-ID Variable which is the Key-Field for the Employee Master File.

Scenario 1 - EMP-ID=55
I perform a READ on the EMPLOYEE-MASTER File, with Employee-ID(say 55) stored in the Key-Field EMP-ID. This triggers off a search in the Master File for the Employee-id 55. If such an Employee if found, its fine. On Line 138, the New-Salary Value obtained from the Transaction-record, is updated in the Master-Record. The modified, updated new Master-record is written back to the Master-File using REWRITE Statement.

Scenario 2 - EMP-ID=40
But, what if the Employee that you want to update is not present in Master File? That’s what happens with Employee-id 40, observe that there's no guy matching in the Master File with EMP-ID=40. When this happens, the INVALID KEY Condition is raised, and the way I have handled and trapped this error, is I DISPLAY 'EMPLOYEE NOT FOUND IN MASTER' Message, followed by the employee-id. Watch out for the GO TO Statement. I need to avoid and skip off this record, and move on to the next record. To skip the remaining part-of-processing and move on to the next record, I coded a GO TO 2800-UPDATE-MASTER-EXIT.

The 3000-CLEANUP Paragraph closes the Employee Master File and Transactions File.
Image354

Upon running the Program, the Employee Master File the salary fields of the Employees with employee-id=55 and employee-id=65 are updated.

Image355

Here's the Debug-Trace, that shows the flow-of-execution of paragraphs. Take a look at the error-message for the Employee with employee-id=40.

Image356

Thursday, April 1, 2010

Test Page

Pseudo-conversational programs
Software applications on CICS could be conversational or pseudo-conversational. A pseudo-conversational program efficiently utilizes mainframe computer time.

A conversational program : Say, you want to want to reserve a railway-ticket from Mumbai to Pune.Type the TRANSID BOOK on the terminal. The booking software program starts running, and the MAIN MENU is displayed on the screen. Whilst you glare at the screen and decide what option (1,2 or 3) to type next, the program is still running, holds on to resources, stays idle waiting for response, wasting mainframe computer time. Human response(10 seconds) is far slower than CPU processing time(2 seconds). You key in option 1, the software program processes the selected option and displays BOOKING MENU on the screen. As you fill in the passenger details, the software program is waiting idle, till you press enter. Thus, conversational programs are  inefficient and waste resources.




   Menu  RefList  RefMode  Utilities  Help                                      
------------------------------------------------------------------------------
Data Set List Utility
Option ===>


blank Display data set list P Print data set list
V Display VTOC information PV Print VTOC information

Enter one or both of the parameters below:
Dsname Level . . . SYSADM.DEMO.REXXLIB
Volume serial . .

Data set list options
Initial View . . . 1 1. Volume Enter "/" to select option
2. Space / Confirm Data Set Delete
3. Attrib / Confirm Member Delete
4. Total / Include Additional Qualifiers

When the data set list is displayed, enter either:
"/" on the data set list command field for the command prompt pop-up,
an ISPF line command, the name of a TSO command, CLIST, or REXX exec, or
"=" to execute the previous command.


Cobol Run JCL

Run a Cobol program
The job stream is used to run a program written and compiled in Cobol. You may configure the JCL, by modifying the global parameters.

Directions for use :
1. Change the //JOB Card.
2. Set the PGMNAME and LOADLIB parameters to your personal Program-name and Load-Library respectively.

The Closet

My Letters and Notes
How TSO and Time-sharing works

Cobol Compile-Link JCL

Cobol Compile and Link Job
The job stream is used to compile and link-edit a source program written in Cobol. You may configure the JCL, by modifying the global parameters.

Directions for use :
1. Change the //JOB Card.
2. Set the PROGRAM, SRCLIB, COPYLIB and LOADLIB parameters to your personal Program-name, Source-Library, Copy-Library and Load-Library.
3. Find out the COBOL Compiler-Library prefix. COBOL Compiler libraries end with *.SIGYCOMP. Set
COBPRFX(Cobol prefix)=prefix of the Compiler-Library.

Run a Cobol-Db2 application program

Run a Cobol-Db2 Program
This job-stream is used to run a Cobol-Db2 application program with a matching Db2 PLAN. You may configure the JCL, by modifying the global parameters.

Directions for use :
1. Change the //JOB Card.
2. Set the LOADLIB and DBRMLIB Parameters to you own Load Library. and DBRM Library.
3. Ensure that your //SYSTSIN card is correct.

Db2 BIND PLAN

BIND a DBRM into Plan
The job stream is used to BIND a DBRM(Database Request Module) into an Application Plan. You may configure the JCL, by modifying the global parameters.

Directions for use :
1. Change the //JOB Card.
2. Set the PROGRAM, DBRMLIB and BINDLIB Parameters to you own Personal Program-name, DBRM Library and Bind-Cards Library.
3. Ensure that your BIND-card is stored in the correct BIND-Library. //SYSTSIN File points to the BIND-Card.

Pre-compile, Compile and Link-edit a Cobol-Db2 Program

Pre-compile, Compile and Link a Cobol-Db2 program
The job stream is used to pre-compile, compile and link-edit a source program written Cobol and containing embedded SQL statements. You may configure the JCL, by modifying the global parameters.

Directions for use :
1. Change the //JOB Card.
2. Set the PROGRAM, DBRMLIB, SRCLIB, COPYLIB, DCLGEN and LOADLIB parameters to your personal Program-name, DBRM Library, Source-Library, Copy-Library, Declarations Library and Load-Library respectively.
3. Find out the COBOL Compiler-Library prefix. COBOL Compile Libraries end with *.SIGYCOMP. SET COBPRFX=prefix of the COBOL Compiler-Library.
4. Find out the Linker-Library Prefix. Linker Libraries generally end with *.SCEELKED. SET LNKPRFX=prefix of the Linker-Library.
5. Find out the DB2-Library prefix. DB2 Library-names follow the convention DSN*.SDSNLOAD. The prefix maybe DSN710, DSN810 or DSN910 depending on the DB2 Version at your shop. SET DB2PRFX=prefix of DB2-Library.

REXX and ISPF Services


  This post is partially complete and several sections may require editing and proof-reading. The contents on Rexx, ISPF panel design is under updation.

Tutorial Description
ISPF Panel Primer Learn how to write WYSIWIG(What You See Is What You Get) code and the newer DTL(Dialog Tag Language) tags to design and build ISPF panels.
Introduction to Rexx What is Rexx? Learn how to declare variables, assign values and code simple statements in Rexx.
Conditions  
Loops  
String Functions  
Other functions in Rexx  
Rexx-TSO Programming  
Calling ISPF services from Rexx  
ISPF Edit Macros  
ISPF File Tailoring Skeletons  
ISPF Tables  
ISPF Keylists  
Rexx-Db2 programming  
Rexx-SDSF programming  
TAG Edit-Macro for source-code maintenance I wrote a simple edit-macro to automatically add a modification tag to the lines-of-code(LOCs) changed in a Cobol source program.
Cobol copy-book expansion tool XP I have created this simple tool to expand copy-books inline within a Cobol source program.

To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.