The GN and GNP function codes are used for sequential processing. The differrence between these function codes are as follows:
GN call establishes the parentage at the lowest level segment. Where as the GNP call doesn't establish the parentage.
The GN call retrieves the next segment occurrence in the database.( In this case the segment type may change.) Where as the GNP call retrieves only the segment occurrence that are under the parent segment.
Before issuing a GNP call, a GU or GN call must be issued to establish the parentage. There is no such restriction for issue of GN call.
When a GN call is issued without an SSA, then DL/I retrieves the next segment occurrence in the database from the current position. Thus, if the call is the first call issued then, DL/I retrieves the first CUSTOMER segment occurrence, which is the root segment, in the database. (i.e. the C1 segment which is the first segment occurrence.) Subsequent GN calls retrive the other segment occurrences in the database. Thus, DL/I retrieves the segments C1, S1, B1, B2, S2, C2 etc., in that order until end of the database.
Step1 : GU SHIPTO Step2 : GN |
In Step1 the first SHIPTO segment i.e. S1 segment, is retrieved. The GN call in Step2 retrieves the B1 BUYER segment, which is the next segment occurrence after the S1 segment. The next GN call will retrieve the B2 Buyer segment and the next GN call retrieves the the R1 RECVABLE segment, and so on.
When an unqualified GN call is issued, DL/I would retrieve the first occurrecne of that segment type in the database, if the call is the first one issued in the program. Thus, the following GN call would retrieve the first SHIPTO segment occurrence i.e. S1 segment.
GN SHIPTO |
If the above GN call is issued repeatedly, then all the SHIPTO segment occurrences in the database are retrieved one after the other from the current position, i.e. the segments S1, S2, S3 and S4.
A GN call with qualified SSA has the same effect as that of a GU call with qualified SSA. The following two calls retrieve the same segment.
GU CUSTOMER(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') |
and
GN CUSTOMER(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') |
Both the calls retreive the same SHIPTO segment. The difference between the GU and GN calls with qualified SSA's is that GN call is used to perform skip-sequential-processing.
When skip-sequential processing is performed, DL/I selects segment occurrences in hierarchical sequence. i.e. in the key sequence. For the GN call shown below, DL/I retrieves the the SHIPTO segment which has sequence num as '02'.
GN CUSTOMER(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='02') |
Now, for one more GN call issued, which is shown below, DL/I gives a GE error status indicating that the required SHIPTO segment doesn't exist, though it is very much existing. This is because, the key value specified in the second call is not in the key sequence. It can be said that, if a GN call is issued with a key value lower than the one specified in the previous call, DL/I cannot retrieve the segment. Remember that IMS stores the segments in the increasing key value sequence. When using GU call, IMS backs up in the database, if necessary, to locate the segment.
GN CUSTOMER(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') |
GN CUSTOMER(CUSTNUM ='DV0001') SHIPTO(SHPTOSEQ='01') RECVABLE |
For the above GN call, IMS retrieves the first RECVABLE segment occurrence under the SHIPTO segment whose sequence num is 01.
The GU call establishes the parentage. The subsequent GNP call retrieves the segment which is the child segment of CUSTOMER. If Step2 is repeated, all the segments under CUSTOMER (DV0001) are retrieved sequentially. Thus, the segments S1, B1, B2, R1, P1, P2, A1, A2, L1, L2, R2, R3, A3 and S2 are retrieved sequentially.
Step1 : GU CUSTOMER(CUSTNUM ='DV0001') Step2 : GNP |
A GNP call with SSA retrieves only the segments of a specific type under the segment at which the parentage is established. Consider the following steps.
Step1 : GU CUSTOMER(CUSTNUM ='DV0001') Step2 : GNP SHIPTO |
DL/I retrieves only the SHIPTO segments under the CUSTOMER segment having num DV0001.
In below example, Parentage is set at CUSTOMER segment. Generally GNP call retrieves the next available segment of that parent. Since qualified SSA is given for the GNP call, it retrieves the specific segment under that parent.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO(SHPTOSEQ='01') RECVABLE(RSINDATE='010194') |
To, retrieve the CUSTOMER segment also along with SHIPTO segment, the D command code is used as follows:
GN CUSTOMER*D(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') |
Similarly, CUSTOMER and SHIPTO segments can be retrieved along with RECVABLE segment, as follows:
GN CUSTOMER*D(CUSTNUM ='DV0001') SHIPTO*D(SHPTOSEQ='01') RECVABLE |
The N command code has no effect if used with a GN call. DL/I simply ignores it. Thus, a GN call as follows behaves as if only a D command code is used:
GN CUSTOMER*DN(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') |
The F and L command code retrieve the first or last segment occurrence. Consider the following two calls. One is a GN call and the other is a GNP call.
GN CUSTOMER(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') RECVABLE*L |
and
GNP CUSTOMER(CUSTNUM='DV0001') SHIPTO(SHPTOSEQ='01') RECVABLE*L |
In both the above calls the last RECVABLE segment occurrence, i.e., R3, is retrieved. The only difference is that In case of the GN call the parentage is established at the R3 segment and when the GNP call is issued the parentage is not set at R3 instead parentage remains at the same location where it was earlier.
All the SHIPTO segment occurrences under CUSTOMER DV0001 can be retrieved by issuing a GU call for CUSTOMER and then a series of GNP calls for SHIPTO segment, as follows.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO |
No doubt that the above steps retrieves all the SHIPTO segments. Since, any DL/I call is expensive, if at least one call can be avoided it is better to avoid. The P command code can be used for this purpose as follows.
Step1 : GU CUSTOMER*P(CUSTNUM='DV0001') SHIPTO Step2 : GNP SHIPTO |
Thus, one DL/I call is avoided. The P command code is used at CUSTOMER segment as that is the place where the parentage needs to be established.
The U and V command codes provide control over moving forward in the database when issuing GN or GNP calls. They can be used to prevent a GN or GNP call from leaving the current position.
Suppose if all the RECVABLE segments for each SHIPTO segment under CUSTOMER DV0001 are to be retrieved. The following is one possible call sequence.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO Step3 : GNP RECVABLE |
(Step2 and Step3 are to be repeated until end of database)
The above sequence wouldn't work. When the GNP call in Step2 is issued first time then the S1 segment occurrence is retrieved. Now when GNP calls are issued repeatedly for RECVABLE segment, the segments R1, R2, R3 and R4 segments are retrieved. Note that R4 doesn't belong to S1 but it belongs to S2. As per the requirement, S1 and it's depends and then S2 and it's dependents and so on are to be retrieved in sequence. Thus, by issuing the above sequence of calls, segments cannot be retrieved as required. To achieve this a qualified GNP call for SHIPTO segment, in Step3, can be issued as follows.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO Step3 : GNP SHIPTO(SHPTOSEQ= ) RECVABLE |
The key value of SHIPTO segment is moved into the SSA for SHIPTO of the GNP call, after Step2, which is available in the PCB.
A better way is to use U command code in the third step, as follows.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO Step3 : GNP SHIPTO *U RECVABLE |
Using U command code in the SHIPTO SSA has the same effect as a qualified SSA for that particular segment occurrence.
If the ADJSTMNT segments are also to be retrieved along for each RECVABLE segment, then one more GNP call may be issued as follows.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO Step3 : GNP SHIPTO *U RECVABLE Step4 : GNP SHIPTO *U RECVABLE *U ADJSTMNT |
In Step4 U command code is used for SHIPTO and RECVABLE segments. Instead of specifying U command code at all the levels the V command code can be used only once with RECVABLE segment as follows.
Step1 : GU CUSTOMER(CUSTNUM='DV0001') Step2 : GNP SHIPTO Step3 : GNP SHIPTO *U RECVABLE Step4 : GNP RECVABLE *V ADJSTMNT |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on IBMMainframer Community!