1 / 299

Enterprise COBOL Concepts

Learn about COBOL, a language designed for business processing with great compilers that execute programs quickly. It's relatively simple to learn, and it keeps evolving with new features like XML and object-oriented programming.

waynej
Télécharger la présentation

Enterprise COBOL Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Enterprise COBOL Concepts Dr. David Woolbright woolbright_david@columbusstate.edu 2013

  2. 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)

  3. 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

  4. Program Organization • Program – Organized like a book • Division – Identification, Environment, Data, Procedure • Section • Paragraph • Sentence • Clause • Phrase • Word

  5. Grammatical Hierarchy • The grammatical hierarchy follows this form: • Identification division • Paragraphs • Entries • Clauses • Environment division • Sections • Paragraphs • Entries • Clauses • Phrases • Data division • Sections • Entries • Clauses • Phrases • Procedure division • Sections • Paragraphs • Sentences • Statements • Phrases

  6. 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 |

  7. Continuation of Statements • Statements can be continued on the next line in Area B

  8. Continuation of Literals • Continue the constant through column 71 • Put a “-” in column 7 • Continue constant with a ‘ OR “ • Continue constant in area B

  9. 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

  10. Things That Go in Area B Area B items: • Entries, sentences, statements, and clauses • Continuation lines

  11. Things That Go in A or B • Level-numbers • Comment lines • Compiler-directing statements • Debugging lines • Pseudo-text

  12. Preparing a Program Your Cobol Program Object Module Load Module CoboL Compiler Linkage Editor

  13. 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.

  14. 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.

  15. Things You Should Try • Here is a video that discusses how to change the JCL to fit your situation.

  16. Structure of a Program

  17. 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

  18. 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

  19. 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

  20. DATA DIVISION We define the fields/variables the program will need for computations in the WORKING-STORAGE SECTION. WORKING-STORAGE SECTION. 01 CUSTOMER-COUNT PIC S999 PACKED-DECIMAL. 01 PHONE-NUMBER. 05 AREA-CODE PIC X(3). 05 EXCHANGE PIC X(3). 05 LOCAL-NUMBER PIC X(4).

  21. DATA DIVISION We define files and the structure of records in each file in the FILE-SECTION. 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).

  22. Variables (Fields) • A variable or field is a storage area that has a name and a type • The type controls the kind Of data the variable can contain CUST-NAME VARIABLE NAME STORAGE AREA DATA TYPE (ALPHANUMERIC) SMITH

  23. Two Categories of Variables • Elementary Items – a single field • Group Items – a field that contains other fields 01 PART. 10 PART-NAME PIC X(20). 10 PART-NO PIC X(8).

  24. Cobol Variable Declaration • Each declaration has up to five parts: 15 CUST-COUNT PIC S999 PACKED-DECIMAL VALUE 0. Level Number Picture clause Initial value clause Variable Name Usage clause Level – identifies the position of the variable in a hierarchical structure Picture clause - Describes the number of digits or characters in the field, whether the field has a sign, and any editing characters the field contains Usage clause – identifies the type of data, if omitted, usage is DISPLAY. Can be declared USAGE IS PACKED-DECIMAL

  25. Omission of Declaration Parts • Every field must have a level number that indicates its place in a hierarchy 01 PART. 10 PART-NAME PIC X(20). 10 PART-NO PIC X(8).

  26. Omission of The Name • The field name can be omitted or declared as FILLER: 10 PIC X(8). 10 FILLER PIC X(8). • In both cases, this is an unnamed field.

  27. Omission of Declaration Parts • Every elementary field must have PICTURE clause 10 COUNT PIC S999 PACKED-DECIMAL.

  28. Omission of Declaration Parts • The USAGE clause can be omitted. If omitted, USAGE IS DISPLAY is assumed. • Within a USAGE clause, the phrase USAGE IS can be omitted: 10 COUNT PIC S999 PACKED-DECIMAL. 10 COUNT PIC S999 USAGE IS PACKED-DECIMAL. 10 COUNT PIC S999.

  29. Omission of Declaration Parts • Group fields never have explicit pictures. Instead, they have default PIC X declarations based on the size of the elementary items they contain. 01 PART. Default PIC X(28) 10 PART-NAME PIC X(20). 10 PART-NO PIC X(8).

  30. Omission of Declaration Parts • The VALUE clause can be omitted. In this case, the contents of the field are uninitialized and determined by the contents of memory at runtime. 10 COUNT PIC S999 PACKED-DECIMAL VALUE 0. 10 COUNT PIC S999 PACKED-DECIMAL. Uninitialized!

  31. Sequential Declarations • Variables that are declared sequentially, occupy sequential locations in memory 01 PART. 10 PART-NAME PIC X(20). 10 PART-NO PIC X(8). PART PART-NAME PART-NO

  32. Level Numbers • Group item – a subdivided field • Elementary item – a non-subdivided field • 01 – Group or independent item • Higher numbers indicate subordinate fields

  33. Level Numbers • Level number range: 01 - 49 • Only 01 has a specific meaning • The specific numbers you choose doesn’t matter – what matters is the relation of the numbers to each other • Some companies have standards for level numbers • An increment of 3 or 5 is often used: 01, 05, 10, 15, …

  34. Level Numbers 01 XXX. 05 YYY. 10 AAA PIC X. 10 BBB PIC X. 05 ZZZ PIC X(20). Indention is important for making the hiearchical relationship explicit

  35. Three Special Level Numbers • 66, 77, 88 have special significance • 66 – Used to rename (no longer used) • 77 – An independent item (choose 01) 01 CUST-COUNT PIC S999. 77 CUST-COUNT PIC S999. • 88 – Condition name

  36. Condition Names • 01 TRAN-CODE PIC X. 88 GOOD-CODE VALUE ‘G’. 88 BAD-CODE VALUE ‘B’. 88 INDIFFERENT VALUE ‘I’. … SET GOOD-CODE TO TRUE … IF (GOOD-CODE) … CONDITION Equivalent to MOVE ‘G’ TO TRAN-CODE Equivalent to IF TRAN-CODE = ‘G’

  37. Level 88

  38. Condition Names

  39. 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

  40. Picture Clauses • PIC 9(6) • PIC 9(6)V99 • PIC 999999V99 • PICTURE X(10) • PIC XXXXXXXXXX • PIC S9(4)V9(4) • PIC S9999V9999 • PIC 9(18)

  41. Numeric Edited Fields These fields contain editing symbols (B, /, *, ., -, $) and are intended for display not for arithmetic • XXXBXXBXXXX • 99/99/99 • ZZ,ZZZ.99DB • ***,***.99 • ----.99 • $$$9.99 • 99999.99

  42. Numeric vs Numeric Edited • Numeric fields are designed for arithmetic operations • Numeric edited fields are designed for printing 01 X PIC S999 PACKED-DECIMAL. 01 Y PIC 999.99- .

  43. 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).

  44. 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.

  45. Hexadecimal • Base 16 • Digits: 0,1,2,3,…,9,A,B,C,D,E,F • With 4 bits, there are 16 combinations: • 0000 1000 We can represent 4 bits with one hex digit • 0001 1001 • 0010 1010 One byte (8 bits)can be represented by 2 hex • 0011 1011 digits • 0100 1100 10110101  1011 0101 • 0101 1101 B 5 • 0110 1110 11111101  1111 1101 • 0111 1111 F D

  46. 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’

  47. 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’

  48. 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

  49. 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. • 11111 is a negative number. Inverting, we have 00000. Adding 1 we get 00000 + 1 = 00001, so 1 is the additive complement. The original number is -1.

  50. Overflow/Underflow • Any scheme for representing numbers with a finite number of digits has computational limitations • Consider using a 4-bit 2’s complement representation. The range of integers is from -8 to + 7

More Related