abap2UI5

SmartForm, editable toggle

needs the GWSAMPLE_BASIC OData service

Z2UI5_CL_SMPS_APP_476

Stack Smart Controls UI5 1.71 needs a system

needs a system. This sample is listed here because a sample somebody cannot find is worse than one they cannot run: SAPUI5 + an activated Gateway service. The ABAP is below; installed on a system that has what it needs, it runs there.

The facts

Repository
abap2UI5/samples-stack
Class
Z2UI5_CL_SMPS_APP_476
Source file
z2ui5_cl_smps_app_476.clas.abap
Category
Smart Controls
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
needs a system — it opens for reading instead
Runs on
Cloud + Standard ≥ 7.40 SP08

Keywords: smartform, smartfield, editable, toggle, edit, mode

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

The ABAP

z2ui5_cl_smps_app_476.clas.abap — 92 lines, on branch 02-smart-controls Read it on GitHub ↗
" @keywords smartform smartfield editable toggle edit mode
" @summary needs the GWSAMPLE_BASIC OData service
CLASS z2ui5_cl_smps_app_476 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    " Smart controls build their UI from OData V2 metadata, so this app carries no
    " ABAP data at all - it switches the default model to a service instead. The
    " SAP Gateway demo service GWSAMPLE_BASIC ships with every on-premise system
    " and only has to be activated once in /IWFND/MAINT_SERVICE. Its entity set is
    " ProductSet, which is why the tutorial's Products entity set and two of its
    " field names are mapped onto it ({ProductId} -> {ProductID}, {CategoryName}
    " -> {Category}).
    CONSTANTS c_odata_service TYPE string VALUE `/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/`.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smps_app_476 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    IF client->check_on_navigated( ).

      DATA(view) = 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:smartField` v = `sap.ui.comp.smartfield`
              )->a( n = `xmlns:smartForm`  v = `sap.ui.comp.smartform` ).

      DATA(page) = view->ele( `Shell`
          )->ele( `Page`
              )->a( n = `title`          v = `abap2UI5 - Smart Controls - SmartForm`
              )->a( n = `showNavButton`  b = client->check_app_prev_stack( )
              )->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).

      " editTogglable renders the display/edit toggle in the form header. The
      " element binding replaces the controller's bindElement( ) - an OData ENTITY
      " path into the service, so there is no client->_bind( ) variable behind it;
      " every SmartField value and the form title {Name} are relative to it.
      DATA(form) = page->ele( n = `SmartForm` ns = `smartForm`
          )->a( n = `id`            v = `smartForm`
          )->a( n = `editTogglable` v = `true`
          )->a( n = `title`         v = `{Name}`
          )->a( n = `flexEnabled`   v = `false`
          )->a( n = `binding`       v = `{/ProductSet('AR-FB-1000')}` ).

      DATA(group) = form->ele( n = `Group` ns = `smartForm`
          )->a( n = `label` v = `Product` ).

      group->ele( n = `GroupElement` ns = `smartForm`
          )->ele( n = `SmartField` ns = `smartField`
              )->a( n = `value` v = `{ProductID}` ).

      group->ele( n = `GroupElement` ns = `smartForm`
          )->ele( n = `SmartField` ns = `smartField`
              )->a( n = `value` v = `{Name}` ).

      " elementForLabel picks the second field of the group element as the one the
      " group label belongs to (0-based, so Description)
      group->ele( n = `GroupElement` ns = `smartForm`
          )->a( n = `elementForLabel` v = `1`
          )->ele( n = `SmartField` ns = `smartField`
              )->a( n = `value` v = `{Category}`
          )->end(
          )->ele( n = `SmartField` ns = `smartField`
              )->a( n = `value` v = `{Description}` ).

      group->ele( n = `GroupElement` ns = `smartForm`
          )->ele( n = `SmartField` ns = `smartField`
              )->a( n = `value` v = `{Price}` ).

      form->ele( n = `Group` ns = `smartForm`
          )->a( n = `label` v = `Supplier`
          )->ele( n = `GroupElement` ns = `smartForm`
              )->ele( n = `SmartField` ns = `smartField`
                  )->a( n = `value` v = `{SupplierName}` ).

      client->view_display( val = view->stringify( ) switch_default_model_path = c_odata_service ).

    ENDIF.

  ENDMETHOD.

ENDCLASS.

More in Smart Controls

Search every abap2UI5 sample · the full list on one page

On this page