I have noticed a very odd behaviour with an IF-statement in Progress 4gl.
I define an integer with the format "999" which tells it to have 3 digits and then I assign a value lower than 100 (eg. 12) then when I display it it shows as "012" as it should.
But when I add an IF-statement inside the DISPLAY statement that really shouldn't do anything, the variable is displayed as "12".
This is a test code to clearify the differences. The LABEL doesn't affect the output of the variable.
DEF VAR tmp AS INTEGER FORMAT "999".
ASSIGN tmp = 12.
DISPLAY
tmp LABEL "disp1".
DISPLAY
IF TRUE THEN tmp ELSE tmp LABEL "disp2".
The same behaviour could also be acheived by changing the format to ">99".
My question is: Why does an IF-statement change the way a variable is displayed?
Best regards
//MrBucket
Your second example is similar to:
define variable tmp1 as integer no-undo format "999".
define variable tmp2 as integer no-undo format "99999".
display
if true then tmp1 else tmp2
.
The compiler sees the IF function returns an integer and applies the default formatting for an integer. The compiler does not try to second guess you and notice that (in your example) both results are the same variable.
(In this case IF is a function embedded within the DISPLAY -- not a stand-alone statement of it's own.)
To get the result you are looking for:
display
( if true then tmp1 else tmp2 ) format "999"
.
Whenever I embed an IF function I make a point of wrapping it in parenthesis -- it helps make it clear that it is embedded and clearly shows where things like a FORMAT phrase apply.
Related
I'm creating an OCR line for our remits that our scanner will read. The scanner doesn't allow the '.' in the field - it assumes the last 2 digits are the decimal place values. I'm converting the field to to text but not sure how to remove the '.' and keep the decimal place values.
The most simple solution would be to create a Formula Field and use the Replace() function. The formula for your Formula Field would look like this:
StringVar myVariable;
myVariable := Replace({table.column}, ".", "");
myVariable;
This will search {table.column} for the first occurrence of a decimal and replace it with an empty string.
However, if your intent is to barcode the value, there may be a UFL available that could also do this for you. When creating barcodes, User Function Libraries are usually preferred because they have functions specifically designed to encode your barcode values. They aren't required though and you can always choose to manually encode barcode values manually with Formula Fields.
I'm trying to change the value of nulls to something else that can be used to filter. This data comes from a QVD file. The field that contains nulls, contains nulls due to no action taken on those items ( they will eventually change to something else once an action has been taken). I found this link which was very informative but i tried multiple solutions from the document to no avail.
What i don't quite understand is that whenever i make a new field (in the script or as an expression) the formula does not propagate in the records that are null, it shows " - ". For instance, the expression isNull(ActionTaken) will return false in a field that that not null, but only " - " in fields that are null. If i export the table to Excel, the " - " is exported, i copy this cell to a text analyzer i the UTF-8 encoded is \x2D\x0A\x0A, i'm not sure if that's an artifact of the export process.
I also tried using the NullAsValue statement but no luck. Using a combination of Len & Trim = 0 will return the same result as above. This is only one table, no other tables are involved.
Thanks in advance.
I had a similar case few years ago where the field looked empty but actually it was filled with a character which just looked empty. Trimming the field also didnt worked as expected in this case, because the character code was different
What I can suggest you is to check if the character number, returned for the empty value, is actually an empty string. You can use the ord to check the character number for the empty values. Once you have the number then you can use this number to replace it with whatever you want (for example empty string)
I am using below code to do calculation
select column1 from tablename where code SIMILAR TO '%(-|_|–)EST[1-2][0-9](-|_)%'
for this column value -CSEST190-KCY18-04-01-L the condition was passed, but in actual I want to ignore this type of data.
The correct value which should pass through the above condition is
-CS-EST19-0-KCY18-04-01-L
-CS_EST19-0-KCY18-04-01-L
Any suggestions, how to avoid this type of confusion?
Easiest way is to go full-regex, instead of using SQL standard SIMILAR TO.
select column1 from tablename where code ~ '[_–-]EST[12][0-9][_-]'
Notice this is does not have to match the full string, and you don't have to add .* on both ends (equivalent of % in LIKE and SIMILAR TO). The reason you got a match on that is, because of the underscore _, which is a single wildcard character.
Also, I switched the order, in the square brackets, so that the dash is the last character. That way it's treated as a character literal, not as a range specifier.
I'm trying to format decimal's to round to the nearest hundredth with a temp-table declaration similar to this.
DEFINE TEMP-TABLE foo
FIELD random-decimal AS DECIMAL FORMAT "->>>,>>>,>>>.99".
The end result is displayed on a report through which I'm using the following to output:
EXPORT STREAM sStream DELIMITER ',' foo.
This does not seem to work as I'm intending it to. I'm still receiving values like this: 0.000073.
Does anyone have any insight to what I'm doing wrong? I was unable to find anything for this specific case anyone online.
FORMAT has no impact on storage. It is only a "hint" for default display and input purposes.
What you want is the "decimals" field attribute:
DEFINE TEMP-TABLE foo
FIELD random-decimal AS DECIMAL decimals 2 FORMAT "->>>,>>>,>>>.99".
create foo.
random-decimal = 1.12345.
display random-decimal format ">.9999".
we are using oracle forms...
we have to protect (or) block a text item field from special charecters.
like ( !##$%^&*)
please send some guidences.... thanks in advance...
Regards,
Vijay
When your text box as some entered text you got to have a function that validates all input.
On that function you have a range off invalid values. That range is made in ASCII.
You can use format mask property like 999.99
Which version of forms?
Brute force method:
v_prohibited_chars VARCHAR2(100) := '!##$%^&*';
v_result VARCHAR2(4000);
...
-- strip prohibited characters
v_result := TRANSLATE(:form_field,'A'||v_prohibited_chars,'A');
-- if anything was stripped, lengths will differ
IF LENGTH(:form_field) <> LENGTH(v_result) THEN
error...
END IF
If I understand your comment correctly, you want to be able to filter the special character(s) out of the form field?
The above code does that, and places the result in v_result. So, if you have an input value of 'ABC#DEF#', and your filter mask is '!##$%^&*', then after executing TRANSLATE your result will be 'ABCDEF'. You can then reassign this value to your form field. If you just want to silently strip the character, you can skip the LENGTH checking and simply assign the output of TRANSLATE back to your form field:
:form_field := TRANSLATE(:form_field,'A'||v_prohibited_chars,'A');
What TRANSLATE does is check the characters in the first parameter against the characters in the second parameter. When it finds a match, it translates that character into the corresponding character in the third parameter. If no corresponding characters exist in the third parameter for one in the second, then the character is translated to NULL. If a character does not appear in the second parameter, it remains unchanged. So, the character 'A' is translated to 'A', and all of the other characters in the mask are translated to NULL. The third parameter cannot be NULL, hence the dummy translation of 'A' to 'A'.