Chapter Contents |
Previous |
Next |
MOPEN |
Category: | Directory |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
file-id=MOPEN(directory-id,member-name<open-mode <,record-length<,record-format>>>); |
Type: Numeric
Type: Numeric
Type: Character
'A' |
APPEND mode, which allows writing new records after the current end of the file. |
'I' |
INPUT mode, which allows reading only. (This is the default.) |
'O' |
OUTPUT mode, which defaults to the OPEN mode that was specified in host-options in the FILENAME statement or function. If no host option was specified, then OUTPUT mode allows writing new records at the beginning of the file. |
'S' |
Sequential input mode, which is used for pipes and other sequential devices such as hardware ports. |
'U' |
UPDATE mode, which allows both reading and writing. |
Type: Character
Type: Numeric
'B' |
Interpret data as binary data. |
'D' |
Use the default record format. |
'E' |
Use an editable record format. |
'F' |
The file contains fixed-length records. |
'P' |
The file contains printer carriage-control characters in a host-dependent record format. |
'V' |
The file contains variable-length records. |
To use the existing record format, do not specify a value here.
Type: Character
Details |
The member file is identified by directory-id and member-name instead of by a fileref. You can also open a directory member by using FILENAME to assign a fileref to the member, followed by a call to FOPEN. However, using MOPEN saves you from having to use a separate fileref for each member.
If the file already exists and is opened with an open-mode of O, then the output mode defaults to either APPEND or REPLACE, based on host-options that were specified in the FILENAME function or statement. For example:
rc=filename('file',filename,' ','mod'); fid=fopen('file','o'); rc=fput(fid,'This is a test.'); rc=fwrite(fid); rc=fclose(fid);
If FILE already exists, then FWRITE appends a new record. However, if no host option was specified with the FILENAME function, then FWRITE writes the value at the beginning of the file, which could replace an existing value.
If the open fails, use SYSMSG to retrieve the message text.
Operating Environment Information: The term directory in this description refers to an aggregate grouping of files managed by the host operating system. Different host operating systems identify such groupings with different names, such as directory, subdirectory, MACLIB, or partitioned data set. See the SAS documentation for your operating environment for details.
Opening a directory member for output is not possible on some operating systems.
Example |
Assign the fileref MYDIR to a directory. Then open the directory, determine the number of members, retrieve the name of the first member, and open that member. The last three arguments to MOPEN are the defaults.
rc=filename('mydir','filename'); did=dopen('mydir'); frstname=' '; memcount=dnum(did); if (memcount>0) then do; frstname=dread(did,1); fid=mopen(did,frstname,'i',0,'d'); ...SCL statements to process the member... rc=fclose(fid); end; else _msg_=sysmsg(); rc=dclose(did);
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.