NAME

stdio_cookbook - recipes and examples for the use of OS390::Stdio

DESCRIPTION

mvsopen() modes

The mode argument to mvsopen() corresponds to the mode argument to fopen() in the C programming language. From the C/C++ Run-Time Library Reference document we find:

"r"

Open a text file for reading. (The file must exist.)

"w"

Open a text file for writing. If the "w" mode is specified for a ddname that has DISP=MOD, the behavior is the same as if "a" had been specified. Otherwise, if the file already exists, its contents are destroyed.

"a"

Open a text file in append mode for writing at the end of the file. mvsopen() creates the file if it does not exist.

"r+"

Open a text file for both reading and writing. (The file must exist.)

"w+"

Open a text file for both reading and writing. If the "w+" mode is specified for a ddname that has DISP=MOD, the behavior is the same as if "a+" had been specified. Otherwise, if the file already exists, its contents are destroyed.

"a+"

Open a text file in append mode for reading or updating at the end of the file. mvsopen() creates the file if it does not exist.

"rb"

Open a binary file for reading. (The file must exist.)

"wb"

Open an empty binary file for writing. If the "wb" mode is specified for a ddname that has DISP=MOD, the behavior is the same as if "ab" had been specified. Otherwise, if the file already exists, its contents are destroyed.

"ab"

Open a binary file in append mode for writing at the end of the file. mvsopen() creates the file if it does not exist.

"rt"

Open a text file for reading. (The file must exist.)

"wt"

Open a text file for writing. If the file already exists, its contents are destroyed.

"at"

Open a text file in append mode for writing at the end of the file. mvsopen() creates the file if it does not exist.

"r+b" or "rb+"

Open a binary file for both reading and writing. (The file must exist.)

"w+b" or "wb+"

Open an empty binary file for both reading and writing. If the "w+b" (or "wb+") mode is specified for a ddname that has DISP=MOD, the behavior is the same as if "ab+" had been specified. Otherwise, if the file already exists, its contents are destroyed.

"a+b" or "ab+"

Open a binary file in append mode for writing at the end of the file. mvsopen() creates the file if it does not exist.

"r+t" or "rt+"

Open a text file for both reading and writing. (The file must exist.)

"w+t" or "wt+"

Open a text file for both reading and writing. If the file already exists, its contents are destroyed.

"a+t" or "at+"

Open a text file in append mode for writing at the end of the file. mvsopen() creates the file if it does not exist.

dynalloc() and dynfree() example

Here is an example of the use of dynalloc() and dynfree() with JCL DD card equivalent statements in comments on the right hand side:

use OS390::Stdio qw(&dynalloc &dynfree);
my %dyn_hash = (
    "ddname" => "MYDD",              # //MYDD DD
    "dsname" => "PVHP.MYDSN",        # //     DSN=PVHP.MYDSN,
    "status" => 4,                   # //     DISP=(NEW,   
    "normdisp" => 2,                 # //               CATLG),
    "alcunit" => '\001',             # //     SPACE=(CYL,
    "primary" => 2,                  # //             (2,
    "secondary" => 1,                # //               1),
    "misc_flags" => (2 | 8),         # //                RLSE,CONTIG),
    "dsorg" => 0x4000,               # //     DSORG=PS,
    "recfm" => 0x80 + 0x04 + 0x02,   # //     RECFM=FAM,
    "lrecl" => 121,                  # //     LRECL=121,
    "blksize" => 12100               # //     BLKSIZE=12100
);
if (dynalloc(\%dyn_hash)) {

    # use //'PVHP.MYDSN' data set

}
else {
    die "unable to dynalloc $dyn_hash{dsname}";
}
if (!dynfree(\%dyn_hash)) {
    warn "unable to dynfree $dyn_hash{dsname)}"
}

REFERENCES

The discussion of mvsopen() modes was adapted from:

EDCLB010: OS/390 V2R8.0 C/C++ Run-Time Library Reference
Table 21.  Values for the Positional Parameter