Simulating partitioned data sets

You can create memory files that are conceptually grouped as a partitioned data set (PDS). Grouping the files in this way offers the following advantages:

When you establish hat a memory file has members, you can rename and remove all the members by specifying the file name and no members, just as with a PDS or PDSE. None of the members can be open for you to perform this action. Once a memory file is created with or without a member, another memory file with the same name (with or without a member) cannot be created as well. For example, if you open memory file a.b and write to it, z/OS® XL C/C++ does not allow a memory file named a.b(c) until you close and remove a.b. Also, if you create a memory file named a.b(mbr1), you cannot open a file named a.b until you close and remove a.b(mbr1).

Sample program CCNGMF1 (Figure 1) demonstrates the removal of all the members of the data set a.b. After the call to remove(), neither a.b(mbr1) nor a.b(mbr2) exists.

Figure 1. Removing members of a PDS
/* this example shows how to remove members of a PDS */

#include <stdio.h>

int main(void)
{
   FILE * fp1, * fp2;
   fp1=fopen("a.b(mbr1)","w,type=memory");
   fp2=fopen("a.b(mbr2)","w,type=memory");
   fwrite("hello, world\n", 1, 13, fp1);
   fwrite("hello, world\n", 1, 13, fp2);
   fclose(fp1);
   fclose(fp2);
   remove("a.b");
   fp1=fopen("a.b(mbr1)","r,type=memory");
   if (fp1 == NULL) {
      perror("fopen():");
      printf("fopen(\"a.b(mbr1)\"...) failed as expected: "
             "the file has been removed\n");
   }
   else {
      printf("fopen() should have failed\n");
   }

   return(0);
}

Sample program CCNGMF2 (Figure 2) demonstrates the renaming of a PDS from a.b to c.d.

Figure 2. Renaming members of a PDS
/* this example shows how to rename a PDS */

#include <stdio.h>

int main(void)
{
   FILE * fp1, * fp2;

   fp1=fopen("a.b(mbr1)","w,type=memory");
   fp2=fopen("a.b(mbr2)","w,type=memory");
   fclose(fp1);
   fclose(fp2);
   rename("a.b","c.d");

/* after renaming, you cannot access members of PDS a.b */

   fp1=fopen("a.b(mbr1)","r,type=memory");
   if (fp1 == NULL) {
      perror("fopen():");
      printf("fopen(\"a.b(mbr1)\"...) failed as expected: "
             "the file has been renamed\n");
   }
   else {
      printf("fopen() should have failed\n");
   }

   fp2=fopen("c.d(mbr2)","r,type=memory");
   if (fp2 != NULL) {
      printf("fopen(\"c.c(mbr1)\"...) worked as expected: "
             "the file has been renamed\n");
   }
   else {
      perror("fopen():");
      printf("fopen() should have worked\n");
   }

   return(0);
}
Note: If you are using simulated PDSs, you can change either the name of the PDS, or the member name. You cannot rename a.b(mbr1) to either c.d(mbr2) or c.d, but you can rename a.b(mbr1) to a.b(mbr2), and a.b to c.d.
Memory files that are open as a sequential data set cannot be opened again with a member name specified. Also, if a data set is already open with a member name, the sequential data set version with only the data set name cannot be opened. These operations result in fopen() returning NULL. For example, fopen() returns NULL in the second line of the following:
   fp = fopen("a.b","w,type=memory");
   fp1 = fopen("a.b(m1)","w,type=memory");

You cannot use the rename() or remove() functions on open files.