Samples / Controls / sap.ui.unified

Currency in Table

Display Currencies in Table

Class
z2ui5_cl_smpc_app_171
Repository
abap2UI5/samples-controls
Ports
sap.ui.unified.sample.CurrencyInTable
UI5 libraries
sap.m, sap.ui.core, sap.ui.unified
Lowest UI5 release
1.71
In the browser
Runs in the playground
Controls it builds
sap.m.Column, sap.m.ColumnListItem, sap.m.ObjectIdentifier, sap.m.ObjectNumber, sap.m.Table, sap.m.Text, sap.ui.core.mvc.View, sap.ui.unified.Currency

The class

" @keywords currency sap.ui.unified amounts table column text columnlistitem objectidentifier objectnumber
" @summary Display Currencies in Table
" @origin sap.ui.unified.sample.CurrencyInTable - https://sdk.openui5.org/entity/sap.ui.unified.Currency/sample/sap.ui.unified.sample.CurrencyInTable (status: checked - verified in a running system)
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,
        transactionamount 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 = `{TRANSACTIONAMOUNT/SIZE}`
                            )->a( n = `currency`     v = `{TRANSACTIONAMOUNT/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`
          transactionamount = VALUE #( size = `560.67` currency = `EUR` )
          exchange_rate      = `1.00000`
          amount             = `560.67` )
        ( expense            = `Meals`
          transactionamount = VALUE #( size = `180.50` currency = `USD` )
          exchange_rate      = `0.85654`
          amount             = `154.72` )
        ( expense            = `Hotel`
          transactionamount = VALUE #( size = `675.00` currency = `USD` )
          exchange_rate      = `0.85654`
          amount             = `578.57` )
        ( expense            = `Taxi`
          transactionamount = VALUE #( size = `15` currency = `USD` )
          exchange_rate      = `0.85654`
          amount             = `12.86` )
        ( expense            = `Daily allowance`
          transactionamount = VALUE #( size = `80.00` currency = `BGN` )
          exchange_rate      = `0.51129`
          amount             = `40.90` )
        ( expense            = `Daily allowance Japan`
          transactionamount = VALUE #( size = `7000` currency = `JPY` )
          exchange_rate      = `0.0067`
          amount             = `46.69` ) ).

  ENDMETHOD.

ENDCLASS.