IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Unable to interpret a hex value to Decimal coming in a file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 33
Location: Chennai

PostPosted: Tue Nov 26, 2024 11:03 pm
Reply with quote

Hi all,
I am receiving a 10 byte hex value (like X'808E640000') in a file. Corresponding layout has a variable, defined as X(5).

Now i am supposed to convert that hex value to a decimal value of 12 bytes (like 552144732160).

How can i achieve this?. Since its a 10 byte, unable to use COMP.
Throw some light on this. I will try at my end.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1050
Location: Richmond, Virginia

PostPosted: Wed Nov 27, 2024 12:46 am
Reply with quote

I don't know if there is a COBOL function for this, but it should be easy enough to write the code to multiply each hex-digit's value by the value of its position and then add them up.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2159
Location: USA

PostPosted: Wed Nov 27, 2024 1:44 am
Reply with quote

Try to use this:

Native binary (COMP-5) items
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 33
Location: Chennai

PostPosted: Wed Nov 27, 2024 9:57 am
Reply with quote

Hi Phil,
Thanks for the suggestion. Will give a try on that.

Hi Sergeyken,
If I declare as 9(9) comp-5, it occupies 4 bytes only and the last bytes is getting displayed on next variable and if i declare 9(10), it occupies 8 bytes. It looks like COMP and COMP-5 doesn't have any difference here.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2159
Location: USA

PostPosted: Wed Nov 27, 2024 10:26 pm
Reply with quote

selvamsrinivasan85 wrote:
Hi Phil,
Thanks for the suggestion. Will give a try on that.

Hi Sergeyken,
If I declare as 9(9) comp-5, it occupies 4 bytes only and the last bytes is getting displayed on next variable and if i declare 9(10), it occupies 8 bytes. It looks like COMP and COMP-5 doesn't have any difference here.

You MUST declare your intermediate PIC 9(12) COMP-5 field (8 bytes), and populate its lower part with your initial X(5) - via REDEFINE, or any other trick.
Back to top
View user's profile Send private message
jerryte

Active User


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

PostPosted: Mon Dec 16, 2024 7:54 am
Reply with quote

Is your input a 10 byte character string made of hexadecimal chars? If so then you might have to do this hard way ie. one char at a time.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2159
Location: USA

PostPosted: Mon Dec 16, 2024 6:15 pm
Reply with quote

jerryte wrote:
Is your input a 10 byte character string made of hexadecimal chars? If so then you might have to do this hard way ie. one char at a time.

The input is FIVE BYTES HEX DATA, as shown: X'808E640000'.
Please, read the post carefully.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2159
Location: USA

PostPosted: Mon Dec 16, 2024 9:30 pm
Reply with quote

sergeyken wrote:
selvamsrinivasan85 wrote:
Hi Phil,
Thanks for the suggestion. Will give a try on that.

Hi Sergeyken,
If I declare as 9(9) comp-5, it occupies 4 bytes only and the last bytes is getting displayed on next variable and if i declare 9(10), it occupies 8 bytes. It looks like COMP and COMP-5 doesn't have any difference here.

You MUST declare your intermediate PIC 9(12) COMP-5 field (8 bytes), and populate its lower part with your initial X(5) - via REDEFINE, or any other trick.

Code:

01 INPUT-DATA PIC X(5) VALUE X'0123456789'.
01 RECALC-AREA.
    05 LONG-BINARY PIC 9(12) COMP-5.
    05 SPLIT-AREA REDEFINES LONG-BINARY.
      10 FILLER    PIC X(3).
      10 HEX-COPY   PIC X(5).
   05 LONG-DEC-PACKED PIC 9(12) COMP-3.
   05 LONG-DEC-CHAR    PIC 9(12).
. . . . . . . . .
LONG-BINARY = 0
HEX-COPY = INPUT-DATA
LONG-DEC-PACKED = LONG-BINARY
LONG-DEC-CHAR = LONG-DEC-PACKED
. . . . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Can BPXBATCH update TAPE file COBOL Programming 3
No new posts Sort to insert record in an empty file. DFSORT/ICETOOL 5
No new posts 3 File Match Method - Useful across a... COBOL Programming 2
No new posts Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts batch SFTP job using AOPBATCH unable ... All Other Mainframe Topics 7
Search our Forums:

Back to Top