10 1 Handling Missing Records Simply

LANSA Application Design

10.1 Handling Missing Records Simply

The following code is very common in reporting programs:

FETCH      FIELDS(#PRODES) FROM_FILE(PROMST) WITH_KEY(#PRODNO)

IF_STATUS  IS_NOT(*OKAY)

CHANGE     FIELD(#PRODES) TO('''N/AVAILABLE''')

ENDIF

This effectively says, "if you can't find the product's description,  print it as N/AVAILABLE".

HOWEVER, the following code will achieve exactly the same result and save 2 lines of coding:

CHANGE     FIELD(#PRODES) TO('''N/AVAILABLE''')

FETCH      FIELDS(#PRODES) FROM_FILE(PROMST) WITH_KEY(#PRODNO)

If the FETCH fails to find any details, the product description field will remain unchanged.