2011-12-14

WD Screen Variants - Dynamic Dates

overview

<< previous | next >>

The concept of a selection screen variant is something that most SAP users have come to expect, yet this feature is unavailable in standard Web Dynpro. Below is the next in a series of posts detailing how to bring this necessary feature back to Web Dynpro. Start here to see the full requirements.

Some might say that the most beneficial feature of the selection screen variant in classic ABAP programs is the dynamic date functionality.

SNAGHTML3a94be1

This has been emulated in the Web Dynpro implementation.   For this we need to go back to the V_SAVE_VARIANT view.  It starts with an enhancement made to the INIT_ALV routine.  The field VTYPE is being replaced with a [Date] button.

   1: METHOD init_alv .                                           " PLM8034
   2:  
   3:   DATA: lo_cmp_usage                  TYPE REF TO if_wd_component_usage.
   4:   DATA: lr_salv_wd_table              TYPE REF TO iwci_salv_wd_table.
   5:   DATA: lr_column_settings            TYPE REF TO if_salv_wd_column_settings,
   6:         lr_table_settings             TYPE REF TO if_salv_wd_table_settings,
   7:         lr_std_fxns                   TYPE REF TO if_salv_wd_std_functions,
   8:         lr_column                     TYPE REF TO cl_salv_wd_column,
   9:         lt_columns                    TYPE salv_wd_t_column_ref,
  10:         ls_column                     TYPE salv_wd_s_column_ref.
  11:   DATA: lr_col_header                 TYPE REF TO cl_salv_wd_column_header.
  12:   DATA: l_text                        TYPE string.
  13:  
  14:   DATA: lr_input_field                TYPE REF TO cl_salv_wd_uie_input_field.
  15:   DATA: lr_ddlb_field                 TYPE REF TO cl_salv_wd_uie_dropdown_by_key.
  16:   DATA: lr_button_field               TYPE REF TO cl_salv_wd_uie_button.
  17:  
  18: *create an instance of ALV component
  19:   lo_cmp_usage = wd_this->wd_cpuse_alv2( ).
  20: * if not initialized, then initialize
  21:   IF lo_cmp_usage->has_active_component( ) IS INITIAL.
  22:     lo_cmp_usage->create_component( ).
  23:   ENDIF.
  24:  
  25: * get ALV component
  26:   lr_salv_wd_table = wd_this->wd_cpifc_alv2( ).
  27:  
  28:   lr_table_settings ?= lr_salv_wd_table->get_model( ).
  29:   lr_table_settings->set_read_only( abap_false ).
  30:   lr_table_settings->set_cell_action_event_enabled( abap_true ).
  31:  
  32:   lr_std_fxns ?= lr_salv_wd_table->get_model( ).
  33:   lr_std_fxns->set_pdf_allowed( abap_false ).
  34:   lr_std_fxns->set_edit_insert_row_allowed( abap_false ).
  35:   lr_std_fxns->set_edit_delete_row_allowed( abap_false ).
  36:   lr_std_fxns->set_edit_check_available( abap_false ).
  37:   lr_std_fxns->set_edit_append_row_allowed( abap_false ).
  38:   lr_std_fxns->set_display_settings_allowed( abap_false ).
  39:   lr_std_fxns->set_dialog_settings_allowed( abap_false ).
  40:   lr_std_fxns->set_filter_filterline_allowed( abap_false ).
  41:   lr_std_fxns->set_view_list_allowed( abap_false ).
  42:  
  43:   lr_column_settings ?= lr_salv_wd_table->get_model( ).
  44:   lt_columns = lr_column_settings->get_columns( ).
  45:   LOOP AT lt_columns INTO ls_column.
  46:     lr_col_header = ls_column-r_column->get_header( ).
  47:  
  48:     CASE ls_column-id.
  49:       WHEN 'FIELDTEXT' OR 'VTEXT'.
  50:  
  51:       WHEN 'VTYPE'.
  52:         "CREATE OBJECT lr_input_field
  53:         "  EXPORTING
  54:         "    value_fieldname = ls_column-id.
  55:         "lr_input_field->set_read_only_fieldname( 'RONLY_DYNDATE' ).
  56:         CREATE OBJECT lr_button_field.
  57:         lr_button_field->set_enabled_fieldname( 'EDIT_DYNDATE' ).
  58:         lr_button_field->set_text( 'Date' ).
  59:         ls_column-r_column->set_cell_editor( lr_button_field ).
  60:  
  61:       WHEN OTHERS.
  62:         ls_column-r_column->set_visible( if_wdl_core=>visibility_none ).
  63:     ENDCASE.
  64:  
  65:   ENDLOOP.
  66:  
  67: ENDMETHOD.

Next the ALV_ON_CELL_ACTION is used to catch the button press.


SNAGHTML3b4c007


In the case of the ‘VTYPE’ column, a new window W_ASK_PARAMETERS is presented to the user.  The data for the dynamic date selection is retrieved from the field’s static attributes and placed into the node FIELD_PARAMS for temporary use by the V_ASK_PARAMETERS view.



   1: METHOD prompt_for_params .                                  " PLM8034
   2:  
   3:   DATA: lr_nd_fields                  TYPE REF TO if_wd_context_node.
   4:   lr_nd_fields = wd_context->get_child_node( 'VARIANT_FIELDS' ).
   5:  
   6:   DATA: lt_elements                   TYPE wdr_context_element_set,
   7:         lr_element                    TYPE REF TO if_wd_context_element.
   8:   DATA: ls_value                      TYPE zes_vuvvalues_alv.
   9:  
  10:   lt_elements = lr_nd_fields->get_elements( ).
  11:   READ TABLE lt_elements INTO lr_element INDEX wd_this->m_cell_action->index.
  12:  
  13:   lr_element->get_static_attributes( IMPORTING static_attributes = ls_value ).
  14:  
  15:   DATA: lr_nd_in                      TYPE REF TO if_wd_context_node.
  16:   lr_nd_in = wd_context->get_child_node( 'IN' ).
  17:  
  18:   lr_nd_in->set_attribute( EXPORTING name  = 'VNAME'
  19:                                      value = ls_value-vname ).
  20:  
  21:   DATA: lr_nd_params                  TYPE REF TO if_wd_context_node.
  22:   lr_nd_params = wd_context->get_child_node( 'FIELD_PARAMS' ).
  23:  
  24:   lr_nd_params->set_attribute( EXPORTING name  = 'SIGN'
  25:                                          value = ls_value-sign_dy ).
  26:   lr_nd_params->set_attribute( EXPORTING name  = 'OPTION'
  27:                                          value = ls_value-option_dy ).
  28:   lr_nd_params->set_attribute( EXPORTING name  = 'LOW'
  29:                                          value = ls_value-low_dy ).
  30:   lr_nd_params->set_attribute( EXPORTING name  = 'HIGH'
  31:                                          value = ls_value-high_dy ).
  32:  
  33:   DATA: lo_window_manager             TYPE REF TO if_wd_window_manager,
  34:         lo_api_component              TYPE REF TO if_wd_component,
  35:         lo_window                     TYPE REF TO if_wd_window,
  36:         lo_api                        TYPE REF TO if_wd_view_controller.
  37:  
  38:   lo_api = wd_this->wd_get_api( ).
  39:   lo_api_component = wd_comp_controller->wd_get_api( ).
  40:   lo_window_manager = lo_api_component->get_window_manager( ).
  41:  
  42:   lo_window = lo_window_manager->create_window(
  43:                       window_name               = 'W_ASK_PARAMETERS'
  44:                       title                     = 'Set Dynamic Date'
  45:                       button_kind               = if_wd_window=>co_buttons_okcancel
  46:                       close_button              = abap_true ).
  47:   lo_window->subscribe_to_button_event(
  48:                       button            = if_wd_window=>co_button_ok
  49:                       action_name       = 'ASK_OK'
  50:                       action_view       = lo_api
  51:                       is_default_button = abap_true ).
  52:  
  53:   lo_window->open( ).
  54:  
  55: ENDMETHOD.

This view contains the same fields available in the classic dynpro version of dynamic dates.  When the view loads, the WDDOINIT routine calls INIT_DYNAMIC_CONTEXT to load the values for the Dynamic date type drop-down list from wd_assist->mt_varivar table.


SNAGHTML3cb28e7


The drop-down list is attached to an action DYN_DATE_ON_SELECT.  This action calls the REFRESH_PARAM_FIELDS to identify which fields to enable based on the selected dynamic date type.



   1: METHOD refresh_param_fields .                               " PLM8034
   2:  
   3:   DATA: lr_nd_in                      TYPE REF TO if_wd_context_node.
   4:   lr_nd_in = wd_context->get_child_node( 'IN' ).
   5:  
   6:   DATA: l_vname                       TYPE rs38l_fnam.
   7:   lr_nd_in->get_attribute( EXPORTING name  = 'VNAME'
   8:                            IMPORTING value = l_vname ).
   9:  
  10:   DATA: l_flag1                       TYPE xfeld,
  11:         l_flag2                       TYPE xfeld,
  12:         l_flag_jahr                   TYPE xfeld,
  13:         l_flag_cal                    TYPE xfeld,
  14:         l_flag_restrict               TYPE xfeld.
  15:  
  16:   IF      l_vname =  'RS_VARI_V_TODAY_X'.
  17:     l_flag_jahr = l_flag2 = space.
  18:     l_flag1 = 'X'.
  19:   ELSEIF   l_vname =  'RS_VARI_V_TODAY_XWD'.
  20:     l_flag_jahr = l_flag2 = space.
  21:     l_flag1 = l_flag_cal = 'X'.
  22:   ELSEIF  l_vname =  'RS_VARI_V_DAYS_UP_TO_NOW'.
  23:     l_flag_jahr = space.
  24:     l_flag1 = l_flag2 = 'X'.
  25:   ELSEIF  l_vname =  'RS_VARI_V_WDAYS_UP_TO_NOW'.
  26:     l_flag_jahr = space.
  27:     l_flag1 = l_flag2 = l_flag_cal = 'X'.
  28:   ELSEIF  l_vname CP 'RS_VARI_V_QUARTER*'.
  29:     l_flag_jahr = 'X'.
  30:     l_flag1 = l_flag2 = space.
  31:   ELSEIF l_vname = 'RS_VARI_V_MONTH_XXX_YYY'.
  32:     l_flag_jahr = space.
  33:     l_flag1 = l_flag2 = 'X'.
  34:   ELSEIF l_vname = 'RS_VARI_V_XWD_ACTUAL_MONTH'.
  35:     l_flag_jahr = l_flag2 = space.
  36:     l_flag1 = l_flag_cal = 'X'.
  37:   ELSEIF  l_vname = space.
  38:     l_flag1 = l_flag_jahr = l_flag2 = space.
  39:     "l_flag1 = 'X'.
  40:   ENDIF.
  41:  
  42:   DATA: ls_varivar                    TYPE rsvarivar.
  43:   READ TABLE wd_assist->mt_varivar INTO ls_varivar WITH KEY runt_fb = l_vname.
  44:   IF ls_varivar-vtype = 'F'.
  45:     l_flag_restrict = abap_true.
  46:   ENDIF.
  47:  
  48:   lr_nd_in->set_attribute( EXPORTING name  = 'USE_PARAM1'
  49:                                      value = l_flag1 ).
  50:  
  51:   lr_nd_in->set_attribute( EXPORTING name  = 'USE_PARAM2'
  52:                                      value = l_flag2 ).
  53:  
  54:   lr_nd_in->set_attribute( EXPORTING name  = 'USE_RESTRICT'
  55:                                      value = l_flag_restrict ).
  56:  
  57:   DATA: lr_nd_param                   TYPE REF TO if_wd_context_node.
  58:   lr_nd_param = wd_context->get_child_node( 'FIELD_PARAMS' ).
  59:  
  60:   IF l_flag1 IS INITIAL.
  61:     lr_nd_param->set_attribute( name  = 'LOW'
  62:                                 value = space ).
  63:   ENDIF.
  64:  
  65:   IF l_flag2 IS INITIAL.
  66:     lr_nd_param->set_attribute( name  = 'HIGH'
  67:                                 value = space ).
  68:   ENDIF.
  69:  
  70:   IF l_flag_restrict IS INITIAL.
  71:     lr_nd_param->set_attribute( name  = 'SIGN'
  72:                                 value = space ).
  73:     lr_nd_param->set_attribute( name  = 'OPTION'
  74:                                 value = space ).
  75:   ENDIF.
  76:  
  77: ENDMETHOD.

 

When the [OK] button is pressed, the ASK_OK action is used to generate a human-readable text string that represents the dynamic date selection (call method REPLACE_VARIVAR_TEXT).  Then values are stored back into the field’s static attributes.



   1: METHOD replace_varivar_text .                               " PLM8034
   2:  
   3:   CLEAR: cs_value-vtext.
   4:   CHECK cs_value-vname IS NOT INITIAL.
   5:  
   6:   DATA: lt_intrange                   TYPE TABLE OF rsintrange,
   7:         ls_intrange                   TYPE rsintrange.
   8:   MOVE: cs_value-sign_dy     TO ls_intrange-sign,
   9:         cs_value-option_dy   TO ls_intrange-option,
  10:         cs_value-low_dy      TO ls_intrange-low,
  11:         cs_value-high_dy     TO ls_intrange-high.
  12:   APPEND ls_intrange TO lt_intrange.
  13:  
  14:   DATA: ls_varivar                    TYPE rsvarivar.
  15:   READ TABLE wd_assist->mt_varivar INTO ls_varivar
  16:         WITH KEY runt_fb = cs_value-vname.
  17:   CALL FUNCTION 'RS_VARI_V_REPLACE_VARIABLES'
  18:     EXPORTING
  19:       p_varivar        = ls_varivar
  20:     IMPORTING
  21:       p_vtext          = cs_value-vtext
  22:     TABLES
  23:       p_intrange       = lt_intrange
  24:     EXCEPTIONS
  25: *     NO_ACTION        = 1
  26:       OTHERS           = 2.
  27:  
  28:   DATA: l_sign                        TYPE string,
  29:         l_option                      TYPE string.
  30:  
  31:   IF ls_varivar-vtype = 'F'.
  32:     CASE ls_intrange-option.
  33:       WHEN 'EQ' OR space.       l_option = '='.
  34:       WHEN 'GT'.                l_option = '>'.
  35:       WHEN 'GE'.                l_option = '>='.
  36:       WHEN 'LT'.                l_option = '<'.
  37:       WHEN 'LE'.                l_option = '<='.
  38:       WHEN 'NE'.                l_option = 'not ='.
  39:       WHEN OTHERS.              l_option = 'Error - choose another option'.
  40:     ENDCASE.
  41:  
  42:     CASE ls_intrange-sign.
  43:       WHEN 'I' OR space.
  44:       WHEN 'E'.                 l_sign = 'Not'.
  45:     ENDCASE.
  46:  
  47:     CONCATENATE l_sign
  48:                 l_option
  49:                 cs_value-vtext
  50:            INTO cs_value-vtext SEPARATED BY space.
  51:     CONDENSE cs_value-vtext.
  52:   ENDIF.
  53:  
  54: ENDMETHOD.

The static attributes travel along with the rest of the save operation described in the previous post.  Then in the component controller’s GET_FIELDS routine, each field is reviewed as the result table is generated.  Another routine in the component controller – GET_FIELD_PARAMS – takes the task of retrieving the static attributes for each field and assigning the dynamic date values to the fields in the ZES_VUVVALUES structure.



   1: METHOD get_field_params .                                   " PLM8034
   2:  
   3:   DATA: lr_nd_fields                  TYPE REF TO if_wd_context_node.
   4:   lr_nd_fields = wd_context->get_child_node( 'VARIANT_FIELDS' ).
   5:  
   6:   DATA: lt_elements                   TYPE wdr_context_element_set,
   7:         lr_element                    TYPE REF TO if_wd_context_element.
   8:   DATA: ls_value                      TYPE zes_vuvvalues.
   9:  
  10:   lt_elements = lr_nd_fields->get_elements( ).
  11:   LOOP AT lt_elements INTO lr_element.
  12:     lr_element->get_static_attributes( IMPORTING static_attributes = ls_value ).
  13:     IF ls_value-paramid = ct_field-paramid.
  14:       " Copy over specific field-level values from 'SAVE_VARIANT' window.
  15:       ct_field-vtype      = ls_value-vtype.
  16:       ct_field-sign_dy    = ls_value-sign_dy.
  17:       ct_field-option_dy  = ls_value-option_dy.
  18:       ct_field-low_dy     = ls_value-low_dy.
  19:       ct_field-high_dy    = ls_value-high_dy.
  20:       ct_field-vname      = ls_value-vname.
  21:       RETURN.
  22:     ENDIF.
  23:   ENDLOOP.
  24:  
  25: ENDMETHOD.

This allows the user to specify what dynamic date function to use and and additional offset parameters.  But how and where does this get used when the variant is used?


When the user selects a variant, the component controller’s LOAD_VARIANT routine is executed.  It calls SET_FIELDS to read the variant data and put the values into the attached selection screens.  One more routine - SET_FIELD_PARAMS - is called for each field to call the selected dynamic date function to interpret the resulting date.



   1: METHOD set_field_params .                                   " PLM8034
   2:  
   3:   DATA: l_date                        TYPE sydatum.
   4:   DATA: lt_intrange                   TYPE TABLE OF rsintrange,
   5:         ls_intrange                   TYPE rsintrange.
   6:   DATA: lt_daterange                  TYPE TABLE OF rsdatrange,
   7:         ls_daterange                  TYPE rsdatrange.
   8:  
   9:   CLEAR: rs_return.
  10:   CLEAR: l_date, lt_intrange, ls_intrange, lt_daterange, ls_daterange.
  11:  
  12:   MOVE: is_value-low_dy          TO ls_intrange-low,
  13:         is_value-high_dy         TO ls_intrange-high.
  14:   APPEND ls_intrange TO lt_intrange.
  15:  
  16:   CALL FUNCTION is_value-vname
  17:     IMPORTING
  18:       p_date     = l_date
  19:     TABLES
  20:       p_datetab  = lt_daterange
  21:       p_intrange = lt_intrange.
  22:  
  23:   IF LINES( lt_daterange ) > 0.
  24:     READ TABLE lt_daterange INTO rs_return INDEX 1.
  25:   ELSE.
  26:     rs_return-low = l_date.
  27:   ENDIF.
  28:  
  29:   MOVE: is_value-sign_dy         TO rs_return-sign,
  30:         is_value-option_dy       TO rs_return-option.
  31:  
  32: ENDMETHOD.

In the next post, we’ll close the series by showing how this Web Dynpro component can be used in your own application.








overview

<< previous | next >>

No comments:

Post a Comment