<!-- https://abap2ui5.github.io/docs/tutorials/walkthrough/step-4 -->

# Step 4: Data Binding

So far the app only talks. Now the user answers: an input field replaces the
text, and whatever is typed into it arrives in your class — without a single
line of transfer code:

```abap
CLASS zcl_app_walkthrough DEFINITION PUBLIC.
  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.
    DATA recipient TYPE string.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_app_walkthrough IMPLEMENTATION.
  METHOD z2ui5_if_app~main.

    IF client->check_on_navigated( ).

      recipient = `World`.

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

              )->ele( `Shell`
                  )->ele( `Page`
                      )->a( n = `title` v = `Walkthrough - Step 4`

                      )->tag( `Input`
                          )->a( n = `value` v = client->_bind( recipient )
                      )->tag( `Button`
                          )->a( n = `text`  v = `Say Hello`
                          )->a( n = `press` v = client->_event( `SAY_HELLO` ) ).

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

    ELSEIF client->check_on_event( `SAY_HELLO` ).

      client->message_toast_display( |Hello { recipient }!| ).

    ENDIF.

  ENDMETHOD.
ENDCLASS.
```

## How the Value Travels

- **`DATA recipient TYPE string`** — a public attribute is the model. After
  every roundtrip the framework serializes the whole app instance into a draft
  on the server and restores it before the next one, so your class keeps its
  state without any session handling. Attributes you `_bind( )` must be in the
  `PUBLIC SECTION` — the framework reaches them dynamically, and a private or
  protected one fails the roundtrip with `BINDING_ERROR`. (Everything else may
  stay protected; it is serialized either way. Full rules on the
  [Binding](/cookbook/model/binding) page.)
- **`client->_bind( recipient )`** connects the attribute to the `value`
  property of the input. When the button fires, the browser sends the current
  screen state along with the event — by the time your `ELSEIF` branch runs,
  `recipient` already holds what the user typed.
- **Type it, press the button** — the toast greets whatever name is in the
  field. Both directions, and you wrote no transfer code.

Next, the same binding moves a whole internal table into a list.

<!-- samples:start (generated by scripts/link-samples.mjs — do not edit) -->

## Working Samples

Complete apps from the [sample catalog](https://abap2ui5.github.io/playground/samples/)
that use what this page describes. Each is a single class in [abap2UI5/samples](https://github.com/abap2UI5/samples)
unless its row names another of the three sample repositories — pull that repository with
[abapGit](https://abapgit.org) and start the class with `?app_start=<class>`.

| Sample | Class |
|---|---|
| Basics II — Data Binding: Input and Button | [`Z2UI5_CL_SMP_APP_494`](https://github.com/abap2UI5/samples/blob/main/src/01/z2ui5_cl_smp_app_494.clas.abap) |

<!-- samples:end -->
