2019 Oct 16 10:16 AM
Hi,
Can we pass the Field symbol as a internal table to the method of class? I have requirement that in one method internal table will get create dynamically with help of field Catalog and that internal table I have to pass to other method for filling data into that internal table. please help me into this.
Thanks.
2019 Oct 16 10:38 AM
why it should not work ?
CLASS lc_display DEFINITION FINAL.
PUBLIC SECTION.
METHODS display_marc
IMPORTING
it_table_marc TYPE marc_tt
RETURNING
VALUE(rv_sucess) TYPE abap_bool.
ENDCLASS.
CLASS lc_display IMPLEMENTATION.
METHOD display_marc.
cl_demo_output=>display_data( it_table_marc ).
ENDMETHOD.
ENDCLASS.
CLASS lc_data DEFINITION FINAL.
PUBLIC SECTION.
METHODS get_marc_entry
IMPORTING
iv_material_number TYPE matnr
RETURNING
VALUE(rv_success) TYPE abap_bool.
ENDCLASS.
CLASS lc_data IMPLEMENTATION.
METHOD get_marc_entry.
DATA lt_marc_entries TYPE marc_tt.
SELECT *
INTO TABLE lt_marc_entries
FROM marc
WHERE matnr EQ iv_material_number.
FIELD-SYMBOLS <lt_marc> TYPE table.
ASSIGN lt_marc_entries TO <lt_marc>.
CHECK <lt_marc> IS ASSIGNED.
NEW lc_display( )->display_marc( <lt_marc> ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
NEW lc_data( )->get_marc_entry( 'yourmaterialnumber' ).
END-OF-SELECTION.
2019 Oct 16 10:24 AM
As long as the field symbol is assigned to a internal table of the correct type, that should work.
But if you'd post a code snippet, it will be easier to 'judge'..
2019 Oct 16 11:23 AM
REPORT zsk_alv_sum.
*& types
TYPES:
BEGIN OF ty_suborder,
tabix TYPE sy-tabix,
branch TYPE zsk_cust-branch,
END OF ty_suborder.
*& Data Definations
DATA: gt_suborder TYPE STANDARD TABLE OF ty_suborder.
DATA: it_cust TYPE TABLE OF zsk_cust,
wa_cust TYPE zsk_cust,
it_cust1 TYPE TABLE OF zsk_cust,
wa_cust1 TYPE zsk_cust,
it_final TYPE REF TO data,
wa_final TYPE REF TO data,
it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF it_fcat.
DATA: lv_lines TYPE i,
lv_no TYPE n,
lv_tabix TYPE i,
currancy TYPE string,
currancy1 TYPE string,
subtotal TYPE string,
line_color TYPE string,
subtotal1 TYPE p DECIMALS 2,
total1 TYPE p DECIMALS 2,
lv_conv TYPE p DECIMALS 2,
total TYPE string,
branch TYPE string.
DATA: gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
ifc TYPE lvc_t_fcat,
lwa_suborder TYPE ty_suborder..
** Objects
** Field Symbols
FIELD-SYMBOLS: <fs_final> TYPE STANDARD TABLE,
<fw_final> TYPE any,
<customer_name>,
<branch>,
<subtotal>,
<curr>,
<total>,
<color>.
***--------------------------------------------------------------------*
***BREAK-POINT.
*& to select Data from database table
PERFORM get_data.
*& create a dynamic fieldCatalog
PERFORM create_catalog.
*& Fill the dynamic internal table in order to display at the output screen
PERFORM fill_it.
*& Display the output Call ALV grid display
PERFORM display.
form get_data.
SELECT * FROM zsk_cust
INTO TABLE it_cust.
endform.
form create_catalog.
LOOP AT it_cust INTO wa_cust.
DATA: lv_tabix TYPE i.
lv_tabix = sy-tabix.
IF sy-tabix = 1.
wa_fcat-fieldname = 'CUSTOMER'..
wa_fcat-seltext_m = 'CUSTOMER'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDIF.
IF wa_cust-branch <> branch.
wa_fcat-fieldname = wa_cust-branch.
wa_fcat-seltext_m = wa_cust-branch.
branch = wa_cust-branch.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lwa_suborder-tabix = lwa_suborder-tabix + 1.
lwa_suborder-branch = wa_cust-branch.
APPEND lwa_suborder TO gt_suborder.
ENDIF.
endloop.
total = 'TOTAL'.
wa_fcat-fieldname = total.
wa_fcat-seltext_m = 'TOTAL'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = it_final.
ASSIGN it_final->* TO <fs_final>.
*& Create dynamic work area and assign to Field Symbol
CREATE DATA wa_final LIKE LINE OF <fs_final>.
ASSIGN wa_final->* TO <fw_final>.
endform.
form fill_it.
*** fill <fs_final>.
endform.
form display.
**call function alv grid display. passing <fs_final>
endform.
2019 Oct 16 11:30 AM
Now above code i want in object oriented form like methods and class so we can not use Field symbol in class definition, How can i get generated internal table <fs_final> in create_catalog form into the method as a changing parameter??
2019 Oct 16 7:58 PM
You could go for something like this:
CLASS lv_test DEFINITION.
PUBLIC SECTION.
METHODS:
use_any_parameter IMPORTING i_table TYPE ANY TABLE.
ENDCLASS.
In this case you can pass any table as an importing parameter of the method.
Another option is of course using 'type ref to data' as Frederic explains below.
2019 Oct 16 10:38 AM
why it should not work ?
CLASS lc_display DEFINITION FINAL.
PUBLIC SECTION.
METHODS display_marc
IMPORTING
it_table_marc TYPE marc_tt
RETURNING
VALUE(rv_sucess) TYPE abap_bool.
ENDCLASS.
CLASS lc_display IMPLEMENTATION.
METHOD display_marc.
cl_demo_output=>display_data( it_table_marc ).
ENDMETHOD.
ENDCLASS.
CLASS lc_data DEFINITION FINAL.
PUBLIC SECTION.
METHODS get_marc_entry
IMPORTING
iv_material_number TYPE matnr
RETURNING
VALUE(rv_success) TYPE abap_bool.
ENDCLASS.
CLASS lc_data IMPLEMENTATION.
METHOD get_marc_entry.
DATA lt_marc_entries TYPE marc_tt.
SELECT *
INTO TABLE lt_marc_entries
FROM marc
WHERE matnr EQ iv_material_number.
FIELD-SYMBOLS <lt_marc> TYPE table.
ASSIGN lt_marc_entries TO <lt_marc>.
CHECK <lt_marc> IS ASSIGNED.
NEW lc_display( )->display_marc( <lt_marc> ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
NEW lc_data( )->get_marc_entry( 'yourmaterialnumber' ).
END-OF-SELECTION.
2019 Oct 16 11:17 AM
Hi Fredric,
here in your method declaration you are taking internal table like marc_tt. But I want to create a internal table dynamically with field symbol and then pass that internal table to another method.
PUBLICSECTION.
METHODS display_marc
IMPORTING
it_table_marc TYPE marc_tt
RETURNINGVALUE(rv_sucess)TYPE abap_bool.
2019 Oct 16 12:14 PM
so everything should be in TYPE REF TO DATA
CLASS lc_display DEFINITION FINAL.
PUBLIC SECTION.
METHODS display_table
IMPORTING
o_table TYPE REF TO data
RETURNING
VALUE(rv_sucess) TYPE abap_bool.
ENDCLASS.
CLASS lc_display IMPLEMENTATION.
METHOD display_table.
FIELD-SYMBOLS <it_table> TYPE table.
ASSIGN o_table->* TO <it_table>.
cl_demo_output=>display_data( <it_table> ).
ENDMETHOD.
ENDCLASS.
CLASS lc_data DEFINITION FINAL.
PUBLIC SECTION.
METHODS get_marc_entry
IMPORTING
iv_material_number TYPE matnr
RETURNING
VALUE(rv_success) TYPE abap_bool.
PRIVATE SECTION.
DATA go_table TYPE REF TO data.
ENDCLASS.
CLASS lc_data IMPLEMENTATION.
METHOD get_marc_entry.
DATA lt_marc_entries TYPE marc_tt.
SELECT *
INTO TABLE lt_marc_entries
FROM marc
WHERE matnr EQ iv_material_number.
CREATE DATA go_table LIKE lt_marc_entries.
ASSIGN go_table->* TO FIELD-SYMBOL(<lt_data>).
<lt_data> = lt_marc_entries.
NEW lc_display( )->display_table( go_table ).
ENDMETHOD.
ENDCLASS.
2019 Oct 17 7:46 AM