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

Unable to create multiple files using BPXWDYN


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

New User


Joined: 19 Jan 2011
Posts: 15
Location: Toronto

PostPosted: Fri May 05, 2017 5:35 pm
Reply with quote

Hi,

I have a requirement to create multiple files based on input file. I have first tried to create two files using BPXWDYN, if it is successful thought of creating the actual program.

Now the problem is job is running fine with zero return code for calls to BPXWDYN but only one file is being created. Below is the code, please let me know where I am going wrong. Thanks for the help.

Code:

 IDENTIFICATION DIVISION.             
 PROGRAM-ID. XXXXXXXX.               
 ENVIRONMENT DIVISION.               
 INPUT-OUTPUT SECTION.               
 FILE-CONTROL.                       
     SELECT OT-FILE ASSIGN TO OTFILE 
     FILE STATUS FS.                 
 DATA DIVISION.                       
 FILE SECTION.                       
 FD  OT-FILE.                         
 01  OT-REC PIC X(80).               
 WORKING-STORAGE SECTION.             
 01  FS PIC X(02).                   
 01  FN PIC X(17).                   
 01  WS-ALLOC-STRING PIC X(100).     
 01  PGM PIC X(08) VALUE 'BPXWDYN'.   
 PROCEDURE DIVISION.                 
***  FILE 1                           
     MOVE 'XXXXXXX.TSTS.DYN1'    TO FN.               
     STRING 'ALLOC DD(OTFILE) DSN(' FN ') NEW '       
            'CATALOG ' 'LRECL(80) RECFM(F,B)'         
        DELIMITED BY SIZE                             
        INTO WS-ALLOC-STRING                           
     END-STRING.                                       
     DISPLAY ' WS-ALLOC-STRING *' WS-ALLOC-STRING '*' 
     CALL PGM                    USING WS-ALLOC-STRING.
     DISPLAY RETURN-CODE.                             
                                                       
     OPEN OUTPUT OT-FILE.                             
     MOVE 'MY REC1'              TO OT-REC.           
     WRITE OT-REC.                                     
     DISPLAY 'FS :' FS                                 
     CLOSE OT-FILE.                                   
                                                       
***  FILE 2                                           
     MOVE 'XXXXXXX.TSTS.DYN2'    TO FN.               
     STRING 'ALLOC DD(OTFILE) DSN(' FN ') NEW '       
            'CATALOG ' 'LRECL(80) RECFM(F,B)'       
         DELIMITED BY SIZE                           
        INTO WS-ALLOC-STRING                         
     END-STRING.                                     
     DISPLAY ' WS-ALLOC-STRING *' WS-ALLOC-STRING '*'
     CALL PGM USING WS-ALLOC-STRING.                 
     DISPLAY RETURN-CODE.                           
                                                     
     OPEN OUTPUT OT-FILE.                           
     MOVE 'MY REC2'              TO OT-REC.         
     WRITE OT-REC.                                   
     DISPLAY 'FS :' FS                               
     CLOSE OT-FILE.                                 
                                                     
     GOBACK.                                         
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri May 05, 2017 6:22 pm
Reply with quote

You need to call BPXWDYN with a request type of FREE after you close OT-FILE the first time. Otherwise, OTFILE remains allocated to your first file until the end of the job step (or job).
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri May 05, 2017 6:23 pm
Reply with quote

For a start you are using the same DDNAME for your allocated dataset (not a "file" on mainframe). Try using different DDNAMEs for each allocation.
Back to top
View user's profile Send private message
mbattu

New User


Joined: 19 Jan 2011
Posts: 15
Location: Toronto

PostPosted: Fri May 05, 2017 6:32 pm
Reply with quote

Thank you so much Robert. It worked when I used CLOSE command along with ALLOCATE.


Hi Nic, the reason I am using only one DDNAME is the number of files I use vary and can't be determined before. Using CLOSE command I can use the same for multiple files.

Thank you both for the response.
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 INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts How to create a list of SAR jobs with... CA Products 3
Search our Forums:

Back to Top