Originally posted by Barbara Morris
View Post
Announcement
Collapse
No announcement yet.
slickest way to move packed decimal to char field
Collapse
X
-
If you are just assigning the result of %DEC to a packed field, you don't need to have the exact length and decimals of the packed field for the %DEC. If you use values that are larger than the length and decimals of the result, it will work fine. The only time this wouldn't work is if MyResult has more than 31 decimal positions.
Code:MyResult = %Dec(MyValue: 63 : 31);
Leave a comment:
-
oh, now that is slicker than owl poop - thx BirgittaOriginally posted by B.Hauser View PostIt is not possible to use variables as replacement of X:X!
What you can do you can replace the X with a constant, which is for example defined based on a reference field, i.e.
For Example:
BirgittaCode:DCL-C ConstDecPos Const(%DecPos(VarX)); DCL-C ConstDecLen Const(%Len(VarX)); MyResult = %Dec(MyValue: ConstDecLen: ConstDecPos);
Leave a comment:
-
It is not possible to use variables as replacement of X:X!
What you can do you can replace the X with a constant, which is for example defined based on a reference field, i.e.
For Example:
BirgittaCode:DCL-C ConstDecPos Const(%DecPos(VarX)); DCL-C ConstDecLen Const(%Len(VarX)); MyResult = %Dec(MyValue: ConstDecLen: ConstDecPos);
- Likes 1
Leave a comment:
-
while we are on the topic... does anyone know if host variables can be used place of the following for x... %dec(field:x:x);
I'm trying it and getting a compile error. but could be because they are integer data type...???
Leave a comment:
-
If you know the size of your packed decimal and want to keep at least 1 digit before the dp, then how about (for an 8p6):
%trim(%editw(num:'0 . -'));
Though annoyingly the -ve sign must be at the end with this method
Leave a comment:
-
yes just tested it... trying to avoid %subst, but unless anyone has a better idea...???Originally posted by Vectorspace View Post
Are you sure? I thought that %char kept the decimal place?
I do find however that %char strips all leading zero's, so 0.123 becomes ".123"
i was WRONG - went by the DSPLY of the field which left off the decimal point - put in debug and yes the new g_packed has the decimal - sorry!Last edited by jayvaughn; August 2, 2017, 08:06 AM.
Leave a comment:
-
Are you sure? I thought that %char kept the decimal place?Originally posted by jayvaughn View Post
i'm afraid, that will drop the decimal place and g_packed will become 1234
I do find however that %char strips all leading zero's, so 0.123 becomes ".123"
Leave a comment:
-
g_char = %TrimL(%Char(p_packed)) ;
g_packed = %Dec(g_char:6:5) ;
Leave a comment:
-
As arrow says - it depends what you want. The absolute simplest would be g_char = %Char(p_packed);
That gives you the decimal insertion and stripping of leading blanks. i.e 123.45 becomes '123.45' (6 characters) and 1.23 becomes '1.23' (3 characters).
In addition to %EditC (which can use any edit code) you could also use %EditW which allows the use of any edit word.
Leave a comment:
-
what about the other way...? g_packed = g_char.... say g_packed is 6p5 and g_char is 1024
Leave a comment:
-
It depends on what you want the result to look like. How aboutchanging the edit code to adjust how you want decimals, negatives, etc to appear.Code:g_char = %editc(p_packed:'J')
Leave a comment:
-
slickest way to move packed decimal to char field
anything better than this?
g_char = %subst(%editc(p_packed:'X'):1:xx) + '.' +
%subst(%editc(p_packed:'X'):xx:xx);Tags: None

Leave a comment: