Using "IF set-name MEMBER" tests

Document ID : KB000018483
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

This document describes how best to utilize the IF set-name MEMBER condition in a cobol program.

Solution:

Care needs to be taken when using the IF set-name MEMBER test in a cobol program.

The IF set-name MEMBER test issues a CALL to IDMS. The action taken after the IF set-name MEMBER test depends upon the value that CALL returns in ERROR-STATUS. The most common values are:-


0000  The current record is a member of the named set
1601  The current member is not a member of the named set
1608  The type of the current record of rununit is not the same as the member record type of the named set.

The 1608 most likely indicates a program bug and tells you nothing about whether or not a particular record is a member of the named set. If not coded correctly, an IF set-name MEMBER test may interpret a 1608 as meaning that the member record is not a member of the named set, when that is not the case.

For example, consider this code:-


 IF set-name MEMBER THEN                                          
     PERFORM PROCESS-MEMBER
 ELSE                                                                 
     PERFORM PROCESS-NON-MEMBER    
 END-IF.

The IF test generates a CALL followed by a test for whether or not ERROR-STATUS is '0000'. If there is an error in the prior coding and the current record of rununit is not a member type of the named set, then a '1608' will be returned and the above code will invoke PROCESS-NON-MEMBER. That is most likely not the desired effect.

The best method is to code it like this:-


 IF NOT set-name MEMBER THEN                                          
     PERFORM PROCESS-NON-MEMBER
 ELSE                                                                 
     PERFORM IDMS-STATUS
     PERFORM PROCESS-MEMBER
 END-IF.

The IF NOT test generates a CALL followed by a test for whether or not ERROR-STATUS is '1601'. This correctly indicates that the current record of rununit is of the correct type but is not a member of the named set.

If ERROR-STATUS is not '1601', control falls to the ELSE clause. The PERFORM IDMS-STATUS ensures that if ERROR-STATUS is '1608' (i.e., the current record of rununit is not a member type of the named set), or indeed if ERROR-STATUS is anything else other than '0000', then the program is aborted.

If ERROR-STATUS is '0000', PROCESS-MEMBER will be correctly performed.