Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COALESCE function used in COBOL

Status
Not open for further replies.

criculet

Programmer
Apr 26, 2005
1
RO
Hi,
How the "coalesce" SQL function is used with COBOL variables? I have to make a "MOVE H-VARS into W-VARS", but H-VARS is obtained with an SQL statement, which can return NULL.
Thanks,
Bye!!
 
You can't but the SQL you use can do that for you.

But if you are using ESQL or similar and the SQL can return null then you should also be using indicators with your SQL, and you should then test if that indicator flag is true and act upon it.

e.g.

IF MY_FIELD_NULL_INDICATOR = (ON_VALUE)
MOVE ZEROS (OR SPACES) TO MY_FIELD
END-IF.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Hi Criculet,
From a DB2 point of view, the following example might help:

EXEC SQL
SELECT COALESCE(COL1, COL2)
INTO :H-VARS :H-VARS-NI
END-EXEC

IF H-VARS-NI = -1
do whatever you want to do when null is found....
ELSE
MOVE H-VARS TO W-VARS
END-IF

Hope this is clear, if not, get back to us.

Regards,
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top