Skip to Content
0
Former Member
May 13, 2010 at 12:50 PM

Comparing pointers not values, how ?

43 Views

Hi,

I'd like to somehow be able to compare memory locations of variables rather than their values.

For those curious why ? Well, I'd like to implement a conversion exit driven by an internal table. As the only parameters given to conversion exits are INPUT and OUTPUT I figured out I could make an internal table inside my report, store references to the variables (ie. reference to ITAB[1]-myvalue ) there and inside MATCH_FORM (or conversion exit) compare memory location of the input parameter with the locations stored inside the table of references.

Long story short(with some code snippets):

PART A.

- insert 4 numbers into an internal table it_numbers[]

- insert reference to the 4th number into an internal table it_references[]

DATA:
       it_numbers TYPE STANDARD TABLE OF i,
       it_references TYPE STANDARD TABLE OF REF TO i,
       ref_to_number TYPE REF TO i.

FIELD-SYMBOLS:
       <fs_number> LIKE LINE OF it_numbers.

APPEND 123 TO it_numbers.
APPEND 456 TO it_numbers.
APPEND 789 TO it_numbers.
APPEND 123 TO it_numbers.

READ TABLE it_numbers INDEX 4 ASSIGNING <fs_number>.
GET REFERENCE OF <fs_number> INTO ref_to_number.
APPEND ref_to_number TO it_references.

PART B.

- get the reference of passed parameter

- loop at table of references and compare whether reference to the parameter is there

- if it is there then do something

PERFORM match USING <fs_number>.

FORM match USING number TYPE i.
  DATA:
        lcl_ref_to_number TYPE REF TO i.

  FIELD-SYMBOLS:
       <fs_reference> LIKE LINE OF it_references.

  GET REFERENCE OF number INTO lcl_ref_to_number.

  LOOP AT it_references ASSIGNING <fs_reference>.
    IF <fs_reference> EQ lcl_ref_to_number.
      WRITE: / ' OK '.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "match

The problem is I got lost, kept trying but was only able to achieve comparison at the value level(code above) i.e. numbers where compared and not their respective memory locations. Is is actually possible to "go the low level way" and compare memory locations rather than values ?

Cheers,

Bart