Application Development and Automation 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: 
Read only

using field symbols in OOPs programming...have ur points.

Former Member
0 Likes
725

Hi all,

I want to use field symbols in OOPS programming like this...

But the system is giving me dump....help me.

START-OF-SELECTION.

CREATE OBJECT OBJ.

FIELD-SYMBOLS : <AB> TYPE ANY.

ASSIGN OBJ TO <AB>.

CALL METHOD <AB>->add

EXPORTING

a = 4

b = 6

changing

c = Z

.

WRITE : / Z.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
651

Pradeep,

In this piece of code you have declared your field symbol as TYPE ANY. In this case when you do a call method it will give you errors. Instead of this declare the field sybol as the type of the calling class. refer to this syntax -


REPORT  ZSKC_TEST4 MESSAGE-ID IH
        NO STANDARD PAGE HEADING.

TYPES : TYP_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA : L_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA : L_HEIGHT TYPE I.

FIELD-SYMBOLS : <FS> TYPE TYP_CONT.

START-OF-SELECTION.

CREATE OBJECT L_CONT EXPORTING CONTAINER_NAME = 'TEST'.

ASSIGN L_CONT TO <FS>.

CALL METHOD L_CONT->GET_HEIGHT
  IMPORTING
    HEIGHT     = L_HEIGHT
  EXCEPTIONS
    CNTL_ERROR = 1
    others     = 2.

WRITE L_HEIGHT.

CALL METHOD <FS>->GET_HEIGHT
  IMPORTING
    HEIGHT     = L_HEIGHT
  EXCEPTIONS
    CNTL_ERROR = 1
    others     = 2.

WRITE L_HEIGHT.

Just make sure your OBJ is initialized, u can check that in debugging mode.

3 REPLIES 3
Read only

Former Member
0 Likes
651

Hi Pradeep,

Is this your complete code?

Regards,

Ravi

Read only

Former Member
0 Likes
651

check the code below

TYPES: BEGIN OF t_struct,

col1 TYPE i,

col2 TYPE i,

END OF t_struct.

DATA: dref1 TYPE REF TO data,

dref2 TYPE REF TO data.

FIELD-SYMBOLS: <fs1> TYPE t_struct,

<fs2> TYPE i.

CREATE DATA dref1 TYPE t_struct.

ASSIGN dref1->* TO <fs1>.

<fs1>-col1 = 1.

<fs1>-col2 = 2.

dref2 = dref1.

ASSIGN dref2->* TO <fs2> CASTING.

WRITE / <fs2>.

GET REFERENCE OF <fs1>-col2 INTO dref2.

ASSIGN dref2->* TO <fs2>.

WRITE / <fs2>.

reward points if helpful.........

Read only

Former Member
0 Likes
652

Pradeep,

In this piece of code you have declared your field symbol as TYPE ANY. In this case when you do a call method it will give you errors. Instead of this declare the field sybol as the type of the calling class. refer to this syntax -


REPORT  ZSKC_TEST4 MESSAGE-ID IH
        NO STANDARD PAGE HEADING.

TYPES : TYP_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA : L_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA : L_HEIGHT TYPE I.

FIELD-SYMBOLS : <FS> TYPE TYP_CONT.

START-OF-SELECTION.

CREATE OBJECT L_CONT EXPORTING CONTAINER_NAME = 'TEST'.

ASSIGN L_CONT TO <FS>.

CALL METHOD L_CONT->GET_HEIGHT
  IMPORTING
    HEIGHT     = L_HEIGHT
  EXCEPTIONS
    CNTL_ERROR = 1
    others     = 2.

WRITE L_HEIGHT.

CALL METHOD <FS>->GET_HEIGHT
  IMPORTING
    HEIGHT     = L_HEIGHT
  EXCEPTIONS
    CNTL_ERROR = 1
    others     = 2.

WRITE L_HEIGHT.

Just make sure your OBJ is initialized, u can check that in debugging mode.