Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Accesing selected columns from trwo files in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Shrikanth
Warnings : 1

New User


Joined: 26 Feb 2007
Posts: 5
Location: Bangalore

PostPosted: Wed Feb 28, 2007 4:01 am    Post subject: Accesing selected columns from trwo files in COBOL
Reply with quote

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
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed Feb 28, 2007 4:12 am    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Feb 28, 2007 4:14 am    Post subject:
Reply with quote

Hello,

In file A, how is dept. defined?
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Wed Feb 28, 2007 3:25 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Feb 28, 2007 9:13 pm    Post subject:
Reply with quote

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
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Sun Mar 04, 2007 3:08 am    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Mar 04, 2007 7:17 am    Post subject:
Reply with quote

Sorry, i misread your post. It all runs together and i just didn't see it correcty. icon_redface.gif

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us