100 pts.
 How to handle Null value in COBOL/400.
I have created a view that have Null value.I have populated this field on the basis of some conditions.But when i am reading this view in COBOL program it is going in infinite loop & reading the same record.



Software/Hardware used:
ASKED: May 9, 2011  5:49 AM
UPDATED: May 12, 2011  10:40 PM

Answer Wiki:
Last Wiki Answer Submitted:  Be the first to answer this question.
All Answer Wiki Contributors:  Be the first to answer this question.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Can you post the code.
If you are just doing a read, it should not make any difference if a value is null.
If you are reading an LF and updating, then there is more of a possibility to keep on reading the same record.

 33,695 pts.

 

Also, can you clarify if this is COBOL/400 (OPM) or ILE COBOL? The program code might be the same, but the compiled behaviors may be slightly different.

Tom

 110,115 pts.

 

The SQL Programming with Host Languages manual has examples for COBOL coding. As with RPG, null columns will supply a “null indicator” that you need to test before using a variable that has a null value. An example might be like the following.

Given the statement:

EXEC SQL FETCH CLS_CURSOR INTO :CLS-CD,
                               :NUMDAY :NUMDAY-IND,
                               :BGN :BGN-IND,
                               :ENDCLS :ENDCLS-IND
END-EXEC.

The variables can be declared as follows:

EXEC SQL BEGIN DECLARE SECTION END-EXEC.
77 CLS-CD     PIC X(7).
77 NUMDAY     PIC S9(4) BINARY.
77 BGN        PIC X(8).
77 ENDCLS     PIC X(8).
77 NUMDAY-IND PIC S9(4) BINARY.
77 BGN-IND    PIC S9(4) BINARY.
77 ENDCLS-IND PIC S9(4) BINARY.
EXEC SQL END DECLARE SECTION END-EXEC.

Is that what you’re looking for?

Tom

 110,115 pts.

 

Thanks for the reply.It is in COBOL/400.I am not using the null values in our program.It is present in View.When i am reading the view,it is reading same record due to Null value & giving 46 error code.

 100 pts.

 

If your tables have null-capable columns and any of those columns have null values, your program must use null-indicators in order to fetch those rows successfully.

Tom

 110,115 pts.

 

Flat files (unkeyed) can not contain nulls (null capable fields). You must use keyed PF or keyed LF: Null key map is used when any of the key fields are null capable. Null map is used when any of the fields (key or not) are null capable. In the null map or null key map fields will contain a B’1′ or B’0′ (’0′ = not null, ’1′ = null). Before any updating (write/rewrite), if you change a null to a value other than null, the corr null map field (and/or null key map) for that field needs to be changed from B’1′ to B’0′. The source must be changed from “CBL” to “CBLLE”.

SELECT IOF-GIS
ASSIGN DATABASE-XXXLFA40W-ALWNULL
ORGANIZATION INDEXED
ACCESS DYNAMIC
RECORD KEY EXTERNALLY-DESCRIBED-KEY
WITH DUPLICATES
FILE STATUS WS-FILE-STATUS.
Working Storage Section.
01 WS-NULL-FILE-AREA.
COPY DDS-ALL-FORMATS OF XXXLFA40W
WITH NULL-MAP
WITH NULL-KEY-MAP.
Procedure Division.
READ IOF-GIS
NULL-KEY-MAP IS SOMPFA40W-NKM
NULL-MAP IS SOMPFA40W-NM
INVALID KEY (or next record)
go to xxxx
END-READ.

 675 pts.

 

Flat files (unkeyed) can not contain nulls (null capable fields). You must use keyed PF or keyed LF:

Flat files do not equate with ‘unkeyed’. Unkeyed files are not necessarily ‘flat files’ even though flat files will be unkeyed.

Further, null-capable columns can exist in unkeyed files. I have a number of them.

However, thanks for pointing out that this might not be a SQL issue. It hasn’t actually been stated if the COBOL is using SQL or native I/O to process the file. The way that the term “view” was used in the question put me into thinking that SQL was the focus.

Your native I/O example could be the right direction.

Tom

 110,115 pts.