Enterprise COBOL Concepts. Dr. David Woolbright woolbright_david@columbusstate.edu 2013. Video Link. Watch the Introductory video lesson here. COBOL?. Co mmon B usiness O riented L anguage Billions of lines of existing code with more added each year Designed for business processing
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Video Link • Watch the Introductory video lesson here
COBOL? • Common Business Oriented Language • Billions of lines of existing code with more added each year • Designed for business processing • Great compilers • Cobol programs execute quickly • Relatively simple to learn • Not your father’s or mother’s COBOL - The language keeps evolving (XML, OO)
Enterprise Cobol for z\OS IBM COBOL: • http://www-01.ibm.com/software/awdtools/cobol/zos/ Languagage Reference • http://publibfp.boulder.ibm.com/epubs/pdf/igy3lr50.pdf Programming Guide • http://publibfp.boulder.ibm.com/epubs/pdf/igy3pg50.pdf
Program Organization • Program – Organized like a book • Division – Identification, Environment, Data, Procedure • Section • Paragraph • Sentence • Clause • Phrase • Word
Coding Rules • Cols 1-6 – left blank. Editor fills in with sequence numbers • Col 7 – Usually blank,* means comment line, - is continuation, D for debugging lines • Cols 8-11 – “A” margin or Area A • Cols 12-72 – “B” margin or Area B • Cols 73-80 – unused • 1 2 3 4 5 6|7| 8 9 10 11|12 13 …71 72 | Seq Nos | | Area A | Area B |
Continuation of Literals • Continue the constant through column 71 • Put a “-” in column 7 • Continue constant with a ‘ OR “ • Continue constant in area B
Things That Go in Area A Area A items: • Division headers • Section headers • Paragraph headers or paragraph names • Level indicators or level-numbers (01 and 77) • DECLARATIVES and END DECLARATIVES • End program, end class, and end method markers
Things That Go in Area B Area B items: • Entries, sentences, statements, and clauses • Continuation lines
Things That Go in A or B • Level-numbers • Comment lines • Compiler-directing statements • Debugging lines • Pseudo-text
Preparing a Program Your Cobol Program Object Module Load Module CoboL Compiler Linkage Editor
Things You Should Try • You will need to create a PDS (Partitioned Data Set) to hold the programs (members) you create. You can watch a video about how to create a PDS here. • You will also need a load library where the linkage editor can place the executable programs (load modules) you create. Here is a video that describes how to build a load library.
Things You Should Try • When you’re beginning to learn a new language, it’s a good idea to type in a few programs from scratch. Here is a Hello, World program you should create in your PDS. And here is a video of how to create the program. • Here’s a link to some JCL that can be modified to compile, link, and run a COBOL program on your system.
Things You Should Try • Here is a video that discusses how to change the JCL to fit your situation.
IDENTIFICATION DIVISION IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. AUTHOR. JOE SMITH. INSTALLATION. TSYS. DATE-WRITTEN. 12/03/2011. DATE-COMPILED. 12/03/2011. • Only PROGRAM-ID is required • Some interesting parms can be coded on the PROGRAM-ID
ENVIRONMENT DIVISION This division connects external DD file names with internal file names. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MSTRFILE ASSIGN TO MSTRFILE SELECT CUSTOMER-FILE ASSIGN TO CUSTMAST ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS COSTOMER-KEY FILE STATUS IS CUSTOMER-FILE-STATUS. Internal File Name External DD File Name
DATA DIVISION • Used to create variables and constant fields • Only three data types • numeric PIC 99999. • alphanumeric (text/string) PIC XXX. • alphabetic PIC AAA. • Level numbers indicate subordination of fields. Use levels 01-49 • Alphabetic is seldom used
Level Numbers • Group item – a subdivided field • Elementary item – a non-subdivided field • 01 – Group or independent item • Higher numbers indicate subordinate fields
Level Numbers • 66, 77, 88 have special significance • 66 – Used to rename (no longer used) • 77 – An independent item (choose 01) • 88 – Condition name
Condition Names • 01 TRAN-CODE PIC X. 88 GOOD VALUE ‘G’. 88 BAD VALUE ‘B’. 88 INDIFFERENT VALUE ‘I’. … SET GOOD TO TRUE … IF (GOOD) … Equivalent to MOVE ‘G’ TO TRAN-CODE Equivalent to IF TRAN-CODE = ‘G’
Picture Clauses • Picture clause values usually use 9, X, V, S, A • 9 – a decimal digit • X – any alphanumeric character • V – an implied decimal point • S – a sign • A – A-Z, and blank
USAGE Clause • Specifies the format in which data is stored in memory • Normally, the phrase “USAGE IS” is omitted 01 COST USAGE IS PACKED-DECIMAL PIC S9(5). 01 COST PACKED-DECIMAL PIC S9(5). 01 FIRST-NAME USAGE ISDISPLAY PIC X(20). 01 FIRST-NAME PIC X(20).
DATA DIVISION We define data used in input-output operations. FILE SECTION. FD CUSTOMER-FILE. 01 CUSTOMER-MASTER. 05 CUST-NUM PIC 9(2). 05 CUST-FNAME PIC X(20). 05 CUST-LNAME PIC X(20). FD SALES-REPORT. 01 REPORT-AREA PIC X(132).
Data Formats Older terms: Modern terms: • COMPUTATIONAL BINARY • COMP BINARY • COMP-1 FLOATING POINT • COMP-2 FLOATING POINT • COMP-3 PACKED-DECIMAL • COMP-4 BINARY • COMP-5 BINARY (NATIVE) 05 XDATA PIC S9(5) PACKED-DECIMAL. 05 YDATA PIC S9(4) BINARY.
EBCDIC • EBCDIC is an IBM format for storing alphanumeric characters A - X’C1’ J - X’D1’ B - X’C2’ K - X’D2’ S – X’E2’ C - X’C3’ L - X’D3’ T – X’E3’ D - X’C4’ M - X’D4’ U – X’E4’ E - X’C5’ N - X’D5’ V – X’E5’ F - X’C6’ O - X’D6’ W – X’E6’ G - X’C7’ P - X’D7’ X – X’E7’ H - X’C8’ Q - X’D8’ Y – X’E8’ I - X’C9’ R - X’D9’ Z – X’E9’
EBCDIC • EBCDIC is an IBM format for storing alphanumeric characters 0 - X’F0’ SPACE – X’40’ 1 – X’F1’ . - X’4B’ 2 - X’F2’ , - X’6B’ 3 – X’F3’ * - X’5C’ 4 - X’F4’ - - X’60’ 5 – X’F5’ 6 - X’F6’ 7 – X’F7’ 8 – X’F8’ 9 – X’F9’
BINARY DATA • Stored in 2’s Complement format • Leftmost bit is a sign ( 0 +, 1 - ) • If the number is positive, interpret it as plain binary 01011 = 8 + 2 + 1 = + 11 • If the number is negative, compute the complement – Invert. (Change all 1’s to 0’s and 0’s to 1’s.) Add 1. The result is the additive complement
BINARY DATA • 10011 is a negative number. Inverting we have 01100. Adding 1 we have 01100 + 1 = 01101. This is a positive number. 01101 8 + 4 + 1 = 13, so the original number is -13.
BINARY DATA • Declaring a data field as BINARY causes the data to be stored in 2’s complement format. • 01 X-FIELD PIC S9(4) BINARY VALUE -1. • X-FIELD will contain 1111111111111111 = X’FFFF’. • Binary data is processed in a register
PACKED-DECIMAL DATA • Defining a field to be PACKED-DECIMAL or Computational-3 causes the data to be stored internally in a packed decimal format. • There are 2 decimal digits stored in each byte. A sign is stored in the rightmost “nibble”. (C +, D -) • Y-FIELD PIC S999 VALUE -23 PACKED-DECIMAL. produces a 2 byte field containing X’023D’ • Most business arithmetic occurs in packed decimal.
Packed No-Sign Data • Packed no-sign data is a non-native data type that was created to save space on a disk when storing dates • If the digits in a date like 10/23/89 were stored in a packed field, the field would require 4 bytes: 01|02|38|9C • By removing the sign, the date fits in 3 bytes: 10|23|89
Packed No-Sign Data • These type fields require special handling in Cobol • Program PKNOSIGN illustrates how a displayable date can be recovered from a packed no-sign field.
ZONED-DECIMAL DATA • A numeric field which is described as DISPLAY, or in which the usage clause is omitted, is stored in a zoned decimal format. • In zoned decimal, each digit takes up one byte, and a sign is stored in the zone portion of the rightmost byte of the field. • Z-FIELD PIC S999 VALUE -32 produces a 3 byte field containing X’F0F3D2’.
ZONED-DECIMAL DATA • Z-FIELD PIC S999 VALUE -32. produces a 3 byte field containing X’F0F3D2’. • Z-FIELD PIC S999 VALUE 32. produces a 3 byte field containing X’F0F3C2’. • W-FIELD PIC 999 VALUE 0. MOVE -32 TO W-FIELD produces a 3 byte field containing X’F0F3C2’.
DATA DIVISION Define the data needed for internal processing in the WORKING-STORAGE SECTION. Storage is statically allocated and exists for the life of the rununit. WORKING-STORAGE SECTION. 01 TOTAL-FIELDS. 05 CUST-TOTAL PIC S9(7)V99 VALUE 0. 05 COST-TOTAL PIC S9(7)V99 VALUE 0. 01 DATE-AND-TIME. 05 CD-YEAR PIC 9999. 05 CD-MONTH PIC 99.
DATA RELATIONSHIPS BINARY PACKED-DECIMAL CHARACTER or ALPHANUMERIC ZONED-DECIMAL
DATA DIVISION • Describe data that exists in another program, or storage you want to associate with a symbolic name in the LINKAGE SECTION. LINKAGE SECTION. 01 LK-DATA-AREA 05 NAME PIC X(40). 05 AGE PIC 999.
DATA DIVISION The LOCAL-STORAGE SECTION is used to have storage allocated each time a program is entered, and deallocated on return from the program. Used for compatibility with C or Java. LOCAL-STORAGE SECTION. 01 CUST-NO PIC X(3). 01 COST PIC 9(5)V99.
Initialization of Storage • WORKING-STORAGE for programs is allocated at the start of the run unit. • Any data items with VALUE clauses are initialized to the appropriate value at that time.
Initialization of Storage • For the duration of the run unit, WORKING-STORAGE items persist in their last-used state. Exceptions are: 1) A program with INITIAL specified in the PROGRAM-ID paragraph In this case, WORKING-STORAGE data items are reinitialized each time the program is entered. IDENTIFICATION DIVISION. PROGRAM-ID. MAIN IS INITIAL. ...
Initialization of Storage • For the duration of the run unit, WORKING-STORAGE items persist in their last-used state. Exceptions are: 2) A subprogram that is dynamically called and then canceled In this case, WORKING-STORAGE data items are reinitialized on the first reentry into the program following the CANCEL. MOVE ‘PROG23’ TO PROGID CALL PROGID CANCEL PROGID CALL PROGID
Connexion au compte
Connectez-vous pour publier votre contenu sur SlideServe.