Skip to content

Commit

Permalink
Type Ref to Data Table with refresh
Browse files Browse the repository at this point in the history
There seem to be an error when refreshing type ref to data Tables. 

Start App -> Klick Button Add -> Klick Refresh 

Table in Background has 2 Entries 
Table in Browser has 4 Entries
  • Loading branch information
Viktor Hoffmann authored and Viktor Hoffmann committed May 16, 2024
1 parent dd61841 commit 529ad6e
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 0 deletions.
197 changes: 197 additions & 0 deletions src/z2ui5_cl_demo_app_199.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
CLASS z2ui5_cl_demo_app_199 DEFINITION
PUBLIC
CREATE PUBLIC.

PUBLIC SECTION.
INTERFACES z2ui5_if_app.

DATA mt_table TYPE REF TO data.

DATA mt_comp TYPE abap_component_tab.

PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
DATA check_initialized TYPE abap_bool.

METHODS on_init.
METHODS on_event.

METHODS render_main.

PRIVATE SECTION.
METHODS get_data.
METHODS refresh.
METHODS add_data.

METHODS get_comp
RETURNING VALUE(result) TYPE abap_component_tab.
ENDCLASS.

CLASS z2ui5_cl_demo_app_199 IMPLEMENTATION.

METHOD on_event.

CASE client->get( )-event.

WHEN 'BACK'.

client->nav_app_leave( client->get_app( client->get( )-s_draft-id_prev_app_stack ) ).

WHEN 'REFRESH'.

refresh( ).
client->view_model_update( ).

WHEN 'ADD'.

add_data( ).
client->view_model_update( ).

ENDCASE.
ENDMETHOD.

METHOD on_init.
get_data( ).
render_main( ).
ENDMETHOD.

METHOD render_main.

DATA(page) = z2ui5_cl_xml_view=>factory( ).

FIELD-SYMBOLS <tab> TYPE data.
ASSIGN mt_table->* TO <tab>.

DATA(table) = page->table( growing = 'true'
width = 'auto'
items = client->_bind( <tab> )
* headertext = mv_table
).

DATA(columns) = table->columns( ).

LOOP AT mt_comp INTO DATA(comp).

IF comp-name = 'DATA'.
CONTINUE.
ENDIF.

columns->column( )->text( comp-name ).

ENDLOOP.

DATA(cells) = columns->get_parent( )->items(
)->column_list_item( valign = 'Middle'
type = 'Navigation'
)->cells( ).

LOOP AT mt_comp INTO comp.

IF comp-name = 'DATA'.
CONTINUE.
ENDIF.

cells->object_identifier( text = '{' && comp-name && '}' ).
ENDLOOP.

page->button( text = 'Refresh'
press = client->_event( 'REFRESH' )
)->button( text = 'Add'
press = client->_event( 'ADD' ) ).

client->view_display( page->get_root( )->xml_get( ) ).

ENDMETHOD.

METHOD z2ui5_if_app~main.
me->client = client.

IF check_initialized = abap_false.
check_initialized = abap_true.

on_init( ).

ENDIF.

on_event( ).
ENDMETHOD.

METHOD get_data.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

mt_comp = get_comp( ).

TRY.

DATA(new_struct_desc) = cl_abap_structdescr=>create( mt_comp ).

DATA(new_table_desc) = cl_abap_tabledescr=>create( p_line_type = new_struct_desc
p_table_kind = cl_abap_tabledescr=>tablekind_std ).

CREATE DATA mt_table TYPE HANDLE new_table_desc.

ASSIGN mt_table->* TO <table>.

SELECT * FROM z2ui5_t_01
INTO CORRESPONDING FIELDS OF TABLE @<table>
UP TO 2 ROWS.

CATCH cx_root.

ENDTRY.

ENDMETHOD.

METHOD get_comp.
TRY.

DATA index TYPE int4.

TRY.

cl_abap_typedescr=>describe_by_name( EXPORTING p_name = 'Z2UI5_T_01'
RECEIVING p_descr_ref = DATA(typedesc)
EXCEPTIONS type_not_found = 1
OTHERS = 2 ).

DATA(structdesc) = CAST cl_abap_structdescr( typedesc ).
DATA(comp) = structdesc->get_components( ).

LOOP AT comp INTO DATA(com).
IF com-as_include = abap_false.
APPEND com TO result.
ENDIF.
ENDLOOP.

CATCH cx_root.

ENDTRY.

DATA(component) = VALUE cl_abap_structdescr=>component_table(
( name = 'ROW_ID'
type = CAST #( cl_abap_datadescr=>describe_by_data( index ) ) ) ).

APPEND LINES OF component TO result.

CATCH cx_root.
ENDTRY.
ENDMETHOD.

METHOD add_data.

FIELD-SYMBOLS <tab> TYPE STANDARD TABLE.

ASSIGN mt_table->* TO <tab>.

APPEND LINES OF <tab> TO <tab>.

ENDMETHOD.

METHOD refresh.

get_data( ).

ENDMETHOD.

ENDCLASS.
16 changes: 16 additions & 0 deletions src/z2ui5_cl_demo_app_199.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_DEMO_APP_199</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Deep Structure Sub App</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

0 comments on commit 529ad6e

Please sign in to comment.