What’s new at MAINFRAMES 360
(Updates May '11)...
- We are a cosmopolitan community of 400 members, from around the globe.
- Working on writing and publishing articles on CICS.
- Special article on "How do I learn Mainframe Programming"

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

Introduction to COBOL Programming


Q. What does COBOL stand for?
COBOL stands for Common Business Oriented Language. COBOL Programs are used to process. Business-Data. COBOL Programs are easy to code and analyse, because it is an English-like language. Writing a COBOL program is just like writing a passage in English.
Q. Are COBOL Programs English-like?
Just as text in English is organised into sections and para’s, COBOL Programs can also be broken down into divisions, divisions further into sections, and sections into paragraphs. Each paragraph contain sentences, or COBOL Statements. Like the English language, sentences(statements) in COBOL should end with a period(full-stop).

When you start new paragraphs in COBOL, you need to indent them, just as in English you follow indentation rules. COBOL then is whole-lot English like. Even instructions in COBOL, are words borrowed from English, ADD, SUBTRACT, MULTIPLY, DIVIDE etc.
Q. What’s the basic skeleton of a COBOL Program
The basic skeleton of a COBOL Program is as follows :
 
     Image198[1]

A COBOL Program can be divided or broken down into 4 parts – IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION. The PROCEDURE DIVISION contains the instructions to be executed(performed), one after the other, step-by-step till you reach the end of the Program and stop running it(STOP RUN).

Under a division, you may have several sections as well, and sections in turn can have several paragraphs. Divisions, sections and paragraphs help make the COBOL Program more structured, and the flow of the COBOL Program is easy to grasp.
Q. What are the Alignment(Indentation rules) in COBOL?
The lines in a COBOL Program are indented or aligned, as its done in English. When you write COBOL Program on the Mainframe terminal, you have 80 columns on a line to code on. The area spanning from columns 8-11 is called Area A. The area spanning from columns 12-72 is called Area B.

In COBOL, division names, sections and paragraphs begin in Area A. See below, how I’ve coded IDENTIFICATION DIVISION, ENVIRONMENT DIVISION,.. etc. starting on Column 8 -

Image199[1]

You code COBOL Instructions, COBOL Statements in Area B(that’s anywhere between Column 12 – 72). So, all your COBOL Instructions in the PROCEDURE DIVISION like ADD, SUBTRACT, MOVE should begin on or after Column 12. Look below, how I’ve coded COBOL Instructions in Area B.

Image200[1] 

An interesting bit of trivia, back in the early days, COBOL Programs were coded on a COBOL Coding-Sheet, before punching the Instructions onto a Punched-Card. Here's a picture of, how a Coding-Sheet. looked like.

image
Q. What is the IDENTIFICATION DIVISION used for?
The IDENTIFICATION DIVISION is used to identify the COBOL Program to the system. Under the IDENTIFICATION DIVISION, you can code several para-entries like PROGRAM-ID, AUTHOR etc. which supply extra-descriptive information about the COBOL Program.

The PROGRAM-ID para assigns a unique-name to the COBOL-Program. You simply write the name of your COBOL Program after the PROGRAM-ID Para. Here’s how you code it -

Image262

The AUTHOR Paragraph tells, who’s written this COBOL Program. If you’ve coded the COBOL Program, you can put your name as the AUTHOR of the program.

Image263

The INSTALLATION would be the name of the company, where the COBOL Software Program was designed and written. For example, if I work for TCS, I would code :

Image264

The DATE-WRITTEN is the date when the COBOL Source-Program was coded. When you choose not to write a date, the COBOL Compiler software would insert a date for free.

Image265

The DATE-COMPILED is the date when the COBOL-Program was compiled. Again, if you don’t supply a Compile date, the Compiler software inserts one for you.

Image266

Under the IDENTIFICATION DIVISION, you must compulsorily code the PROGRAM-ID Para, you can skip off coding the AUTHOR, INSTALLATION, DATE-WRITTEN and DATE-COMPILE Entries. PROGRAM-ID Para is must.

Q. How do you document a COBOL Program?

A well-documented COBOL Program is easy to analyse. You can quickly understand the functionality of the COBOL Program, if it contains comments. In COBOL, you code comments by putting an asterisk * in Column 7.

Image267

You must always supply document what the program-name is, which system, a brief description of the processing it does.

Q. What is PROCEDURE DIVISION?

The PROCEDURE DIVISION is the starting-point of the COBOL-Program. This is where the Mainframe begins to run(execute the COBOL instructions). Hence, all your instructions/programming logic must be written inside this PROCEDURE DIVISION.

Under the PROCEDURE DIVISION, you can write Instructions one-after-the other. The Mainframe executes, runs the instruction in the PROCEDURE DIVISION, one-by-one, step-by-step sequentially, till you say, STOP RUNning the Program. To stop running the COBOL Program, the last-instruction you code must be STOP RUN.

PROCEDURE DIVISION.
   Instruction-1
   Instruction-2
   Instruction-3
   Instruction-4
   ...
   Instruction-N
   STOP RUN.

Q. How do you display text on the Screen in COBOL?
To Display data on the Screen, in COBOL you code the DISPLAY Instruction. You code DISPLAY followed by the text that want to print on the Screen, enclosed in Single Quotes. Say for example, if I want to display Hello World on the Screen, I would write -

Image268
Q. How do I setup  Compile-Link Job?
To run and process data using a Program, you need to first Compile-Link a COBOL Program. The Free COBOL-Compiler Software on Mainframes is IGYCRCTL. The Compiler-Software works like a Translator, translates the Program from
COBOL to Binary Language.
                Image269

Like any other Program on Mainframes, the free Compiler IGYCRCTL also expects you to supply some Input-Output Files
                     Image270
To run the Compiler-Software IGYCRCTL, I set-up a job like this – I’ve set //SYSIN DD Input-File to point to my COBOL Source Program which resides at SYSADM.DEMO.SRCLIB(PROG04). //SYSLIN DD Output-File, where the compiler stores Binary Object code points to a Temporary-File LOADSET. The //SYSPRINT DD File is set to point to the Spool SYSOUT=*. This contains the Compile-Listing. I look at the Compile-Listing, and know if my program successfully compiled, or the compiler complained about my Program(its faulty, has syntax errors). //SYSUT1 to //SYSUT7 are temporary-work-Files.

Image271

The Output Binary-Object-Code generated by the Compiler-Software IGYCRCTL, cannot  run on its own, standalone. To get it running, it needs other Helper Programs. The Linker-Software packs and bundles together my Binary-Program along-with any other Helper-Programs, it may need into one composite Load-Module. My Program is all set to go! The Free COBOL-Linker Software on Mainframes is HEWL. It expects the following files - 
                     Image272

To run the Linker Software HEWL, I added a LKED Step to my job. I have set the //SYSLIN DD Input-File to point to Binary Object-Code stored at the
Temporary-Dataset LOADSET created in the COMPILE Step. Bundled-up Output Load Module of the Linker HEWL is stored in //SYSLMOD File. I have made the //SYSLMOD DD File point to the dataset SYSADM.DEMO.LOADLIB(PROG04). The Load-Module PROG04 would be stored in my personal Load-Library SYSADM.DEMO.LOADLIB.

Image273
Q. I’ve hit SUB on the Compile-Link Job. What next?
Hit SUBmit on the Compile-Link job after you’ve set it up.

Image274 
Start SDSF to see the Output of the Compile-Link Job in the Spool, and check Compile SYSPRINT-Listing for any errors.

Image275

Here’s how, the Compile-Listing looks. It shows that I running Enterprise COBOL Version. The SSRANGE, XREF, LIST, MAP, OFFSET Compiler options have been turned ON.

Image277

The Compiler Software IGYCRCTL leaves behind  signature, a Two-Digit Return-Code as a signal, to indicate if the COBOL-Program compiled successfully, or it contained errors. Check the Return-Code set by the Compiler, by scrolling to the bottom of the Compile-Listing. The Return-Code set by the Compiler is RC=04. A Zero RC suggests, the COBOL Program is correct, an RC=04 denotes Warnings(W). This is acceptable. When the Compiler sets the RC=08, the COBOL Program contains Errors(E), and an RC=12 says the COBOL Program has
Severe-Errors(S). When the Compiler complains with Errors(E) and
Severe Messages(S), you need to go back and correct your COBOL Program.

Image276
Q. How do I run my Program?
To run your program , you need to write a Job. I’d run my Program, by setting up a job like this -

Image278

I need to run the Program PROG04, so I write EXEC PGM=PROG04. The Mainframe Computer should pickup this Load Module from my Personal Load Library SYSADM.DEMO.LOADLIB, so I added a //JOBLIB DD Statement pointing to my
Load-Library. When I SUBmit this Job, the Output Listing in the Spool, shows up as -

Image279
Related Posts Plugin for WordPress, Blogger...

Note :

Protected by Copyscape Online Copyright Protection
© Copyright – Quasar Chunawalla, 2010.
Note : The copyrights of all the material, text and pictures posted in this website belong to the author. Any instance of lifting the material from this website, shall be considered as an act of plagiarism. For any clarifications, please drop me a line at
 
back to top