View previous topic :: View next topic
|
Author |
Message |
nileshyp
New User
Joined: 22 Jun 2005 Posts: 65 Location: Mumbai
|
|
|
|
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 |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
Back to top |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
Yes - you can do exactly what you want to do using PUTENV. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
a69356
New User
Joined: 01 Dec 2006 Posts: 21 Location: Gurgaon
|
|
|
|
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 |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
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 |
|
|
|