View previous topic :: View next topic
|
Author |
Message |
sure116
New User
Joined: 03 Feb 2006 Posts: 11
|
|
|
|
I am reading file A and writing to file B.
I need to write file A to file B But in file B I need to see
a constant value which appears in file A first 5 chars of First record.
Rest of all the file B and file A should be same.
Please let me know if I need to declare some variable as GLOBAL or anything to retain same value.
I tried moving to temp field when I read first rec of A.
But its is diplaying spaces when coming to 2nd record of file B.
I am not at all intializing the temp field.
Eg.,
File A
---------------
123 afdsfdsfdsfd
567 fdsfdsfdsfdsf
678 gfdgfdgfdgfd
Expected File B
------------------
123 afdsfdsfdsfd
123 fdsfdsfdsfdsf
123 gfdgfdgfdgfd
Thanks
Suresh |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
I'm not a programmer, but this seems like a rather simplistic task:
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGxx.
INSTALLATION.
AUTHOR. SUPERK.
DATE-WRITTEN. 02/03/2006.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT A ASSIGN TO FILEA
ORGANIZATION IS SEQUENTIAL.
SELECT B ASSIGN TO FILEB
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD A
LABEL RECORD STANDARD
BLOCK 0 RECORDS
RECORDING MODE F
RECORD CONTAINS 80 CHARACTERS.
01 A-REC.
03 A-FIRST-FIVE PIC X(05).
03 FILLER PIC X(75).
FD B
LABEL RECORD STANDARD
BLOCK 0 RECORDS
RECORDING MODE F
RECORD CONTAINS 80 CHARACTERS.
01 B-REC.
03 B-FIRST-FIVE PIC X(05).
03 FILLER PIC X(75).
WORKING-STORAGE SECTION.
01 WS-FIRST-FIVE PIC X(05) VALUE SPACES.
01 EOF PIC X VALUE 'N'.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN INPUT A, OUTPUT B.
MOVE SPACES TO B-REC.
READ A AT END MOVE 'Y' TO EOF.
MOVE A-FIRST-FIVE TO WS-FIRST-FIVE.
PERFORM READ-PARA UNTIL EOF = 'Y'.
CLOSE A, B.
MOVE ZEROS TO RETURN-CODE.
STOP RUN.
READ-PARA.
MOVE A-REC TO B-REC.
MOVE WS-FIRST-FIVE TO B-FIRST-FIVE.
WRITE B-REC.
READ A AT END MOVE 'Y' TO EOF.
|
Input:
Code: |
123 afdsfdsfdsfd
567 fdsfdsfdsfdsf
678 gfdgfdgfdgfd
|
Output:
Code: |
123 afdsfdsfdsfd
123 fdsfdsfdsfdsf
123 gfdgfdgfdgfd
|
|
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Or you can do something like this (no better or wose than K's):
Do the 1st read outside the loop and save "123" as suggested.
In the loop, move "123" to the A rec.
Write the B rec from the A rec.
Just another way to do it. |
|
Back to top |
|
|
sure116
New User
Joined: 03 Feb 2006 Posts: 11
|
|
|
|
Thank you very much for your kind responses.
Now am able to get the results. The worng thing I have done is
I am moving to the WS field after a statement where spaces were moved to CARD-IN so I am not getting the result.
But after the reply from K and mm I am reviewing the code and
cought myself where I have coded wrong location of move stmt.
Now I have changed the move prior to the initialize.
Thank you very much for your suggestions.
I really appreciate it.......................
suresh |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
sure116,
No chance you would be waiting for any suggestion now, after two super suggestions above...
One thing I would like to add, If 123 is constant for each & every record of output file....
Code: |
01 A-REC.
03 A-FIRST-FIVE PIC X(05).
03 A-REST PIC X(75).
01 B-REC.
03 B-FIRST-FIVE PIC X(05) VALUE '123 '.
03 B-REST PIC X(75).
PROCEDURE DIVISION.
MAIN-PARA.
OPEN INPUT A, OUTPUT B.
PERFORM READ-PARA UNTIL EOF = 'Y'.
CLOSE A, B.
STOP RUN.
READ-PARA.
READ A INTO A-REC AT END MOVE 'Y' TO EOF.
MOVE A-REST TO B-REST.
WRITE B-REC. |
Regards,
Priyesh. |
|
Back to top |
|
|
mijanurit Currently Banned New User
Joined: 26 Aug 2005 Posts: 33 Location: bangalore
|
|
|
|
hi all,
whatever is given by superk, is right. i want to modify procedure division then it will be more easy to understand.
Code: |
PROCEDURE DIVISION.
MAIN-PARA.
MOVE SPACE TO B-REC.
OPEN INPUT A, OPEN OUTPUT B.
PERFORM READ-PARA UNTIL EOF='Y'.
CLOSE A,B.
STOP RUN.
READ-PARA.
READ A INTO W-REC AT END MOVE 'Y' TO EOF.
IF EOF='N'
MOVE W-REC TO B-REC
WRITE B-REC.
|
|
|
Back to top |
|
|
|