View previous topic :: View next topic
|
Author |
Message |
sourav_dasgupta
New User
Joined: 26 Dec 2007 Posts: 18 Location: Chennai, India
|
|
|
|
Hi,
Is it possible to read an S9(3)V99 variable in X(3) format and convert it back to packed decimal format?
Note: Both takes the same space i.e. 3 bytes.
My requirement actually is, given the length and position of the packed decimal, I have to extract it from a X(20) variable (can not use group variable or copybook variable ), read it in a alphanumeric temporary variable and then move it back to a packed decimal variable without losing the sign or data.
Thanks
Sourav |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Is it possible to read an S9(3)V99 variable in X(3) format and convert it back to packed decimal format? |
Please re-post your question differently - as worded, many will not understand (i'm fairly sure that i don't). S9(3)V99 is zoned decimal and will not "fit" in an X(3) field and neither is it packed decimal. I am also not sure where/how the X(20) field is involved.
If you show some "input" data values (maybe in hex) and the desired output (also in hex), we can show you how to get from your intput to your needed output. |
|
Back to top |
|
|
sourav_dasgupta
New User
Joined: 26 Dec 2007 Posts: 18 Location: Chennai, India
|
|
|
|
Hi,
I will try to elaborate my situation.
I am reading a record from an input file. Suppose I am reading it into one X(20) variable WS-READ.
There is a copybook for this input file which is
Code: |
05 :TAG:-TEMP-RECORD.
10 :TAG:-TEMP-TYPE PIC X(06).
10 :TAG:-ACC-NO PIC 9(11).
10 :TAG:-AMOUNT PIC S9(03)V99 USAGE COMP-3.
|
Suppose in the read record the amount field is holding the value 123.45
Now I need to read the amount field as WS-READ(18,3) and move to a WS-LOCAL-AMOUNT variable which is also of type S9(03)V99 USAGE COMP-3.
It should be some thing like
MOVE WS-READ(18,3) TO WS-TEMP => WS-TEMP is x(3)
MOVE WS-TEMP TO WS-LOCAL-AMOUNT => there should be some processing instead of this line
The ultimate purpose is to have 123.45 in WS-LOCAL-AMOUNT.
If you need any other info just let me know.
Sourav |
|
Back to top |
|
|
k.junaid83
New User
Joined: 19 Apr 2006 Posts: 22 Location: bangalore
|
|
|
|
Hi sourav,
First of all the input data u are reading will not fit into X(20), the amount feild will get truncated.You can define WS-READ similarly as ur input file copy book as declare bleow:
05 WS-READ.
10 WS-TEMP-TYPE PIC X(06).
10 WS-ACC-NO PIC 9(11).
10 WS-AMOUNT PIC S9(03)V99 USAGE COMP-3.
using the above declaration u can read ur input file into WS-READ, so that WS-AMOUNT gets the desired value.
OR
U can define variables similar to the Input file copy book like
10 WS-TAG-TEMP-TYPE PIC X(06).
10 WS-TAG-ACC-NO PIC 9(11).
10 WS-TAG-AMOUNT PIC S9(03)V99 USAGE COMP-3.
With the above declaration u can directly move the input file variables to working storage variables.
MOVE TAG:-TEMP-TYPE TO WS-TAG-TEMP-TYPE
MOVE TAG:-ACC-NO TO WS-TAG-ACC-NO
MOVE TAG:-AMOUNT TO WS-TAG-AMOUNT
U can direclty get the amount value without moving it to temp variable
Thanks |
|
Back to top |
|
|
sourav_dasgupta
New User
Joined: 26 Dec 2007 Posts: 18 Location: Chennai, India
|
|
|
|
Hi Junaid,
The layout length which i gave in the previous post is 20.
X(06) => 6 bytes
9(11) => 11 bytes
S9(3)V99 => 3 bytes
so the length of the group variable :TAG:-TEMP-RECORD is 20.
If i read it to WS-READ I think there should not be any truncation for the amount field.
Here my problem is i can not declare WS-READ as group variable and read the fields directly.
I am trying find out if it is possible to read all types of field depending on the position and length.
For Example:
Suppose the following condition
05 :TAG:-TEMP-RECORD.
10 :TAG:-TEMP-TYPE PIC X(06). => contains value "ABCD"
10 :TAG:-ACC-NO PIC 9(11). => contains 99999.
10 :TAG:-AMOUNT PIC S9(03)V99 USAGE COMP-3. => contains 123.45
Now if I write
MOVE WS-READ(1,6) TO WS-LOCAL-TEMP-TYPE
MOVE WS-READ(7,11) TO WS-LOCAL-ACC-NO-CHAR
COMPUTE WS-LOCAL-ACC-NO = FUNCTION NUMVAL(WS-LOCAL-ACC-NO-CHAR)
DISPLAY WS-LOCAL-TEMP-TYPE
DISPLAY WS-LOCAL-ACC-NO
It will display ABCD and 99999 respectively
In the same way i want to read the amount also, which is WS-READ(18,3) |
|
Back to top |
|
|
Varun Singh
New User
Joined: 01 Aug 2007 Posts: 25 Location: Delhi
|
|
|
|
Hi Saurav,
Is it possible to read an S9(3)V99 COMP-3 variable in X(3) format and convert it back to packed decimal format?
No, it will give data exception error
you have to do like this:-
S9(3)V99 COMP-3 to 9(6)
then only you can move 9(6) to again S9(3)V99 COMP-3. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
you have to do like this:-
S9(3)V99 COMP-3 to 9(6)
then only you can move 9(6) to again S9(3)V99 COMP-3 |
This is not correct. There is no need for the move to 9(6) (actually that move will not work as desired - the decimal places will be lost because 9(6) has no decimal places).
WS-AMOUNT can be directly moved to WS-LOCAL-AMOUNT. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
There is a contradiction in your statements:
sourav_dasgupta wrote: |
There is a copybook for this input file which is
Code: |
05 :TAG:-TEMP-RECORD.
10 :TAG:-TEMP-TYPE PIC X(06).
10 :TAG:-ACC-NO PIC 9(11).
10 :TAG:-AMOUNT PIC S9(03)V99 USAGE COMP-3. |
|
If you have a copybook, why not just do
Code: |
MOVE :TAG:-AMOUNT TO WS-LOCAL-AMOUNT |
If you do not have a copybook and must use WS-READ(18:3) then it is easy to do:
Code: |
01 WS-AMOUNT-X.
05 WS-AMOUNT-9 PIC S9(03)V99 USAGE COMP-3.
MOVE WS-READ(18:3) TO WS-AMOUNT-X
IF WS-AMOUNT-9 IS NUMERIC THEN
MOVE WS-AMOUNT-9 TO WS-LOCAL-AMOUNT
ELSE
DISPLAY '!!!ERROR!!!' |
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
A heads up for you regarding the NUMERIC check on a COMP-3 field.
If you're unsure of this data's origination and it contains an "F" neutral-nibble instead of a "C" or a "D" sign-nibble, the NUMERIC check will fail, because the picture clause indicates that the data should be signed.
If that's the case, redefine it again as COMP-3 unsigned (remove the S) and try the NUMERIC test again.
If it fails a second time, then the data is not packed-decimal of any type.
Regards,
Bill |
|
Back to top |
|
|
saidharrao Warnings : 1 New User
Joined: 19 Feb 2005 Posts: 27 Location: hyderabad-ap-india
|
|
|
|
Hi,
Irrespective of your problem, I just want to give some info on COMP-3 and check if it is helpful.
Without reference modification
-----------------------------------
Move the comp-3 field (already read to record) directly to another Comp-3
or
Move the comp-3 field to 9(5)v9(2) and then from 9(5)v9(2) to your local Comp-3 field
With reference modification
-------------------------------
Move the comp-3 field to 9(5)v9(2) and then from 9(5)v9(2)
Please note that, if sign s required you may have to move to s9(4)v9(2).
I think it should work.
All the best. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
saidharrao wrote: |
Hi,
Irrespective of your problem, I just want to give some info on COMP-3 and check if it is helpful.
Without reference modification
-----------------------------------
Move the comp-3 field (already read to record) directly to another Comp-3
or
Move the comp-3 field to 9(5)v9(2) and then from 9(5)v9(2) to your local Comp-3 field
With reference modification
-------------------------------
Move the comp-3 field to 9(5)v9(2) and then from 9(5)v9(2)
Please note that, if sign s required you may have to move to s9(4)v9(2).
I think it should work.
All the best. |
Moving the COMP-3 field to an unsigned COMP-3 field will probably work, because under the covers, the compiler issues an MVC followed by an OI X'0F' of the last byte, to ensure an 'F' neutral-nibble.
However, if the COMP-3 field is truly NOT NUMERIC and you move it to a signed COMP-3 field, again the compiler issues an MVC but will ensure a valid sign-nibble, by issuing a ZAP of the field itself. Unlike an MVC, if there's bad packed-decimal data, the ZAP will fail with a S0C7.
Regards,
Bill |
|
Back to top |
|
|
sourav_dasgupta
New User
Joined: 26 Dec 2007 Posts: 18 Location: Chennai, India
|
|
|
|
Hi Marso,
Thanks a lot for the solution. Yess!! It worked .
Quote: |
01 WS-AMOUNT-X.
05 WS-AMOUNT-9 PIC S9(03)V99 USAGE COMP-3.
MOVE WS-READ(18:3) TO WS-AMOUNT-X
IF WS-AMOUNT-9 IS NUMERIC THEN
MOVE WS-AMOUNT-9 TO WS-LOCAL-AMOUNT
ELSE
DISPLAY '!!!ERROR!!!'
|
Actually i was trying out accessing the fields depending on the position so that later i can use them in a simple loop. Given the positions and type of the field in a separate flat file or an array, i am trying to find a process that will fetch the field in a X(XX) variable and from there process depending on the type of the field (X, 9 or S9).
I think i can go ahead to the next step of processing now
Thanks for the reply to all
Sourav |
|
Back to top |
|
|
Varun Singh
New User
Joined: 01 Aug 2007 Posts: 25 Location: Delhi
|
|
|
|
Thanks, dick for correcting me..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
d |
|
Back to top |
|
|
|