Handling Null Values in COBOL DB2 SQL Statements

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

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.

COBOL DB2 Program Behavior on Host Variable and Column Mismatch

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

732 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.

DCLGEN Utility for Null Host Variable in 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

Finding Least Number of Notes to Sum an Amount in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:39:10

772 Views

Suppose, we have a currency system where we have denominations of 1000 units, 500 units, 100 units, 50 units, 20 units, 10 units, 5 units, 2 units and 1 unit.Given a specific amount, we are required to write a function that calculates the least number of total denominations that sum up to the amount.For example, if the amount is 512, The least number of notes that will add up to it will be: 1 unit of 500, 1 unit of 10 and 1 unit of 2.So, in this we for 512, our function should return 3, i.e., the total count ... Read More

Append Two Strings Omitting Double Characters in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:32:14

202 Views

We are required to write a JavaScript function that takes in two strings and concatenates the second string to the first string.If the last character of the first string and the first character of the second string are the same then we have to omit one of those characters. Let’s say the following are our strings in JavaScript −const str1 = 'Food'; const str2 = 'dog';Let’s write the code for this function −const str1 = 'Food'; const str2 = 'dog'; const concatenateStrings = (str1, str2) => {    const { length: l1 } = str1;    const { length: l2 ... Read More

Check for Perfect Square Without Using Math Libraries in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:30:36

384 Views

We are required to write a JavaScript function that takes in a number and returns a boolean based on the fact whether or not the number is a perfect square.Examples of perfect square numbers −4, 16, 81, 441, 256, 729, 9801Let’s write the code for this function −const num = 81; const isPerfectSquare = num => {    let ind = 1;       while(ind * ind

Convert Decimal 7-3 into Equivalent COBOL Host Variable PIC Form

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

2K+ 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).

Get Tomorrow and Day After Tomorrow Date in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:28:39

783 Views

Using the Date class of JavaScript whose object new Date() returns a JavaScript date for the current day, we have to find the date of the next two days.This is a fairly simple problem and we can achieve this with a few lines of code. At first, get today’s date −// getting today's date const today = new Date();Let’s write the code for this function −// getting today's date const today = new Date(); // initializing tomorrow with today's date const tomorrow = new Date(today); // increasing a day in tomorrow and setting it to tomorrow tomorrow.setDate(tomorrow.getDate() + 1); const ... Read More

COBOL Host Variable Equivalents for DB2 Data Types

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

980 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)

Advertisements