Save Select Options and ALV Selection records in ABAP Web Dynpro Application

By Ravi Aswani, Yash Technologies

Scenario:  Display Material Details based on the plant provided by the user on the selection screen.

Requirement: It was required to provide the basic variant functionality in WD application as it available in SAP ABAP report. 

In the below WD example application I am creating a variant by saving the select-options data along with the records that are selected in the ALV list.

The application has a Main view which contains selection parameter Plant.  The user provides the Plant and clicks on ‘Get Details’ button to display the materials and its relevant master data based on the plant entered. The user then selects the records from the ALV list that contains all the materials and does ‘Save Variant’ accordingly all the selection records and parameter details are saved in a variant. 

Again the user loads the application and clicks on ‘Display Variant’ and navigates to view ‘Variant_Table’  that contains list of variants created by the user in the application  now the details are fetched from the variant and the plant and material details are automatically displayed from the variant.

1.     Create your application with select options using used component WDR_SELECT_OPTIONS.  

METHOD wddoinit.

DATA:  lt_range_table TYPE REF TO data,
       rt_range_table TYPE REF TO data,
       read_only      TYPE abap_bool,
       typename       TYPE string.

  DATA: lr_componentcontroller TYPE REF TO ig_componentcontroller,
        l_ref_cmp_usage        TYPE REF TO if_wd_component_usage.

* create the used component
  l_ref_cmp_usage = wd_this->wd_cpuse_select_option ( ).

  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.

  wd_this->m_wd_select_options = wd_this->wd_cpifc_select_option( ).

* init the select screen
  wd_this->m_handler = wd_this->m_wd_select_options->init_selection_screen( ).
  wd_this->m_handler->set_global_options(
                              i_display_btn_cancel  = abap_false
                              i_display_btn_check   = abap_false
                              i_display_btn_reset   = abap_false
                              i_display_btn_execute = abap_false ).


* create a range table that consists of this new data element
  lt_range_table = wd_this->m_handler->create_range_table

                                      (i_typename = 'WERKS’).


* add a new field to the selection
  wd_this->m_handler->add_selection_field( i_id = 'WERKS'
  it_result       = lt_range_table
  i_read_only     = read_only
  i_no_intervals  = abap_true
  i_no_extension  = abap_true ).

ENDMETHOD.
 

2.     After user provides the input on the selection screen (i.e. Plant) and clicks on “Get Details” an ALV list is displayed that contains all the materials belonging to the corresponding plant.  

METHOD onactionget_details.

* Field Symbol Declarations
  DATABEGIN OF wa_mard,
           matnr TYPE mard-matnr,
           werks TYPE mard-werks,
           lgort TYPE mard-lgort,
         END OF wa_mard.

  DATA: s_werks   TYPE REF TO data.  

* Field Symbols declarations
  FIELD-SYMBOLS: <s_werks> TYPE table.

* Local Data Declarations
  DATA lo_nd_header TYPE REF TO if_wd_context_node.
  DATA ls_header    TYPE wd_this->element_header.
  DATA wa_mara      TYPE mara.
  DATA li_mard      LIKE TABLE OF wa_mard.
  DATA wa_marc      TYPE marc.
  DATA wa_makt      TYPE makt.

lo_api_controller ?= wd_this->wd_get_api( ).
  s_aufnr  = wd_this->m_handler->get_range_table_of_sel_field

                                ( i_id = 'WERKS').
  
ASSIGN s_werks->* TO <s_werks>.

  
READ TABLE <s_werks> INTO ls_werks INDEX 1.

  CHECK ls_werks-low IS NOT INITIAL.

* Constants Declarations
  CONSTANTS: c_x    TYPE c VALUE 'X'.
  CONSTANTS: c_text TYPE string VALUE 'Select'.

  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA li_marc       TYPE TABLE OF marc.
  DATA li_mara       TYPE TABLE OF mara.
  DATA li_makt       TYPE TABLE OF makt.
  DATA ls_context    TYPE wd_this->element_context.
  DATA lv_visible    LIKE ls_context-visible.

*   get element via lead selection
  lo_el_context = wd_context->get_element(  ).

*   get single attribute
  lo_el_context->set_attribute(
    EXPORTING
      value =  c_x
      name  = 'VISIBLE' ).

  SELECT *
    FROM marc
    INTO TABLE li_marc
    WHERE werks EQ ls_werks-low .

  IF li_marc IS NOT INITIAL.

    SELECT *
      FROM mara
      INTO TABLE li_mara
      FOR ALL ENTRIES IN li_marc
      WHERE matnr EQ li_marc-matnr.

    CHECK li_mara IS NOT INITIAL.

* Get Material Description
    SELECT *
      FROM makt
      INTO TABLE li_makt
      FOR ALL ENTRIES IN li_mara
      WHERE spras EQ sy-langu
        AND matnr EQ li_mara-matnr.

* Fetch Material Storage Locations Details
    SELECT matnr
           werks
           lgort
      FROM mard
      INTO TABLE li_mard
      FOR ALL ENTRIES IN li_mara
      WHERE matnr EQ li_mara-matnr
        AND werks EQ ls_werks-low .

      CHECK li_mard IS NOT INITIAL.

    DATA lo_nd_item_details TYPE REF TO if_wd_context_node.
    DATA ls_item_details    TYPE wd_this->element_item_details.
    DATA li_item_details    TYPE wd_this->elements_item_details.

*   navigate from <CONTEXT> to <ITEM_DETAILS> via lead selection
    lo_nd_item_details = wd_context->get_child_node (name = wd_this->wdctx_item_details).

    LOOP AT li_marc INTO wa_marc.
      READ TABLE li_mara INTO wa_mara WITH KEY matnr = wa_marc-matnr.
      IF sy-subrc EQ 0.
        MOVE-CORRESPONDING wa_mara TO ls_item_details.
        READ TABLE li_mard INTO wa_mard WITH KEY matnr = wa_mara-matnr.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING wa_mard TO ls_item_details.
        ENDIF.
        READ TABLE li_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING wa_makt TO ls_item_details.
        ENDIF.
      ENDIF.

      MOVE space TO ls_item_details-select.
      APPEND ls_item_details TO li_item_details.
      CLEAR  ls_item_details.

    ENDLOOP.

    lo_nd_item_details->bind_table (li_item_details).

  ENDIF.

  DATA lr_nd_mcc_follow_up    TYPE REF TO if_wd_context_node.
  DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.
  DATA lo_value               TYPE REF TO cl_salv_wd_config_table.
  DATA lo_cmp_usage           TYPE REF TO if_wd_component_usage.
  DATA: lr_column_settings    TYPE REF TO if_salv_wd_column_settings,
        lr_table_settings     TYPE REF TO if_salv_wd_table_settings,
        lr_input_field        TYPE REF TO cl_salv_wd_uie_input_field,
        lr_column             TYPE REF TO cl_salv_wd_column,
        lr_col_header         TYPE REF TO cl_salv_wd_column_header,
        lr_checkbox           TYPE REF TO cl_salv_wd_uie_checkbox.

  lo_cmp_usage =   wd_this->wd_cpuse_material_data_alv( ).

  IF lo_cmp_usage->has_active_component ( ) IS INITIAL.
    lo_cmp_usage->create_component( ).
  ENDIF.

* Navigate from <CONTEXT> to <ALV_CHGDLR> via lead selection

  lr_nd_mcc_follow_up = wd_context->get_child_node( name = wd_this->wdctx_item_details ).

  lo_interfacecontroller =   wd_this->wd_cpifc_material_data_alv( ).
  lo_interfacecontroller->set_data( r_node_data = lr_nd_mcc_follow_up ).

  lo_value = lo_interfacecontroller->get_model( ).

  lr_table_settings ?= lo_value.
  lr_table_settings->set_visible_row_count( '20' ).

*sets column as a checkbox
  lr_column_settings ?= lo_value.
* Set required text
  lr_column = lr_column_settings->get_column( 'SELECT' ).

  CREATE OBJECT lr_checkbox
    EXPORTING
      checked_fieldname = 'SELECT'.

  lr_checkbox->set_enabled( abap_true ).
  lr_column->set_cell_editor( lr_checkbox ).

  lr_column = lr_column_settings->get_column( 'SELECT' ).
  lr_col_header = lr_column->get_header( ).
  lr_col_header->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ).
  lr_col_header->set_text( EXPORTING value = c_text ).

* initially when output is displayed, cursor is on first row.
* By below statement index is set to 0
  CALL METHOD lr_nd_mcc_follow_up->set_lead_selection_index
    EXPORTING
      index = '0'.

  lo_value->if_salv_wd_table_settings~set_read_only( abap_false ).

ENDMETHOD.

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image