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

768 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

196 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

373 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

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

Get Tomorrow and Day After Tomorrow Date in JavaScript

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

776 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

960 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

272 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

332 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

Advertisements