Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Dynamic File Creation in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
nileshyp

New User


Joined: 22 Jun 2005
Posts: 65
Location: Mumbai

PostPosted: Wed Aug 29, 2007 2:10 pm    Post subject: Dynamic File Creation in COBOL
Reply with quote

Can we create file dynamically in COBOL depending on the required number of output files? For. e.g. I have a input files which contains 100000 records which I want to split 10000 records in each file. So in this case it will create 10 files. But is the same input file contains 500000 records it will create more files dynamically. Does anybody have any example on this?
Back to top
View user's profile Send private message

shreevamsi

Active User


Joined: 23 Feb 2006
Posts: 305
Location: Hyderabad,India

PostPosted: Wed Aug 29, 2007 2:31 pm    Post subject: Reply to: Dynamic File Creation in COBOL
Reply with quote

hi,

You can't create dynamic number of outputs in cobol which defines at run time!! All the DD names should be declared in a cobol program!!

How ever you can call a subroutine(probably an Assembler program or else) to create your required number of output dynamically!! Please check with your system administrator whether such programs exists in your shop.

~Vamsi
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Wed Aug 29, 2007 6:30 pm    Post subject: Reply to: Dynamic File Creation in COBOL
Reply with quote

Here's some previous topics for similar subjects:

http://ibmmainframes.com/viewtopic.php?t=1378
http://ibmmainframes.com/viewtopic.php?t=3895
http://ibmmainframes.com/viewtopic.php?t=5501
http://ibmmainframes.com/viewtopic.php?t=3194
http://ibmmainframes.com/viewtopic.php?t=6604
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 149
Location: Ottawa Canada

PostPosted: Tue Sep 04, 2007 11:40 pm    Post subject:
Reply with quote

Yes - you can do exactly what you want to do using PUTENV.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


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

PostPosted: Wed Sep 05, 2007 11:19 am    Post subject: Re: Dynamic File Creation in COBOL
Reply with quote

nileshyp wrote:
I have a input files which contains 100000 records which I want to split 10000 records in each file. So in this case it will create 10 files.
Do you always want to have 10,000 records in your output?

For this
nileshyp wrote:
But is the same input file contains 500000 records it will create more files dynamically.
yeah..it'll create 50 files now. So, what is your constraint number of files or number of records in files?
Back to top
View user's profile Send private message
a69356

New User


Joined: 01 Dec 2006
Posts: 21
Location: Gurgaon

PostPosted: Wed Sep 05, 2007 11:33 am    Post subject: Reply to: Dynamic File Creation in COBOL
Reply with quote

Yes - you can do exactly what you want to do using PUTENV.

Hi Murphy, Can you please give an example to explain above Statement ?

Regards
Ashish
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 149
Location: Ottawa Canada

PostPosted: Wed Sep 05, 2007 10:39 pm    Post subject:
Reply with quote

Code:
          FILE-CONTROL.
   A          SELECT OUTPUT-FILE ASSIGN UT-S-OUTFILE
                     FILE STATUS IS WS-FILE-STATUS.
   
          DATA DIVISION.
          FILE SECTION.
          FD  OUTPUT-FILE
              RECORDING MODE F
              BLOCK CONTAINS 0 RECORDS
              LABEL RECORDS ARE STANDARD.
          01  OUTPUT-RECORD    PIC X(80).
          WORKING-STORAGE SECTION.
                                                                          
          01 WS-EYE-CATCHER           PIC X(35) VALUE                     
              '*** WORKING STORAGE STARTS HERE ***'.                     
                                                                          
                                                                          
          01 WS-FILE-STATUS  PIC 9(2).
             88  WS-FILE-STATUS-OK                  VALUE 0.
             88  WS-FILE-STATUS-FILE-NOT-FOUND      VALUE 96.
   
          01 WS-RC                 PIC S9(9) BINARY.
          01 WS-ADDRESS-POINTER    POINTER.
   B      01 WS-ENVAR-DELETE-FILE  PIC X(120) VALUE
              Z"OUTFILE=DSN(MY.BIG.FILE) OLD DELETE  ".
         *                                                                 
   C      01 WS-ENVAR-CREATE-FILE  PIC X(120) VALUE
              Z"OUTFILE=DSN(RH.UT.OUTFILE) NEW CATALOG SPACE(3,20) TRACKS
         -    "UNIT(SYSDA)                                             ".
         *                                                                 
          PROCEDURE DIVISION.                                             
          000-MAINLINE SECTION.                                           
         *---------------------                                           
              PERFORM DELETE-FILE
              PERFORM CREATE-NEW-FILE
              STOP RUN.
         *
         *
         *
          DELETE-FILE SECTION.
         *---------------------
   D          SET WS-ADDRESS-POINTER TO ADDRESS OF WS-ENVAR-DELETE-FILE
              CALL "PUTENV" USING BY VALUE WS-ADDRESS-POINTER
                   RETURNING WS-RC
              IF WS-RC NOT = 0
                  DISPLAY "PUTENV FAILED " WS-RC
                  STOP RUN
              END-IF
   
              OPEN OUTPUT OUTPUT-FILE
              IF WS-FILE-STATUS-OK
                 CLOSE OUTPUT-FILE
                 IF NOT WS-FILE-STATUS-OK
                    DISPLAY "ATTEMPT TO CLOSE FILE FAILED " WS-FILE-STATUS
                    STOP RUN
                 END-IF
              ELSE
         *       *---------------------------------------------------------
         *       * If the file we attempted to delete did not exist, then
         *       * do not abend - just continue along.
         *       *---------------------------------------------------------
                 IF WS-FILE-STATUS-FILE-NOT-FOUND
                    CONTINUE
                 ELSE
         *          *------------------------------------------------------
         *          * OPEN error.  Abend the program.
         *          *------------------------------------------------------
                    DISPLAY "BAD FILE STATUS ON ATTEMPT TO DELETE FILE "
                             WS-FILE-STATUS
                    STOP RUN
                 END-IF
              END-IF
   
              .
         *
         *
         *
          CREATE-NEW-FILE SECTION.
         *------------------------
              SET WS-ADDRESS-POINTER TO ADDRESS OF WS-ENVAR-CREATE-FILE
              CALL "PUTENV" USING BY VALUE WS-ADDRESS-POINTER
                   RETURNING WS-RC
              IF WS-RC NOT = 0
                  DISPLAY "PUTENV FAILED " WS-RC
                  STOP RUN
              END-IF
   
              OPEN OUTPUT OUTPUT-FILE
              IF NOT WS-FILE-STATUS-OK
                 DISPLAY "BAD FILE STATUS ON ATTEMPT TO OPEN FILE "
                          WS-FILE-STATUS
                 STOP RUN
              END-IF
              DISPLAY "OUTPUT-FILE-STATUS=" WS-FILE-STATUS
              PERFORM 10 TIMES
                 MOVE SPACES TO OUTPUT-RECORD
                 STRING "MY OUTPUT RECORD " FUNCTION CURRENT-DATE
                   DELIMITED BY SIZE
                   INTO OUTPUT-RECORD
                 WRITE OUTPUT-RECORD
              END-PERFORM
              CLOSE OUTPUT-FILE
              IF NOT WS-FILE-STATUS-OK
                 DISPLAY "ATTEMPT TO CLOSE FILE FAILED " WS-FILE-STATUS
                 STOP RUN
              END-IF
              .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Changing of LRECL of a file abdulrafi DFSORT/ICETOOL 2 Fri Mar 24, 2017 3:25 pm
No new posts splitting a file abdulrafi DFSORT/ICETOOL 3 Fri Mar 24, 2017 11:51 am
No new posts Receive a file using PCOMM macro Harald.v.K IBM Tools 0 Thu Mar 23, 2017 6:50 pm
No new posts Export flat file data into excel sheet murali.andaluri DFSORT/ICETOOL 2 Mon Mar 20, 2017 5:39 pm
No new posts Formatting VB File Learncoholic DFSORT/ICETOOL 3 Mon Mar 20, 2017 12:29 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us