Skip to Content

Passing unassigned field symbols to a method

Hello Gurus,

I work with a field symbol in a method and after the work is finished i have to use it i my program that i call the method from.

The problem is that the field symbol gets assigned only in the method so i can`t get the field symbol as a changing parameter in my method because it is not assigned yet.

I thought that i can return the field symbol from the method after it has been assigned, but i don`t know how. The <fs> is a dynamic itab that i created within the method.

Can anyone help please ??

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Dec 01, 2007 at 08:39 PM

    It's an annoying feature of ABAP Objects that you can't return field symbols in this way. But there's a way of getting the same results.

    Calling program

    DATA: lp_data TYPE REF TO DATA.
    ...
    lp_data = my_method( ).
    ASSIGN lp_data->* TO <fs>.

    In my_method, which is defined with a RETURNING parameter, rp_data, TYPE REF TO DATA, you have something like this:

    GET REFERENCE OF <fs_table_in_method> INTO rp_data. 

    When you run the calling program, you'll find that <fs> contains what was in <fs_table_in_method>.

    I hope that's clear!

    matt

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 30, 2007 at 05:11 PM

    You need to assign it before you pass to the Method.

    So, try to assign some DUMMY strcutre to that.

    Try like this

    FIELD-SYMBOLS: <FS> TYPE ANY.
    
    DATA: BEGIN OF ITAB OCCURS 0,
          DATE TYPE D,
          END   OF ITAB.
    
    ITAB-DATE = SY-DATUM.
    APPEND ITAB.
    
    ASSIGN ITAB[] TO <FS>.
    
    * CALL METHOD

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 01:18 PM

    Although already answered this code snippet might make it clearer

    my_line is your data structure typically an itab structure.

    For example

    TYPES: BEGIN OF s_elements,

    tabname type DD02L-tabname,

    tabclass type dd02l-tabclass,

    as4user type dd02L-as4user,

    as4date type dd02l-as4date,

    as4time type DD02l-as4time,

    viewed(1) type c.

    TYPES: END OF s_elements.

    Data: my_line TYPE s_elements.

    1) get the structure of your itab automatically so you can build an FCAT simply for any structure without the horrendous usual coding to manipulate and create FCATS.

    CALL METHOD me->return_structure

    EXPORTING

    my_line = my_line.

    You need to make a table ZOGT data available in the class definition either as an attribute if you are using the class builder SE24 or as DATA in the relevant class section.

    data:

    zog LIKE LINE OF lr_rtti_struc->components .

    data:

    zogt LIKE TABLE OF zog .

    method RETURN_STRUCTURE.

    lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( my_line ).

    zogt[] = lr_rtti_struc->components.

    • ...

    endmethod.

    Your structure details are now in table zogt.

    Use this to build an FCAT.

    CALL METHOD me->create_dynamic_fcat

    IMPORTING

    it_fldcat = it_fldcat.

    method CREATE_DYNAMIC_FCAT.

    LOOP AT zogt INTO zog.

    CLEAR wa_it_fldcat.

    wa_it_fldcat-fieldname = zog-name .

    wa_it_fldcat-datatype = zog-type_kind.

    wa_it_fldcat-inttype = zog-type_kind.

    wa_it_fldcat-intlen = zog-length.

    wa_it_fldcat-decimals = zog-decimals.

    wa_it_fldcat-coltext = zog-name.

    wa_it_fldcat-lowercase = 'X'.

    APPEND wa_it_fldcat TO it_fldcat .

    ENDLOOP.

    • ...

    endmethod.

    Now having got your FCAT you can build your dynamic table.

    CALL METHOD me->create_dynamic_table

    EXPORTING

    it_fldcat = it_fldcat

    IMPORTING

    dy_table = dy_table.

    (dy_table is defined as ref to data)

    method CREATE_DYNAMIC_TABLE.

    CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

    it_fieldcatalog = it_fldcat

    IMPORTING

    ep_table = dy_table.

    • ...

    endmethod.

    Now populate your dynamic table as per sample code here

    field_symbols:

    <dyn_table> TYPE STANDARD TABLE.

    <dyn_wa>.

    data: dy_line TYPE REF TO data.

    FORM populate_dynamic_itab.

    ASSIGN dy_table->* TO <dyn_table>.

    CREATE DATA dy_line LIKE LINE OF <dyn_table>.

    ASSIGN dy_line->* TO <dyn_wa>.

    SELECT *

    FROM DD02L

    INTO CORRESPONDING FIELDS OF TABLE <dyn_table>

    WHERE TABNAME LIKE 'ZHR%'.

    ENDFORM.

    Now you can display your grid and process your data.

    CALL METHOD z_object->display_grid

    EXPORTING

    g_outtab = <dyn_table>

    g_fldcat = it_fldcat

    i_gridtitle = i_gridtitle

    i_edit = i_edit

    i_zebra = i_zebra

    CHANGING

    it_fldcat = it_fldcat

    gt_outtab = <dyn_table>.

    In the Method

    method DISPLAY_GRID.

    GET REFERENCE OF g_outtab INTO g_outtab1.

    GET REFERENCE OF g_fldcat INTO g_fldcat1.

    struct_grid_lset-edit = i_edit. "To enable editing

    struct_grid_LSET-zebra = i_zebra.

    struct_grid_lset-grid_title = i_gridtitle.

    struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.

    struct_grid_lset-stylefname = 'CELLTAB'.

    CALL METHOD grid1->set_ready_for_input

    EXPORTING

    i_ready_for_input = '1'.

    CALL METHOD grid1->set_table_for_first_display

    EXPORTING

    is_layout = struct_grid_lset

    CHANGING

    it_outtab = gt_outtab

    it_fieldcatalog = it_fldcat.

    ENDMETHOD.

    You can even easily code your own column names if you so wish in the application program.

    Before calling the method that displays the grid encode the following macro.

    DEFINE col_name.

    read table it_fldcat into wa_it_fldcat index &1.

    wa_it_fldcat-coltext = &2.

    wa_it_fldcat-outputlen = &3.

    modify it_fldcat from wa_it_fldcat index &1.

    END-OF-DEFINITION.

    Then have a subroutine in your application code something like this

    Form name_columns.

    • Here before displaying you can change the field catalog to

    • adjust your own column names.

    *col_name col-nr 'your name' output length.

    col_name 1 'Table name' 30.

    col_name 2 'Table class' 12.

    col_name 3 'Changed By' 12.

    col_name 4 ' On' 12.

    col_name 5 ' At' 8.

    col_name 6 'Act' 3.

    i_gridtitle = 'HR ESS / ITS ZHR Tables - Double click to display'.

    i_zebra = 'X'.

    i_edit = ' '.

    endform.

    Hope this clears it up a bit.

    Once you get this stuff working you can re-use 99% of the code for almost any structure making the whole process of OO ALV grid applications really simple.

    Yoy only need as well a standard dynpro with a custom container on it (se51).

    Cheers

    jimbo

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.