Page 1 of 1

Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 12:49 am
by waynebowden
Hello all,

I have been working as an Admin on Racf through the vanguard utility for years blissfully unaware of a majority of the mainframe.

I have enrolled on a mainframe development class to get to grips with JCL and Cobol.

Looking for a little help, Have been give some code with 8 errors and wondering can you guys help pick them out.

I am having trouble finding any.

Code is

1. ENVIRONMENT DIVISION.
2. PROGRAM-ID CBLCALC.
3. IDENTIFICATION DIVISION.
4. INPUT-OUTPUT.
5. FILE-CONTROL.
6. SELECT CREDCARD-FILE ASSIGN.
7. DATA DIVISION.
8. FILE SECTION.
9. FD I-CREDCARD-FILE
10. RECORDING MODE IS F.
11. 01 ICRED-RECORD.
12. 03 CUST-NO PIC 9(3) VALUE SPACES.
13. 03 FIRST-NAME PIC X(10) VALUE SPACES.
14. 03 AMOUNT PIC S9(4). 99 VALUE ZEROS.
15. WORKING-STORAGE SECTION.
16. 01 FLAG-EOF PIC 9 VALUE ZEROS.
17. 01 RECORD-COUNT PIC 9(5) VALUE ZEROS.
18. * THIS IS MY MAIN PROCESSING LOGIC
19. PROCEDURE-DIVISION.
20. PERFORM BEGIN UNTIL FLAG-EOF EQUAL 1.
21. PERFORM FINISH.
22. STOP RUN.
23. BEGIN.
24. OPEN OUTPUT CREDCARD-FILE.
25. READ CREDCARD-FILE
AT END DISPLAY 'EOF - NO RECORDS IN FILE'
MOVE 1 TO FLAG-EOF.
26. ADD 1 TO REC-COUNT.
27. FINISH.
28. DISPLAY RECORD-COUNT.
29. CLOSE INPUT-CREDCARD-FILE.

Thank you,

Wayne

Re: Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 2:20 am
by BillyBoyo
The first thing you need to do is look at the highest two levels of "things" in a COBOL program. The DIVISIONs and the required SECTIONs (where they exist) within them.

That part will not be a long-term problem, as you will (won't you?) always copy a COBOL program as the starting point for a new program).

Then look for typos. Things that when you read them are "the same", but when you study them have subtle differences. You have to practice, but it'll come. Things have to be exact. If you add permissions to a user-id but you misspell it, the correct user doesn't get the expected result. Same with COBOL.

There's a couple of logic errors.

You need to sort the first two groups out, then look at the first fixed program. Then go through closely. Take a pencil and scrap paper. Read the code. Write down in English or pseudo-code. Read the code again and check that the two agree and make sense. Continue.

Again, that is practice. It'll become natural, if you spend the time to go through it.

Re: Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 2:32 am
by waynebowden
Thank you for the reply Billy,

Correct we will always start with an existing program and tweak to suit the needs.

I guess my main problem is I have a class test on the above, so time and practice is not viable within the time line.

I can see maybe 3 issues.

Divisions not in correct order
SELECT CREDCARD-FILE ASSIGN not assigned to anything
Variable is called REC-COUNT but should be RECORD-Count

Any other you can point out?

Thank you

Wayne

Re: Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 2:58 am
by Robert Sample
1. The FD does not match the ASSIGN nor the OPEN / CLOSE statements.
2. You only want to open the file once -- hence you do not want to PERFORM BEGIN more than once, or you want to move the OPEN so it only occurs once.
3. If you want to READ CREDCARD-FILE you probably don't want to open it for OUTPUT.
4. Your code will display 'EOF - NO RECORDS IN FILE' when the end of file is reached no matter how many records were read (related to #2).
5. Not only are the divisions out of sequence, but some of the names under the divisions are incomplete.

Re: Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 4:21 am
by BillyBoyo
This is wrong: 03 AMOUNT PIC S9(4). 99 VALUE ZEROS., numeric-edited can't have an implicit sign. There's a 9(3) with a VALUE SPACES. Your file is given multiple names. I strongly suspect a lot more than eight errors... perhaps that was another test?

Re: Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 4:25 am
by BillyBoyo
Messages    Total    Informational    Warning    Error    Severe
Printed:      34           3                       14        17

Re: Need to Identify 8 errors

PostPosted: Mon Mar 30, 2015 4:33 am
by BillyBoyo
After correcting the order, formatting, then de-hyphenating PROCEDURE DIVISION (typo posting here?)

     4  IGYDS1103-E   Expected "SECTION", but found ". ".  "SECTION" was assumed
                                                                               
     6  IGYDS0093-S   ". " was found in the "ASSIGN" clause.  The clause was dis
                                                                               
     6  IGYGR1131-S   Neither an "FD" nor an "SD" was found in this program for
                                                                               
     9  IGYGR1232-S   No "SELECT" statement was specified for file "I-CREDCARD-F
                                                                               
    12  IGYDS1158-I   A non-level-88 "VALUE" clause was found in the "FILE SECTI
                      treated as comments.                                     
                                                                               
                      Same message on line:     13     14                       
                                                                               
    14  IGYDS1149-S   "S9(4).99" was not a valid combination of "PICTURE" string
                      assumed.                                                 
                                                                               
    23  IGYPS2122-S   "CREDCARD-FILE" was not defined as a file-name.  The state
                                                                               
                      Same message on line:     24                             
                                                                               
    27  IGYPS2121-S   "REC-COUNT" was not defined as a data-name.  The statement
                                                                               
    30  IGYPS2122-S   "INPUT-CREDCARD-FILE" was not defined as a file-name.  The


Even then, that's nine (eight S's and an E, plus three Is which should always be cleared up).

Plus, the logic errors Robert detailed.