View previous topic :: View next topic
|
Author |
Message |
chetanambi
New User
Joined: 21 Jan 2012 Posts: 58 Location: India
|
|
|
|
Hi,
I am new to Ezytrieve programming. I want to know how to define a variable with decimal point in Ezytrieve?. I want to use this field for computations involving decimal values so that my report shows output like 5456.56 etc. I have looked into manuals and found this :-
Code: |
Field-name Location Attributes
DEFINE FIELDA 100 5 A
|
Appreciate your help!.. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
From my Easytrieve notes made a few years ago (and, presumably, taken from the manual)
Code: |
* attributes (l dt d) - l - length in bytes
*
* dt - datatype - A - alphanumeric,
P - packed decimal,
N - zoned decimal
*
* d - number of decimals
*
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You need to get a copy of the documentation. There are quite a few things that are not difficult but they are surely not intuitive.
If your organization is licensed to use Easytrieve, all of the manuals are downloadable free fro CA Support. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
In your documentation locate references to MASK.
From the documentation, understand that a MASK is only applied when a field is PRINTed or DISPLAYed. |
|
Back to top |
|
|
chetanambi
New User
Joined: 21 Jan 2012 Posts: 58 Location: India
|
|
|
|
Yes, Bill.. I searched in the forum and MASK is only applied if the field is PRINTed or DISPLAYed.
But my requirement is like this: In my input file there are about 5 fields which are defined with S9(7)V99 COMP-3. I need to subtract sum of these 5 fields from the field defined with S9(9) COMP-3 which is also defined in the same input file. When I subtract I am not getting correct result. Please help me out.
I have defined those 5 fields and WS field for computation as below
Code: |
FILE INPFILE
I-CREDIT-LIMIT 1 5 P
I-AMOUNT1 10 5 P
I-AMOUNT2 15 5 P
I-AMOUNT3 06 5 P
I-AMOUNT4 06 5 P
I-AMOUNT5 21 5 P
WS-BALALNCE-AMT W 10 N 2
|
Suppose if I-CREDIT-LIMIT = 500 and sum of other 5 fields is 465.65 then WS-BALANCE-AMT = I-CREDIT-LIMIT - (Sum of 5 fields) should give 34.35 but I am getting 46065. This is because 500 is being subtracted from 46565 and giving 46065 because I-CREDIT-LIMIT is not defined with decimal point. Can anyone guide me how can I solve this? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
if you follow the P with a number, does that not indicate decimal positions?
you are not into testing/experimenting are you? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
As dbz indicates, you have defined all your fields without decimal places. That is like multiplying them by 100. Here your problem.
Put a number after the P indicating the number of decimal places you have. Note that if you have a whole number, and you want it signed, you have to specify 0 decimal places. In Easytrieve Plus, the number of decimals also inidates a signed field. |
|
Back to top |
|
|
chetanambi
New User
Joined: 21 Jan 2012 Posts: 58 Location: India
|
|
|
|
dbz,
Ofcourse I am doing trial and error method to find the solution.
All amount fields are actually defined with S9(7)V99 COMP-3 and credit limit as S9(9) COMP-3. So as per your suggestions I have modified the definition as below. When I put display for amount fields it is not considering digits after decimal point.
Code: |
FILE INPFILE
I-CREDIT-LIMIT 1 5 P 0
I-AMOUNT1 10 5 P 2
I-AMOUNT2 15 5 P 2
I-AMOUNT3 20 5 P 2
I-AMOUNT4 25 5 P 2
I-AMOUNT5 30 5 P 2
WS-BALALNCE-AMT W 10 N 2
|
So its taking only 465 and subtracting from 500 giving result as 35 without decimal points. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
why not change
Code: |
I-CREDIT-LIMIT 1 5 P 0 |
to
Code: |
I-CREDIT-LIMIT 1 7 P 2 |
? |
|
Back to top |
|
|
chetanambi
New User
Joined: 21 Jan 2012 Posts: 58 Location: India
|
|
|
|
dbz,
I-CREDIT-LIMIT is input field and is defined with S9(9) COMP-3. How can you change its definition?. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
opps, I overlooked that part.
why not move credit limit to your ws-balance-amt
then subtract the others?
ws-balance-amt = credit-amt - (amt1 + amt2 ...)
i do not know of any programming or scripting language,
that will ignore decimal positions when the result of the computation had declared decimal positions.
are you subtracting everything from credit amount and then
moving to ws-balance-amt. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
it would be helpful to see your arithmetic statements
in addition to the data descriptions that you have already provided. |
|
Back to top |
|
|
chetanambi
New User
Joined: 21 Jan 2012 Posts: 58 Location: India
|
|
|
|
dbz,
I am storing sum of all the amounts in one more variable and then subtracting this from credit-amount and storing the result in WS-BALANCE amout as below:
Code: |
WS-SUM-AMT W 10 N 2
WS-BALALNCE-AMT W 10 N 2
|
Other information which you have requested:-
Code: |
FILE MATCHFL
MATCH-RECORD 1 80 A
MATCH-BALANCE-AMT 1 10 N 2
|
Code: |
IF MATCHED
WS-SUM-AMT = I-AMOUNT1 +
+ I-AMOUNT2 +
+ I-AMOUNT3 +
+ I-AMOUNT4 +
+ I-AMOUNT5
WS-BALANCE-AMT = (I-CREDIT-LIMIT - WS-SUM-AMT)
PUT MATCHFL
END-IF
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Can you do DISPLAY HEX <field-name> for each of your I- fields and post the results/ |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I notice you haven't put anything in the field on MATCHFL. |
|
Back to top |
|
|
sandip_mainframe Warnings : 2 New User
Joined: 20 Sep 2006 Posts: 63 Location: pune
|
|
|
|
Hi Chetan,
Display working storage variables in spool area and then copy spool data in the dataset after execution of job.
DISPLAY WS-SUM-AMT WS-BALANCE-AMT
In spool you will be able to view the values in deciamal format. It will surely work. Some days back I had same requirement and I did in the same way.
Thanks,
Sandip Walsinge
Walsinge Technologies Pvt Ltd Pune. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
That's all fine, sandip_mainframe, but pointless. If it worked in that particular program the topic would never have been started.
Until we've seen the code/data which is wrong, there's not much we can do. Inane little bits of code are no help at all, I'm sorry to say. |
|
Back to top |
|
|
|