Random processing using DL/I is similar to random processing with standard files. GU function code is used for random processing. The GU call establishes the parentage at lowest level segment in the hierarchy.
When a GU call is issued without an SSA, then DL/I assumes an unqualified SSA for the root segment and therefore, retrieves the first occurrence of the root segment. In the CUSTOMER database, the first occurrence of the CUSTOMER segment i.e. the C1 segment, is retrieved.
An unqualified SSA with the GU function code indicates to DL/I that we are interested in the first occurrence of that segment type in the database.
Suppose, a GU call is issued on the CUSTOMER segment with an unqualified SSA as shown below. Let's see what happens
Note that a blank is left over after the segment name CUSTOMER.
When such a call is issued, DL/I retrieves the first occurrence of the CUSTOMER segment type in the CUSTOMER database i.e the C1 segment is retrieved.
Now, let's see what happens when a DL/I call as the following one is issued,
GU CUSTOMER SHIP-TO RECVABLE
DL/I retrieves the first occurrence of the RECVABLE segment i.e. the R1 segment, under the first occurrence of the SHIPTO segment i.e. the S1 segment, under the first occurrence of the CUSTOMER segment i.e. the C1 segment.
When we know exactly which segment occurrence is to be retrieved, i.e. the key is known, then fully qualified SSA's can be used.
Suppose, the customer whose number is DV0001 is to be retrieved, then the GU call is issued as follows :
GU CUSTOMER(CUSTNUM ='DV0001')
Similarly, to retrieve the SHIPTO segment where the shipto sequence num is '01' for the customer DV0001, a GU call can be issued as follows.
GU CUSTOMER(CUSTNUM ='DV0001') SHIPTO (SHPTOSEQ='01')
Qualified and unqualified SSA's can be combined, in any way, while issuing a GU call. The way DL/I handles such calls depend on the level at which unqualified SSA's are coded. Let's see what would be the effect of the following GU calls:
In this case, the first RECVABLE segment i.e. segment R1, under the SHIPTO segment whose sequence no is '01' which is under customer DV0001, is retrieved.
GU CUSTOMER(CUSTNUM ='DV0001') SHIPTO(SHPTOSEQ='01') RECVABLE
In this case, DL/I scans CUSTOMER and SHIPTO segments from the begining of the database, and finally reaches the RECVABLE segment, if any present, whose invoice num is '123456' for those CUSTOMER and SHIPTO segment values. From this it is evident that such GU calls are very expensive.
GU CUSTOMER SHIPTO RECVABLE(RSINVNUM='123456')
It is possible to make retrieval calls without supplying SSA's for each level in the hierarchy above the segment, like the one given below:
If such call is issued, then DL/I assumes unqualified SSA's for each of the segment up in the hierarchy above. Thus, above call is equivalent to:
GU CUSTOMER SHIPTO RECVABLE(RSINVNUM='123456')
Using C command code.
GU CUSTOMER(CUSTNUM ='DV0001') SHIPTO(SHPTOSEQ='01')
The C command code is used when the full key of a segment is known. Instead of specifying CUSTOMER and SHIPTO key values seperately, as shown above, both key value can be concatenated and can be given in GU call with C command code as shown below.
GU SHIPTO *C(DV000101)
Note that the all the key values are concatenated together. For this, the SSA may be coded in the working-storage section of the program like this:
01 CON-SHIPTO-SSA. 05 FILLER PIC X(9) VALUE 'SHIPTO *C('. 05 CUSTOMER-KEY-VAL PIC X(6). 05 SHIPTO-KEY-VAL PIC X(2). 05 FILLER PIC X VALUE ')'.
Generally the details of last segment are retrieved into the I/O area. Using D command code, the details of the parent segments can also be retrieved into the I/O area. The example shown below retrieves both the segment details into the I/O area.
GU CUSTOMER*D(CUSTNUM ='DV0001') SHIPTO(SHPTOSEQ='01')
Note here that the D command code is not specified for SHIPTO segment, since anyway DL/I retrieves the SHIPTO segment. Since, more than one command code can be specified for an SSA, a GU call along with C command code can also can be issued as follows:
GU SHIPTO *CD(DV000101)
This call also has the same effect as the previous call.
A GU call with F or L command codes with a fully qualified SSA is meaningless. But, they can be used to retrieve the first or last occurrences of a segment as follows:
GU CUSTOMER(CUSTNUM=DV0001) SHIPTO *L
By issuing a GU call as the one above, the last segment occurrence of SHIPTO segment under the CUSTOMER segment whose customer num is DV0001 is retrieved.
Similarly, F command code can be used to retrieve the first occurrence of a segment.
Since, the GU call establishes the parentage at the lowest level segment in the hierarchy, to set the parentage at any other segment up in the hierarchy, a P command code is used. For example:
GU CUSTOMER*P(CUSTNUM=DV0001) SHIPTO
In the above case, the parentage is established at the CUSTOMER segment.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on IBMMainframer Community!