0

I'm trying to access to a DataSet called X.Y.Z; my code is:

ZFile zFile = new ZFile("//X.Y.Z","r");
    try {
        String enc = ZUtil.getDefaultPlatformEncoding();
        InputStream is = zFile.getInputStream();
        BufferedReader rdr = new BufferedReader(new InputStreamReader(is, enc));
        String line;
        while ((line = rdr.readLine()) != null) {
            System.out.println(line);
        };
    }finally {
        zFile.close();
    }

I get this exception:

com.ibm.jzos.ZFileException: X.Y.Z: Filename is not a valid MVS dataset or DD name; errno=99 errno2=0x0 last_op=0 errorCode=0x0
    at com.ibm.jzos.ZFile.checkSecurityManager(ZFile.java:1592)
    at com.ibm.jzos.ZFile.<init>(ZFile.java:475)
    at it.Main.test(MainApp.java:20)
com.ibm.jzos.ZFileException: //'X.Y.Z': fopen() failed; EDC5049I The specified file name could not be located.; errno=49 errno2=0xc00b0641 last_op=50 errorCode=0x21708
    at com.ibm.jzos.ZFile.fopen(Native Method)
    at com.ibm.jzos.ZFile.doZFileOpen(ZFile.java:613)
    at com.ibm.jzos.ZFile.<init>(ZFile.java:476)
    at it.Main.test(MainApp.java:22)

Any suggestion? Thanks.

S-Wing
  • 485
  • 6
  • 25
  • Why not define the DD via JCL, and in your code specify the DD? Why did you tag `db2` for this question? – mao Sep 14 '20 at 08:13
  • I can't use the DD because I don't call this program whit the JCL; I have install this jar inside the db2 as an external stored procedure. – S-Wing Sep 14 '20 at 08:17
  • The exception seems clear, `'TSTCWLMY.L065291.SUN.JAVALOG'` is not found... (you cannot use read mode for a dataset that does not exist). – mao Sep 14 '20 at 08:20
  • The problem is that the file exist and the name is correct; could it be a problem of permission? – S-Wing Sep 14 '20 at 08:33
  • How do you check the file exists (and with which authid?). When the external sproc runs, a different authid may be involved so your assumptions might not be true. – mao Sep 14 '20 at 09:58
  • I have add a check for the file presence: ZFile.exists("//X.Y.Z") and the program return false ( the file doesn't exist for the program ) but again, the file is present. – S-Wing Sep 14 '20 at 10:08
  • 2
    if `X` is the high level qualifier try using `"//'X.Y.Z'"`. – meat Sep 14 '20 at 13:28
  • @meat That's correct; thank you very much. – S-Wing Sep 14 '20 at 14:08

1 Answers1

5

If the double slash notation is used to refer to a data set on z/OS, it assumes the data set's high level qualifier (HLQ) is the user id of the current user. For example, //X.Y.Z would resolve to MEAT.X.Y.Z assuming my username was my user id on z/OS. Quotes should be added if the data set specified is the fully-qualified data set name. In your case, //'X.Y.Z' would resolve to X.Y.Z.

meat
  • 609
  • 3
  • 8