Showing posts with label OOP ALV. Show all posts
Showing posts with label OOP ALV. Show all posts

Thursday, March 08, 2012

Alv events for real time scenario

It has been so long that I have not been able to update my blog. I was quite busy with left to right projects to one of our clients.

Today, I want to share with you on how to handle oop alv using events specifically if front-end data has been changed. I.e sorted, deleted or filtered. On the following scenario below, I am going to present to you my own approach on how to deal with issues regarding alv front-end changes.

Steps:

1. Create a wrapper class for " set_table_for_first_display " method of cl_gui_alv_grid to handle "changing" internal table - meaning every time there are changes on the alv front-end, we will be able to capture and to read the appropriate record or data being clicked (hotpost_click event), changed (user_command event), etc.

2. Create a constructor (class' method called during creation of an object - typically for initialization of attributes) for your wrapper class for us to be able to send the cl_gui_alv_grid object coming from our main program. Our main program should act as a caller for the wrapper class by passing the appropriate parameters for "set_table_for_first_display_ method as shown below:

  variant-report = sy-repid. "to save the alv layout
  variant-username = sy-uname. "to save the alv layout
  variant-variant = alv_var. "layout name

  CREATE OBJECT obj_alv_pir01
    EXPORTING
      i_object = grid1
      .

  CALL METHOD obj_alv_pir01->set_table_for_first_display
    EXPORTING
      is_layout       = wa_alv_layout
      is_variant      = variant "to show the alv layout button
      i_save          = 'A' "to show the alv layout button
    CHANGING
      it_outtab       =   tb_final
      it_fieldcatalog = tb_fieldcat


 3. In our wrapper class, declare a static attribute for our internal table that will handle the it_outtab of "set_table_for_first_display" method. Note: parameter "changing" means that changes of an it_table inside the called method will reflect also to the it_table of the calling program.

4. Inside our event, let us take event USER_COMMAND, we should do the below code in ordfer for us to capture the appropriate line of records being selected from the ALV front-end. "NO matter what happens to the front-end data will also reflect to our static table as shown below":

  DATA lt_selected_rows TYPE lvc_t_roid .
  DATA ls_selected_row TYPE lvc_s_roid .

  CALL METHOD grid_object->get_selected_rows
  IMPORTING
  et_row_no = lt_selected_rows .
  READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1 .

  IF sy-subrc ne 0 .
    MESSAGE s000(su) WITH 'Select a row!'(203) .
    EXIT.
  ENDIF .

  READ TABLE ZCL_ALV_PIR01=>tb_final INDEX ls_selected_row-row_id INTO l_wa_final.

That's it! If you have any clarification, please don't hesitate to post a comment.

Have a nice day!

Monday, April 04, 2011

Printing Header in OOP ALV

In using ALV OOP and you want to print the header i.e. using spliter screen. Don't forget to include this event:

Sunday, March 20, 2011

OOP ALV toolbar button exclusion

A while ago after reading some stuff in SAP SDN site, I stumbled over this exclusion of alv toolbar buttons and found this pdf guide very useful, courtesy of http://www.volker-wegert.de/en/alv-function-codes

Sunday, March 13, 2011

ALV Splitter Screen Create Header

Steps in creating a header in a splitter screen:

Friday, March 11, 2011

OOP ALV splitter screen

Custom container can be divided into parts by a splitter screen class. Usually, developers can create different panel within a custom container to separate its selection screen header or the ALV data itself.

Thursday, March 10, 2011

OOP ALV events

Lately, I always practice to develop my applications in OOP ALV. By using cl_gui_alv_grid class compared to the FM reuse_alv_grid*, I noticed that the former uses EVENTS for the buttons or the mouse clicks to capture user actions over the alv.

To learn more about this events, please download the guide here from SAP AG itself. To give you an idea about this reference, it contains and lists the basic guidelines in using cl_gui_alv_grid. Some of the codes that for example to capture event DATA_CHANGED is not being explained here.

To trigger the data changed event, you may insert the code below and you can set the action you may want your event be triggered:


"activate data_changed 
  CALL METHOD g_alv_grid_ref->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter  
"trigger event after ENTER is pressed
*    i_event_id = cl_gui_alv_grid=>MC_EVT_MODIFIED  
"or trigger once you go to next cell after modification 
(without pressing ENTER)
    EXCEPTIONS
      error      = 1
      OTHERS     = 2.



Thank you!

ALV Object Model (OM)

Hi Guys, so far at least there are different types of approach in developing or creating an ALV depending on your needs and objective. One of them is called ALV Object Model which has been around for some time. This type of ALV can be created using a cl_salv_table class - a wrapper class of the previous ALV classes.

Tuesday, March 08, 2011

Reporting using ALV in OOP

In this topic I will show you how to generate a report using ALV in OOP.