2 Replies - 7776 Views - Last Post: 27 November 2007 - 07:26 PM Rate Topic: -----

#1 karadawn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-July 06

COBOL table & subscript help

Posted 13 November 2006 - 03:48 PM

I know this is a very outdated language, but it's a core requirement and I'm lost. Teacher is of very little help. :angry:

The program is suppose to put out a list of scores, with an average at the bottom. The average is all of the scores, minus the lowest score. Then it's suppose to say at the bottom which test number was taken out.

I can't even get the program to compile, and I know there is some missing parts of the code. But I just need some help with setting up the subscripts, searching the table, and outputting the right thing. Below is the code I have so far, any help would be very appreciated!!

	   IDENTIFICATION DIVISION.
	   PROGRAM-ID.	 SCORES.
	   AUTHOR.		 KARA KELSO.

	   ENVIRONMENT DIVISION.
	   INPUT-OUTPUT SECTION.
	   FILE-CONTROL.
		   SELECT STUDENT-FILE ASSIGN TO 'C:\SCORES.DAT'
			   ORGANIZATION IS LINE SEQUENTIAL.
		   SELECT PRINT-FILE
			   ASSIGN TO 'C:\SCORES.TXT'.

	   DATA DIVISION.
	   FILE SECTION.
	   FD STUDENT-FILE
		   RECORD CONTAINS 69 CHARACTERS.
	   01 STUDENT-RECORD.
		   05 STUDENT-NUM				  PIC X(9).
		   05 TEST-SCORES OCCURS 20 TIMES  PIC 9(3).


	   FD PRINT-FILE
		   RECORD CONTAINS 132 CHARACTERS.
	   01 PRINT-LINE   PIC X(132).

	   WORKING-STORAGE SECTION.
	   01 DATA-REMAINS-SWITCH   PIC X(2)  VALUE SPACES.

	   01 SUBSCRIPTS		   COMP.
		   05 SCORE-SUB		PIC S9(4).
		   05 SAVE-SUB		 PIC S9(4).

	   01 FIRST-HEADER.
		   05 FILLER			PIC X(7) VALUE SPACES.
		   05 FILLER			PIC X(26) VALUE
		   'PROFESSOR JONES  REPORT TO'.
		   05 FILLER			PIC X VALUE SPACE.
		   05 STUDENT-NUM	   PIC 999B99B9999.
		   05 FILLER			PIC X(7) VALUE SPACES.
		   05 FILLER			PIC X(4) VALUE 'PAGE'.
		   05 FILLER			PIC X VALUE SPACE.
		   05 PAGE-NO		   PIC X(2).
		   05 FILLER			PIC X(73) VALUE SPACES.

	   01 SECOND-HEADER.
		   05 FILLER		   PIC X(19) VALUE SPACES.
		   05 FILLER		   PIC X(11) VALUE 'TEST SCORES'.
		   05 FILLER		   PIC X(102) VALUE SPACES.

	   01 DETAIL-LINE.
		   05 FILLER		   PIC X(21) VALUE SPACES.
		   05 TEST-NUM		 PIC Z9.
		   05 FILLER		   PIC XBX VALUE SPACES.
		   05 TEST-SCORES	  PIC ZZ9.
		   05 FILLER		   PIC X(103) VALUE SPACES.

	   01 SUBSCRIPTS		   COMP.
		   05 SCORE-SUB		PIC S9(4).
		   05 SAVE-SUB		 PIC S9(4).

	   01 AVERAGE-LINE.
		   05 FILLER		   PIC X(7) VALUE SPACES.
		   05 FILLER		   PIC X(18) VALUE 'TEST SCORE AVERAGE'.
		   05 FILLER		   PIC X VALUE SPACE.
		   05 AVERAGE-SCORE	PIC ZZ9.9.

	   01 FOOTER-LINE.
		   05 FILLER		   PIC X VALUE SPACE.
		   05 FILLER		   PIC X(27)
			   VALUE '*** NOTE: TEST SCORE NUMBER'.
		   05 LOWEST-SCORE	 PIC Z9.
		   05 FILLER		   PIC X.
		   05 FILLER		   PIC X(23)
			   VALUE 'NOT INCLUDED IN AVERAGE'.
		   05 FILLER		   PIC X(78) VALUE SPACES.

	   PROCEDURE DIVISION.
	   100-PROCESS-STUDENT-RECORDS.
		   OPEN INPUT STUDENT-FILE
			   OUTPUT PRINT-FILE.
		   PERFORM UNTIL DATA-REMAINS-SWITCH = 'YES'
			   READ STUDENT-FILE
				   AT END
					   MOVE 'YES' TO DATA-REMAINS-SWITCH
				   NOT AT END
					   PERFORM 200-CREATE-REPORT
			   END-READ
		   END-PERFORM.

		   CLOSE   STUDENT-FILE
				   PRINT-FILE.
		   STOP RUN.

	   200-CREATE-REPORT.
		   PERFORM 210-WRITE-HEADINGS.
		   PERFORM 220-WRITE-SCORES.
		   PERFORM 230-CALCULATE-AVERAGE.
		   PERFORM 240-WRITE-FOOTER.

	   210-WRITE-HEADINGS.
		   MOVE FIRST-HEADER TO PRINT-LINE.
		   WRITE PRINT-LINE.
		   MOVE SECOND-HEADER TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 2 LINES.

	   220-WRITE-SCORES.
		   PERFORM 225-INCREMENT-AVERAGE
			   VARYING SCORE-SUB FROM 1 BY 1
				   UNTIL SCORE-SUB > 20.
		   MOVE DETAIL-LINE TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 1 LINE.

	   225-INCREMENT-AVERAGE.
		   ADD SCORES (SCORE-SUB) TO SCORES.
		   MOVE SCORES TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 1 LINE.

	   230-CALCULATE-AVERAGE.
		   COMPUTE AVERAGE-SCORE =
			   ADD SCORES (SCORE-SUB)
			   AVERAGE-SCORE / 19
		   END-COMPUTE.

	   240-WRITE-FOOTER.
		   MOVE FOOTER-LINE TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 1 LINE.




Is This A Good Question/Topic? 0
  • +

Replies To: COBOL table & subscript help

#2 peter.feyen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-July 07

Re: COBOL table & subscript help

Posted 06 July 2007 - 03:32 PM

View Postkaradawn, on 13 Nov, 2006 - 03:48 PM, said:

I know this is a very outdated language, but it's a core requirement and I'm lost. Teacher is of very little help. :angry:

The program is suppose to put out a list of scores, with an average at the bottom. The average is all of the scores, minus the lowest score. Then it's suppose to say at the bottom which test number was taken out.

I can't even get the program to compile, and I know there is some missing parts of the code. But I just need some help with setting up the subscripts, searching the table, and outputting the right thing. Below is the code I have so far, any help would be very appreciated!!

	   IDENTIFICATION DIVISION.
	   PROGRAM-ID.	 SCORES.
	   AUTHOR.		 KARA KELSO.

	   ENVIRONMENT DIVISION.
	   INPUT-OUTPUT SECTION.
	   FILE-CONTROL.
		   SELECT STUDENT-FILE ASSIGN TO 'C:\SCORES.DAT'
			   ORGANIZATION IS LINE SEQUENTIAL.
		   SELECT PRINT-FILE
			   ASSIGN TO 'C:\SCORES.TXT'.

	   DATA DIVISION.
	   FILE SECTION.
	   FD STUDENT-FILE
		   RECORD CONTAINS 69 CHARACTERS.
	   01 STUDENT-RECORD.
		   05 STUDENT-NUM				  PIC X(9).
		   05 TEST-SCORES OCCURS 20 TIMES  PIC 9(3).


	   FD PRINT-FILE
		   RECORD CONTAINS 132 CHARACTERS.
	   01 PRINT-LINE   PIC X(132).

	   WORKING-STORAGE SECTION.
	   01 DATA-REMAINS-SWITCH   PIC X(2)  VALUE SPACES.

	   01 SUBSCRIPTS		   COMP.
		   05 SCORE-SUB		PIC S9(4).
		   05 SAVE-SUB		 PIC S9(4).

	   01 FIRST-HEADER.
		   05 FILLER			PIC X(7) VALUE SPACES.
		   05 FILLER			PIC X(26) VALUE
		   'PROFESSOR JONES  REPORT TO'.
		   05 FILLER			PIC X VALUE SPACE.
		   05 STUDENT-NUM	   PIC 999B99B9999.
		   05 FILLER			PIC X(7) VALUE SPACES.
		   05 FILLER			PIC X(4) VALUE 'PAGE'.
		   05 FILLER			PIC X VALUE SPACE.
		   05 PAGE-NO		   PIC X(2).
		   05 FILLER			PIC X(73) VALUE SPACES.

	   01 SECOND-HEADER.
		   05 FILLER		   PIC X(19) VALUE SPACES.
		   05 FILLER		   PIC X(11) VALUE 'TEST SCORES'.
		   05 FILLER		   PIC X(102) VALUE SPACES.

	   01 DETAIL-LINE.
		   05 FILLER		   PIC X(21) VALUE SPACES.
		   05 TEST-NUM		 PIC Z9.
		   05 FILLER		   PIC XBX VALUE SPACES.
		   05 TEST-SCORES	  PIC ZZ9.
		   05 FILLER		   PIC X(103) VALUE SPACES.

	   01 SUBSCRIPTS		   COMP.
		   05 SCORE-SUB		PIC S9(4).
		   05 SAVE-SUB		 PIC S9(4).

	   01 AVERAGE-LINE.
		   05 FILLER		   PIC X(7) VALUE SPACES.
		   05 FILLER		   PIC X(18) VALUE 'TEST SCORE AVERAGE'.
		   05 FILLER		   PIC X VALUE SPACE.
		   05 AVERAGE-SCORE	PIC ZZ9.9.

	   01 FOOTER-LINE.
		   05 FILLER		   PIC X VALUE SPACE.
		   05 FILLER		   PIC X(27)
			   VALUE '*** NOTE: TEST SCORE NUMBER'.
		   05 LOWEST-SCORE	 PIC Z9.
		   05 FILLER		   PIC X.
		   05 FILLER		   PIC X(23)
			   VALUE 'NOT INCLUDED IN AVERAGE'.
		   05 FILLER		   PIC X(78) VALUE SPACES.

	   PROCEDURE DIVISION.
	   100-PROCESS-STUDENT-RECORDS.
		   OPEN INPUT STUDENT-FILE
			   OUTPUT PRINT-FILE.
		   PERFORM UNTIL DATA-REMAINS-SWITCH = 'YES'
			   READ STUDENT-FILE
				   AT END
					   MOVE 'YES' TO DATA-REMAINS-SWITCH
				   NOT AT END
					   PERFORM 200-CREATE-REPORT
			   END-READ
		   END-PERFORM.

		   CLOSE   STUDENT-FILE
				   PRINT-FILE.
		   STOP RUN.

	   200-CREATE-REPORT.
		   PERFORM 210-WRITE-HEADINGS.
		   PERFORM 220-WRITE-SCORES.
		   PERFORM 230-CALCULATE-AVERAGE.
		   PERFORM 240-WRITE-FOOTER.

	   210-WRITE-HEADINGS.
		   MOVE FIRST-HEADER TO PRINT-LINE.
		   WRITE PRINT-LINE.
		   MOVE SECOND-HEADER TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 2 LINES.

	   220-WRITE-SCORES.
		   PERFORM 225-INCREMENT-AVERAGE
			   VARYING SCORE-SUB FROM 1 BY 1
				   UNTIL SCORE-SUB > 20.
		   MOVE DETAIL-LINE TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 1 LINE.

	   225-INCREMENT-AVERAGE.
		   ADD SCORES (SCORE-SUB) TO SCORES.
		   MOVE SCORES TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 1 LINE.

	   230-CALCULATE-AVERAGE.
		   COMPUTE AVERAGE-SCORE =
			   ADD SCORES (SCORE-SUB)
			   AVERAGE-SCORE / 19
		   END-COMPUTE.

	   240-WRITE-FOOTER.
		   MOVE FOOTER-LINE TO PRINT-LINE.
		   WRITE PRINT-LINE
			   AFTER ADVANCING 1 LINE.




Hi your program has a good base but, the compute statement is wrong.
you should write
	   230-CALCULATE-AVERAGE.
		   COMPUTE AVERAGE-SCORE =
			   SCORES (SCORE-SUB) + 
			   AVERAGE-SCORE / 19
		   END-COMPUTE.


Was This Post Helpful? 0
  • +
  • -

#3 67Rambler  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-November 07

Re: COBOL table & subscript help

Posted 27 November 2007 - 07:26 PM

Hi.

The only problem I see with this is in the PERFORM VARYING FROM 1 BY 1 UNTIL ... > 20. This will be performed 20 times. That's fine, but the average is based on 19 scores. If these scores are recieved at random (98, 62, 85, 91...), the last score will alter the average. If every score is 10, the total is 200. If the total is divided by 20, the average score is 10; dividing by 19 = 10.526.

If you want to use 19 scores, you might want to try > 19 or NOT LESS THAN 20.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1