# help with first cobol program!! extreme programming newb



## jonathan731 (Aug 30, 2003)

I am just starting to learn programming and I cant find any reason why my cobol program wont run. When I compiled it, it had so many errors. If anybody can help me it can be greatly appreciated.


*Jonathan Garcia, 000-846-100
*This program is meant to organize the file employee.dat

Identification Division. 
Program-id. Simple. 
Date-Compiled. 


Environment Division. 
Input-Output Section. 
File-Control.
Select input-file assign to "/home1/c/a/acsi203/company.dat"
Organization is line sequential. 

Select output-file assign to "prog1out.dat" 
Organization is line sequential.


Data Division. 
File Selection.

FD Input-file. 
01 input-rec. 
02 Last-name pic x(10).
02 First-name pic x(10).
02 ssn pic 9(9).
02 Filler pix x(6). 
02 Salary pic 9(4) v 9(2).
02 Filler pic x(1).
02 Marital-Status pic x.
02 Dependents pic 9.
02 Filler pic x(28).
02 Age pic 9(3).
02 Filler pic x(59).

FD Output-file.
01 output-rec. 
02 Last-name pic x(10).
02 First-name pic x(10).
02 ssn pic 9(9).
02 Filler pic x(6). 
02 Salary pic 9(4) v 9(2).
02 Filler pic x(1).
02 Marital-Status pic x.
02 Dependents pic 9.
02 Filler pic x(28).
02 Age pic 9(3).
02 Filler pic x(59).

FD Output-file.
01 output-rec pic x(132).


Working-Storage Section. 
01 Report-header.
02 Filler pic x(45) value spaces.
02 Filler pic x(42) value "Univertsity Textile Company - Employee List".
02 Filler pix x(45) value spaces.

01 Info-line. 
02 Filler pic x(10) value spaces. 
02 Last-name-out pic x(10).
02 Filler pic x(10) value spaces.
02 First-name-out pic x(10).
02 Filler pic x(10) value spaces.
02 ssn-out pic 9(9).
02 Filler pic x(10) value spaces. 
02 Salary-out pic 9(4) v 9(2).
02 Filler pic x(10) value spaces. 
02 Marital-Status-out pic x.
02 Filler pic x(10) value spaces.
02 Dependents-out pic 9.
02 Filler pic x(10) value spaces.
02 Age-out pic 9(3).
02 Filler pic x(24) value spaces. 


01 Report-footer.
02 Filler pic x(51) value spaces.
02 filler pic x(31) value "Number of Records Processed: xx". 
02 Filler pic x(50) value spaces. 

01 eof-flag pic x(3) value "no".


Procedure Division. 

0000-main-logic. 
Perform 1000-init.
Perform 2000-main-loop until eof-flag = "yes".
Perform 3000-finish. 
Stop Run.

1000-init. 
Open input input-file output output-file. 
Write output-rec from report-header. 
Read input-file at end move "yes" to eof-flag. 

2000-main-loop.
move last-name to last-name-out.
move first-name to first-name-out.
move ssn to ssn-out.
move salary to salary-out.
move marital-status to marital-status-out.
move dependents to dependents-out.
move age to age-out. 
write output-rec from info-line.
read input-file at end move "yes" to eof-flag. 

3000-finish.
write output-rec from report-footer. 
close input-file output-file.


----------



## BDACBT (Oct 13, 2007)

It's been a lot of years since my main frame days but I see a few things. First off, it looks like some careless mistakes. FD's have to be unique don't they? Look at your record descriptions. I think your count is off. I love this one, look at the line following Data Division.

From a cosmetic point, use indention. I can't tell if you did and formating here wiped it out. 

Use comments throughout program. I had an instructor who would practically fail a project if it wasn't well documented with comments. Months after you write this thing, you won't remember a damn thing about it. Whats worse is when other programmers have to work on it and have to spend a lot of time figuring out what a module does before they can even start working on it. They may spend a lot of time just to realize the module isn't involved in the problem. It may not seem like it's necessary with simple programs but it's good practice nonetheless. So at the beginning of a paragraph, write a brief synopsis of what the paragraph does. It will save you and other programmers a lot of time down the road. 

The Init routine should open files. A Read routine reads the records. A Move routine moves data. A Write routine writes the records. A Close routine closes the files. Point being, a good paragraph performs one type of activity. You aren't charged extra for an additional paragraph or two.

BTW, the one I love is "File Selection". I always thought it was "File Section."


----------



## jonathan731 (Aug 30, 2003)

oh wow theres definately a couple of errors...I just started learning I think i mispelled file section. i was going to add comments at the end and I did indent but it got messed up when i copied and pasted. In the procedure division I tried to follow the format that the professor set up. Thanks alot for the help I really appreciate it.


----------



## jonathan731 (Aug 30, 2003)

I tried to fix what you pointed out but the compiler still has a whole bunch of errors. writin this program really seemed alot easier than its been. Maybe an untrained eye but this really looks good! I added some comments so you know what im attempting to do everywhere. I hope you can helps thanks alot 


*This program is meant to organize the file employee.dat.

Identification Division. 
Program-id. Simple. 
Date-Compiled. 


Environment Division. 
Input-Output Section. 
File-Control.
Select input-file assign to "/home1/c/a/acsi203/company.dat"
Organization is line sequential. 

Select output-file assign to "prog1out.dat" 
Organization is line sequential.


Data Division. 
File Section.

*Attempting to describe the input file "company.dat" 
FD Input-file. 
01 Input-rec. 
02 Last-name pic x(10).
02 First-name pic x(10).
02 ssn pic 9(9).
02 Filler pix x(6). 
02 Salary pic 9(4) v 9(2).
02 Filler pic x(1).
02 Marital-Status pic x.
02 Dependents pic 9.
02 Filler pic x(28).
02 Age pic 9(3).
02 Filler pic x(59).

*Attempting to Describe te output file "prog1out.dat"
FD Output-file.
01 Output-rec. 
02 Last-name-test pic x(10).
02 First-name-test pic x(10).
02 ssn-test pic 9(9).
02 Filler pic x(6). 
02 Salary-test pic 9(4) v 9(2).
02 Filler pic x(1).
02 Marital-Status-test pic x.
02 Dependents-test pic 9.
02 Filler pic x(28).
02 Age-test pic 9(3).
02 Filler pic x(59).

*Attempting to describe the header. 
Working-Storage Section. 
01 Report-header.
02 Filler pic x(45) value spaces.
02 Filler pic x(42) value "University Textile Company - Employee List".
02 Filler pic x(45) value spaces.

*Attempting to describe the line of info. that will be repeated until info ends. 
01 Info-line. 
02 Filler pic x(10) value spaces. 
02 Last-name-out pic x(10).
02 Filler pic x(10) value spaces.
02 First-name-out pic x(10).
02 Filler pic x(10) value spaces.
02 ssn-out pic 9(9).
02 Filler pic x(10) value spaces. 
02 Salary-out pic 9(4) v 9(2).
02 Filler pic x(10) value spaces. 
02 Marital-Status-out pic x.
02 Filler pic x(10) value spaces.
02 Dependents-out pic 9.
02 Filler pic x(10) value spaces.
02 Age-out pic 9(3).
02 Filler pic x(24) value spaces. 

*trying to describe the what the footer will look like. There is supposed to be a counter to replace xx.
01 Report-footer.
02 Filler pic x(51) value spaces.
02 filler pic x(31) value "Number of Records Processed: xx". 
02 Filler pic x(50) value spaces. 

*supposed to be the switch to end program later on. 
01 eof-flag pic x(3) value "no".


Procedure Division. 

*the main logic program tells what has to be done in what order. 
0000-main-logic. 
Perform 1000-init.
Perform 2000-main-loop until eof-flag = "yes".
Perform 3000-finsish. 
Stop Run.

*This is going to open the files and print the header. 
1000-init. 
Open input input-file output output-file. 
Write output-rec from report-header. 
Read input-file at end move "yes" to eof-flag. 

*this moves the info from the input file into the output file variables...(i guess). 
*this makes a loop with the switch so it will do this for every line of data.
2000-main-loop.
move last-name to last-name-out.
move first-name to first-name-out.
move ssn to ssn-out.
move salary to salary-out.
move marital-status to marital-status-out.
move dependents to dependents-out.
move age to age-out. 
write output-rec from info-line.
read input-file at end move "yes" to eof-flag. 

*this makes it so that the footer is written and then leads to the end of the program. 
3000-finish.
write output-rec from report-footer. 
close input-file output-file.


----------



## jonathan731 (Aug 30, 2003)

I added "-test" to the end of the output-rec variables since they are supposed to be unique.


----------



## Chicon (Jul 29, 2004)

Hi jonathan731,

In COBOL, you may have non-unique name variables, example :

```
[SIZE=2]
       01  INPUT_RECORD.
           02 NAME           PIC X(50).
           02 CARD_NUMBER    PIC 9(16).
       01  OUTPUT_RECORD.
           02 NAME           PIC X(50).
           02 ADDRESS        PIC X(200).
           02 CARD_NUMBER    PIC 9(16).
...
...
       PROCEDURE DIVISION.
...
...
           MOVE NAME OF INPUT_RECORD     TO NAME OF OUTPUT_RECORD
           MOVE CARD_NUMBER OF INPUT_RECORD 
                                         TO CARD_NUMBER OF OUTPUT_RECORD
      * the following statement does the same thing as the two previous ones
           MOVE CORRESPONDING INPUT_RECORD TO OUTPUT_RECORD
[/SIZE]
```
Also, some COBOL versions need the *LABEL RECORD STANDARD* in the FD declaration, example :

```
[SIZE=2]
       FD  OUTPUT_FILE
           RECORD CONTAINS 266 CHARACTERS
           DATA RECORD IS OUTPUT_RECORD
           LABEL RECORD STANDARD.
       01  OUTPUT_RECORD.
           02 NAME           PIC X(50).
           02 ADDRESS        PIC X(200).
           02 CARD_NUMBER    PIC 9(16).
[/SIZE]
```


----------



## jonathan731 (Aug 30, 2003)

okay so if i change that it will rid the errors. However chicon i couldnt understand the first example I dont really know what you mean for me to change. thanks for the assistance


----------



## stantley (May 22, 2005)

When you compile a COBOL program and there are errors, it produces an error listing. Post the error listing.


----------



## jonathan731 (Aug 30, 2003)

i feel like the entire program is an error. 
but im not good at interpreting what the error wants me to fix.

1 *Jonathan Garcia, 000-846-100.
* 143-S* ( 0)**
** Unknown IDENTIFICATION DIVISION paragraph
2 *This program is meant to organize the file employee.dat.
*1013-E**************************************************** ( 1)**
** SECTION missing or misspelled. SECTION assumed.
* 71-S******************************************************** ( 1)**
** PROCEDURE DIVISION missing or unknown statement
4 Identification Division.
* 331-S*************** ( 1)**
** Program is nested - must compile with NESTCALL directive
12 Select input-file assign to "/home1/c/a/acsi203/company.dat"
*1004-E****************************************************************( 1)**
** Continuation character expected. End of literal assumed.
27 02 Filler pix x(6).
* 233-S**************************** ( 1)**
** Unknown data description qualifier PIX
28 02 Salary pic 9(4) v 9(2).
* 233-S*********************************** ( 1)**
** Unknown data description qualifier V
42 02 Salary pic 9(4) v 9(2).
* 233-S*********************************** ( 1)**
** Unknown data description qualifier V
53 02 Filler pic x(42) value "University Textile Company - Employee L
*1004-E****************************************************************( 1)**
** Continuation character expected. End of literal assumed.
54 02 Filler pix x(45) value spaces.
*1014-E********* ( 2)**
** Period missing. Period assumed.
* 233-S******************** ( 2)**
** Unknown data description qualifier PIX
64 02 Salary-out pic 9(4) v 9(2).
* 233-S*************************************** ( 2)**
** Unknown data description qualifier V
69 02 Filler pix x(10) value spaces.
* 233-S******************************** ( 2)**
** Unknown data description qualifier PIX
76 02 filler pic x(31) value "Number of Records Processed: xx".
*1004-E****************************************************************( 2)**
** Continuation character expected. End of literal assumed.
77 02 Filler pic x(50) value spaces.
*1014-E********* ( 2)**
** Period missing. Period assumed.
96 move last-name to last-name-out.
* 5-S********************* ( 2)**
** User-name LAST-NAME not unique
97 move first-name to first-name-out.
* 5-S********************** ( 3)**
** User-name FIRST-NAME not unique
98 move ssn to ssn-out.
* 5-S*************** ( 3)**
** User-name SSN not unique
99 move salary to salary-out.
* 12-S****************** ( 3)**
** Operand SALARY is not declared
100 move marital-status to marital-status-out.
* 5-S************************** ( 3)**
** User-name MARITAL-STATUS not unique
101 move dependents to dependents-out.
* 5-S********************** ( 3)**
** User-name DEPENDENTS not unique
102 move age to age-out.
* 5-S*************** ( 3)**
** User-name AGE not unique
108 close input-file output-file.
* 795-S ( 3)**
** END PROGRAM ; missing.


----------



## stantley (May 22, 2005)

Take the comments out before the Identification Division. In fact to make life easier I'd take out all comments until you get a clean compile and then put them back in.

Both select statements need periods at the end. 

Change 9(4) v 9(2) to 9(4)V9(2) no spaces.

Salary out should be 9(4).9(2)

To make life easier make the field names on the input file different than the output file.

Check to make sure everything ends with a period.

Put an END PROGRAM at the end.

Compile it again and try working through the errors.


----------



## jonathan731 (Aug 30, 2003)

i fixed all of the errors and still i get errors. and im not missing any period anywhere!

9 Select input-file assign to "/home1/c/a/acsi203/company.dat"
*1004-E****************************************************************( 0)**
** Continuation character expected. End of literal assumed.
50 02 Filler pic x(42) value "University Textile Company - Employee L
*1004-E****************************************************************( 1)**
** Continuation character expected. End of literal assumed.
51 02 Filler pic x(45) value spaces.
*1014-E********* ( 1)**
** Period missing. Period assumed.
73 02 filler pic x(31) value "Number of Records Processed: xx".
*1004-E****************************************************************( 1)**
** Continuation character expected. End of literal assumed.
74 02 Filler pic x(50) value spaces.
*1014-E********* ( 2)**
** Period missing. Period assumed.
107 End Program.
* 613-S************* ( 2)**
** Invalid program name
*1014-E ( 3)**
** Period missing. Period assumed.


----------



## stantley (May 22, 2005)

There's a limit on how long a line of source code can be, so break longer lines into two.

Like this:

02 Filler pic x(42) value "University Textile Company - Employee L

02 Filler pic x(42)
value "University Textile Company - Employee List".

In the first line you hit the limit and it chopped off ist". so that's why you got a period missing error.


----------



## jonathan731 (Aug 30, 2003)

thanks alot I was actually able to fix everthing...for a simple language as it seems, it got really complicated to write. THanks alot for the help.


----------

