Thursday, April 4, 2013

ALV Configuration on Webdynpro


Introduction:

One of my post explains the process of displaying ALV on a webdynpro screen. Once you see the ALV output, next requirement from business would be, Can I sort the data? or Can I show different colors on the output? or Summation of totals and various other requirements related to the ALV output.

ALV's using Function Module:

If you are displaying ALV using function module on a dynpro, it is pretty straight forward where you pass your field catalog, layout options and data to SAP standard function module and it has all the logic to display ALV. If you have to do some additional functionality, then you might have to call few other function modules either before or after ALV display.

ALV's Using Global Class/Methods option:

If using class and methods to display ALV on a regular dynpro, there is a main method to which you pass data, field catalog, layout and it displays ALV. This standard class does have other methods which can be used to configure ALV display as per user requirements, like coloring columns, Sorting, Sum/Total of columns etc. You would have to call those methods with the same instance of the class which you use for ALV display.

ALV's on WD:

Whereas on WD ALV, display of ALV is handled in a different manner as WD is based on OVC concept and also it utilizes Oop's concepts in development. It might be little complex to other methods we have seen above, but this provides more options and features to the final ALV display.

Coming to actual concept of WD ALV,

Just like a function module, SAP has developed a standard WD component SALV_WD_TABLE which needs to be included in your used components list and then map your internal table to DATA context and it shows that data in an ALV. So far its simple but if you want to configure the look of ALV, like coloring ALV  rows or columns, setting sort etc it needs some additional logic

For WD ALV, SAP has used the core object oriented concept in coding, the reason I am saying this is because I see that there are classes for even for small requirements like, for getting, setting column's configuration, there is a method CL_SALV_WD_COLUMN, for creating header for ALV, there is a class with its own methods which is, CL_SALV_WD_HEADER and so on.
But to be able to use this classes and methods, first you have to get MODEL of that alv.

In lay man terms, I will try to explain the concept SAP followed : (for people who are good in OOP's what I am saying now might look childish :) but this helps for people who started working in ABAP directly).
In main WD Component SAP has provided an interface method which is GET_MODEL whose output is a Class which SAP has referred in its WD component to handle ALV configuration. Class name is, CL_SALV_WD_CONFIG_TABLE. Now, inside that class there are lot of inherited methods which again have another class as exporting value, like IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN method has CL_SALV_WD_COLUMN as output. Now, if you want to perform any column operations for your ALV, you would have to call the methods in the latter class. Basically, SAP collected all the requirements related to ALV, then grouped them based on its topic and then developed a global class for each topic or scenario and then inherited all the classes in the main SALV_WD_TABLE WD component. Now, if you want to use those methods you just have to create instances for each class and call respective methods.

Now the interesting part, that is actual coding :) to understand what I am talking above: 

Here I am trying to handle a requirement where we have to color code ALV Columns based on certain condition. I am taking standard SPFLI data and coloring few columns based on certain condition.

First step is to develop a simple WD ALV application which shows SPFLI data( I already have a post explaining how to display a simple ALV) which looks as shown below.









Now I am coloring certain rows based on Carr id. To make it more interesting, When coloring comes to picture, question every one has is what colors are allowed. There is standard domain, WDUI_TABLE_CELL_DESIGN which has the list of colors. To make our ALV little interesting, I added a parameter to our WD View to select what color needs to be shown and based on that displayed ALV. My View looks as shown below,









Input field refers to domain WDUI_TABLE_CELL_DESIGN which provides automatic F4 for that field and the view container for ALV. User needs to specify color number and click on a button to show ALV output. I have all my logic in the method which triggers when that button is clicked.

Step 1: Get the color field value into a variable.

Step 2: Now, we have to create an instance for the wd component salv_wd_table. In my wd, wd_alv_output is the name i used for that component usage.

* Declaring variable for component usage.
  DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

* Moving ALV_OUTPUT component usage instance to local variable.
  lo_cmp_usage =   wd_this->wd_cpuse_alv_output).

  IF lo_cmp_usage->has_active_componentIS INITIAL.
    lo_cmp_usage->create_component).
  ENDIF.


Step 3: Now, I want to access the interface methods inside that SALV* component for which I have to create an instance for its interface controller.

* Variable for the interface controller of SALV
  DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

* Creating an instance for local variable.
  lo_interfacecontroller =   wd_this->wd_cpifc_alv_output).

Until above, we can use Generator to generate code automatically.

Step 4: As mentioned in above explanation, I have to call method GET_MODEL which is SALV interface method which will give access to all the methods as shown below,

* Get Model is done here
  DATA lv_value TYPE REF TO cl_salv_wd_config_table.

* lv_value is the instance of the class cl_salv_wd_config_table.
  lv_value lo_interfacecontroller->get_model ).

Step 5 : Now you can access any method of that class, one example is, if I want to disable the Filter button which you see on the right corner of ALV, you just have to call a method as shown below,

* Setting the indicator to disable Filter button.
if_salv_wd_std_functions~set_filter_filterline_allowed ( value abap_false ).

Step 6: Coming to our requirement which is to color a column, first you need a field in your context menu which can handle as what color needs to be shown. In my test case, I have created field named,


First, fill your internal table with data. Then loop through table to fill that field with the color which you want to show on the output,

  SELECT *
    FROM spfli INTO TABLE li_spfli_copy.

* Here I am filling a color based on carr-id.
  LOOP AT li_spfli_copy INTO li_spfli.
    IF li_spfli-carrid EQ 'AZ'.
      li_spfli-cell_design lv_color.
    ELSEIF li_spfli-carrid EQ 'LH'.
      li_spfli-cell_design cl_wd_table_column=>e_cell_design-goodvalue_light.
    ENDIF.
    APPEND li_spfli TO lt_spfli.
  ENDLOOP.


Step 7: Now, the main part where you have to set the columns which you want to color code. This is a little tricky method,

First you have the get column settings(Basically, you are inheriting the properties of SALV_WD_TABLE which you create its instance)

* SALV has used cl_salv_wd_column and its method to set properties of columns, here you are trying to inherit that into your wd.

  DATA:
     l_column TYPE REF TO cl_salv_wd_column,


* lv_value is filled when you did get model. Inside that, you are calling get_column method to get the instance * of the columns and then call the methods inside that class to make settings to that column.

  l_column lv_value->if_salv_wd_column_settings~get_column('CARRID').
  l_column->set_cell_design_fieldnamevalue 'CELL_DESIGN').

* Similarly setting other columns also to point to that field.
  l_column lv_value->if_salv_wd_column_settings~get_column('CONNID').
  l_column->set_cell_design_fieldnamevalue 'CELL_DESIGN').

Now, the final output looks as shown below:











You can email me if you have any questions or if I have something wrong in my post. Hope this was helpful for you guys :).

3 comments:

  1. Thanks a lot for this info. It is really an informative post. So much clear examples with slides and print screens.
    Just cleared almost all my doubts. Wonder it will solve some of the questions too for which I use to Google and Youtube some of the queries.
    Hope this online course also clears some of the doubts I came across like about the controllers and the FPM. http://www.wiziq.com/course/8153-sap-web-dynpro-pro-abap-training
    I have no idea regarding online and e learning platforms. Still want to go for this one.Wonder it works for me as well.

    ReplyDelete
  2. hey sukaniya,
    I am taking this course from http://www.wiziq.com/course/8153-sap-web-dynpro-pro-abap-training its a really good one and has worked form me so if you have any question regarding this course you can ask me .

    ReplyDelete
  3. Hey Heena,
    I have also taken this course from http://www.wiziq.com/course/8153-sap-web-dynpro-pro-abap-training and i agree with you that it is a really good one. And for people who likes to learn online this site is very useful because it provides different courses for people with different interests.

    ReplyDelete