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

Display the hexadecimal address of a pointer in Cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu May 28, 2015 6:26 pm
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu May 28, 2015 8:10 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu May 28, 2015 8:11 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu May 28, 2015 8:19 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu May 28, 2015 8:56 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri May 29, 2015 2:21 am
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri May 29, 2015 4:46 am
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri May 29, 2015 5:00 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri May 29, 2015 5:35 pm
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 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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Routing command Address SDSF to other... TSO/ISPF 2
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top