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

Dynamically changing dd name in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Thu Dec 23, 2010 3:10 pm
Reply with quote

Hi,

I went through below mentioned thread to work on one of requirements and had 2 queries :-
Thread:- ibmmainframes.com/about10103.html
1.
Its about dynamically changing dd name.I used routine provied on above mentioned thread by David(I.e. program CHGDDN & its call) and want info that how its working....i m not getting it neither from first look nor from executing it(though its working fine if used with one file only).

2. As per my requirement,we had 2 file with same record structure and LRECL.File1 is opening in input mode and file 2 is in output mode.Now using CHGDDN,file1 is opened successfully but its not opening file2 in output mode and giving status code 41.
Then I placed DISPLAY statements in CHGDDN before & after MOVE statements in procedure division to check whether its processing with correct file.DISPLAY results showed that file2 is received by parameters(I.e. NEW-DDNAME,DDNAME2 & DDNAME).Now I m not aware of backend process so couldn't dig more in it.So please help.
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Mon Dec 27, 2010 11:41 am
Reply with quote

Hi All,

I am trying to find answer of my query but still its not rtesolved.I didn't see any reply here also.Please help me as I had used the below mentioned code,but dont know how its working and at the same time facing issue while using it with more than 1 file(I had mentioned all these queries in my last post):-
[u]Program CHGDDN
ID DIVISION.
PROGRAM-ID. CHGDDN.
AUTHOR. DAVIDATK.
DATE-WRITTEN.
DATE-COMPILED.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.

LINKAGE SECTION.
01 DCB.
05 FILLER PIC X(40).
05 DDNAME PIC X(8).
05 FILLER PIC X(192).
05 DDNAME2 PIC X(8).

01 NEW-DDNAME PIC X(8).
PROCEDURE DIVISION USING DCB
NEW-DDNAME.

MOVE NEW-DDNAME TO DDNAME2 DDNAME.

GOBACK.

[u]And its calling(Main) program:-
ID DIVISION.
.....
FILE-CONTROL.
SELECT TEST-FILE ASSIGN TO DD1.
SELECT TEST-DD2 ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD TEST-FILE
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS.
01 TEST-REC PIC X(80).
FD TEST-DD2
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS.
01 TEST-DD2REC PIC X(80).

WORKING-STORAGE SECTION.

01 NEW-DDNAME PIC X(8) VALUE 'NEWDD1'.
01 WS-EOF-SW PIC X VALUE 'N'.
88 EOF VALUE 'Y'.

LINKAGE SECTION.

PROCEDURE DIVISION.

CALL 'CHGDDN' USING TEST-FILE NEW-DDNAME.

OPEN INPUT TEST-FILE
TEST-DD2.

PERFORM
UNTIL EOF
READ TEST-FILE
AT END MOVE 'Y' TO WS-EOF-SW
END-READ
DISPLAY TEST-REC
END-PERFORM.

CLOSE TEST-FILE
TEST-DD2.

GOBACK.


Please help.
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Mon Dec 27, 2010 12:35 pm
Reply with quote

I am just curious. Why you require dynamic DDNAMES in first place?

You have one input and one output file. Cant you allocate seperate DDNAMES to them in file section?
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Mon Dec 27, 2010 1:26 pm
Reply with quote

Hi mlp,

Here I am trying to perform file operations of files with same LRECL using a piece of code(Like CHGDDN).First define it and then call it in main program to perform file operations.It works perfectly fine with one file but when we try to work(like open,read or write or rewrite and close) with another file,it creates problem.
So I want to know the process behind it.
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Mon Dec 27, 2010 2:47 pm
Reply with quote

I dont know your requirement. But I think if you want implement the same via the CHNGDDN type of code then you are un-necessarily complicating things. Becuase your requirement seems simple to me and I think you just want to try out something new over here...(I hope I am right..:-)).

I have not tried what David has posted and hence not sure about it. You are saying that you implemented it and it worked for the first file(TEST-FILE) and not for the second file (TEST-DD2). If I see your piece of code for the main program, you are not doing anything with TEST-DD2 file. You are just opening it in input mode. So I am not sure where exactly you are getting file status 41.

Also, if you want to know how the file allocations work then here it is.

Once you define file with file-name in COBOL prog then you make association of the logical file name to the DD-name which will be used by your JCL to execute the program and allocate the resource( in this case, file) for you.

Logical file name (in COBOL prog) -> DD name -> Physical file name (Dataset name)

So the link between COBOL program and JCL is the DDname as far as file operations are concerned. So all the files which are listed in your JCL should be in your file-control section, so that your COBOL program comes to know that there are some files which are allocated (either by JCL or dynamiclly allocated) for the execution.

If you want to dig further here are some references for you.

DFSMShsm Primer IBM red book
DFSMS Access Method Services for Catalogs
JCL reference
Enterprise cobol reference

All of the above can be downloaded from web. Also refer below topic. Might give you some info regrd dataset allocations.

Also refer below link for TSO/E commands. Look for "ALLOCATE".

publib.boulder.ibm.com/infocenter/zos/v1r9/index.jsp?topic=/com.ibm.zos.r9.ikjc500/ikj4c580.htm
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: Mon Dec 27, 2010 9:57 pm
Reply with quote

Hello,

Quote:
Here I am trying to perform file operations of files with same LRECL
If you have multiple files (input and/or output), the DDnames need not (probably should not) be changed. . .

All you need to do is change the dataset names in the JCL to be submitted.

Possibly there is something i misunderstand. . .
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Wed Dec 29, 2010 12:52 pm
Reply with quote

Hi,
MLP,
As you stated "I dont know your requirement. But I think if you want implement the same via the CHNGDDN type of code then you are un-necessarily complicating things. Becuase your requirement seems simple to me and I think you just want to try out something new over here...(I hope I am right..:-)). "

Its like that only and that's why I used code given by David but now I want to know the process doing this.

Dick,
I think, you are saying about normal process we need to follow but here scenerio is like that only.
I am trying to make a set of code(common code) which can be used for opening the file in different modes and its getting done using CHGDDN(code suggested by David) with 1 file in any mode but in same program,if we call this common code again for another file,then its giving status code 41.It seems like its not taking the second DD name to change....something like initialization we do in cobol program same if we can do in this routine after knowing its process to change the DD name,then this problem may resolve.
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: Wed Dec 29, 2010 8:29 pm
Reply with quote

Hello,

So far, i have seen nothing that requires dynamically changing the ddname in the COBOL process. Maybe i am just slow this month. . .

Is there some business or technical reason (not some personal preference to try an experiment) that you cannot simply use the correct ddname in the jcl to be submitted. . . icon_confused.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Dec 29, 2010 8:47 pm
Reply with quote

Quote:
So far, i have seen nothing that requires dynamically changing the ddname in the COBOL process. Maybe i am just slow this month. . .

partially agree icon_biggrin.gif
unless somebody is trying to simulate the PL1 file variable

Code:
DCL FILE1 ...
DCL FILE2 ...
DCL FILE3 ...
DCL FILEX ...

DCL FILE VAR


FILE = FILE1
OPEN FILE
<process> FILE
CLOSE FILE

FILE=FILE2

OPEN FILE
<process> FILE
CLOSE FILE
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Thu Dec 30, 2010 11:35 am
Reply with quote

Quote:
Its like that only and that's why I used code given by David but now I want to know the process doing this.


So you want to know how the code (given by David) is working and what are the resposible processes which run behind the scene?
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Thu Dec 30, 2010 12:25 pm
Reply with quote

Hi MLP,

yes,I want to know the process which is changing the DD name dynamically and looking for answer of another query (I.e.
Quote:

2. As per my requirement,we had 2 file with same record structure and LRECL.File1 is opening in input mode and file 2 is in output mode.Now using CHGDDN,file1 is opened successfully but its not opening file2 in output mode and giving status code 41.
Then I placed DISPLAY statements in CHGDDN before & after MOVE statements in procedure division to check whether its processing with correct file.DISPLAY results showed that file2 is received by parameters(I.e. NEW-DDNAME,DDNAME2 & DDNAME).Now I m not aware of backend process so couldn't dig more in it.So please help.)
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Thu Dec 30, 2010 3:05 pm
Reply with quote

I still did not get what exactly you are doing. If I have to imagine then I think your are trying use two different files with same DDname at the same time and may be thats why your are getting file status as 41 for the second file (An OPEN operation has been tried on file already opened).

If you notice Dave has used the file descriptor name itself in the using caluse of the CALL statement.

Code:
CALL 'CHGDDN' USING TEST-FILE NEW-DDNAME.


Now this FD TEST-FILE is a pointer which points to a data structure or variable declaration which looks like below.

Code:

01  DCB.                                           
    05  FILLER             PIC X(40).             
    05  DDNAME             PIC X(8).               
    05  FILLER             PIC X(192).             
    05  DDNAME2            PIC X(8).               


The same variable declarartion is used in the linkage of CHNGDDN. Now in CHNGDDN you can modify the values of DDNAME and DDNAME2 with value in NEW-DDNAME. Once program contraol returns to the main program you have actually over-ridden the FILE CONTROL DDname.

Please note that this is my undestanding of the code shared by Dave and may require a verification.
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Fri Dec 31, 2010 11:26 am
Reply with quote

Hi MLP,

I would like to share complete scenerio with you.
I had 2 files(I.e. File1 & File2) with diffenent DD & FD names but same LRECL & structure.Now I want to open file1 in input mode and file2 in output mode.File1 opened successfully using CHGDDN but for file2 status code 41(file already opened) returned.Then I put display statements in CHGDDN and checked values of NEW-DDNAME,DDNAME & DDNAME2.It had DD name(which needs to be changes using CHGDDN) of file2,still file2 is not opened in output mode.
Now I don't understand the reason behind it so trying to know the execution process of CHGDDN to dig further in issue.Please let me know,if need any more info in this.
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Fri Dec 31, 2010 12:13 pm
Reply with quote

Few questions.

1) Did you pass the file descriptor of second (output) file to your CHNGDDN prog while changing the DDname for second file or did you used the same file descriptor as that of the first(input) file?

2) Are you trying the use the same DDname for both files using CHNGDDN prog?
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 Dec 31, 2010 12:21 pm
Reply with quote

Hello,

Quote:
I had 2 files(I.e. File1 & File2) with diffenent DD & FD names but same LRECL & structure.Now I want to open file1 in input mode and file2 in output mode.
Why does anyone in your organization believe this should be done by dynamically changing the ddname. . . Will your manager approve this code to be promoted?

As mentioned before, i see no reason for this convolution. There are 2 files (FD) and 2 data definitions (DD). Why not simply name them separately and proceed?
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Fri Dec 31, 2010 6:10 pm
Reply with quote

Hi All,

I wish A very Happy New Year to all.
icon_smile.gif
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 Jan 01, 2011 3:21 am
Reply with quote

And to you also!

"See" you next year. . . icon_smile.gif

d
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top