Mainframes 360
The one stop destination for System Z professionals

Thursday, August 20, 2009

MOVE Verb, Alpha-numeric MOVE, Numeric MOVE, Editing Symbols


Contents

  1. How the MOVE Verb works 
    1. Rules to be applied while MOVEing 
  2. MOVEing to an Alphanumeric Data-Item 
    1. Simple Program that shows an alpha-numeric MOVE 
  3. MOVEing to a Numeric Data-item
    1. Simple Program to show a Numeric MOVE 
  4. Editing Symbols 
    1. Rules of how EDITING symbols work
    2. Simple Program to show working of varous EDITING Symbols

Q. How does the MOVE Verb in COBOL work?

Suppose we have two WORKING STORAGE Data-items A and B. Assume that A is a numeric data-item containing the value 2. B is also a numeric data-item containing the value 3. What happens when we write the instruction :

MOVE A TO B.

This instruction copies the value of A into B. Note that the variable B can only hold 1 value at a time. So, the old data value 3 stores in B, is now over-written by a new data-value 2.

A is called the sending field, B is called the receiving field. We can also move literals/figurative constants into a variable. For example,

MOVE 123 TO A.

However, we cannot just move any value into a destination variable. There are some rules which apply.
1.
MOVE can copy elementary or group data-items.
2. In MOVE Operation, if the source data-item is too small to fit into the destination data-item fully, the remaining area is blanked(B) out (if alphanumeric move) or zeroed out(if numeric move).
3. When moving to a numeric data-item, the contents are always right-justified, for digits before the decimal point(to the left), and left-justified for digits after the decimal point.
4. When moving to an alpha-numeric data-item, the contents are always left-justified.
5. You can also move one group data-item or record to another group data-item. These are always treated as alpha-numeric moves.

Q. What is an Alpha-numeric MOVE?

When the receiving field/destination item is alpha-numeric, i.e. it has a PICTURE Clause XXX, then the move is called an Alphanumeric MOVE.

Let’s take a simple program that’ll help us to understand the above rules. Suppose we have a EMP-NAME Independent data-item which is alphanumeric of size 8. It initially stores the value JAYAPRADA.

Now, we move the literal ‘QUASAR’ to EMP-NAME. Firstly, we need to understand, that when we move data to a field, this old contents of the receiving field will be completely replaced. So, ‘QUASAR’ has a length=6. Thus, EMP-NAME is large enough to hold the literal ‘QUASAR’. What happens to the remaining 2 places in EMP-NAME? They will contain blanks. So, in the output, EMP-NAME is displayed as

QUASARBB

I’ve explicitly written BB to indicated two blanks. Blanks are simply displayed as whitespace in Output.

Now, when we move the literal ‘CHUNAWALLA’ to EMP-NAME, ‘CHUNAWALLA’ has length 10, so its too large to fit into EMP-NAME. Hence, a small part of ‘CHUNAWALLA’ will be stripped off, or cut off. Since, EMP-NAME is alpha-numeric, the contents will be left-justified. Hence, EMP-NAME will contain CHUNAWAL, and the last two characters LA are cut-off.


Upon running the above COBOL Program, we get the following Output in the SYSOUT Dataset.


Q. What is a Numeric MOVE?

When the destination is a numeric data-item, we consider it to be a numeric move. In Numeric moves, the data is aligned along the decimal point. For the integer part of the number, the movement is from right to left. For the decimal portion of the number, the movement is from left to right.

Let me show you a simple example that will be an aid to understand the above concept with great ease.




The Output of the above COBOL Program, as seen in SYSOUT Dataset, is as follows :

 
In the first MOVE, we store the value 1234.56 in SALARY Field which 9(4)V9(2). Thus, it fits exactly into SALARY. In the second MOVE, we store 12345.6 in SALARY. First, the SALARY Field is zeroed out so it contains 0000|00. Next, 12345 in SALARY, from right-to-left. 1 is truncated, or stripped off. The 6 is stored in the decimal part from left-to-right. So, SALARY field contains 2345|60. In the third move, we store 123.456 in SALARY Field. In this case, the integer part contains 0123 and the decimal part stores 45, with 6 being cut-off.

Q. What are the various EDITING Symbols?

A COBOL Program takes input data in the form of records, performs processing or operations on the Input Data records, to produce resultant Output Records. Very often, we need to customize or re-format the way, certain fields are displayed in the Output report.

For example, we may have to add leading blank spaces, suppress leading zeroes, or trailing zeros to the rhs of the decimal point, insert $, CR and DB symbols, show sign(+ or -) of the number, display decimal point etc. These are called as
Editing symbols.

Given below is simple COBOL Program, which demonstrates how to use various Edit symbols.




 
Upon compiling and executing the above COBOL Program, we get the following output in the SYSOUT Dataset -

Saturday, August 15, 2009

WORKING-STORAGE SECTION, Rough-work areas in COBOL


Contents

  1. WORKING-STORAGE SECTION 
  2. Simple COBOL Program to declare and use WORKING STORAGE Areas 



Q. Could you throw some light on the WORKING-STORAGE SECTION of a COBOL Program?

The WORKING-STORAGE SECTION is used to declare any fields or records that are not going to be used in input files, or output files, but they are used to store the intermediate results of processing in a temporary storage area. WORKING STORAGE SECTION will always follow the FILE SECTION. Here too, we can describe the records in the same as we do in the FILE SECTION.
WORKING-STORAGE SECTION can contain group-items and elementary data-items also, just like the FILE SECTION Paragraph. An initial value may also be assigned to the data-items by using the VALUE Clause.

The storage for WORKING-STORAGE items is allocated, when you start running the COBOL Program.

Given below is a simple program that stores some data in Working Storage Variables, and then displays them on the Spool Output SYSOUT Dataset.


Upon running the above COBOL Program, we get the following output in the SYSOUT Dataset.

Thursday, August 6, 2009

Common COBOL Errors and Coding Standards

Q. What are some of the common COBOL Errors, a beginner could make?
Here are the top 10 Mistakes in COBOL, you should watch out for, when you start-out to write COBOL-Programs.

1. Period was Required
Often, you forget to put periods after divisions, sections or para's, and that’s when you get a "A Period was Required" Message. See what happens when you forget to put a period after IDENTIFICATION DIVISION.

Image280 
2. Forgetting a Dash
You will get strange error-Messages when you forget to put a dash in paragraph names that have multiple words. For example, if you forget to code a dash in the OPEN-FILE-ROUTINE, you get the following error Message.

Image281 
3. XXX should not begin in Area-A
I have coded PERFORM Instruction by error in Col 11. Coding a COBOL-statement in Area-A, when it should begin in Area-B, will issue an error like ... should not begin in Area-A, it was processed as if in Area-B.

Image282 
4. YYY should begin in Area-A.
I have coded the OPEN-FILE-ROUTINE by mistake in Area B. Coding a para, section or division entry in Area-B, when it should begin in Area-A, will issue an error like ...should begin in Area-A, it was processed as if in
Area-A.

Image283 
5. XXX was not defined as a data-name.
I have declared the Variable WS-EMPLOYEE-SALARY in the Working Storage Section. But in the PROCEDURE DIVISION, while using it, I did a Typo-error, and spelled it as WS-EMPLOYEE-SALRY(forgot the 'A'). COBOL Compiler does not recognize the Data-name WS-EMPLOYEE-SALRY(the one without the 'A'), and complains about it.

Image284 
6. The XXX Statement was Invalid. Expected ..., but found something else.
I must have committed a Syntax-error. Out here, I’ve forgotten to put a closing single-quote on the Literal String 'QUASAR'. Here’s what the Compiler complains.

Image285 
7. Putting PICTURE Clause on a Group Data-Item.
Many beginners write the PICTURE Clause on the Group Level Data-Item. In COBOL, you break down Group Data-items further in smaller Storage Areas. So, you always specify the PICTURE Clause for the Lowest-Level Data-Items. By error, I have coded PICTURE Clause on WS-EMPLOYEE-RECORD, when it should be specified only for the EMPLOYEE-NAME, EMPLOYEE-SALARY and EMPLOYEE-JDATE Fields.

Image286 
8. Neither an FD nor SD was found in the Program for the File XXX.
I have done a typo-error in the FD Para, so the COBOL Internal file-name specified in the SELECT Clause does not match the FD Descriptor.

Image287

9. No Matching Scope-Terminator Found.
When you code IFs, EVALUATEs, loops using Inline PERFORMs be sure to supply the Scope Terminator END-IF, END-EVALUATE,
END-PERFORM correctly. The Compiler Software recognizes the statements inside an PERFORM..END-PERFORM as one block. I've forgotten to code an END-PERFORM, and the compiler complains about it– it doesn't know where the PERFORM Block ends. 

Image290
Q. What are some COBOL Coding Standards one should follow?
Program Header : Every COBOL Module should begin with a Program-Header, that specifies the Program Name, system, description, File Access, DB2 Tables Access, Sub-programs called etc.

Here's how I have coded the Program-Header for my COBOL-Program PROG05.

Image291

IDENTIFICATION DIVISION : The PROGRAM-ID should be 7 OR 8 chars and must be the same as Member-name. Most projects or Production Environments specify a naming-convention for the PROGRAM-ID. At my work-place  it goes like this -

PROGRAM-ID. XXXYZAnn.

The first 3 characters XXX should be the name of the Sub-system. Say for example,  our Mainframe sub-system is GEMINI, so we use the three letter prefix GEM for all our programs. It is followed by B, if it’s a Batch Program, C if its an Online Program. Our programs are mostly Batch, so we'd put a B. We also use a single letter code - I for Inserts, U for Updates, D for Deletes, S for Selects. Say, that my Program does Inserts, so I use the code I. We also code D for DB2, or I for IMS. My Program uses DB2 for storing Data. Hence, my program-id would be GEMBIDnn. So, in my project, all our Programs are like GEMBID01, GEMBID27, GEMBID58, GEMBID59, GEMBID60, GEMBID2A so on and so forth.

ENVIRONMENT DIVISION : For readability, you should write each SELECT Statement on a new line, and the ASSIGN TO Clause, ORGANIZATION IS, ACCESS MODE IS, FILE STATUS IS, and the RECORD KEY IS Clauses should be indented thereafter on successive lines.

image

DATA DIVISION : It's a good practice to organize the Working-Storage Variables in the COBOL-Program, so its very easy to FIND Variables. For example, all the Storage Areas used for Input-Output go together. All the Print-Formats such as Header-Lines, Separator Lines should be grouped. Then follows the DB2-I/O Areas which contain 'EXEC SQL – END-EXEC' Blocks. These are Storage Areas in COBOL that will receive the data fetched from DB2 Tables, or send data-output to be stored in DB2 Tables. Likewise, Flags-and-Switches which help detect special conditions, Literals and Constants(Values that don’t change) and Counters which help keep track how many times you do a thing;are stored together under the Working Storage Section.

image

Level-Numbers and Picture Clause – Get into the habit of inserting Blank
Empty-Lines, lavishly. Don't hesitate to use them.

Level-Numbers indicate Break-up or Structure. User Non-contiguous Level-Numbers like 01, 05, 10, 15 and so on. Indent each higher Level-Number 3 columns to the right. See how I have indented 01, 05 and 88-Levels.

image

Code the Picture Clause preferably on Position 45. For Numeric-Edited variables like WS-CONTRACT-FACE-AMT, write the entire PIC Clause 
–ZZZ,ZZZ,ZZZ,ZZZ,ZZZ.99 instead of writing –Z(3),Z(3),Z(3),Z(3),Z(3).9(2).

image
Q. I want a comprehensive list of all the possible COBOL Errors, that the COBOL Compiler complains about? 
To generate a complete Listing of all possible errors in COBOL, along with the Errors-Codes and their Description, I'd call for ERRMSG. Write a COBOL Program, with the PROGRAM-ID ERRMSG. and that does the trick. I've coded the ERRMSG COBOL Program.

Image288

This magic trick works, COBOL-Compiler Software recognizes the special-program ERRMSG, and it produces an entire list of Error-codes and Descriptions in the Compiler-Listing. Here's an extract of what you'll get as output in the Compile-Listing. It’s a huge List. Get the Complete Error-Listing here.

Image289

Tuesday, August 4, 2009

JOB Log – How to understand and interprete JES 2 Job Log


Q. What is JOB Log? Why do we need a JOB Log? What purpose does it serve?
When you submit a Batch JOB/JCL to the MVS System, the MVS executes the Job Stream, makes the necessary resources available to the the EXEC PGM (Program), and finally tells you the result of the Job. The Result of the Batch JOB is different from the output of the Program. The result of the Batch JOB indicates – success/failure(ABEND) of the JOB.

The result of the Batch JOB is stored in SYSOUT Dataset. This file is called the Job Log. The JOB Log is stored in the queue or Spool. There would be many Job Logs for Jobs submitted by you as well as other users lying in the Queue/Spool. In the olden days, these JOB Logs waited in the printer queue to be printed. Since, there was only one Printer, not all JOB Logs could be printed at the same time. Every JOB Log/Output awaited its turn in the Queue/Spool. However, now-a-days, you can directly view the JOB Log from the Printer Queue.

Typically, most sites have SDSF(Spooler Display and Search Facility) installed, which is just a program running on top of TSO, which helps you to easily see the JOB Logs and search for JOB Logs by Job name etc. To invoke SDSF, you must type S at the command line on ISPF. The command ST shows the Jobs which have finished or Terminated.




When you submit JCL/Job Stream to the MVS O/S, you get JOB Log like the above in the Queue/Spool. MVS dumps several lines of Print Output (informational and diagnostic messages) to tell you, what it did of the Job. Here, I am going to dissect the JOB Log.

a. The first few informational messages tell you, when the JOB started on the CPU, and when it got completed. It also tells you, who started the Job, and that JES2 has converted the JCL into an internal format.
b. JOB STATISTICS tell you, how many input JCL statements were there. These are called Input Cards. Every line is treated like a Card. So, even the Instream DD * Statements are Control Cards. In the above example, JES2 read 21 Cards.
c. The JCL Listing that you’ve submitted is printed here. All the JCL Statements have been numbered.
d. COND CODE – The statement
CAA0176I – STEP01 – STEP WAS EXECUTED – COND CODE 0000
indicates, that the Job-Step STEP01 for the JOB-Name CAA0176I, was executed successfully with a condition code 0000. Condition Codes indicate the success or failure of a Batch JOB. Condition Code of 0 implies that the Job was successful. A non-zero condition code may imply warnings or severe errors. Each Program will return a condition code ranging from 0000 to 4095.
Moreover, this section also tells you about the status of all Datasets referred in the DD Cards.
e. The final informational messages in the form IEFXXXX indicate the total time the JOB took. You can find description of these informational messages in the IBM Manuals.

Monday, August 3, 2009

DFSORT – OUTREC FIELDS Control Statement, Performing Arithmetic on Numeric Fields, OUTREC OVERLAY and OUTREC IFTHEN Control Cards


Q. In the previous tutorial, you’ve told me how to obtain the Sum(Aggregation) of records using SUM FIELDS. Some of the fields in the Output Report are not meaningful. How do I display only the relevant fields, and remove the unnecessary ones?
Consider the following Input Dataset -

----+----1----+----2----+----3----+----4----+----5----+----6----+
AG10001  RAMESH CHANDRA GUHA INDIA     MAHARASHT MUMBAI    01000
AG10002  QUASAR SHABBIR CHUN INDIA     MAHARASHT PUNE      02000
AG10003  VEERAMANI DARYAGANJ INDIA     MAHARASHT NAGPUR    03000
AG10004  DELPHAN FERANDAZ    INDIA     TAMIL NAD CHENNAI   04000
AG10005  PADMAVATHI SUNDARAM INDIA     TAMIL NAD SALEM     05000
AG10006  NEELESHWARI IYER    INDIA     TAMIL NAD ERNAKULAM 06000
AG10007  AJAY NANUBHAI PARSA INDIA     WEST BENG KOLKATA   07000
AG10008  MEHUL POPATLAL SUTA INDIA     WEST BENG KHARAGPUR 08000
AG10009  KRITHIKA RAMANUJAM  INDIA     WEST BENG SUNDARBAN 09000
AG10010  ANKUR CHOUDHARY     INDIA     PUNJAB    AMRITSAR  10000
AG10011  HIREN NITIN SHETH   INDIA     PUNJAB    JALANDHAR 11000
AG10012  DARSHAN SHAH        INDIA     HARYANA   CHANDIGAR 12000


For finding the Total Sales Figure of all Insurance Agents(01000+02000+...+12000), we must use the SUM FIELDS Control Statement of DFSORT Tool. If we apply the SUM FIELDS control statement, on DFSORT as :

SUM FIELDS=(60,5,ZD)                                                 

We get the following Output Dataset :

----+----1----+----2----+----3----+----4----+----5----+----6----+
AG10001  RAMESH CHANDRA GUHA INDIA     MAHARASHT MUMBAI    78000


This tells us that the Total Sales of all Insurance Agents in COUNTRY=INDIA is 78,000. All other fields are irrelevant/not-meaningful. Now, let’s say I wanted to display only the COUNTRY and TOTAL SALES Field in the Output Report.

So, I’ve written the following JCL/JOB Stream -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//CAA0176A JOB A123,QUASAR,CLASS=G,MSGCLASS=Y,NOTIFY=&SYSUID           
//STEP01 EXEC  PGM=SORT,REGION=1024K                                   
//SORTIN DD    DSN=CAA0176.DEMO.SORTIN,DISP=SHR                        
//SYSPRINT DD  SYSOUT=*                                                
//SYSOUT DD    SYSOUT=*                                                
//SORTXSUM DD  DSN=CAA0176.DEMO.REPORT,DISP=SHR                        
//SORTOUT DD   DSN=CAA0176.DEMO.SORTOUT,DISP=SHR                       
//SYSIN  DD    *                                                       
  SORT FIELDS=(30,10,CH,A)                                             
  SUM FIELDS=(60,5,ZD)                                                 
  OUTREC FIELDS=(30,5,2X,60,5)                                         
//                   
                                                 


The OUTREC FIELDS Control Statement is used to display only select fields in the Output Report, and eliminate the unnecessary/irrelevant ones.
In the Input Dataset,
COUNTRY Field = Starts at Position 30 and has length 5.
SALES   Field = Starts at Position 60 and has length 5.
We would like only these 2 fields to be displayed in the Final Output File. Hence, we must code the OUTREC FIELDS Control Statement as
OUTREC FIELDS=(column1,column2,...)

OUTREC FIELDS=(30,5,2X,60,5)

Here, 2X inserts 2 whitespaces(blanks) between COUNTRY and SALES Field. The Output File Dataset is as follows :

----+----1----+
INDIA  78000  

Q. Hey, I wanted the records in the above Output report to be displayed in Hexadecimal format – the EBCDIC values in Hex, just like how its really stored in a Computer? How do I do it in JCL?

Well, you just need to use the HEX Switch in the OUTREC FIELDS Control Statement. So, in the OUTREC FIELDS Control Statement for the above output report, add the HEX Switch to all fields, you want to be displayed in HEX -

OUTREC FIELDS=(30,5,HEX,2X,60,5,HEX)

The above OUTREC FIELDS Control Statement, when submitted as a part of the Job Stream, gives the following Output Report:

----+----1----+----2----+
C9D5C4C9C1  F7F8F0F0F0  

Q. Hey I have had enough of Sum/Aggregation! Gimme a break.. Show me something else. Like how do I perform some Arithmetic Operations on the numeric field of the Input Records?

Let me just flash before you the Input Dataset, that I’ve chosen for this example. This is the data as of the year 2008.

----+----1----+----2----+----3----+----4----+----5----+----6----+
AG10001  RAMESH CHANDRA GUHA INDIA     MAHARASHT MUMBAI    01000
AG10002  QUASAR SHABBIR CHUN INDIA     MAHARASHT PUNE      02000
AG10003  VEERAMANI DARYAGANJ INDIA     MAHARASHT NAGPUR    03000
AG10004  DELPHAN FERANDAZ    INDIA     TAMIL NAD CHENNAI   04000
AG10005  PADMAVATHI SUNDARAM INDIA     TAMIL NAD SALEM     05000
AG10006  NEELESHWARI IYER    INDIA     TAMIL NAD ERNAKULAM 06000
AG10007  AJAY NANUBHAI PARSA INDIA     WEST BENG KOLKATA   07000
AG10008  MEHUL POPATLAL SUTA INDIA     WEST BENG KHARAGPUR 08000
AG10009  KRITHIKA RAMANUJAM  INDIA     WEST BENG SUNDARBAN 09000
AG10010  ANKUR CHOUDHARY     INDIA     PUNJAB    AMRITSAR  10000
AG10011  HIREN NITIN SHETH   INDIA     PUNJAB    JALANDHAR 11000
AG10012  DARSHAN SHAH        INDIA     HARYANA   CHANDIGAR 12000


In the year 2009, due to a performance bonus given to Insurance Agents, they all put in more efforts and in the next quarter it was observed, that their Sales grew by 10 percent. Write a Batch JOB/JCL that increases the Sales of Insurance Agents by 10 percent. So, you need to generate a report for Sales for the financial Year ending 2009, showing a 10% rise in the SALES Figure for all the agents.

To perform arithmetic(like increasing/addition) on numeric fields, we can use several operators like ADD,SUB,MUL,DIV,MOD inside the OUTREC FIELDS Control Statement. To treat a field as numeric, and to be able to perform numerical operations on it, we code ZD(Zoned Decimal) specifier.

To raise the Sales figure by 10 percent, we need to multiply the Sales x 1.1. But, since decimal(float) values are not allowed, we will multiply SALES x 11, and then describe the format of the resultant Edited field. The format of the Edited field can be specified using EDIT Subparameter.

If we have input sales = 1000, we multiply by 11, 1000 x 11 = 11000.
To display correct result, decimal point needs to be shifted one place left.
So, format is TTTT.T(where T stands for any significant digit to be displayed). We can add a comma like T,TTT.T. Some sales figures are above 10,000(5 digits). So, we need to ensure that they are also displayed correctly. Thus, we need to add an I(Insignificant digit).

We specify the format for the output field using EDIT Parameter. We will code the EDIT Parameter for the above example as,

EDIT=(IT,TTT.T)

This is how the Batch JOB/JCL for raising the Sales by 10 percent looks :

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//CAA0176K JOB A123,QUASAR,CLASS=G,MSGCLASS=Y,NOTIFY=&SYSUID           
//STEP01 EXEC  PGM=SORT,REGION=1024K                                   
//SORTIN DD    DSN=CAA0176.DEMO.SORTIN,DISP=SHR                        
//SYSPRINT DD  SYSOUT=*                                                
//SYSOUT DD    SYSOUT=*                                                
//SORTXSUM DD  DSN=CAA0176.DEMO.REPORT,DISP=SHR                        
//SORTOUT DD   DSN=CAA0176.DEMO.SORTOUT,DISP=SHR                       
//SYSIN  DD    *                                                       
  SORT FIELDS=(30,5,CH,A) -                                            
  OUTREC FIELDS=(30,5,2X,(60,5,ZD,MUL,+11),EDIT=(IT,TTT.T),80:X)        
//                                                                     


Upon submitting the above Job Stream, the final Output Report for the Sales 2009, which shows a 10% increase in Sales of Each Insurance Agent, looks something like this -

----+----1----+
INDIA   1,100.0
INDIA   2,200.0
INDIA   3,300.0
INDIA   4,400.0
INDIA   5,500.0
INDIA   6,600.0
INDIA   7,700.0
INDIA   8,800.0
INDIA   9,900.0
INDIA  11,000.0
INDIA  12,100.0
INDIA  13,200.0

Q. How do you reformat records with OUTREC OVERLAY Control Statement?

When we use OUTREC FIELDS to re-format the output records, you need to specify all the fields/items, that you desire to appear in the Output Record. You must tell the DFSORT tool through the OUTREC FIELDS Control Statement, every item that you would like the record. Thus, you have to build the re-formatted record, one item at a time - field by field. In between, you can add some special characters like comma(,) or currency symbol($). This can be very tedious and cumbersome, if the record has a large length and contains many fields/columns.

If you intend to change/modify only a handful of columns, an easier and more convenient option is to use the OVERLAY Control Statement. Note that OVERLAY statement can be used to do the same tasks that you can accomplish with OUTREC Statement.

Let me show you a simple example which illustrates how to raise the Sales figure of the Insurance Agents like in the above example, but using the OUTREC OVERLAY Statement. This example proves, how easy it is to use the OVERLAY statement as opposed to the meticulous and cumbersome OUTREC FIELDS Control Statement.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//CAA0176A JOB A123,QUASAR,CLASS=G,MSGCLASS=Y,PRTY=15,NOTIFY=&SYSUID 
//STEP01 EXEC  PGM=SORT,REGION=1024K                                 
//SORTIN DD    DSN=CAA0176.DEMO.SORTIN,DISP=SHR                      
//SYSPRINT DD  SYSOUT=*                                              
//SYSOUT DD    SYSOUT=*                                              
//SORTXSUM DD  DSN=CAA0176.DEMO.REPORT,DISP=SHR                      
//SORTOUT DD   DSN=CAA0176.DEMO.SORTOUT,DISP=SHR                     
//SYSIN  DD    *                                                     
  OPTION COPY -                                                      
  OUTREC OVERLAY=(60:60,5,ZD,ADD,(60,5,ZD,DIV,+10),TO=ZD,LENGTH=5)   

Q. How the OUTREC IFTHEN Control Statement work? Can you elaborate by showing a simple JCL/Job stream?

OUTREC FIELDS and OUTREC Overlay allows you to apply the same reformatting to all the Output Records. However, if you would like to apply different re-formatting to different output records, then one should use the IFTHEN option. By using the IFTHEN option, one can apply different OUTREC FIELDS or OUTREC OVERLAY(formats) statements to different output records.

Suppose, we would like the Output Report to be generated as follows -
1) If SALES of Agent < 06000, then Increase = 10%
2) If SALES of Agent >= 06000, then Increase = 20%

So, for all records having sales < 06000, we multiply(MUL) by 1.1.
For all records having sales >= 06000, we multiply(MUL) by 1.2.
Thus, we can multiply records by +11 and +12 respectively, in JCL, and display the output field using the EDIT Format, EDIT=(IT,TTT.T)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- 
//*--------------------------------------------------------------------
//*OUTREC IFTHEN Control Statement – Reformatting Records differently    
//*--------------------------------------------------------------------
//CAA0176Q JOB A123,QUASAR,CLASS=G,MSGCLASS=Y,PRTY=15,NOTIFY=&SYSUID   
//STEP01 EXEC  PGM=SORT,REGION=1024K                                   
//SORTIN DD    DSN=CAA0176.DEMO.SORTIN,DISP=SHR <==INPUT FILE          
//SYSPRINT DD  SYSOUT=*                                                
//SYSOUT DD    SYSOUT=*                                                
//SORTOF01 DD  DSN=CAA0176.DEMO.REPORT,DISP=(OLD,KEEP,KEEP) <==REPORT  
//SORTOUT DD   DSN=CAA0176.DEMO.SORTOUT,DISP=(OLD,KEEP,KEEP) <==OUTPUT 
//SYSIN  DD    *       <== INSTREAM CONTROL STATEMENTS                 
  OPTION COPY                                                          
  OUTREC IFTHEN=(WHEN=(60,5,ZD,LT,06000), -                            
  BUILD=(1:1,9,10:10,20,X,(60,5,ZD,MUL,+11),EDIT=(IT,TTT.T))),         
  IFTHEN=(WHEN=(60,5,ZD,GE,06000), -                                   
  BUILD=(1:1,9,10:10,20,X,(60,5,ZD,MUL,+12),EDIT=(IT,TTT.T)))


The Output Report for the above Batch Job/JCL looks as follows : AG10004

----+----1----+--
AG10001  1,100.0
AG10002  2,200.0
AG10003  3,300.0
AG10004  4,400.0
AG10005  5,500.0
AG10006  7,200.0
AG10007  8,400.0
AG10008  9,600.0
AG10009 10,800.0
AG10010 12,000.0
AG10011 13,200.0
AG10012 14,400.0

Sunday, August 2, 2009

DFSORT– SUM FIELDS


Q. What is Aggregation?
To aggregate, is to sum things up. When you add up values together, to find a total sum, its an Aggregation. For example, if a salesman is able to sell products worth Rs. 1000 in January, Rs. 4000 in February and Rs. 5000 in March, his total sales = 1000 + 4000 + 5000 = Rs.10,000. This operation is called aggregation.

A Fast Moving Consumer goods company(FMCG) like Unilever manufactures the beauty-soap Lux. Say, a manager at his disposal, possesses the sales data for the year 2011-2012, for the soap Lux, all over the Indian Sub-continent. The data runs into lakhs of records. It is of little help. You begin to aggregate the raw disjointed data, over the territory or city of sale and analyse the results. The Lux Soap Sales, city-wise distribution gives a better picture to the manager about the geography, where the brand is performing better, and the territories, where they need to focus and requires more promotion. If you aggregate the sales data over different age groups, you may figure out conclusively, as to which age group prefers Lux Soap over other Soap bars, is it the 20s something, or the 30s, or the middle-aged.

The essence of the above example is that, summary reports having aggregate data provides useful insight to the higher management in an organisation. Its a knowledge-discovery process. We are knee-deep in data, there's tonnes of data around us, but we need to mine, extract knowledge from it.


As you read further, you shall learn how easy it is to run SORT, the free software program supplied by IBM, to aggregate data.
Q. How to add up numbers using the free software program DFSORT?
Have you ever tried adding up numbers in your favourite spread-sheet application, Microsoft Excel? Just pick the column with the numbers you wish to add, select or highlight it, and click on the Auto-sum button(the one with the Greek alphabet Sigma on it). The numbers in the Excel column are added up together, and the sum-total is displayed.
 
image
IBM's free software program SORT offers the SUM operation, to add numbers up. The SUM operation takes a parameter FIELDS. FIELDS parameter specifies the column of numeric values, you wish to add. 

image

To refer to any column, you must know the position and the length. Take a look at the above picture. The name of the Sales Representative starts at position 01, and has a length 25 characters. Thus, the Sales-Representative column is (01,25). The territory column is (26,12). The country column will be referred to as (38,06). The sales figure in Rs. column would be (44,05).

I would like to sum up the sales(in Rs.) in the country India. I wrote the SORT Control card like this -

image

The SORT software program performs a SUM operation on the (44,05) column. It adds up the data in the Sales(in Rs.) column. The SORT Software program also needs to be told the data-format. Since we are adding a bunch of numbers, the appropriate data-type is numeric, ZD. 

Often managers need data with different levels of summarization, to make intelligent decisions. For example, the global sales manager, would study the sales by country, and understand how their products are faring in India vis-a-vis other Asian countries. Lower in the organisational hierarchy, the India sales manager would take a look at the territory-wise sales. While summarizing and adding things up, you may form groups or sets. For example, if I consider each country as a single large group, and add things up, I'd get the total-sales in India, the total-sales in China, the total-sales in Bangladesh and so on.. This would be a country-wise sales report. You may group data by territory to produce a sales(in Rs.) territory-wise distribution report.

Adjusting the level-of-detail, forming groups or subsets of data is done by coding the SORT operation. I am interested to know the total sales(in Rs.) in the country India. The SORT software program should treat each country, as a separate group, while adding up the sales. Hence, I have referred to the Country (38,06), as a criterion to group data. Country is said to be the controlling field.

When you run the SORT Software Program, with above Control-Card, the Output Dataset shall look like this. The total sales in India is Rs.15,000.

image

On the same lines, the break-up of sales by territory, could be done by treating each region or state as a single group. You must code the SORT operation, and group by the territory (26,12). I wrote the SORT Control card like this -

image
 
When you run the SORT Software Program, with above Control-Card, the Output Dataset shall look like this. The total sales in Gujarat state is Rs.7000, in Maharashtra Rs. 1000, in Tamil Nadu Rs.5000, and in the state of Uttarakhand Rs.2000.

image
Q. Is it possible to add numbers, on two or more control fields?
Patients do not have knowledge of medicine. Hence, they approach a doctor/general-pracitioner, who prescribes them drugs. Glaxo Smithkline(GSK), a leading pharmaceutical company employs many field representatives to promote and pass on knowledge about their drugs(prescription drugs and not OTC drugs), to doctors. Shri. Quasar S Chunawala works for GSK, as a sales rep in the Eastern states, Shri. Prasanna Limaye handles the western states, Smt. Neha Laxman Rawat is covering Northern states of Uttaranchal, Himachal Pradesh and Punjab, whereas Shri. Sai Kiran Valisetty is a field rep in South India.

The below table is the sales data for Glaxo Smithkline Pharma company in India, for the year 2011-12.

image
At the end of the year, it is time to evaluate the performance of the sales representatives. I would like to look at the sales totals of each sales rep, territory-wise, and further state-wise.

In this sales analysis, the software program DFSORT allows you to divide this cosmos(universe) of data into galaxies(clusters) and further drill them down into smaller sub-groups(Solar-systems), to calculate totals and sub-totals. For example, you may form groups of Sales data by territory, say Eastern region sales(blue colored), Western region sales(red colored), sales up in the North(green colored) and sales down south(sky-blue colored).

You may further dissect it by state. So, the total sales in the Northern territory, constitutes the sales in Uttaranchal, Himachal Pradesh and Punjab.

image 

I would like to sum up the Sales Target(in Units) referred to as (46,03) column, the Sales Actual(in Units) referred to as (50,03) column. To do so, I must code the SUM operation. I began writing my SORT control card like this -

image

I would like to control the Sales-analysis by territory (01,06), and look at the sales totals by territory. I coded the SORT operation, to group the data by territory.

When you run the SORT software program using the above control-Card, the output-dataset looks like this. Shri. Quasar Chunawala has sold 806 units, against a quota of 965 units in Eastern region. Smt. Neha Laxman Rawat has sold 890 units in the North, Shri. Sai Kiran Valisetty has sold 760 units in the South and Shri. Prasanna Limaye was able to sell 840 units in the Western territory.

image

To calculate the sales sub-totals for each state (08,18), the state must be the second controlling field. This will form state-wise sub-groups within each territory group. I modified the SORT control-card as follows.

image

When you run the SORT software program using the above control-Card, the output-dataset looks like this.

image

Saturday, August 1, 2009

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.