Implement IF statements in COBOL:

 

If you are taking this course in class or have access to the lab, I suggest you do the assignments in COBOL to get the experience of working with the language.  If you are exclusively distance learning, you have the choice of doing the assignment on paper or doing it in the lab.

The sample COBOL programs you will need to modify are pasted to the bottom of this sheet.

 

I have given you a series of COBOL programs (on disk if you are in the lab).  The programs read a COBOL file and display the results on the screen.  I want you to modify the programs with the IF statements that were done in this assignment.  You will find that the COBOL if statement closely parallels the pseudocode that you have written.  If you are a distance learning student, you may modify the programs in notepad or word and pass them in that way and I will correct them.

 

Employee File:

 

Characters

Field Name

Data

Allowed codes

Data Type

1-5

IDNO

Identification Number

 

Num

6-25

NAME

Name

 

Char

26-29

YRBTH

Year of Birth

 

Num

30

GEN

Gender

M, F, U

Char

31

MARSTAT

Marital Status

S, M, W, D, U

Char

32-33

NUMDEP

Number of Dependents

 

Num

34-36

ED

Education

NOH, HSC, GED, C2, C4, M, PHD

Char

37

JBCD

Job Code

S, F, P

Char

38-42

PAYHR

Pay per hour for full time and part time

 

Num (2 dec)

43 - 50

SAL

Salary

 

Num (2 dec)

51-55

BONUS

Bonus

 

Num

56-57

DEPT

Department

2 digit numeric

Num

58-59

STATE

State

2 char state code

Char

 

Sample data:  Note that on the disk this is a long string of data.  I have broken it up so that the records are easy to see.  Note that I have also put character positions to help you read the data.

 

                       11111111111122222222222223333333333334444444444444555555555555

12345678901234567890123456789012345678901234567890123456789

 

11111Michael Costa       1970MM03C2 S00000052000000600015MA

12121Susan Morse         1980FS01C2 S00000052000000000015RI

12345John Wilson         1975MM03GEDF03000000000000000015MA

12356Ann Johnson         1977FM06C2 S00000060000000600015NY

12567Lee Stuart          1980UU00C4 S00000035000000000014MA

20000Linda Costa         1956FM06C2 S00000060000000000008RI

21000James Allan         1981MM06C4 S00000065000000600016MA

21234Kevin Brooks        1956MS01M  F03500000000000000004MA

23456Stanley Souza       1981MD06C2 F02600000000000000010MA

24567Jane Trever         1982FM03C4 S00000045000000600016MA

27890Doris Tyler         1984FM06C2 S00000075000000600015MA

30000Peter Anders        1976MD01GEDP01875000000000000013RI

31234Al Richards         1956MS01M  S00000110000001000015MA

40000Susan Jenkins       1950FM06C2 S00000090000001000010RI

41111Ann Lynch           1989FS01C4 F05000000000000550017MA

54321David Lee           1987MS01C2 F03000000000000000008MA

Problem #1: Print or display a list of all records where the state is equal to either MA or RI.

 

Problem #2:  Print or display a list of all records where the year of birth is greater than 1980 and the marital status is married.

 

Problem #3: The list you are printing or displaying should have a message that says SALARIED if the job code is S should say HOURLY for all other codes.

 

Problem #4:  Print a list of all people who make a bonus greater than 5000 and either have a salary greater than 50000 or a pay per hour greater than 25 per hour.

 

Problem #5: Print a list of all people in department 15 who either are salaried and make more than 60000 or are part time or full time and make more than 25 per hour.

 

Problem #6: Print or display a list of all people and their dept group. If the dept is greater than 16 they are in SALES, if the dept is between 10 and 15 inclusive they are in FINANCE, if the dept is between 7 and 9 inclusive they are in PAYROLL, otherwise they are in BUSINESS.

 

Problems #7: If the person is married and has more than 5 dependents MOVE MSG-1 TO MSG-PR,  if the person is married and does not have more than 5 dependents MOVE MSG-2 TO MSG-PR, if the person is not married with more than 4 dependents MOVE MSG-3 TO MSG-PR, if the person is not married and does not have more than 4 dependents MOVE MSG-4 TO MSG-PR.

 

Problem #8: The list you are printing should meet the following criteria:

·        If the person is female and married and has more than three dependents print the message GROUP1

·        If the person is female and married and has 0, 1, 2, or 3 dependents print the message GROUP2

·        If the person is female and not married print the message GROUP3.

·        If the person is male and married and has more than three dependents print the message GROUP4

·        If the person is male and married and has 0, 1, 2, or 3 dependents print the message GROUP5.

·        If the person is male and not married print the message GROUP6.

·        If the gender is not know, print the message GROUP 7.

 

COBOL sample programs:

 

       IDENTIFICATION DIVISION.

       PROGRAM-ID. CIS17LAB.

       ENVIRONMENT DIVISION.

       INPUT-OUTPUT SECTION.

       FILE-CONTROL.

       SELECT EMPLOYEE-FILE

               ASSIGN TO "A:\EMPLOYEE.DAT".

       DATA DIVISION.

       FILE SECTION.

       FD  EMPLOYEE-FILE

           DATA RECORD IS EMPLOYEE-RECORD.

       01  EMPLOYEE-RECORD.

           05 IDNO         PIC XXXXX.

           05 EMPNAME      PIC X(20).

           05 YRBTH        PIC 9(4).

           05 GEN          PIC X.

           05 MARSTAT      PIC X.

           05 NUMDEP       PIC 99.

           05 ED           PIC XXX.

           05 JBCD         PIC X.

           05 PAYHR        PIC 999V99.

           05 SAL          PIC 9(6)V99.

           05 BONUS        PIC 9(5).

           05 DEPT         PIC 99.

           05 STATE        PIC XX.

       WORKING-STORAGE SECTION.

       01  PROG-INDICATORS.

           05  END-OF-FILE-IND    PIC XXX VALUE "NO ".

       PROCEDURE DIVISION.

       MAINLINE.

           PERFORM A-100-HOUSEKEEPING.

           PERFORM B-100-PROCESS.

           PERFORM C-100-WRAPUP.

           STOP RUN.

       A-100-HOUSEKEEPING.

           OPEN INPUT EMPLOYEE-FILE.

           DISPLAY " " WITH BLANK SCREEN.

           DISPLAY " ".

       B-100-PROCESS.

           READ EMPLOYEE-FILE

               AT END

                  MOVE "YES" TO END-OF-FILE-IND.

           PERFORM B-200-LOOP

               UNTIL END-OF-FILE-IND = "YES".

       B-200-LOOP.

           IF ED = "C2"

              DISPLAY EMPNAME "   " ED

           ELSE

              IF ED = "C4"

                 DISPLAY EMPNAME "   " ED

              END-IF

           END-IF

           READ EMPLOYEE-FILE

               AT END

                  MOVE "YES" TO END-OF-FILE-IND.

       C-100-WRAPUP.

           CLOSE EMPLOYEE-FILE.

 

 

 

 

 

 

       IDENTIFICATION DIVISION.

       PROGRAM-ID. CIS17lab.

       ENVIRONMENT DIVISION.

       INPUT-OUTPUT SECTION.

       FILE-CONTROL.

       SELECT EMPLOYEE-FILE

               ASSIGN TO "A:\EMPLOYEE.DAT".

       DATA DIVISION.

       FILE SECTION.

       FD  EMPLOYEE-FILE

           DATA RECORD IS EMPLOYEE-RECORD.

       01  EMPLOYEE-RECORD.

           05 IDNO         PIC XXXXX.

           05 EMPNAME      PIC X(20).

           05 YRBTH        PIC 9(4).

           05 GEN          PIC X.

           05 MARSTAT      PIC X.

           05 NUMDEP       PIC 99.

           05 ED           PIC XXX.

           05 JBCD         PIC X.

           05 PAYHR        PIC 999V99.

           05 SAL          PIC 9(6)V99.

           05 BONUS        PIC 9(5).

           05 DEPT         PIC 99.

           05 STATE        PIC XX.

       WORKING-STORAGE SECTION.

       01  PROG-INDICATORS.

           05  END-OF-FILE-IND    PIC XXX VALUE "NO ".

       PROCEDURE DIVISION.

       MAINLINE.

           PERFORM A-100-HOUSEKEEPING.

           PERFORM B-100-PROCESS.

           PERFORM C-100-WRAPUP.

           STOP RUN.

       A-100-HOUSEKEEPING.

           OPEN INPUT EMPLOYEE-FILE.

           DISPLAY " " WITH BLANK SCREEN.

           DISPLAY " ".

       B-100-PROCESS.

           READ EMPLOYEE-FILE

               AT END

                  MOVE "YES" TO END-OF-FILE-IND.

           PERFORM B-200-LOOP

               UNTIL END-OF-FILE-IND = "YES".

       B-200-LOOP.

           IF ED = "C2"

              DISPLAY EMPNAME "   " ED

           ELSE

              IF ED = "C4"

                 DISPLAY EMPNAME "   " ED

              END-IF

           END-IF

           READ EMPLOYEE-FILE

               AT END

                  MOVE "YES" TO END-OF-FILE-IND.

       C-100-WRAPUP.

           CLOSE EMPLOYEE-FILE.

 

 

 

 

       IDENTIFICATION DIVISION.

       PROGRAM-ID. CIS17lab.

       ENVIRONMENT DIVISION.

       INPUT-OUTPUT SECTION.

       FILE-CONTROL.

       SELECT EMPLOYEE-FILE

               ASSIGN TO "A:\EMPLOYEE.DAT".

       DATA DIVISION.

       FILE SECTION.

       FD  EMPLOYEE-FILE

           DATA RECORD IS EMPLOYEE-RECORD.

       01  EMPLOYEE-RECORD.

           05 IDNO         PIC XXXXX.

           05 EMPNAME      PIC X(20).

           05 YRBTH        PIC 9(4).

           05 GEN          PIC X.

           05 MARSTAT      PIC X.

           05 NUMDEP       PIC 99.

           05 ED           PIC XXX.

           05 JBCD         PIC X.

           05 PAYHR        PIC 999V99.

           05 SAL          PIC 9(6)V99.

           05 BONUS        PIC 9(5).

           05 DEPT         PIC 99.

           05 STATE        PIC XX.

       WORKING-STORAGE SECTION.

       01  PROG-INDICATORS.

           05  END-OF-FILE-IND    PIC XXX VALUE "NO ".

       PROCEDURE DIVISION.

       MAINLINE.

           PERFORM A-100-HOUSEKEEPING.

           PERFORM B-100-PROCESS.

           PERFORM C-100-WRAPUP.

           STOP RUN.

       A-100-HOUSEKEEPING.

           OPEN INPUT EMPLOYEE-FILE.

           DISPLAY " " WITH BLANK SCREEN.

           DISPLAY " ".

       B-100-PROCESS.

           READ EMPLOYEE-FILE

               AT END

                  MOVE "YES" TO END-OF-FILE-IND.

           PERFORM B-200-LOOP

               UNTIL END-OF-FILE-IND = "YES".

       B-200-LOOP.

           IF ED = "C2"

              DISPLAY EMPNAME "   " ED

           ELSE

              DISPLAY EMPNAME "   NOT C2 - " ED

           END-IF

           READ EMPLOYEE-FILE

               AT END

                  MOVE "YES" TO END-OF-FILE-IND.

       C-100-WRAPUP.

           CLOSE EMPLOYEE-FILE.