Popular

COBOL REDEFINES Clause IN COBOL Explanation With Example in COBOL

REDEFINES Clause IN COBOL


Sometime two or more different variables defined in a program are not in use simultaneously. Their memory can be then saved by sharing the same location for all such variables which will not be used simultaneously. For this we can use redefine verb in cobol. The redefine verb.
Using redefine the same memory location can be used for different variables, but the care of usage of the memory hence, variables should be taken as the content of any on of the redefined variable are reflected in the all of its redefined variables.

Example- mailing list where the addressee may be either a person or a company, but never both. To include both an individual name field and a company name field would waste space, since only one of them would ever be filled, so the name field can be reused (redefined) as company name. Furthermore, while a company name requires just one field, the individual name is usually composed of two fields, last name and first name. For example, bytes 1-12 might be last name, and bytes 13-20 the first name. But when redefined, bytes 1-20 would be the company name. Now you have two fields redefined by one field. COBOL can handle this just fine, but most PC applications don't use redefined fields and do not deal with this well

01 SUBSCRIBERS.
    05 TYPE-OF-NAME PIC X.
    05 INDIVIDUAL-NAME.
       10 LAST-NAME PIC X(12).
       10 FIRST-NAME PIC X(8).
    05 COMPANY-NAME REDEFINES INDIVIDUAL-NAME PIC X(20).
    05 ADDRESS PIC X(20)
    05 CITY PIC X(15)
    05 STATE PIC X(2)
    05 ZIP PIC X(5)


Here, TYPE-OF-NAME indicates the type of name saved in the 20 bytes of name field, whether it is person name or company name. It takes 1 byte to be stored but saves another 20 bytes, also in many cases it will not be needed.

COBOL COMP SYNC - What is COMP SYNC in COBOL?

SYNC Keyword is used in COBOL to align the data(storage-area) to a Word-Boundary(Any address which is a multiple of 4). This is because, on Mainframes reading data from a word-boundary is computationally efficient.



COBOL INDEX, COBOL Sub-script - What is the difference between Index and Sub-script?

Subscript is the slot-no. or position in the table. Index is the displacement (in no of bytes)/actual address from the beginning of the array. Indexes are much faster than subscripts. Subscripts have to be converted internally to the address.
For example,
01 WS-TABLE.
  
05 WS-NAME OCCURS 5 TIMES PIC X(10).
----------------------- Subscript Index -----------------------
  
0        0    1        10
  
2        20
  
3        30
  
..       ..
-----------------------

Since index is much more efficient, you should declare a table and Index it.
01 WS-TABLE.
   05 WS-NAME OCCURS 5 TIMES PIC X(3) INDEXED BY I.

You use indexes just like subscripts, except for the fact that they are much faster and efficient.
PERFORM 1000-DISPLAY-DATA VARYING I FROM 1 BY 1 UNTIL I > 5
1000-DISPLAY-DATA.
   DISPLAY WS-NAME(I).

To increment or decrement an Index, SET Verb is used. SET I UP BY WS-LIT-ONE.
SET I TO 1.

You cannot MOVE data to Indexes. You also cannot perform Arithmetic Operations on an Index.

IS NUMERIC clause IN COBOL IS NUMERIC CLAUSE

IS NUMERIC is used to check if the data is numeric or not.


IS NUMERIC clause IN COBOL EXAMPLE


01 WS-TEXT PIC X(05).
MOVE '15623' TO WS-TEXT.
IF WS-TEXT IS
NUMERIC DISPLAY 'NUMBER'
ELSE
DISPLAY 'TEXTUAL CHARACTERS’
END-IF.

Output:
NUMBER
MOVE 'HE123' TO WS-TEXT

IF WS-TEXT IS NUMERIC DISPLAY 'NUMBER'
ELSE
DISPLAY 'TEXTUAL CHARACTERS’
END-IF.



Output:
TEXTUAL CHARACTERS

COBOL PICTURE Clauses COBOL Picture Clause Usage Descriptions

Some examples
- PICTURE 999 a three digit (+iveonly) integer
- PICTURE S999 a three digit (+ive/-ive) integer
- PICTURE XXXX a four character text item or string
- PICTURE 99V99 a +ive‘real’in the range 0 to 99.99
- PICTURE S9V9 a +ive/-ive‘real’in the range ?
- If you wish you can use the abbreviation PIC.
- Numeric values can have a maximum of 18 (eighteen) digits (i.e. 9’s).
- The limit on string values is usually system-dependent.


Abbreviating recurring symbols

Recurring symbols can be specified using a ‘repeat’factor inside round brackets
  • PIC 9(6) is equivalent to PICTURE 999999
  • PIC 9(6)V99 is equivalent to PIC 999999V99
  • PICTURE X(10) is equivalent to PIC XXXXXXXXXX
  • PIC S9(4)V9(4) is equivalent to PIC S9999V9999
  • PIC 9(18) is equivalent to PIC 999999999999999999

How do you define a table or array in COBOL?

01 CONTACT-RELIST.
05 CONTACT-RECORDs OCCURS 5 TIMES.
10 NAME PIC X(10).
10 PHONE PIC 9(08).



LEVEL 66 In COBOL : What is level 66 used for ?

Level-66 Data-item is used for RENAMES Clause. RENAMES clause is used to regroup(Re-arrange), club together existing fields under a new name.

01 RECORDS.
05 GROUP-A.
10 FIELD-1 PIC 9(02).
10 FIELD-2 PIC 9(02).
05 GROUP-B.
10 FIELD-3 PIC 9(02).
10 FIELD-4 PIC 9(02).
66 GROUP-C RENAMES FIELD-2 THRU FIELD-3.

HIGH-VALUES Clause in COBOL And LOW-VALUES Clause in COBOL - What are HIGH-VALUES and LOW-VALUES in COBOL?

How does the Mainframe Computer store data and information?

Every character or alphabet is represented as a unique 8-bit pattern of 0s and 1s. For example, A is stored as 1100 0001 or X'C1' in hex. B is stored as 1100 0010 or X'C2' in Hex.

Similarly, the LOW-VALUE character is stored as 0000 0000 or X'00' in Hex.

The HIGH-VALUE Character is stored as 1111 1111 or X'FF' in Hex. Understand, that these are non-displayable characters.

INDEX in COBOL : How to Define INDEX in Working-Storage Section ?

01 WS-I USAGE IS INDEX

This is a valid working-storage definition of an Index.

EXIT PROGRAM Clause in COBOL

EXIT PROGRAM only works in sub-programs, and transfers control to the calling Program. If used in the Main Driver Program, it causes 4038 Abend.

GO BACK Clause in COBOL

STOP RUN terminates the entire run-unit – the Main Driver Program along with all its sub-programs. GO BACK returns the control back to the calling program.
GO BACK when used the Main Driver Program, returns the control back to the OS.

STOP RUN Clause in Cobol

STOP RUN terminates the entire run-unit – the Main Driver Program along with all its sub-programs. GO BACK returns the control back to the calling program.

What is the difference between STOP RUN, GO BACK and EXIT PROGRAM?

STOP RUN terminates the entire run-unit – the Main Driver Program along with all its sub-programs. GO BACK returns the control back to the calling program.

GO BACK when used the Main Driver Program, returns the control back to the OS.

EXIT PROGRAM only works in sub-programs, and transfers control to the calling Program. If used in the Main Driver Program, it causes 4038 Abend.

Can you pass an Index to another COBOL Program, via LINKAGE SECTION?

No, an INDEX is not a Working-storage area. It is maintained by the System. You can only send the data which is in Working-storage areas(Rough-work area) or in File Input-Output Areas to a COBOL Program.

You can pass a Subscript to another COBOL Program.

88-Level In Cobol : What is 88-Level used for?

Used for assigning labels to data-values that a COBOL-Variable can take. Very useful in detecting special-conditions. They work like flags or switches.

01 TEMPERATURE PIC 9(03).
88 HIGH-TEMPERATURE VALUES 75 THRU 100.
88 MEDIUM-TEMPERATURE VALUES 50 THRU 74.
88 LOW-TEMPERATURE VALUES 32 THRU 49.

MOVE 60 TO TEMPERATURE

IF MEDIUM-TEMPERATURE(You need not write TEMPERATURE=60)
...
END-IF

Rules for forming User-defined words IN Cobol

- Can be at most 30 characters in length.
- Only alphabets, digits and hyphen are allowed.
- Blanks are not allowed.
- May not begin or end with a hyphen.
- Should not be a COBOL reserved word like ADD,SUBTRACT,MOVE,DISPLAY etc….

Data names in COBOL

Data names

- Are named memory locations.
- Must be described in the DATA DIVISION before
they can be used in the PROCEDURE DIVISION.
- Can be of elementary or group type.
- Can be subscripted for Arrays.
- Are user defined words .

COBOL coding sheet


Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas.
These are -

AREA A
- Between Column 8 to 11
-Division, Section, Paragraphnames, FD entries & 01 level entries must start in Area A

AREA B
- Between Column 12 to 72
- All Sentences & Statements start in Area B