Skip to content

problem to get the zos file size #5

Open

Description

@matmass

Hi,

I don't find the way to get the file size for a Z/os sequential file in bytes or even in tracks.

How can I do that?

Regards,
Mathias.

Activity

  1. fjeremic commented on Mar 9, 2021

    @fjeremic

    To get a dataset size you can use the getLrecl API from the com.ibm.jzos package. You can find full documentation here:
    https://www.ibm.com/support/knowledgecenter/SSYKE2_7.0.0/com.ibm.java.zsecurity.api.70.doc/com.ibm.jzos/com/ibm/jzos/ZFile.html#getLrecl()

    There is an example of using the API to read entire contents of a dataset into a byte[] here:
    https://www.ibm.com/support/knowledgecenter/en/SSYKE2_7.1.0/com.ibm.java.zsecurity.api.71.doc/com.ibm.jzos/com/ibm/jzos/RecordReader.html

  2. matmass commented on Mar 10, 2021

    @matmass
    Author

    Thanks for the reply.

    So if I understand, we need to read the file and to count the bytes.

    It means that we can't get directly the file size as a property.

    Is-there any other way to get it?

    Regards,
    Mathias.

  3. fjeremic commented on Mar 10, 2021

    @fjeremic

    You do not need to read the whole dataset to get it's length. The example in the second link above does that, but if all you want is the length of the dataset you can just use getLrecl. What the second example does is it creates a RecordReader and uses getLrecl to get the size of the dataset, then it allocates a byte[] using the size and reads the entire dataset into the byte[].

    This is not what you need. You can just directly create a ZFile and use the API in my first link.

    Here is how the constructor of ZFile looks (with examples):
    https://www.ibm.com/support/knowledgecenter/SSYKE2_7.0.0/com.ibm.java.zsecurity.api.70.doc/com.ibm.jzos/com/ibm/jzos/ZFile.html#ZFile(java.lang.String,%20java.lang.String)

    So if your dataset is SYS1.HELP(ACCOUNT) as in the example, you can do:

    ZFile dsn = new ZFile("//'SYS1.HELP(ACCOUNT)'", "rt");
    int datasetSizeInBytes = dsn.getLrecl();
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions