Highlighted
Honored Contributor.
Honored Contributor.
1505 views

"BY VALUE LENGTH OF directory-name SIZE 4" construct

Jump to solution

The Micro Focus Developer doc related to CBL_GET-CURRENT-DIR suggests this:   "Use the "BY VALUE LENGTH OF directory-name SIZE 4" construct to pass the name-length parameter."  Based on the explanation in the doc, if I have a MY-DIR-NAME PIC X(80 and a MY-DIR-NAME-LENGTH PIC 9(4) then I can MOVE LENGTH OF MY-DIR-NAME TO MY-DIR-NAME-LENGTH in order to initialize it to a value of 80 in this example.  My question is about the terminology and concept of the "Use the "BY VALUE LENGTH OF directory-name SIZE 4" construct.  I would like to see an example of this and/or any links to doc explaining this concept behind this construct.

Thanks!

OK, Update.

I now can see how it might be used.  Instead of setting up an actual MY-DIR-NAME-LENGTH variable in working storage to be initialized with the length of MY-DIR-NAME, you can just use the expression "BY VALUE LENGTH OF MY-DIR-NAME SIZE 4" as a phrase at the appropriate point in the CBL_GET_CURRENT_DIR library routine/command, thereby eliminating an extra variable and a separate statement to initialize it.  However, the "SIZE 4" part... where is this explained?

 Thanks,

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: "BY VALUE LENGTH OF directory-name SIZE 4" construct

Jump to solution

Hi Austin,

Certain dialects of COBOL (including the Micro Focus dialect)  support the use of a special register named "LENGTH OF". This is used in the form:

LENGTH OF MY-VARIABLE-NAME

and returns the size in bytes of the storage used by the variable MY-VARIABLE-NAME. So, instead of having to define a separate variable to contain the length value to be passed, you can use this register to determine the value on-the-fly. This also has the advantage that if you change the size of MY-VARIABLE-NAME, you don't have the housekeeping of also fixing the value of the associated variable where you've stored the length of MY-VARIABLE-NAME.

You can find the LENGTH OF special register documented here:

The SIZE keyword is actually an optional part of the CALL statement, when the BY VALUE phrase is used. The CALL BY VALUE essentially says  "let the called subprogram have its own copy of this value, rather than allowing it to access (and modify) the value here in the calling program". Since we are asking that the called routine be given its own copy, the SIZE option allows us to specify the size of the field that is dynamically created in that routine to hold this value. This is documented under General Rule 16 for the CALL statement here. Since the CBL_GET_CURRENT_DIR routine wants a 4 byte value passed that contains the size of the target field that will receive the directory name, we can use the SIZE option to make this dynamically created field that size.

Please let us know if you have any additional questions about this.

Blair McDonald

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: "BY VALUE LENGTH OF directory-name SIZE 4" construct

Jump to solution

Hi Austin,

Certain dialects of COBOL (including the Micro Focus dialect)  support the use of a special register named "LENGTH OF". This is used in the form:

LENGTH OF MY-VARIABLE-NAME

and returns the size in bytes of the storage used by the variable MY-VARIABLE-NAME. So, instead of having to define a separate variable to contain the length value to be passed, you can use this register to determine the value on-the-fly. This also has the advantage that if you change the size of MY-VARIABLE-NAME, you don't have the housekeeping of also fixing the value of the associated variable where you've stored the length of MY-VARIABLE-NAME.

You can find the LENGTH OF special register documented here:

The SIZE keyword is actually an optional part of the CALL statement, when the BY VALUE phrase is used. The CALL BY VALUE essentially says  "let the called subprogram have its own copy of this value, rather than allowing it to access (and modify) the value here in the calling program". Since we are asking that the called routine be given its own copy, the SIZE option allows us to specify the size of the field that is dynamically created in that routine to hold this value. This is documented under General Rule 16 for the CALL statement here. Since the CBL_GET_CURRENT_DIR routine wants a 4 byte value passed that contains the size of the target field that will receive the directory name, we can use the SIZE option to make this dynamically created field that size.

Please let us know if you have any additional questions about this.

Blair McDonald

View solution in original post

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: "BY VALUE LENGTH OF directory-name SIZE 4" construct

Jump to solution

Thanks!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.