Beruflich Dokumente
Kultur Dokumente
2 ALPHA
http://matrixguy180.tripod.com/cobol_bible.html
v1.0.2 ALPHA Written by Colin Wheeler from various sources These are notes that I have obtained from various sources on how to write the syntax of COBOL programs. I initially wrote this for myself but then decided to make this document public. Feel free to re-distribute this but do not alter it. If I find any errors on this page I will post the error and correct it and update the version number which is why I wrote a version number above so you can keep track of the updates. This page was written with Mozilla Composer v1.1a(Alpha) and is generally the best browser to view this page with because Mozilla supports more web standards than Internet Explorer. If you find anywhere in this document that I have made an error please compose an e-mail to me @ cdwheeler@mac.com with the subject "COBOL Error" and copy the section of this page that has an error and paste it into the e-mail message and then write what the error is then paste the code or section again and correct it. I will attempt to correct any errors on this page as quickly as possible. I know that i will probably make many errors but for me finding them and correcting them is more important than anything else. If you think that anything needs to be added to this guide please go to the COMING SOON page and check to see if your idea is in the works if it's not then e-mail it to me or if you think that one of my descriptions doesn't aqeately describe the code or section it's refeering to then e-mail me and let me know if there are enough people who have a problem with a section i will revise it. Please note that this is the very first post of this webpage and it could very well have a hundred errors and will eventually expand, but for now just notify me of anything wrong with the page. COBOL Bible v1.0.3 Coming Soon! Some of the fixes/new features are: * Over 30 various spelling and format errors fixed! * Fixed some various syntax errors present in the COBOL code * Fixed the code on this page that caused some text to be disproportional in Internet Explorer (still no probs with Mozilla :-) ) * Finally started work to enhance the page for Mozilla/Netscape users (Mozilla 1.0 and above - Netscape 7.0 preview 1 and above) * Finished Bolding all Procedure Division Statements What's new in COBOL Bible v1.0.2 ALPHA? (Updated 12:10am Wednesday July 17) * Completed Procedure Division Statements * Added Evaluate Statement Syntax (was previously missing from list of commands) * Corrected Miscelanious Errors on Page * Corrected Font Code in HTML so the page can be viewed well on Internet Explorer Index of COBOL Notes: I. Book Conventions II. Compiler Directives III. SELECT Statements IV . File Descriptions V . Picture & Value Clauses (Working Storage) VI. Procedure Division Statements Accept / Display Add Call Close Compute Delete Divide Evaluate Examine If ... Else ... If ... Else ... If .... Else... If If... Else Else Inspect Move Move Corresponding Multiply Open Perform Perform Until Perform Varying Perform Varying ...After Read Release Return Rewrite Search Sort Start String Subtract Transform Write VII. Validation Tecniques VIII. Table Usage IX. End Notes
I. Book Conventions
In order for you to get the most out of this page this book will assume a couple of things. The first assumption is that you have a general understanding of COBOL and want to know more and make sure that the syntax you use it correct to better correct errors. Eventually this page might be expanded to include sections on how to build better and
1 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
more efficient COBOL programs and if I receive suggestions on anything else I might include too. The next thing is that code is shown as such: SELECT DISK-FILE ASSIGN TO 'C:\Documents and Settings\User\file.dat' ORGANIZATION IS LINE SEQUENTIAL. In some cases I may show code that is like this... CARD-FILE RECORD CONTAINS 80 CHARACTERS 01 CARD-RECORD. 05 CARD-CODE ... ... 05 CARD-NAME
PIC X(25).
PIC X(15).
When I put "..." on a line as such that means that you can put more code in the section as necessary. When I enter code like this "CARD-CODE" that means that it is a variable name or section of code that you can change as needed. Please note though that in some instances some variable names depend on another defined name at which I will note it within or after the code. Please note that with this document i am trying to provide the framework for your syntax and in a lot of cases you can move parts of the code I have provided around or substitute different statements other than the ones i have provided. These examples are here to show you ways of doing your syntax that you might not have even been aware you could do but they are hardly the limit of what you can do with your syntax . I encourage you to look up other websites that involve COBOL syntax examples and see what they have also. Knowledge is Power after all.
01
FD
2 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
** Note ** The PICTURE clause is normally abbreviated to PIC and the USAGE clause is normally omitted since the defa is DISPLAY. 01 H1. 05 PIC X VALUE SPACES. (There is no name here because this part of the line is blank ... ... ... ... ... ... 05 PIC X(12) VALUE "REPORT TITLE". **Note** The number of characters on each line must equal the amount on the printer file 01 PERSONELL-REC. 05 PERS-NUM 05 PERS-NAME ...
66 Level Items:
01 EMPLOYEE-RECORD. 05 EMPLOYEE-LNAME PIC X(26). 05 EMPLOYEE-FNAME PIC X(26). 05 EMPLOYEE-BIRTH-DATE. 10 EMPLOYEE-BIRTH-DAY PIC 99. 10 EMPLOYEE-BIRTH-MON PIC 99. 66 EMPLOYEE-FULL-NAME RENAMES EMPLOYEE-LNAME THRU EMPLOYEE-FNAME.
77 Level Items:
77 77 IO-STATUS IO-LITERAL PIC XX VALUE SPACES. PIC X(29) VALUE "TOTALS FOR SECTION".
88 Level Items:
01 WOR-REC. 05 WK-GRADE 88 K6 88 MIDSCHL 88 HIGH-SCHOOL 88 GRADE-ERROR PIC 99. VALUE 1 THRU 6. VALUE 7 8. VALUE 9 THRU 12. VALUE 00 13 THRU 99.
ACCEPT WORK-DATE FROM DATE. **Note** : "WORK-DATE" should be defined in the working storage and DATE is supplied by the operating system you are using ( Mac OS X, Windows XP, etc.) ACCEPT causes the program to 'stop' and allows you to enter data on console and will not continue with the execution of the program until the user presses the Enter key. This allows you to communicate with the terminal (user) and enter data into the program. ACCEPT FILENAME FROM CONSOLE. This statement will receive information into the program and places it into a data-item defined in the program. FILENAME is desined in the working storage section. DISPLAY 'message here' UPON CONSOLE ** Note that the "UPON CONSOLE" section is not required in this statement ** DISPLAY PAGE-CTR This causes the value of PAGE-CTR to be displayed - 2. ADD (1)ADD SUB-BAL TO TOTAL-BAL.
3 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
(2)ADD SUB-BAL SLS-BAL SSLS-BAL TO TOT-BAL (3)ADD SUB-BAL SLS-BAL SSLS-BAL GIVING TOT-BAL (4)ADD INPUT-BAL TO TOT-BAL ROUNDED ON SIZE ERROR MOVE 0 TOT TOT-BAL DISPLAY 'ERROR IN ADDITION'. (1) Adds "SUB-BAL" to "TOTAL-BAL" (2) Adds "SUB-BAL", "SLS-BAL","SSLS-BAL" to "TOT-BAL" (3) Adds "SUB-BAL","SLS-BAL","SSLS-BAL" using the fiield defined for "TOT-BAL" (4) Adds "INPUT-BAL" to "TOT-BAL" rounding the number. If the field is too big it will give an error - 3. CALL CALL 'PAYCAL' USING PARM1 PARM2 PARM3.
- 5. COMPUTE -
(1)COMPUTE BALANCE=(INTRST * (2)COMPUTE BALANCE=(INTRST * (3)COMPUTE BALANCE ROUNDED = ON SIZE ERROR MOVE 0 TO BALANCE DISPLAY 'ERROR ON
COMPUTE'.
- 6 . DELETE DELETE TABLE-FILE. This form of the delete statement has to follow a sucsessful read before the delete statement can be performed. If the read is not performed then the delete statement will not be performed and in an interactive COBOL program you would need to generate an error message. - 7. DIVIDE (1)DIVIDE 100 INTO INT-RATE. (2)DIVIDE MONTHS INTO INT-RATE GIVING MONTH-RATE. (3)DIVIDE INTO-RATE BY MONTHS GIVING MONTH-RATE. - 8. EVALUATE -
EVALUATE YEARS-IN-COLLEGE-IN WHEN 1 PERFORM 300-FRESHMAN-RTN WHEN 2 PERFORM 400-SOPHMORE-TRN WHEN 3 PERFORM 500-JUNIOR-RTN WHEN 4 PERFORM 600-SENIOR-RTN WHEN OTHER PERFORM 700-ERR-RTN END EVALUATE - 8. EXAMINE EXAMINE statements replace one value with another value. Example below: EXAMINE PRT-FLD REPLACING ALL ',' BY '/'. - 9. IF... ELSE (1)IF RATE-CODE EQUAL 'A' MOVE '9' TO RATE. (2)IF RATE-CODE EQUAL 'A' MOVE '9' TO RATE. ELSE MOVE '7' TO RATE. WRITE PRT-REC FROM D1 AT EOP PERFORM 4000-HDG. GO TO 4000-EXIT. 10. If...Else If...Else IF SALES LESS 500 COMPUTE COMMISSSION = .02 * SALES
4 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
ELSE IF SALES LESS 5000 COMPUTE COMISSION = .05 * SALES ELSE COMPUTE COMISSION = .1 * SALES. 11. IF IF... ELSE ELSE
IF SALES GREATER 499.99 IF SALES GREATER 4999.99 COMPUTE COMISSION = .1 * SALES ... ELSE COMPUTE COMISSION = .05 * SALES ... ELSE COMPUTE COMISSION = .05 * SALES
12. INSPECT
-INSPECT FLD3 TALLYING CTR1 FOR ALL ','. -INSPECT FLD3 REPLACING ALL ',' BY '/'. 13. MOVE
MOVE INPUT-BAL TO PRT-BAL. MOVE ZERO TO REC-CTR LINE-CTR PAGE-CTR MOVE ZERO TO REC-CTR LINE-CTR PAGE-CTR. 14. MOVE CORRESPONDING
PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC
MOVE CORRESPONDING CURR-DATE TO SWT-DATE. MOVE CORR CURR-DATE TO SWT-DATE. **Note** If identically named field must be referenced, the group level of the field must be identified with an OF c ex: MOVE DD OF CURR-DATE TO WORK-DD. 15. MULTIPLY
MULTIPLY INPUT-HRS BY INPUT-RATE. MULTIPLY INPUT-HRS BY INPUT-RATE GIVING GROSS-PAY. MULTIPLY INPUT-HRS BY INPUT-RATE GIVING GROSS-PAY ROUNDED ON SIZE ERROR MOVE 'Y' TO ERROR-SWT DISPLAY 'ERROR ON MULTIPLY'. 16. OPEN
OPEN INPUT CARD-FILE OUTPUT PRT-FILE ISAM-FILE. OPEN INPUT CARD-FILE TAPE-FILE VSAM-FILE. OPEN OUTPUT PRT-FILE. 17. PERFORM
5 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
PERFORM 2000-PRT UNTIL PAGE-CTR GREATER THAN 100. PERFORM 2000-PRT THRU 2000-X. UNTIL MORE-CARDS EQUAL 'N'. PERFORM 4100-READ THRU 4100-X UNTIL MORE-CARD EQUAL 'N' OR CARD-CODE EQUAL 3. PERFORM 4100-READ THRU 4100-X UNTIL MORE-CARD EQUAL 'N' OR CARD-CODE EQUAL 3 OR CARD-CTR GREATER 100. 19. PERFORM VARYING:
PERFORM 1100-CLEAR VARYING SUB FROM 1 BY 1 UNTIL SUB GREATER 100. PERFORM 4100-PRT THRU 4100-X VARYING EMP-NO FROM 10 BY -1 UNTIL LIST(EMP-NO) EQUAL 'ADAMSON' OR EMP-NO EQUAL 1. 20. PERFORM VARYING ...AFTER:
PERFORM 1100-FIND THRU 1100-X VARYING ROW-SUB FROM 1 BY 1 UNTIL ROW-SUB GREATER 10 AFTER COL-SUB FROM 1 BY 1 UNTIL COL-SUB GREATER 3 AFTER DEPTH-SUB FROM 1 BY 1 UNTIL DEPTH-SUB GREATER THAN 5. 21. READ:
READ CARD-FILE READ CARD-FILE INTO EMP-CARD. READ CARD-FILE INTO EMP-CARD AT END MOVE 'N' TO MORE-RECS GO TO 4100-X.
6 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
23. RETURN:
RETURN SORT-FILE. RETURN SORT-FILE INTO WK-RECORD. RETURN SORT-FILE INTO WK-RECORD AT END MOVE 'N' TO MORE-SORT-RECS GO TO 1200-X. 24. REWRITE:
REWRITE VSAM-REC. REWRITE VSAM-REC FROM WK-REC. REWRITE VSAM-REC FROM WK-REC INVALID KEY MOVE 'Y' TO ERROR-SWT DISPLAY 'ERROR ON REWRITE'. 25. SEARCH:
01 GRADE-AREA. 05 GRADE-TABLE OCCURS 25 TIMES INDEXED BY INDX. 10 GRADE-NAME PIC X(10). 10 GRADE-NUM PIC 999. SET INDX TO 1. SEARCH GRADE-TABLE AT END MOVE 'DONE' TO SEARCH-STATUS WHEN WK-NAME GREATER GRADE-NAME(INDX) MOVE 'FOUND' TO SEARCH-NAME-SWT. SET INDX TO 1. SEARCH GRADE-TABLE AT END MOVE 'DONE' TO SEARCH-STATUS WHEN WK-NAME GREATER GRADE-NAME(INDX) MOVE 'FOUND' TO SEARCH-NAME-SWT WHEN WK-NUM EQUAL GRADE-NUM(INDX) MOVE 'FOUND' TO SEARCH-NUM-SWT. 26. SORT:
SORT SORT-FILE ASCENDING KEY SORT-SSN SORT-LNAME SORT-FNAME USING INPUT-FILE GIVING OUTPUT-FILE. SORT SORT-FILE ASCENDING KEY SORT-SSN SORT-LNAME SORT-FNAME DESCENDING KEY SORT-ACT-BAL ASCENDING KEY SORT-TRAN-DATE INPUT PROCEDURE IS 4100-READ THRU 4100-X OUTPUT PROCEDURE IS 4200-PRT THRU 4200-X. 27. START:
START VSAM-FILE INVALID KEY DISPLAY 'NO RECORD FOUND WITH MATCHING KEY' START VSAM-FILE KEY GREATER THAN EMP-NAME INVALID KEY DISPLAY 'NO RECORD FOUND WITH REQUESTED KEY'. 28. STRING:
STRING 'A' 'B' 'C' DELMITED BY SIZE INTO REC-FLD. STRING FNAME DELMITED BY ' ' SPACE DELMITED BY SIZE
7 of 8
3/24/2013 1:12 AM
http://matrixguy180.tripod.com/cobol_bible.html
LNAME DELMITED BY SPACE INTO PRT-NAME. STRING FNAME MNAME SPACE DELMITED BY SIZE LNAME DELMITED BY SPACE INTO PRT-NAME WITH POINTER BEGIN-POSITION ON OVERFLOW DISPLAY 'STRUNG TOO MUCH'. 29. SUBTRACT:
SUBTRACT INPUT-BAL FROM TOT-BAL. SUBTRACT INPUT-BAL INPUT-DEP INPUT-INT FROM TOT-BAL. SUBTRACT INPUT-BAL FROM TOT-BAL ROUNDED ON SIZE ERROR MOVE 0 TO TOT-BAL DISPLAY 'ERROR IN SUBTRACTION'. 30. TRANSFORM:
WRITE PRT-REC AFTER ADVANCING 2 LINES. WRITE PRT-REC FROM H1 AFTER AVDANCING PAGE. WRITE PRT-REC AT EOP PERFORM 4100-HDGS. WRITE PRT-REC AFTER ADVANCING 4 LINES AT EOP PERFORM 4100-HDGS.
Sequential Disk
WRITE SEQ-DISK-REC FROM WK-REC INVALID KEY PERFORM 4300-ERR GO TO 2000-X.
8 of 8
3/24/2013 1:12 AM