ALV

You are currently browsing articles tagged ALV.

If you want to create an ALV report in just 8 simple steps, here’s your chance – http://www.alvrobot.com.ar.

This site lets you create a ABAP report through a wizard and it’s for free. You just need to provide the tables used to gather information, selection criteria, selection screen options, and fields required to be displayed. Furthermore, the report generated is well commented and easy-to-understand; therefore, you can customize the report to fit to your requirement, just as easily – adding any calculations, performance tuning, etc. The site also provides a well written guide to use the wizard.

This wizard is intended for use of ABAP Programmers, but I think it’ll be very useful for non-programmers as well as for beginners

Tags: , , ,

Last week, I had a problem with the Excel in place (ALV Excel InPlace) feature of the ALV grid. None of the data was transferred to the excel sheet, and I was clueless of what was wrong; however, after some googling I figured out that it’s the macro security of excel which causes the problem.

You have to set the macro security level of Excel to low or medium. You can set this by opening the Macro Security dialog box (Tools->Macro->Security…) and setting the Security Level (in tab Security Level) to low or medium and the checking the option Trust access to Visual Basic Project in the tab trusted sources.

Tags: , , ,

ALV Grid lets you get subtotals and totals of columns, but you might often need to get averages and percentages among other not so frequent requirements.

It’s possible to get averages (or sub-averages) instead of subtotals you can use field_cat-do_sum = 'C'. in place offield_cat-do_sum = 'X'. which you use to get subtotals.

But what if you need to get a percentage; for example, you are given number of students present in each class and the total number of students in each class (which is not the same) and you need to get the percentage present in each class as well as the total of all class, which is obviously not the sum of all percentages – you must divide the total number present by the tatal number of students in the school. You can’t do this in the traditional way, but this isn’t very hard.

You can use the method get_subtotals, since this method returns a reference you can use it to change the values displayed as subtotals to what ever you want, not just percentages – ratios, powers, logarithms, anything you want. I haven’t still tested whether the values you’ve changed are changed back, when you hide columns (or do something with the ALV grid) in the ALV grid after it’s been displayed.

This is the code


CREATE OBJECT gr_alvcon
  EXPORTING container_name = 'ABC'. "Name of the custom container
  
CREATE OBJECT gr_alvgrid
  EXPORTING i_parent = gr_alvcon.

CALL METHOD gr_alvgrid->set_table_for_first_display
    EXPORTING
      is_layout = ps_layout
    CHANGING
      it_fieldcatalog = fieldcat
      it_sort = it_sort
      it_outtab = it_delsm[].

DATA : total TYPE REF TO data,
       subto TYPE REF TO data.

FIELD-SYMBOLS <ftotal> TYPE STANDARD TABLE.
FIELD-SYMBOLS <fsubto> TYPE STANDARD TABLE.
DATA wa_tot TYPE t_delsm.

CALL METHOD gr_alvgrid->get_subtotals
    IMPORTING ep_collect00 = total
              ep_collect01 = subto.
ASSIGN total->* TO <ftotal>.
ASSIGN subto->* TO <fsubto>.
  
LOOP AT <ftotal> INTO wa_tot.
  wa_tot-delpc = wa_tot-delpr * 100 / wa_tot-totpr. " Set any value for this
  MODIFY <ftotal> FROM wa_tot INDEX sy-tabix.
ENDLOOP.

CALL METHOD gr_alvgrid->set_ready_for_input
    EXPORTING i_ready_for_input = 1.

Hope this suits your need.

There are many ways of customizing the values in subtotals and totals. I’ll later put information about them also.

EDIT

Since there had been some questions about the above code and using it with REUSE_ALV_GRID_DISPLAY (see comments), I thought of adding a piece of code that might help you. This will set an event and change the subtotals during that event.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
* Events
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
  EXPORTING
  i_list_type = 0
  IMPORTING
  et_events = v_events.
 
READ TABLE v_events INTO wa_event WITH KEY name = 'END_OF_PAGE'.
wa_event-form = 'SET_DEL_PERC'.
MODIFY v_events FROM wa_event TRANSPORTING form WHERE name = wa_event-name.
 
*Set the percentages for subtotals
FORM SET_DEL_PERC.
	DATA : total TYPE REF TO data,
         subto TYPE REF TO data,
         subt1 TYPE REF TO data,
	       gr_alvgrid TYPE REF TO cl_gui_alv_grid.
	FIELD-SYMBOLS  : <ftotal> TYPE STANDARD TABLE,
                   <fsubto> TYPE STANDARD TABLE,
                   <fsubt1> TYPE STANDARD TABLE.
	DATA wa_tot TYPE t_delsm.
 
	CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
		IMPORTING
			e_grid = gr_alvgrid.
 
 
	CALL METHOD gr_alvgrid->get_subtotals
	    IMPORTING ep_collect00 = total
	              ep_collect01 = subto
	              ep_collect02 = subt1.
 
  ASSIGN total->* to <ftotal>.
  ASSIGN subto->* to <fsubto>.
  ASSIGN subt1->* to <fsubt1>.
 
* Use a method to calculate percentages if number of levels with subtotals increase
	LOOP AT <ftotal> INTO wa_tot.
    PERFORM cal_del_per CHANGING wa_tot.
 
	  MODIFY <ftotal> FROM wa_tot INDEX sy-tabix.
	ENDLOOP.
 
	LOOP AT <fsubto> INTO wa_tot.
    PERFORM cal_del_per CHANGING wa_tot.
 
	  MODIFY <fsubto> FROM wa_tot INDEX sy-tabix.
	ENDLOOP.
 
	LOOP AT <fsubt1> INTO wa_tot.
    PERFORM cal_del_per CHANGING wa_tot.
 
	  MODIFY <fsubt1> FROM wa_tot INDEX sy-tabix.
	ENDLOOP.
 
CALL METHOD gr_alvgrid->set_ready_for_input
		EXPORTING i_ready_for_input = 1.
ENDFORM.

Hope this helps

Tags: , , , ,