Informix - Esql/Cobol
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I have got a question on esql/(MF-)Cobol. When inserting a record into a table using a host-variable, is it possible to set a specific column to NULL-value? For example there are no values known for the columns t46-zbg-2 and t46-ort, so these columns should be set to NULL from Informix when inserting the record. The problem is: I have to initialize the include-member-record before moving the correct values into the variables and execute the sql-statement. So the variables are set (for the database correct ) to t46-zbg-2 = 0 and t46-ort = "". To what value have I set the variables, so that an insert-statement ends as requested? exec sql insert into tab46_plz values ( :tab46-plz-rec) end-exec. * INCLUDE-member generated for SQL-table tab46_plz 01 tab46-plz-rec. 03 t46-postleitzahl pic s9(5) usage comp-3. 03 t46-zbg-1 pic s9(2) usage comp-3. 03 t46-zbg-2 pic s9(3) usage comp-3. 03 t46-ort pic X(20). 03 t46-zanr pic X(2). Thanks in advance for some support. matthias
"M. Köching" wrote:
> I have got a question on esql/(MF-)Cobol.
> When inserting a record into a table using a host-variable, is it possible
> to set a specific column
> to NULL-value?
> For example there are no values known for the columns t46-zbg-2 and
> t46-ort, so these
> columns should be set to NULL from Informix when inserting the record. The
> problem is: I have to initialize the include-member-record before moving the
> correct values into the variables and execute the sql-statement. So the
> variables are
> set (for the database correct ) to t46-zbg-2 = 0 and t46-ort = "". To what
> value have I set the variables, so that an
> insert-statement ends as requested?
>
> exec sql
> insert
> into tab46_plz
> values ( :tab46-plz-rec)
> end-exec.
>
> * INCLUDE-member generated for SQL-table tab46_plz
> 01 tab46-plz-rec.
> 03 t46-postleitzahl pic s9(5) usage comp-3.
> 03 t46-zbg-1 pic s9(2) usage comp-3.
> 03 t46-zbg-2 pic s9(3) usage comp-3.
> 03 t46-ort pic X(20).
> 03 t46-zanr pic X(2).
>
> Thanks in advance for some support.
>
> matthias
Hi Matthias,
you must use "indicator variables".
How it works:
You have to define a variable:
EXEC SQL BEGIN DECLARE ......
01 indic_vars.
02 indic_plz pic s9(5) comp-5.
....
EXEC SQL END DECLARE ...
move -1 to indic_plz.
exec sql
insert into tab46_plz (postleitzahl, ort, zbg_1 .....)
values (:t46_postleitzahl:indic_plz,
:ort, :zbg_1, ...)
end-exec.
a negative value in the indicator variable at insert/update means to write a
NULL value,
a negative value in the indicator variable after a fetch means a NULL value has
been found.
If an indicator variable is not specified, it defaults to "0".
For additional information see the Informix ESQL/COBOL Programmer's Manual.
Regards
--
Helmut Leininger
Bull AG / Vienna
Open Systems Support
Email: h.leininger@bull.at
helmut.leininger@bull.net
This opinion is mine and not necessarily that of my employer.
No guarantees whatsoever.