TSO-ISPF JCL COBOL VSAM DB2 CICS IMS-DB Tools Articles Forum Quiz Interview Q&A

Random Retrieval(GU CALL)

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.

A GU call without SSA's:

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.

A GU call with unqualified SSA's:

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.

  1. 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.

  2. Now, let's see what happens when a DL/I call as the following one is issued,


    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.

A GU call with qualified SSA's:

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.

  1. Suppose, the customer whose number is DV0001 is to be retrieved, then the GU call is issued as follows :


  2. 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.

      		SHIPTO  (SHPTOSEQ='01')

Combination of qualified and unqualified SSA's:

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:

  1. 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.


  2. 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.


Missing hierarchical levels:

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 call with command codes:

Using C command code.


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:

   05 FILLER            PIC X(9) VALUE 'SHIPTO  *C('.
   05 SHIPTO-KEY-VAL    PIC X(2).
   05 FILLER            PIC X    VALUE ')'.

Using D command code:

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.


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.

F and L command codes:

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:

    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.

Using P command code:

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:


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!

Are you looking for Job Change? Job Portal