Skip to Content
author's profile photo
Former Member

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

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 11:12 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 10:08 AM

    Hi Pradeep,

    Is this your complete code?

    Regards,

    Ravi

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 10:26 AM

    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.........

    Add comment
    10|10000 characters needed characters exceeded