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.
/* 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.
/* 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);
}
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.