By Default it looks bit elliptical which can be made round by specifying proper values using LPI statement. The pie's size is determined only by the SAS system options LINESIZE and PAGESIZE=. In the snippet above, LS and PS are the parameters which stands for Linesize and Pagesize.
Saturday, August 23, 2025
SAS Mainframe - Create PIE Chart using SAS
With the proc chart procedure, the PIE statement will create the PIECHART. The size of a pie represents the percentage that of category of data. Since the output is in spool and not routed to any printer, it is not exact circular.
Labels:
SAS
Friday, October 6, 2017
Interpreting TSO ISRDDN command in mainframe ISPF
The TSO ISRDDN command is a useful tool that lets you browse/view your active TSO session libraries. From any session, type TSO ISRDDN and the below widow will open up.
On the right side of the display is a list of DDNAME(in white colour) and their associated data sets ( (in Green colour) currently allocated to the user session.
**Dataset names in green are blurred on purpose
The left side of the display contains columns of information about individual data sets like the volume information and all. When you scroll right (using F11)or left(or F10) , the left side of the screen changes. Initially, the left side of the screen contains the volume name and disposition,if the dataset is SMS managed or not ,etc . If the disposition is red, there are other jobs waiting to use this data set as shown.
Generally the dataset associated with sysproc ddname contains the pds for the clist macros available in the system.
Try issuing the command LINKLIST or LPA. Either command will add both the system LINKLIST and LPA libraries to the display.The LINKLIST and LPALIB (Link Pack Area LIBrary) are related concepts. The LINKLIST is a collection of libraries, established during the IPL, that contain system and user load modules. Any program in the LINKLIST does NOT require a JOBLIB or STEPLIB to point to the load library -- the system can find such programs without any JCL statements. The LPALIB basically contains read-only programs (which may system or user load modules) that are reenterable.
On the right side of the display is a list of DDNAME(in white colour) and their associated data sets ( (in Green colour) currently allocated to the user session.
**Dataset names in green are blurred on purpose
The left side of the display contains columns of information about individual data sets like the volume information and all. When you scroll right (using F11)or left(or F10) , the left side of the screen changes. Initially, the left side of the screen contains the volume name and disposition,if the dataset is SMS managed or not ,etc . If the disposition is red, there are other jobs waiting to use this data set as shown.
Generally the dataset associated with sysproc ddname contains the pds for the clist macros available in the system.
Try issuing the command LINKLIST or LPA. Either command will add both the system LINKLIST and LPA libraries to the display.The LINKLIST and LPALIB (Link Pack Area LIBrary) are related concepts. The LINKLIST is a collection of libraries, established during the IPL, that contain system and user load modules. Any program in the LINKLIST does NOT require a JOBLIB or STEPLIB to point to the load library -- the system can find such programs without any JCL statements. The LPALIB basically contains read-only programs (which may system or user load modules) that are reenterable.
Saturday, July 30, 2016
Zoned Decimal and packed Decimal (COMP- 3) fields. How Does COMP 3 saves storage space?
Two computer codes which are used for internal representation of data are EBCDIC and ASCII.
Extended Binary coded decimal interchange(EBCDIC) code is a 8 bit character encoding standard used in IBM environment.
Most of the other Non IBM machines use ASCII standard.
Below is the EBCDIC representation of the alphabets and numbers followed in IBM environment.
Following the chart, we can see 'a' (2nd row in above chart) is represented in binary in 1000000001 and has the hex value of 81.
All characters & numbers are represented in 8 bits. These 8 bits can be broken into two 4 bit segments. For historical reasons, the high order 4 bits are called zone part and low order 4 bits are called digits part.
Each of these 4 bits are represented by one hexadecimal character. Thus each 8 bit EBCDIC can be represented by two character hexadecimal value. The high order 4 bits are used to represent whether the value stored is a letter,positive or negative number. Low order 4 bits represents numbers 0-9.
Let us see how the letter D is stored internally.(Map with the chart above)
In similar fashion, we can see how the letter 8 will be stored in the system( Map with the chart above)
Thus we see that in zoned decimal each byte represents one digit.
So, how will the positive number 62587 be stored in the system?
In zoned decimal, the zone portion of the rightmost byte represents the sign of the number.
For positive number, the zone portion is always 1111.
For negative number the zone portion becomes 1101.
Thus -6 can will be represented as: 1101(Zone part) 0110(Digit part)
Packed Decimal fields: How does it save spaces? Let's see how it works.
In packed decimal format, the zone portion is stripped from each byte, so that two digits can be packed together in one byte.This way the space for zone portion of each byte can be used to represent another digit. Thus two digits are represented in single byte there by saving the space.
Only the zone portion of the low order or the rightmost byte is kept for storing the sign of the field.
Considering the same example, see how the number 62587 will be stored in packed decimal format.
Space utilized will be reduced from 5 bytes to 3 bytes.
Number : 6 2 5 8 7
We can see that two digits are packed in single byte by stripping of the zone portion of all the bytes except the last byte (marked in brown).
Extended Binary coded decimal interchange(EBCDIC) code is a 8 bit character encoding standard used in IBM environment.
Most of the other Non IBM machines use ASCII standard.
Below is the EBCDIC representation of the alphabets and numbers followed in IBM environment.
![]() |
| EBCDIC represenation of Aphabets and Numerals |
Following the chart, we can see 'a' (2nd row in above chart) is represented in binary in 1000000001 and has the hex value of 81.
All characters & numbers are represented in 8 bits. These 8 bits can be broken into two 4 bit segments. For historical reasons, the high order 4 bits are called zone part and low order 4 bits are called digits part.
Each of these 4 bits are represented by one hexadecimal character. Thus each 8 bit EBCDIC can be represented by two character hexadecimal value. The high order 4 bits are used to represent whether the value stored is a letter,positive or negative number. Low order 4 bits represents numbers 0-9.
Let us see how the letter D is stored internally.(Map with the chart above)
Thus we see that in zoned decimal each byte represents one digit.
So, how will the positive number 62587 be stored in the system?
![]() |
| Zoned decimal number in EBCDIC repreentaion |
For positive number, the zone portion is always 1111.
For negative number the zone portion becomes 1101.
Thus -6 can will be represented as: 1101(Zone part) 0110(Digit part)
Packed Decimal fields: How does it save spaces? Let's see how it works.
In packed decimal format, the zone portion is stripped from each byte, so that two digits can be packed together in one byte.This way the space for zone portion of each byte can be used to represent another digit. Thus two digits are represented in single byte there by saving the space.
Only the zone portion of the low order or the rightmost byte is kept for storing the sign of the field.
Considering the same example, see how the number 62587 will be stored in packed decimal format.
Space utilized will be reduced from 5 bytes to 3 bytes.
Number : 6 2 5 8 7
![]() |
| Packed decimal representation |
Had it been a negative number the last byte would have contained 1101 in place of 1111.
This way, a packed decimal number saves space by packing two digits in one byte.
This way, a packed decimal number saves space by packing two digits in one byte.
Friday, June 24, 2016
COALESCE function in DB2 . Alternative to NULL indicator variable in DB2 ; SQLCODE - 305.
If a table column is not defined with NOT NULL, then it implies that the column value can be NULL sometimes. For such columns,if we do not use null handling technique, then the application program will give sqlcode -305.
To avoid that we use indicator variables.However , we can also use the DB2 COALESCE function.
COALESCE is a function that allows you to substitute any numeric or character value for a null, based on the column data type.
Suppose in DEPT table, i have one column for optional subject(optsubj). It can have a value of 'Y'or 'N'. However since the column is not defined with NOT NULL keyword,it can fetch null values.
If we simply use the query below, our application program will return sqlcode -305.
However, we can tweak the same query in the below way using COALESCE function to get rid of -305 without using indicator variable
What it will do is, it will replace NULL value with space of 1 byte whenever the column optsubj fetches a null value for any record;
To avoid that we use indicator variables.However , we can also use the DB2 COALESCE function.
COALESCE is a function that allows you to substitute any numeric or character value for a null, based on the column data type.
Suppose in DEPT table, i have one column for optional subject(optsubj). It can have a value of 'Y'or 'N'. However since the column is not defined with NOT NULL keyword,it can fetch null values.
If we simply use the query below, our application program will return sqlcode -305.
SELECT fname
,lname
,optsubj
into :hv-fname
:hv-lname
:hv-optsubj
from DEPT
However, we can tweak the same query in the below way using COALESCE function to get rid of -305 without using indicator variable
SELECT fname
,lname
,coalesce(optsubj,space(1))
into :hv-fname
:hv-lname
:hv-optsubj
from DEPT
What it will do is, it will replace NULL value with space of 1 byte whenever the column optsubj fetches a null value for any record;
This function can be used in many ways to get desired results.
Labels:
DB2
Thursday, June 16, 2016
RENT compiler option in cobol - Understanding reentrant programming
For understanding RENT compiler option, we need to know what is a re-entrant program.
A re-entrant is a program that doesn’t change itself. “How can a program change itself?” Does the word "Multi threading " looks familiar? Reentrant and mutithreading are related but somewhat different topics.
We can divide our program(logically) into three parts:
1. Program code – the instructions that are executed when a program runs.
2. Constants – constants used in a program. These are set when the program is written, and never change.
3.Working Storage area – or variables. This area changes when different user fires the same program.
"A reentrant Cobol program gives each user their own copy of working storage. "
For every user,MVS supplies the GETMAIN and STORAGE macros to support this and they can be
used by subsystems such as CICS or IMS or whatever to support reentrant programs.
For each user the copy of the working storage is dynamically acquired and initialized from the original copy. When a user interacts with the program , he only modifies his copy of the variables.
When the program is interrupted to give another user a turn to use the program, information about the data area associated with that user is saved.
So, what will happen if we write a CICS program as non-renetrant?
When one transaction waits, a second transaction can come and modify the working storage variables, and thus providing unstable or undesirable results.
Thus, Re-entrant programs allow a single copy of a program or routine to be used concurrently by two or more processes.
For cobol, we use the compiler option RENT to generate reentrant object program.
A re-entrant is a program that doesn’t change itself. “How can a program change itself?” Does the word "Multi threading " looks familiar? Reentrant and mutithreading are related but somewhat different topics.
We can divide our program(logically) into three parts:
1. Program code – the instructions that are executed when a program runs.
2. Constants – constants used in a program. These are set when the program is written, and never change.
3.Working Storage area – or variables. This area changes when different user fires the same program.
"A reentrant Cobol program gives each user their own copy of working storage. "
For every user,MVS supplies the GETMAIN and STORAGE macros to support this and they can be
used by subsystems such as CICS or IMS or whatever to support reentrant programs.
For each user the copy of the working storage is dynamically acquired and initialized from the original copy. When a user interacts with the program , he only modifies his copy of the variables.
When the program is interrupted to give another user a turn to use the program, information about the data area associated with that user is saved.
So, what will happen if we write a CICS program as non-renetrant?
When one transaction waits, a second transaction can come and modify the working storage variables, and thus providing unstable or undesirable results.
Thus, Re-entrant programs allow a single copy of a program or routine to be used concurrently by two or more processes.
For cobol, we use the compiler option RENT to generate reentrant object program.
Sunday, March 27, 2016
FETCH FIRST N ROWS Vs OPTIMIZE FOR N ROWS in DB2
Very Often we use these two statements in our SQL query,ie, OPTIMIZE FOR N ROWS and FETCH FIRST N ROWS ONLY.
Although it may sound similar,but both of them have specific usage when it comes to the optimizer. This post we will try to see difference between the two.
As the name suggests FETCH FIRST 5 ROWS ONLY, it actually puts a limitation on the number of rows the query is returning.I am assuming here n=5. So, here user gets only 5 rows even though there can be 100 qualifying rows for that query.
OPTIMIZE FOR 5 ROWS will straight way influence the optimizer.It does not limit the number of rows SQL will return. So using this , we will get all the qualifying rows,may be incrementally.Intent here is to give priority to retrieve first few rows.Once optimizer understands this ,it will give preference to access plan that will minimize the response time.So,DB2 will send the rows in a single block. Consider the below scenario where this will come handy.
You have an online application where the screen can hold details of 5 customers at a time. Suppose you have the below query to fetch the customer details
Select Fname, Lname, Dept, Sal,Rollno
From Dept table
Order by Sal Desc;
We are assuming the index to be defined on Rollno. If a descending index also exists on SAL column, its likely to have low cluster ratio.
Without using the OPTIMIZE clause, DB2 will do a full table space scan and sort on sal column to fetch you the details.
Now on Adding 'ÓPTIMIZE FOR 5 ROWS' to the query, DB2 will use SAL index directly because it knows you need the details of 5 highest paid employees.
So, it displays 5 rows to the screen and depending on user input will process the next 5 or do something else.Here DB2 encourage matching index scan and would not prefer list or sequential prefetch. Access plan selected for 5 records may not be good for 100 rows.
Thus, this OPTIMIZE clause comes handy for queries where you can process incrementally.We can use it to get rows directly from table without going through any buffering operations like sorting.
Although it may sound similar,but both of them have specific usage when it comes to the optimizer. This post we will try to see difference between the two.
As the name suggests FETCH FIRST 5 ROWS ONLY, it actually puts a limitation on the number of rows the query is returning.I am assuming here n=5. So, here user gets only 5 rows even though there can be 100 qualifying rows for that query.
OPTIMIZE FOR 5 ROWS will straight way influence the optimizer.It does not limit the number of rows SQL will return. So using this , we will get all the qualifying rows,may be incrementally.Intent here is to give priority to retrieve first few rows.Once optimizer understands this ,it will give preference to access plan that will minimize the response time.So,DB2 will send the rows in a single block. Consider the below scenario where this will come handy.
You have an online application where the screen can hold details of 5 customers at a time. Suppose you have the below query to fetch the customer details
Select Fname, Lname, Dept, Sal,Rollno
From Dept table
Order by Sal Desc;
We are assuming the index to be defined on Rollno. If a descending index also exists on SAL column, its likely to have low cluster ratio.
Without using the OPTIMIZE clause, DB2 will do a full table space scan and sort on sal column to fetch you the details.
Now on Adding 'ÓPTIMIZE FOR 5 ROWS' to the query, DB2 will use SAL index directly because it knows you need the details of 5 highest paid employees.
So, it displays 5 rows to the screen and depending on user input will process the next 5 or do something else.Here DB2 encourage matching index scan and would not prefer list or sequential prefetch. Access plan selected for 5 records may not be good for 100 rows.
Thus, this OPTIMIZE clause comes handy for queries where you can process incrementally.We can use it to get rows directly from table without going through any buffering operations like sorting.
Saturday, March 19, 2016
DB2 unload utility using the program DSNTIAUL
IBM provides two methods of unloading data from a DB2 table. One is DSNTIAUL program that is run under IKJEFT01 or IKJEFT1A, or 1B and the other being DSNUTILB program. DSNUTILB is a fairly new and is considered IBM’s Fast Unload Utility. Each has unique functionality that you may want to explore prior to choosing one.
Outlined below are functions of DSNTIAUL process.
1. DSNTIAUL Program: The DSNTIAUL program allows two type of unloads to be invoked against a DB2 table. When invoking DSNTIAUL you may specify an entire table unload or a selective SQL unload. The key DD statements that are being used are the SYSIN and the SYSTSIN. Both types of unloads are being run under IKJEFT1B.
Basic JCL example:
//UNLOAD EXEC PGM=IKJEFT1B, DYNAMNBR=20
//STEPLIB DD DSN=SYSDB2.DQA0.SDSNLOAD, DISP=SHR
// DD DSN=SUBSYS.DB2.DSNEXIT, DISP=SHR
//*************************************************************
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSREC00 DD DSN=userid.tablerecords.dataset,
// DISP=(,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(300,300),RLSE)
//*
//SYSPUNCH DD DSN=user-id.tablelayout.dataset,
// UNIT=SYSDA,SPACE=(CYL,(1,1),RLSE),DISP=(,CATLG,DELETE)
//SYSTSIN DD *
SYSTEM (SUBSYS) RUN PROGRAM (DSNTIAUL) PLAN (DSNTIAUL) -
LIBRARY (‘SUBSYS.DB2.RUNLIB.LOAD’)
END
//SYSIN DD *
DBCREATOR.TABLENAME
/*
//*
//UNLOAD EXEC PGM=IKJEFT1B, DYNAMNBR=20
//STEPLIB DD DSN=SYSDB2.DQA0.SDSNLOAD, DISP=SHR
// DD DSN=SUBSYS.DB2.DSNEXIT, DISP=SHR
//*************************************************************
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSREC00 DD DSN=userid.tablerecords.dataset,
// DISP=(,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(300,300),RLSE)
//*
//SYSPUNCH DD DSN=user-id.tablelayout.dataset,
// UNIT=SYSDA,SPACE=(CYL,(1,1),RLSE),DISP=(,CATLG,DELETE)
//SYSTSIN DD *
SYSTEM (SUBSYS) RUN PROGRAM (DSNTIAUL) PLAN (DSNTIAUL) -
LIBRARY (‘SUBSYS.DB2.RUNLIB.LOAD’)
END
//SYSIN DD *
DBCREATOR.TABLENAME
/*
//*
For selective Unload, like when you are using a where clause or using select statements (like SELECT * from user_table;) we need to use PARM('SQL') in SYSTSIN statement; else you may endup with SQLCODE -104.
Your SYSTSIN would look like
//SYSTSIN DD *
SYSTEM (SUBSYS) RUN PROGRAM (DSNTIAUL)
PLAN (DSNTIAUL) -
LIBRARY (‘SUBSYS.DB2.RUNLIB.LOAD’) PARM('SQL')
END
//SYSIN DD *
SELECT * FROM schema.Tablename ;
Your SYSTSIN would look like
//SYSTSIN DD *
SYSTEM (SUBSYS) RUN PROGRAM (DSNTIAUL)
PLAN (DSNTIAUL) -
LIBRARY (‘SUBSYS.DB2.RUNLIB.LOAD’) PARM('SQL')
END
//SYSIN DD *
SELECT * FROM schema.Tablename ;
Thursday, February 18, 2016
TSO WHOHAS code in REXX
Sometimes we face job abends, or job waiting for resource owing to the fact that some datasets get into contention with some other jobs or some user is using that particular file. Most of the organizations use TSO WHOHAS command to check the user holding the dataset. In this post we will see the piece of code in REXX which makes the command work.
Without the rexx code also , we even can execute the command
TSO ISRDDN ENQ 'Data-set Name'
and it will show the corresponding information
/* REXX*/Simple piece of code and it uses ISRDDN utility. It is an IBM utility which lists all the allocated DDNAME for your current TSO session.
DSNAME = ARG(1)
IF DSNAME = ' ' THEN DO
SAY 'ENTER DATASET NAME'
PARSE UPPER EXTERNAL DSNAME
END
ADDRESS TSO
IF SYSDSN("'"DSNAME"'") <> 'OK' THEN DO
SAY "DATASET DOES NOT EXIST"
ADDRESS ISREDIT
EXIT
END
ADDRESS TSO "ISRDDN E ' "DSNAME" ' "
EXIT
Without the rexx code also , we even can execute the command
TSO ISRDDN ENQ 'Data-set Name'
and it will show the corresponding information
Tuesday, January 12, 2016
How to find the plan and package name in DB2 from program name
Suppose we have a cobol-db2 module named 'PGM-ABC'
We want to bind it and run the program. But we are not sure about the package and plan details.So where do we find it from? SYSIBM tables will give us the details we need.Lets check it out.
With the program name we can query SYSIBM.SYSPACKAGE table giving the name of the program(PGM-ABC) against the column 'NAME'. We can use DB2 file-aid tool or use the below query in SPUFI.
Select location, collid,name ,contoken,timestamp,bindtime from SYSIBM.SYSPACKAGE where NAME = 'PGM-NAME' ;
Once we get the COLLID,we need to query the SYSIBM.SYSPACKLIST table to get the plan name
SELECT PLANNAME,LOCATION,COLLID FROM SYSIBM.SYSPACKLIST WHERE COLLID='colld-id-name-we-got-above';
From experience, we should try to select the latest rows from the tables checking the TIMESTAMP fields; or check what other ppl have used in recent times.
Labels:
DB2
Wednesday, January 6, 2016
SAS in Mainframes(z/Os) - Connecting to DB2 from SAS in mainframes
This post is all about connecting DB2 from SAS in mainframe environment and using the result set for further processing. To call and connect to DB2 session we need the SQL proc to be called first using the statement PROC SQL. When used in a program we need to begin the code with PROC SQL and end it with QUIT; In Between these two we can write our SQL codes to fetch the required data.
Without wasting much time lets check the first JCL used to connect to db2.
Without wasting much time lets check the first JCL used to connect to db2.
//TTYYTST JOB(TEST),CLASS=I,MSGCLASS=X,MSGLEVEL=(1,1)
// NOTIFY=&SYSUID
//STEP01 EXEC PROC=SAS,OPTIONS=' '
//WORK DD SPACE=(CYL,(,500)),VOL=(,,,59)
//OUTFILE DD DSN=TEST.OUTPUT.SAS,
// DISP=(,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=122,BLKSIZE=000),
// UNIT=SYSDA,SPACE=(TRK,(500,500),RLSE)
//SYSIN DD *
OPTION NOCENTER;
OPTION SORTLIB;
PROC SQL; <== Starts here
CONNECT TO DB2 (SSID=DQAT); <== DQAT is the db2 subsystem here
CREATE TABLE test AS <== test is the sas datset here.
SELECT *
FROM CONNECTION TO DB2 (
select fname,
lastname,
dept_name,
from test01.dept
where student_id = 1 fetch first 5 rows only) ;
//STEP01 EXEC PROC=SAS,OPTIONS=' '
//WORK DD SPACE=(CYL,(,500)),VOL=(,,,59)
//OUTFILE DD DSN=TEST.OUTPUT.SAS,
// DISP=(,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=122,BLKSIZE=000),
// UNIT=SYSDA,SPACE=(TRK,(500,500),RLSE)
//SYSIN DD *
OPTION NOCENTER;
OPTION SORTLIB;
PROC SQL; <== Starts here
CONNECT TO DB2 (SSID=DQAT); <== DQAT is the db2 subsystem here
CREATE TABLE test AS <== test is the sas datset here.
SELECT *
FROM CONNECTION TO DB2 (
select fname,
lastname,
dept_name,
from test01.dept
where student_id = 1 fetch first 5 rows only) ;
%PUT SQLXRC=&SQLXRC;
%PUT SQLMSG=&SQLMSG;
QUIT;
DATA STEP1;
SET TEST;
FILE OUTFILE DLM=',' ;
IF _N_=1 THEN DO;
PUT 'FIRST NAME,'
'LAST NAME,'
'DEPT NAME,'
;
END;
PUT FNAME
LASTNAME
DEPT_NAME
;
//SYSPRINT DD SYSOUT=*
//*
JCL is self explanatory. %PUT SQLXRC and SQLMSG are the macros used to capture the DB2 return codes and error messages if any.
Labels:
SAS
Saturday, January 2, 2016
Invoke CA7 commands from Batch terminal - use of SASBSTR
CA7 is a product of Computer Associates and is a scheduling tool for batch jobs in mainframe. When the number of jobs to be executed are astronomical, it is difficult to manage the jobs manually. So we need a tool like CA7 to manage the same. Manipulation of jobs, predecessor and triggers are done through CA7 panels. But sometimes we need to define hundreds of jobs to CA7, it is advisable to use batch terminal to do the same. Also batch terminals are less prone to errors. Batch terminals are a set of CA7 commands in a member of a partitioned dataset which is input to a CA7 batch program and submitted using a JCL
The program which executes the CA7 commands in batch is called SASSBSTR. The list of commands are put into a member of a partitioned dataset and given as an input to the program through SYSIN DD statement in the JCL. When executing the SASSBSTR program, the SYSIN input statements are copied into the input dataset called CA7. Communication dataset informs CA7 that there are commands waiting in the input dataset. These are read and processed by CA7. Any output is written to the output dataset. When all the commands have been processed, SASSBSTR copies the contents of the output dataset to SYSPRINT. Have a look into the below diagram
![]() |
| CA7 commands from batch terminal |
Now, lets have the JCL to execute the CA7 from batch terminal.
//@SASBSTR EXEC PGM=SASBSTR
//UCC7CMDS DD DSN=TTOS.NCA7A01.COMMDS,DISP=SHR
//SYSDUMP DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
LJOB,JOB=SJABCD7,LIST=ALL <== CA7 command goes here
/*
//*
All relevant information for the particular job SJABCD7 will be listed in SYSOUT since we gave SYSPRINT DD SYSOUT=*.
Check the commonly used CA7 commands in this page. We can use these commands in the SYSIN DD* statements.
Explanation of JCL:
SASSBSTR is the program which executes the batch terminal
UCC7CMDS DD statement is a communication dataset which is used to read the CA7 commands from SYSIN DD Statements into the input dataset.
The CA7 commands are embedded within the SYSIN DD statement.All valid commands can be used here. Usually the programs are written in a cataloged procedure and the batch terminal is given as an input to the program. The output can be stored in a dataset.
Wednesday, December 30, 2015
Passing Data from JCL to COBOL program
We pass data from JCL to cobol program in two ways:
1. Using the PARM keyword
2. Using SYSIN DD in JCL
The basic difference between these two ways of passing are as follows:
2. Using SYSIN DD in JCL
The basic difference between these two ways of passing are as follows:
A. Using 'PARM=' on the exec keyword, we can pass only 100 characters of data. Also in cobol we need linkage section to take the values in.
B. When we pass data through SYSIN, we need to have the accept keyword in COBOL. For each row in SYSIN, we need to have corresponding ACCEPT verb in cobol.
Sample cobol program accepting PARM value through linkage
...
......
LINKAGE SECTION.
...
......
LINKAGE SECTION.
01 LS-TEST-PARM.
05 LS-TEST-LENGTH PIC S9(04) USAGE COMP.
05 LS-VAR1 PIC 9(02).
05 LS-VAR2 PIC 9(02).
PROCEDURE DIVISION USING LS-TEST-PARM.
DISPLAY LS-VAR1.
DISPLAY LS-VAR2.
DISPLAY LS-TEST-LENGTH.
STOP RUN.
Have a look into the corresponding JCL.
//TTYYTST JOB(TEST),CLASS=I,MSGCLASS=X,MSGLEVEL=(1,1)
// NOTIFY=&SYSUID
//*
//JSTEP01 EXEC PGM=SAMPLE3,PARM='1211212'
//STEPLIB DD DSN=TEST.LOAD.LIB1,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
RESULT:
12
11
007
Sample program accepting data from SYSIN .
...
....
DATA DIVISION.
....
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TOTAL
05 WS-VAR1 PIC X(02).
05 WS-VAR2 PIC X(02).
PROCEDURE DIVISION.
INITIALIZE WS-TOTAL.
ACCEPT WS-VAR1.
ACCEPT WS-VAR2.
DISPLAY WS-VAR1.
DISPLAY WS-VA22 .
Corresponding JCL:
//TTYAATST JOB(TEST),CLASS=I,MSGCLASS=X,MSGLEVEL=(1,1)
// NOTIFY=&SYSUID
//*
//JSTEP01 EXEC PGM=SAMPLE1
//STEPLIB DD DSN=TEST.LOAD.LIB1,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=
//sysin dd*
12
31
/*
//*
Result:
12
31
If we do not have any data to be passed we can make SYSIN DD DUMMY. I tried passing blank values via SYSIN. Was Expecting an abend, but it did not. It displayed spaces in SYSOUT.
Wednesday, November 25, 2015
COBOL DB2 Program from scratch - step by step guide
This post is just to help/guide to a new programmer in writing a cobol db2 program from scratch. For Advanced topics on mainframe you can visit https://dbztech.blog/
Let us write a cobol program to read the EMPLOYEE table and get the details of the employee with name 'RYAN'.
I am assuming the table is already created in the user database like below:.
EMPLOYEE
EMPID EMPNAME DEPARTMENT SALARY DESIGNATION
1000 XXXXXXX XX 10000 SE
1001 YYYYYYY YY 9000 SE
1002 ZZZZZZZ ZZ 20000 TL
STEP1: We need to declare the Table structure in the Working Storage section. Ideally we should DCLGEN Tool to generate the structure for our DB2 table. The option to go to our DCLGEN tool depends on the ISPF settings. Generally it can be invoked using 'D' option on the ispf menu to display DB2I Default pannel.
On pressing ENTER, the DCLGEN will be generated and will look like below.
I am not going into the details of cursor programming here, since those are there in other posts.
Once the program is ready and compiled , we need to bind it to a plan in the test region. Once the bind is successful, we can run the program using the IKJEFT01 utility as below.
Let us write a cobol program to read the EMPLOYEE table and get the details of the employee with name 'RYAN'.
I am assuming the table is already created in the user database like below:.
EMPLOYEE
EMPID EMPNAME DEPARTMENT SALARY DESIGNATION
1000 XXXXXXX XX 10000 SE
1001 YYYYYYY YY 9000 SE
1002 ZZZZZZZ ZZ 20000 TL
STEP1: We need to declare the Table structure in the Working Storage section. Ideally we should DCLGEN Tool to generate the structure for our DB2 table. The option to go to our DCLGEN tool depends on the ISPF settings. Generally it can be invoked using 'D' option on the ispf menu to display DB2I Default pannel.
![]() |
| DCLGEN Screen |
*****************************************************************This DCLGEN needs to be included into the Working Storage Section of our cobol program in the following way:
EXEC SQL DECLARE DEV.EMPLOYEE TABLE
( EMPID CHAR(10) NOT NULL,
EMPNAME CHAR(30) NOT NULL,
DEPARTMENT CHAR(2) NOT NULL,
SALARY DECIMAL(10,2) NOT NULL,
DESIGNATION CHAR(4) NOT NULL )
)
END-EXEC.
*************** COBOL DECLARATION FOR TABLE DEV.EMPLOYEE *********
01 EMPOYEE-RECORD.
05 HV-EMPID PIC X(10).
05 HV-EMPNAME PIC X(30).
05 HV-DEPARTMENT PIC X(2).
05 HV-SALARY PIC S9(8)V99 COMP-3.
05 HV-DESIGNATION PIC CHAR(4).
*********** THE NUMBER OF COLUMNS IN THIS DECLARATION IS 5 *****
EXEC SQLAlso, the most important copybook SQLCA needs to be included . Apart from this we wont be able to capture the SQL Return codes
INCLUDE EMPLOYEE
END-EXEC.
EXEC SQLAlso since our query in the program might return more than single row, we need cursors in our program. Read About cursor programming here
INCLUDE SQLCA
END-EXEC.
I am not going into the details of cursor programming here, since those are there in other posts.
Once the program is ready and compiled , we need to bind it to a plan in the test region. Once the bind is successful, we can run the program using the IKJEFT01 utility as below.
![]() |
| cobol db2 run jcl |
Wednesday, November 18, 2015
Frequently used CA7 Commands
To Define Jobs in CA7:
Each Job in CA7 must first be defined in its database; the easiest way to do this is through the command 'JOB'. Just type the command JOB or 'DB' in the CA7 Scheduler and it will show the list of available options we have to add the jobs.Lets have look into some of the day-to-day commands which we use frequently to check the job schedules and other details.
1. LJOB,JOB=jobname,LIST=ALL
It will show you all the details of the job once you press enter.
We can use the below values with the LIST parameter
LIST=NODD. It will show the TRIGGERED BY JOS and SUCCESSOR jobs
LIST=RQMT to get the Requirement and Network connections
LIST=SCHD to know many sch id are assigned to a particular job using the below command
LIST=TRIG to know only the triggering jobs
2. Get the list of jobs in tree structure. Use the command
FRJOB,JOB=jobname
3. Get the tree structure of the downstream job. Use the command
FSTRUC,JOB=jobname
4. Get the JCL in the pannel using the below command
LJCL,JOB=jobname
5.List the active jobs using the command
LACT
6. Want to see the member names in any PDS. Use the below command
LISTDIR,DSN=pds-name
Labels:
CA7
CA7 Guide for beginner's
CA7 is a product of Computer Associates and is a scheduling tool for batch jobs in mainframe.When the number of jobs to be executed is huge in number and jobs need to be executed depending on several parameters (like time dependency, availability of data sets from other jobs, successful completion of other jobs), a tool like CA7 comes into play.
Once a job is scheduled /triggered or manually added in CA7, it will start a process of moving through various QUEUES in CA7. CA7 will manage it until its completion.
Below is the diagram which shows in brief the lifecyle of the job inside a CA7 Scheduler.
Lets have a quick look into the Queues:
Request Queue: When a job enters CA7, it will reside in the request queue until all its requirements have been satisfied. Examples of requirements can be cited like :
Predecessor job
User holds
Submit time
Data set requirements
Ready Queue: When a job's requirement have been satisfied, it will move to the ready queue. It will wait until initiators are available and any virtual resource or workload manager requirement is satisfied to enable it to execute.
Active Queue: When job can run it is moved to the active Q where it will remain whilst the job is executing within JES2. Once the job has completed successfully on JES2 the job will be marked completed within CA7 and is removed from the active Q.
Failure list: If the job fails the it will be moved back to the requirement queue but will need correction prior to rerun. JCL errors are returned to ready Q and other failures are moved to request Q.
How to login to CA7.
Differnet systems use different methods to get into CA7. Some system allow the users to access the CA7 from ISPF menu while others use varied methods. Once we go inside the interface all remains the same.
Refer to This link for list of CA7 Commands.
Once a job is scheduled /triggered or manually added in CA7, it will start a process of moving through various QUEUES in CA7. CA7 will manage it until its completion.
Below is the diagram which shows in brief the lifecyle of the job inside a CA7 Scheduler.
Lets have a quick look into the Queues:
Request Queue: When a job enters CA7, it will reside in the request queue until all its requirements have been satisfied. Examples of requirements can be cited like :
Predecessor job
User holds
Submit time
Data set requirements
Ready Queue: When a job's requirement have been satisfied, it will move to the ready queue. It will wait until initiators are available and any virtual resource or workload manager requirement is satisfied to enable it to execute.
Active Queue: When job can run it is moved to the active Q where it will remain whilst the job is executing within JES2. Once the job has completed successfully on JES2 the job will be marked completed within CA7 and is removed from the active Q.
Failure list: If the job fails the it will be moved back to the requirement queue but will need correction prior to rerun. JCL errors are returned to ready Q and other failures are moved to request Q.
How to login to CA7.
Differnet systems use different methods to get into CA7. Some system allow the users to access the CA7 from ISPF menu while others use varied methods. Once we go inside the interface all remains the same.
Refer to This link for list of CA7 Commands.
Thursday, October 29, 2015
REUSE option in VSAM and IDCAM. Drawbacks of Reuse.
I have seen the REUSE parameter in the REPRO statement using IDCAMS. Backtracking the purpose of using it, came to know several features of this keyword which i am sharing here.
Some applications might need temporary files, which can be deleted after the program run is over.You may need these files in the form of a KSDS,ESDS or RRDS. Thus VSAM allows to create a Reusable cluster or files using this keyword in the definition of the cluster.
Lets see what happens if we do not use the REUSE parameter ?
In this case, we can reload the VSAM only once.Only way to reload the data is to DELETE DEFINE the vsam file and repro the data.Should we reload it again, we need to delete/define it again. In order to remove this repeated DELETE DEFINE steps, we can define the vsam with REUSE parameter.
Do we remember the term HURBA ? Check the listcat section once how we can know about it.
HURBA stands for --> Highly Used Relative Byte Area.
When we delete define a VSAM, this HURBA remains as zero. It increments as we add records. Ideally this HURBA indicates the offset of the last byte in the data set.
When we use reuse option, this HURBA is reset back to zero. Logically we are deleting all the records thereby.
Thus,the REUSE parameter allows us to reload the vsam as if it were empty.
Although it sounds simple, but there are certain drawbacks for using REUSE parameter.
We know VSAM performance depends on the CI/CA splits. With this resue option, the CI/CA splits remain in place. Over the period of time the performance degrades.
Few points to remember :
1. We cant use REUSE in the repro when the cluset is not defined with REUSE option.
However we can Alter the VSAM definition to make it resuable.
Some applications might need temporary files, which can be deleted after the program run is over.You may need these files in the form of a KSDS,ESDS or RRDS. Thus VSAM allows to create a Reusable cluster or files using this keyword in the definition of the cluster.
Lets see what happens if we do not use the REUSE parameter ?
In this case, we can reload the VSAM only once.Only way to reload the data is to DELETE DEFINE the vsam file and repro the data.Should we reload it again, we need to delete/define it again. In order to remove this repeated DELETE DEFINE steps, we can define the vsam with REUSE parameter.
Do we remember the term HURBA ? Check the listcat section once how we can know about it.
HURBA stands for --> Highly Used Relative Byte Area.
When we delete define a VSAM, this HURBA remains as zero. It increments as we add records. Ideally this HURBA indicates the offset of the last byte in the data set.
When we use reuse option, this HURBA is reset back to zero. Logically we are deleting all the records thereby.
Thus,the REUSE parameter allows us to reload the vsam as if it were empty.
Although it sounds simple, but there are certain drawbacks for using REUSE parameter.
We know VSAM performance depends on the CI/CA splits. With this resue option, the CI/CA splits remain in place. Over the period of time the performance degrades.
Few points to remember :
1. We cant use REUSE in the repro when the cluset is not defined with REUSE option.
However we can Alter the VSAM definition to make it resuable.
//STEPA EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=A
//SYSIN DD *
ALTER -
TEST.VSAMDATASET -
REUSE
2. Cluster defined with Reuse keyword can not have alternate index defined on it.Saturday, September 26, 2015
Including Date field in the output file using SORT
Including Date field in the output file:
Many a times it is required to include the date in the output file. This can be done using DATE parameter in SORT.
There are 3 DATE parameter option available, DATEn, DATEn(c) and DATEnP where n=1, 2 or 3.
Consider the input file INFILE,
1111111111111111111111111111
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
The output date is in Zoned Decimal format.
The DATE1 occupies 10 bytes and gives the date in YYYYMMDD format.
The DATE2 occupies 6 bytes and gives the date in YYYYMM format.
The DATE3 occupies 7 bytes and gives year and Julian date (JDT) as YYYYJDT format.
The JCL’s below show the use of DATEn parameter. The current date August 26, 2010(Julian Date 238)
The contents of OUTFILE are as below,
OUTFILE:
1111111111111111111111111111 20100826
1111111111111111111111111111 20100826
1211111111111111111111111111 20100826
............
On using DATE1 we have the current date in YYYYMMDD format.
1111111111111111111111111111 201008
1111111111111111111111111111 201008
1211111111111111111111111111 201008
.........
On using DATE2 we have the output date in YYYYJDT format
1111111111111111111111111111 2010238
Using the DATEn(c) parameter:
On using the DATEn(C) parameter, the output date appears in formatted way wherein a character ‘/’ is placed between the year month and date fields.
DATE1(c) occupies 10 bytes and the format is YYYY/MM/DD.
DATE2(c) occupies 7 bytes and the format is YYYY/MM.
DATE3(c) occupies 7 bytes and the format is YYYY/JDT.
Using the DATEnP parameter:
On using DATEnP the output appears in Packed decimal format. So the number of bytes occupied is lesser than DATEn parameter. Other than this there is no difference between DATEn and DATEnP.
The DATE1 occupies 5 bytes and gives the date in YYYYMMDD format.
The DATE2 occupies 4 bytes and gives the date in YYYYMM format.
The DATE3 occupies 4 bytes and gives year and Julian date (JDT) as YYYYJDT format.
1111111111111111111111111111 2010238
Retrieving Information on records having older dates:
Consider a case wherein we need to retrieve records that have yesterday’s date.
The JCL is as below,
Many a times it is required to include the date in the output file. This can be done using DATE parameter in SORT.
There are 3 DATE parameter option available, DATEn, DATEn(c) and DATEnP where n=1, 2 or 3.
Consider the input file INFILE,
1111111111111111111111111111
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
The output date is in Zoned Decimal format.
The DATE1 occupies 10 bytes and gives the date in YYYYMMDD format.
The DATE2 occupies 6 bytes and gives the date in YYYYMM format.
The DATE3 occupies 7 bytes and gives year and Julian date (JDT) as YYYYJDT format.
The JCL’s below show the use of DATEn parameter. The current date August 26, 2010(Julian Date 238)
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT DD DSN=OUTFILE1,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,29,&DATE1)
//
The contents of OUTFILE are as below,
OUTFILE:
1111111111111111111111111111 20100826
1111111111111111111111111111 20100826
1211111111111111111111111111 20100826
............
On using DATE1 we have the current date in YYYYMMDD format.
//STEP01 EXEC PGM=SORTThe contents of OUTFILE2 are as below,
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT DD DSN=OUTFILE2,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,29,&DATE2)
//
1111111111111111111111111111 201008
1111111111111111111111111111 201008
1211111111111111111111111111 201008
.........
On using DATE2 we have the output date in YYYYJDT format
//STEP01 EXEC PGM=SORTThe contents of the OUTFILE2 is as below,
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT DD DSN=OUTFILE2,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,29,&DATE3)
//
1111111111111111111111111111 2010238
Using the DATEn(c) parameter:
On using the DATEn(C) parameter, the output date appears in formatted way wherein a character ‘/’ is placed between the year month and date fields.
DATE1(c) occupies 10 bytes and the format is YYYY/MM/DD.
DATE2(c) occupies 7 bytes and the format is YYYY/MM.
DATE3(c) occupies 7 bytes and the format is YYYY/JDT.
Using the DATEnP parameter:
On using DATEnP the output appears in Packed decimal format. So the number of bytes occupied is lesser than DATEn parameter. Other than this there is no difference between DATEn and DATEnP.
The DATE1 occupies 5 bytes and gives the date in YYYYMMDD format.
The DATE2 occupies 4 bytes and gives the date in YYYYMM format.
The DATE3 occupies 4 bytes and gives year and Julian date (JDT) as YYYYJDT format.
1111111111111111111111111111 2010238
Retrieving Information on records having older dates:
Consider a case wherein we need to retrieve records that have yesterday’s date.
The JCL is as below,
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=INFILE1,DISP=SHR
//SORTOUT DD DSN=OUTFILE3,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(30,8,CH,EQ,&DATE1-1)
OUTREC FIELDS=(1,40)
//
Thursday, September 3, 2015
Splitting Input Files using Sort. Use of SPLIT ,SPLITBY,SPLIT1R commmands
SPLIT command spits the output records one record at a time among output datasets. This happens until all the output records are written. The split happens in rotation among the datasets mentioned in the OUTFIL.
The First record from the output records is written to first dataset mentioned in the OUTFIL group, the Second record from the output records gets written to the second dataset mentioned in the OUTFIL group and so on.
When each OUTFIL dataset has 1 record, the rotation starts again with the dataset mentioned first in the OUTFIL group.
The records are not contiguous in the OUTFIL datasets.
The Below JCL splits the data in INFILE and copies to OUTFILE1 and OUTFILE2 as mentioned above.
Consider the contents of Input File - INFILE as below:
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
Let us use the commands and see the outputs.
The Below JCL splits the data in INFILE and copies to OUTFILE1 and OUTFILE2 as mentioned above.
The contents of OUTFILE1 and OUTFILE2 would be as below,
OUTFILE1
1111111111111111111111111111
1311111111111111111111111111
1511111111111111111111111111
1711111111111111111111111111
1911111111111111111111111111
2111111111111111111111111111
OUTFILE2
1211111111111111111111111111
1411111111111111111111111111
1611111111111111111111111111
1811111111111111111111111111
2011111111111111111111111111
OUTFILE1 dataset contains records 1, 3, 5…so on.
OUTFILE2 dataset contains records 2, 4, 6…so on.
Note that the records in the output datasets are not contiguous.
SPLITBY Command:
SPLITBY splits the output records M records at a time in rotation among the datasets mentioned in the OUTFIL. This happens until all the output records are written.
The First Set of records from the output records gets written to first dataset mentioned in the OUTFIL group, the Second Set of records from the output records gets written to the second dataset mentioned in the OUTFIL group and so on.
When each OUTFIL dataset has the specified set of records, the rotation starts again with the dataset mentioned first in the OUTFIL group.
The syntax is SPLITBY=M, where M=1,2,3…so on
The records are not contiguous in the OUTFIL datasets.
SPLITBY=1 is equivalent to SPLIT.
The below JCL splits the data in INFILE and copies to OUTFILE3 and OUTFILE4 as mentioned above.
OUTFILE3
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
OUTFILE4
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
OUTFILE3 contains records (1, 2, 3), (7, 8, 9).
OUTFILE4 contains records (4, 5, 6), (10, 11).
Note that the records in the output datasets are not contiguous.
SPLIT1R splits output records M records at a time in one rotation among the datasets mentioned in the OUTFIL. This happens until all the records are written. In SPLIT1R the rotation happens only once among the OUTFIL datasets.
If on reaching the last OUTFIL, more than M records from the output records is left, all of those would be move to last OUTFIL.
If the input has only M records, then all input records will get moved to the first OUTFIL. The remaining OUTFIL datasets will be empty.
The syntax is SPLIT1R=M, where M=1, 2, 3…so on.
The records are contiguous among the OUTFIL datasets.
The below JCL’s splits the data in INFILE,
JCL1:
The output files contents are shown below,
OUTFILE5:
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
OUTFILE6:
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
There are two output files, and M=5. The input INFILE contains 11 records.
The OUTFILE5 contains records 1, 2, 3, 4, 5.
The dataset OUTFILE6 contains records 6, 7, 8, 9, 10, 11(i. e all the remaining records)
JCL2:
OUTFILE7:
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
OUTFILE8
empty as expected.
The First record from the output records is written to first dataset mentioned in the OUTFIL group, the Second record from the output records gets written to the second dataset mentioned in the OUTFIL group and so on.
When each OUTFIL dataset has 1 record, the rotation starts again with the dataset mentioned first in the OUTFIL group.
The records are not contiguous in the OUTFIL datasets.
The Below JCL splits the data in INFILE and copies to OUTFILE1 and OUTFILE2 as mentioned above.
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
Let us use the commands and see the outputs.
The Below JCL splits the data in INFILE and copies to OUTFILE1 and OUTFILE2 as mentioned above.
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT1 DD DSN=OUTFILE1,DISP=SHR
//SORTOUT2 DD DSN=OUTFILE2,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(SORTOUT1,SORTOUT2),SPLIT
/*
The contents of OUTFILE1 and OUTFILE2 would be as below,
OUTFILE1
1111111111111111111111111111
1311111111111111111111111111
1511111111111111111111111111
1711111111111111111111111111
1911111111111111111111111111
2111111111111111111111111111
OUTFILE2
1211111111111111111111111111
1411111111111111111111111111
1611111111111111111111111111
1811111111111111111111111111
2011111111111111111111111111
OUTFILE1 dataset contains records 1, 3, 5…so on.
OUTFILE2 dataset contains records 2, 4, 6…so on.
Note that the records in the output datasets are not contiguous.
SPLITBY Command:
SPLITBY splits the output records M records at a time in rotation among the datasets mentioned in the OUTFIL. This happens until all the output records are written.
The First Set of records from the output records gets written to first dataset mentioned in the OUTFIL group, the Second Set of records from the output records gets written to the second dataset mentioned in the OUTFIL group and so on.
When each OUTFIL dataset has the specified set of records, the rotation starts again with the dataset mentioned first in the OUTFIL group.
The syntax is SPLITBY=M, where M=1,2,3…so on
The records are not contiguous in the OUTFIL datasets.
SPLITBY=1 is equivalent to SPLIT.
The below JCL splits the data in INFILE and copies to OUTFILE3 and OUTFILE4 as mentioned above.
//STEP01 EXEC PGM=SORTThe contents of OUTFILE3 and OUTFILE4 would be as below,
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT1 DD DSN=OUTFILE3,DISP=SHR
//SORTOUT2 DD DSN=OUTFILE4,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(SORTOUT1,SORTOUT2),SPLITBY=3
/*
OUTFILE3
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
OUTFILE4
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
OUTFILE3 contains records (1, 2, 3), (7, 8, 9).
OUTFILE4 contains records (4, 5, 6), (10, 11).
Note that the records in the output datasets are not contiguous.
SPLIT1R splits output records M records at a time in one rotation among the datasets mentioned in the OUTFIL. This happens until all the records are written. In SPLIT1R the rotation happens only once among the OUTFIL datasets.
If on reaching the last OUTFIL, more than M records from the output records is left, all of those would be move to last OUTFIL.
If the input has only M records, then all input records will get moved to the first OUTFIL. The remaining OUTFIL datasets will be empty.
The syntax is SPLIT1R=M, where M=1, 2, 3…so on.
The records are contiguous among the OUTFIL datasets.
The below JCL’s splits the data in INFILE,
JCL1:
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT1 DD DSN=OUTFILE5,DISP=SHR
//SORTOUT2 DD DSN=OUTFILE6,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(SORTOUT1,SORTOUT2),SPLIT1R=5
The output files contents are shown below,
OUTFILE5:
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
OUTFILE6:
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
There are two output files, and M=5. The input INFILE contains 11 records.
The OUTFILE5 contains records 1, 2, 3, 4, 5.
The dataset OUTFILE6 contains records 6, 7, 8, 9, 10, 11(i. e all the remaining records)
JCL2:
//STEP01 EXEC PGM=SORTThe output file contents are shown below:
//SORTIN DD DSN=INFILE,DISP=SHR
//SORTOUT1 DD DSN=OUTFILE7,DISP=SHR
//SORTOUT2 DD DSN=OUTFILE8,DISP=SHR
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(SORTOUT1,SORTOUT2),SPLIT1R=11
//
OUTFILE7:
1111111111111111111111111111
1211111111111111111111111111
1311111111111111111111111111
1411111111111111111111111111
1511111111111111111111111111
1611111111111111111111111111
1711111111111111111111111111
1811111111111111111111111111
1911111111111111111111111111
2011111111111111111111111111
2111111111111111111111111111
OUTFILE8
empty as expected.
Convert VB file to FB and Convert FB file to VB using SORT
The below JCL copies the VB file to FB file.
The INPUTVBFILE is a VB file with record length 80.
The OUTPUTFFBFILE is a FB file of record length 76.
Before executing the JCL it is assumed that both the SORTIN and SORTOUT datasets exists.
SORT FIELDS=(5,76,CH,A) sorts the input VB file.
VTOF will handle copying the VB file to FB file.
It is essential to give BUILD or OUTREC parameter when VTOF parameter is used.
Below JCL will Convert FB file to VB
It is not essential to give BUILD or OUTREC parameter when FTOV parameter is used.
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=INPUTVBFILE,DISP=SHR
//SORTOUT DD DSN=OUTPUTFBFILE,DISP=SHR
//*
//SORTWK01 DD SPACE=(CYL,10),UNIT=SYSDA
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(5,76,CH,A)
OUTFIL FNAMES=SORTOUT,VTOF,BUILD=(5,76)
/*
The INPUTVBFILE is a VB file with record length 80.
The OUTPUTFFBFILE is a FB file of record length 76.
Before executing the JCL it is assumed that both the SORTIN and SORTOUT datasets exists.
SORT FIELDS=(5,76,CH,A) sorts the input VB file.
VTOF will handle copying the VB file to FB file.
It is essential to give BUILD or OUTREC parameter when VTOF parameter is used.
Below JCL will Convert FB file to VB
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=INPUTFBFILE,DISP=SHR
//SORTOF01 DD DSN=OUTPUTVBFILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// DCB=(LRECL=80,RECFM=VB,BLKSIZE=84),
// SPACE=(TRK,(3000,2000),RLSE)
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOF01,FTOV
It is not essential to give BUILD or OUTREC parameter when FTOV parameter is used.
Tuesday, August 4, 2015
Can we delay the execution of a mainframe job?OPSWAIT is an option
Have you ever tried to keep a job or certain steps in a job to wait for sometime and then execute without using any scheduler ?
This post is just to help/guide to a new programmer in writing a cobol db2 program from scratch. For Advanced topics on mainframe you can visit https://dbztech.blog/
When would it be useful to ask mainframes to sleep like this?
Few days back ,came across a specific scenario when it was needed to put a job step on hold for sometime and then execute it.
Say for unit testing you want to execute two jobs in certain instance to check dataset conflict or table conflict.
Suppose we have a job with 3 steps. We want to execute step1 an then wait for sometime, say 1 minute, and then execute the remaining 2 steps. How do we do it ?
OPSWAIT is the option which can help us in this scenario. (We need CA tool to be installed in our environment).
The OPSWAIT function suspends processing of the program or rule for a specified period in an OPS/REXX program or REQ rule.This function can be used in OPS/REXX, AOF rules, TSO/E REXX, or CLIST.
//Jobcard..
//PSTEP01 EXEC PGM=TSTPGM
...
//PSTEP02 EXEC PGM=OPSWAIT,PARM='FOR(01:00)'
//PSTEP03 EXEC PGM=TSTPGM2
....
Once you submit this JCL, it till execute the step PSTEP01,then it will cause the mainframe to sleep for 1 min and then execute step 2.
We can try this command going into TSO command (option 6) and typing OPSWAIT 01:00.(01=mins,00=seconds)
We can also use this JCL to put the program on hold.
//SLEEP EXEC PGM=IKJEFT01
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
OPSWAIT FOR(01:10)
//*
Subscribe to:
Posts (Atom)









