Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP WITH SIMPLE COBOL PROGRAM

Status
Not open for further replies.

bluedemus

Programmer
Sep 24, 2002
21
US
Can anyone help me with my program???
I'm trying write a report with col headings as:

last name first name ext last name first name ext

here is a copy of my program....This problem is in my Procedure division.......process-employee-lines....
My output is only printing 1 column of info..help....

000010 @OPTIONS MAIN
000020 IDENTIFICATION DIVISION.
000030 PROGRAM-ID. REPORT1.
000040* PROGRAMER: WENDY HANKS
000050* DATE WRITTEN: 9/06/2002
000060* DUE DATE: 9/26/2002
000070
000080* THIS PROGRAM PRINTS A REPORT
000090* WITH COLUMN HEADINGS WITH TWO
000100* RECORDS ON EACH LINE
000110
000120 ENVIRONMENT DIVISION.
000130
000140 CONFIGURATION SECTION.
000150 SOURCE-COMPUTER. IBM-PC.
000160 OBJECT-COMPUTER. IBM-PC.
000170
000180 INPUT-OUTPUT SECTION.
000190
000200 FILE-CONTROL.
000210 SELECT EMPLOYEE-FILE
000220 ASSIGN TO "C:\INPUT.DAT"
000230 ORGANIZATION IS LINE SEQUENTIAL.
000240 SELECT EMPLOYEE-LIST
000250 ASSIGN TO PRINTER.
000260
000270 DATA DIVISION.
000290
000300 FILE SECTION.
000310
000320 FD EMPLOYEE-FILE
000330 LABEL RECORDS ARE STANDARD.
000340
000350
000360 01 EMPLOYEE-RECORD.
000370 05 ER-EMPL-NUM PIC X(7).
000380 05 ER-LNAME PIC X(11).
000390 05 ER-FNAME PIC X(9).
000400 05 ER-MIDDLE-INT PIC X.
000410 05 ER-ADDRESS PIC X(46).
000420 05 ER-EXTENTION PIC X(4).
000421 05 ER-LASTN PIC X(7).
000422 05 ER-FIRSTN PIC X(9).
000423 05 ER-EXTN PIC X(4).
000431
000441
000451
000461 FD EMPLOYEE-LIST.
000511
000512 01 PRINT-AREA PIC X(68).
000522
000700 WORKING-STORAGE SECTION.
000710
000720 01 SWITCHES.
000730 05 SW-EOF-SWITCH PIC X(3).
000731
000732
000750 01 HEADING-LINE-1.
000751 05 FILLER PIC X(11) VALUE "LAST NAME ".
000752 05 FILLER PIC X VALUE SPACE.
000753 05 FILLER PIC X(9) VALUE "FIRST NAM".
000754 05 FILLER PIC X(3) VALUE SPACES.
000755 05 FILLER PIC X(3) VALUE "EXT".
000756 05 FILLER PIC X(3) VALUE SPACE.
000757 05 FILLER PIC X(11) VALUE "LAST NAME ".
000758 05 FILLER PIC X VALUE SPACE.
000759 05 FILLER PIC X(9) VALUE "FIRST NAM".
000760 05 FILLER PIC X(3) VALUE SPACES.
000761 05 FILLER PIC X(3) VALUE "EXT".
000762
000763 01 EMPLOYEE-LINE.
000765 05 EL-LNAME PIC X(11).
000775 05 FILLER PIC X.
000776 05 EL-FNAME PIC X(9).
000777 05 FILLER PIC X(3).
000778 05 EL-EXTENTION PIC X(4).
000779 05 FILLER PIC X.
000780 05 EL-LASTN PIC X(11).
000781 05 FILLER PIC X.
000782 05 EL-FIRSTN PIC X(9).
000783 05 FILLER PIC X(3).
000784 05 EL-EXTN PIC X(4).
000786
000787
000788 PROCEDURE DIVISION.
000789
000790 000-PREPARE-EMPLOYEE-REPORT.
000800 OPEN INPUT EMPLOYEE-FILE
000810 OUTPUT EMPLOYEE-LIST
000811 MOVE "NO " TO SW-EOF-SWITCH
000820 PERFORM 200-PRINT-HEADING-LINES
000821 PERFORM 100-PREPARE-EMPLOYEE-LINES
000822 UNTIL SW-EOF-SWITCH IS EQUAL TO "YES"
000823 CLOSE EMPLOYEE-FILE
000860 EMPLOYEE-LIST
000870 STOP RUN.
000880
000890 100-PREPARE-EMPLOYEE-LINES.
000891 READ EMPLOYEE-FILE
000892 AT END
000893 MOVE "YES" TO SW-EOF-SWITCH.
000894 IF SW-EOF-SWITCH IS EQUAL TO "NO "
000895 MOVE SPACES TO EMPLOYEE-LINE
000911 MOVE EL-LNAME TO ER-LNAME
MOVE EL-FNAME TO ER-FNAME
MOVE EL-EXTENTION TO ER-EXTENTION
MOVE EL-LASTN TO ER-LASTN
MOVE EL-FIRSTN TO ER-FIRSTN
MOVE EL-EXTN TO ER-EXTN
MOVE EMPLOYEE-LINE TO PRINT-AREA
000972 WRITE PRINT-AREA
000981 AFTER ADVANCING 2 LINES.
000991
001001
001003 200-PRINT-HEADING-LINES.
001011 MOVE HEADING-LINE-1 TO PRINT-AREA
001021 WRITE PRINT-AREA
001031 AFTER ADVANCING 2 LINES.
001041
001071
001081
001091
001101
001111
001121
001131
001141
001151
001161
001171
001181

 
Your program seem correct.
Check content on file EMPLOYEE-FILE.
Are there all data you expected ?
 
Please cross check the length of the respective fields in the input file with the record layout of the output file.
 
Actually...this is what I meant to post....
Now, I'm only getting an output report with my column headings??? I'm pulling my hair out now.....!!!





@OPTIONS MAIN
IDENTIFICATION DIVISION.
PROGRAM-ID. REPORT1.
* PROGRAMER:
* DATE WRITTEN:
*
* THIS PROGRAM PRINTS A REPORT
* WITH COLUMN HEADINGS WITH TWO
* RECORDS ON EACH LINE

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.

INPUT-OUTPUT SECTION.

FILE-CONTROL.
SELECT EMPLOYEE-FILE
ASSIGN TO "C:\INPUT.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT EMPLOYEE-LIST
ASSIGN TO "C:\OUTPUT.RPT"
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.

FILE SECTION.

FD EMPLOYEE-FILE
LABEL RECORDS ARE STANDARD.


01 EMPLOYEE-RECORD.
05 ER-EMPL-NUM PIC X(7).
05 ER-LNAME PIC X(11).
05 ER-FNAME PIC X(9).
05 ER-MIDDLE-INT PIC X.
05 ER-ADDRESS PIC X(46).
05 ER-EXTENTION PIC X(4).
05 ER-LASTN PIC X(7).
05 ER-FIRSTN PIC X(9).
05 ER-EXTN PIC X(4).



FD EMPLOYEE-LIST.

01 PRINT-AREA PIC X(68).

WORKING-STORAGE SECTION.

01 SWITCHES.
05 SW-EOF-SWITCH PIC X(3).


01 HEADING-LINE-1.
05 FILLER PIC X(11) VALUE "LAST NAME ".
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE "FIRST NAM".
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE "EXT".
05 FILLER PIC X(3) VALUE SPACE.
05 FILLER PIC X(11) VALUE "LAST NAME ".
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE "FIRST NAM".
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE "EXT".

01 EMPLOYEE-LINE.
05 EL-LNAME PIC X(11).
05 FILLER PIC X.
05 EL-FNAME PIC X(9).
05 FILLER PIC X(3).
05 EL-EXTENTION PIC X(4).
05 FILLER PIC X.
05 EL-LASTN PIC X(11).
05 FILLER PIC X.
05 EL-FIRSTN PIC X(9).
05 FILLER PIC X(3).
05 EL-EXTN PIC X(4).

PROCEDURE DIVISION.

000-PREPARE-EMPLOYEE-REPORT.
OPEN INPUT EMPLOYEE-FILE
OUTPUT EMPLOYEE-LIST
MOVE "NO " TO SW-EOF-SWITCH
PERFORM 100-PRINT-COL-LINES
PERFORM 200-PREPARE-EMPLOYEE-LINES
UNTIL SW-EOF-SWITCH IS EQUAL TO "YES"
CLOSE EMPLOYEE-FILE
EMPLOYEE-LIST
STOP RUN.

100-PRINT-COL-LINES.
MOVE HEADING-LINE-1 TO PRINT-AREA
WRITE PRINT-AREA
AFTER ADVANCING 2 LINES.

200-PREPARE-EMPLOYEE-LINES.
READ EMPLOYEE-FILE
AT END
MOVE "YES" TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO "NO "
MOVE SPACES TO EMPLOYEE-LINE
MOVE ER-LNAME TO EL-LNAME
MOVE ER-FNAME TO EL-FNAME
MOVE ER-EXTENTION TO EL-EXTENTION
MOVE EMPLOYEE-LINE TO PRINT-AREA
READ EMPLOYEE-FILE
AT END
MOVE "YES" TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO "NO "
MOVE SPACES TO EMPLOYEE-LINE
MOVE ER-LASTN TO EL-LASTN
MOVE ER-FIRSTN TO EL-FIRSTN
MOVE ER-EXTN TO EL-EXTN
MOVE EMPLOYEE-LINE TO PRINT-AREA
END-IF
WRITE PRINT-AREA
END-IF.

 
Well, try this (I posted only relevant paragraphs) :

000-PREPARE-EMPLOYEE-REPORT.
OPEN INPUT EMPLOYEE-FILE
OUTPUT EMPLOYEE-LIST.
MOVE "NO " TO SW-EOF-SWITCH.
PERFORM 100-PRINT-COL-LINES .
** the following two lines are changed !!
PERFORM 200-PREPARE-EMPLOYEE-LINES
THRU 200-PREPARE-EMPLOYEE-LINES-END.
************
CLOSE EMPLOYEE-FILE
EMPLOYEE-LIST.
STOP RUN.

** here there are many changes !!
200-PREPARE-EMPLOYEE-LINES.
READ EMPLOYEE-FILE AT END
GO 200-PREPARE-EMPLOYEE-LINES-END.
MOVE SPACES TO EMPLOYEE-LINE.
MOVE ER-LNAME TO EL-LNAME.
MOVE ER-FNAME TO EL-FNAME.
MOVE ER-EXTENTION TO EL-EXTENTION.
WRITE PRINT-AREA FROM EMPLOYEE-LINE.
READ EMPLOYEE-FILE AT END
GO 200-PREPARE-EMPLOYEE-LINES-END.
MOVE SPACES TO EMPLOYEE-LINE.
MOVE ER-LASTN TO EL-LASTN.
MOVE ER-FIRSTN TO EL-FIRSTN.
MOVE ER-EXTN TO EL-EXTN.
WRITE PRINT-AREA FROM EMPLOYEE-LINE.
GO 200-PREPARE-EMPLOYEE-LINES.
200-PREPARE-EMPLOYEE-LINES-END.

Again I ask you : are you sure that EMPLOYEE-FILE contain data and that data is correct ??
If the file contain data, there is no reason you can't print it.

 
erba,

Thank you for your help, but I can't use Go statements. this is the format of the output expected...

col headings are
Last Name First Nam Ext Last Name First Nam Ext

Aston bob 4554 Alford James 5566

 
OPTIONS MAIN
IDENTIFICATION DIVISION.
PROGRAM-ID. REPORT1.
* PROGRAMER:
* DATE WRITTEN:
*
* THIS PROGRAM PRINTS A REPORT
* WITH COLUMN HEADINGS WITH TWO
* RECORDS ON EACH LINE

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.

INPUT-OUTPUT SECTION.

FILE-CONTROL.
SELECT EMPLOYEE-FILE
ASSIGN TO "C:\INPUT.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT EMPLOYEE-LIST
ASSIGN TO "C:\OUTPUT.RPT"
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.

FILE SECTION.

FD EMPLOYEE-FILE
LABEL RECORDS ARE STANDARD.


01 EMPLOYEE-RECORD.
05 ER-EMPL-NUM PIC X(7).
05 ER-LNAME PIC X(11).
05 ER-FNAME PIC X(9).
05 ER-MIDDLE-INT PIC X.
05 ER-ADDRESS PIC X(46).
05 ER-EXTENTION PIC X(4).
05 ER-EMPLY-NUM PIC X(7).
05 ER-LASTN PIC X(11).
05 ER-FIRSTN PIC X(9).
05 ER-MID-INT PIC X.
05 ER-ADD PIC X(46).
05 ER-EXTN PIC X(4).

FD EMPLOYEE-LIST.

01 PRINT-AREA PIC X(68).

WORKING-STORAGE SECTION.

01 SWITCHES.
05 SW-EOF-SWITCH PIC X(3).


01 HEADING-LINE-1.
05 FILLER PIC X(11) VALUE "LAST NAME ".
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE "FIRST NAM".
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE "EXT".
05 FILLER PIC X(3) VALUE SPACE.
05 FILLER PIC X(11) VALUE "LAST NAME ".
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE "FIRST NAM".
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE "EXT".

01 EMPLOYEE-LINE.
05 EL-LNAME PIC X(11).
05 FILLER PIC X.
05 EL-FNAME PIC X(9).
05 FILLER PIC X(3).
05 EL-EXTENTION PIC X(4).
05 FILLER PIC X.
05 EL-LASTN PIC X(11).
05 FILLER PIC X.
05 EL-FIRSTN PIC X(9).
05 FILLER PIC X(3).
05 EL-EXTN PIC X(4).

PROCEDURE DIVISION.

000-PRINT-EMPLOYEE-LISTING.
OPEN INPUT EMPLOYEE-FILE
OUTPUT EMPLOYEE-LIST
MOVE "NO " TO SW-EOF-SWITCH
PERFORM 100-PRINT-COLUMN-LINES
PERFORM 200-PRINT-EMPLOYEE-REPORT
UNTIL SW-EOF-SWITCH IS EQUAL TO "YES"
CLOSE EMPLOYEE-FILE
EMPLOYEE-LIST
STOP RUN.


100-PRINT-COLUMN-LINES.
MOVE HEADING-LINE-1 TO PRINT-AREA
WRITE PRINT-AREA
AFTER ADVANCING 2 LINES.

200-PRINT-EMPLOYEE-REPORT.
READ EMPLOYEE-FILE
AT END
MOVE "YES" TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO "NO "
MOVE SPACES TO EMPLOYEE-LINE
MOVE ER-LNAME TO EL-LNAME
MOVE ER-FNAME TO EL-FNAME
MOVE ER-EXTENTION TO EL-EXTENTION
READ EMPLOYEE-FILE
AT END
MOVE "YES" TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO "NO "
MOVE ER-LASTN TO EL-LASTN
MOVE ER-FIRSTN TO EL-FIRSTN
MOVE ER-EXTN TO EL-EXTN
MOVE EMPLOYEE-LINE TO PRINT-AREA
END-IF
WRITE PRINT-AREA
AFTER ADVANCING 2 LINES
END-IF.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top