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

Can I dynamically change an File DDNAME in COBOL?


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

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Fri Mar 31, 2006 3:28 am
Reply with quote

We code a file control statement as
SELECT <filename> ASSIGN TO <ddname>
where DDNAME is assigned to a DSN in the JCL.

Can I in COBOL, change the file name associated to the DDNAME?

ie if <ddname> is assigned to <file01> in the JCL, can I change it to point to <file02> in COBOL?
Back to top
View user's profile Send private message
Pollyannaish

New User


Joined: 09 Jul 2005
Posts: 31
Location: Pune, India

PostPosted: Fri Mar 31, 2006 10:23 am
Reply with quote

new2cobol wrote:


ie if <ddname> is assigned to <file01> in the JCL, can I change it to point to <file02> in COBOL?


I am not sure of COBOL but a simple solution to this is use symbolic parameter in JCl to change the DDNAME dynamically.......


Let me know if this helps you..
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Fri Mar 31, 2006 6:02 pm
Reply with quote

hy there,

you cannot change the ddname dynamically,
or any association from select clause to the jcl's ddname.
as long you do not allocate any dataset dynamically
by your program, this is not possible...

martin9
Back to top
View user's profile Send private message
new2cobol

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Sat Apr 01, 2006 2:19 am
Reply with quote

Ok, let me explain.

I am dynamically allocating a dataset in my COBOL program and I want to write int the file using COBOL's WRITE. I could have use an in-house assembler utility to write, but it takes 5 times the cpu time than a COBOL Write takes, and I am talking about writing 250-300 million records in each files and there are a total of 10-15 files.

I saw in UNISYS systems, the COBOL they use has a CHANGE ATTRIBUTE FILENAME command in the COBOL they use, which dynamically re-allocates the DDNAME with a different File.

I was wondering whether there was an MVS way to do this, I know there is know COBOL keywords for this, but if there is some utility which does this...

Any info icon_question.gif
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Apr 01, 2006 2:38 am
Reply with quote

new2cobol,

I didn't read your requirements close enough, so I don't think this is what you want, but I'll post it anyway. This will change the DDNAME associated with an "FD"



This works for me, but I have only used it once. Maybe it wont work on all types of files.

Code this subroutine:

Code:


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.                                       



Call like this:

Code:


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.




See if this works for you.

Dave,
Back to top
View user's profile Send private message
new2cobol

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Sun Apr 02, 2006 2:05 am
Reply with quote

Thanks Dave,

But I guess it won't fit into my requirement. Your code still points to same physical file; you are only changing the logical file. But thanks anyway... icon_smile.gif
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sun Apr 02, 2006 9:36 am
Reply with quote

new2cobol,

I'm still a little confused about what you want to accomplish, (the bulb burns dimly sometimes).

In your COBOL program you have a select that makes the relationship between your FD entry and the DDNAME/DSNAME (Physical file on disk).

Do you want to change the DDNAME the FD has the relationship to, or do you want to change the DSNAME the DDNAME has the relationship to, or other.

You also said that you are dynamically allocating the dataset in you Cobol program. What method are you using to accomplish this?

Maybe you could give a Pseudo code example.


Please come back

Dave
Back to top
View user's profile Send private message
gowrishankars

New User


Joined: 27 Mar 2006
Posts: 4
Location: pune

PostPosted: Sun Apr 02, 2006 10:55 pm
Reply with quote

HI new2cobol,
I think you can do that.
Check the following logic.
You have to use two cobol programs.
Step1:Write the cobol program(2) which contains cobol READ and WRITE commands.
Step2:a.Write cobol program(1) in which you have to write the entire JCL
to compile the cobol program(2)and display that in spool.
b.Use ACCEPT to accept the DSNNAME.
c. Put a,b in a loop.
Step3: Write the main JCL with INTRDR and pass the list of
DSNNAMES thru SYSIN DD.

Corrections and suggestions welcome.

Gowri
Back to top
View user's profile Send private message
new2cobol

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Mon Apr 03, 2006 6:39 pm
Reply with quote

Hey Dave,
Let me explain my problem a bit.

I have this input file which has 200 - 300 million records. I need to format them and load them to a storage. The Data storage to which I load the file, can accept only files of X size. So I have to load a file which has 20 million records max.

So I open the file reformat the record and write it in to a new output file. When the count reaches 20 million, I close the output file and allocate a new file, open it and start writing into it.

Now I've done all these with assembler utilities which my shop provides, but the job takes a hell lot of time to run. So what I need to do is use COBOL WRITE keyword to reduce the CPU time it takes.

Now I can declare one file, say file01 and declare it in JCL as
Code:

//DD1  DD  DSN=A.B.C.FILE01,...


And have corresponding cobol File control and file sections as
Code:

SELECT OUTFILE ASSIGN TO DD1
....
....

FD OUTFILE
       RECORDING MODE IS F.
01 OUTREC.
    05  FILLER           PIC X(133).


Now, I successfully write in 20 million records and close this file. I dynamically allocate another file with my assembler utility, viz. A.B.C.FILE02. Now to access the new file using the same FD, the JCL DD1 statement should point to A.B.C.FILE02.

OR

I should have some way to dynamically code an FD statement while the code is in execution.

I guess you all got a gist of my problems ... Whacking my head for a solution...
Back to top
View user's profile Send private message
new2cobol

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Mon Apr 03, 2006 6:42 pm
Reply with quote

Gowri,

With all due respect, I did not understand what you were trying to explain here...

Is it that I couldn't comprehend what you keyed in or did you completely miss the target?
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Mon Apr 03, 2006 7:55 pm
Reply with quote

new2cobol,

I think I understand what you are trying to accomplish now.

In your Assembler subroutine, when you allocate a new file, you must also have to give it a DDNAME to access it through? i.e.

CALL 'ALLOC' USING 'DDNAME','YOUR.OUTPUT.FILE'. ?

Two solutions come to mind.

If your shop has an allocate subroutine, it probably has a de-allocate subrotine also.

After Closing the first file, de-allocate it, allocate the second file to DD1, re-open and continue.

or, if a de-allocate routine is not available,

After closing the first file, Allocate the second file to DD2, use the subroutine above to re-assign the FD to DD2, open and continue.

or am I again missing something?

Please come back, I'm sure this is solvable.


Dave
Back to top
View user's profile Send private message
new2cobol

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Mon Apr 03, 2006 8:40 pm
Reply with quote

Yes Dave, I am passing the DDNAME and File name to the assembler utility. Let me check upon the "de-allocate" options I have icon_biggrin.gif

Thanks a lot for the response!!!
Back to top
View user's profile Send private message
new2cobol

New User


Joined: 04 Jan 2006
Posts: 77
Location: Bangalore

PostPosted: Mon Apr 03, 2006 10:18 pm
Reply with quote

Dave. Sir.

YOU ARE A LIFE-SAVER!!! icon_biggrin.gif icon_biggrin.gif

The second option you provided worked icon_idea.gif ! Now let me get some info from you...

The "DCB" you coded was the 248 char long was the FD section argument, which has the DD name at two places... what does the fillers include? is it file name? icon_idea.gif
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Mon Apr 03, 2006 11:54 pm
Reply with quote

New2cobol,

I followed your query about PUTENV. I think this will suit you to a ?T?. The routine I gave you is old and was designed to re-assign the DDNAME only. The PUTENV subroutine is new with Enterprise Cobol. I just tried this and it does work well. Follow the code in the Other Post by dmmadsen.



Check this link for other allocation options for PUTENV

Assignment name for environment variable

If you have trouble with it, or have questions, please come back.

Well, come back anyway and let us know how it works for you.

Good luck,

Dave
Back to top
View user's profile Send private message
salehi

New User


Joined: 30 Sep 2006
Posts: 14
Location: Iran

PostPosted: Thu Jan 29, 2009 1:16 pm
Reply with quote

Hi,
This can be done using some integration between COBOL and PL1 or any other program which is able to change the DD statement dynamically through using ISPF command.
Your program shoukd CALL the second program which change the DD statement dynamically anywhere he needs.
Try using INTEGRATION techniques ..
Back to top
View user's profile Send private message
lohithegde

New User


Joined: 18 May 2008
Posts: 31
Location: Chennai

PostPosted: Thu Jan 29, 2009 3:31 pm
Reply with quote

Hi New2Cobol

Normally we wont change the FIlenames in Cobol,and we will try to change in JCL

To change in JCL Dynamically we use Rexx to do that

Regards
Lohit
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 Jan 29, 2009 9:12 pm
Reply with quote

Hello salehi,

It is best to reply to current topics rather than a topic that has been inactive for almost 3 years. . .

d
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Tue Mar 03, 2009 12:46 pm
Reply with quote

I use BPXWDYN for this. It's similar to putenv but I have less trouble with it and you don't have to worry about the dynamic vs static call to putenv.
Back to top
View user's profile Send private message
mfguy01

New User


Joined: 06 Sep 2010
Posts: 30
Location: India

PostPosted: Thu Dec 23, 2010 9:51 am
Reply with quote

Hi,

I went through this thread to work on one of requirements and had 2 queries :-
1.
For David,
Its about dynamically changing dd name.I used routine provied by you(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 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 need to help.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Dec 23, 2010 12:50 pm
Reply with quote

This topic has been happily dormant for 21 months.

If you have a question, please start a new topic.
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 Dec 23, 2010 8:33 pm
Reply with quote

Hello,

And it has been nearly 4 years since David last posted. . .
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 FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top