IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Write to sequence of files


 
IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Karthikeyan Subbarayan

New User


Joined: 24 Feb 2008
Posts: 62
Location: Boston

PostPosted: Wed Aug 07, 2013 11:00 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Aug 07, 2013 11:12 pm
Reply with quote

Code:
DCL (FILE01, FILE02, ...
     FILE98, FILE99)                    FILE RECORD OUTPUT;
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Wed Aug 07, 2013 11:18 pm
Reply with quote

Did you check the manual for syntax?

You can also open/close multiple files in the same sort of way.
Back to top
View user's profile Send private message
Karthikeyan Subbarayan

New User


Joined: 24 Feb 2008
Posts: 62
Location: Boston

PostPosted: Wed Aug 07, 2013 11:36 pm
Reply with quote

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 icon_sad.gif
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1224
Location: Vilnius, Lithuania

PostPosted: Thu Aug 08, 2013 1:20 am
Reply with quote

Use a pre-processor loop to write the code for you.
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 310
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Thu Aug 08, 2013 10:53 am
Reply with quote

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
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1224
Location: Vilnius, Lithuania

PostPosted: Thu Aug 08, 2013 2:53 pm
Reply with quote

NO!
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Aug 08, 2013 4:13 pm
Reply with quote

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
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1097
Location: Dublin, Ireland

PostPosted: Thu Aug 08, 2013 5:18 pm
Reply with quote

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
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1224
Location: Vilnius, Lithuania

PostPosted: Thu Aug 08, 2013 10:14 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Aug 08, 2013 10:37 pm
Reply with quote

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
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1224
Location: Vilnius, Lithuania

PostPosted: Thu Aug 08, 2013 11:00 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Aug 08, 2013 11:10 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts JOINKEYS to match two input files on ... DFSORT/ICETOOL 3
No new posts Hexadecimal Group compare and write t... DFSORT/ICETOOL 5
No new posts Group comparison/update between two f... DFSORT/ICETOOL 10
No new posts Need assistance formatting when joini... SYNCSORT 8
No new posts Combining more 4 files with sorted or... DFSORT/ICETOOL 3

Back to Top