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

Dynamic File Creation in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Global Moderator


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

PostPosted: Wed Aug 29, 2007 6:30 pm
Reply with quote

Here's some previous topics for similar subjects:

ibmmainframes.com/viewtopic.php?t=1378
ibmmainframes.com/viewtopic.php?t=3895
ibmmainframes.com/viewtopic.php?t=5501
ibmmainframes.com/viewtopic.php?t=3194
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: 148
Location: Ottawa Canada

PostPosted: Tue Sep 04, 2007 11:40 pm
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

Superior Member


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

PostPosted: Wed Sep 05, 2007 11:19 am
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
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: 148
Location: Ottawa Canada

PostPosted: Wed Sep 05, 2007 10:39 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 8
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top