%KEYVAL

Extract the value of an index file’s key from a record

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
contents = %KEYVAL(channel, record, keynum[, result])

Return value

contents

The contents of the referenced key, concatenated in key segment order. (a)

Arguments

channel

The number of the channel opened to an ISAM file on which the record is being processed. (n)

record

The record from which the key value will be extracted. (a)

keynum

The number of a key for the opened file. (n)

result

(optional) The variable that will be loaded with the contents of the referenced key. (a)

Discussion

%KEYVAL returns the value of an index file’s key from an existing record matching the layout in the file specified by channel. No file I/O is actually performed.

This function enables you to get an entire segmented key. If result is present, the return value is also returned in result.

You can use %KEYVAL even if your key isn’t segmented.

Examples

The following subroutine creates a temporary tag file to process data from an ISAM file. It reads through the file searching for records with a nonblank entry in a nonkey field. It then creates a temporary tag file and saves the RFA position of the ISAM record with the nonblank field. It sorts the temporary file using the alternate segmented key as the sort key, then extracts the appropriate records from the ISAM file in sorted order to pass to a print subroutine.

subroutine report
.define ISMCHN          ,10
.define TAGCHN          ,11
.define TAGFILE         ,"tagfile"
record ism_rec
    key0                ,a10
    key1a               ,a2
    ism_fld             ,a5
    key1b               ,d4
record tag_rec
    tag_rfa_1           ,a8
    tag_rfa_2           ,a4
    tag_sort            ,a6
record
    group rfa           ,a
      part1             ,a4
      part2             ,a2
    endgroup
proc
    open(ISMCHN, i:i, "isam")
    open(TAGCHN, o, TAGFILE)
    repeat
      begin
        reads(ISMCHN, ism_rec, done1, getrfa:rfa)               ;Read sequentially
                                                                ; by primary key
        if (ism_fld)
          begin
            tag_sort=%keyval(ISMCHN, ism_rec, 1)
            tag_rfa_1=%hex(rfa.part1, 4)
            tag_rfa_2=%hex(rfa.part2, 2)
            writes(TAGCHN, tag_rec)
          end
      end
done1,
    close TAGCHN
    sort(input=TAGFILE, key=tag_sort, record=tag_rec)
    open(TAGCHN, i, TAGFILE)
    repeat
      begin
        reads(TAGCHN, tag_rec, done2)
        rfa.part1=%x(tag_rfa_1)
        rfa.part2=%x(tag_rfa_2)
        read(ISMCHN, ism_rec, match:Q_RFA, rfa:rfa)
        xcall print_it(ism_rec)
      end
done2,
    close TAGCHN
    close ISMCHN
    xreturn
endsubroutine