Multiple Dynamic file allocations in COBOL Program



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Multiple Dynamic file allocations in COBOL Program

Postby apjohn1986 » Tue Sep 23, 2014 6:36 pm

Hi All,

I need to split a file into multiple files (number of out files may vary from 1 to 50). so i use BPXWDYN to allocate files dynamically. I have allocated a file and write records into it and close, free the same. then allocate the new file (DSN) by using same file in FD section and write records into it.

In this, file allocation works fine. but when i FREE the DSN. its not working. can you please help on this?

below is the code i used to free the DSN.

MOVE 'FREE DSN('''HLQ1.BAL.REPORT.N001''') ' TO WS-PARM
CALL BPXWDYN USING WS-PARM

Thanks in advance for the help!
Thanks,
John
apjohn1986
 
Posts: 16
Joined: Mon Jan 31, 2011 12:26 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Multiple Dynamic file allocations in COBOL Program

Postby NicC » Tue Sep 23, 2014 8:32 pm

I have split this into its own topic because, as you know, you should start a new topic and not tailgate a topic that has been dead for 4 years.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Multiple Dynamic file allocations in COBOL Program

Postby steve-myers » Wed Sep 24, 2014 1:30 am

I don't know, for sure, why it doesn't work, but ...

does BPXWDYN FREE accept DSN as a keyword? The DSNAME keyword as an alias for the DATASET keyword is a fairly recent change in the TSO ALLOCATE and FREE commands, and BPXWDYN tends to trail the equivalent TSO commands. Note that BPXWDYN has its own scanner; it does not actually use the TSO commands. Try changing DSN to DATASET or perhaps DA.

Another thought. Does BPXWDYN provide a return code? It might be a good idea to obtain the return code and display it if possible. It's not a good idea for something like a BPXWDYN function that can fail for multiple reason not to provide a return code and for a program to continue running if the return code does not indicate success.

One more thought. Try finding the documentation for BPXWDYN for your z/OS release and see what it says about the DSN keyword.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Multiple Dynamic file allocations in COBOL Program

Postby apjohn1986 » Wed Sep 24, 2014 12:39 pm

Hi Steve,

The return code i am getting is -23.

Another note:
Before writing a file, i have verified that whether it is already present. if so, i have deallocate and free the file and then write it. FREE command is working fine after deallocation. but its not working after closing a file.
Thanks,
John
apjohn1986
 
Posts: 16
Joined: Mon Jan 31, 2011 12:26 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Multiple Dynamic file allocations in COBOL Program

Postby Robert Sample » Wed Sep 24, 2014 5:05 pm

The -23 indicates that you have a key error in the 3rd key. Look at what you are passing to BPXWDYN.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Multiple Dynamic file allocations in COBOL Program

Postby steve-myers » Wed Sep 24, 2014 6:39 pm

apjohn1986 wrote:... The return code i am getting is -23.

Another note:
Before writing a file, i have verified that whether it is already present. if so, i have deallocate and free the file and then write it. FREE command is working fine after deallocation. but its not working after closing a file.

You may have an issue with terminology. "Freeing" an allocation is the same as deallocating the allocation. What method are you using to determine if the data set is allocated?

For that matter, the spell check in Google Chrome claims "deallocation" or "deallocate" is not valid, though I use the word myself.

If you think about it, it is not too terribly important if the data set is allocated to your job when you start this sequence; what is probably more important is if the DD name you intend to use is is already allocated to your job. Then you have to free the DD name, not the data set. Similarly, when you allocate the data set you are - I hope - using ALLOCATE FILE(xxx) DSN('the data set'). Once you have done this, just free the DD name - use FREE FILE(xxx). I'm not a Cobol programmer; I use Assembler almost exclusively, so I do not use BPXWDYN. I have been using dynamic allocation, either TSO dynamic allocation before MVS, or MVS dynamic allocation. I generally do not specify a DD name in the allocation; I have allocation return the DD name it created for the allocation to me, and then use and free the DD name created by allocation. I use FRE DSN as a TSO command, but I can't recall that I have ever used FREE DSN as a direct use of dynamic allocation.

Does the documentation for BPXWDYN tell you what RC = -23 means?
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Multiple Dynamic file allocations in COBOL Program

Postby chaat » Mon Sep 29, 2014 4:26 am

John,

part of your issue is that BPXWDYN returns a 4 byte return / reason code in register 15. To capture this you need to use the "RETURNING" phrase on the CALL statement. If you send me a private message, I could email a sample of the source code i use for dynamic allocation.

      01  RC-RETURN-CODE-AREA.                                           
          05  RC-RETURN-CODE              PIC S9(8)   USAGE COMP.         
          05  RC-RETURN-CODE-X  REDEFINES  RC-RETURN-CODE.               
              10  RC-RETURN-CODE-HIGH.                                   
                  15  RC-RETURN-CODE-HIGH-BIN                             
                                          PIC S9(4)   USAGE COMP.         
              10  RC-RETURN-CODE-LOW.                                     
                  15  RC-RETURN-CODE-LOW-BIN                             
                                          PIC S9(4)   USAGE COMP.         


   CALL PGM-BPXWDYN USING BP-BPXWDYN-PARM-AREA-ALLOC     
                    RETURNING RC-RETURN-CODE.           


in my code I always use the following string to do the ALLOC and FREE statements. Notice that the FREE is using the FI phrase which matches what was used on the ALLOC and is the DDNAME.

    01  BP-BPXWDYN-PARM-AREA-FREE.                                           
        05  FILLER                      PIC S9(4) COMP  VALUE +20.           
        05  FILLER                      PIC X(24)                           
            VALUE ' FREE FI(DYNAM007)  '.                                   
                                                                             
    01  BP-BPXWDYN-PARM-AREA-ALLOC.                                         
        05  FILLER                      PIC S9(4) COMP  VALUE +105.         
        05  BP-ALLOC-LITERAL            PIC X(24)                           
            VALUE ' ALLOC FI(DYNAM007) DSN('.                               
        05  BP-DSN-AREA.                                                     
            10  BP-DSN-CHAR OCCURS 55 TIMES                                 
                            INDEXED BY BP-INDEX                             
                                        PIC X.                               
        05  FILLER                      PIC X(6)                             
            VALUE '  SHR '.                                                 
        05  BP-NORECALL                 PIC X(8).                           
        05  BP-MSG                      PIC X(12)                           
            VALUE ' MSG(WTP)   '.                                           



Chuck H.
chaat
 
Posts: 27
Joined: Sun Aug 16, 2009 11:07 pm
Location: St. Cloud, Minnesota
Has thanked: 0 time
Been thanked: 1 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post