Can you please review my homework?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Can you please review my homework?

Postby jaanu » Mon Oct 01, 2012 10:22 pm

Hi Friends,

I am a student, preparing for campus and doing assignment for campus. Please help me on this question. Following is my question.

Write a program to summarize acceidental records to obtain the following information:
A) The percentage of drivers under 25
B) The percentage of drivers who are female
C) The percentage of drivers from New York

There is one disk of record for each driver involved in accident in past year
1-4 Driver number
5-6 State Code(01 for New York)
7-12 Birth date(mmyyyy)
13 sex(M for male, F for female)

Results should be displayed on a screen as follows:
% of drivers under 25 99.99 who are female inm mexico
% of drivers greater 47 who are male 99.99 in New York
% of drivers from New York 99.99 who are under 25
-------------------------

And this is the program i have wrote: Please review and debug it and let me know the same. Please help me on this.

IDENTIFICATION DIVISION.
PROGRAM-ID. ACCREC.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
   SELECT AR ASSIGN TO DISK
   ORGANIZATION IS LINE SEQUENTIAL.
   SELECT OAR ASSIGN TO DISK
   ORGANIZATION IS LINE SEQUENTIAL.   
   DATA DIVISION.
   FILE SECTION.
FD AR
   LABEL RECORDS ARE STANDARD
   VALUE OF FILE-ID "AA.DAT".
01 ARREC.
   02 DRIVERNUMBER PIC 9(4).
   02 STATECODE PIC 9(2).
   02 CURYEAR PIC 9(4).
    02 BIRTHYEAR PIC 9(4).
   02 SEX PIC X(1).
   02 N PIC 9(1).
FD OAR
   LABEL RECORDS ARE STANDARD
   VALUE OF FILE-ID "OAA.DAT".
01 OARREC PIC X(80).
WORKING-STORAGE SECTION.
01 AGE PIC 9(2).
01 I PIC 9(2).
01 COUNTONE 9(1).
01 PERCENTONE 9(2).V99.
01 COUNTTWO 9(1).
01 PERCENTTWO 9(2).V99.
01 COUNTTHREE 9(1).
01 PERCENTTHREE 9(2).V99.
01 H1.
   02 F PIC X(25) VALUE SPACES.
   02 F PIC X(30) VALUE "ACCIDENTAL RECORDS".
01 H2.
   02 F PIC X(80) VALUE SPACES.
01 H3.
   02 F PIC X(25) VALUE SPACES.
   02 F PIC X(35) VALUE "% OF DRIVERS UNDER 25" 99.99 "WHO ARE FEMALE IN MEXICO".
   02 F PIC X(25) VALUE SPACES.
   02 F PIC X(35) VALUE "% OF DRIVERS GREATER THAN 47 WHO ARE MALE" 99.99 "IN NEWYORK".
   02 F PIC X(25) VALUE SPACES.
   02 F PIC X(35) VALUE "% OF DRIVERS FROM NEWYORK" 99.99 "WHO ARE UNDER 25".
01 H4.
   02 F PIC X(25) VALUE SPACES.
   02 OCOUNTONE Z(1).
   02 OPERCENTONE Z(2).ZZ.
   02 OCOUNTTWO Z(1).
   02 OPERCENTTWO Z(2).ZZ.
   02 OCOUNTONE Z(1).
   02 OPERCENTTHREE Z(2).ZZ.
PROCEDURE DIVISION.
P1.
   OPEN INPUT AR TO OUTPUT OAR.
P2.
   WRITE OAREC FROM H1.
   WRITE OAREC FROM H2.
   WRITE OAREC FROM H3.
   WRITE OAREC FROM H4.
   WRITE OAREC FROM H2.
P3.
   READ AR AT END GO TO P6.
P4.
   COMPUTE AGE = CURYEAR - BIRTHYEAR.
P5.
   ACCEPT COUNTONE = 0.
   PERFORM P6 VARYING I FROM 1 BY 1 UNTIL I < N
   IF ( AGE < 25 AND SEX = = ' F ' AND STATECODE = 02 )
   COMPUTE I = I + 1.
P6.
    COMPUTE PERCENTONE = ( COUNTONE / N ) * 100.
   
P7.
   ACCEPT COUNTTWO= 0.
   PERFORM P8 VARYING I FROM 1 BY 1 UNTIL I < N
    IF ( AGE > 47 AND SEX = ' M ' AND STATECODE = 01 )
   COMPUTE I = I + 1.
P8.
    COMPUTE PERCENTTWO = ( COUNTTWO / N ) * 100.
P9.
   ACCEPT COUNTTHREE = 0.
   PERFORM P6 VARYING I FROM 1 BY 1 UNTIL I < N
   IF ( AGE < 25 AND STATECODE= 01 )
   COMPUTE I = I + 1.
P10.
    COMPUTE PERCENTTHREE = ( COUNTTHREE / N ) * 100.
   WRITE OARREC FROM H3.
P11.   
   WRITE OARREC FROM H2.
   CLOSE AR OAR.
   STOP RUN.
jaanu
 
Posts: 1
Joined: Mon Oct 01, 2012 10:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Can you please review my homework?

 

Re: Can you please review my homework?

Postby NicC » Mon Oct 01, 2012 10:37 pm

Welcome to the forum! As with any forums you should read the rules first.
I have done the following:
    split your post away from an old topic
    Split your topic away from an irrelevant topic
    'coded' your code so that it is more readable - spacing preserved
    Moved your topic to a more relevant section. You can raise a new topic in Abends and Debugging once you have your program running (assuming it has problems that you cannot resolve by looking up the manuals).
Why can you not try compiling your code at your college? It is much quicker, and thorough, than trying to desk-check it and I doubt if anyone will try an in-depth review.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Can you please review my homework?

Postby steve-myers » Mon Oct 01, 2012 10:41 pm

We are not here to "desk check" (the common term for the activity you requested) programs. This was common 50 or 60 years ago when most people were lucky to get one "turnaround" (the most common term used to describe the process of submitting a job and obtaining its output) a day. Desk checking was done by the programmer, often assisted by colleagues. to fill in the time waiting for turnarounds. Tools like TSO and fast turnarounds were visions of the future for most of us. Now you can submit the program and analyze the output quite quickly, and desk checking is a lost (or at least forgotten) art.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Can you please review my homework?

Postby enrico-sorichetti » Mon Oct 01, 2012 11:00 pm

I do not speak too much cobolese, but

...
   VALUE OF FILE-ID "AA.DAT".
...
   VALUE OF FILE-ID "OAA.DAT".
...
   OPEN INPUT AR TO OUTPUT OAR.
...
   ACCEPT COUNTONE = 0.


do not look like valid <IBM> COBOL constructs
some kind of PC COBOL variant ?

( the TO in the OPEN statement could be a typo )
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Can you please review my homework?

Postby Robert Sample » Tue Oct 02, 2012 6:21 am

First, this is a MAINFRAME forum. You are not writing mainframe COBOL -- you are using some variant that is not running on a mainframe. You might be better finding a COBOL forum instead of a mainframe forum.

Second, since this is a mainframe forum, you should know that on mainframes using 02 F repeatedly as you do is not valid syntax -- F is not an abbreviation for FILLER on the mainframe, and it must either be spelled as FILLER or not be there at all. This may be valid on whatever variation of COBOL you are using, but I doubt it.

Third, constructs such as
   PERFORM P8 VARYING I FROM 1 BY 1 UNTIL I < N
    IF ( AGE > 47 AND SEX = ' M ' AND STATECODE = 01 )
   COMPUTE I = I + 1.
shows a number of basic problems:
1) P8 never references I, so why do the PERFORM?
2) N is not defined
3) If N is defined and is > 1, the PERFORM statement terminates very quickly since 1 will be less than N
4) Why are you using I as a loop index as well as a counter? Basic programming 101: define a variable for each purpose and use each variable only for one purpose. You are not going to be able to run out of them, and mixing uses confuses what you want to do with them.
5) Since SEX is defined as a one-byte variable, why are you comparing it to 3-byte literals? The comparisons will never be true.

Why so many paragraphs? You should only define a paragraph when you need one, and the problem statement you have presented can be solved in COBOL (at least on the mainframe) with no paragraphs required.
88 levels for the states instead of using codes would clarify the values and allow them to be easily changed if required.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times


Return to IBM Cobol