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
 

 

Display the hexadecimal address of a pointer in Cobol

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

New User


Joined: 28 May 2015
Posts: 3
Location: Germany

PostPosted: Thu May 28, 2015 5:50 pm    Post subject: Display the hexadecimal address of a pointer in Cobol
Reply with quote

I want to display the hexadecimal address of a pointer in Cobol.

My attempts leads to display the decimal address only.

My pointer is defined like:

Code:
       WORKING-STORAGE SECTION.
       01  CURRENT-PTR                    USAGE IS POINTER VALUE NULL.
       01  START-PTR                      USAGE IS POINTER VALUE NULL.
       ...


my attempt to display the address brings decimal numbers:

Code:

                 SET START-PTR TO CURRENT-PTR


CURRENT-POINTER is defined the same way and assigned by this call:

Code:
             CALL "CEEGTST" USING HEAPID , FIELD-SIZE,
                            CURRENT-PTR , FC


Here the display (it's in a loop):

Code:
             DISPLAY "Address: " START-PTR


Here the output:

Code:
-------------------------------------------
Address: 0386720240
This is list item number 1
-------------------------------------------
Address: 0386720344
This is list item number 2
-------------------------------------------
Address: 0386720448
This is list item number 3   
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Thu May 28, 2015 6:26 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Try this one from Mr Bill.

REDEFINES your POINTER as PIC X(4) and use that in place of W-SYSIN-VALUE.
Back to top
View user's profile Send private message
M_Kaiser

New User


Joined: 28 May 2015
Posts: 3
Location: Germany

PostPosted: Thu May 28, 2015 7:55 pm    Post subject:
Reply with quote

Hi, thanks for your advise, some problems left...

I understood, that the W-SYSIN-VALUE from Bills sample is equivalent to my pointer START-PTR. Is that correct?

When I just exchange both values, this fails at compile time:

Code:
             MOVE START-PTR TO WS-DISPLAY-X                                      1084 1087

 IGYPS2074-S "START-PTR" was defined as a type that was invalid in this context.  The
                     statement was discarded.


Definitions:
Code:

       01  START-PTR                      USAGE IS POINTER VALUE NULL.

       01  WS-DISPLAY           PIC 9(08)V9.
       01  WS-DISPLAY-X         REDEFINES WS-DISPLAY PIC X(09).
       01  WS-PACKED            PIC 9(08)V9 COMP-3.
       01  WS-PACKED-X          REDEFINES WS-PACKED PIC X(05).
       01  WS-HEX-VALUE         PIC X(04).


Coding:
Code:

             MOVE START-PTR TO WS-DISPLAY-X
             MOVE ZERO TO WS-DISPLAY-X (9:)

             INSPECT WS-DISPLAY-X CONVERTING 'ABCDEF'
                                     TO X'FAFBFCFDFEFF'
             MOVE WS-DISPLAY  TO WS-PACKED
             MOVE WS-PACKED-X TO WS-HEX-VALUE

             DISPLAY "Address in Hex: " WS-HEX-VALUE
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Thu May 28, 2015 8:10 pm    Post subject:
Reply with quote

MOVE START-PTR TO WS-DISPLAY
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 May 28, 2015 8:10 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Redefine START-PTR as START-FWORD PIC 9(08) COMP.

HTH....
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Thu May 28, 2015 8:11 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Yes, you can't MOVE a POINTER. That's why I suggested a REDEFINES of it.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Thu May 28, 2015 8:19 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Flurry of activity on this one :-)

The REDEFINES needs to be the same type as the field you want to MOVE it to. PIC X(4) to PIC X(4), for instance.

If you want to define it as binary, I'd use PIC 9(9) COMP-5. COMP-5 says you're going to have access to all the bits. With COMP (or COMP-4 or BINARY) you have a maximum value of the number of digits in the definition.

For addresses, which can easily be a value of greater than 99,999,999 COMP-5 is better in a documentary way and can be vital depending on what is done with the field.
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 May 28, 2015 8:56 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Bill,

As I'm a proponent of COMP-5, you're correct that the OP should redefine the POINTER as such to address the whole magilla. It's better than non COMP-5 with TRUNC(BIN) icon_smile.gif
Back to top
View user's profile Send private message
M_Kaiser

New User


Joined: 28 May 2015
Posts: 3
Location: Germany

PostPosted: Thu May 28, 2015 9:02 pm    Post subject:
Reply with quote

unfortunatley it prints out then only "@" when using REDEFINES PIC X(4)


I now got a sample from a peer which works, but I can't distribute it public.



Maybe I will try to get your sample running tomorrow...
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri May 29, 2015 2:21 am    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Sorry, my fault. I gave the link to the version which takes a character hex value and turns it into a field with that binary value.

If you "run it backwards" it will work, but I'll try to sort out a new link when I have more than 18 seconds available.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri May 29, 2015 4:46 am    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

I'm not so sure the search is working here properly. Here's this one.

Here's the bit you want, obviously you'll need equivalent WORKING-STORAGE items as well:

Code:
           MOVE WS-GET2CAA-POINTER-X   TO WS-PACKED-X (1:4)             
           MOVE WS-PACKED-V9           TO WS-DISPLAY-V9                 
      *                                                                 
           INSPECT WS-DISPLAY-X        CONVERTING X'FAFBFCFDFEFF'       
                                       TO 'ABCDEF'


The power of the method is that you can do multiple bytes in one shot, very efficiently.

Here's a program I use for displaying stuff in hex from within a program.

At some point in time I'll update the program to use Mr Bill's superior method, and also to give the option of sideways or vertical for the hex. At some point in time.
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: Fri May 29, 2015 5:00 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Bill,

BTW, when using the "ARITH(EXTEND)" compiler option, WS-PACKED-V9 can be defined as PIC 9(30)V9 PACKED-DECIMAL and WS-DISPLAY-V9 can be defined as PIC 9(30)V9, allowing up to 30-Bytes to be converted in one fell swoop.

HTH....
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri May 29, 2015 5:35 pm    Post subject: Reply to: Easy way to display the hex address of a pointer
Reply with quote

Hi Bill,

Yes, and it can do 30 bytes faster than any other method can do one :-)

At least up to Enterprise COBOL V4.2. I don't know, but perhaps V5.x can do one byte faster due to the substitution of bit-shifting for multiplication/division of binary fields by powers of two. But even so, that's only one byte, not 30.
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
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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