Concatenate two numbers in Webi (not adding numbers) - sap

I need to compare the first, middle and last test in each program year. The measurements for doing so involve two variables (1) Level (a text) and (2) score (a number).
There are 52 levels, which I have interpreted into a variable which translates each Level into a number: ([IReady - Level #]). I would like to join the ([IReady - Level #]) variable with the Score associated with each test: ([Total Reading - Score_1965]).
For example, my ([IReady - Level #]) variable translates the level named Early 1 into the number 4. And it translates the next level, Mid 1, into the number 5. So an individual's original results from three tests taken during one program year might look like this:
Test1 Level & Score: Early 1 & 301
Test2 Level & Score: Mid 1 & 299
Test3 Level & Score: Early 1 & 300
However, the goal is to use my ([IReady - Level #]) variable, joined with the Score ([Total Reading - Score_1965]) so that those test results would look like the following -- creating a new number that's easily comparable to one another and reliably reflects inter and intra- level progress:
Test1 Level & Score: 4301
Test2 Level & Score: 5299
Test3 Level & Score: 4300
The following formula works (this variable's name is [zzLevel + Score concatenated]:
=[IReady - Level #] + "" + [Total Reading - Score_1965]
...but it turns the resulting number into a string, even after I've used the ToNumber function as listed below:
over the larger variable
=`ToNumber([zzLevel + Score concatenated]`
within the [IReady - Level #] variable
=[IReady - Level #]=ToNumber(((If ([Total Reading - Level_1966] InList( "Emerging K"; "emerging K"; "emerging k")) Then 0...
(And I've found that, even for this to work, I have to turn the [IReady - Level #] variable into a "Dimension" vs. a "Measure" in order for it to be read as a number. ) But it does, successfully, see this variable as a number, now. So now I just need to figure out how to concatenate two numbers.
Can someone help me with turning the result into a number? I probably have questions following this, but this is the most crucial aspect.
UPDATE: with the help of an associate I've figured out another way to accomplish what I need--I've multiplied my Level # by 1,000: ([IReady - Level #]*1000) ...so that I can just add that new variable to the score number. Now a test resulting in the level "Early 1" with a Score of "301" equals the sum: "4,301". However, I'm still curious if there's a way to join two numbers, (i.e. the number "100" + "401" = 100401--as a number vs. a string). So I still welcome any ideas for that.

There is a function that converts numbers into strings: FormatNumber()
However, if you aren't actually wanting to format anything, and just want to convert a number to a string for the sort of concatenation you are mentioning, the easiest way is to just add a string to it. If you use a null string, then you can convert it back to a number using ToNumber. For example:
="Number: " + 100 - would assign a variable to the string value of "Number: 100"
=""+100 - would assign a variable to the string value of "100"
=100+"" - would also assign a variable to the string value of "100"
=100+""+401 - would assign a variable to the string value of "100401"
=""+100+401 - would also assign a variable to the string value of "100401"
=100+401+"" - would assign a variable to the string value of "501" (left to right calculation means it isn't converted to a string until the string is encountered, so it adds the numbers and then converts)
=ToNumber(100+""+401) - would compute to the numeric value 100401

Related

Maths Rules in Kotlin

I'm trying to depreciate the value of an item in a straight line over time
If I use itemValue2 = itemvalue1 - itemvalue1*item-Age/item-Life, It works perfectly BUT when I originally
used itemValue2 = itemvalue1 * ( 1 - item-Age/item-Life) it constantly evaluated to itemValue1 .
Why would this be ? is it the type of the number 1 ?
itemValue1 and itemValue2 are Doubles, item-Age and item-Life are Longs
Or is it some maths rule that I haven't understood?
Like mentioned in the comments, Longs that divide will result in a truncated Long value. If your resulting value would've been been less than 1, then the result is a truncated value of 0. That leaves itemValue1 to be multiplied by 1, which is itself. You will have to cast to number types that use decimals without truncating like Double or Float.
This thing called Mathematical precedence in kotlin, mean when you create operation like this 1+2*3 the expected result is 9 but not, 7 is the result, in kotlin be the priority for the multiply's * and the divide's / then came the plus + and minus -.
To resolve this issue you need to add the brackets () it's had priority before any operation symbol in the language.
And the operation will be (1+2)*3it will gave result 9.

How to extract numbers(Integer) from String field in database and find the maximum

I have an entity. One field named "number" consists of String. It is a number + some text information. For example:
131-MOD
11853-ARO
983-AKK
etc.
My task is: get the maximum of the first number. So, I have to extract Integer value from String "number" and find the maximum from it. For the examples higher, it would be the numbers 131, 11853 and 983. So, the maximum is 11853. I have to get this Integer value as a result.
Here i have my try using Hibernate. But it working with only Integer values. How to extract number, i have no idea.
public Integer getMaxNumber()
{
return (Integer) getSessionFactory().getCurrentSession().createQuery("select max(id) from EmployeeTripCard s").uniqueResult();
}
How can i do that?
You may use the following JPQL query:
SELECT
MAX(CAST(SUBSTRING(id, 1, LOCATE(id, '-') - 1) AS INTEGER))
FROM EmployeeTripCard s;
We can use LOCATE to find the index of the first -, then call SUBSTRING to find the initial number. Note carefully that we also need to cast this resulting string to an integer, in order for MAX to behave the way we want (numbers as text don't always sort the same way as actual pure numbers).

How to check the Year EDT lenght?

I created a Table's Field, and in addition to this, I created my custom EDT, named : MyEDT (for example).
MyEDT is INTEGER type and I have extended the System standard EDT YearBase.
So, if I insert the alphabetic characters (look like "abecjskjfh") I get an error.
But I need to have a rule, I want to insert only value with 4 Number character, I only want values look like : 2000 , 2006, 1982 etc... .
I can check/control this by code, in methods validateWrite or validateField I insered this code :
switch (p1)
{
case fieldNum(MyTable, MyField) :
if (strLen( (strFmt("%1",this.MyField)) ) != 4)
throw error ("Inser only value AAAA");
break;
}
But,It's possible or exist to creato or axtends the YEAR EDT with only 4 number char length ? Or, there is another way to check the length the field valu ?
Thanks all,
enjoy!
If you want to use an integer EDT, I think there is no way to restrict the range of allowed numbers, except the AllowNegative property. So you have to do the validation in code like in your question. But I would suggest to change your validation logic to validate a number range instead of casting the number to a string and then validating the number of characters. This way you could also make sure that users cannot enter a year like 0000.
if (this.MyField< 1900 || this.MyField > 9999)
{
throw error("Please enter a year between 1900 and 9999");
}
Another possibility could be to use a date EDT where you set the DateYear, DateMonth and DateDay properties such that only the year is shown. This would also help with data entry (e.g. 2 gets replaced with 2002) and gives you a nice error dialog if the users enters for example "abc".
You can use X++ match function.
match('<:d:d:d:d>','2004') would match all 4 digit string (0000-9999).
match('<[12]:d:d:d>','2004') would match string 1000-2999.
Alternate way is to use System.Text.RegularExpressions.Regex.IsMatch('1234', '^\d{4}$')

SQL query not providing range for nvarchar

What I am trying to do is get a range of cube numbers within our building. The issue being the the cube number data type is nvarchar. I know its what messing me up but I have no control over the DB also all of our cube numbers are prefaced with a couple of chars such as AA-1 through AA-255 (thus the nvarchar). My question is this why does the below work:
Select
PCName,
CubeNumer
From
thisTable
where
CubeNumber like 'AA-[1-9]'
The above will give me the PCNames for AA-1 through AA-9 but when I do the following:
...
where CubeNumber like 'AA-[1-20]'
it gives me AA-1 and AA-2. I see the 1 and 2 there, I get its not seeing it as a 20. So is it possible to get that range to work, or any range beside 1-9 to work with that syntax?
Regex is a string comparison and therefore will will look for specific strings. Your pattern of 'AA-[1-20]' is looking for anything that starts with AA- and then numbers 1 through 2, or 0. The correct way would be to do 'AA-[0-9]*'
If your cubes always start with AA-, you could also do a replace and then cast to convert the cube numbers to actual numbers and then do a BETWEEN query.
CAST(REPLACE(CubeNumber,'AA-','') as INT) BETWEEN 1 AND 20;

select using wildcard to find ending in two character then numeric

I am querying to find things ending in "ST" followed by a number 1 - 999.
SELECT NUMBER WHERE NUMBER LIKE '%ST -- works correctly to return everything ending in "ST"
SELECT NUMBER WHERE NUMBER LIKE '%[1-999] -- works correctly to return everything ending in 1 - 999
SELECT NUMBER WHERE NUMBER LIKE '%ST[1-999] -- doesn't work - returns nothing
Also tried:
SELECT NUMBER WHERE NUMBER LIKE '%ST%[1-999] -- works, but also returns things like "GRASTNT3" that have extra things between the "ST" and the number
Can anyone help this struggling beginner?
Thanks!
The problem is that [1-999] doesn't mean what you think it does.
SQL Server interprets that as a set of values (1-9, 9, 9) which basically means that if there's more than 1 digit after the ST, the entry won't be returned.
So far as I can tell, your best bet is:
SELECT NUMBER WHERE
NUMBER LIKE '%ST[1-9][0-9][0-9]' OR
NUMBER LIKE '%ST[1-9][0-9]' OR
NUMBER LIKE '%ST[1-9]'
(assuming that your numbers don't have leading zeros - if they do, replace the ones with more zeros)
You need to do
SELECT NUMBER WHERE
NUMBER LIKE '%ST[1-9][0-9][0-9]'
OR NUMBER LIKE '%ST[1-9][0-9]'
OR NUMBER LIKE '%ST[1-9]';
The group in the the [] is a Char/NChar not an Int.
Better still normalise and type your data, so you have an ST bit and an int column for the number.
If you find you need to define different filters on variable string data, consider Full Text Searching or another Lucene related technology depending on your RDBMS.