abap2UI5

Currency in Table

Display Currencies in Table

Z2UI5_CL_SMPC_APP_171

Controls sap.ui.unified UI5 1.71

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_171
Source file
z2ui5_cl_smpc_app_171.clas.abap
Library
sap.ui.unified
UI5 entity
sap.ui.unified.Currency
Demo kit sample
sap.ui.unified.sample.CurrencyInTable
SAP's own sample
running at sdk.openui5.org ↗
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
runs in the browser, with no system and nothing installed

Keywords: currency, sap.ui.unified, amounts, table, column, text, columnlistitem, objectidentifier, objectnumber

Controls it builds

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_smpc_app_171.clas.abap — 146 lines Read it on GitHub ↗
" @keywords currency sap.ui.unified amounts table column text columnlistitem objectidentifier objectnumber
" @summary Display Currencies in Table
CLASS z2ui5_cl_smpc_app_171 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    TYPES:
      BEGIN OF ty_s_transaction_amount,
        size     TYPE p LENGTH 14 DECIMALS 2,
        currency TYPE string,
      END OF ty_s_transaction_amount,
      BEGIN OF ty_s_data,
        expense            TYPE string,
        transaction_amount TYPE ty_s_transaction_amount,
        exchange_rate      TYPE p LENGTH 13 DECIMALS 5,
        amount             TYPE p LENGTH 14 DECIMALS 2,
      END OF ty_s_data.
    DATA t_modeldata TYPE STANDARD TABLE OF ty_s_data WITH EMPTY KEY.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS model_init.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_171 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_init( ).
      model_init( ).
      view_display( ).
    ELSEIF client->check_on_navigated( ).
      view_display( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

    DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).

    view->ele( n = `View` ns = `mvc`
        )->a( n = `xmlns`     v = `sap.m`
        )->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
        )->a( n = `xmlns:u`   v = `sap.ui.unified`

        )->ele( `Table`
            )->a( n = `id`    v = `idProductsTable`
            )->a( n = `items` v = client->_bind( t_modeldata )

            )->ele( `columns`
                )->ele( `Column`
                    )->a( n = `id`     v = `exapnseColumn`
                    )->a( n = `hAlign` v = `Begin`

                    )->tag( `Text`
                        )->a( n = `text` v = `Expense`

                )->end(
                )->ele( `Column`
                    )->a( n = `id`     v = `transactionAmountColumn`
                    )->a( n = `hAlign` v = `End`

                    )->tag( `Text`
                        )->a( n = `text` v = `Transaction amount`

                )->end(
                )->ele( `Column`
                    )->a( n = `id`     v = `exchangeRateColumn`
                    )->a( n = `hAlign` v = `End`

                    )->tag( `Text`
                        )->a( n = `text` v = `Exchange rate`

                )->end(
                )->ele( `Column`
                    )->a( n = `id`     v = `amountColumn`
                    )->a( n = `hAlign` v = `End`

                    )->tag( `Text`
                        )->a( n = `text` v = `Amount`

                )->end(
            )->end(

            )->ele( `items`
                )->ele( `ColumnListItem`
                    )->ele( `cells`
                        )->tag( `ObjectIdentifier`
                            )->a( n = `text` v = `{EXPENSE}`
                        )->tag( n = `Currency` ns = `u`
                            )->a( n = `value`        v = `{TRANSACTION_AMOUNT/SIZE}`
                            )->a( n = `currency`     v = `{TRANSACTION_AMOUNT/CURRENCY}`
                            )->a( n = `maxPrecision` v = `2`
                            )->a( n = `useSymbol`    v = `false`
                        )->tag( `ObjectNumber`
                            )->a( n = `number` v = |\{ path: 'EXCHANGE_RATE', type: 'sap.ui.model.type.Float', formatOptions: \{ minFractionDigits: 5, maxFractionDigits: 5 \} \}|
                        )->tag( `ObjectNumber`
                            )->a( n = `number` v = |\{ path: 'AMOUNT', type: 'sap.ui.model.type.Float', formatOptions: \{ minFractionDigits: 2, maxFractionDigits: 2 \} \}|
                            )->a( n = `unit`   v = `EUR` ).

    client->view_display( view->stringify( ) ).

  ENDMETHOD.


  METHOD model_init.

    " inline mock data of the sample's controller (aData -> /modelData)
    t_modeldata = VALUE #(
        ( expense            = `Flight`
          transaction_amount = VALUE #( size = `560.67` currency = `EUR` )
          exchange_rate      = `1.00000`
          amount             = `560.67` )
        ( expense            = `Meals`
          transaction_amount = VALUE #( size = `180.50` currency = `USD` )
          exchange_rate      = `0.85654`
          amount             = `154.72` )
        ( expense            = `Hotel`
          transaction_amount = VALUE #( size = `675.00` currency = `USD` )
          exchange_rate      = `0.85654`
          amount             = `578.57` )
        ( expense            = `Taxi`
          transaction_amount = VALUE #( size = `15` currency = `USD` )
          exchange_rate      = `0.85654`
          amount             = `12.86` )
        ( expense            = `Daily allowance`
          transaction_amount = VALUE #( size = `80.00` currency = `BGN` )
          exchange_rate      = `0.51129`
          amount             = `40.90` )
        ( expense            = `Daily allowance Japan`
          transaction_amount = VALUE #( size = `7000` currency = `JPY` )
          exchange_rate      = `0.0067`
          amount             = `46.69` ) ).

  ENDMETHOD.

ENDCLASS.

More in sap.ui.unified

Search every abap2UI5 sample · the full list on one page

On this page