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
 

 

How to use hex and octal numbers in cobol

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

New User


Joined: 05 Aug 2006
Posts: 11

PostPosted: Wed Aug 16, 2006 12:46 am    Post subject: How to use hex and octal numbers in cobol
Reply with quote

can anyone tell me, how to use hex and octal numbers in cobol.
i mean how to initialize them.
Back to top
View user's profile Send private message

DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Aug 16, 2006 2:32 am    Post subject: Re: hex and octal nos.
Reply with quote

Can you give an example of what you expect? What the results should be?

Dave
Back to top
View user's profile Send private message
NIRAJ BILGE

New User


Joined: 05 Aug 2006
Posts: 11

PostPosted: Fri Aug 18, 2006 10:37 am    Post subject:
Reply with quote

yes david
i just want to enter no. in respective no system
and will get display in the same.
i am writing appl. pgm for scientific calculator.
Back to top
View user's profile Send private message
Sridevi_C

Active User


Joined: 22 Sep 2005
Posts: 104
Location: Concord, New Hampshire, USA.

PostPosted: Fri Aug 18, 2006 10:20 pm    Post subject:
Reply with quote

COBOL is for business data and NOT for scientific stuff. "Octals" is still an alien to traditional COBOL.

Thanks.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Aug 19, 2006 4:14 am    Post subject:
Reply with quote

Code:

WORKING-STORAGE SECTION.                               
                                                       
01  WS-DEC-NUM              PIC X(10).                 
01  WS-HEX-NUM              PIC X(10).                 
01  WS-OCT-NUM              PIC X(10).                 
                                                       
01  WS-WORK1                PIC 9(10)   COMP-3.         
01  WS-WORK2                PIC 9(10)   COMP-3.         
01  WS-LEN1                 PIC 9(10)   COMP-3.         
                                                       
01  WS-CONV.                                           
    05  WS-CONST            PIC X(16)   VALUE           
        '0123456789ABCDEF'.                             
    05  WS-DIG REDEFINES WS-CONST                       
                            OCCURS 16 TIMES             
                            PIC X.                     
01  WS-SUB1                 PIC S9(3)   COMP-3. 

PROCEDURE DIVISION.                               
                                                 
PROGRAM-START.                                   
                                                 
    MOVE 0015288453      TO WS-DEC-NUM.           
    PERFORM C1000-DEC-HEX                         
        THRU C1000-EXIT.                         
    DISPLAY 'DEC NUMBER = ' WS-DEC-NUM           
           ' HEX NUMBER = ' WS-HEX-NUM.           
                                                 
    PERFORM C2000-DEC-OCT                         
        THRU C2000-EXIT.                         
    DISPLAY 'DEC NUMBER = ' WS-DEC-NUM           
           ' OCT NUMBER = ' WS-OCT-NUM.           
                                                 
    GOBACK.                                       
C1000-DEC-HEX.                                                   
    MOVE LENGTH OF WS-HEX-NUM TO WS-LEN1.                       
    MOVE WS-LEN1 TO WS-SUB1                                     
    MOVE WS-DEC-NUM  TO WS-WORK1.                               
    PERFORM                                                     
      VARYING WS-SUB1 FROM WS-LEN1 BY -1                         
      UNTIL WS-SUB1 < 1                                         
        DIVIDE WS-WORK1 BY 16 GIVING WS-WORK1 REMAINDER WS-WORK2
        MOVE WS-DIG(WS-WORK2 + 1) TO WS-HEX-NUM(WS-SUB1:1)       
    END-PERFORM.                                                 
C1000-EXIT.                                                     
    EXIT.                                                       
C2000-DEC-OCT.                                                 
    MOVE LENGTH OF WS-OCT-NUM TO WS-LEN1.                     
    MOVE WS-LEN1 TO WS-SUB1                                   
    MOVE WS-DEC-NUM  TO WS-WORK1.                             
    PERFORM                                                   
      VARYING WS-SUB1 FROM WS-LEN1 BY -1                       
      UNTIL WS-SUB1 < 1                                       
        DIVIDE WS-WORK1 BY 8 GIVING WS-WORK1 REMAINDER WS-WORK2
        MOVE WS-DIG(WS-WORK2 + 1) TO WS-OCT-NUM(WS-SUB1:1)     
    END-PERFORM.                                               
C2000-EXIT.                                                   
    EXIT.                                                     


Results of above code

Code:

DEC NUMBER = 0015288453 HEX NUMBER = 0000E94885       
DEC NUMBER = 0015288453 OCT NUMBER = 0072244205       


If you look at the code you will see that it can be condenced. I'll leave this up to you. If you have a problem convering from hex or oct to dec let me know.

Dave
Back to top
View user's profile Send private message
Sridevi_C

Active User


Joined: 22 Sep 2005
Posts: 104
Location: Concord, New Hampshire, USA.

PostPosted: Mon Aug 21, 2006 8:16 pm    Post subject: Re: How to use hex and octal numbers in cobol
Reply with quote

Thank you Dave. Good info.
Back to top
View user's profile Send private message
NIRAJ BILGE

New User


Joined: 05 Aug 2006
Posts: 11

PostPosted: Wed Aug 30, 2006 11:30 am    Post subject:
Reply with quote

thanks david.
thank u very much icon_biggrin.gif
Back to top
View user's profile Send private message
Sarva_bubli

New User


Joined: 09 Aug 2006
Posts: 37
Location: Pune, India

PostPosted: Wed Aug 30, 2006 12:04 pm    Post subject:
Reply with quote

Thanks Dave, It is a good info..

Regds,
Saravanan V.S
Pune,
India
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 SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am


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