View previous topic :: View next topic
|
Author |
Message |
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
I am in a such a requirement where i have to convert a data from X(5) type to 9(2) COMP.
My source string will be always of below type with X(5):
1 character in the beginning and rest 4 are numbers.
e.g A1152, U1153, C0621 etc...
I understand that data with a character can not be converted into COMP field.
when i am passing U1153 to 9(2) COMP field, i am getting data as '41153' which is quiet obvious.
Is there any way to convert X(5) to 9(2) COMP for handling above situation?
I need to find some way as i have to write data to journal in 9(2) COMP format. Existing logic will decode it to displayable format further. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the existing logic is ( using a very kind adjective) flawed
the algorithm is not reversible ...
as You can see from this hex display
Code: |
EDIT ENRICO.CUST.JCL(AAA) - 01.00 Columns 00001 00072
Command ===> Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001 {ABCDEFGHIôöòóõ
CCCCCCCCCCCCCCCC44444444444444444444444444444444444444444444444444444444
0123456789ABCDEF00000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
000002 }JKLMNOPQR¹ûüùúÿ
DDDDDDDDDDDDDDDD44444444444444444444444444444444444444444444444444444444
0123456789ABCDEF00000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
000003 \÷STUVWXYZ²ÔÖÒÓÕ
EEEEEEEEEEEEEEEE44444444444444444444444444444444444444444444444444444444
0123456789ABCDEF00000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data **************************** |
D, M, U, when converting from X to comp map to 4
so ... Your organization should review the logic |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Whether it's 9(02) COMP or 9(04) COMP, it occupies two-bytes (halfword). Why not define it as 9(04) COMP and specify the TRUNC(BIN) compiler option or better yet, define it as COMP-5 (if supported by your compiler).
An unsigned halfword (either TRUNC(BIN) with COMP/COMP-4/BINARY or COMP-5 straightaway), has a maximum capacity of 65535 decimal (X'FFFF'). So, regardless of the definition used (and based upon your example data), you WILL have high-order truncation issues as well as other "opportunities".
You may have to get creative.... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Unless there are rules that you haven't explained, what you want to do is not physically possible. There are 26 letters A to Z and with 4 digits there are 10,000 possible values (0000 to 9999). Hence there are 260,000 possible combinations of letters and digits. A PIC 9(02) COMP variable is a binary half-word or 16 bits. There are 65,536 unique combinations of 16 bits. You cannot squeeze 260,000 unique values into 65,536 unique values without losing something somewhere. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
01 a-nice-name COMP/BINARY/COMP-4 PIC 9(2).
01 another-nice-name COMP-5 PIC 9(2). |
a-nice-name, with compile option TRUNC(OPT) or TRUNC(STD), has a maximum value of 99. The space occupied will be two bytes. With TRUNC(BIN), it behaves as does another-nice-name.
another-nice-name is as described by Mr Bill and Robert, 65,536 possibilities, or a value of zero to 65,535. As enrico has pointed out, it doesn't matter what you do, or what influence the compile options have, you are not going to be able to fully represent your input, no matter what existing code there is. |
|
Back to top |
|
|
Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA
|
|
|
|
Is there a limit on the number? Like can it only go up to 3000? or do you need to allow for 9999? |
|
Back to top |
|
|
jerryte
Active User
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
|
|
|
|
If you don't want the first letter of the field then the below logic should work:
Code: |
05 WS-CHAR5 PIC X(5).
05 WS-COMP2 PIC S9(4) COMP-5.
05 WS-NUM4 PIC 9(4).
MOVE WS-CHAR5 (2:) TO WS-NUM4
MOVE WS-NUM4 TO WS-COMP2
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Or, turning a "blind eye" to the brutal data-names:
Code: |
05 WS-CHAR5 PIC X(5).
10 WS-CHAR5 -CHAR PIC X.
10 WS-CHAR5 -NUM PIC 9(4).
05 WS-COMP2 PIC S9(2) COMP. (how TS defined it).
IF WS-CHAR5 -NUM NUMERIC
MOVE WS-CHAR5 -NUM TO WS-COMP2
ELSE
do whatever the spec describes for this situation, if it is possible
END-IF
|
|
|
Back to top |
|
|
|