Is there any real difference between "IF integer IS INITIAL" and "IF integer = 0" in ABAP? I mean, the initial value in the I type is 0 instead of NULL, so the result is the same, isn't it?
There is no functional difference.
The only difference is that if you ever change the type of the variable you are testing, the meaning might change. E.g. if you change it to a character based type the initial value will be SPACE.
Related
In VB.Net, I typically create Enums like so:
Private Enum Zone
IsNegative = -3
IsBad = -2
IsError = -1
Undefined = 0 ' or Unknown, Nothing...
Value1
Value2
ValueN
End Enum
This looks to be in alignment with the Enum Framework Design Guidelines.
Recently, I started to ensure that also the Undefined or Nothing value gets the value of 0 assigned so that comparisons like the following work correctly:
Dim enu as Zone
If enu = Nothing Then ...
Nothing is 0, this matches the Nothing or Undefined value of the Enum.
Often, and because I always assign negative values to error, wrong, or somehow bad values, I also do comparisons like:
If enu > 0 Then
' Perform something with the Zone Enum knowing it's a correct value
Else
' Handle the Enum error or correct its value
End If
This allows testing against all the values of the Enum that are good at once.
Is this good practice, or should I never compare an Enum numerically? Are there reasons why this should be avoided?
Enum is more of systematic styling approach of using known values. Your way is not wrong but instead of that you could still use constants or some other variables or direct values, but for the sake of readability and code maintainability, it is recommended, you use enum the way enumerators should be used.
If yourvalue = enu.Undefined then ...
i just want calculate amount with percent on database access.
this my code
xlWorksheet.Range("AI" & CurrentRow2).Value = Format(CDbl(strGetAccrualAllocation*ADORS_Temp1.Fields("PERCENTAGE").Value).ToString("N2"))
and this error respond
System.InvalidCastException: Operator '*' is not defined for string
"11106.9" and type 'DBNull'.
thankyou
It is always wise to check data used in a calculation for NULL. I often use the inline if to do that, for example:
IIF(IsDBNull(MyValue),0,MyValue)
If MyValue is null, zero is returned, if not, the value of MyValue is returned.
Or if you need to indicate to the user that a value is null:
If IsDBNull(MyValue) Then
'message to user that vaslue is null or some other action
Else
'perforn calculation
End If
When using a string of numeric characters, implicit conversion from string to value will take place. If there is any chance that the string could contain anything other than numeric characters, you should test for that, otherwise another error will be generated.
I am novice in Objective-c ,i want to know ,in Objective-C, how can I check whether input value is integer or float like 2, 3.00,
here 2 is integer and 3.00 is float data-type
how can i find-out it.Thanks in advance
So, the simplest solution is probably to check each string input for a period (.) character (possibly also checking for another number after it) because checking that the number 3.00 and 3 are different is quite hard (because they are only different if you tell them to be).
The easiest way to do that would be with rangeOfString:.
I need to store an alphanumeric string in an integer column on one of my models.
I have tried:
#result.each do |i|
hex_id = []
i["id"].split(//).each{|c| hex_id.push(c.hex)}
hex_id = hex_id.join
...
Model.create(:origin_id => hex_id)
...
end
When I run this in the console using puts hex_id in place of the create line, it returns the correct values, however the above code results in the origin_id being set to "2147483647" for every instance. An example string input is "t6gnk3pp86gg4sboh5oin5vr40" so that doesn't make any sense to me.
Can anyone tell me what is going wrong here or suggest a better way to store a string like the aforementioned example as a unique integer?
Thanks.
Answering by request form OP
It seems that the hex_id.join operation does not concatenate strings in this case but instead sums or performs binary complement of the hex values. The issue could also be that hex_id is an array of hex-es rather than a string, or char array. Nevertheless, what seems to happen is reaching the maximum positive value for the integer type 2147483647. Still, I was unable to find any documented effects on array.join applied on a hex array, it appears it is not concatenation of the elements.
On the other hand, the desired result 060003008600401100500050040 is too large to be recorded as an integer either. A better approach would be to keep it as a string, or use different algorithm for producing a number form the original string. Perhaps aggregating the hex values by an arithmetic operation will do better than join ?
This should be a simple question on JasperReports. I'm trying to do a simple counter over the whole report that should increment based on a condition. However, whatever I try, it seems like the counter variable is always being incremented, regardless of the variable expression. My variable's definition properties are below:
Class: Integer
Calculation: Count
Reset type: Report
Increment type: None
Variable Expression: $F{on_target}.doubleValue() >= 0.0
Initial Value: Integer.valueOf(0)
I have a total of 23 rows in the data set, and based on the criteria, the counter should eventually equal 18. I have the variable outputting in the Summary band, with Evaluation Time to Now. However, regardless of the evaluation time, and even setting the Variable Expression to Boolean.valueOf(true == false), the variable's value always ends up as 23.
What simple little thing am I forgetting?
I think I've got it. This makes vaguely no sense, but... (mind you, this is my first time working with Jasper Variables, so it was trial and error).
The Variable Expression isn't quite a Boolean, where a counter type variable isn't incremented if the expression is false, like you'd think. The variable is incremented if there is any value evaluated in the expression. Thus, for me, what ended up working is below:
$F{on_target} >= 0 ? 1 : null
Note the usage of null if the expression should be false.
It makes vague, twisted sense. But is in no way intuitive. Oh well, so it goes...
or in other words:
When you are using the Calculation:Count function of a Jasper-defined Variable you want the Variable Expression to:
resolve to non-null value to increment the counter
resolve to a null value if you do not want to increment the counter
That's why the test listed above works
As well as the setting the variable expression to:
$F{on_target} >= 0 ? 1 : null
Try also setting the initialValueExpression of the variable to 0.
This worked for me:
$F{on_target} >= 0 ? 1 : BigDecimal.ZERO
No initial variable value necessary.