Binding
Binding types for integer, decimal, date and time - the conversion between the ABAP field and what the control shows, with a sum over the bound table.
Z2UI5_CL_SMP_APP_047
Learn
Binding
UI5 1.71
The facts
- Repository
- abap2UI5/samples
- Class
Z2UI5_CL_SMP_APP_047- Source file
z2ui5_cl_smp_app_047.clas.abap↗- Category
- Binding
- Learning path
- Get your data on screen
- Minimum UI5
- 1.71 — the floor abap2UI5 holds its samples to
- In the playground
- runs in the browser, with no system and nothing installed
- Documentation
- abap2ui5.github.io/docs/cookbook/model/binding ↗
Keywords: type, conversion, sum, amount, number, field
Controls it builds
- sap.m.Button
- sap.m.Column
- sap.m.ColumnListItem
- sap.m.Input
- sap.m.Label
- sap.m.MessageStrip
- sap.m.Page
- sap.m.ScrollContainer
- sap.m.Shell
- sap.m.Table
- sap.m.Text
- sap.m.Title
- sap.ui.core.mvc.View
- sap.ui.layout.form.SimpleForm
Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.
Libraries
Run it here
The sample running, in this page — the app on its own, with no editor over it.
Switch to Playground with this code
Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.
The ABAP
z2ui5_cl_smp_app_047.clas.abap — 146 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords type conversion sum amount number field
" @summary Binding types for integer, decimal, date and time - the conversion between the ABAP field and what the control shows, with a sum over the bound table.
" @docs https://abap2ui5.github.io/docs/cookbook/model/binding
CLASS z2ui5_cl_smp_app_047 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
TYPES:
BEGIN OF ty_s_row,
date TYPE d,
time TYPE t,
END OF ty_s_row.
DATA int1 TYPE i.
DATA int2 TYPE i.
DATA int_sum TYPE i.
DATA dec1 TYPE p LENGTH 10 DECIMALS 4.
DATA dec2 TYPE p LENGTH 10 DECIMALS 4.
DATA dec_sum TYPE p LENGTH 10 DECIMALS 4.
DATA date TYPE d.
DATA time TYPE t.
DATA mt_tab TYPE STANDARD TABLE OF ty_s_row WITH EMPTY KEY.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smp_app_047 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
IF client->check_on_init( ).
date = sy-datum.
time = sy-uzeit.
dec1 = - 1 / 3.
dec2 = 2 / 3.
mt_tab = VALUE #( ( date = sy-datum time = sy-uzeit ) ).
client->_bind( mt_tab ).
ENDIF.
CASE client->get_event( ).
WHEN `BUTTON_INT`.
int_sum = int1 + int2.
WHEN `BUTTON_DEC`.
dec_sum = dec1 + dec2.
ENDCASE.
DATA(page) = z2ui5_cl_ui5_view_builder=>factory(
)->ele( n = `View` ns = `mvc`
)->a( n = `displayBlock` v = `true`
)->a( n = `height` v = `100%`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns:form` v = `sap.ui.layout.form`
)->ele( `Shell`
)->ele( `Page`
)->a( n = `title` v = `abap2UI5 - Binding - Types for Integer, Decimal, Date and Time`
)->a( n = `showNavButton` b = client->check_app_prev_stack( )
)->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).
page->tag( `MessageStrip`
)->a( n = `text` v = `Numeric and date/time binding: integer and decimal fields use automatic type ` &&
`conversion, buttons calculate the sums, and a growing table lists the values.`
)->a( n = `type` v = `Information`
)->a( n = `showIcon` b = abap_true
)->a( n = `class` v = `sapUiSmallMargin` ).
page->ele( n = `SimpleForm` ns = `form`
)->a( n = `title` v = `Integer and Decimals`
)->a( n = `editable` b = abap_true
)->ele( n = `content` ns = `form`
)->tag( `Title`
)->a( n = `text` v = `Input`
)->tag( `Label`
)->a( n = `text` v = `integer`
)->tag( `Input`
)->a( n = `value` v = client->_bind( int1 )
)->tag( `Input`
)->a( n = `value` v = client->_bind( int2 )
)->tag( `Input`
)->a( n = `enabled` b = abap_false
)->a( n = `value` v = client->_bind( int_sum )
)->tag( `Button`
)->a( n = `press` v = client->_event( `BUTTON_INT` )
)->a( n = `text` v = `calc sum`
)->tag( `Label`
)->a( n = `text` v = `decimals`
)->tag( `Input`
)->a( n = `value` v = client->_bind( dec1 )
)->tag( `Input`
)->a( n = `value` v = client->_bind( dec2 )
)->tag( `Input`
)->a( n = `enabled` b = abap_false
)->a( n = `value` v = client->_bind( dec_sum )
)->tag( `Button`
)->a( n = `press` v = client->_event( `BUTTON_DEC` )
)->a( n = `text` v = `calc sum`
)->tag( `Label`
)->a( n = `text` v = `date`
)->tag( `Input`
)->a( n = `value` v = client->_bind( date )
)->tag( `Label`
)->a( n = `text` v = `time`
)->tag( `Input`
)->a( n = `value` v = client->_bind( time ) ).
DATA(tab) = page->ele( `ScrollContainer`
)->a( n = `height` v = `70%`
)->a( n = `vertical` b = abap_true
)->ele( `Table`
)->a( n = `items` v = client->_bind( mt_tab )
)->a( n = `growing` b = abap_true
)->a( n = `growingThreshold` v = `20`
)->a( n = `growingScrollToLoad` b = abap_true
)->a( n = `sticky` v = `ColumnHeaders,HeaderToolbar` ).
tab->ele( `columns`
)->ele( `Column`
)->tag( `Text`
)->a( n = `text` v = `Date`
)->end(
)->ele( `Column`
)->tag( `Text`
)->a( n = `text` v = `Time`
)->end( ).
tab->ele( `items`
)->ele( `ColumnListItem`
)->ele( `cells`
)->tag( `Text`
)->a( n = `text` v = `{DATE}`
)->tag( `Text`
)->a( n = `text` v = `{TIME}` ).
client->view_display( page->stringify( ) ).
ENDMETHOD.
ENDCLASS.
More in Binding
- Binding — A View Built From RTTI, No Field Named
- Binding — Currency Amounts (sap.ui.model.type.Currency)
- Binding — Dynamic Table Typed at Runtime (RTTI)
- Binding — Expression Binding, Types and Composite Parts
- Binding — Model setSizeLimit for Large Tables (A)
- Binding — Single Table Cell (tab_index)
- Binding — Structure Fields and INCLUDEs
On this page