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


3.     The user then selects few entries from the list and press on “Save Variant” button. 

4.     The program stores the variant data in system table INDX using (EXPORT TO ...DATABASE). Using table INDX places a restriction that the WDA component name can't be more than 20 char. Cluster table is created with same table fields as INDX (with more wide SRTFD field) or VARI to store variants. The variants are stored as following in this example.  

·         Area (INDX-RELID) is populated with ‘YW'.

·         The first 20 characters of user defined key (INDX-SRTFD) contains the WD component name. The last 2 characters are used to store the unique variant sequence number.

·         The first 4 characters of INDX-PGMID contains the variant name (plant), the 6th character contains ‘/'.  This is a separator indicator.

·         The rest 8(10) chars are the creation date of variant.

·         The field USERA contains the name of the user who created the variant.

·         The program checks if there is no already existing variant this the same name.

·         The range tables plant are referencing to data. They are made dereference and store the data in range internal tables (... type range of WERKS_D because referenced data can't be exported to database).

·         The both tables are exported to database to ID ‘YW' with key prepared in previous steps.

METHOD onactionsave_variant .

* Local Data Declarations
  DATA lo_nd_header TYPE REF TO if_wd_context_node.
  DATA ls_header    TYPE wd_this->element_header.

* navigate from <CONTEXT> to <HEADER> via lead selection
  lo_nd_header = wd_context->get_child_node( name = wd_this->wdctx_header ).

* get all declared attributes
      static_attributes = ls_header ).

  DATABEGIN OF w_variant_rec_key,
            relid TYPE indx-relid,
            srtfd TYPE indx-srtfd,
            srtf2 TYPE indx-srtf2,
            pgmid TYPE indx-pgmid,
            begdt TYPE indx-begdt,
          END OF w_variant_rec_key.

  DATA : i_variant_rec_key LIKE TABLE OF w_variant_rec_key.

  DATA lo_componentcontroller     TYPE REF TO ig_componentcontroller .
  DATA lo_api_componentcontroller TYPE REF TO if_wd_component.
  DATA my_comp_info               TYPE REF TO if_wd_rr_component.
  DATA my_comp_name               TYPE string.

  DATA l_len        TYPE i.
  DATA l_next_count TYPE i.
  DATA l_pgmid      TYPE char14.
  DATA l_indx       TYPE indx.
  DATA l_program    TYPE indx-srtfd.

  DATA: my_message_manager TYPE REF TO if_wd_message_manager,
      my_selection_items TYPE if_wd_select_options=>tt_selection_screen_item.

  lo_componentcontroller     = wd_this->get_componentcontroller_ctr( ).
  lo_api_componentcontroller = lo_componentcontroller->wd_get_api( ).

*-----Get component controller infor
  my_comp_info = lo_api_componentcontroller->get_component_info( ).
*----Get name of the component
  my_comp_name = my_comp_info->get_name( ).

*-----Program name is first 20 characters of component name
*-----Last 2 characters are being used for variant sequence #
  l_len = STRLEN( my_comp_name ).
  IF l_len GT 20.
    l_program = my_comp_name+0(20).
    l_program = my_comp_name.

  CONCATENATE l_program '%' INTO l_program.

*Read DB to fetch the variant data
* Check if the variant is already present in the database
  SELECT relid
    INTO TABLE i_variant_rec_key
    FROM indx
    WHERE relid EQ 'YW'
      AND srtfd LIKE l_program.

  IF sy-subrc = 0.
    l_next_count = sy-dbcnt + 1.
    LOOP AT i_variant_rec_key INTO w_variant_rec_key.
      IF w_variant_rec_key-pgmid+0(4EQ ls_header-plant.

* Overwrite the existing variant
        CONCATENATE ls_header-plant '%' INTO l_pgmid .
        DELETE FROM indx WHERE pgmid LIKE l_pgmid.
        l_next_count = l_next_count - 1.

*----Now start making the w_index_key to save the variant
  MOVE  l_next_count TO l_program+20(2).

  CLEAR w_variant_rec_key.
  w_variant_rec_key-relid = 'YW'.
  w_variant_rec_key-srtfd = l_program.
  w_variant_rec_key-pgmid+0(4)  = ls_header-plant.
  w_variant_rec_key-pgmid+6(1)  = '/'.
  w_variant_rec_key-pgmid+8(10) = sy-datum.

  CLEAR l_indx.
  MOVE-CORRESPONDING w_variant_rec_key TO l_indx.
  l_indx-usera = sy-uname.
  l_indx-begdt = sy-datum.
  save_indx( EXPORTING in_indx = l_indx ).


5.     The retrieval process takes the following steps.  

·         Reload the application.

·         Click on "Display Variant" button on Main view

·         The control will navigate to Variant_Table view that holds the table with variants.

·         METHOD onactiondisplay_variant.
* Navigate to Variant Table View
  wd_this->fire_to_variant_table_plg ( ).


·         Read all the records from table INDX for area ‘YW' and key having a pattern of 20 characters of WD component name.

·         Get the variant name from first 4 characters of INDX-PGMID field.

METHOD wddomodifyview.

* Local Data Declarations
  DATA lo_nd_variant_table TYPE REF TO if_wd_context_node.
  DATA ls_variant_table    TYPE wd_this->element_variant_table.
  DATA li_variant_table    TYPE wd_this->elements_variant_table.

* navigate from <CONTEXT> to <VARIANT_TABLE> via lead selection
  lo_nd_variant_table = wd_context->get_child_node( name = wd_this->wdctx_variant_table ).

  DATA: my_component       TYPE REF TO if_wd_component,
        my_component_info  TYPE REF TO if_wd_rr_component,
        my_component_name  TYPE string.

  DATA : BEGIN OF w_variant_rec_key,
            relid TYPE indx-relid,
            srtfd TYPE indx-srtfd,
            srtf2 TYPE indx-srtf2,
            pgmid TYPE indx-pgmid,
            usera TYPE indx-usera,
            begdt TYPE indx-begdt,
          END OF w_variant_rec_key.

  DATA : i_variant_rec_key LIKE TABLE OF w_variant_rec_key,
         l_prog            TYPE indx-srtfd,
         l_len             TYPE i.

* Constants Declarations
  CONSTANTS: c_x     TYPE c VALUE 'X',
             c_yw(2TYPE c VALUE 'YW'.

  CHECK first_time IS NOT INITIAL.

*----get component name
  my_component = view->if_wd_controller~get_component( ).
  my_component_info = my_component->get_component_info( ).
  my_component_name = my_component_info->get_name( ).

*----Read all the variants for this component
  l_len = STRLEN( my_component_name ).
  IF l_len GT 20.
    l_prog = my_component_name+0(20).
    l_prog = my_component_name.

  CONCATENATE l_prog '%' INTO l_prog.

  SELECT relid
    INTO TABLE i_variant_rec_key
    FROM indx
    WHERE relid EQ c_yw
      AND srtfd LIKE l_prog.

  CLEAR li_variant_table.

*----Only keep global or user's variant
  LOOP AT i_variant_rec_key INTO w_variant_rec_key.
    IF w_variant_rec_key-usera NE sy-uname AND
       w_variant_rec_key-pgmid+6(1NE '/'.
      DELETE i_variant_rec_key INDEX sy-tabix.

      CLEAR ls_variant_table.

      MOVE : w_variant_rec_key-pgmid+0(4)  TO ls_variant_table-variant_name,
             w_variant_rec_key-pgmid+8(10TO ls_variant_table-variant_desp.
      ls_variant_table-user   = w_variant_rec_key-usera.
      ls_variant_table-created_on   = w_variant_rec_key-begdt.

      APPEND ls_variant_table TO li_variant_table.
      CLEAR  ls_variant_table.


  SORT li_variant_table BY created_on.

* Delete duplicate entries
  CALL METHOD lo_nd_variant_table->bind_table
      new_items = li_variant_table.


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