COBOL Host Variable Equivalents for DB2 Data Types

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

1K+ 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)

Reduce Array to Sum of Every Nth Element in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:27:20

296 Views

We are required to write a JavaScript function that takes in an array of numbers and returns the cumulative sum of every number present at the index that is a multiple of n from the array.Let’s write the code for this function −const arr = [1, 4, 5, 3, 5, 6, 12, 5, 65, 3, 2, 65, 9]; const num = 2; const nthSum = (arr, num) => {    let sum = 0;    for(let i = 0; i < arr.length; i++){       if(i % num !== 0){          continue;       };       sum += arr[i];    };    return sum; }; console.log(nthSum(arr, num));OutputFollowing is the output in the console −99Above, we added every 2nd element beginning with index 0 i.e.1+5+5+12+65+2+9 = 99

Find Average of Array Elements Except Largest and Smallest in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:25:35

352 Views

We are required to write a JavaScript function that takes in an array of Number and returns the averages of its elements excluding the smallest and largest Number.Let’s write the code for this function −Following is the code −const arr = [1, 4, 5, 3, 5, 6, 12, 5, 65, 3, 2, 65, 9]; const findExcludedAverage = arr => {    const creds = arr.reduce((acc, val) => {       let { min, max, sum } = acc;       sum += val;       if(val > max){          max = val;     ... Read More

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

Test the Equality of Two Arrays in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:21:04

158 Views

We are required to write a JavaScript function that takes in two arrays of literals and checks the corresponding elements of the array and it should return true if all the corresponding elements of the array are equal otherwise it should return false.Let’s write the code for this function −ExampleFollowing is the code −const arr1 = [1, 4, 5, 3, 5, 6]; const arr2 = [1, 4, 5, 2, 5, 6]; const areEqual = (first, second) => {    if(first.length !== second.length){       return false;    };    for(let i = 0; i < first.length; i++){     ... Read More

Divide a String into N Equal Parts in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:19:06

659 Views

We are required to write a JavaScript function that takes in a string and a number n (such that n exactly divides the length of string). We need to return an array of string of length n containing n equal parts of the string.Let’s write the code for this function −Exampleconst str = 'this is a sample string'; const num = 5; const divideEqual = (str, num) => {    const len = str.length / num;    const creds = str.split("").reduce((acc, val) => {       let { res, currInd } = acc;       if(!res[currInd] || res[currInd].length ... Read More

Find Second Most Frequent Character in Array using JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:16:53

612 Views

We are required to write a JavaScript function that takes in a string and returns the character from the string that appears for the second most number of times.Let’s say the following is our array −const arr = [1, 34, 4, 3, 2, 1, 4, 6, 4, 6, 5, 3, 6, 6];So, the frequent character appearing is −6But we want the output to be the second most frequent character i.e.4Let’s write the code for this function −Exampleconst arr = [1, 34, 4, 3, 2, 1, 4, 6, 4, 6, 5, 3, 6, 6]; const secondMostFrequent = arr => {   ... Read More

Recursive Multiplication in Array using JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:12:40

406 Views

We are required to write a JavaScript function that takes in an array of nested arrays of Numbers and some false values (including 0) and some strings as wel. the function should return the product of number values present in the nested array.If the array contains some 0s, we should ignore them as well. Let’s write the code for this function −Exampleconst arr = [1, 5, 2, null, [       2, 5, null, undefined, false, 5, [          1, 3, false, 0, 2       ], 4, 2, false    ], 4, 6, 0 ... Read More

Count Appearances of a String in Another String in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:09:11

141 Views

We are required to write a JavaScript function that takes in two strings and returns the count of the number of times the first string appears in the second stringLet’s say our string is −const main = 'This is the is main is string';We have to find the appearance of the below string in the above “main” string −const sub = 'is';Let’s write the code for this function −Exampleconst main = 'This is the is main is string'; const sub = 'is'; const countAppearances = (main, sub) => {    const regex = new RegExp(sub, "g");    let count = ... Read More

Find Uncommon Elements in Two Arrays using JavaScript

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

2K+ Views

Let’s say, we have two arrays of numbers −const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34];We are required to write a JavaScript function that takes in two such arrays and returns the element from arrays that are not common to both.Let’s write the code for this function −ExampleFollowing is the code −const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34]; const unCommonArray = (first, second) => {    const res = [];    for(let i ... Read More

Advertisements