View previous topic :: View next topic
|
Author |
Message |
Karthikeyan Subbarayan
New User
Joined: 24 Feb 2008 Posts: 62 Location: Boston
|
|
|
|
Hi,
Is there a way to open all files sequentially in few lines.
For eg i have file with names as File01, File02,....till File99
Instead of coding like below, is there a way to reduce the line of coding
Code: |
DCL FILE01 FILE RECORD OUTPUT;
DCL FILE02 FILE RECORD OUTPUT;
DCL FILE03 FILE RECORD OUTPUT;
.
.
.
DCL FILE99 FILE RECORD OUTPUT;
|
|
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
Code: |
DCL (FILE01, FILE02, ...
FILE98, FILE99) FILE RECORD OUTPUT; |
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Did you check the manual for syntax?
You can also open/close multiple files in the same sort of way. |
|
Back to top |
|
|
Karthikeyan Subbarayan
New User
Joined: 24 Feb 2008 Posts: 62 Location: Boston
|
|
|
|
Thanks, I know this .......
I thought, do we can open the file in a while loop since the file names are sequential ? .......
If we do in a loop then it is like dynamic right |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Use a pre-processor loop to write the code for you. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
hi..I was just wondering if we can use File Variable for opening..though it will still require the DECLARE statements for all of them..something like below:
Code: |
DECLARE OUTFILE FILE VARIABLE;
DECLARE COUNT PIC'99' INIT(0) ;
.
.
.
DO COUNT = 1 TO 99;
OUTFILE = 'FILE' || CHAR(COUNT);
OPEN FILE(OUTFILE);
END; |
I don't have access to Mainframe to test it..but just a thought which occured to me..will it work? |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
NO! |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
mistah kurtz wrote: |
hi..I was just wondering if we can use File Variable for opening..though it will still require the DECLARE statements for all of them..something like below:
Code: |
DECLARE OUTFILE FILE VARIABLE;
DECLARE COUNT PIC'99' INIT(0) ;
.
.
.
DO COUNT = 1 TO 99;
OUTFILE = 'FILE' || CHAR(COUNT);
OPEN FILE(OUTFILE);
END; |
I don't have access to Mainframe to test it..but just a thought which occured to me..will it work? |
To expand on Mr. Prins' answer, only a file (constant or variable) can be assigned to a file variable; you are attempting to assign a character string to it in your example. No can do. |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
You can, however, declare the individual files and a FILE VARIABLE as an array. The files can be assigned to the array elements and these can then be processed in a loop.....
Code: |
DCL MYFILE(3) FILE VARIABLE;
DCL FILE1 FILE RECORD OUTPUT;
DCL FILE2 FILE RECORD OUTPUT;
DCL FILE3 FILE RECORD OUTPUT;
MYFILE(1) = FILE1;
MYFILE(2) = FILE2;
MYFILE(3) = FILE3;
Do I = 1 to 3;
OPEN FILE(MYFILE(I));
End;
|
Garry |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Garry Carroll wrote: |
You can, however, declare the individual files and a FILE VARIABLE as an array. The files can be assigned to the array elements and these can then be processed in a loop.....
Code: |
DCL MYFILE(3) FILE VARIABLE;
DCL FILE1 FILE RECORD OUTPUT;
DCL FILE2 FILE RECORD OUTPUT;
DCL FILE3 FILE RECORD OUTPUT;
MYFILE(1) = FILE1;
MYFILE(2) = FILE2;
MYFILE(3) = FILE3;
Do I = 1 to 3;
OPEN FILE(MYFILE(I));
End;
|
|
And that just moves the typing from the open statements to the assignments.
Sigh... |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
prino wrote: |
Use a pre-processor loop to write the code for you. |
I believe that Mr. Prins has something like this in mind:
Code: |
foo42: proc options (main) reorder;
%dcl (i, #) fixed;
%dcl name char;
%do i = 1 to 99;
%name = 'FILE' || trim(i);
DCL NAME FILE RECORD OUTPUT;
OPEN FILE(NAME);
%end;
end foo42; |
|
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Akatsukami wrote: |
prino wrote: |
Use a pre-processor loop to write the code for you. |
I believe that Mr. Prins has something like this in mind:
Code: |
foo42: proc options (main) reorder;
%dcl (i, #) fixed;
%dcl name char;
%do i = 1 to 99;
%name = 'FILE' || trim(i);
DCL NAME FILE RECORD OUTPUT;
OPEN FILE(NAME);
%end;
end foo42; |
|
Do we really have to supply ready-made answers, why not force the wuckfits to open a manual themselves every now and then? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
prino wrote: |
Akatsukami wrote: |
prino wrote: |
Use a pre-processor loop to write the code for you. |
I believe that Mr. Prins has something like this in mind:
Code: |
foo42: proc options (main) reorder;
%dcl (i, #) fixed;
%dcl name char;
%do i = 1 to 99;
%name = 'FILE' || trim(i);
DCL NAME FILE RECORD OUTPUT;
OPEN FILE(NAME);
%end;
end foo42; |
|
Do we really have to supply ready-made answers, why not force the wuckfits to open a manual themselves every now and then? |
IMNSHO, the PL/I pre-processor is a slightly obscure topic. The average software engineer can no more learn to use it by reading the fine manual than heesh can learn PL/I itself that way, |
|
Back to top |
|
|
|