IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Is there any way to use TWO files by a single SELECT


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
devidas-patil

New User


Joined: 08 Jan 2007
Posts: 54
Location: pune

PostPosted: Wed May 30, 2007 10:03 am
Reply with quote

Hi all

i have two file and i want to use both the file in the cobol program and both file have the same attribute as well as the same FD entires but allowed me to use only one SELECT INFILE ASSIGN TO DDNAME
i cant
---> use two select statement in my program and
--> i cant merge two file,
--> i can't concatenate two file

what to do in this situation?
please let me know.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed May 30, 2007 10:26 am
Reply with quote

Patil,

Quote:
--> i cant merge two file,
--> i can't concatenate two file


Why cant? Is there any business reason for this.
Back to top
View user's profile Send private message
devidas-patil

New User


Joined: 08 Jan 2007
Posts: 54
Location: pune

PostPosted: Wed May 30, 2007 10:44 am
Reply with quote

hi murali
this is question of my interviews so oi told him this two option but he was expecting something different than this
Back to top
View user's profile Send private message
Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Wed May 30, 2007 10:44 am
Reply with quote

Quote:
--> cant use two select statement in my program and
--> i cant merge two file,
--> i can't concatenate two file


Can you atleast execute the program twice with 2 diff files?
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed May 30, 2007 11:38 am
Reply with quote

devidas-patil wrote:
Hi all
i have two file ...


I think the interviewer was talking about one input & one output.

Quote:


i cant
---> use two select statement in my program and

Under the above assumption, one can direct the output to SYSOUT dataset & one'll need only one SELECT statement in COBOL program.

Quote:

--> i cant merge two file,
--> i can't concatenate two file
what to do in this situation?


If Both the files are inputs.. then don't know.

Did you ask about the files usage !? If yes please let me know. Hopefully we can come up with some good idea.
Back to top
View user's profile Send private message
devidas-patil

New User


Joined: 08 Jan 2007
Posts: 54
Location: pune

PostPosted: Wed May 30, 2007 2:20 pm
Reply with quote

Hi anuj
i not asked him about the file usage. i am very sure he was asking me both are the input file.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Jun 07, 2007 8:03 pm
Reply with quote

devidas-patil wrote:
Hi anuj
i not asked him about the file usage. i am very sure he was asking me both are the input file.


Hi,

Every file used in COBOL program has to have a SELECT clause, so if both are inputs, then in this situation answer for the question is - not possible.
Back to top
View user's profile Send private message
Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Thu Jun 07, 2007 8:15 pm
Reply with quote

Quote:
Every file used in COBOL program has to have a SELECT clause

This is not true and cannot be generalized.

There is no need for SELECT statement in below COBOL code
- From COBOL you can open/close/read using assembler routintes without COBOL SELECT clause
- In IMS COBOL you can read files without COBOL SELECT clause
-In CICS COBOL program there is no need for COBOL SELECT clause
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jun 07, 2007 9:08 pm
Reply with quote

Hello,

You might run a step that copies/merges the 2 files into one before executing your program with these strange rules. . . icon_smile.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Jun 08, 2007 7:40 pm
Reply with quote

Hi,

I hope interviewer asked about simple COBOL-batch program, by simple I mean a program which is not using any database. From the window of original question I think I didn't direct the OP in wrong direction.

However, if you can provide some examples or can direct to some link, that would be great to understand your statements rather better.

dick scherrer wrote:
Hello,

You might run a step that copies/merges the 2 files into one before executing your program with these strange rules. . . icon_smile.gif


Dick,
I didn't get your intention here..!?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jun 08, 2007 8:59 pm
Reply with quote

Hi Anuj,

If the files were combined prior to the COBOL program, the rather non-business "rules" of the question (can't use 2 . . .etc in the COBOL program) might be met.

I just took that work out of the COBOL code to satisfy the "rules" - probably not the best way to approach this, but keeps the 3 "can't"s out of COBOL icon_confused.gif

There is always the chance that what the interviewer meant to ask and what was understood to be the requirement was not the same. . . Happens quite often when you combine an interviewer with limited technical knowldege with an interviewee with limited experience and especially if they are communicating in a language that is not the "main" language of either one.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Jun 11, 2007 9:28 pm
Reply with quote

Still bounced..!
Let's leave it. icon_neutral.gif
Back to top
View user's profile Send private message
utkarshtewari

New User


Joined: 26 Mar 2007
Posts: 9
Location: UK

PostPosted: Fri Jun 15, 2007 2:13 pm
Reply with quote

Hi Anuj,
Guess what dick is suggesting is that in RUN JCL we need to put a step to merge/sort the two files into one, using Utilities...thus creating a single file to be dealt with in the program...

and in the next JCL step you can execute the program.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sat Jun 16, 2007 5:02 am
Reply with quote

Yup, not a way i'd do it if i had the need to process those files, but might get around the non-business requirement mentioned above.

I am fairly sure there is no business reason for the restrictons. . . icon_confused.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Jun 19, 2007 6:35 pm
Reply with quote

Thanks Utkarsh. icon_smile.gif

dick scherrer wrote:
I am fairly sure there is no business reason for the restrictons. . . icon_confused.gif


Yeah, I do agree.
Back to top
View user's profile Send private message
skkp2006

New User


Joined: 14 Jul 2006
Posts: 93
Location: Chennai,India

PostPosted: Wed Jun 20, 2007 11:13 am
Reply with quote

When two different files are used in a program two sets of output files or processing(database updates/deletes) is to be expected.

I would suggest to create a proc which would run the program in step1 and overriding the file in step2 which would run the same proc in a jcl to get the results.

Regards,
Syam
Back to top
View user's profile Send private message
Johnson_Jiang

New User


Joined: 05 Apr 2007
Posts: 11
Location: China,ShenZhen

PostPosted: Wed Jun 20, 2007 12:03 pm
Reply with quote

Hi, Patil,

I think the question is about the run jcl. In your COBOL program, you can use one SELECT statement to handle several input file (same layout, same length), just implement it in JCL like follows:

//INPUTFIL DD DSN=FILE1.XXX,DISP=SHR
// DD DSN=FILE2.XXX,DISP=SHR
// DD DSN=FILE3.XXX,DISP=SHR
:
:
:
So in cobol program, you can use:

SELECT Inputfil-file ASSIGN TO INPUTFIL ....

It works!
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Jun 20, 2007 12:09 pm
Reply with quote

Johnson,

Quote:
//INPUTFIL DD DSN=FILE1.TTT,DISP=SHR
// DD DSN=FILE2.TTT,DISP=SHR
// DD DSN=FILE3.TTT,DISP=SHR


Please go through the original post, which says - cant concatenate two files.
Back to top
View user's profile Send private message
devidas-patil

New User


Joined: 08 Jan 2007
Posts: 54
Location: pune

PostPosted: Thu Jun 21, 2007 1:25 pm
Reply with quote

Thanks all!!!!!!!!!!!!!
Back to top
View user's profile Send private message
Naresh Kumar Reddy P

New User


Joined: 24 May 2007
Posts: 8
Location: Bangalore

PostPosted: Thu Jun 21, 2007 4:15 pm
Reply with quote

Probably, the interviewer was expecting DD concatination in your JCL. I believe it is the only way to accept two input files with one select statement in your program (for pure cobol program).

Thanks
Reddy
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jun 21, 2007 6:13 pm
Reply with quote

Hello Reddy,

Please read the post from the beginning. The initial post post says
Quote:
--> i can't concatenate two file
Back to top
View user's profile Send private message
kgumraj

Active User


Joined: 01 May 2006
Posts: 151
Location: Hyderabad

PostPosted: Thu Jun 21, 2007 7:04 pm
Reply with quote

Hi,

I can imagine only this: Using same DD name for the input files.
When I ran it only took the first input file.
But I didnt get the buisnees in doing so icon_neutral.gif
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Jun 30, 2007 9:38 pm
Reply with quote

Hi Anju,

There's a relatively new feature in COBOL (Eviroment Variables - I think) that allows the coder to change the FD stmt to define a different dataset than the one being currently used. It calls a subroutine "putenv", among other things. It's a fairly involved process.

Another approach is BPXWDYN, an interface to SVC 99.

I haven't used either of these so this is about all I know on the subject.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Jul 02, 2007 7:44 pm
Reply with quote

mmwife wrote:
Hi Anju,

Hi,

If this is for me, then my name is Anuj not Anju icon_neutral.gif

However,coming to the topic of thread..
OP says
Quote:
i have two file

so
Quote:
that allows the coder to change the FD
will not suffice the requirement of OP. As stated by you, subroutine 'putenv' will allow to change the FD of the same file while OP says
Quote:
both file have the same attribute as well as the same FD entires
, so he does not want to open the same file with different layout instead he wants to open a different file with the same layout. In a nutshell, there are two input files, with different data, but with same FD entries and he wants to refer both files with a single SELECT.
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Tue Jul 03, 2007 3:59 am
Reply with quote

I think you can only have max of 16 fd's per cobol program. was involved with project years ago that required using same fd in cobol
program. I used a dynamic allocation subroutine to change
the dataset name on the fly and then open/close the file as logically needed.

FD SAME-FD assign SAMEFD
..
..
..
PROCEDURE DIVISION.
MOVE 'MYFILE.FILEONE' TO WS-FILE-NAME.
CALL 'DYDSN' USING WS-FILE-NAME, SAME-FD, 'SAMEFD'.
OPEN INPUT SAME-FD.
READ SAME-FD INTO WS-SAVE-FILEONE-RECORD.
CLOSE SAME-FD.

MOVE 'MYFILE.FILETWO' TO WS-FILE=NAME.
CALL 'DYDSN' USING WS-FILE-NAME, SAME-FILE.
OPEN INPUT SAME-FD
READ SAME-FD INTO WS-SAVE-FILETWO-RECORD.
PERFORM PROCESS-FILE-TWO.
....
...
....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 5
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
Search our Forums:

Back to Top