View previous topic :: View next topic
|
Author |
Message |
Shrikanth Warnings : 1 New User
Joined: 26 Feb 2007 Posts: 5 Location: Bangalore
|
|
|
|
Hi
i have a 2 files A and B.
In File A i have Empno. Empname. Dept.In File B i have Deptno. Deptname, Deptlocation
now my question is i want to take data from file A (Empno. Empname, Dept.) and only Deptno. from File B.
how will i achieve this? please advice me.
Thanks
Shrikanth |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
What is the relation of file A's Dept to file B's Deptno or Deptname?
With a relationship, no problem, easy. Without a relationship, impossible.
Waiting for your feedback. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
In file A, how is dept. defined? |
|
Back to top |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
I GIVE YOU THE PROGRAME
ID DIVISION
PROGRAME-ID. XXX.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION
FILE-CONTROL.
SELECT FILE1 ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS1.
SELECT FILE2 ASSIGN TO DD2
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS2.
SELECT FILE2 ASSIGN TO DD3
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS3.
DATA DIVISION.
FILE-SECTION.
FD FILE1.
01 MASTER
02 EMPNO PIC X(4).
02 EMPNAME PIC X(10).
02 DEPT PIC 9(2).
01 MASTER2.
02 DEPTNO PIC 9(4).
02 DEPTNAME PICX(4)
02 DEPT LOCATION PIC X(5).
01 MASTER3.
02 EMPNO1 PIC X(4).
02 EMPNAME1 PIC X(10).
02 DEPT1 PIC 9(2).
02 DEPTNO1 PIC 9(4).
WORKING-STORAGE SECTION.
77 FS1 PIC 99 VALUE "Y".
77 FS2 PIC 99.
77 FS3 PIC 99.
PROCEDURE DIVISION.
MAINPARA.
PERFORM OPEN-PARA.
PERFORM READ-PARA UNTIL EOF NOT = 'Y'
PERFORM CLOSE-PARA.
OPEN-PARA.
OPEN INPUT FILE1.
OPEN INPU FILE2.
OPEN OUTPUT FILE3.
READ-PARA.
READ FILE1 AT END MOVE "Y" TO EOF
NOT AT END
READ FILE2
IF FS1=0
MOVE EMPNO TO EMPNO1.
MOVE EMPNAME TO EMPNAME1.
MOVE DEPT TO DEPT1.
MOVE DEPTNO TO DEPTNO1.
WRITE MASTER3
DISPLAY MASTER.
CLOSE-PARA.
CLOSE FILE1.
CLOSE FILE2.
CLOSE FILE3.
STOP RUN.
I THINK THIS WILL HELP YOU
FROM- SACHIN BORASE
PUNE |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Yes, having the code does help.
When you post code, it is best to use the "code" tag so it will be easier to read - i've put your program in "code mode" to show how it looks. It also helps to use proper indentation.
Code: |
ID DIVISION
PROGRAME-ID. XXX.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION
FILE-CONTROL.
SELECT FILE1 ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS1.
SELECT FILE2 ASSIGN TO DD2
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS2.
SELECT FILE2 ASSIGN TO DD3
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS3.
DATA DIVISION.
FILE-SECTION.
FD FILE1.
01 MASTER
02 EMPNO PIC X(4).
02 EMPNAME PIC X(10).
02 DEPT PIC 9(2).
01 MASTER2.
02 DEPTNO PIC 9(4).
02 DEPTNAME PICX(4)
02 DEPT LOCATION PIC X(5).
01 MASTER3.
02 EMPNO1 PIC X(4).
02 EMPNAME1 PIC X(10).
02 DEPT1 PIC 9(2).
02 DEPTNO1 PIC 9(4).
WORKING-STORAGE SECTION.
77 FS1 PIC 99 VALUE "Y".
77 FS2 PIC 99.
77 FS3 PIC 99.
PROCEDURE DIVISION.
MAINPARA.
PERFORM OPEN-PARA.
PERFORM READ-PARA UNTIL EOF NOT = 'Y'
PERFORM CLOSE-PARA.
OPEN-PARA.
OPEN INPUT FILE1.
OPEN INPU FILE2.
OPEN OUTPUT FILE3.
READ-PARA.
READ FILE1 AT END MOVE "Y" TO EOF
NOT AT END
READ FILE2
IF FS1=0
MOVE EMPNO TO EMPNO1.
MOVE EMPNAME TO EMPNAME1.
MOVE DEPT TO DEPT1.
MOVE DEPTNO TO DEPTNO1.
WRITE MASTER3
DISPLAY MASTER.
CLOSE-PARA.
CLOSE FILE1.
CLOSE FILE2.
CLOSE FILE3.
STOP RUN.
|
I believe what you posted is not the complete program. You have 3 "open"s (with one misspelled) and only one FD.
My guess is that master2&3 should be file2 and file3. If so, you might read file 1 and get the deptno from "master3". This should be straight-foirward as there are matching fields in file1&3. I'm not sure why you need to use file2? |
|
Back to top |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
thanks for advise
yes there in - fd file2 -master2
fd file3 - master3
and your second question matching the deptnoi=coloumn matching in file1 and 3
read the question i want data from two files so that files are file1 and file2, and we want to put some selected field from file1 and file2 to output file3 so i have use read file1 and read file2 in input mode and output mode for file3
and about ur question about matching of deptno coloumn matching so check it once again
there is no field of name of deptni in file1 that in only in file2 and i have given the name deptno1 in file3
have a nice day |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Sorry, i misread your post. It all runs together and i just didn't see it correcty.
Given your input files, it appears you have no way to "relate" them to each other.
Let's call your input employee-master and dept-master (file1,2,etc says nothing). On hr (human resources) systems i've worked on there is a field in the employee-master that is the "key" to the dept-master. Why your system needs both a 2-digit and a 4-digit dept-no is confusing. I have seen this sometimes when dieffernt systems are consolidated. . . It is sometimes one of the growing pains that should go away over time.
You could ask others who know your system if there is a cross-reference file somewhere that has both formats of dept-no so that you can find the 4-digit dept record with only a 2-digit dept-no as input. If such a cross-reference does not exist, you may need to create one. If the number of departments is small, it could become a copybook of "old" and "new" values. If there are many departments, using a vsam file or database table would work. |
|
Back to top |
|
|
|