Sei sulla pagina 1di 14

ALV Object Model Notes:

Introduction:

The CL_SALV_TABLE class is part of the ALV Object Model which was introduced in Net Weaver
2004. Basically it is an encapsulation of the pre-existing ALV tools. For example the class
CL_SALV_TABLE actually wraps around the CL_GUI_ALV_GRID class for container
implementation, as well as the REUSE_ALV_GRID_DISPLAY and REUSE_ALV_LIST_DISPLAY
function modules for full screen display.

It was designed to be a single point of entry when using a specific ALV tool such as the ALV
table display, ALV hierarchical sequential list, and tree ALV. All of these individual ALV tools
have their own base class, for table it is the CL_SALV_TABLE, but all have a common look. A lot
of the methods are the same, with only some differences in the parameters of the methods
depending on the actual tool you are using.

Following are the general classes used in ALV Object Model:

Basis Class for Simple Tables: CL_SALV_TABLE

Basis Class for Hierarchical-Sequential Tables: CL_SALV_HIERSEQ_TABLE

Basis Class for Tree Structure: CL_SALV_TREE

So to summarize, the ALV Object Model was delivered to give a more collective interface to the
ALV tools. There are limitations in the ALV Object Model, for example, you can NOT color a line
or a cell, but you can color a column. Also, you can NOT have an editable ALV using the Object
Model.

But for basic lists, it is a very powerful tool.

Following are the restrictions with CL_SALV_TABLE (ALV Object Model):-

The number of columns is restricted to 90.

The output length of a column is restricted to 128 characters.

For sorting and subtotals, you use a total of nine levels or columns.

For columns that can be aggregated, note that the internal length of the column is large
enough for both single values and the result.

The output is column-oriented. You are only able to display flat, structured tables. You are not
able to display nested tables.
Tables displayed with ALV are not ready for input.

If you insert the table as grid in container, you are not able to use batch mode (background)

MVC Requirement

MVC Design Pattern Layout

Design Pattern: is a set of rules using which the code can be implemented.
Design Patterns in ABAP Objects:

1. Singleton Design Pattern ---> implementation  Singleton class --> Example:


Persistence service (actor class is a singleton class)

2. MVC Design Pattern - --> In this, we need to separate the business logic with presentation
logic

MVC --> Model view controller

Model ---> responsible for fetching the data

View ---> responsible for generating the content to the user (output)

Controller --> acts as a interface (mediator) between model and view

3. Factory Design Pattern - ---> hides the complexity of instantiating the objects

4. FACADE Design Pattern

5. Observer Design Pattern

MVC (Model View Controller) Design pattern: The aim of MVC design pattern is to separate
the business logic and presentation logic, so that in future, changes can be made to business
logic and presentation logic without having much dependency.

Requirement: Develop an interface using MVC Design pattern to display the sales orders data
in the selected format.

Create Model class: z730model

Attribute tab:
Note: ‘ZTVBAK’ is table type associated with dictionary structure ‘ZCVBAK’ with the fields vbeln,
erdat, erzet, ernam
Method tab:

Parameters for method ‘getsalesorders’:


Note: In the above method signature ‘ZSTRERDAT’ is a custom dictionary structure copied from
standard dictionary structure ‘RSDSSELOPT’

After copying the standard dictionary structure ‘RSDSSELOPT’ to the custom dictionary
structure ‘ZSTRERDAT’, replace the data elements of low and high fields to ‘ERDAT’.
Implementation for method ‘getsalesorders’:

method getsalesorders.
select vbeln erdat erzet ernam
from vbak
into table gt_vbak
where erdat between i_erdat-low and i_erdat-high.
endmethod.

Save and activate the model class

Create Controller class: z730controller

Attribute Tab:

Method tab:
Implementation for method ‘createmodelobject’ :

method createmodelobject.
create object o_model.
endmethod.

Save and activate the controller class

SMARTFORM Creation: (one of the view generated based on user selection)

T-code: SMARTFORMS
Save and activate the smartform  Generates function module dynamically

Report Program (Generates Appropriate View based on User Selection)

report z730view.

data v_erdat type vbak-erdat.


select-options so_erdat for v_erdat default '19970103' to '19970203' no-extension.

parameters : p_r1 radiobutton group grp1 user-command fc1,


p_r2 radiobutton group grp1,
p_r3 radiobutton group grp1,
p_r4 radiobutton group grp1 default 'X'.

data o_ctrl type ref to z730controller.

initialization.
create object o_ctrl.

at selection-screen on radiobutton group grp1.


case sy-ucomm.
when 'FC1'.
if p_r1 = 'X'.
perform getmodelobject.
perform getdata.
perform displayalvreport.
elseif p_r2 = 'X'.
perform getmodelobject.
perform getdata.
perform displayclassicalreport.
elseif p_r3 = 'X'.
perform getmodelobject.
perform getdata.
perform displaysmartform.
endif.
endcase.

form getmodelobject .
call method o_ctrl->createmodelobject.
endform. " GETMODELOBJECT

form getdata .
call method o_ctrl->o_model->getsalesorders
exporting
i_erdat = so_erdat.

endform. " GETDATA

form displayalvreport .
data o_alv type ref to cl_salv_table.
try.
call method cl_salv_table=>factory "uses factory design pattern
importing
r_salv_table = o_alv
changing
t_table = o_ctrl->o_model->gt_vbak.

catch cx_salv_msg .
message 'Exception in creating ALV object' type 'I'.
endtry.

if o_alv is not initial.


call method o_alv->display.
endif.
endform. " DISPLAYALVREPORT

form displayclassicalreport .
data wa_vbak type zcvbak.
leave to list-processing.
format color 3.
loop at o_ctrl->o_model->gt_vbak into wa_vbak.
write :/ wa_vbak-vbeln,
wa_vbak-erdat,
wa_vbak-erzet,
wa_vbak-ernam.
endloop.
format color off.
endform. " DISPLAYCLASSICALREPORT

form displaysmartform .
* get the smartform function module name
data lv_fname type rs38l_fnam.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'Z730SFORM'
importing
fm_name = lv_fname.

* call the smartform


call function lv_fname
exporting
t_vbak = o_ctrl->o_model->gt_vbak.
endform. " DISPLAYSMARTFORM

Selection-Screen selection texts:

In the program, choose goto menu  text elements  selection texts (construct appropriate
text)

Potrebbero piacerti anche