Found 6705 Articles for Database

What will happen if a NULL value is detected for a SQL statement in COBOL-DB2 program and the NULL indicator is not used?

Mandalika
Updated on 14-Sep-2020 14:54:26

2K+ Views

There is no concept of NULL in COBOL language. Therefore, if any of the columns in DB2 table can hold NULL value then we need to give the NULL indicator in SELECT query in order to detect the NULL value.However, if we miss to give the null indicator in the SELECT query and any of the columns contains the NULL value then the query will fail and we will get a value of -305 in SQLCODE field of SQLCA. As per the IBM documentation -305 value states that.“THE NULL VALUE CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE NUMBER position-number BECAUSE ... Read More

How to verify NULL value in DB2 column data using COBOL paragraph?

Mandalika
Updated on 14-Sep-2020 14:52:20

2K+ Views

In order to accomplish this, we will make use of NULL indicator after the SELECT query on the INVOICE_ID of the ORDERS table. If the NULL indicator has the value as -1 then we can conclude that INVOIVE_ID has a null value.Below is a COBOL paragraph for this−A010-CHECK-ORDER.    EXEC SQL    SELECT INVOICE_ID INTO :INVOICE_ID_DATA :INVOICE_ID_N    FROM ORDERS       WHERE ORDER_ID = ‘678542112’    END-EXEC    IF INVOICE-ID-N = -1    MOVE SPACES TO INVOICE-ID-DATA END-IFINVOICE-ID-N is a null indicator here which is generated automatically by DCLGEN utility.

How will the COBOL-DB2 program behave when there is a mismatch between the host variable and number of columns in the SELECT statement?

Mandalika
Updated on 14-Sep-2020 14:44:03

717 Views

In case there is a mismatch in the number of columns and number of host variables,the query will fail. There are two ways in which we can detect this condition.The SQLWARN3 field of SQLCA will get the value as ‘W’ in case there is a mismatch.In some installations the SQLCODE field for SQLCA gets the error code as -804 when there is a mismatch.We can use IF condition to check the value in SQLWARN3 or SQLCODE and direct the program processing accordingly.

How does DCLGEN utility accommodate NULL host variable for VARCHAR(n) data type?

Mandalika
Updated on 14-Sep-2020 14:39:55

2K+ Views

The DB2 column can store NULL value if it is explicitly not defined with the ‘NOT NULL’ option. However, COBOL does not have any NULL concept. In order to handle these NULL values, COBOL programs use spaces for character columns and zeros for integer columns having NULL value.However, the main challenge is how to detect that particular column is having NULL value and how to move spaces/zeros into corresponding host variables. In order to overcome this, the DCLGEN utility generates a NULL indicator for each DB2 column which can hold a null value. The NULL indicator is a 2 byte ... Read More

Convert DECIMAL(7,3) into equivalent COBOL host variable PIC form.

Mandalika
Updated on 14-Sep-2020 14:30:09

1K+ Views

The formula for converting DECIMAL DB2 data type to COBOL equivalent is−DECIMAL(p,q) = PIC S9(p-q)V(q). Where V indicates implied decimal.The DECIMAL(7,3) can take a sample value as 7861.237 and this can be converted to COBOL equivalent as PIC S9(7-3)V(3) = PIC S9(4)V(3).

What are the COBOL host variable equivalent for various DB2 data types?

Mandalika
Updated on 14-Sep-2020 14:28:07

956 Views

The host variables are used to transfer the data from DB2 to program and vice versa.For each DB2 table column we have a COBOL equivalent host variable defined. The host variables can be generated automatically using the DCLGEN utility or we can explicitly give the host variables in the working storage section of the COBOL-DB2 program.The COBOL equivalent of various DB2 data types is mentioned in the table below.DB2 data typesCOBOL equivalentSMALLINT - 2 bytesPIC S9(4) COMPINTEGER - 4 bytesPIC S9(9) COMPTIMESTAMP - 10 bytesPIC X(26)CHAR - 5 bytesPIC X(5)

What are the default values used by DB2 for various data types?

Mandalika
Updated on 14-Sep-2020 14:21:06

1K+ Views

DB2 provides a facility to insert a default value in case the user does not give any value for the column. For each DB2 data type there is a fixed default value which will be assigned to the column (which was defined with ‘DEFAULT’ parameter during table creation) if the value is not given during insertion.Below table gives the DB2 default values for CHAR, VARCHAR, TIMESTAMP and INTEGER.Data typeDB2 Default valueCHARSpacesVarcharEmpty string having length 0TIMESTAMPCurrent timestampINTEGERZero

What is NULL check and insertion rule in a DB2 table?

Mandalika
Updated on 14-Sep-2020 14:06:49

703 Views

Null in DB2 is defined as nothing. It is an unknown value. If we want to restrict NULL value in any column then the column should be defined with the “NOT NULL” parameter in CREATE TABLE.The “NOT NULL” will force the user to enter a value for the column. However, if we do not want to give any value for this column we can also place a “WITH DEFAULT” parameter which will allow DB2 to place the default value in case the user has not provided any value for the “NOT NULL” column.For example, if we have a column INVOICE_ID ... Read More

What is CASCADE rule for the foreign key on one table referencing to another table?

Mandalika
Updated on 14-Sep-2020 13:57:08

3K+ Views

The foreign key is used to establish a referential constraint between the child table(in which column is defined as foreign key) and parent table (in which foreign key of the child table becomes primary key). For example if we have an ORDER table in which foreign key is defined as TRANSACTION_ID. This foreign key will refer to the TRANSACTION_ID column of TRANSACTIONS table. In this TRANSACTIONS table, TRANSACTION_ID will be the primary key. The parent table here is TRANSACTIONS table while the child table here is ORDERS table.The CASCADE rule of the foreign key states that when any entry is ... Read More

What is the definition and usage of alternate key in a DB2 table?

Mandalika
Updated on 14-Sep-2020 13:52:07

668 Views

The DB2 table contains a number of columns whose value will remain unique in the entire table. Among these multiple columns only one column is selected as the primary key and the remaining keys are known as candidate keys.We can declare any candidate key as an alternate key. Which means that the value of this key cannot take duplicate value, however unlike primary key the primary index is not built on the alternate key.We can define alternate key while defining any table using a UNIQUE keyword. For example, if we want to make TRANSACTION_ID as an alternate key then−CREATE TABLE ... Read More

Advertisements