Oops Notes
Oops Notes
1. Encapsulation --> binding data and member functions into single unit (class)
4. Execute select queries to read data from db into work area / internal table
5. Process the work area/ internal table to show the content (data) to the user
field 2, ename
----
end of <type name>. endclass.
ty_emp-empno = 1. (invalid)
wa_emp1-empno = 1.
wa_emp1-ename = 'Raju'.
wa_emp2-empno = 4.
wa_emp2-ename = 'Ramesh'.
2. Global class --> global to all objects ----> class builder tool (se24)
1. Definition of class
Syntax:
declaration of components.
endclass.
Note: if class definition contains method declarations, then we need to implement the class
2. Implementation of class
Syntax :
implementation of methods.
endclass.
Note: class definition and class implementation doesn't allocate any memory, it only
provides template of the class
Instantiate the class ---> creating the object for the class--> memory will be
allocated
Syntax:
Syntax:
Instance Attributes:
They are specific to object i.e. for every object, separate memory will be allocated for each
instance attribute.
They can be accessed only by using the Object.
Static Attributes:
The memory for static attributes will be allocated whenever the class is loaded in to the
memory i.e. memory will be allocated only once which will be shared by all the objects of the
class.
They can be accessed either by using the object or by using the class name.
Constant Attributes:
In Local classes, they are declared by using the keyword ‘constants’. They must be initialized at
the time of declaration itself. The value of the constant attribute remains same throughout the
program.
The memory for them will be allocated whenever the class is loaded in to the memory i.e.
memory will be allocated only once which will be shared by all the objects of the class.
They can be accessed either by using the object or by using the class name.
Note: We go for instance attributes whenever we need to maintain unique (different) values for
each object. We go for static attributes, whenever we need to maintain a common (same) value
for all the objects of the class. We go for constant attributes, whenever we need to maintain a
fixed value for all the objects of the class.
Types Attributes
In Local classes, they are declared by using the keyword ‘Types’. Types attribute declaration
only provides template, but doesn’t allocated any memory. To make use of Types attributes, we
need to create references based on types attribute declaration. These references can be either
a normal data attribute / internal table / work area.
Methods:
- A method is a set of statements which is implemented only once and can be called any
no. of times.
Method Parameters:
We can use the keyword ‘optional’ as part of local class method parameters to declare
it as optional parameter and in case of global class methods, select the checkbox
‘optional’
1. Declaration
syntax:
syntax:
statements.
endmethod.
3. Calling
syntax 1:
syntax 2:
- In case of ABAP a method can return any no. of values. The no. of return values depends
on no of Exporting/changing Parameters.
Returning Parameters:
- To restrict a method to return exactly one value, we must use returning parameter.
Instance methods:
Static methods:
They can access only static components, constant attributes and types attributes. i.e
they cannot access instance components.
Note: In Local classes, the sequence of visibility sections (access specifiers) for the class
components should be in the order of public, protected, private sections.
Note: It is recommended to define and implement the local class at the beginning of
executable program and explicitly handle the event ‘start-of-selection’ after the class
implementation to indicate the starting point of program execution.
Me keyword:
“Me” keyword refers to current object in execution i.e. as part of every instance method
execution (runtime), an implicitly created object (created by SAP) will be available and it
refers to the object which is currently executing the method.
Friend keyword:
In General outside the class, A Object can access only public components of the class
directly. i.e protected and private components of the class cannot be accessed outside
the class using an object of a class.
In order to enable the objects of the class to access all components of the class outside
the class irrespective of the visibility, then we can go for Friend classes.
In local classes “Friend” is a keyword used as part of class definition to consider another
class as friend.
Deferred Keyword:
As part of declaring local friend classes, we need to forward declare the friend classes by
using “Deferred” keyword. This deferred keyword indicates that the class definition is
provided somewhere else in the program and not at the beginning of the program.
Load keyword:
It is used to load the global classes explicitly in the executable program. This is
mandatory before the release 6.20 for accessing static components of the global class
before instantiating them.
From 6.20, it is not required, but in case, if we get any compilation error while accessing
the static components / any other components of global class, then we can load the
global class explicitly from the class library by using load keyword.
Constructor:
- It is special method used for initializing the attributes of the class i.e. whenever an
object is created, the attributes should be initialized with some initial values.
1. Instance constructor.
2. Static constructor.
Instance constructor
- It is specific to object i.e. whenever a new object is created SAP executes “Instance
constructor”.
- Instance constructor is executed only once in the life time of every object.
Static constructor
- It is declared by using keyword “class_constructor”.
- It is executed only once in the life time of every class. I.e. it is executed in either of the
following cases.
- Case 1: When we access any static components of the class before creating any objects
for the class. (or)
- Case 2: when we create first object of the class before accessing any static components
of the class.
Note:
If a class contains static and instance Constructor and if we instantiate first object before
accessing any static components, than SAP first executes Static Constructor and then the
Instance Constructor will be executed on behalf of that first object, from the second
object onwards only instance constructor will be executed.
INHERITANCE
It is a process of using the properties (components) of one class inside other class.
The main aim of Inheritance is Reusability of the components i.e. a component declared
in one class can be accessed by other class.
In Inheritance, two classes are involved (super class/base class and sub class/derived
class).
The class which gives properties is called as super class / base class.
Only Public and Protected components can be inherited i.e. Private Components cannot
be inherited.
Types of inheritance:
1. SINGLE INHERITANCE: A Class acquiring properties from only one super class.
2. MULTIPLE INHERITANCE: A class acquiring properties from more than one entity
(interface).
Note: In ABAP, Multiple inheritance can be implemented using the combination of class
and interfaces.
Inheriting from – is a keyword used as part of local class definition for inheriting another
class.
A class declared as Final cannot be inherited i.e. it cannot have subclass. In case of local
classes, we use the keyword ‘final’ as part of class definition to declare a final class.
Polymorphism
Morph-> forms,
Ism-> behaviour
Example:
Method Overloading:
Method Overriding:
- Whenever a local subclass wants to redefine the super class method, the sub class as to
re-declare super class method by using “redefinition” keyword.
- Whenever the super class method is redefined in subclasses, we cannot change the
visibility / category.
- Whenever a subclass redefines super class method, it is always recommended to call the
super class method implementation in the subclass and this is done by using “super”
keyword.
- Instance public / Instance protected methods declared as final can be inherited but
cannot be redefined.
- If a super class contains static and instance constructor and subclass without any
constructors, and if we instantiate first object of super class/sub class before accessing
any static components of super/sub class ,then SAP first executes static constructor of
super class and then instance constructor of super class and from second object of super
class/sub class only instance constructor of super class will be executed.
- If a super class contains static and instance constructor and subclass only with static
constructor, and if we instantiate first object of sub class before accessing any static
components of super/sub class and also before creating any objects for super class, then
SAP first executes static constructors from super class to sub class and then instance
constructor of super class and from second object onwards, only instance constructor of
super class will be executed.
- If a super class contains static and instance Constructor and subclass also with static and
instance constructor, then it is mandatory for sub class instance constructor to call the
super class instance constructor explicitly by using super keyword.
- In this case, if we instantiate first object of sub class before accessing any static
components of super/sub class and before creating any objects for super class, then SAP
first executes static constructors from super class to sub class (top to bottom) and then
instance constructors from sub class to super class (bottom to top) and from second
object of sub class onwards, only instance constructors will be executed from sub class
to super class.
If a super class contains instance constructor with mandatory parameters and sub class
also contains instance constructor with mandatory parameters and whenever we
instantiate the sub class, make sure that you pass values for the parameters of sub class
instance constructors and from sub class instance constructor implementation we need
to call super class instance constructor by passing values for parameters of super class
instance constructor.
If a super class contains instance constructor with mandatory parameters and sub class
without any instance constructor and whenever we instantiate the sub class, make sure
that you pass values for the parameters of super class instance constructors while
instantiating sub class object.
Public classes:
- Public class can be instantiated anywhere (within same class/ inside subclasses /outside
classes).
- The subclass inheriting the super public class is also created as public by default.
- The sub class inheriting the super public class can be created as explicit
protected/private.
Protected classes:
- Create protected is the keyword used as part of local class definition to create the
protected classes.
- Protected classes cannot be instantiated outside the classes but they can be instantiated
inside same classes as well as inside subclass methods.
- The subclass inheriting protected class can be created as explicit public class (or) private
class.
- Private classes:
- Private class cannot be instantiated outside the classes and inside subclasses, but they
can be instantiated within the same class. In order to instantiate private classes inside
subclasses or inside any other independent class, the private super class should consider
sub class / independent class as friend.
- The subclass inheriting the private class is also created as private by default.
- By default, the subclass inheriting the private class cannot be created as explicit public
class / explicit protected class. This can be made possible if the super private class
considers subclass as friend.
Friend keyword:
In local classes “Friend” is a keyword used as part of class definition to consider another
class as friend.
In this case friend class should be forward declared by using “Deferred” keyword. This
deferred keyword indicates that the class is defined somewhere else in the program and
not at the beginning of the program.
ABSTRACT CLASS:
Abstract is a class which contains one or more Abstract methods.
- We declare a method as abstract when we are not sure about the implementation.
- The implementation for the abstract methods can be provided as part of subclasses.
- If a class contains an abstract method, the class also should be declared as abstract.
- The subclass whichever is inheriting the abstract class must implement all the abstract
methods of the abstract super class otherwise the subclass also should be declared as
abstract.
- We cannot create the objects for abstract classes because they are not implemented
completely. But once abstract methods are implemented inside subclass, we can
instantiate the subclass and assign subclass object to abstract super class reference
which is called as narrow casting.
- Whenever narrow casting is done, by using super class object we can access methods of
super class only, in order to access direct methods of subclass using super class object,
we need to call the subclass method using dynamic calling approach.
INTERFACES
- An interface is a pure abstract class i.e. by default all the methods of interface are
abstract.
- Interface components doesn’t contain any explicit visibility section, by default all the
components are public.
- The class which ever implements the interface is called as implementation class.
- If a class implements any interface and if that implemented interface contains any
included interfaces, then class must also implement all the methods of the included
interfaces.
- If a global class has to implement one or more global interfaces, then global class must
declare those interfaces in the interfaces tab.
Aliases
Aliases are the alternative names provided for interface components .i.e. whenever we
refer to the interface components outside the interface, it must be prefixed with the
name of the interface. This lengthy naming representation can be avoided by declaring
“aliases” for interface components.
- Aliases can be declared in any of the visibility sections inside implementation class
- If the aliases as to be declared in the interface it can be declared only for included
interfaces components and that alias will be created as component of interface.
Note: The included interfaces can be referred directly in the implementation class .i.e.
the interface which is included in other interface can be directly referred in the
implementation class.
Note: As Part of global classes, If a global class Includes any interface in the interfaces
tab and the checkbox ‘final’ is selected, it indicates that these interface methods cannot
be further implemented (re-defined) in other classes.
Example: Instance Vs Static Attributes
REPORT Z730OOPS1.
lcl_abc=>y = 20.
method set.
* empno = 4. "(or)
me->empno = 4.
* ename = 'Ravi'. "(or)
me->ename = 'Ravi'.
endmethod.
endclass.
uline.
data ob2 type ref to lcl_emp.
create object ob2.
write :/ 'Values of object ob2...'.
call method ob2->display.
Example: Calling a Protected method from a Public Method
REPORT Z730OOPS3.
method set.
empno = 4.
ename = 'Ravi'.
* call method ob1->display. "syntax error
* call method display. "(or)
call method me->display.
endmethod.
endclass.
REPORT Z730OOPS4.
method set.
empno = i_empno.
ename = i_ename.
call method display.
endmethod.
endclass.
uline.
call method ob1->set
EXPORTING
i_empno = p_empno
i_ename = p_ename.
uline.
ob1->set( EXPORTING i_empno = p_empno i_ename = p_ename ).
uline.
ob1->set( i_empno = p_empno i_ename = p_ename ).
REPORT Z730OOPS5.
class lcl_customer DEFINITION.
PUBLIC SECTION.
methods getcustomer IMPORTING i_kunnr type kna1-kunnr
exporting e_name1 type kna1-name1
e_ort01 type kna1-ort01.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_customer.
create object ob.
format color 3.
write :/ 'Customer name :',v_name1,
/ 'Customer city :',v_ort01.
format color off.
uline.
call method ob->getcustomer
EXPORTING
i_kunnr = p_kunnr
IMPORTING
e_name1 = v_name1.
format color 7.
write :/ 'Customer name :',v_name1,
/ 'Customer city :',v_ort01.
format color off.
uline.
call method ob->getcustomer
EXPORTING
i_kunnr = p_kunnr
IMPORTING
e_name1 = v_name1
e_ort01 = v_ort01.
format color 1.
write :/ 'Customer name :',v_name1,
/ 'Customer city :',v_ort01.
format color off.
uline.
clear : v_name1,
v_ort01.
ob->getcustomer( EXPORTING i_kunnr = '0000001001'
IMPORTING e_name1 = v_name1
e_ort01 = v_ort01 ).
format color 1.
write :/ 'Customer name :',v_name1,
/ 'Customer city :',v_ort01.
format color off.
REPORT Z730OOPS6.
method m2.
format color 7.
write :/ 'inside static method m2...'.
data v_k1 type k.
write :/ y,z,v_k1.
format color off.
endmethod.
endclass.
START-OF-SELECTION.
* call method lcl_abc=>m1. "syntax error
call method lcl_abc=>m2.
REPORT Z730OOPS7.
clear v_name1.
call method ob->getcustomer
EXPORTING
i_kunnr = p_kunnr
RECEIVING
e_name1 = v_name1.
uline.
clear v_name1.
v_name1 = ob->getcustomer( EXPORTING i_kunnr = p_kunnr ).
write :/ 'Customer name :',v_name1.
REPORT Z730OOPS8.
method m1.
write :/ 'Inside public method m1 of lcl_abc...'.
endmethod.
method m2.
write :/ 'Inside protected method m2 of lcl_abc...'.
endmethod.
method m3.
write :/ 'Inside private method m3 of lcl_abc...'.
endmethod.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_pqr.
create object ob.
Because of above data declaration, SAP creates instance attribute in the attributes tab
Methods:
Parameters for method ‘Getsalesorders’
Implementation of methods (Double click on each method):
method GETSALESORDERS.
refresh t_vbak.
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where kunnr = i_kunnr.
if sy-subrc eq 0.
call method display.
else.
message 'No Sales Orders for given customer' type 'I'.
endif.
endmethod.
method DISPLAY.
data wa_vbak type ty_vbak.
loop at t_vbak into wa_vbak.
write :/ wa_vbak-vbeln,
wa_vbak-erdat,
wa_vbak-erzet,
wa_vbak-ernam.
endloop.
endmethod.
REPORT Z730OOPS9.
method M1.
write :/ 'inside static method ...'.
x = 10.
write :/ x.
endmethod.
Executable Program:
REPORT Z730OOPS10.
write :/ z730class2=>x.
call method z730class2=>m1.
Class 1:
Implementations:
method M1.
write :/ 'inside instance public method m1 of class3...'.
endmethod.
method M2.
write :/ 'inside instance protected method m2 of class3...'.
endmethod.
method M3.
write :/ 'inside instance private method m3 of class3...'.
endmethod.
Class 2:
Activate class 2 and go back to class 1 for adding this class 2 as friend to class 1
Save, activate class 3
method M4.
write :/ 'inside instance public method m4 of class4...'.
data ob type ref to z739class3.
create object ob.
call method ob->m1.
call method ob->m2.
call method ob->m3.
endmethod.
Executable program:
REPORT Z730OOPS11.
REPORT Z730OOPS12.
method constructor.
empno = 4.
ename = 'Ravi'.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_emp.
create object ob1.
REPORT Z730OOPS13.
class lcl_emp DEFINITION.
PUBLIC SECTION.
methods display.
methods constructor IMPORTING i_empno type i i_ename type c. "instance constructor
PROTECTED SECTION.
data : empno type i,
ename(20) type c.
endclass.
method constructor.
empno = i_empno.
ename = i_ename.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_emp.
*create object ob1. "syntax error as mandatory parameter values are not passed
REPORT Z730OOPS14.
method constructor.
write :/ 'Inside instance constructor...'.
endmethod.
method class_constructor.
write :/ 'Inside static constructor...'.
endmethod.
endclass.
START-OF-SELECTION.
*lcl_abc=>x = 10. "static const.gets executed
format color 3.
write :/ 'First object ob1...'.
data ob1 type ref to lcl_abc.
create object ob1.
uline.
format color 7.
write :/ 'Second object ob2...'.
data ob2 type ref to lcl_abc.
create object ob2.
uline.
format color 1.
write :/ 'Third object ob3...'.
data ob3 type ref to lcl_abc.
create object ob3.
REPORT Z730OOPS15.
START-OF-SELECTION.
data ob1 type ref to lcl_cycle.
create object ob1.
format color 3.
call method : ob1->setcycle,
ob1->display.
uline.
format color 7.
data ob2 type ref to lcl_bike.
create object ob2.
method DISPLAY.
write :/ wheels,brakes.
endmethod.
method SETCYCLE.
wheels = 2.
brakes = 2.
color = 'Green'.
write :/ 'Color of cycle is ',color.
endmethod.
method SETBIKE.
wheels = 2.
brakes = 1.
color = 'Red'.
gears = 5.
write :/ 'color of bike :',color,
/ 'Gears in bike :',gears.
endmethod.
REPORT Z730OOPS16.
format color 3.
call method : ob1->setcycle,
ob1->display.
uline.
format color 7.
data ob2 type ref to zcl_bike.
create object ob2.
REPORT Z730OOPS17.
REPORT Z730OOPS18.
method m2.
write :/ 'inside instance final method m2 of super class abc...'.
endmethod.
method m3.
write :/ 'inside static method m3 of super class abc...'.
endmethod.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_xyz.
create object ob.
method M1.
write :/ 'inside instance method m1 of super class abc...'.
endmethod.
method M2.
write :/ 'inside instance final method m2 of super class abc...'.
endmethod.
method M3.
write :/ 'inside static method m3 of super class abc...'.
endmethod.
endmethod.
Executable Program:
REPORT Z730OOPS19.
REPORT Z730OOPS20.
method class_constructor.
write :/ 'inside static const. of super class...'.
ENDMETHOD.
endclass.
endclass.
START-OF-SELECTION.
*format color 2.
*write :/ 'First object of super class...'.
*data ob type ref to lcl_super.
*create object ob.
format color 3.
write :/ 'First object of sub class...'.
data ob1 type ref to lcl_sub.
create object ob1.
uline.
format color 7.
write :/ 'Second object of sub class...'.
data ob2 type ref to lcl_sub.
create object ob2.
uline.
format color 1.
write :/ 'Third object of sub class...'.
data ob3 type ref to lcl_sub.
create object ob3.
REPORT Z730OOPS21.
method class_constructor.
write :/ 'inside static const. of super class...'.
ENDMETHOD.
endclass.
START-OF-SELECTION.
*format color 2.
*write :/ 'First object of super class...'.
*data ob type ref to lcl_super.
*create object ob.
format color 3.
write :/ 'First object of sub class...'.
data ob1 type ref to lcl_sub.
create object ob1.
uline.
format color 7.
write :/ 'Second object of sub class...'.
data ob2 type ref to lcl_sub.
create object ob2.
uline.
format color 1.
write :/ 'Third object of sub class...'.
data ob3 type ref to lcl_sub.
create object ob3.
REPORT Z730OOPS22.
method class_constructor.
write :/ 'inside static const. of super class...'.
ENDMETHOD.
endclass.
method constructor.
write :/ 'inside instance const. of sub class...'.
call method super->constructor.
ENDMETHOD.
method class_constructor.
write :/ 'inside static const. of sub class...'.
endmethod.
endclass.
START-OF-SELECTION.
*format color 2.
*write :/ 'First object of super class...'.
*data ob type ref to lcl_super.
*create object ob.
format color 3.
write :/ 'First object of sub class...'.
data ob1 type ref to lcl_sub.
create object ob1.
uline.
format color 7.
write :/ 'Second object of sub class...'.
data ob2 type ref to lcl_sub.
create object ob2.
uline.
format color 1.
write :/ 'Third object of sub class...'.
data ob3 type ref to lcl_sub.
create object ob3.
REPORT Z730OOPS23.
endclass.
method constructor.
write :/ 'inside instance const. of sub class...'.
write :/ 'Parameter received for sub class instance const is ',x.
* call method super->constructor. "syntax error
call method super->constructor
exporting
x = 10.
ENDMETHOD.
endclass.
START-OF-SELECTION.
format color 3.
write :/ 'First object of sub class...'.
data ob1 type ref to lcl_sub.
*create object ob1. "syntax error
create object ob1
EXPORTING
x = 'ABAP'.
endclass.
endclass.
START-OF-SELECTION.
PARAMETERS p_x type i.
format color 3.
write :/ 'First object of sub class...'.
data ob1 type ref to lcl_sub.
create object ob1
EXPORTING
x = p_x.
REPORT Z730OOPS25.
method calc_disc.
totalfees = ( i_fees - i_fees * 5 / 100 ).
endmethod.
method display_fees.
write :/ 'Total Fees after discount :',totalfees.
ENDMETHOD.
endclass.
method calc_disc.
totalfees = ( i_fees - i_fees * 10 / 100 ).
ENDMETHOD.
endclass.
method calc_disc.
totalfees = ( i_fees - i_fees * 15 / 100 ).
ENDMETHOD.
endclass.
data ob type ref to lcl_enquiry.
START-OF-SELECTION.
PARAMETERS : p_fees type i,
p_no_enq type i.
if p_no_enq > 0.
case p_no_enq.
when 1.
create object ob type lcl_enquiry.
call method ob->calc_disc
exporting
i_fees = p_fees.
when 2 or 3.
create object ob type lcl_enquiry_r.
call method ob->calc_disc
exporting
i_fees = p_fees.
when others.
create object ob type lcl_enquiry_v.
call method ob->calc_disc
exporting
i_fees = p_fees.
endcase.
call method ob->display_fees.
else.
message 'Please enter Positive values for no.of enquiries' type 'I'.
endif.
REPORT Z730OOPS26.
START-OF-SELECTION.
data ob type ref to lcl_abc.
create object ob.
REPORT Z730OOPS27.
START-OF-SELECTION.
data ob type ref to lcl_abc.
*create object ob. "syntax error
*
data ob1 type ref to lcl_pqr.
*create object ob1. "syntax error
REPORT Z730OOPS28.
*class lcl_mnr2 DEFINITION create public INHERITING FROM lcl_abc. "syntax error
*endclass.
*class lcl_mnr3 DEFINITION create protected INHERITING FROM lcl_abc. "syntax error
*endclass.
*
*START-OF-SELECTION.
data ob type ref to lcl_abc.
*create object ob. "syntax error
**
*data ob1 type ref to lcl_pqr.
**create object ob1. "syntax error
REPORT Z730OOPS29.
method display.
write :/ tableno,steward.
endmethod.
endclass.
method m1.
write :/ 'inside method m1 of cheque class..'.
endmethod.
endclass.
START-OF-SELECTION.
data r type ref to lcl_restaurant.
*create object r. "syntax error
format color 3.
write :/ 'Cheque class object ....'.
data cq type ref to lcl_cheque.
create object cq.
uline.
format color 7.
write :/ 'Cheque class object --> Abstract class restaurant reference..'.
r = cq. "narrow casting
call method : r->store,
r->display,
r->payment,
* r->m1. "syntax error
r->('M1'). "dynamic call
uline.
format color 3.
write :/ 'Credit card class object ....'.
data cc type ref to lcl_creditcard.
create object cc.
method STORE.
tableno = 1.
steward = 'ABC'.
endmethod.
method DISPLAY.
write :/ tableno,steward.
endmethod.
method PAYMENT.
chequeno = 123.
chequedate = sy-datum.
bankname = 'RBS'.
amt = 12000.
endmethod.
method DISPLAY.
CALL METHOD SUPER->DISPLAY.
write :/ chequeno,chequedate,bankname,amt.
endmethod.
method PAYMENT.
ccno = 32123.
bname = 'ICICI'.
amt = 11000.
endmethod.
method DISPLAY.
CALL METHOD SUPER->DISPLAY.
write :/ ccno,bname,amt.
endmethod.
Executable Program:
REPORT Z730OOPS30.
format color 3.
write :/ 'Cheque class object ....'.
data cq type ref to zcl_cheque.
create object cq.
uline.
format color 7.
write :/ 'Cheque class object --> Abstract class restaurant reference..'.
r = cq. "narrow casting
call method : r->store,
r->payment,
r->display.
uline.
format color 3.
write :/ 'Credit card class object ....'.
data cc type ref to zcl_creditcard.
create object cc.
REPORT Z730OOPS31.
interface rectangle.
constants : length type i value 10,
breadth type i value 5.
methods : area,
perimeter.
endinterface.
interface square.
constants side type i value 10.
methods : area,
perimeter.
endinterface.
method rectangle~perimeter.
clear res.
res = 2 * ( rectangle~length + rectangle~breadth ).
write :/ 'Perimeter of rectangle is ',res.
endmethod.
method square~area.
clear res.
res = square~side * square~side.
write :/ 'Area of square is ',res.
endmethod.
method square~perimeter.
clear res.
res = 4 * square~side.
write :/ 'Perimeter of square is ',res.
endmethod.
endclass.
START-OF-SELECTION.
uline.
data r type ref to rectangle.
*create object r. "syntax error
r = ob. "narrow casting
call method : r->area,
r->perimeter.
uline.
data s type ref to square.
*create object s. "syntax error
s = ob. "narrow casting
call method : s->area,
s->perimeter.
Interface 1: ZIF_RECTANGLE
Interface 2: ZIF_SQUARE
Implementation class: Implementing above 2 interfaces
Implementations for interface methods:
method ZIF_RECTANGLE~AREA.
clear res.
res = zif_rectangle~length * zif_rectangle~breadth.
write :/ 'Area of rectangle is ',res.
endmethod.
method ZIF_RECTANGLE~PERIMETER.
clear res.
res = 2 * ( zif_rectangle~length + zif_rectangle~breadth ).
write :/ 'Perimeter of rectangle is ',res.
endmethod.
method ZIF_SQUARE~AREA.
clear res.
res = zif_square~side * zif_square~side.
write :/ 'Area of square is ',res.
endmethod.
method ZIF_SQUARE~PERIMETER.
clear res.
res = 4 * zif_square~side.
write :/ 'Perimeter of square is ',res.
endmethod.
REPORT Z730OOPS32.
uline.
data r type ref to zif_rectangle.
*create object r. "syntax error
r = ob. "narrow casting
call method : r->area,
r->perimeter.
uline.
data s type ref to zif_square.
*create object s. "syntax error
s = ob. "narrow casting
call method : s->area,
s->perimeter.
REPORT Z730OOPS33.
interface abc.
methods : m1,
m2,
m3.
endinterface.
class lcl_impl1 DEFINITION ABSTRACT.
public SECTION.
interfaces abc ABSTRACT METHODS m2 m3.
endclass.
method abc~m3.
write :/ 'Inside interface method m3 of implementation class impl2....'.
ENDMETHOD.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_impl2.
create object ob.
REPORT Z730OOPS34.
interface intf1.
methods : m1,
m2.
endinterface.
interface intf2.
methods m3.
interfaces intf1.
endinterface.
method intf1~m1.
write :/ 'inside method m1 of interface intf1...'.
endmethod.
method intf1~m2.
write :/ 'inside method m2 of interface intf1...'.
endmethod.
endclass.
START-OF-SELECTION.
data ob type REF TO lcl_impl.
create object ob.
REPORT Z730OOPS35.
interface intf1.
methods : m1,
m2.
ENDINTERFACE.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_impl.
create object ob.
uline.
call method ob->a1.
*call method ob->a2. "syntax error
Global Interface:
Global Implementation class implementing above interface:
Executable Program: Accessing above Global aliases
REPORT Z730OOPS36.
method m2.
write :/ 'inside instance normal method m2-about to raise event'.
raise event e1.
endmethod.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_abc.
create object ob.
REPORT Z730OOPS38.
START-OF-SELECTION.
data ob type ref to lcl_abc.
create object ob.
REPORT Z730OOPS39.
method m2.
write :/ 'inside instance normal method m2-about to raise event'.
raise event e1.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_abc.
create object ob1.
data ob2 type ref to lcl_abc.
create object ob2.
REPORT Z730OOPS40.
method m2.
write :/ 'inside instance normal method m2-about to raise event'.
raise event e1.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_abc.
create object ob1.
REPORT Z730OOPS41.
class lcl_abc DEFINITION.
public SECTION.
events e1. "instance event declaration
methods : m1 for event e1 of lcl_abc, "instance event handler method
m2. "normal instance method
endclass.
method m2.
write :/ 'inside instance normal method m2-about to raise event'.
set handler me->m1 for me.
raise event e1.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_abc.
create object ob1.
REPORT Z730OOPS42.
method m2.
write :/ 'inside instance normal method m2-about to raise event'.
raise event e1.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_abc.
create object ob1.
REPORT Z730OOPS43.
method m1.
format color 3.
write :/ 'inside instance event handler method m1 of class lcl_eventreceiver1...'.
endmethod.
method m2.
write :/ 'inside static event handler method m2 of class lcl_eventreceiver1...'.
endmethod.
method m3.
write :/ 'inside instance normal method m3 of class lcl_eventreceiver1..about to raise event..'
..
raise event e1.
endmethod.
endclass.
method m4.
write :/ 'inside instance event handler method m4 of class lcl_eventreceiver2...'.
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_eventreceiver1.
create object ob1.
REPORT Z730OOPS44.
method handle_e1.
format color 7.
select vbeln ernam netwr
from vbak
into table t_sales
where kunnr = e_kunnr.
if sy-subrc eq 0.
write :/ 'No of sales orders :',sy-dbcnt.
call method display_salesorders.
else.
message 'No Sales orders for given customer' type 'I'.
endif.
endmethod.
method raise_e1.
format color 3.
write :/ 'Inside Normal method ..about to raise event e1..'.
raise event e1
EXPORTING
* e_kunnr = '0000001010'.
e_kunnr = i_kunnr.
endmethod.
method display_salesorders.
format color 2.
data wa_sales type ty_sales.
loop at t_sales into wa_sales.
write :/ wa_sales-vbeln,
wa_sales-ernam,
wa_sales-netwr.
endloop.
endmethod.
endclass.
START-OF-SELECTION.
method RAISE_E1.
format color 3.
write :/ 'Inside Normal method ..about to raise event e1..'.
raise event e1
EXPORTING
* e_kunnr = '0000001010'.
e_kunnr = i_kunnr.
endmethod.
method DISPLAY_SALESORDERS.
format color 2.
data wa_sales type ty_sales.
loop at t_sales into wa_sales.
write :/ wa_sales-vbeln,
wa_sales-ernam,
wa_sales-netwr.
endloop.
endmethod.
Executable program:
REPORT Z730OOPS45.
REPORT Z730OOPS46.
method m2.
uline.
write :/ 'Inside instance event handler method m2'.
endmethod.
method m3.
write :/ 'Inside instance normal method m3-raising events e1 and e2'.
raise event e1.
raise event e2.
endmethod.
method m4.
write :/ 'Inside static normal method m4'.
* raise event e2. "valid
* raise event e1. "invalid
endmethod.
endclass.
START-OF-SELECTION.
data ob1 type ref to lcl_eventreceiver.
create object ob1.
REPORT Z730OOPS47.
interface intf1.
events e1.
methods m1 for event e1 of intf1.
endinterface.
method m2.
write :/ 'inside interface event handler method m2 ..'.
endmethod.
method m3.
write :/ 'inside normal method m3..'.
raise event intf1~e1.
endmethod.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_abc.
create object ob.
REPORT Z730OOPS48.
START-OF-SELECTION.
PARAMETERS : p_x type i,
p_y type i.
format color 7.
write :/ 'Division is ',v_z.
write :/ 'End of program...'.
format color off.
Example: Capturing Standard Exception Messages
REPORT Z730OOPS49.
START-OF-SELECTION.
PARAMETERS : p_x type i,
p_y type i.
format color 7.
write :/ 'Division is ',v_z.
write :/ 'End of program...'.
format color off.
REPORT Z730OOPS50.
START-OF-SELECTION.
try.
call method ob->m1
EXPORTING
i_x = p_x
i_y = p_y
IMPORTING
e_z = v_z.
catch cx_sy_zerodivide.
format color 3.
write :/ 'Inside catch block...'.
write :/ 'Cannot divide by zero...'.
endtry.
format color 7.
write :/ 'Division is ',v_z.
format color off.
uline.
uline.
data k type ref to cx_sy_zerodivide.
try.
call method ob->m1
EXPORTING
i_x = p_x
i_y = p_y
IMPORTING
e_z = v_z.
catch cx_sy_zerodivide into k.
format color 3.
CALL METHOD K->IF_MESSAGE~GET_TEXT
RECEIVING
RESULT = v_str.
REPORT Z730OOPS52.
START-OF-SELECTION.
PARAMETERS : p_x type i,
p_y type i.
format color 7.
write :/ 'Division is ',v_z.
write :/ 'End of program...'.
format color off.
Example: Custom Exception class Referring to OTR
Create Exception ids id1 and id2 in texts tab
Attributes id1 and id2 gets created automatically:
Associate exception messages for id1(short and long) and id2 (only short)
Activate the exception class:
Executable program:
REPORT Z730OOPS53.
clear v_str.
endtry.
format color off.
uline.
try.
format color 7.
RAISE EXCEPTION TYPE ZCX_MYEXCEPTIONS
EXPORTING
TEXTID = zcx_myexceptions=>id2.
clear v_str.
endtry.
REPORT Z730OOPS54.
clear v_str.
endtry.
format color off.
uline.
try.
format color 7.
RAISE EXCEPTION TYPE ZCX_MYEXCEPTIONS_MSGCLASS
EXPORTING
TEXTID = zcx_myexceptions_msgclass=>id2
ATTR1 = 'Gensoft Technologies'
ATTR2 = 'SAP Technical Training'
ATTR3 = 'Ameerpt'
ATTR4 = 'ABAP HANA'.
catch zcx_myexceptions_msgclass into ob.
clear v_str.
CALL METHOD OB->IF_MESSAGE~GET_TEXT
RECEIVING
RESULT = v_str.
clear v_str.
endtry.
Example: User defined exceptions in Local classes
REPORT Z730OOPS55.
START-OF-SELECTION.
data ob type ref to lcl_abc.
create object ob.
if sy-subrc eq 0.
write :/ 'Division is ',v_z.
elseif sy-subrc eq 1.
write :/ 'Cannot divide by zero'.
elseif sy-subrc eq 2.
write :/ 'Unknown error'.
endif.
method M1.
if i_y eq 0.
raise myexception.
else.
e_z = i_x / i_y.
endif.
endmethod.
Executable program:
REPORT Z730OOPS56.
if sy-subrc eq 0.
write :/ 'Division is ',v_z.
elseif sy-subrc eq 13.
write :/ 'Cannot divide by zero'.
elseif sy-subrc eq 21.
write :/ 'Unknown error'.
endif.
REPORT Z730OOPS57.
endclass.
START-OF-SELECTION.
data ob type ref to lcl_abc.
create object ob.
Example: Macros
REPORT Z730OOPS58.
define abc.
&3 = &1 + &2.
&4 = &1 - &2.
&5 = &1 * &2.
end-OF-DEFINITION.
uline.
abc 20 10 v_r1 v_r2 v_r3.
write :/ v_r1,v_r2,v_r3.
Event Handling in Classes
- As part of class there are many events provided by SAP which can be used in ALV
reporting, Webdynpro, UI5, workflow etc. which are called as standard events and they
exist as part of STD.classes.
- These custom events are declared, raised and handled by developer itself.
- The events and the event handler methods can belong to same class or different class.
- As part of this event handler method we need to implement the business logic for the
event.
- Whenever an event is raised, SAP will execute all the event handler methods one after
the other by using registered handlers.
- The handler can be object in case of instance event handler method or a object/class
name in case of static event handler methods.
- The sequence of execution of event handler methods depends upon the sequence of
handler registrations.
- Event can contain only exporting parameters which can be imported by Event Handler
Method.
- Event parameters are always exported by value, the parameter Name in the event and
in the event handler method must be same.
- Whenever we deal with custom events in custom classes, we need to have minimum 2
methods. One method for raising the event and the other method for handling the
event.
- Static Event.
Syntax:
Syntax:
Syntax:
Statements---
Endmethod.
Syntax:
Syntax 1:
Syntax 2:
Syntax 3:
Note:
1. Event handler method should not be called explicitly; they are automatically called
whenever the event is raised.
2. If the event is raised and there is no handler registration, SAP will not execute the event
handler methods. Handler will instruct SAP using what objects or class name the
event handler method should be executed.
3. The handler registration should be made before raising the events .i.e. SAP should know
with what handler it has to execute event handler method whenever event is raised.
4. For all instances, while registering the handler for instance events we must specify the
object name as part of “FOR” keyword in the “set handler statements”. This
indicates that, this object which is responsible for raising the events. If all the objects
of the class as to be registered there should be a separate “set handler” for each
object. Instead for registering each object separately we can use “for all instances”
statements as part of set handler.
6. If an event contains any mandatory export parameters then those parameter values
must be exported at the time of raising the event, if the parameters are declared as
optional, then we need not export the values. These exported parameters can be
imported by event handler methods based on which we can implement the business
logic. Event parameters are always passed by value.
Scenario 1: In this, event ‘E1’ is raised in the method ‘M2’, but Method ‘M1’ will not be
executed because SAP Doesn’t know by using what handler(object/class) it should call the
event handler method ‘M1’.
Scenario 2: In this, event ‘E1’ is raised in the method ‘M2’, but Method ‘M1’ will not be
executed because SAP doesn’t know about the handler (object/class) at the time of raising the
event. I.e.in this case handler is registered after raising the event.
Scenario 3: In this, event ‘E1’ is raised in the method ‘M2’ by the object OB1, and we also
registered the handler, but the event handler method ‘M1’ will not be executed by SAP,
because we have registered the object OB2 as part of ‘for statement’ in ‘set handler statement’,
but the event is actually raised by the object OB1.
Scenario 4 and Scenario 5: In this, event ‘E1’ is raised in the method ‘M2’ and then the event
handler method ‘M1’ will be executed by SAP by using registered handler ‘OB’ (in case if the
handler is registered outside – Scenario 4 ) (or) ‘ME’ (in case if the handler is registered with in
the method ‘m2’ implementation – Scenario 5).
Scenario 6: In this, event ‘E1’ is raised in the method ‘M2’ three times, first using the object
‘OB1’ and then using the object ‘OB2’ and then using OB3. In all these cases, SAP executes
event handler method ‘M1’ as we have registered all the objects of the class at a time by using
the addition ‘FOR ALL INSTANCES’ as part of set handler statement.
Scenario 7: In this, whenever event ‘E1’ is raised in the method ‘M3’, SAP executes event
handler methods ‘M1’, ‘M2’, of ‘LCL_EVENTRECEIVER1’ class and also method ‘M4’ of
‘LCL_EVENTRECEIVER2’ class. Here ‘M2’ method is static, so handler can be either object / class.
The sequence of execution of event handler methods depends on sequence of handler
registrations. It is also understood that event and the event handler methods can be part of
same class / different class. In case of STD. events, event belongs to STD. class and then the
event handler method should be declared and implemented as part of Custom class.
Scenario 8: Event can contain only exporting parameters which can be imported by Event
Handler Method. Event parameters are always exported by value, the parameter Name in the
event and in the event handler method must be same. If an event contains any mandatory
export parameters then those parameter values must be exported at the time of raising the
event. If the parameters are declared as optional, then we need not export the values. These
exported parameters can be imported by event handler methods based on which we can
implement the business logic. In this case, we exported the customer no (e_kunnr) while raising
the event ‘E1’ in the method ‘RAISE_E1’. This parameter is imported in one of the event handler
method ‘’HANDLE_E1’ based on which we retrieved the sales orders of the customer.
Scenario 9: Instance events can be raised only in Instance methods whereas Static events can
be raised either in Instance / Static methods. Since static events are not specific to any object,
there should not be any object registration at the time of registering the handlers. I.e. In this
case, Objects Ob1 and Ob2 are raising the static event ‘E1’ in the method m3, but none of the
objects are registered.
Note: We can also declare events as part of interfaces
- Exception handling is a process of handling the Runtime Error’s and continue the
program execution without termination.
- The exceptions which are raised by SAP are called as Standard Exceptions.
- These standard exceptions are raised from standard exception classes which start with
Naming convention “CX___”.
- Inside the “TRY” Block we need to keep those statements where the possible exceptions
might be raised.
- The ‘CATCH’ block is placed immediately after the Try Block; it is responsible for
handling the exceptions by providing appropriate exception handling statements which
can be system defined exception message / user-defined exception message.
- “CX_ROOT” is common for any exceptions i.e it is super class for all exception classes.
- As part of the catch block we need to provide the exception class name which is
responsible for raising the exception.
- If we are not sure about the exception class, we can give the exception class name as
“CX_ROOT”.
Note:
Whenever an exception is raised in a “TRY” block, SAP creates the object of the exception
class which is raising the exception and the control will jump to catch block.
As part of catch block, we need to receive the exception class object into our local reference
of exception class and using this referenced object we can access the appropriate methods
of Exception class to capture standard exception messages.
Whenever an exception is raised in try block, SAP ignores the rest of the statements in the
try block and the control will jump to catch block.
Standard Exceptions:
Cleanup block:
Cleanup block is provided as part of try block to execute certain statements mandatorily
whenever an exception is raised in the try block. In general, whenever an exception is raised
in the try block, the control jumps to catch block ignoring the rest of the statements in the
try block. In these cases, there might be certain statements which we need to execute
whenever an exception is raised, these statements we can provide as part of cleanup block.
If a try block contains cleanup block, we cannot have catch block, so in order to handle the
exception, catch block should be provided as part of outer try block. As part of cleanup
block, we can perform cleanup activities. i.e clearing the variables, free internal tables, close
the files…….
We should not abruptly terminate the execution of cleanup block using the statements
stop, submit and call transaction statements.
Procedure
3. Handle the exception while calling the method by checking the sy-subrc status.
Note: We can use ‘raise’ keyword to raise any exceptions i.e system defined or user-defined.
Raising keyword:
Raising is a keyword used as part of local class method declaration to indicate that a
method might raise the exception but cannot handle the exception.
In these cases, the caller of the method should take the responsibility of handling the
exception.
The advantage of this approach is since a method can be called any no. of times at different
places in the object, at each place, we can handle the exception in different way (custom
defined exception messages in one place, std.exception messages in another place..)
We create custom exception classes to store the repository of custom exception messages
Global custom exception classes starts with ‘ZCX_....’ / ‘YCX_....’ and it must be subclass of
‘CX_STATIC_CHECK’ / ‘CX_DYNAMIC_CHECK’ / ‘CX_NO_CHECK’.
Whenever exception id is created, SAP creates corresponding constant attribute with the same
name. This attribute needs to be accessed while raising the exception from these exception
classes.
Each Exception id must be associated either with OTR Text / with message of a message class.
In case of Exception classes using OTR, each exception id that we create must be associated
with short text / long text / both.
In case of Exception classes using message class, each exception id that we create must be
associated with message id of a message class which can be static / dynamic message.
In case of Dynamic message, we need to create corresponding attributes for mapping to the
place holder of dynamic message.
The values for these attributes associated with placeholders should be passed at the time of
raising the exception.
Note: A Try block can be associated with ‘n’ of catch blocks, but the catch block exception
classes should be in the ascending order of exception classes i.e from sub class to super classes.
Example: ALV Reporting using classes (ABORT ERROR - Field Catalog Not Found)
REPORT Z730ALV1.
*tables vbak.
*SELECT-OPTIONS so_vbeln for vbak-vbeln.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
Flowlogic:
------
-----
Example: ALV Reporting using classes (Field Catalog information provided by considering
parameter ‘I_STRUCTURE_NAME’ as part of method ‘SET_TABLE_FOR_FIRST_DISPLAY’)
REPORT Z730ALV2.
START-OF-SELECTION.
call screen 100.
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
* I_STRUCTURE_NAME = 'VBAK' "runtime error
I_STRUCTURE_NAME = 'ZCVBAK'
CHANGING
IT_OUTTAB = t_sales.
Flowlogic:
Note: In the above example ‘ZCVBAK’ is the dictionary structure which needs to be created
Example: ALV Reporting using classes (Field Catalog information generated using the function
module ‘LVC_FIELDCATALOG_MERGE’, Modifying Field catalog)
REPORT Z730ALV3.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZCVBAK'
CHANGING
CT_FIELDCAT = t_fcat.
REPORT Z730ALV4.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam netwr
from vbak
into table t_temp_sales
where vbeln in so_vbeln.
if sy-subrc eq 0.
* append lines of t_temp_sales to t_final_sales.
loop at t_temp_sales into wa_temp_sales.
clear wa_final_sales.
wa_final_sales-vbeln = wa_temp_sales-vbeln.
wa_final_sales-erdat = wa_temp_sales-erdat.
wa_final_sales-erzet = wa_temp_sales-erzet.
wa_final_sales-ernam = wa_temp_sales-ernam.
wa_final_sales-netwr = wa_temp_sales-netwr.
append wa_final_sales to t_final_sales.
endloop.
endif.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_final_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person'.
wa_fcat-outputlen = 30.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM ROWCOLORING .
loop at t_final_sales ASSIGNING <wa_final>.
if <wa_final>-erdat = '19970121'.
<wa_final>-rowcolor = 'C510'.
elseif <wa_final>-erdat = '19970122'.
<wa_final>-rowcolor = 'C310'.
elseif <wa_final>-erdat = '19970123'.
<wa_final>-rowcolor = 'C710'.
else.
<wa_final>-rowcolor = 'C210'.
endif.
endloop.
ENDFORM. " ROWCOLORING
FORM LAYOUT .
clear wa_layo.
wa_layo-info_fname = 'ROWCOLOR'. "row coloring
ENDFORM. " LAYOUT
REPORT Z730ALV7.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam netwr
from vbak
into table t_temp_sales
where vbeln in so_vbeln.
if sy-subrc eq 0.
* append lines of t_temp_sales to t_final_sales.
loop at t_temp_sales into wa_temp_sales.
clear wa_final_sales.
wa_final_sales-vbeln = wa_temp_sales-vbeln.
wa_final_sales-erdat = wa_temp_sales-erdat.
wa_final_sales-erzet = wa_temp_sales-erzet.
wa_final_sales-ernam = wa_temp_sales-ernam.
wa_final_sales-netwr = wa_temp_sales-netwr.
append wa_final_sales to t_final_sales.
endloop.
endif.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_final_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person'.
wa_fcat-outputlen = 30.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM LAYOUT .
clear wa_layo.
wa_layo-ctab_fname = 'CELLCOLOR'. "cell coloring
ENDFORM. " LAYOUT
FORM CELLCOLORING .
loop at t_final_sales assigning <wa_final>.
if <wa_final>-netwr < 10000.
clear wa_cellcolor.
wa_cellcolor-fname = 'VBELN'.
wa_cellcolor-color-col = 3.
wa_cellcolor-color-int = 1.
wa_cellcolor-color-inv = 0.
append wa_cellcolor to <wa_final>-cellcolor.
elseif <wa_final>-netwr >= 10000 and
<wa_final>-netwr < 20000.
clear wa_cellcolor.
wa_cellcolor-fname = 'VBELN'.
wa_cellcolor-color-col = 7.
wa_cellcolor-color-int = 1.
wa_cellcolor-color-inv = 0.
append wa_cellcolor to <wa_final>-cellcolor.
elseif <wa_final>-netwr > 20000 and
<wa_final>-netwr <= 40000.
clear wa_cellcolor.
wa_cellcolor-fname = 'VBELN'.
wa_cellcolor-color-col = 2.
wa_cellcolor-color-int = 1.
wa_cellcolor-color-inv = 0.
append wa_cellcolor to <wa_final>-cellcolor.
elseif <wa_final>-netwr > 40000.
clear wa_cellcolor.
wa_cellcolor-fname = 'VBELN'.
wa_cellcolor-color-col = 6.
wa_cellcolor-color-int = 1.
wa_cellcolor-color-inv = 0.
append wa_cellcolor to <wa_final>-cellcolor.
endif.
endloop.
ENDFORM. " CELLCOLORING
REPORT Z730ALV8.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam netwr
from vbak
into table t_temp_sales
where vbeln in so_vbeln.
if sy-subrc eq 0.
append lines of t_temp_sales to t_final_sales.
endif.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_final_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 13.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 13.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person'.
wa_fcat-outputlen = 25.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'LIGHTS'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Status'.
wa_fcat-outputlen = 7.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 6.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM LAYOUT .
clear wa_layo.
wa_layo-grid_title = 'Traffic Lights'.
wa_layo-excp_fname = 'LIGHTS'.
ENDFORM. " LAYOUT
FORM TRAFFICLIGHTS .
loop at t_final_sales ASSIGNING <wa_final>.
if <wa_final>-netwr < 10000.
<wa_final>-lights = '1'. "red color
elseif <wa_final>-netwr >= 10000 and <wa_final>-netwr <= 30000.
<wa_final>-lights = '2'. "yellow color
else.
<wa_final>-lights = '3'. "green color
endif.
endloop.
ENDFORM. " TRAFFICLIGHTS
Flowlogic:
REPORT Z730ALV9.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam netwr
from vbak
into table t_temp_sales
where vbeln in so_vbeln.
if sy-subrc eq 0.
append lines of t_temp_sales to t_final_sales.
endif.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_final_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 13.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 13.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person'.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'LIGHTS'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Status'.
wa_fcat-outputlen = 10.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 6.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM LAYOUT .
clear wa_layo.
wa_layo-grid_title = 'Traffic Lights'.
ENDFORM. " LAYOUT
FORM TRAFFICLIGHTS .
loop at t_final_sales ASSIGNING <wa_final>.
if <wa_final>-netwr < 10000.
<wa_final>-lights = '@0A@'. "red color
* <wa_final>-lights = '1'. "red color
CONCATENATE <wa_final>-lights 'Red' into <wa_final>-lights SEPARATED BY space.
elseif <wa_final>-netwr >= 10000 and <wa_final>-netwr <= 30000.
<wa_final>-lights = '@09@'. "yellow color
CONCATENATE <wa_final>-lights 'Yellow' into <wa_final>-lights SEPARATED BY space.
else.
<wa_final>-lights = '@08@'. "green color
CONCATENATE <wa_final>-lights 'Green' into <wa_final>-lights SEPARATED BY space.
endif.
endloop.
ENDFORM. " TRAFFICLIGHTS
Flowlogic:
FORM TREE .
* link tree control with container (o_cont1)
CREATE OBJECT O_TREE
EXPORTING
PARENT = o_cont1
NODE_SELECTION_MODE = cl_gui_simple_tree=>node_sel_mode_single.
* construct nodes
clear wa_nodes.
wa_nodes-node_key = 'RT'.
wa_nodes-isfolder = 'X'.
wa_nodes-expander = 'X'.
wa_nodes-text = 'Transactions'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'SO'.
wa_nodes-relatkey = 'RT'.
wa_nodes-isfolder = 'X'.
wa_nodes-expander = 'X'.
wa_nodes-text = 'Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CSO'.
wa_nodes-relatkey = 'SO'.
wa_nodes-n_image = '@15@'.
wa_nodes-text = 'Create Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CHSO'.
wa_nodes-relatkey = 'SO'.
wa_nodes-n_image = '@15@'.
wa_nodes-text = 'Change Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'DSO'.
wa_nodes-relatkey = 'SO'.
wa_nodes-n_image = '@15@'.
wa_nodes-text = 'Display Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'PO'.
wa_nodes-relatkey = 'RT'.
wa_nodes-isfolder = 'X'.
wa_nodes-expander = 'X'.
wa_nodes-text = 'Purchase Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CPO'.
wa_nodes-relatkey = 'PO'.
wa_nodes-n_image = '@16@'.
wa_nodes-text = 'Create Purchase Order'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CHPO'.
wa_nodes-relatkey = 'PO'.
wa_nodes-n_image = '@16@'.
wa_nodes-text = 'Change Purchase Order'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'DPO'.
wa_nodes-relatkey = 'PO'.
wa_nodes-n_image = '@16@'.
wa_nodes-text = 'Display Purchase Orders'.
append wa_nodes to t_nodes.
FORM PICTURE .
* link picture control with container (o_cont2)
CREATE OBJECT O_PIC
EXPORTING
PARENT = o_cont2.
Flowlogic:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
Example: Managing ALV Toolbar (Adding Custom Buttons, Enabling / disabling standard ALV
toolbar buttons)
REPORT Z730ALV11.
clear wa_button.
wa_button-butn_type = 3. "separator
append wa_button to e_object->mt_toolbar.
clear wa_button.
wa_button-function = 'F2'.
wa_button-icon = '@16@'.
wa_button-quickinfo = 'Navigate to Transactions'.
wa_button-butn_type = 2. "menu button
wa_button-text = 'Transactions'.
append wa_button to e_object->mt_toolbar.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_toolbar for o_grid.
ENDFORM. " REGHANDLERS
FORM LAYOUT .
clear wa_layo.
wa_layo-sel_mode = 'A'. "multiple selection
ENDFORM. " LAYOUT
REPORT Z730ALV12.
clear wa_button.
wa_button-butn_type = 3. "separator
append wa_button to e_object->mt_toolbar.
clear wa_button.
wa_button-function = 'F2'.
wa_button-icon = '@16@'.
wa_button-quickinfo = 'Navigate to Transactions'.
wa_button-butn_type = 2. "menu button
wa_button-text = 'Transactions'.
append wa_button to e_object->mt_toolbar.
endmethod.
method handle_menu_button.
* message 'menu button event' type 'I'.
case e_ucomm.
when 'F2'.
CALL METHOD E_OBJECT->ADD_FUNCTION
EXPORTING
FCODE = 'MI1'
TEXT = 'ABAP EDITOR'.
* add submenu
CALL METHOD E_OBJECT->ADD_SUBMENU
EXPORTING
MENU = ob
TEXT = 'Forms'.
endcase.
endmethod.
method handle_user_command.
case e_ucomm.
when 'F1'. "normal button function code
* message 'Normal button' type 'I'.
* get indexes of selected rows
data : t_rows type lvc_t_row,
wa_row type lvc_s_row.
CALL METHOD O_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = t_rows.
if t_rows is INITIAL .
message 'Please select atleast one row' type 'I'.
else.
refresh lt_sales.
loop at t_rows into wa_row.
clear wa_sales.
read table t_sales into wa_sales index wa_row-index
TRANSPORTING vbeln.
if sy-subrc eq 0.
append wa_sales to lt_sales.
endif.
endloop.
if lt_sales is not INITIAL.
* get sales items for selected sales orders
perform getsalesitems.
if t_sales_items is not initial.
call screen 200.
else.
message 'No sales items for selected sales orders' type 'I'.
endif.
endif.
endif.
when 'MI1'.
call transaction 'SE38'.
when 'MI2'.
call transaction 'SE37'.
when 'MI3'.
call transaction 'SE24'.
when 'MI4'.
call transaction 'SE36'.
when 'MI5'.
call transaction 'SM36'.
when 'MI6'.
call transaction 'SM37'.
when 'MI7'.
call transaction 'SE71'.
when 'MI8'.
call transaction 'SMARTFORMS'.
when 'MI9'.
call transaction 'SFP'.
endcase.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_toolbar for o_grid.
set handler ob->handle_menu_button for o_grid.
set handler ob->handle_user_command for o_grid.
ENDFORM. " REGHANDLERS
FORM LAYOUT .
clear wa_layo.
wa_layo-sel_mode = 'A'. "multiple selection
ENDFORM. " LAYOUT
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_sales_items
for ALL ENTRIES IN lt_sales
where vbeln = lt_sales-vbeln.
ENDFORM. " GETSALESITEMS
FORM FLDCAT_ITEMS .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item Number'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Netvalue'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT_ITEMS
FORM DISPLAY_ITEMS .
CALL METHOD O_GRID2->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales_items
IT_FIELDCATALOG = t_fcat.
REPORT Z730ALV13.
clear wa_button.
wa_button-butn_type = 3. "separator
append wa_button to e_object->mt_toolbar.
clear wa_button.
wa_button-function = 'F2'.
wa_button-icon = '@16@'.
wa_button-quickinfo = 'Navigate to Transactions'.
wa_button-butn_type = 2. "menu button
wa_button-text = 'Transactions'.
append wa_button to e_object->mt_toolbar.
endmethod.
method handle_menu_button.
* message 'menu button event' type 'I'.
case e_ucomm.
when 'F2'.
CALL METHOD E_OBJECT->ADD_FUNCTION
EXPORTING
FCODE = 'MI1'
TEXT = 'ABAP EDITOR'.
* add submenu
CALL METHOD E_OBJECT->ADD_SUBMENU
EXPORTING
MENU = ob
TEXT = 'Forms'.
endcase.
endmethod.
method handle_user_command.
case e_ucomm.
when 'F1'. "normal button function code
* message 'Normal button' type 'I'.
* get indexes of selected rows
data : t_rows type lvc_t_row,
wa_row type lvc_s_row.
CALL METHOD O_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = t_rows.
if t_rows is INITIAL .
message 'Please select atleast one row' type 'I'.
else.
refresh lt_sales.
loop at t_rows into wa_row.
clear wa_sales.
read table t_sales into wa_sales index wa_row-index
TRANSPORTING vbeln.
if sy-subrc eq 0.
append wa_sales to lt_sales.
endif.
endloop.
if lt_sales is not INITIAL.
* get sales items for selected sales orders
perform getsalesitems.
if t_sales_items is not initial.
call screen 200.
else.
message 'No sales items for selected sales orders' type 'I'.
endif.
endif.
endif.
when 'MI1'.
call transaction 'SE38'.
when 'MI2'.
call transaction 'SE37'.
when 'MI3'.
call transaction 'SE24'.
when 'MI4'.
call transaction 'SE36'.
when 'MI5'.
call transaction 'SM36'.
when 'MI6'.
call transaction 'SM37'.
when 'MI7'.
call transaction 'SE71'.
when 'MI8'.
call transaction 'SMARTFORMS'.
when 'MI9'.
call transaction 'SFP'.
endcase.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYSALESORDERS
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_toolbar for o_grid.
set handler ob->handle_menu_button for o_grid.
set handler ob->handle_user_command for o_grid.
ENDFORM. " REGHANDLERS
FORM LAYOUT .
clear wa_layo.
wa_layo-sel_mode = 'A'. "multiple selection
ENDFORM. " LAYOUT
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_sales_items
for ALL ENTRIES IN lt_sales
where vbeln = lt_sales-vbeln.
ENDFORM. " GETSALESITEMS
FORM FLDCAT_ITEMS .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item Number'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Netvalue'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT_ITEMS
FORM DISPLAY_ITEMS .
CALL METHOD O_GRID2->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales_items
IT_FIELDCATALOG = t_fcat.
include z730alv14_inc.
START-OF-SELECTION.
call screen 100.
Include Program:
FORM GETCUSTOMERS .
select kunnr land1 name1
from kna1
into table t_kna1
where kunnr in so_kunnr.
ENDFORM. " GETCUSTOMERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-style = cl_gui_alv_grid=>mc_style_button.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATVBAK
FORM LAYOUTKNA1 .
clear wa_layo.
wa_layo-grid_title = 'CUSTOMER MASTER DATA'.
ENDFORM. " LAYOUTKNA1
FORM DISPLAYKNA1 .
CALL METHOD O_KNA1_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_kna1
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYKNA1
FORM REGHANDLERS .
create object ob.
set handler ob->handle_double_click for o_kna1_grid.
ENDFORM. " REGHANDLERS
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where kunnr = wa_kna1-kunnr.
ENDFORM. " GETSALESORDERS
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-grid_title = 'SALES ORDERS'.
ENDFORM. " LAYOUTVBAK
FORM DISPLAYVBAK .
CALL METHOD O_VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbak
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAK
FORM FLDCATKNA1 .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Customer Number'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'LAND1'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Country Key'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NAME1'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Customer Name'.
wa_fcat-outputlen = 30.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATKNA1
REPORT Z730ALV15.
INCLUDE Z730ALV15_INC.
START-OF-SELECTION.
call screen 100.
Include Program:
method handle_button_click.
* message 'button click' type 'I'.
clear wa_vbak.
read table t_vbak into wa_vbak
index es_row_no-row_id TRANSPORTING vbeln.
if sy-subrc eq 0.
* get sales items for selected sales order
perform getsalesitems.
if t_vbap is not INITIAL.
call screen 300.
else.
message 'No sales items for selected sales order' type 'I'.
endif.
endif.
endmethod.
method handle_hotspot_click.
* message 'hotspot' type 'I'.
clear wa_vbap.
read table t_vbap into wa_vbap
index e_row_id-index TRANSPORTING matnr.
if sy-subrc eq 0.
set PARAMETER ID 'MAT' field wa_vbap-matnr.
call transaction 'MM03'.
endif.
endmethod.
endclass.
FORM GETCUSTOMERS .
select kunnr land1 name1
from kna1
into table t_kna1
where kunnr in so_kunnr.
ENDFORM. " GETCUSTOMERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-style = cl_gui_alv_grid=>mc_style_button.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATVBAK
FORM LAYOUTKNA1 .
clear wa_layo.
wa_layo-grid_title = 'CUSTOMER MASTER DATA'.
ENDFORM. " LAYOUTKNA1
FORM DISPLAYKNA1 .
CALL METHOD O_KNA1_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_kna1
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYKNA1
FORM REGHANDLERS .
create object ob.
set handler ob->handle_double_click for o_kna1_grid.
ENDFORM. " REGHANDLERS
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where kunnr = wa_kna1-kunnr.
ENDFORM. " GETSALESORDERS
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-grid_title = 'SALES ORDERS'.
ENDFORM. " LAYOUTVBAK
FORM DISPLAYVBAK .
CALL METHOD O_VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbak
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAK
FORM FLDCATKNA1 .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Customer Number'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'LAND1'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Country Key'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NAME1'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Customer Name'.
wa_fcat-outputlen = 30.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATKNA1
MODULE USER_COMMAND_0200 INPUT.
case sy-ucomm.
when 'F2'.
leave to screen 100.
endcase.
ENDMODULE. " USER_COMMAND_0200 INPUT
FORM REG_HANDLERS .
create object ob.
set handler ob->handle_button_click for o_vbak_grid.
ENDFORM. " REG_HANDLERS
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln = wa_vbak-vbeln.
ENDFORM. " GETSALESITEMS
* generate layout
perform layout_vbap.
FORM FLDCAT_VBAP .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item Number'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 12.
wa_fcat-hotspot = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
FORM LAYOUT_VBAP .
clear wa_layo.
wa_layo-grid_title = 'SALES ITEMS'.
ENDFORM. " LAYOUT_VBAP
FORM DISPLAY_VBAP .
CALL METHOD O_VBAP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbap
IT_FIELDCATALOG = t_fcat.
FORM HANDLERS_REG .
create object ob.
set handler ob->handle_hotspot_click for o_vbap_grid.
ENDFORM. " HANDLERS_REG
REPORT Z730ALV16.
include z730alv16_inc.
START-OF-SELECTION.
call screen 100.
Include Program:
endif.
REPORT Z730ALV17.
INCLUDE Z730ALV17_INC.
START-OF-SELECTION.
call screen 100.
Include Program:
method handle_data_changed.
* message 'checkbox selected or deselected' type 'I'.
data wa_modi type lvc_s_modi.
read table er_data_changed->mt_mod_cells into wa_modi
index 1.
if sy-subrc eq 0.
* read final internal table row where the interaction is made
clear wa_final_vbak.
read table t_final_vbak into wa_final_vbak
index wa_modi-row_id
TRANSPORTING sel.
if sy-subrc eq 0.
* update the internal table corresponding row
wa_final_vbak-sel = wa_modi-value.
modify t_final_vbak from wa_final_vbak
index wa_modi-row_id TRANSPORTING sel.
endif.
endif.
endmethod.
method handle_user_command.
case e_ucomm.
when 'FC1'.
refresh lt_final_vbak.
append lines of t_final_vbak to lt_final_vbak.
delete lt_final_vbak where sel = ' '.
* get sales items for selected sales orders
if lt_final_vbak is not INITIAL.
perform getsalesitems.
if t_vbap is not INITIAL.
* logic for vbap grid
if o_vbap_grid is INITIAL.
* link vbap container with vbap grid
CREATE OBJECT O_VBAP_GRID
EXPORTING
I_PARENT = o_vbap_cont.
* generate field catalog for sales items fields
perform fldcatvbap.
* generate layout for sales items grid
perform layoutvbap.
* display sales items grid
perform displayvbap.
else.
* refresh sales items grid
CALL METHOD O_VBAP_GRID->REFRESH_TABLE_DISPLAY.
endif.
else.
message 'No Sales items' type 'I'.
endif.
else.
message 'Please select atleast one row' type 'I'.
if o_vbap_grid is not INITIAL.
refresh t_vbap.
CALL METHOD O_VBAP_GRID->REFRESH_TABLE_DISPLAY.
endif.
endif.
endcase.
endmethod.
endclass.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_temp_vbak
where vbeln >= '0000004980' and vbeln <= '0000004985'.
if sy-subrc eq 0.
* copy data to final int.table
append lines of t_temp_vbak to t_final_vbak.
endif.
ENDFORM. " GETSALESORDERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'SEL'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Select'.
wa_fcat-outputlen = 8.
wa_fcat-checkbox = 'X'.
wa_fcat-edit = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-grid_title = 'SALES ORDERS'.
ENDFORM. " LAYOUTVBAK
FORM DISPLAYVBAK .
CALL METHOD O_VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_final_vbak
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAK
FORM REGHANDLERS .
create object ob.
set handler ob->handle_toolbar for o_vbak_grid.
set handler ob->handle_data_changed for o_vbak_grid.
set handler ob->handle_user_command for o_vbak_grid.
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
for ALL ENTRIES IN lt_final_vbak
where vbeln = lt_final_vbak-vbeln.
ENDFORM. " GETSALESITEMS
FORM FLDCATVBAP .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item Number'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
FORM LAYOUTVBAP .
clear wa_layo.
wa_layo-grid_title = 'SALES ITEMS'.
ENDFORM. " LAYOUTVBAP
FORM DISPLAYVBAP .
CALL METHOD O_VBAP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbap
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAP
REPORT Z730ALV17.
INCLUDE Z730ALV17_INC.
START-OF-SELECTION.
call screen 100.
Include Program:
data : o_cust_cont type ref to cl_gui_custom_container,
o_split1 type ref to cl_gui_splitter_container,
o_split2 type ref to cl_gui_splitter_container,
o_vbak_grid type ref to cl_gui_alv_grid,
o_vbap_grid type ref to cl_gui_alv_grid,
o_top_cont type ref to cl_gui_container,
o_sub_cont type ref to cl_gui_container,
o_vbak_cont type ref to cl_gui_container,
o_vbap_cont type ref to cl_gui_container.
method handle_data_changed.
* message 'checkbox selected or deselected' type 'I'.
data wa_modi type lvc_s_modi.
read table er_data_changed->mt_mod_cells into wa_modi
index 1.
if sy-subrc eq 0.
* read final internal table row where the interaction is made
clear wa_final_vbak.
read table t_final_vbak into wa_final_vbak
index wa_modi-row_id
TRANSPORTING sel.
if sy-subrc eq 0.
* update the internal table corresponding row
wa_final_vbak-sel = wa_modi-value.
modify t_final_vbak from wa_final_vbak
index wa_modi-row_id TRANSPORTING sel.
endif.
endif.
endmethod.
method handle_user_command.
case e_ucomm.
when 'FC1'.
refresh lt_final_vbak.
append lines of t_final_vbak to lt_final_vbak.
delete lt_final_vbak where sel = ' '.
* get sales items for selected sales orders
if lt_final_vbak is not INITIAL.
perform getsalesitems.
if t_vbap is not INITIAL.
* logic for vbap grid
if o_vbap_grid is INITIAL.
* link vbap container with vbap grid
CREATE OBJECT O_VBAP_GRID
EXPORTING
I_PARENT = o_vbap_cont.
* generate field catalog for sales items fields
perform fldcatvbap.
* generate layout for sales items grid
perform layoutvbap.
* register handlers for vbap grid
perform handlers_reg.
* display sales items grid
perform displayvbap.
else.
* refresh sales items grid
CALL METHOD O_VBAP_GRID->REFRESH_TABLE_DISPLAY.
endif.
else.
message 'No Sales items' type 'I'.
endif.
else.
message 'Please select atleast one row' type 'I'.
if o_vbap_grid is not INITIAL.
refresh t_vbap.
CALL METHOD O_VBAP_GRID->REFRESH_TABLE_DISPLAY.
endif.
endif.
endcase.
endmethod.
method handle_top_of_page.
* message 'top' type 'I'.
CALL METHOD E_DYNDOC_ID->ADD_TEXT
EXPORTING
TEXT = text-001
SAP_STYLE = cl_dd_document=>heading
SAP_COLOR = cl_dd_document=>LIST_HEADING_INT
SAP_FONTSIZE = cl_dd_document=>LARGE
SAP_FONTSTYLE = cl_dd_document=>SANS_SERIF
SAP_EMPHASIS = cl_dd_document=>STRONG.
endmethod.
endclass.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_temp_vbak
where vbeln >= '0000004980' and vbeln <= '0000004985'.
if sy-subrc eq 0.
* copy data to final int.table
append lines of t_temp_vbak to t_final_vbak.
endif.
ENDFORM. " GETSALESORDERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'SEL'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Select'.
wa_fcat-outputlen = 8.
wa_fcat-checkbox = 'X'.
wa_fcat-edit = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-grid_title = 'SALES ORDERS'.
ENDFORM. " LAYOUTVBAK
FORM DISPLAYVBAK .
CALL METHOD O_VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_final_vbak
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAK
FORM REGHANDLERS .
create object ob.
set handler ob->handle_toolbar for o_vbak_grid.
set handler ob->handle_data_changed for o_vbak_grid.
set handler ob->handle_user_command for o_vbak_grid.
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
for ALL ENTRIES IN lt_final_vbak
where vbeln = lt_final_vbak-vbeln.
ENDFORM. " GETSALESITEMS
FORM FLDCATVBAP .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item Number'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
FORM LAYOUTVBAP .
clear wa_layo.
wa_layo-grid_title = 'SALES ITEMS'.
ENDFORM. " LAYOUTVBAP
FORM DISPLAYVBAP .
CALL METHOD O_VBAP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbap
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAP
FORM HANDLERS_REG .
create object ob.
set handler ob->handle_top_of_page for o_vbap_grid.
* register the event top_of_page explictly
data k type ref to cl_dd_document.
create object k.
REPORT Z730ALV18.
START-OF-SELECTION.
call screen 100.
* get employees
perform getemployees.
if t_emp is not INITIAL.
* generate fieldcatalog
perform fldcat.
* register handlers.
perform reghandlers.
* display employees
perform displayemployees.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETemployees .
select *
from z9amemp
into table t_emp
where empno in so_empno.
ENDFORM. " GETEMPLOYEES
FORM DISPLAYEMPLOYEES.
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_emp
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'EMPNO'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Employee No'.
wa_fcat-outputlen = 10.
wa_fcat-tooltip = 'Empno'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ENAME'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Employee Name'.
wa_fcat-edit = 'X'.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EMPDESIG'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Designation'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'DEPTNO'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Department No'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_data_changed for o_grid.
REPORT Z730ALV19.
endclass.
method handle_user_command.
case e_ucomm.
when 'MI1'.
call transaction 'SE38'.
when 'MI2'.
call transaction 'SE37'.
when 'MI3'.
call transaction 'SE24'.
endcase.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_context_menu_request for o_grid.
set handler ob->handle_user_command for o_grid.
ENDFORM. " REGHANDLERS
Flowlogic:
Screen Layout:
Example: Scheduling ALV Report in Background
REPORT Z730ALV20.
START-OF-SELECTION.
call screen 100.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
Flowlogic:
Screen Layout:
Example: ALV Drop down columns
REPORT Z730ALV21.
START-OF-SELECTION.
call screen 100.
* get employees
perform getemployees.
if t_emp is not INITIAL.
* generate fieldcatalog
perform fldcat.
* prepare dropdown values
perform dropdown_values.
* display employees
perform displayemployees.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETemployees .
select *
from z9amemp
into table t_emp
where empno in so_empno.
ENDFORM. " GETEMPLOYEES
FORM DISPLAYEMPLOYEES.
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_emp
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYEMPLOYEES
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'EMPNO'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Employee No'.
wa_fcat-outputlen = 10.
wa_fcat-tooltip = 'Empno'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ENAME'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Employee Name'.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EMPDESIG'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Designation'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'DEPTNO'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Department No'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'DNAME'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Department Name'.
wa_fcat-outputlen = 15.
wa_fcat-drdn_hndl = 25.
wa_fcat-edit = 'X'.
append wa_fcat to t_fcat.
FORM DROPDOWN_VALUES .
refresh t_drop.
clear wa_drop.
wa_drop-handle = 25.
wa_drop-value = 'SAP'.
append wa_drop to t_drop.
clear wa_drop.
wa_drop-handle = 25.
wa_drop-value = 'ORACLE'.
append wa_drop to t_drop.
clear wa_drop.
wa_drop-handle = 25.
wa_drop-value = 'JAVA'.
append wa_drop to t_drop.
clear wa_drop.
wa_drop-handle = 25.
wa_drop-value = '.Net'.
append wa_drop to t_drop.
Flowlogic:
REPORT Z730ALV22.
when 'PO'.
method handle_node_context_menu_sel.
case node_key.
when 'SO'.
if fcode = 'MI1'.
call transaction 'VA01'.
elseif fcode = 'MI2'.
call transaction 'VA02'.
elseif fcode = 'MI3'.
call transaction 'VA03'.
endif.
when 'PO'.
if fcode = 'MI4'.
call transaction 'ME21'.
elseif fcode = 'MI5'.
call transaction 'ME22'.
elseif fcode = 'MI6'.
call transaction 'ME23'.
endif.
endcase.
endmethod.
method handle_node_double_click.
* message 'Double' type 'I'.
case node_key.
when 'CSO'.
call transaction 'VA01'.
when 'CHSO'.
call transaction 'VA02'.
when 'DSO'.
call transaction 'VA03'.
when 'CPO'.
call transaction 'ME21'.
when 'CHPO'.
call transaction 'ME22'.
when 'DPO'.
call transaction 'ME23'.
endcase.
endmethod.
method handle_node_keypress.
case node_key.
when 'CSO'.
if key = cl_gui_simple_tree=>key_enter.
message 'Pressed enter key' type 'I'.
elseif key = cl_gui_simple_tree=>key_delete.
message 'Pressed delete key' type 'I'.
endif.
endcase.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
FORM TREE .
* link tree control with container (o_cont1)
CREATE OBJECT O_TREE
EXPORTING
PARENT = o_cont1
NODE_SELECTION_MODE = cl_gui_simple_tree=>node_sel_mode_single.
* construct nodes
clear wa_nodes.
wa_nodes-node_key = 'RT'.
wa_nodes-isfolder = 'X'.
wa_nodes-expander = 'X'.
wa_nodes-text = 'Transactions'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'SO'.
wa_nodes-relatkey = 'RT'.
wa_nodes-isfolder = 'X'.
wa_nodes-expander = 'X'.
wa_nodes-text = 'Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CSO'.
wa_nodes-relatkey = 'SO'.
wa_nodes-n_image = '@15@'.
wa_nodes-text = 'Create Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CHSO'.
wa_nodes-relatkey = 'SO'.
wa_nodes-n_image = '@15@'.
wa_nodes-text = 'Change Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'DSO'.
wa_nodes-relatkey = 'SO'.
wa_nodes-n_image = '@15@'.
wa_nodes-text = 'Display Sales Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'PO'.
wa_nodes-relatkey = 'RT'.
wa_nodes-isfolder = 'X'.
wa_nodes-expander = 'X'.
wa_nodes-text = 'Purchase Orders'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CPO'.
wa_nodes-relatkey = 'PO'.
wa_nodes-n_image = '@16@'.
wa_nodes-text = 'Create Purchase Order'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'CHPO'.
wa_nodes-relatkey = 'PO'.
wa_nodes-n_image = '@16@'.
wa_nodes-text = 'Change Purchase Order'.
append wa_nodes to t_nodes.
clear wa_nodes.
wa_nodes-node_key = 'DPO'.
wa_nodes-relatkey = 'PO'.
wa_nodes-n_image = '@16@'.
wa_nodes-text = 'Display Purchase Orders'.
append wa_nodes to t_nodes.
FORM REG_HANDLERS .
create object ob.
set handler ob->handle_node_context_menu_req for o_tree.
set handler ob->handle_node_context_menu_sel for o_tree.
set handler ob->handle_node_double_click for o_tree.
set handler ob->handle_node_keypress for o_tree.
Example: Custom F4 Help (onf4 event) and Custom F1 help (onf1 event) for ALV columns
REPORT Z730ALV23.
method handle_onf1.
case e_fieldname.
when 'EMPNO'.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Custom F1 help'
TXT1 = 'Employee Number'
TXT2 = 'Table:Z9AMEMP Field:EMPNO'.
endcase.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
* get employees
perform getemployees.
if t_emp is not INITIAL.
* generate fieldcatalog
perform fldcat.
* register handlers
perform reghandlers.
* display employees
perform displayemployees.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETemployees .
select *
from z9amemp
into table t_emp
where empno in so_empno.
ENDFORM. " GETEMPLOYEES
FORM DISPLAYEMPLOYEES.
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_emp
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'EMPNO'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Employee No'.
wa_fcat-outputlen = 10.
wa_fcat-tooltip = 'Empno'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ENAME'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Employee Name'.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EMPDESIG'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Designation'.
wa_fcat-outputlen = 15.
wa_fcat-f4availabl = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'DEPTNO'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Department No'.
wa_fcat-outputlen = 12.
wa_fcat-tooltip = 'Deptno'.
wa_fcat-f4availabl = 'X'.
append wa_fcat to t_fcat.
FORM REGHANDLERS .
create object ob.
set handler ob->handle_onf4 for o_grid.
set handler ob->handle_onf1 for o_grid.
clear wa_f4.
wa_f4-fieldname = 'DEPTNO'.
wa_f4-register = 'X'.
* append wa_f4 to t_f4. "runtime error
insert wa_f4 into table t_f4.
CALL METHOD O_GRID->REGISTER_F4_FOR_FIELDS
EXPORTING
IT_F4 = t_f4.
Flowlogic:
Screen Layout:
START-OF-SELECTION.
call screen 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ABC'.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_sales
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM DISPLAYSALESORDERS .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_sales
IT_FIELDCATALOG = t_fcat.
FORM FLDCAT .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-tooltip = 'Sales Document Number'.
wa_fcat-ref_table = 'VBAK'. "for standard f4 and standard f1 helps
wa_fcat-ref_field = 'VBELN'.
wa_fcat-f4availabl = 'X'. "custom f4 help
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Name of Person Created Sales Doc'.
wa_fcat-outputlen = 40.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_onf4 for o_grid.
clear wa_f4.
wa_f4-fieldname = 'VBELN'.
wa_f4-register = 'X'.
append wa_f4 to t_f4.
Flowlogic:
Screen Layout:
Procedure for Classical Reporting:
8. Display the data in the ALV grid using the method 'SET_TABLE_FOR_FIRST_DISPLAY'
of the grid class 'cl_gui_alv_grid'
Whenever we display the data in the form of ALV report, we need to provide field catalog
information; otherwise the report execution leads to ABORT error. In case of ALV reporting
using classes, we can generate field catalog in 2 ways.
2. Manually
Note: In either of the above 2 process, once the fieldcatalog is generated, we need to pass it as
a value to the parameter ‘IT_FIELDCATALOG’ as part of the method call
‘SET_TABLE_FOR_FIRST_DISPLAY’.
For this, we need to identify the function codes of the ALV toolbar buttons and prepare an
internal table with those function codes and pass the internal table as a value to the parameter
“IT_TOOLBAR_EXCLUDING” of the method “SET_TABLE_FOR_FIRST_DISPLAY” of the class
‘CL_GUI_ALV_GRID’. All the ALV toolbar buttons function codes exist in the form of constant
public attributes with the naming standard ‘MC_FC…’ of the class ‘CL_GUI_ALV_GRID’.
Note: For excluding entire ALV toolbar in the Report, set the field ‘NO_TOOLBAR’ to ‘X’ as part
of Layout.
For displaying the entire ALV column as pushbutton, set the field ‘STYLE’ as part of field catalog.
All the styles exist in the form of constant attributes with the naming standard ‘MC_STYL’ as
part of the class ‘CL_GUI_ALV_GRID’.
Displaying ALV cells as pushbutton:
Procedure:
Step1:
Take an additional column in the final internal table which is of table type “LVC_T_STYL”.
Step 2:
Before displaying the final data in the ALV grid, loop the final internal table and set the
button style (MC_STYLE_BUTTON) to ALV cells based on the condition.
As part of layout generation, set the field “stylefname” whose value is name of the
additional field which holds the style.
For coloring the entire ALV column, set the field ‘EMPHASIZE’ to a color coding as part of field
catalog.
Procedure:
Step1:
Take an additional column in the final internal table which is of type char4.
Step 2:
Before displaying the final data in the ALV grid, loop the final internal table and set the color
coding for the additional field based on the condition.
As part of layout generation, set the field “info_fname” whose value is name of the
additional field which holds the row color coding.
Procedure:
Step1:
Take an additional column in the final internal table which is of type ‘LVC_T_SCOL’.
Step 2:
Before displaying the final data in the ALV grid, loop the final internal table and set the color
coding for the additional field based on the condition.
For this, we need to prepare work area of type ‘LVC_S_SCOL’ and append the same to the
additional field and update the internal table.
As part of layout generation, set the field “ctab_fname” whose value is name of the
additional field which holds the cell color coding.
- These traffic lights by default are displayed as First column of the ALV report.
- Traffic light codes are 3 types (1-Red, 2-Yellow, 3-Green) and also we can refer to the
corresponding constant values in the ICON type-group.
Procedure:
Step 1:
Take an additional column in the final internal table which is of type character of “One”.
Step 2:
Before displaying the final data in the ALV GRID, loop the internal table and set the traffic
light code for an additional column based on a condition.
Step 3:
As part of layout, set the field “EXCP_FNAME”, the value of the field should be “Name of the
additional column” containing traffic light code.
Note: By default, Traffic light column is displayed in first column position. To display traffic
light in a specific column position, declare an additional column of type character with some
length, generate field catalog for this column including required column position and assign
traffic light code to its column value along with static text. In this case, we should not set
the field ‘EXCP_FNAME’ in layout.
Splitter control
It is used for splitting the container in to “N” no of partitions.
Each “PANE” should be associated with a container to hold an object. The object can be ALV
Grid, Image and Tree.
Step 1:
In SMW0, choose the radio button ‘binary data for webrfc applications’, click on ‘FIND’
(appl.toolbar) provide package name(any package), object name (any name, unique id)
description(…), click on execute click on ‘create’ button (appl.toolbar),provide object name
(ZBT), description(…), click on ‘import button’ (status bar of dialog box)
Step 2:
This function module takes an image object id as input and returns the “URL” of picture which is
of type “cndp_url”.
Note:
Step 3: Create the object of picture class ‘CL_GUI_PICTURE’ linking with a container.
Step 4: call the instance method “load_picture_from_url” of the class “cl_gui_picture”. This
method takes URL of the picture as input and displays the picture in the container.
We can add the nodes to the tree control by using the instance method “add_nodes”
of the class “cl_gui_simple_tree”.
Note: “ABDEMONODE” is one of the standard structure given by SAP which represents simple
tree (or) we can create custom dictionary structure by including std.structure ‘TREEV_NODE’
and a character field ‘text’ of any length
Generally we display ALV column as drop down when we have fixed set of values to be shown
to the user as a drop down so that the user can select the value in the runtime.
Procedure:
Step 1:
Take an additional column in the final internal table, this additional column needs to be
displayed as dropdown.
Step 2:
As part of the field catalog, set the field “DRDN_HNDL” to some Numeric value and also set
the edit field to ‘X’ as the column should be editable, so that user can choose value from the
drop down in the runtime.
Step 3:
Prepare an internal table of type ‘LVC_T_DROP’ with drop down handle and dropdown
values and pass this internal table as a parameter to the method
‘SET_DROP_DOWN_TABLE’ of the class ‘CL_GUI_ALV_GRID’.
2. Event Business logic needs to implemented as part of custom class implementation (inside
event handler method)
3. Raised by SAP itself depending on user actions (from. The std. methods)
Note:
1. To Display ALV column values as link, we need to set the field ‘HOTSPOT’ as part of field
catalog for that particular field.
5. As part of interactive ALV reporting using classes, when the user interacts and navigates
from one screen to another screen, we need to refresh the grid with the corresponding
internal table data using the method ‘REFRESH_TABLE_DISPLAY’ of the class
‘CL_GUI_ALV_GRID’.
TOOLBAR Event: is the instance event of the class ‘CL_GUI_ALV_GRID’ which is triggered when
the ALV grid is displayed. This event can be used to manage the ALV Toolbar for
Enabling/Disabling standard ALV Toolbar buttons, Adding custom buttons.
MENU_BUTTON event: is the instance event of the class ‘CL_GUI_ALV_GRID’ which is triggered
when the user clicks on custom MENU buttons on ALV toolbar.
Note:
1. To enable multiple selection of rows on ALV grid, we need to set the field ‘SEL_MODE’
TO ‘A’ as part of layout
2. To identify the selected rows on the ALV grid, we need to use the instance method
‘GET_SELECTED_ROWS’ of the class ‘CL_GUI_ALV_GRID’. This method returns the
internal tables containing the indexes of selected rows.
Procedure:
1. For the ALV column to be editable, set the field edit to ‘X’ As part of field catalog,
2. Handle the event ‘DATA_CHANGED’ of the class ‘CL_GUI_ALV_GRID’. This event is not
triggered by default as it is a system event, it requires explicit registration and it is done
by calling the instance method ‘REGISTER_EDIT_EVENT’ of the class
‘CL_GUI_ALV_GRID’. This method takes event id as a mandatory input parameter.
These event ids exist in the form of constant attributes of the grid class and we can use
any of the following attribute event ids.
a) Mc_evt_modified Allows only single cell editing, in this case the event
‘DATA_CHANGED’ is triggered when the user shifts the focus from the first modified
cell or when the user presses enter key in the first modified cell.
b) Mc_evt_enter -> Allows multi cell editing, in this case the event is triggered when
the user presses enter key in the last modified cell.
3. As part of the event handler method, we need to import the event parameter
‘ER_DATA_CHANGED’ and using this event parameter (object) access the instance
attribute (internal table) ‘MT_MODIFIED_CELLS’ which keeps track about the
information of the modified cells which includes row_id and modified value. Based on
this, update the grid internal table as well as corresponding database table.
For this, we need to handle the event ‘TOP_OF_PAGE’. It is the instance event of the class
‘CL_GUI_ALV_GRID’ used for generating content in the TOP OF PAGE area of ALV Grid. This
event is not triggered by default; it should be registered explicitly by calling the instance
method ‘LIST_PROCESSING_EVENTS’ of the class ‘CL_GUI_ALV_GRID’.
Report Program:
REPORT Z730ALV25.
start-OF-SELECTION.
* get sales orders
perform getsalesorders.
if t_vbak is not INITIAL.
* generate fieldcatalog for sales orders fields
perform fldcatvbak.
* register events
perform regevents.
* display sales orders grid
perform displayvbak.
endif.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM FLDCATVBAK .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZCVBAK'
CHANGING
CT_FIELDCAT = t_fcat.
FORM DISPLAYVBAK .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_TITLE = 'SALES ORDERS'
IT_FIELDCAT = t_fcat
IT_EVENTS = t_events
TABLES
T_OUTTAB = t_vbak.
ENDFORM. " DISPLAYVBAK
FORM REGEVENTS .
clear wa_events.
wa_events-name = 'USER_COMMAND'.
wa_events-form = 'SALESITEMS'.
append wa_events to t_events.
ENDFORM. " REGEVENTS
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln = wa_vbak-vbeln.
ENDFORM. " GETSALESITEMS
FORM FLDCATVBAP .
refresh t_fcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZCVBAP'
CHANGING
CT_FIELDCAT = t_fcat.
ENDFORM. " FLDCATVBAP
FORM DISPLAYVBAP .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_GRID_TITLE = 'SALES ITEMS'
IT_FIELDCAT = t_fcat
IT_EVENTS = t_events
TABLES
T_OUTTAB = t_vbap.
clear wa_events.
wa_events-name = 'USER_COMMAND'.
wa_events-form = 'MATERIALDATA'.
append wa_events to t_events.
ENDFORM. " EVENTSREG
form heading.
* message 'top' type 'I'.
data : t_header type SLIS_T_LISTHEADER,
wa_header like line of t_header.
clear wa_header.
wa_header-typ = 'H'.
wa_header-info = 'Gensoft Technologies'.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-info = 'SAP Technical Training'.
append wa_header to t_header.
FORM MATERIALBLOCKS .
* Initialize ALV Blocked list
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID.
FORM FLDCATMARC .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 1.
wa_fcat-outputlen = 15.
wa_fcat-seltext_m = 'Material No'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-col_pos = 2.
wa_fcat-outputlen = 10.
wa_fcat-seltext_m = 'Plant'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EKGRP'.
wa_fcat-col_pos = 3.
wa_fcat-outputlen = 15.
wa_fcat-seltext_m = 'Purchase Group'.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATMARC
FORM GETMATERIALPLANTS .
select matnr werks ekgrp
from marc
into table t_marc
where matnr = wa_vbap-matnr.
ENDFORM. " GETMATERIALPLANTS
FORM APPENDMARC .
refresh t_events.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = wa_layo
IT_FIELDCAT = t_fcat
I_TABNAME = 'T_MARC'
IT_EVENTS = t_events
TABLES
T_OUTTAB = t_marc.
FORM GETMATERIALSTORAGELOCS .
select matnr werks lgort
from mard
into table t_mard
where matnr = wa_vbap-matnr.
ENDFORM. " GETMATERIALSTORAGELOCS
FORM FLDCATMARD .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 1.
wa_fcat-outputlen = 15.
wa_fcat-seltext_m = 'Material No'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-col_pos = 2.
wa_fcat-outputlen = 10.
wa_fcat-seltext_m = 'Plant'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'LGORT'.
wa_fcat-col_pos = 3.
wa_fcat-outputlen = 15.
wa_fcat-seltext_m = 'Storage Locations'.
append wa_fcat to t_fcat.
FORM APPENDMARD .
refresh t_events.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = wa_layo
IT_FIELDCAT = t_fcat
I_TABNAME = 'T_MARD'
IT_EVENTS = t_events
TABLES
T_OUTTAB = t_mard.
ENDFORM. " APPENDMARD
Example: Hierarchical Sequential Report using ALV Function Modules (Field catalog
generated using Function Module)
REPORT Z730ALV26.
START-OF-SELECTION.
* get sales orders header data
perform getsalesorders.
if t_vbak is NOT INITIAL.
* get sales orders item data
perform getsalesitems.
if t_vbap is not INITIAL.
* generate fieldcatalog for salesorder header and item tables
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_INTERNAL_TABNAME = 'T_VBAK'
I_STRUCTURE_NAME = 'ZCVBAK'
CHANGING
CT_FIELDCAT = t_fcat.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
for ALL ENTRIES IN t_vbak
where vbeln = t_vbak-vbeln.
ENDFORM. " GETSALESITEMS
FORM REGKEYFIELDS .
clear wa_keyinfo.
wa_keyinfo-header01 = 'VBELN'.
wa_keyinfo-item01 = 'VBELN'.
wa_keyinfo-header02 = space.
wa_keyinfo-item02 = 'POSNR'.
ENDFORM. " REGKEYFIELDS
FORM DISPLAY .
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
IT_FIELDCAT = t_fcat
I_TABNAME_HEADER = 'T_VBAK'
I_TABNAME_ITEM = 'T_VBAP'
IS_KEYINFO = wa_keyinfo
TABLES
T_OUTTAB_HEADER = t_vbak
T_OUTTAB_ITEM = t_vbap.
ENDFORM. " DISPLAY
Example: Hierarchical Sequential Report using ALV Function Modules (Field catalog
generated manually)
REPORT Z730ALV27.
types : begin of ty_vbak.
include type zcvbak.
types end of ty_vbak.
START-OF-SELECTION.
* get sales orders header data
perform getsalesorders.
if t_vbak is NOT INITIAL.
* get sales orders item data
perform getsalesitems.
if t_vbap is not INITIAL.
* generate fieldcatalog for salesorder header and item tables
perform fldcat.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
for ALL ENTRIES IN t_vbak
where vbeln = t_vbak-vbeln.
ENDFORM. " GETSALESITEMS
FORM REGKEYFIELDS .
clear wa_keyinfo.
wa_keyinfo-header01 = 'VBELN'.
wa_keyinfo-item01 = 'VBELN'.
wa_keyinfo-header02 = space.
wa_keyinfo-item02 = 'POSNR'.
ENDFORM. " REGKEYFIELDS
FORM DISPLAY .
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
IT_FIELDCAT = t_fcat
I_TABNAME_HEADER = 'T_VBAK'
I_TABNAME_ITEM = 'T_VBAP'
IS_KEYINFO = wa_keyinfo
TABLES
T_OUTTAB_HEADER = t_vbak
T_OUTTAB_ITEM = t_vbap.
ENDFORM. " DISPLAY
FORM FLDCAT .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-seltext_m = 'Sales Doc'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAK'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-seltext_m = 'Date'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAK'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-seltext_m = 'Time'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAK'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-seltext_m = 'Person'.
wa_fcat-outputlen = 15.
wa_fcat-tabname = 'T_VBAK'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 5.
wa_fcat-seltext_m = 'Sales Doc'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAP'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 6.
wa_fcat-seltext_m = 'Item No'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAP'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 7.
wa_fcat-seltext_m = 'Material'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAP'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 8.
wa_fcat-seltext_m = 'Net value'.
wa_fcat-outputlen = 12.
wa_fcat-tabname = 'T_VBAP'.
append wa_fcat to t_fcat.
REPORT Z730ALV28.
START-OF-SELECTION.
* get data
perform getdata.
if t_vbak is not INITIAL.
* get instance of SALV table class
data o_salv type ref to CL_SALV_TABLE.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = o_salv
CHANGING
T_TABLE = t_vbak.
CATCH CX_SALV_MSG .
message 'Exception in creating SALV object' type 'I'.
ENDTRY.
FORM GETDATA .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
ENDFORM. " GETDATA
REPORT Z730ALV29.
START-OF-SELECTION.
* get customer data
perform getcustomers.
if t_kna1 is not INITIAL.
* get the ALV object for customer data
data o_kna1_alv type ref to CL_SALV_TABLE.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = o_kna1_alv
CHANGING
T_TABLE = t_kna1.
CATCH CX_SALV_MSG .
message 'Exception in creating ALV object for KNA1 grid' type 'I'.
ENDTRY.
if o_kna1_alv is BOUND. "same as not initial
* get the reference of ALL columns
data o_columns type ref to CL_SALV_COLUMNS_TABLE.
CALL METHOD O_KNA1_ALV->GET_COLUMNS
RECEIVING
VALUE = o_columns.
if o_columns is bound.
* get the reference of a specific column (KUNNR)
data o_column type ref to CL_SALV_COLUMN.
TRY.
CALL METHOD O_COLUMNS->GET_COLUMN
EXPORTING
COLUMNNAME = 'KUNNR'
RECEIVING
VALUE = o_column.
if o_column is bound.
* type cast the object to sub class
data o_col type ref to CL_SALV_COLUMN_TABLE.
o_col ?= o_column.
if o_col is bound.
* set the cell type to HOTSPOT for Kunnr column
CALL METHOD O_COL->SET_CELL_TYPE
EXPORTING
VALUE = IF_SALV_C_CELL_TYPE=>HOTSPOT.
endif.
endif.
CATCH CX_SALV_NOT_FOUND .
message 'Exception in getting the column reference' type 'I'.
ENDTRY.
endif.
endif.
* register handlers
perform reghandlers.
* display the ALV grid containing customer data
CALL METHOD O_KNA1_ALV->DISPLAY.
endif.
FORM GETCUSTOMERS .
SELECT kunnr land1 name1
from kna1
into table t_kna1
where kunnr in so_kunnr.
ENDFORM. " GETCUSTOMERS
FORM REGHANDLERS .
create object ob.
* set handler ob->handle_link_click for o_kna1_alv. "syntax error
* get the object of event table class
data o_events_table type ref to cl_salv_events_table.
CALL METHOD O_KNA1_ALV->GET_EVENT
RECEIVING
VALUE = o_events_table.
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where kunnr = wa_kna1-kunnr.
ENDFORM. " GETSALESORDERS
Introduction:
The CL_SALV_TABLE class is part of the ALV Object Model which was introduced in
NetWeaver 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.
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.
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.
If you insert the table as grid in container, you are not able to use batch mode (background)
For this, we need to handle the events defined in the class ‘CL_SALV_EVENTS_TABLE’.
include z8amalv22_inc.
start-of-SELECTION.
call screen 100.
endmethod.
method handle_print_top_of_page.
write :/ 'PRINT TOP OF PAGE EVENT' color 3,'Page No :' color
4,sy-pagno color 5.
endmethod.
method handle_print_end_of_page.
write :/ 'PRINT END OF PAGE EVENT' color 1.
endmethod.
method handle_print_top_of_list.
write :/ 'PRINT TOP OF LIST EVENT' color 5.
endmethod.
method handle_print_end_of_list.
write :/ 'PRINT END OF LIST EVENT' color 7.
endmethod.
endclass.
data ob type ref to lcl_eventreceiver.
FORM GETCUSTOMERS .
select kunnr land1 name1
from kna1
into table t_kna1
where kunnr in so_kunnr.
FORM FLDCATKNA1 .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZCSTKNA1'
CHANGING
CT_FIELDCAT = t_fcat.
FORM DISPLAYCUSTOMERS .
if kna1_grid is INITIAL.
CREATE OBJECT KNA1_GRID
EXPORTING
I_PARENT = o_cont2.
perform reghandlers.
FORM REGHANDLERS .
create object ob.
set handler ob->handle_top_of_page for kna1_grid.
set handler ob->handle_print_top_of_page for kna1_grid.
set handler ob->handle_print_end_of_page for kna1_grid.
set handler ob->handle_print_top_of_list for kna1_grid.
set handler ob->handle_print_end_of_list for kna1_grid.
Note: To Test Print events, execute the ALV report and in the runtime, click on ‘print’ button so
that report is sent to captured as spool request. Now, go to ‘SP01’ and view the spool.
include z8amalv23_inc.
start-of-SELECTION.
call screen 100.
perform getsalesorders.
if t_vbak is not INITIAL.
perform fldcatvbak.
perform sortcriteria.
perform layoutvbak.
perform displaysalesorders.
endif.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETSALESORDERS .
select vbeln erdat erzet ernam netwr
from vbak
into table t_vbak
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Doc'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 22.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 12.
wa_fcat-do_sum = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'TOTTEXT'.
wa_fcat-coltext = 'Total Net Value'.
wa_fcat-no_out = 'X'.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATVBAK
FORM DISPLAYSALESORDERS .
CALL METHOD VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbak
IT_FIELDCATALOG = t_fcat
IT_SORT = lt_sort.
FORM SORTCRITERIA .
clear ls_sort.
ls_sort-fieldname = 'TOTTEXT'.
ls_sort-subtot = 'X'.
append ls_sort to lt_sort.
ENDFORM. " SORTCRITERIA
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-no_totline = 'X'. "Suppress output total line
ENDFORM. " LAYOUTVBAK
INCLUDE Z8AMALV24_INC.
start-of-SELECTION.
call screen 100.
perform getsalesitems.
if t_vbap is not INITIAL.
perform fldcatvbap.
perform sortcriteria.
perform layoutvbap.
perform reghandlers.
perform displaysalesitems.
endif.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln in so_vbeln.
ENDFORM. " GETSALESITEMS
FORM FLDCATVBAP .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Doc'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item No'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 12.
wa_fcat-do_sum = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'TTEXT'.
wa_fcat-coltext = 'Subtotal is '.
wa_fcat-no_out = 'X'.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATVBAP
FORM DISPLAYSALESITEMS .
CALL METHOD VBAP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbap
IT_FIELDCATALOG = t_fcat
IT_SORT = lt_sort.
FORM SORTCRITERIA .
clear ls_sort.
ls_sort-fieldname = 'VBELN'.
ls_sort-subtot = 'X'.
append ls_sort to lt_sort.
clear ls_sort.
ls_sort-fieldname = 'TTEXT'.
ls_sort-subtot = 'X'.
append ls_sort to lt_sort.
ENDFORM. " SORTCRITERIA
FORM LAYOUTVBAP .
clear wa_layo.
* wa_layo-no_totline = 'X'. "Suppress output total line
ENDFORM. " LAYOUTVBAK
FORM REGHANDLERS .
create object ob.
set handler ob->handle_subtotal_text for vbap_grid.
ENDFORM. " REGHANDLERS
INCLUDE Z8AMALV25_INC.
start-of-SELECTION.
call screen 100.
perform getsalesorders.
if t_vbak is not INITIAL.
perform fldcatvbak.
perform sortcriteria.
perform layoutvbak.
perform configvariant.
perform displaysalesorders.
endif.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETSALESORDERS .
select vbeln erdat erzet ernam netwr
from vbak
into table t_vbak
where vbeln in so_vbeln.
ENDFORM. " GETSALESORDERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Doc'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 22.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 12.
wa_fcat-do_sum = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'TOTTEXT'.
wa_fcat-coltext = 'Total Net Value'.
wa_fcat-no_out = 'X'.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATVBAK
FORM DISPLAYSALESORDERS .
CALL METHOD VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
IS_VARIANT = wa_variant
I_SAVE = 'X'
CHANGING
IT_OUTTAB = t_vbak
IT_FIELDCATALOG = t_fcat
IT_SORT = lt_sort.
FORM SORTCRITERIA .
clear ls_sort.
ls_sort-fieldname = 'TOTTEXT'.
ls_sort-subtot = 'X'.
append ls_sort to lt_sort.
ENDFORM. " SORTCRITERIA
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-no_totline = 'X'. "Suppress output total line
ENDFORM. " LAYOUTVBAK
FORM CONFIGVARIANT .
clear wa_variant.
wa_variant-report = sy-repid.
wa_variant-username = sy-uname.
ENDFORM. " CONFIGVARIANT
Case 1:
Right click on one of the column (say ERZET), and hide, now to save these changes click
on layout icon (alv toolbar), save layout, provide variant name (/v1), description and
continue.
Case 2:
Right click on one of the column (say VBELN), and sort in descending order, now to save
these changes click on layout icon (alv toolbar), save layout, provide variant name (/v2),
description and continue.
Now, in the next execution, to get back the previous layouts, click on layout icon (alv
toolbar) and choose the layout from the list.