diff --git a/CLAUDE.md b/CLAUDE.md index ba23b237..0ce22ac3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,6 +32,7 @@ All serialized files (`.abap`, `.xml`, and any other abapGit-managed file types) - Follow the [SAP ABAP Style Guide](https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md). - Never use an init flag attribute (`check_initialized`, `mv_init`, `is_initialized`, etc.). Always use `client->check_on_init( )` instead. - Use backticks for all string literals, not single quotes. +- Prefer functional to procedural language constructs — use `var = VALUE #( ).` to reset a variable, never `CLEAR var.`. - Do not use Hungarian notation — no type prefixes on variable or attribute names (e.g. `product` not `lv_product`, `client` not `mo_client`). - Class names are always written in **lowercase** in both `DEFINITION` and `IMPLEMENTATION` — never uppercase. - Classes are **not** `FINAL` — do not add the `FINAL` keyword to class definitions. @@ -263,6 +264,8 @@ Key rules for `z2ui5_cl_util_xml`: Write everything directly in `main` — no method encapsulation needed. Count only the lines inside the `main` method, not the total class length. +**Do not extract `view_display` or any other helper method just because the app has a view.** A separate `view_display` method is only justified when the app is large enough to warrant the full canonical structure (≥ 50 lines in `main`). Extracting it in a simple app adds unnecessary indirection. + ### Larger apps — canonical template The following is the **maximum structure**. Only add methods that are actually needed. diff --git a/src/z2ui5_cl_demo_app_001.clas.abap b/src/z2ui5_cl_demo_app_001.clas.abap index c7aa59f9..4119c11c 100644 --- a/src/z2ui5_cl_demo_app_001.clas.abap +++ b/src/z2ui5_cl_demo_app_001.clas.abap @@ -1,84 +1,50 @@ -CLASS z2ui5_cl_demo_app_001 DEFINITION PUBLIC CREATE PUBLIC. +CLASS z2ui5_cl_demo_app_001 DEFINITION PUBLIC. PUBLIC SECTION. - INTERFACES z2ui5_if_app. DATA product TYPE string. DATA quantity TYPE string. - PROTECTED SECTION. - - DATA client TYPE REF TO z2ui5_if_client. - - METHODS z2ui5_set_data. - - METHODS display_view - IMPORTING - client TYPE REF TO z2ui5_if_client. - METHODS on_event - IMPORTING - client TYPE REF TO z2ui5_if_client. - PRIVATE SECTION. ENDCLASS. - CLASS z2ui5_cl_demo_app_001 IMPLEMENTATION. METHOD z2ui5_if_app~main. - me->client = client. - - IF client->check_on_init( ). - display_view( client ). - z2ui5_set_data( ). - ENDIF. - - on_event( client ). - - ENDMETHOD. - - - METHOD display_view. - - DATA(view) = z2ui5_cl_xml_view=>factory( ). - client->view_display( view->shell( - )->page( - title = 'abap2UI5 - First Example' - navbuttonpress = client->_event_nav_app_leave( ) - shownavbutton = client->check_app_prev_stack( ) - )->simple_form( title = 'Form Title' editable = abap_true - )->content( 'form' - )->title( 'Input' - )->label( 'quantity' - )->input( client->_bind_edit( quantity ) - )->label( `product` - )->input( value = product enabled = abap_false - )->button( - text = 'post' - press = client->_event( 'BUTTON_POST' ) - )->stringify( ) ). - - ENDMETHOD. - - METHOD on_event. - - IF client->check_on_event( 'BUTTON_POST' ). + product = `products`. + quantity = `500`. + + DATA(view) = z2ui5_cl_xml_view=>factory( ). + view->shell( + )->page( + title = `abap2UI5 - First Example` + navbuttonpress = client->_event_nav_app_leave( ) + shownavbutton = client->check_app_prev_stack( ) + )->simple_form( + title = `Form Title` + editable = abap_true + )->content( `form` + )->label( `quantity` + )->input( client->_bind_edit( quantity ) + )->label( `product` + )->input( + value = product + enabled = abap_false + )->button( + text = `post` + press = client->_event( `BUTTON_POST` ) ). + client->view_display( view->stringify( ) ). + + ELSEIF client->check_on_event( `BUTTON_POST` ). client->message_toast_display( |{ product } { quantity } - send to the server| ). ENDIF. ENDMETHOD. - - METHOD z2ui5_set_data. - - product = 'products'. - quantity = '500'. - - ENDMETHOD. ENDCLASS. diff --git a/src/z2ui5_cl_demo_app_002.clas.abap b/src/z2ui5_cl_demo_app_002.clas.abap index 12262955..8d29fdf8 100644 --- a/src/z2ui5_cl_demo_app_002.clas.abap +++ b/src/z2ui5_cl_demo_app_002.clas.abap @@ -1,9 +1,19 @@ CLASS z2ui5_cl_demo_app_002 DEFINITION PUBLIC. PUBLIC SECTION. - INTERFACES z2ui5_if_app. + TYPES: + BEGIN OF suggestion_item, + value TYPE string, + descr TYPE string, + END OF suggestion_item. + TYPES: + BEGIN OF combobox_item, + key TYPE string, + text TYPE string, + END OF combobox_item. + DATA: BEGIN OF screen, check_is_active TYPE abap_bool, @@ -19,232 +29,190 @@ CLASS z2ui5_cl_demo_app_002 DEFINITION PUBLIC. check_switch_02 TYPE abap_bool VALUE abap_false, END OF screen. - TYPES: - BEGIN OF s_suggestion_items, - value TYPE string, - descr TYPE string, - END OF s_suggestion_items. - DATA mt_suggestion TYPE STANDARD TABLE OF s_suggestion_items WITH EMPTY KEY. - - TYPES: - BEGIN OF s_combobox, - key TYPE string, - text TYPE string, - END OF s_combobox. - - TYPES ty_t_combo TYPE STANDARD TABLE OF s_combobox WITH EMPTY KEY. - - - DATA client TYPE REF TO z2ui5_if_client. - DATA mt_combo TYPE ty_t_combo. + DATA suggestions TYPE STANDARD TABLE OF suggestion_item WITH EMPTY KEY. + DATA combo TYPE STANDARD TABLE OF combobox_item WITH EMPTY KEY. PROTECTED SECTION. + DATA client TYPE REF TO z2ui5_if_client. - METHODS z2ui5_on_rendering. - METHODS z2ui5_on_event. - METHODS z2ui5_on_init. + METHODS on_init. + METHODS on_event. + METHODS view_display. PRIVATE SECTION. ENDCLASS. - CLASS z2ui5_cl_demo_app_002 IMPLEMENTATION. - METHOD z2ui5_if_app~main. me->client = client. - IF client->check_on_init( ). - z2ui5_on_init( ). - z2ui5_on_rendering( ). - RETURN. + on_init( ). + ELSEIF client->check_on_event( ). + on_event( ). ENDIF. - z2ui5_on_event( ). - ENDMETHOD. - METHOD z2ui5_on_event. + METHOD on_init. - CASE client->get( )-event. - - WHEN 'BUTTON_MCONFIRM'. - client->message_box_display( type = 'confirm' - text = 'Confirm MessageBox' ). - WHEN 'BUTTON_MALERT'. - client->message_box_display( type = 'alert' - text = 'Alert MessageBox' ). - WHEN 'BUTTON_MERROR'. - client->message_box_display( type = 'error' - text = 'Error MessageBox' ). - WHEN 'BUTTON_MINFO'. - client->message_box_display( type = 'information' - text = 'Information MessageBox' ). - WHEN 'BUTTON_MWARNING'. - client->message_box_display( type = 'warning' - text = 'Warning MessageBox' ). - WHEN 'BUTTON_MSUCCESS'. - client->message_box_display( type = 'success' - text = 'Success MessageBox' - icon = `sap-icon://accept` ). - WHEN 'BUTTON_SEND'. - client->message_box_display( 'success - values send to the server' ). - WHEN 'BUTTON_CLEAR'. - CLEAR screen. - client->message_toast_display( 'View initialized' ). - ENDCASE. + screen = VALUE #( + check_is_active = abap_true + colour = `BLUE` + combo_key = `GRAY` + segment_key = `GREEN` + date = `07.12.22` + date_time = `23.12.2022, 19:27:20` + time_start = `05:24:00` + time_end = `17:23:57` ). + + suggestions = VALUE #( + ( descr = `Green` value = `GREEN` ) + ( descr = `Blue` value = `BLUE` ) + ( descr = `Black` value = `BLACK` ) + ( descr = `Gray` value = `GRAY` ) + ( descr = `Blue2` value = `BLUE2` ) + ( descr = `Blue3` value = `BLUE3` ) ). + + combo = VALUE #( + ( key = `BLUE` text = `green` ) + ( key = `GREEN` text = `blue` ) + ( key = `BLACK` text = `red` ) + ( key = `GRAY` text = `gray` ) ). + + view_display( ). ENDMETHOD. - METHOD z2ui5_on_init. + METHOD on_event. - screen = VALUE #( - check_is_active = abap_true - colour = 'BLUE' - combo_key = 'GRAY' - segment_key = 'GREEN' - date = '07.12.22' - date_time = '23.12.2022, 19:27:20' - time_start = '05:24:00' - time_end = '17:23:57' ). - - mt_suggestion = VALUE #( - ( descr = 'Green' value = 'GREEN' ) - ( descr = 'Blue' value = 'BLUE' ) - ( descr = 'Black' value = 'BLACK' ) - ( descr = 'Gray' value = 'GRAY' ) - ( descr = 'Blue2' value = 'BLUE2' ) - ( descr = 'Blue3' value = 'BLUE3' ) ). + CASE client->get( )-event. + WHEN `BUTTON_SEND`. + client->message_box_display( `success - values send to the server` ). + WHEN `BUTTON_CLEAR`. + screen = VALUE #( ). + client->message_toast_display( `View initialized` ). + ENDCASE. ENDMETHOD. - METHOD z2ui5_on_rendering. + METHOD view_display. DATA(view) = z2ui5_cl_xml_view=>factory( ). DATA(page) = view->shell( - )->page( - showheader = xsdbool( abap_false = client->get( )-check_launchpad_active ) - title = 'abap2UI5 - Selection-Screen Example' + )->page( + title = `abap2UI5 - Selection-Screen Example` navbuttonpress = client->_event_nav_app_leave( ) shownavbutton = client->check_app_prev_stack( ) ). - DATA(grid) = page->grid( 'L6 M12 S12' - )->content( 'layout' ). - - grid->simple_form( title = 'Input' - editable = abap_true - )->content( 'form' - )->label( 'Input with suggestion items' - )->input( - id = `suggInput` - value = client->_bind_edit( screen-colour ) - placeholder = 'Fill in your favorite color' - suggestionitems = client->_bind( mt_suggestion ) - showsuggestion = abap_true )->get( - )->suggestion_items( )->get( - )->list_item( - text = '{VALUE}' - additionaltext = '{DESCR}' ). - - grid->simple_form( title = 'Time Inputs' - editable = abap_true - )->content( 'form' - )->label( 'Date' - )->date_picker( client->_bind_edit( screen-date ) - )->label( 'Date and Time' - )->date_time_picker( client->_bind_edit( screen-date_time ) - )->label( 'Time Begin/End' - )->time_picker( client->_bind_edit( screen-time_start ) - )->time_picker( client->_bind_edit( screen-time_end ) ). - - - DATA(form) = grid->get_parent( )->get_parent( )->grid( 'L12 M12 S12' - )->content( 'layout' - )->simple_form( title = 'Input with select options' - editable = abap_true - )->content( 'form' ). - - DATA(lv_test) = form->label( 'Checkbox' - )->checkbox( - selected = client->_bind_edit( screen-check_is_active ) - text = 'this is a checkbox' - enabled = abap_true ). - - mt_combo = VALUE ty_t_combo( - ( key = 'BLUE' text = 'green' ) - ( key = 'GREEN' text = 'blue' ) - ( key = 'BLACK' text = 'red' ) - ( key = 'GRAY' text = 'gray' ) ). - - lv_test->label( 'Combobox' - )->combobox( - selectedkey = client->_bind_edit( screen-combo_key ) - items = client->_bind( mt_combo ) - )->item( - key = '{KEY}' - text = '{TEXT}' - )->get_parent( )->get_parent( ). - - lv_test->label( 'Combobox2' - )->combobox( - selectedkey = client->_bind_edit( screen-combo_key2 ) - items = client->_bind( mt_combo ) - )->item( - key = '{KEY}' - text = '{TEXT}' - )->get_parent( )->get_parent( ). - - lv_test->label( 'Segmented Button' - )->segmented_button( client->_bind_edit( screen-segment_key ) + DATA(grid) = page->grid( `L6 M12 S12` + )->content( `layout` ). + + grid->simple_form( + title = `Input` + editable = abap_true + )->content( `form` + )->label( `Input with suggestion items` + )->input( + id = `suggInput` + value = client->_bind_edit( screen-colour ) + placeholder = `Fill in your favorite color` + suggestionitems = client->_bind( suggestions ) + showsuggestion = abap_true )->get( + )->suggestion_items( )->get( + )->list_item( + text = `{VALUE}` + additionaltext = `{DESCR}` ). + + grid->simple_form( + title = `Time Inputs` + editable = abap_true + )->content( `form` + )->label( `Date` + )->date_picker( client->_bind_edit( screen-date ) + )->label( `Date and Time` + )->date_time_picker( client->_bind_edit( screen-date_time ) + )->label( `Time Begin/End` + )->time_picker( client->_bind_edit( screen-time_start ) + )->time_picker( client->_bind_edit( screen-time_end ) ). + + DATA(content) = page->grid( `L12 M12 S12` + )->content( `layout` + )->simple_form( + title = `Input with select options` + editable = abap_true + )->content( `form` ). + + content->label( `Checkbox` )->checkbox( + selected = client->_bind_edit( screen-check_is_active ) + text = `this is a checkbox` + enabled = abap_true ). + + content->label( `Combobox` )->combobox( + selectedkey = client->_bind_edit( screen-combo_key ) + items = client->_bind( combo ) + )->item( + key = `{KEY}` + text = `{TEXT}` ). + + content->label( `Combobox2` )->combobox( + selectedkey = client->_bind_edit( screen-combo_key2 ) + items = client->_bind( combo ) + )->item( + key = `{KEY}` + text = `{TEXT}` ). + + content->label( `Segmented Button` )->segmented_button( + client->_bind_edit( screen-segment_key ) )->items( )->segmented_button_item( - key = 'BLUE' - icon = 'sap-icon://accept' - text = 'blue' + key = `BLUE` + icon = `sap-icon://accept` + text = `blue` )->segmented_button_item( - key = 'GREEN' - icon = 'sap-icon://add-favorite' - text = 'green' + key = `GREEN` + icon = `sap-icon://add-favorite` + text = `green` )->segmented_button_item( - key = 'BLACK' - icon = 'sap-icon://attachment' - text = 'black' - )->get_parent( )->get_parent( - )->label( 'Switch disabled' - )->switch( + key = `BLACK` + icon = `sap-icon://attachment` + text = `black` ). + + content->label( `Switch disabled` )->switch( enabled = abap_false - customtexton = 'A' - customtextoff = 'B' - )->label( 'Switch accept/reject' - )->switch( + customtexton = `A` + customtextoff = `B` ). + + content->label( `Switch accept/reject` )->switch( state = client->_bind_edit( screen-check_switch_01 ) - customtexton = 'on' - customtextoff = 'off' - type = 'AcceptReject' - )->label( 'Switch normal' - )->switch( + customtexton = `on` + customtextoff = `off` + type = `AcceptReject` ). + + content->label( `Switch normal` )->switch( state = client->_bind_edit( screen-check_switch_02 ) - customtexton = 'YES' - customtextoff = 'NO' ). + customtexton = `YES` + customtextoff = `NO` ). page->footer( )->overflow_toolbar( - )->toolbar_spacer( - )->button( - text = 'Clear' - press = client->_event( 'BUTTON_CLEAR' ) - type = 'Reject' - icon = 'sap-icon://delete' - )->button( - text = 'Send to Server' - press = client->_event( 'BUTTON_SEND' ) - type = 'Success' ). - - client->view_display( page->stringify( ) ). + )->toolbar_spacer( + )->button( + text = `Clear` + press = client->_event( `BUTTON_CLEAR` ) + type = `Reject` + icon = `sap-icon://delete` + )->button( + text = `Send to Server` + press = client->_event( `BUTTON_SEND` ) + type = `Success` ). + + client->view_display( view->stringify( ) ). ENDMETHOD. + ENDCLASS.