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

Date Manipulation: two output files??

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am not a professional programmer. I am here to seek answers from professionals. I am doing a lab in an advanced COBOL class. I am modifying a program that figured out ages and birthdates of a list of people. I now have to print a separate output with just the people that have birthdays in the next 31 days. The program already identifies them with an asterisk on the output. I now just have to get those names to another output, while at the same time leaving the old output alone. So I'll have to outputs.
Here is my old program, it hasn't been changed yet.

------------------------------------------------------------
*-----------------------------------------------------------------
IDENTIFICATION DIVISION.
*-----------------------------------------------------------------
PROGRAM-ID. LAB1.
AUTHOR.
*-----------------------------------------------------------------
*THIS PROGRAM USES DATE MANIPULATION TO COMPUTE THE AGE OF CLIENTS
*THAT ARE IN AN INPUT FILE TO SEE IF THEY HAVE AN UPCOMING
*BIRTHDAY
*-----------------------------------------------------------------

*-----------------------------------------------------------------
ENVIRONMENT DIVISION.
*-----------------------------------------------------------------

*------------------------
INPUT-OUTPUT SECTION.
*------------------------

FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO 'R:\COBOL2\LAB1\CLIENTS.TXT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT REPORT-FILE ASSIGN TO 'R:\COBOL2\LAB1\AGEREPORT.OUT'
ORGANIZATION IS LINE SEQUENTIAL.

*-----------------------------------------------------------------
DATA DIVISION.
*-----------------------------------------------------------------

*------------------------
FILE SECTION.
*------------------------

* |--------------------|
* | INPUT FILE |
* |--------------------|

FD INPUT-FILE
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 41 CHARACTERS
BLOCK CONTAINS 41 CHARACTERS.

01 CLIENT-RECORD.
05 CLIENT-NUMBER-CR PIC X(5).
05 CLIENT-NAME-CR PIC X(20).
05 CLIENT-BIRTHDAY-CR PIC 9(8).
05 FILLER PIC X(8).


* |--------------------|
* | OUTPUT FILE |
* |--------------------|

FD REPORT-FILE
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 100 CHARACTERS
BLOCK CONTAINS 100 CHARACTERS.

01 REPORT-RECORD PIC X(100).

*------------------------
WORKING-STORAGE SECTION.
*------------------------

* |--------------------|
* | FLAG |
* |--------------------|

01 FLAGS-AND-ACCUMULATORS.
05 EOF-FLAG PIC X(3) VALUE 'NO'.


* |--------------------|
* | DATE FIELDS |
* |--------------------|

01 WS-CURRENT-DATE.
05 WS-CURRENT-DATE-MONTH.
10 WS-YEAR PIC 9(04).
10 WS-MONTH PIC 9(02).
10 WS-DAY PIC 9(02).
05 WS-INTEGER-TODAY REDEFINES WS-CURRENT-DATE-MONTH PIC 9(8).

01 DAYS-LEFT.
05 WS-DAYS-LEFT PIC 999.
05 WS-INTEGER-TODAY2 PIC 9(10).
05 WS-INTEGER-CLIENT-BDAY PIC 9(10).

01 CLIENT-BIRTHDAY.
05 WS-YEAR-BDAY PIC 9999.
05 WS-MONTH-BDAY PIC 99.
05 WS-DAY-BDAY PIC 99.

01 WS-INTEGER-CLIENT-BIRTHDAY REDEFINES CLIENT-BIRTHDAY PIC 9(8).

* |--------------------|
* | REPORT STRUCTURES |
* |--------------------|

01 TITLE-LINE-ONE.
05 PIC X(12) VALUE SPACES.
05 PIC X(23) VALUE
'White Insurance Company'.

01 TITLE-LINE-TWO.
05 PIC X(12) VALUE SPACES.
05 PIC X(19) VALUE
'Bruce, South Dakota'.

01 COLUMN-HEADING.
05 PIC X(11) VALUE 'Client Name'.
05 PIC X(14) VALUE SPACES.
05 PIC X(8) VALUE 'Birthday'.
05 PIC X(12) VALUE SPACES.
05 PIC X(3) VALUE 'Age'.
05 PIC X(2) VALUE SPACES.
05 PIC X(8) VALUE 'Upcoming'.

01 DETAIL-LINE.
05 CLIENT-NAME-DL PIC X(25).
05 MONTH-DL PIC Z9.
05 PIC X(1) VALUE '/'.
05 DAY-DL PIC 99.
05 PIC X(1) VALUE '/'.
05 YEAR-DL PIC 9999.
05 PIC X(10) VALUE SPACES.
05 AGE-DL PIC ZZ9.
05 PIC X(5) VALUE SPACES.
05 UPCOMING-DL PIC X.

*-----------------------------------------------------------------
PROCEDURE DIVISION.
*-----------------------------------------------------------------

*------------------------
1000-MAIN-MODULE.
*------------------------

PERFORM 2000-INITIALIZE

* |---------------------|
* |PROCESS INPUT RECORDS|
* |---------------------|


PERFORM UNTIL EOF-FLAG = 'YES'
READ INPUT-FILE
AT END
MOVE 'YES' TO EOF-FLAG
NOT AT END
PERFORM 3000-PROCESS
END-READ
END-PERFORM

PERFORM 4000-TERMINATE

STOP RUN.

*------------------------
2000-INITIALIZE.
*------------------------

* |--------------------|
* | OPEN FILES |
* |--------------------|

OPEN INPUT INPUT-FILE
OUTPUT REPORT-FILE

MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-MONTH

PERFORM 9000-WRITE-HEADINGS.



*------------------------
3000-PROCESS.
*------------------------

MOVE CLIENT-BIRTHDAY-CR TO CLIENT-BIRTHDAY

MOVE FUNCTION INTEGER-OF-DATE (CLIENT-BIRTHDAY-CR)
TO WS-INTEGER-CLIENT-BDAY

MOVE FUNCTION INTEGER-OF-DATE (WS-INTEGER-TODAY)
TO WS-INTEGER-TODAY2

SUBTRACT WS-INTEGER-CLIENT-BDAY FROM WS-INTEGER-TODAY2
GIVING WS-INTEGER-CLIENT-BDAY

DIVIDE WS-INTEGER-CLIENT-BDAY BY 365.25 GIVING AGE-DL
REMAINDER WS-DAYS-LEFT

IF WS-DAYS-LEFT >334
MOVE '*' TO UPCOMING-DL
END-IF

MOVE CLIENT-NAME-CR TO CLIENT-NAME-DL
MOVE CLIENT-BIRTHDAY-CR TO CLIENT-BIRTHDAY
MOVE WS-YEAR-BDAY TO YEAR-DL
MOVE WS-MONTH-BDAY TO MONTH-DL
MOVE WS-DAY-BDAY TO DAY-DL

WRITE REPORT-RECORD FROM DETAIL-LINE AFTER 1

MOVE SPACES TO UPCOMING-DL.

*------------------------
4000-TERMINATE.
*------------------------

CLOSE INPUT-FILE
REPORT-FILE.



*------------------------
9000-WRITE-HEADINGS.
*------------------------

WRITE REPORT-RECORD FROM TITLE-LINE-ONE AFTER PAGE
WRITE REPORT-RECORD FROM TITLE-LINE-TWO AFTER 1
WRITE REPORT-RECORD FROM COLUMN-HEADING AFTER 2
WRITE REPORT-RECORD FROM SPACES.





 
Hi,

If your description is right, the sentence

IF WS-DAYS-LEFT >334
MOVE '*' TO UPCOMING-DL
END-IF

identifies the place that you know that this is the right one to write also the other record into the other file.

So after the MOVE you can insert a PERFORM statement to activate a subroutine that is going to write the record for you.

Regards,

Crox
 
Hi,

What I would do is defer the 2nd WRITE until after you move all your data to your O/P report rec then issue the 1st & 2nd WRITEs in succession, e.g.:

Code:
WRITE REPORT-RECORD     FROM DETAIL-LINE       AFTER 1
         
IF UPCOMING-DL = '*'
   WRITE REPORT-RECORD2 FROM DETAIL-LINE       AFTER 1
END-IF

The usual caveats, disclaimers, and copouts apply.

P.S. Don't forget to SELECT/ASIGN, FD, OPEN/CLOSE the new file and write the headings in 9000-. Also, do you have to worry about page breaks? I noticed you haven't coded any.

Regards, Jack.




 
Moreover, i would defer the moves to make out the second output record to the point Jack mentioned.
In pseudo-code:

BUILD RECORD1
IF '*'
BUILD RECORD2
WRITE RECORD2
END-IF
WRITE RECORD1

I put the write of record 1 afterwards to be sure that output area isn't compromised; it might not even be nescessary.

Regards,
Ronald.
 
There are several ways to do this. If you mark the file for these people as you go you could close the file and reopen it and skip all the ones that are not marked and make another page of print.

You could load a table as you are printing the first report and unload the table to print the report with the B-days withing 30 days. This is the fastest to run on a large file if the table does not get too big.

You could use two print files. Just send the ones you are marking to the second print file. Of course if the list is long this would cause you to look for a page break on 2 separate print files.

There are a few other ways to do this of course. If you do not like my post feel free to point out your opinion or my errors.
 
Hi

If you are working on an ibm mainframe or also on DOS AND you dont want to modify the program, use selcopy tool in JCL (if you are working on the mainframe) to selectively copy the records having * at a particular position to another output file. More information on selcopy can be obtained from
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top