GNP command
The Get Next in Parent (GNP
) command is
used to retrieve dependent segments sequentially.
Format
- 1 If you leave out the SEGMENT option, specify the INTO option as shown.
- 2 Specify INTO on parent segments for a path command.
- 3 If you use multiple qualification statements, specify a length for each, using FIELDLENGTH. For example: FIELDLENGTH(24,8)
- 4 You can use either the KEYS option or the WHERE option, but not both on one segment level.
Options
You can qualify your GNP
command
by using SEGMENT and WHERE options.
If you do not qualify your command, IMS DB retrieves the next sequential segment under the established parent. If you include a SEGMENT option, IMS DB retrieves the first occurrence of that segment type that it finds by searching forward under the established parent.
GNP
command as there
are levels in the database's hierarchy. However, you should not qualify
your command in a way that causes DL/I to move off of the segment
type you have established as a parent for the command. - USING PCB(expression)
- Specifies the DB PCB you want to use for the command. Its argument can be any expression that converts to the integer data type; you can specify either a number or a reference to a halfword in your program containing a number.
- KEYFEEDBACK(area)
- Specifies an area into which the concatenated key for the segment is placed. If the area is not long enough, the key is truncated. Use this to retrieve a segment's concatenated key.
- FEEDBACKLEN(expression)
- Specifies the length of the key feedback area into which you want the concatenated key retrieved. Its argument can be any expression that converts to the integer data type; you can specify either a number or a reference to a halfword in your program containing a number. (It is required in COBOL programs and optional in PL/I and assembler language programs.)
- INTO(area)
- Specifies an area into which the segment is read. Use this to retrieve one or more segments with one command.
- VARIABLE
- Indicates that a segment is variable-length.
- FIRST
- Specifies that you want to retrieve the first segment occurrence of a segment type, or that you want to insert a segment as the first occurrence. Use this to retrieve the first segment occurrence of a segment type.
- LAST
- Specifies that you want to retrieve the last segment occurrence of a segment type, or that you want to insert a segment as the last segment occurrence. Use this to retrieve the last segment occurrence of a segment type.
- CURRENT
- Qualifies the command, and specifies that you want to use the level of and levels above the current position as qualifications for this segment. Use this to retrieve a segment based on your current position.
- SEGLENGTH(expression)
- Specifies the length of the I/O area into which the segment is
retrieved. Its argument can be any expression that converts to the
integer data type; you can specify either a number or a reference
to a halfword in your program containing a number. (SEGLENGTH is required
in COBOL programs for any SEGMENT level that specifies the INTO or
FROM option.)
Requirement: The value specified for SEGLENGTH must be greater than or equal to the length of the longest segment that can be processed by this call.
- OFFSET(expression)
- Specifies the offset to the destination parent. The argument can be any expression that converts to the integer data type; you can specify either a number or a reference to a halfword in your program containing a number. Use OFFSET when you process concatenated segments in logical relationships. OFFSET is required whenever the destination parent is a variable-length segment.
- LOCKED
- Specifies that you want to retrieve a segment for the exclusive use of your program, until a checkpoint or sync point is reached. Use this to reserve a segment for the exclusive use of your program. This option performs the same function as the Q command code, and it applies to both Fast Path and full function. A 1-byte alphabetic character of 'A' is automatically appended as the class for the Q command code.
- LOCKCLASS(class)
- Specifies that you want to retrieve a segment for the exclusive
use of your program until a
DEQ
command is issued or until a checkpoint or sync point is reached. (DEQ
commands are not supported for Fast Path.)Class
is a 1-byte alphabetic character (B-J), representing the lock class of the retrieved segment.For full-function code, the LOCKCLASS option followed by a letter (B-J) designates the class of the lock for the segment. An example is
LOCKCLASS('B')
. IfLOCKCLASS
is not followed by a letter in the range B to J, then EXECDLI sets a status code of GL and initiates an ABENDU1041.Fast Path does not support
LOCKCLASS
but, for consistency between full function and Fast Path, you must specifyLOCKCLASS('x')
), wherex
is a letter in the range B to J. An example isLOCKCLASS('B')
. IfLOCKCLASS
is not followed by a letter in the range B to J, then EXECDLI sets a status code of GL and initiates an ABENDU1041. - MOVENEXT(data_value)
- Specifies a subset pointer to be moved to the next segment occurrence after your current segment.
- GETFIRST(data_value)
- Specifies that you want the search to start with the first segment occurrence in a subset.
- SET(data_value)
- Specifies unconditionally setting a subset pointer to the current segment.
- SETCOND(data_value)
- Specifies conditionally setting a subset pointer to the current segment.
- SETZERO(data_value)
- Specifies setting a subset pointer to zero.
- SETPARENT
- Sets parentage at the level you want.
- WHERE(qualification statement)
- Qualifies the command, specifying the segment occurrence. Its
argument is one or more qualification statements, each of which compares
the value of a field in a segment to a value you supply. Each qualification
statement consists of:
- The name of a field in a segment
- The relational operator, which indicates how you want the two values compared
- The name of a data area in your program containing the value that is compared against the value of the field
- FIELDLENGTH(expression)
- Specifies the length of the field value in a WHERE option.
- KEYS(area)
- Qualifies the command with the segment's concatenated key. You
can use either KEYS or WHERE for a segment level, but not both.
Area
specifies an area in your program containing the segment's concatenated key. - KEYLENGTH(expression)
- Specifies the length of the concatenated key when you use the KEYS option. It can be any expression in the host language that converts to the integer data type; if it is a variable, it must be declared as a binary halfword value. For IBM® COBOL for z/OS® & VM (or VS COBOL II), PL/I, or assembler language, KEYLENGTH is optional. For COBOL programs that are not compiled with the IBM COBOL for z/OS & VM (or VS COBOL II) compiler, you must specify KEYLENGTH with the KEYS option.
- SEGMENT(name), SEGMENT((area))
- Qualifies the command, specifying the name of the segment type
or the area in your program containing the name of the segment type
that you want to retrieve, insert, delete, or replace.
You can have as many levels of qualification for a
GNP
command as there are levels in the database's hierarchy. Using fully qualified commands with the WHERE or KEYS option clearly identifies the hierarchic path and the segment you want, and is useful in documenting the command. However, you do not need to qualify aGNP
command at all, because you can specify aGNP
command without the SEGMENT option.Once you have established position in the database record, issuing a
GNP
command without a SEGMENT option retrieves the next segment occurrence in sequential order.If you specify a SEGMENT option without a KEYS or WHERE option, IMS DB retrieves the first occurrence of that segment type it encounters by searching forward from current position. With an unqualified
GNP
command, the segment type you retrieve might not be the one you expected, so you should specify an I/O area large enough to contain the largest segment your program has access to. (After successfully issuing a retrieval command, you can find out from DIB the segment type retrieved.)If you fully qualify your command with a WHERE or KEYS option, you would retrieve the next segment in sequential order, as described by the options.
Including the WHERE or KEYS options for parent segments defines the segment occurrences that are to be part of the path to the segment you want retrieved. Omitting the SEGMENT option for a level, or including only the SEGMENT option without a WHERE option, indicates that any path to the option satisfies the command. DL/I uses only the qualified parent segments and the lowest-level SEGMENT option to satisfy the command. DL/I does not assume a qualification for the missing level.
Usage
The Get Next in Parent
(GNP
) command makes it possible to limit the search
for a segment; you can retrieve only the dependents of a particular
parent. You must have established parentage before issuing a GNP
command.
Examples
Example 1We
need the complete record for Kate Bailey. Her patient number is 09080.
GU
command
to establish your position and parentage on the PATIENT segment for
Kate Bailey. Then continue to issue a GNP without SEGMENT or WHERE
options until DL/I returns all the dependents of that PATIENT segment.
(A GE status code indicates that you have retrieved all the dependent
segments.) To answer this request, your program can issue these commands:
EXEC DLI GU
SEGMENT(PATIENT) INTO(PATAREA)
WHERE (PATNO=PATNO1);
EXEC DLI GNP
INTO(ILLAREA);
A GNP
command
without SEGMENT or WHERE options retrieves the first dependent segment
occurrence under the current parent. If your current position is already
on a dependent of the current parent, this command retrieves the next
segment occurrence under the parent.
With an unqualified GNP
command,
the segment type you retrieve might not be the one you expected, so
you should specify an I/O area large enough to contain the largest
segment your program has access to. (After successfully issuing a GNP
command,
you can find out from the DIB the segment type retrieved.)
Which doctors have been prescribing acetaminophen for
headaches?
GNP
command
with only a SEGMENT option sequentially retrieves the dependent segments
of the segment type you have specified under the established parent.
Suppose that for this example, the key of ILLNESS is ILLNAME, and
the key of TREATMNT is MEDICINE. You want to retrieve each TREATMNT
segment where the treatment was acetaminophen. The name of the doctor
who prescribed the treatment is part of the TREATMNT segment. (Assume
that data area ILLNAME1 contains HEADACHE, and MEDIC1 contains ACETAMINOP).
To answer this request, you can issue these commands: EXEC DLI GN
SEGMENT(ILLNESS) WHERE (ILLNAME=ILLNAME1);
EXEC DLI GNP
SEGMENT(TREATMNT) WHERE (MEDICINE=MEDIC1);
To
process this, your program continues issuing the GNP
command
until DL/I returned a GE (not found) status code, then your program
retrieves the next headache segment and retrieves the TREATMNT segments
for it. Your program does this until there were no more ILLNESS segments
where the ILLNAME was headache.
Restrictions
Restrictions
for GNP
command:
- You must have established parentage before issuing this command.
- You cannot qualify your
GNP
command in a way that causes DL/I to move off of the segment type you have established as the parent for the command. - You can retrieve only the dependents of a particular parent.