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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With 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

 
Hi bluedemus,

1. You need the opposite MOVE direction.
From EMPLOYEE-RECORD to EMPLOYEE-LINE:
MOVE ER-... TO EL-...

2. As you need to print 2 "records" per line, you need to read the file twice for each print line:
READ EMPLOYEE-FILE
Fill in the first portion of the print line
READ EMPLOYEE-FILE
Fill in the second portion of the print line
WRITE PRINT-AREA

Dimandja
 
OOPs...I retyped the code backwards....I did move ER- to EL-in my program for compile. The problem was: I couldn't figure out the format to do 2 Reads to write both lines.
 

WOULD THIS BE CORRECT????




100-PREPARE-EMPLOYEE-LINES.
000891 READ EMPLOYEE-FILE
000892 AT END
00089 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
READ EMPLOYEE-FILE
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
 
Yes. Except, you still must check for errors/EOF after each READ.
 
Your logic should look something like this:

READ EMPLOYEE-FILE
AT END
MOVE "YES" TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO "NO "
<move data>
READ EMPLOYEE-FILE
AT END
MOVE &quot;YES&quot; TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
<move data>
END-IF
WRITE PRINT-AREA
END-IF.
 
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 &quot;C:\INPUT.DAT&quot;
ORGANIZATION IS LINE SEQUENTIAL.
SELECT EMPLOYEE-LIST
ASSIGN TO &quot;C:\OUTPUT.RPT&quot;
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 &quot;LAST NAME &quot;.
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE &quot;FIRST NAM&quot;.
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE &quot;EXT&quot;.
05 FILLER PIC X(3) VALUE SPACE.
05 FILLER PIC X(11) VALUE &quot;LAST NAME &quot;.
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE &quot;FIRST NAM&quot;.
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE &quot;EXT&quot;.

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 &quot;NO &quot; TO SW-EOF-SWITCH
PERFORM 100-PRINT-COL-LINES
PERFORM 200-PREPARE-EMPLOYEE-LINES
UNTIL SW-EOF-SWITCH IS EQUAL TO &quot;YES&quot;
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 &quot;YES&quot; TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
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 &quot;YES&quot; TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
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.
 
Ask yourself, &quot;How will this condition ever be true?&quot;
Code:
     IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
Tom Morrison
 
Hi BD,

Just some advice from an an old timer. I guess I should say Sonny or something. :)

I know you're just beginning, BD, and probably just want to get past this thing. But, it's a good time to put down your coding pad and think about pgm design.

Think about the problem: you've got to get data from 2 records of input to write 1 record of output. What happens when you have an odd number or i/p recs?

Should you be handeling this in the main loop? Or is it better handled in an i/o routine?

What if you did your 1st read outside of the loop and read the next recs after you process the previous rec? All of that EOF stuff can go into the i/o routine where it belongs.

Should you do both reads back-to-back or read/process/read/ process? Which is less confusing?

Try a combo of flowcharting and pseudo code to try out ideas before you get all tangled up in the code. The code should present an idea clearly and concisely and strive to
enlighten rather than obscure. (Sounds like I'm talking about a novel. That may not be too far off the mark.)

Computer programs (COBOL pgms, in particular) are unique, in that they are tools used to solve problems and also serve as their own maintenance manuals.

So it's important to make sure that the code tells the story
of the solution as well as providing a solution.

OK, OK, end of rant. Hope this helps, BD.

Regards, Jack.
 
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
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
[red]This MOVE is too early; wait for the next READ[/red]
READ EMPLOYEE-FILE
AT END
MOVE &quot;YES&quot; TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
MOVE SPACES TO EMPLOYEE-LINE
[red]This line will wipe out what was already in EMPLOYEE-LINE[/red]

Follow your logic one small step at a time; it will all make sense.

Dimandja
 
Why does BD have to read the file twice for each write? Looking at the I/P rec descr, it looks like each I/P rec contains 2 sets of names. In that case only 1 read per is required.

If, on the other hand, the data for the print line is contained in 2 successive I/P recs, then the record descr is wrong. It should only contain 1 set of names. N'est ce pas?

Or am I missing something? Wouldn't be the 1st time.

Jack
 
Oui, I think you are right, Jack.

But, what threw me off is the following:
1. EMPL-NUM & MIDDLE-INIT & ADDRESS happen only once.
2. The apparent second last name only has 7 chars.

So, bluedemus, could you clarify what this record layout means?
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).
 
I have to have 2 sets of names in order to print two first names, two last names, and two extentions on each line printed on my report ...output should look like this.............
Last Name First nam Ext Last Name First nam Ext

Auston Bob 4566Alford John 3333
and so on
 
OK I see an error on my old program, but that has been long fixed....below is my program and my output..I'm only getting 1 row of info and losing the second one somewhere.....It skips over the second row without printing it....

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 &quot;C:\INPUT.DAT&quot;
ORGANIZATION IS LINE SEQUENTIAL.
SELECT EMPLOYEE-LIST
ASSIGN TO &quot;C:\OUTPUT.RPT&quot;
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 &quot;LAST NAM&quot;.
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE &quot;FIRST NAM&quot;.
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE &quot;EXT&quot;.
05 FILLER PIC X(3) VALUE SPACE.
05 FILLER PIC X(11) VALUE &quot;LAST NAME &quot;.
05 FILLER PIC X VALUE SPACE.
05 FILLER PIC X(9) VALUE &quot;FIRST NAM&quot;.
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(3) VALUE &quot;EXT&quot;.

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 &quot;NO &quot; TO SW-EOF-SWITCH
PERFORM 100-PRINT-COLUMN-LINES
PERFORM 200-PRINT-EMPLOYEE-REPORT
UNTIL SW-EOF-SWITCH IS EQUAL TO &quot;YES&quot;
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 &quot;YES&quot; TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
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 &quot;YES&quot; TO SW-EOF-SWITCH
END-READ
IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
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.



 
And I guess my main question is...what should I change to print both columns of my report, since I am only getting one?????
 
Hi BD,

The key to a solution for your problem is knowing what your input looks like. Can yoou tell us the length of the input recs, how many input recs do you have? Can you show us 2 or 3 of them?

BTW, your code looks fine if each input rec contains only 1 set of emp info (except for the input rec definition). So, I suspect that each of your input recs contains info for 2 emp. That would explain why you don't print data in the R.H. segment of your print line.

Regards, Jack.
 
Hi BD,

Disregard the last pgraph of my previous reply.

The problem, I think, is that you should be using the same input field names after the 2nd read as you used after the 1st read. Apparently each input rec contains only 1 set of emp info.

Jack
 
Hi bluedemus,

Specifying an input record that holds multiple &quot;unrelated&quot; groups of data is not the best way to solve your problem. Try not to manipulate the input in order to fix an output problem. Suppose you need to print three columns instead of two?

I suspect that your 'requirements' call for each input record to hold data for only one EMPLOYEE each. And the outpout requirement is to print two columns of information.

The logic that is now in your PROCEDURE DIVISION will do this, if each input record has information for only one EMPLOYEE.

This is the 'corrected' code:

Code:
 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). 

 200-PRINT-EMPLOYEE-REPORT. 
     READ EMPLOYEE-FILE
      AT END 
        MOVE &quot;YES&quot; TO SW-EOF-SWITCH
     END-READ
     IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
        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 &quot;YES&quot; TO SW-EOF-SWITCH
        END-READ
        IF SW-EOF-SWITCH IS EQUAL TO &quot;NO &quot;
           MOVE ER-LNAME      TO EL-LASTN
           MOVE ER-FNAME      TO EL-FIRSTN
           MOVE ER-EXTENTION  TO EL-EXTN
           MOVE EMPLOYEE-LINE TO PRINT-AREA
        END-IF
        WRITE PRINT-AREA
          AFTER ADVANCING 2 LINES
      END-IF.

Dimandja
 
Dimandja And Slade
Thank-You...I understand...And I am so happy...That is sort of what I was thinking, but I was making it harder than it is.....!!!!!
I feel like I started the first COBOL war online...grin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top