Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing the attributes of a class using field symbols?

suresh_datti
Active Contributor
0 Kudos

An option to pulll a variable into a user exit that otherwise would be out of reach is detailed [here|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/208811b0-00b2-2910-c5ac-dd2c7c50c8e8]

Can a similar approach involving field symbols or otherwise, be used to pull in the attributes of a class into the exit? For now, I'm trying to access the A_FRONTEND_INDEX attribute of the class CL_HRXSS_REM.

any ideas?

~Suresh

1 ACCEPTED SOLUTION

mvoros
Active Contributor
0 Kudos

Hi,

Have you already tried (PROGRAM)(OBJECT)->A_FRONTEND_INDEX in your code? I prepared small testing scenario with two programs and it works.


REPORT  zmv_test1.

FORM test.
  FIELD-SYMBOLS: <fs> TYPE ANY.

  ASSIGN '(ZMV_TEST2)zip->crc32_map' TO <fs>.
  IF sy-subrc EQ 0.
    <fs> = 'Test'.
  ENDIF.

ENDFORM.                    "test


REPORT  zmv_test2.

DATA: zip TYPE REF TO cl_abap_zip.

START-OF-SELECTION.
  CREATE OBJECT zip.
  PERFORM test IN PROGRAM zmv_test1.

Cheers,

8 REPLIES 8

mvoros
Active Contributor
0 Kudos

Hi,

Have you already tried (PROGRAM)(OBJECT)->A_FRONTEND_INDEX in your code? I prepared small testing scenario with two programs and it works.


REPORT  zmv_test1.

FORM test.
  FIELD-SYMBOLS: <fs> TYPE ANY.

  ASSIGN '(ZMV_TEST2)zip->crc32_map' TO <fs>.
  IF sy-subrc EQ 0.
    <fs> = 'Test'.
  ENDIF.

ENDFORM.                    "test


REPORT  zmv_test2.

DATA: zip TYPE REF TO cl_abap_zip.

START-OF-SELECTION.
  CREATE OBJECT zip.
  PERFORM test IN PROGRAM zmv_test1.

Cheers,

suresh_datti
Active Contributor
0 Kudos

It works fine in the classical programs.. I need to use a similar concept in the OO context.. ie access a variable ( attribute) of a Class..

~Suresh

mvoros
Active Contributor
0 Kudos

I knew that it had to be something different. I had similar problem while ago. I think it is impossible. I found this pdf.

[url]https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/37c5db90-0201-0010-3a9b-d0a5288f3c15[url]

There are some restrictions when you work inside the class. One of these restrictions is:

Memory Accesses - No access to memory outside a data object.

Cheers

suresh_datti
Active Contributor
0 Kudos

Impossible? I'm leaving this thread open hoping for a workaround..

~Suresh

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

This is interesting, because when discovering the field symbols trick to access a variable in the call stack, I was super excited. The reason was it allowed me to do some very nice things in order entry without too much of an issue. But at the same time, I kind of felt bad about it. Why? Because I should not have been allowed to do it. I then saw this as a weakness in ABAP, and of course only used it when I abolutly had to. That said, you have to realize that ABAP Objects was introduced to "fix" these types of weaknesses. OO by design, encapulates your data, and specific sections(public, private, and protected) and are only exposed(by the developer) if he really wants you to have access to it. Otherwise you would access it by some GET/SET method. With that said, if you were allowed to access this same attribute using a field symbol, anywhere in the call stack, then there would be absolutly no sense in using the OO concept to begin with. Right?

Regards,

Rich Heilman

0 Kudos

Hello Suresh

I tried to apply the same trick I previously described in [Accessing the Inacessible - Local Classes within Global Classes|https://wiki.sdn.sap.com/wiki/display/ABAP/AccessingtheInacessible-LocalClasseswithinGlobalClasses].

However, while this trick works for public attributes it fails for private attributes which is a relief with respect to Rich's remarks.

Regards

Uwe

matt
Active Contributor
0 Kudos

You can use the enhancement concept, however, to create getter and setter methods which retrieve and set private/protected attributes.

matt

suresh_datti
Active Contributor
0 Kudos

@ Rich, Uwe & Matt: Thanks for your valuable inputs..

I got lucky in this particular instance.. I was able to EXPORT the the variable to memory from a BAdI & IMPORT it inside a routine in a SMARTFORM.. the reqt was to use a different logo on the paystub based on the company (an employee is in for the pay period in question..)

Anyway, it is good to know what is 'private' remains so, after all..

~Suresh