How to identify and convert a series of numbers in DataStage? - datastage

I need to identify the values in a field which are of 9 series and greater than or equal to 99999 and convert them to 0s in DataStage i.e atleast first 5bytes of the field are 9s. Here are some examples to explain the situation better
999.00 - Don't convert
9999.00- Don't convert
99999.00- Convert to 0
999991.00-Convert to 0
100000.00- Don't convert
999999.00- Convert to 0
123456.00-Don't convert
9999999.00-Convert to 0
1999999.00-Don't convert
1000000.00-Don't convert
Right now i have If Convert('9','', Trim(Trim(Field(NullToZero(AMT),'.',1)),'0','L')) = '' Then 0. This converts any 9s but our goal is to convert 9s of 99999 and greater only. Please help with solution

Use Field() function to work with just the digits to the left of the decimal placeholder. Test that this value has at least five characters, and that they are all "9".
If Len(Field(AMT,".",1,1) >= 5 And Convert("9","",Field(AMT,".",1,1)) = "" Then 0 Else AMT
Even better would be to resolve the Field() function into a stage variable, so that it's not executed twice, and use that stage variable in the expression.

Related

How to display datetime() value up to milliseconds

I have two questions:
In the following MATLAB code x is a date time value of the format "datetime(Y,M,D,H,MI,S,MS)". The display(x) command displays '00:00:00'. However the 'if condition' displays 'Well received!' which means the real value of x is greater than 0 as opposed to '00:00:00' displayed by the display(x) command. Please suggest how I could display the full value of x up to milliseconds or microseconds.
How can I save '0000,00,00,00,00,00,200' as a date time value?
send = datetime(2016,08,31,06,01,00,00);
receive=datetime(2016,08,31,06,01,00,100);
x=receive-send;
display(x);
if (x>0)
disp('Well received!')
else
disp('Late!')
end
The solution of your first question is, that you might convert your datetime-variable to a formatted string:
disp(datestr(x,'HH:MM:SS:FFF'));
This gives you the output 00:00:00:100, because F is the symbolic identifier for milliseconds.
Furthermore it seems, datetime doesn't support milliseconds. In this case you should use the MATLAB serial date number:
http://de.mathworks.com/help/matlab/ref/datenum.html
The variable x created in your example is a duration object. You can specify the display of milliseconds (as well as smaller decimal fractions of seconds) by setting the Format property.
>> x.Format = 'hh:mm:ss.SSS';
>> display(x);
x = 00:00:00.100
This is presumably also what you want when you ask about saving '0000,00,00,00,00,00,200' as a date time value. It's not really a date and time but a duration, and can be created using the duration constructor.
>> duration(00,00,00,200,'Format','hh:mm:ss.SSS')
ans =
00:00:00.200
Most operations acting on these duration objects will work as expected, such as comparison with the > operator:
>> x > duration(00,00,00,200)
ans =
0

Expected '33990Times Jobs' to be greater than 0

My code:
var listItemText = element.all(by.css(".list-group-item.ng-binding.ngscope")).get(0).getText()
.then(function(text){ return text.replace(/[\r\n]/g, "")
})
expect(listItemText).toBeGreaterThan(0);
How to compare if string is number with texts should be greater than 0 in protractor.
If you want to convert String to a Number you can either use parseFlaot for floating point numbers or parseInt for integers. As long as it will not start with letter characters it will cut off the non number part. Also watch out with parsing the number as it will also cut of leading 0s in front of a number - you might want to improve your regexp to grab only the number from where you expect it to be in the string to make it more bulletproof.
Also you don't need to use element.all(locator).get(0), element(locator) for multiple occurrences will always return first element found.
element(by.css(".list-group-item.ng-binding.ngscope")).getText()
.then(function(text){
var listItemText = text.replace(/[\r\n]/g, "");
expect(praseFloat(listItemText)).toBeGreaterThan(0);
});
Expected '33990Times Jobs' to be greater than 0
First of all, you are comparing a string with a number. And, the string itself contains the extra Times Jobs part. Let's extract all the digits from the text and use parseInt to convert a string to an integer:
var listItemText = element.all(by.css(".list-group-item.ng-binding.ngscope")).first().getText().then(function(text) {
return parseInt(text.match(/\d+/)[0]);
});
expect(listItemText).toBeGreaterThan(0);

DB2 : Length of concatenated fields different

Below query gives 2 different wrong length but same numbers ,In IBM db2 SQL
Why there is 2 different length for same value ?
select
decimal(TRIM(cast(15 as char(2)))||TRIM(LPAD(cast(7 as char(2)),2,'0'))||TRIM(LPAD(cast(13 as char(2)),2,'0'))),
length(decimal(TRIM(cast(15 as char(2)))||TRIM(LPAD(cast(7 as char(2)),2,'0'))||TRIM(LPAD(cast(13 as char(2)),2,'0')))),
decimal(TRIM(substr(replace(char(current_date -1 days,ISO),'-',''),3,6)),6,0),
length(decimal(TRIM(substr(replace(char(current_date -1 days,ISO),'-',''),3,6)),6,0))
from sysibm.sysdummy1
These numbers are not the same value the first one is 15713 and the second is 150713.
DECIMAL(x,p,s) returns a packed decimal value of precision p, scale s.
A packed decimal(p,s) only takes p/2 + 1 bytes of memory.
So 6 /2 + 1 = 4, which is the value LENGTH() returns for packed decimal expressions per the (DB2 for IBM i) manual

How to take one particular number or a range of particular number from a set of number?

I am looking for to take one particular number or range of numbers from a set of number?
Example
A = [-10,-2,-3,-8, 0 ,1, 2, 3, 4 ,5,7, 8, 9, 10, -100];
How can I just take number 5 from the set of above number and
How can I take a range of number for example from -3 to 4 from A.
Please help.
Thanks
I don't know what you are trying to accomplish by this. But you could check each entry of the set and test it it's in the specified range of numbers. The test for a single number could be accomplished by testing each number explicitly or as a special case of range check where the lower and the upper bound are the same number.
looping and testing, no matter what the programming language is, although most programming languages have builtin methods for accomplishing this type of task (so you may want to specify what language are you supposed to use for your homework):
procfun get_element:
index=0
for element in set:
if element is 5 then return (element,index)
increment index
your "5" is in element and at set[index]
getting a range:
procfun getrange:
subset = []
index = 0
for element in set:
if element is -3:
push element in subset
while index < length(set)-1:
push set[index] in subset
if set[index] is 4:
return subset
increment index
#if we met "-3" but we didn't met "4" then there's no such range
return None
#keep searching for a "-3"
increment index
return None
if ran against A, subset would be [-3,-8, 0 ,1, 2, 3, 4]; this is a "first matched, first grabbed" poorman's algorithm. on sorted sets the algorithms can get smarter and faster.

Rounding Off Decimal Value to Pevious and Next Hundreds

I am working in C#. I have decimal variable startFilter that contains value say 66.76. Now I want this decimal value to appear in the seach filter $0 to $100. But what I also want is, that the search filter starts from the first decimal value that comes in startFilter variable. So for instance in this case the search filter will start from $0 to $100 because the value in startFilter variable is 66.76, but in another case it can be $100 to $200 if the first value that comes in searchFilter is say $105.
Having said that, how should I round off the value in seachFilter to previous hundreds and the next hundreds. Like if the value is 66.76 it rounds off to 0 as floor and 100 as ceiling, so on and so forth.
Any idea how to do that in C#?
double value = ...
int rounded = ((int) Math.Round(value / 100.0)) * 100;
divide your original number by 100. get floor and celing values. Multiply each of them by 100.