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 SkipVought 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
0
0
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,

I am happy that your problem is solved (and I am sure slade is too).

Note: You didn't start any war; you gave anyone interested, the opportunity to take a closer look at COBOL and at programming in general.

Dimandja
 
Hi BD,

Can you expand a bit on this?

I did lose print lines when assigning to printer


Jack
P.S. D is right, I'm glad too.
I hope you take my advice about pgm design. That's where the art lies (or is it "lays"; my COBOL syntax is better than my English) :).
 
One minor thing I think you guys didn't pick up on. What if there are an odd number of records on the input file?

I think "MOVE EMPLOYEE-LINE TO PRINT-AREA" should move outside of its immediate enclosing IF and immediately precede the WRITE.

3gm
 
Hi 3gm,

My point was that only 1 read is needed. I may not have made that clear. I'm not sure about how the input is configured. Is it 1 rec/1 set of emp data or is it 1 rec/2 sets of emp data?

In either case, only 1 read is reqed, unless BD duped (ugh)
each rec in the input stream.

Regards, jack.

 
3gm is right, "MOVE EMPLOYEE-LINE TO PRINT-AREA" should come just before the write as shown below. The input record was "corrected" as indicated (1 employee per record):

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 "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-LNAME      TO EL-LASTN
           MOVE ER-FNAME      TO EL-FIRSTN
           MOVE ER-EXTENTION  TO EL-EXTN
        END-IF
        MOVE EMPLOYEE-LINE TO PRINT-AREA
        WRITE PRINT-AREA
          AFTER ADVANCING 2 LINES
      END-IF.

Dimandja
 
Yeah, 3gm is right on. I don't know what the hey I was thinking.

I'd design it a little differently, though:
Code:
000-main. 
    perform 800-init 
    perform 700-get-the-data
    perform 100-print-a-line 
      until ip-eof
     .
100-print-a-line.
    if data-to-print
       move seg 1 data to lh side of print line
       move seg 2 data to rh side of print line
    end-if
    write line 
    perform 700-get-the-data
    .
700-get-the-data.
    read ip-rec into seg1      at end
         set ip-eof            to true
         set no-data-to-print  to true
     not at end
         set data-to-print     to true
         read ip-rec into seg2 at end
              set ip-eof       to true
              move spaces      to seg2
         end-read     
    end-read
    .
Though this is a simple pgm, and there's not much reason to take the read logic out of the print pgraph, it does simplify the main logic of printing the data. If the print process were more involved than it is, simplifying it would make it easier to read and therefore easier to debug or modify.

I also like the idea that the logic is compartmentalized: the read stuff is in the read pgraph; the print stuff is in the print pgraph.

Anyway, that's how I look at it.

Regards, Jack.
 
THANKS GUYS!
I figured it out...including what if I had an odd number of records....I'm working on a new one and I'm sure I will have questions........
 
Hi BD,

The code in 200-PRINT-EMPLOYEE-REPORT supports an odd number of input records.
 
slade -

I agree that pulling the read out of the main flow of the logic is probably a good thing. In many cases, you need to count the input records, maybe perform some editing or qualification of the records etc. Isolating the read is oftentimes the best approach.

I'm not sure I agree with your use of the "data-to-print" switch. It's totally extraneous as you've coded it (note that the only time it is set to false is at eof and you CANNOT enter 100-print-a-line if EOF is true).

Also, your code doesn't seem to work for the case of odd # of records either.

3gm
 
3gm,

Right again; you found a bug (yes, it's a bug; anything that confuses the reader, in my est, is a bug).

Thanx, Jack.
 
why dont you try loading a table with the output data then moving that table to the output line, do the sane with your headings and thats it. i have done this before and it works well for this type of thing.

hope it helps.
Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top