Using ALV to display/edit fields of a structure

The idea

I got the idea for this when I was working with the web dynpro view editor. I noticed there was something ALV like which was used instead of a classical dynpro to enter values on several fields:

 

 

I was wondering if I could use the ALV grid control for simple input areas in my own applications.

 

The implementation

 

I created a subclass to CL_GUI_ALV_GRID to achieve this. It uses a fixed output table structure containing a column for the label, one for the value (can be editable), and one for a field description (if we input on a field with domain values).

 

At the end of this blog, you will find the coding for the sample program.

To get the program running, create a GUI status 0001 with function code END on the SHIFT+F3 button. Create also a GUI title 0001 saying “Test program” or something similar.

 

Now, if you run the program, you should see something like this:

 

 

P_RDONLY starts the input in read only mode, otherwise the edit mode is active

P_SIMPLE: in read only mode, P_SIMPLE activates a simpler display with no key coloring.

 

Edit mode screen:

 

 

The demo class LCL_APP calls the input control with the structur ADDR1_VAL. As you see, you get a complete input for this structure using the call:

 

        create object go_input
           exporting
             iv_structure_name = ‘ADDR1_DATA’
             io_parent         = go_container
             iv_max_outlen     = 30
             iv_readonly       = p_rdonly
             iv_simplex        = p_simple
             iv_max_outlen_d   = 30

 

In the demo program, I used the table parameter it_fieldattr to set the first two fields to read only.

 

Reusing the code

 

If you want to reuse the coding, you should extract the following classes from the provided source. Remember to do a find/replace for the class names transforming each “LCL_ICTRL” into “ZCL_ICTRL” and “LIF_ICTRL” into “ZCL_ICTRL” in the codings to get the classes working.

 

  • lif_ictrl_input_check: This interface is useful if you want to code own input checks in your application. Implement it in your application class and pass the object reference to the main class. The interface method input_validate will be called for each input in the table. 
  • lif_ictrl_types: This interface is needed for the necessary structure and table types.
  • lcl_ictrl_alv : The main working class
  • lcx_ictrl_fatal: Exception class used in the coding

 

Comments and hints

 

Since the coding “lives” in a standard super class, I decided to use a prefix ZICTRL_ for all objects I created in order to not interfer with further inserted attributes and methods in future releases of CL_GUI_ALV_GRID.

 

The work data structure is accessed by the caller via reference. You can set the reference using method ZICTRL_SET_DATA_BY_REF. In the demo application, a structure GS_DATA is kept as an instance attribute and the ICTRL_ALV class has the reference to it. As soon as GS_DATA is changed, just call ZICTRL_REFRESH to display the new data.

 

Use case example

 

I use this class frequently. It is very good in saving space in complex dialogue applications. Here is a screenshot of a productive GUI application:

 

 

If you try to put this information on a classical dynpro, you will occupy much more space on the screen.

 

Another advantage is that this control fits much better in an OO application than classical dynpros.

 

Disadvantages

 

Unfortunately there is one problem, which I did not resolve yet: Input fields in ALV grids do not have a frontend history. In some cases, when this is very important for the users, I had to refuse using it.

 

Conclusion

 

Feel free to post your comments. Bug annotations are always welcome!

 

All the best!

Jörg

Sample program

Report source

*&---------------------------------------------------------------------* *& Report ZP_ICTRL_DEMO *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zp_ictrl_demo. interface lif_ictrl_input_check. methods input_validate importing iv_fieldname type dfies-lfieldname iv_value type any raising cx_static_check . endinterface. class lcx_ictrl definition inheriting from cx_static_check. public section. interfaces if_t100_message. data mv_handle type balloghndl . methods constructor importing textid like textid optional previous like previous optional t100key type scx_t100key optional mv_message_v1 type symsgv mv_message_v2 type symsgv mv_message_v3 type symsgv mv_message_v4 type symsgv. endclass. interface lif_ictrl_main. constants: cv_long_descr type char1 value 'L', cv_medium_descr type char1 value space, cv_short_descr type char1 value 'S'. data: mv_readonly type abap_bool, mr_data type ref to data, mv_title type lvc_title, mv_width_value type i, mv_width_descr type i, mo_input_check type ref to lif_ictrl_input_check, mv_descr_len type char1. events: user_command exporting value(ev_ucomm) type ui_func, enter_pressed , data_has_changed , link_clicked exporting value(ev_fieldname) type fieldname value(ev_value) type any, double_clicked exporting value(ev_fieldname) type fieldname value(ev_value) type any. methods: set_data changing cs_data type any raising lcx_ictrl, display importing iv_optimized type abap_bool optional raising lcx_ictrl, set_readonly importing iv_in type abap_bool default abap_true raising lcx_ictrl, hide_field importing iv_in type lvc_fname, show_field importing iv_in type lvc_fname, refresh raising lcx_ictrl. endinterface. class lcl_ictrl_alv definition inheriting from cl_gui_alv_grid final create public . public section. interfaces lif_ictrl_main. *"* public components of class lcl_ictrl_alv *"* do not include other source files here!!! methods constructor importing io_parent type ref to cl_gui_container iv_appl_events type abap_bool optional raising lcx_ictrl . private section. types: begin of gty_s_output, fieldlabel type scrtext_l, fieldvalue type text128, fielddescr type text128, ref_field type lvc_rfname, ref_table type lvc_rtname, style type lvc_style, maxlen type int4, t_styles type lvc_t_styl, t_colors type lvc_t_scol, end of gty_s_output, gty_t_output type standard table of gty_s_output with default key, begin of gty_s_fieldattr, fieldname type fieldname, hotspot type lvc_hotspt, readonly type crmt_bsp_readonly, description_field type fieldname, no_display type abap_bool, no_label type abap_bool, end of gty_s_fieldattr, gty_t_fieldattr type standard table of gty_s_fieldattr with default key. aliases: cv_long_descr for lif_ictrl_main~cv_long_descr, cv_medium_descr for lif_ictrl_main~cv_medium_descr, cv_short_descr for lif_ictrl_main~cv_short_descr, mv_width_value for lif_ictrl_main~mv_width_value, mv_width_descr for lif_ictrl_main~mv_width_descr, mv_readonly for lif_ictrl_main~mv_readonly , mr_data for lif_ictrl_main~mr_data , mv_title for lif_ictrl_main~mv_title , mo_input_check for lif_ictrl_main~mo_input_check, mv_descr_len for lif_ictrl_main~mv_descr_len. data: zictrl_mv_optimized type abap_bool, zictrl_mo_input_check type ref to lif_ictrl_input_check, zictrl_mv_error type abap_bool, zictrl_mt_fieldattr type gty_t_fieldattr, zictrl_mt_fieldcat type lvc_t_fcat, zictrl_mt_fields type dd03ttyp, zictrl_mv_structure_name type ddobjname, zictrl_mv_title type lvc_title, zictrl_mt_inputs type gty_t_output. methods: zictrl_set_fieldattr importing iv_fieldname type c iv_attrib type c iv_value type c, zictrl_fieldcat_build, zictrl_error raising lcx_ictrl, zictrl_put_log_dch importing io_data_changed type ref to cl_alv_changed_data_protocol is_good type lvc_s_modi , zictrl_hotspot_clicked for event hotspot_click of lcl_ictrl_alv importing e_row_id e_column_id es_row_no , zictrl_f4 for event onf4 of lcl_ictrl_alv importing e_fieldname e_fieldvalue es_row_no er_event_data et_bad_cells e_display , zictrl_double_click for event double_click of lcl_ictrl_alv importing e_row e_column es_row_no , zictrl_description_fill_forkey importing is_field type dd03p iv_fn_d type fieldname is_screen type any changing cs_input type gty_s_output , zictrl_description_fill importing is_field type dd03p iv_value type any changing cs_input type gty_s_output raising lcx_ictrl, zictrl_after_refresh for event after_refresh of lcl_ictrl_alv , zictrl_convert_input importing is_good type lvc_s_modi io_data_changed type ref to cl_alv_changed_data_protocol iv_currency type waers is_field type dd03p exporting ev_value type any ev_error type flag , zictrl_convert_output importing iv_value type any iv_currency type waers iv_unit type meins returning value(rv_res) type text128 , zictrl_data_changed for event data_changed of lcl_ictrl_alv importing er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm , zictrl_screen_to_input importing iv_refresh type abap_bool default abap_true raising lcx_ictrl, zictrl_data_changed_late for event data_changed_finished of cl_gui_alv_grid importing e_modified et_good_cells , zictrl_get_field_ref importing is_field type dd03p io_data_changed type ref to cl_alv_changed_data_protocol optional is_screen type any exporting ev_curr_ref type waers ev_unit_ref type meins , zictrl_input_error importing io_data_changed type ref to cl_alv_changed_data_protocol is_good type lvc_s_modi , zictrl_set_style , zictrl_build_toolbar_exclude exporting et_tab type ui_functions , zictrl_input_table_create raising lcx_ictrl . endclass. class lcl_app definition. public section. methods main. methods controls_init. private section. methods: fill_data_from_outside raising lcx_ictrl, toggle_change_edit raising lcx_ictrl, user_command for event user_command of lif_ictrl_main importing ev_ucomm, hotspot for event link_clicked of lif_ictrl_main importing ev_fieldname ev_value. data: mo_alv type ref to lcl_ictrl_alv, mo_container type ref to cl_gui_custom_container, mo_input type ref to lif_ictrl_main, ms_data type addr1_val, mv_readonly type abap_bool. endclass. data: go_app type ref to lcl_app, gv_ucomm type syucomm. parameters: p_rdonly as checkbox. start-of-selection. create object go_app. go_app->main( ). class lcx_ictrl implementation. method constructor. call method super->constructor exporting textid = textid previous = previous. if_t100_message~t100key = t100key. endmethod. endclass. class lcl_app implementation. method hotspot. field-symbols 

Dynpro source

**************************************************************** * THIS FILE IS GENERATED BY THE SCREEN PAINTER. * * NEVER CHANGE IT MANUALLY, PLEASE ! * **************************************************************** %_DYNPRO ZP_ICTRL_DEMO 0001 740 40 %_HEADER ZP_ICTRL_DEMO 0001 0001 27120192 37 0 0 27120 0G E 20160806110017 %_DESCRIPTION Träger für ALV-Eingabemaske %_FIELDS CTRL_ALL 120 00 00 00 30 00 1 2 0 0 0 27 U 1 1 101 GV_UCOMM CHAR 20 80 10 00 00 00 255 1 O 0 0 0 0 0 0 ____________________ 00 %_FLOWLOGIC PROCESS BEFORE OUTPUT. MODULE STATUS_0001. * PROCESS AFTER INPUT. MODULE USER_COMMAND_0001. %_PARAMS 

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !
Comments (0)
Add Comment