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

How to display a variable in the HEXADECIMAL format in Cobol


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

New User


Joined: 25 May 2005
Posts: 20

PostPosted: Tue Jun 14, 2005 10:18 am
Reply with quote

Hi,
Suppose i move a value to a variable.

Is it possible to display a variable in the HEXADECIMAL format in Cobol

bye

lal
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Tue Jun 14, 2005 12:22 pm
Reply with quote

Hi shajeeth,

Write the value into a file and type hex on so that the value will be displayed in hexadecimal form. Correct me if i am wrong.
Back to top
View user's profile Send private message
vel2k8

New User


Joined: 10 Jun 2005
Posts: 11
Location: Jacksonville

PostPosted: Tue Jun 14, 2005 1:56 pm
Reply with quote

Hi,

Converting the contents of a data item to printable hexadecimal
notation... it's not as difficult as you think.
This solution is coded as a COBOL subroutine using 3 parameters. It does not DISPLAY anything, but converts
data into a displayable format. Each input character is
converted from 1 byte into 2 "displayable" bytes and is done 8
bytes at a time. This routine does not use any tables, DISPLAYs,
or MOVE CORRESPONDING and can handle an input field up to
16383 bytes.


Code:

IDENTIFICATION DIVISION.
PROGRAM-ID. HEXCOBOL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 FILLER.
05 I PIC S9(4) VALUE ZERO COMP.
05 J PIC S9(4) VALUE ZERO COMP.
05 L PIC S9(4) VALUE ZERO COMP.
05 WS-ONUM-DECIMAL-C.
10 WS-ONUM-DECIMAL PIC S9(17) VALUE ZERO COMP-3.
05 WS-ONUM-DISPLAY-C.
10 WS-ONUM-DISPLAY PIC 9(17) VALUE ZERO.
SKIP3
LINKAGE SECTION.

01 LK-OFLD-LEN PIC S9(4) COMP.
01 LK-IFLD-TXT PIC X(16383).
01 LK-OFLD-TXT PIC X(32767).
EJECT
PROCEDURE DIVISION USING LK-IFLD-TXT
LK-OFLD-LEN
LK-OFLD-TXT.
IF LK-OFLD-LEN > ZERO
IF LK-OFLD-LEN > LENGTH OF LK-IFLD-TXT
MOVE +4 TO RETURN-CODE
ELSE
MOVE +1 TO J
MOVE LK-IFLD-TXT (1:8) TO WS-ONUM-DECIMAL-C (1:8)
MOVE WS-ONUM-DECIMAL TO WS-ONUM-DISPLAY
COMPUTE L = LK-OFLD-LEN
PERFORM VARYING I FROM 9 BY 8
UNTIL L < 16
MOVE WS-ONUM-DISPLAY-C (1:16) TO LK-OFLD-TXT (J:16)
MOVE LK-IFLD-TXT (I:8) TO WS-ONUM-DECIMAL-C (1:8)
MOVE WS-ONUM-DECIMAL TO WS-ONUM-DISPLAY
ADD +16 TO J
ADD -16 TO L
END-PERFORM
IF L > ZERO
MOVE WS-ONUM-DISPLAY-C (1:L) TO LK-OFLD-TXT (J:L)
END-IF
INSPECT LK-OFLD-TXT (1:LK-OFLD-LEN)
CONVERTING X'FAFBFCFDFEFF' TO 'ABCDEF'
MOVE ZERO TO RETURN-CODE
END-IF
ELSE
MOVE +8 TO RETURN-CODE
END-IF.

GOBACK.

Thanks
Vel.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
Search our Forums:

Back to Top