Sunteți pe pagina 1din 7

1959 - COBOL developed by COnference on DAta SYstems Language (CODASYL)

1960 - First COBOL Compiler released


1968 - First ANSI approved version
1974 - Modified ANSI approved version (OS/VS COBOL)
1985 - Modified ANSI approved version (VS COBOL 2)

IBM COBOL for OS/390 V2R2.

01-06 - Sequence Number


07-07 - Continuity (-), Comment (*), New Page (/), Debugging Line (D)
08-11 - Column A - Divisions, Sections, Paragraphs, 01 & 77 declarations
12-72 - Column B - All the other declarations/statements
73-80 - Identification field. Ignored by compiler but visible in the source listing

CHARACTER - Digits (0-9), Alphabets (A-Z), Space (b), Special Characters (+ - * / (


) = $ ; " > < . ,)
WORD - One or more Characters - User defined or Reserved
CLAUSE - One or more Words. Specifies an attribute for an entry
STATEMENT - One or more valid Words & Clauses
SENTENCE - One or more Statements
PARAGRAPH - One or more Sentences
SECTION - One or more Paragraphs
DIVISION - One or more Sections or Paragraphs
PROGRAM - Made up of 4 Divisions

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
*CBL TRUNC(BIN)

IDENTIFICATION DIVISION.
PROGRAM-ID. XXXXXXXX. (Program Name - 8 Characters are identified by
compiler. Rest ignored)
* AUTHOR. <Comment Entry>.
* INSTALLATION. <Comment Entry>.
* DATE-WRITTEN. <Comment Entry>.
* DATE-COMPILED. <Comment Entry>.
* SECURITY. <Comment Entry>.

ENVIRONMENT DIVISION. (Machine dependant)


* CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-370. (Compiled Comp) WITH DEBUGGING MODE.
OBJECT-COMPUTER. IBM-370. (Executed Comp)
PROGRAM COLLATING SEQUENCE IS MY-COLLATE.
SPECIAL-NAMES.
CURRENCY SIGN IS <Literal-1>.
DECIMAL-POINT IS COMMA.
CLASS <DIGIT> IS "0" THRU "9".
ALPHABET MY-COLLATE IS 'ZYXWVUTSRQPONMLKJIHGFEDCBA'.
ALPHABET COL-SEQ IS NATIVE/EBCDIC (EBCDIC "a" X'81 < "A" X'C1' < "1"
X'F1' - X'00' thru X'FF') / STANDARD-1 (ASCII "1" X'31' < "A" X'41' < "a" X'61' -
X'00' thru X'7F').
ALPHABET SPECIAL-SEQ IS
"A" ALSO "a"
"B" ALSO "b"
"C" ALSO "c"
"D" ALSO "d"
"E" ALSO "e"
"F" ALSO "f"
"G" ALSO "g"
"H" ALSO "h"
"I" ALSO "i"
"J" ALSO "j"
"K" ALSO "k"
"L" ALSO "l"
"M" ALSO "m"
"N" ALSO "n"
"O" ALSO "o"
"P" ALSO "p"
"Q" ALSO "q"
"R" ALSO "r"
"S" ALSO "s"
"T" ALSO "t"
"U" ALSO "u"
"V" ALSO "v"
"W" ALSO "w"
"X" ALSO "x"
"Y" ALSO "y"
"Z" ALSO "z".
* INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ?
* I-O CONTROL.

*DATA DIVISION. (Optional)


FILE SECTION.
FD ?
WORKING-STORAGE SECTION.
LINKAGE SECTION.

PROCEDURE DIVISION.

IDENTIFICATION DIVISION.
PROGRAM-ID. XXXXXXXX.
AUTHOR.
DATE-WRITTEN.
DATE-COMPILED.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER.
OBJECT-COMPUTER.
SPECIAL-NAMES.
CURRENCY SIGN IS ..
DECIMAL-POINT IS ..
CLASS XYZ IS ..
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILE-NAME1 ASSIGN TO DDNAME1
ORGANIZATION IS SEQUENTIAL/INDEXED/RELATIVE
ACCESS MODE IS SEQUENTIAL/RANDOM/DYNAMIC RELATIVE KEY IS <>
FILE STATUS IS FILE-STATUS
RECORD KEY IS FILE-KEY
ALTERNATE RECORD KEY IS <> WITH DUPLICATES.
SELECT FILE-NAME2 ASSIGN TO DDNAME2
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE-STATUS
RECORD KEY IS FILE-KEY.
I-O-CONTROL.

DATA DIVISION.
FILE SECTION.
FD/SD FILE-NAME1
RECORDING MODE IS F/V/U/S
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 10 CHARACTERS
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS DATA-RECORD1.
01 DATA-RECORD1.
05 DATA-RECORD1-ID PIC X(01).
05 DATA-RECORD1-DATA PIC X(99).

FD FILE-NAME2
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS DATA-RECORD2.
01 DATA-RECORD2 PIC X(100).
WORKING-STORAGE SECTION.
LINKAGE SECTION.

Identification Division.
Program-id.
Author.
Date-written.
Date-compiled.

Environment Division.
Configuration Section.
Source-computer.
object-computer.
special-names.
class
decimal-point is
currency sign is
input-output section.
file-control.
select file-name assign to ddname
organization is indexed
access mode is sequential
file status is file-status
record key is file-key.
i-o-control.

Data Division.
File Section.
Working-Storage Section.
Linkage Section.

Procedure Division.

Literal - Constant that can be numberic (18 digits) or non-numeric (160 characters)
Identifier/Variable - Named Memory Location which stores the Literal
Figurative Constants - Sub-set of Reserved Words in Cobol that are used frequently
- Literals as well
ZERO/ZEROS/ZEROES/QUOTE/QUOTES/SPACE/SPACES/ALL/HIGH-VALUE/HIGH-VALUES/LOW-
VALUE/LOW-VALUES

01 WS-VARIABLE PIC X(04) VALUE 'ABCD'

Identifier/Variable - WS-VARIABLE
Constant
Literal - ABCD (Non-Numeric)

Level# Variable Picture-Clause Usage-Clause Sync-Clause Sign-Clause Value-Clause

LEVEL# - Specifies hierarchy of data within a record. Values from 01-49 or 66 or 77


or 88
01 - Specifies the Record itself. It can be a group of items or an Elementary item
by itself. Should begin in Area-A.
66 - Specifies the items that contain Renames-Clause
77 - Specifies an Independent data item
88 - Specifies Condition names & values
02-49 - Specifies group or elementary items within a record (Level# 01).
Group level items do not have Picture-Clause

VARIABLE
Name can have upto 30 characters with atleast 1 alphabet and may have hyphen
special char (not first or last).
It should be unique within a record (Level# 01). "OF" qualifier to be used for
same names in different records.

FILLER
Items cannot be initialized or used in any operation of the Procedure division.

PICTURE-CLAUSE:
NUMERIC:
9 - Digit
V - Implied Decimal Point
S - Sign
P - Assumed Decimal Point when point lies outside the data item
NUMERIC EDITS:
+ - Plus Sign
- - Minus Sign
CR - Credit Sign
DB - Debit Sign
. - Period
b - Blank
, - Comma
0 - Zero
/ - Slash
BLANK WHEN ZERO - Insert blank when data value is 0
Z - Zero Suppression
* - Asterisk
$ - Currency Sign
NON NUMERIC:
A - Alphabet
B - Blank Insertion Char
X - Alpha Numeric
G - DBCS (Double Byte Character Set)
EXCLUSIVE SETS:
+ - CR DB
V .
$ + - Z * ($***.**)
VALUE-CLAUSE: initializing data-items in w-s-section. Value of items must not
exceed Picture size. Not defined for Variable size.
VALUE IS literal.
VALUE IS literal-1 THRU/THROUGH literal-2.
VALUE IS literal-1, literal-2.
literals - Numeric without quotes, Non-Numeric with quotes, Figurative Constants.

SIGN-CLAUSE: applicable with PIC string contains "S".


SIGN IS (LEADING) SEPARATE CHARACTER (TRAILING).
Default is TRAILING WITH NO SEPARATE CHARACTER - So "S" doesnot take any space. It
is stored along with last digit.
+1 - +9 = A - I; +0 - {
-1 - -9 = J - R; -0 - }

Number Trailing Sign Leading Sign Leading Separate


-125 12N J25 -125
+125 12E A25 +125

Nibble - 04 Bits - In Packed Decimal each Nibble stores 1 digit.


Byte - 08 Bits - By Default, each character is stored in 1 Byte.
Half Word - 16 Bits / 02 Bytes
Full Word - 32 Bits / 04 Bytes
Doube Word - 64 Bits / 08 Bytes

USAGE CLAUSE:
DISPLAY Default. No of Bytes required equals to size of data item.
COMP Binary representation of data item.
PIC can contain S and 9 only.
S9(01) - S9(04) - Half Word
S9(05) - S9(09) - Full Word
S9(10) - S9(18) - Double Word
COMP-1 Single Word floating point item.
PIC clause should not be specified.
Sign is First Bit of left most Byte.
Exponent is remaining 7 Bits of First Byte.
Mantissa is last 3 Bytes.
COMP-2 Double Word floating point item.
PIC clause should not be specified.
Sign is First Bit of left most Byte.
Exponent is remaining 7 Bits of First Byte.
Mantissa is last 7 Bytes.
COMP-3 Packed Decimal representation of data item.
Each digit takes half byte.
"PIC 9(N) COMP-3" would take (N+1)/2 bytes.
Sign is stored separately in rightmost half-byte regardless of whether "S" is
specified or not.
C - Signed +ve
D - Signed -ve
F - Unsigned +ve
INDEX Used to preserve Index value of an array.
4 Bytes. PIC Clause should not be specified.
When specified for a Group item, it applies to all elementary items but not
the Group item itself.
POINTER 4 Byte Elementary item.
Can be used in SET stmnt, Relation condt, USING phrase of CALL stmnt, ENTRY
stmnt or Procedure Div stmnt.
Value Clause can contain only NULL/NULLS.
SET pointer-1 TO ADDRESS OF pointer-2
SET ADDRESS OF pointer-2 TO pointer-1
pointer-1 is POINTER data item
pointer-2 is Linkage Section item

SYNC CLAUSE:
Specified with COMP, COMP-1, COMP-2 items.
Start at half/full/double word boundaries for faster address resolution.
Starting address of Full-Word should end with 0,4,8,C
Starting address of Half-Word should end with 0,2,4,8,A,C,E
may introduce slack bytes (unused bytes) before Binary Items

REDEFINES: (Any but Same Level - Cannot be done for 66/88)

RENAMES: (66 Level - Cannot be done for 01/66/77/88)

CONDITION: (88 Level) - Set to TRUE will allocate first value to the variable.

JUSTIFIED RIGHT:
Specified with X/A itesm for right justification. Cannot be used with 66 & 88
level items.

OCCURS CLAUSE:
User to define an array / allocate physically contiguous memory locations to store
table values and access them with subscript/index.

LINKAGE SECTION:
Access data that is external to the program
100 chars thru Parm of JCL
32K characters from another Program
Lenght field defined as HALF WORD BINARY is needed as first field.

EXEC CICS ASKTIME


ABSTIME (WS-ABSTIME)
END-EXEC

EXEC CICS FORMATTIME


ABSTIME (WS-ABSTIME)
DATESEP ('/')
MMDDYY (WS-MDY)
TIME (WS-TIME)
TIMESEP (':')
END-EXEC

05 WS-DATE-TIME.
10 WS-ABSTIME PIC S9(15) COMP-3.
10 WS-TIME.
15 WS-TIME-HM.
20 WS-TIME-HM-HH PIC 99.
20 FILLER PIC X.
20 WS-TIME-HM-MM PIC 99.
15 FILLER PIC X.
15 WS-TIME-SS PIC 99.
10 WS-MDY.
15 WS-MDY-MM PIC 9(02).
15 FILLER PIC X(01).
15 WS-MDY-DD PIC 9(02).
15 FILLER PIC X(01).
15 WS-MDY-YY PIC 9(02).
01 WS-TIME.
05 WS-TIME-HH PIC 99.
05 WS-TIME-MM PIC 99.
05 WS-TIME-SS PIC 99.
05 FILLER PIC XX.

01 WS-DATE.
05 WS-DATE-YY PIC 99.
05 WS-DATE-MM PIC 99.
05 WS-DATE-DD PIC 99.

ACCEPT WS-TIME FROM TIME


MOVE WS-TIME-HH TO WS-TIME-HH-ED
MOVE WS-TIME-MM TO WS-TIME-MM-ED
MOVE WS-TIME-SS TO WS-TIME-SS-ED

ACCEPT WS-DATE FROM DATE


MOVE WS-DATE-YY TO WS-DATE-YY-ED
MOVE WS-DATE-MM TO WS-DATE-MM-ED
MOVE WS-DATE-DD TO WS-DATE-DD-ED

DATE - YYMMDD
DAY - YYDDD
TIME - HHMMSSTT
DAY-OF-WEEK - 1-7 (Mon-Sun)

ACCEPT = Transfer data from input device or system information.


ACCEPT WS-VAR <FROM> <DATE/DAY/TIME/DAY-OF-WEEK/OTHER>.
If FROM is not coded, data is read from terminal.

STOP RUN - Last executable stmnt of Main Program - Returns control back to OS
EXIT PROGRAM - Last executable stmnt of Sub Program - Returns control back to Main
Program
GOBACK - can be coded in Main program as well as Sub program - Returns control back
to wehere it received from

LINKAGE - PARM - FZCMHNOT, FZCMMQGT

S-ar putea să vă placă și