11-30-2007 4:56 PM
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 ??
12-01-2007 8: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
11-30-2007 5: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
12-01-2007 8: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
12-03-2007 4:09 AM
12-03-2007 1: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
12-04-2007 10:28 AM
Thank you for the example, that is exactly what i did !!! )
I wrote me a class to work with alv, i have three methods: get_structure, create_dynamic_table and display_alv_grid.
Thanks again.