cancel
Showing results for 
Search instead for 
Did you mean: 

WD -SALV- setting initial view

Former Member
0 Kudos

Hi everyone,

I saw some forums in SDN about setting the initial View in a SALV.

Someone suggested to use R_COMPONENT of type IF_SALV_WD_COMP_TABLE_PERS in order to call the method SET_STANDARD_VIEW.

But noone was able to indicate how r_component could be properly referenced. (Such Forums are anyhow marked as closed but unanswered).

I would be very pleased to know if someone managed to do it, and how.

Thank you so much.

Best Regards,

Christian

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Can you be more specific

Former Member
0 Kudos

Hi,

I copied the same question from another post:

I want to make 'STANDARD view' as a default ALV Layout...If anybody execute my ALV Report STANDARD Layout variant should display by default. Other variant layouts they can select from drill down..

I know class and method but i don't know how to write code for this with paremeters..Can anybody help on code please..

CLASS : CL_SALV_WD_C_TABLE

METHOD : IF_SALV_WD_COMP_TABLE_PERS~SET_STANDARD_VIEW

Regards

Former Member
0 Kudos

Hi,

I copied the same question from another post:

I want to make 'STANDARD view' as a default ALV Layout...If anybody execute my ALV Report STANDARD Layout variant should display by default. Other variant layouts they can select from drill down..

I know class and method but i don't know how to write code for this with paremeters..Can anybody help on code please..

CLASS : CL_SALV_WD_C_TABLE

METHOD : IF_SALV_WD_COMP_TABLE_PERS~SET_STANDARD_VIEW

Regards

Former Member
0 Kudos

Please check if this helps

When you run in Admin Mode with global settings.

Edited by: Lekha on Jun 30, 2011 3:11 PM

Former Member
0 Kudos

Hi Lekha,

I don't want to set the initial view in the settings by Admin Mode.

I need to have separate initial views depending on conditions, e.g. log-on users.

Regards,

Christian

Former Member
0 Kudos

Hi,

Please refer to this code and make changes accordingly as per the conditions -

METHOD wddoinit.
  DATA:
    lo_nd_mara                 TYPE REF TO if_wd_context_node,
    lt_mara                    TYPE        wd_this->elements_mara,
    lo_cmp_usage               TYPE REF TO if_wd_component_usage,
    lo_interfacecontroller     TYPE REF TO iwci_salv_wd_table ,
    lo_api_interfacecontroller TYPE REF TO if_wd_controller,
    lo_pers                    TYPE REF TO if_wd_personalization,
    lv_value                   TYPE REF TO cl_salv_wd_config_table,
    lt_var                     TYPE        wdr_pers_variants,
    wa_var                     TYPE        wdr_pers_variant,
    ls_config_key              TYPE        wdy_config_key.

* navigate from <CONTEXT> to <MARA> via lead selection
  lo_nd_mara = wd_context->get_child_node( name = wd_this->wdctx_mara ).

* Get material master data
  SELECT * FROM mara INTO TABLE lt_mara UP TO 10 ROWS.

* @TODO handle non existant child
  IF lo_nd_mara IS NOT INITIAL.
    lo_nd_mara->bind_table( new_items = lt_mara set_initial_elements = abap_false ).
  ENDIF.

* Instantiate ALV
  lo_cmp_usage =   wd_this->wd_cpuse_alv_materials( ).
  IF lo_cmp_usage->has_active_component( ) IS INITIAL.
    lo_cmp_usage->create_component( ).
  ENDIF.

* Get the interface controller of the component usage
  lo_interfacecontroller =   wd_this->wd_cpifc_alv_materials( ).

* Get the model object of ALV
  IF lo_interfacecontroller IS NOT INITIAL.
    lv_value = lo_interfacecontroller->get_model(
    ).

* Get the API reference
    lo_api_interfacecontroller = lo_interfacecontroller->wd_get_api( ).
  ENDIF.

* Get personalization obect
  IF lo_api_interfacecontroller IS NOT INITIAL.
    CALL METHOD lo_api_interfacecontroller->get_personalization_manager
      RECEIVING
        pers_manager = lo_pers.
  ENDIF.
* Get variants
  IF lo_pers IS NOT INITIAL.
    CALL METHOD lo_pers->get_variants
      RECEIVING
        variants = lt_var.
  ENDIF.
* Set the default variant
* Required variant is read 
* READ statement can be modified as per the requirement.
* As this application holds only one user variant, first record is read. 
##read the respective records based on your condition
  IF lt_var IS NOT INITIAL.
    READ TABLE lt_var INTO wa_var INDEX 1. 
    IF sy-subrc EQ 0.
      ls_config_key-config_id    = wa_var-config_id .
      ls_config_key-config_type  = wa_var-config_type.
      ls_config_key-config_var   = wa_var-config_var.
    ENDIF.
    TRY.
        CALL METHOD lo_pers->set_default_variant
          EXPORTING
            config_key = ls_config_key
            set        = abap_true.
      CATCH cx_wd_personalization .
    ENDTRY.

* Get the variant information based on variant id
* Load the variant/ Set the default variant
    CALL METHOD lo_pers->load_config_by_key
      EXPORTING
        config_key            = ls_config_key
        fetch_default_variant = abap_true.
  ENDIF.
ENDMETHOD.

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha,

I have used your  code but the problem is that this code works perfectly when I am in Customizing-Mode but not in regular mode. I would like to use that always. Do you know how i could solve that?

Thanks,

Sergio

jmtrujillogalan
Explorer
0 Kudos

Hi,

I'm using this code to set custom view by default and it's ok. However, at runtime, i need  to change this custom view to other custom view.

I try to reuse all code with other view key but alv don't take changes. When i refresh web page, i use the new key and view has been changed.

Other test is to delete the alv component, create it again and set all configuration but changes don't appear.

Thanks in advance.

Regards.

[...]

    IF sy-subrc EQ 0.

      ls_config_key-config_id    = wa_var-config_id .

      ls_config_key-config_type  = wa_var-config_type.

      ls_config_key-config_var   = wa_var-config_var.

    ENDIF.

    TRY.

        CALL METHOD lo_pers->set_default_variant

          EXPORTING

            config_key = ls_config_key

            set        = abap_true.

      CATCH cx_wd_personalization .

    ENDTRY.

* Get the variant information based on variant id

* Load the variant/ Set the default variant

    CALL METHOD lo_pers->load_config_by_key

      EXPORTING

        config_key            = ls_config_key

        fetch_default_variant = abap_true.

Answers (1)

Answers (1)

Former Member
0 Kudos

Thank you so much Lekha for your very useful code! Problem solved!

Regards,

Christian

prasanth_kasturi
Active Contributor
0 Kudos

Hi Christian,

Could you please let me know how it is resolved. I need to Set the variant [Standard View]  for my ALV.

When I call the method load_config_by_key , I am getting a dump.