Use of SQLWARN3 in SQLCA Explained with Practical Example

Mandalika
Updated on 14-Sep-2020 13:40:22

315 Views

The SQLWARN3 field in SQLCA is used to detect the condition wherein the number of the resultant columns is greater than the number of host variables given in the query of a COBOL-DB2 program. The SQLWARN3 is a 1 byte field, which contains the value ‘W’when there is mismatch in number of columns returned by the query and number of host variables used.We can enquire the status of SQLWARN3 using IF or EVALUATE statements as in the below exampleA010-CHECK-ORDER. EXEC SQL    SELECT ORDER_DATE,          ORDER_TOTAL       INTO :ORDER-DATE,       FROM ORDERS   ... Read More

Factorial Recursion in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:38:46

303 Views

We are required to write a JavaScript function that computes the Factorial of a number n by making use of recursive approach.Here, we are finding the factorial recursion and creating a custom function recursiceFactorial() −const num = 9; const recursiceFactorial = (num, res = 1) => {    if(num){       return recursiceFactorial(num-1, res * num);    };    return res; };Now, we will call the function and pass the value to find recursion −console.log(recursiceFactorial(num)); console.log(recursiceFactorial(6)); console.log(recursiceFactorial(10));ExampleLet’s write the code for this function −const num = 9; const recursiceFactorial = (num, res = 1) => {    if(num){   ... Read More

Exclude Values in Average Calculation in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:36:48

290 Views

Let’s say, we have an array of objects like this −data = [    {"Age":26, "Level":8},    {"Age":37, "Level":9},    {"Age":32, "Level":5},    {"Age":31, "Level":11},    {"Age":null, "Level":15},    {"Age":null, "Level":17},    {"Age":null, "Level":45} ];We are required to write a JavaScript function that calculates the average level for all the objects that have a truthy value for age propertyLet’s write the code for this function −ExampleFollowing is the code −data = [    {"Age":26, "Level":8},    {"Age":37, "Level":9},    {"Age":32, "Level":5},    {"Age":31, "Level":11},    {"Age":null, "Level":15},    {"Age":null, "Level":17},    {"Age":null, "Level":45} ]; const findAverage = arr => { ... Read More

Checking for Co-Prime Numbers in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:33:39

438 Views

Two numbers are said to be co-primes if there exists no common prime factor amongst them (1 is not a prime number)For example −4 and 5 are co-primes 9 and 14 are co-primes 18 and 35 are co-primes 21 and 57 are not co-prime because they have 3 as the common prime factorWe are required to write a function that takes in two numbers and returns true if they are co-primes otherwise returns falseExampleLet’s write the code for this function −const areCoprimes = (num1, num2) => {    const smaller = num1 > num2 ? num1 : num2;    for(let ... Read More

Count Specific Letter Occurrences in a Sentence Using JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:00:47

109 Views

We are required to write a JavaScript function that finds how many times a specific letter is appearing in the sentenceExampleLet’s write the code for this function −const string = 'This is just an example string for the program'; const countAppearances = (str, char) => {    let count = 0;    for(let i = 0; i < str.length; i++){    if(str[i] !== char){       // using continue to move to next iteration          continue;       };       // if we reached here it means that str[i] and char are same ... Read More

Count N-Digit Numbers with Sum of Even and Odd Positioned Digits Divisible by Given Numbers in JavaScript

AmitDiwan
Updated on 14-Sep-2020 12:58:39

135 Views

We are required to write a JavaScript function that takes in three numbers A, B and N, and finds the total number of N-digit numbers whose sum of digits at even positions and odd positions are divisible by A and B respectively.ExampleLet’s write the code for this function −const indexSum = (num, sumOdd = 0, sumEven = 0, index = 0) => {    if(num){        if(index % 2 === 0){            sumEven += num % 10;        }else{            sumOdd += num % 10;       ... Read More

Rotate an Array in JavaScript

AmitDiwan
Updated on 14-Sep-2020 12:54:22

549 Views

Let’s say, we are required to write a JavaScript function that takes in an array and a number n and rotates the array by n elementsFor example: If the input array is −const arr = [12, 6, 43, 5, 7, 2, 5];and number n is 3, Then the output should be −const output = [5, 7, 2, 5, 12, 6, 43];Let’s write the code for this function −ExampleFollowing is the code −// rotation const arr = [12, 6, 43, 5, 7, 2, 5]; const rotateByOne = arr => {    for(let i = 0; i < arr.length-1; i++){     ... Read More

Truncate Trapping of DB2 Column Data to Host Variable

Mandalika
Updated on 14-Sep-2020 11:45:06

220 Views

There are situations in which DCLGEN members are not used and the host variables declarations are done explicitly in the working storage section. However, due to these explicit declarations there are chances of human errors. One such error is declaring incorrect data length of COBOL equivalent host variables.For example, the host variable should have been declared as PIC X(24) but it was declared as PIC X(14) by mistake. In this case when the data transfer takes place from DB2 to COBOL program, the column data might get truncated due to the shorter length of the receiving host variable.We can detect ... Read More

COBOL DB2 Program Behavior Without DCLGEN Member

Mandalika
Updated on 14-Sep-2020 11:42:21

2K+ Views

The DCLGEN member contains two important sets of data.The table structure containing definitions of all the columns present in the table.The host variable declaration in equivalent COBOL data types.Including the DCLGEN member is not mandatory until we explicitly give the host variables declaration in the working storage section. But it is always considered as a good coding practice to include a DCLGEN member because it also contains the table structure using which the pre-compiler can perform the query column validation. Although, the query column validation is optional for the pre-compiler but it gives us possible errors in the precompilation stage ... Read More

Purpose and Usage of SQLCODE within SQLCA in COBOL DB2 Program

Mandalika
Updated on 14-Sep-2020 11:24:41

2K+ Views

The SQLCODE field of SQLCA is used to get the return code for the last executed SQL query from DB2 to COBOL program. Below are the range of return codes which SQLCODE field can take along with their significance.SQLCODE = 0 → Query executed successfully without any issue.SQLCODE > 0 → There was a warning issued while executing the query.SQLCODE < 0 → There was an error occurred while executing the query.Below is the sample paragraph where the usage of SQLCODE is demonstrated.A010-CHECK-ORDER. EXEC SQL    SELECT ORDER_DATE       INTO :ORDER-DATE,       FROM ORDERS     ... Read More

Advertisements