Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Converting from X(5) to 9(2) COMP variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 176
Location: Pune, Maharashtra, India

PostPosted: Wed Mar 06, 2013 11:55 pm    Post subject: Converting from X(5) to 9(2) COMP variable
Reply with quote

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
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Mar 07, 2013 12:07 am    Post subject: Reply to: Converting from X(5) to 9(2) COMP variable
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Mar 07, 2013 12:09 am    Post subject: Reply to: Converting from X(5) to 9(2) COMP variable
Reply with quote

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.... icon_wink.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Mar 07, 2013 12:10 am    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Mar 07, 2013 12:30 am    Post subject: Reply to: Converting from X(5) to 9(2) COMP variable
Reply with quote

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
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Thu Mar 07, 2013 10:17 pm    Post subject:
Reply with quote

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
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 183
Location: Toronto, ON, Canada

PostPosted: Fri Mar 08, 2013 1:25 am    Post subject: Re: Converting from X(5) to 9(2) COMP variable
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Mar 08, 2013 4:56 am    Post subject: Reply to: Converting from X(5) to 9(2) COMP variable
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Converting multiple VB files to FB fi... Viswanath Reddy JCL & VSAM 6 Mon Aug 08, 2016 11:49 pm
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us