Escolar Documentos
Profissional Documentos
Cultura Documentos
REPORT Z930_PROG2.
uline. "underline
*format color 9. "syntax error
format color 3.
write :/ 'sum of two numbers is ',gv_r1.
if gv_r2 >= 0.
write :/ 'Difference of two numbers is ',gv_r2.
else.
write :/ 'Difference of two numbers is -' no-gap,gv_r2 no-sign LEFT-JUSTIFIED.
endif.
format color off.
Example: Constants
REPORT Z930_PROG3.
1st May
Example: Selection Screen Radiobuttons
REPORT Z930_PROG4.
if p_r1 = 'X'.
gv_res = p_x + p_y.
write :/ 'Sum of Two numbers is ',gv_res.
elseif p_r2 = 'X'.
gv_res = p_x - p_y.
if gv_res >= 0.
write :/ 'Difference of Two numbers is ',gv_res.
else.
write :/ 'Difference of Two numbers is -' no-gap,gv_res no-sign LEFT-JUSTIFIED.
endif.
elseif p_r3 = 'X'.
gv_res = p_x * p_y.
write :/ 'Product of Two numbers is ',gv_res.
*else. "(or)
elseif p_r4 = 'X'.
gv_res = p_x / p_y.
write :/ 'Division of two numbers is ',gv_res.
endif.
REPORT Z930_PROG5.
if p_c1 = 'X'.
gv_res = p_x + p_y.
write :/ 'Sum of Two numbers is ',gv_res.
endif.
if p_c2 = 'X'.
gv_res = p_x - p_y.
if gv_res >= 0.
write :/ 'Difference of Two numbers is ',gv_res.
else.
write :/ 'Difference of Two numbers is -' no-gap,gv_res no-sign,
LEFT-JUSTIFIED.
endif.
endif.
if p_c3 = 'X'.
gv_res = p_x * p_y.
write :/ 'Product of Two numbers is ',gv_res.
endif.
if p_c4 = 'X'.
gv_res = p_x / p_y.
write :/ 'Division of two numbers is ',gv_res.
endif.
2nd May
REPORT Z930_PROG6.
uline.
data gv_y type p.
gv_y = '123.45'.
write / gv_y.
uline.
data gv_z type p DECIMALS 2.
gv_z = '123.45'.
write / gv_z.
uline.
data gv_m type c.
gv_m = 'Gensoft Technologies'.
write / gv_m.
uline.
data gv_k(10) type c. "array of characters
gv_k = 'Gensoft Technologies'.
write / gv_k.
uline.
data gv_r type string.
gv_r = 'Gensoft Technologies'.
write / gv_r.
uline.
data gv_r1 type d. "date-8 bytes
gv_r1 = sy-datum. "system field for application server current date
write / gv_r1. "ddmmyyyy
write /(10) gv_r1. "dd.mm.yyyy
write /(10) gv_r1 using EDIT MASK '__/__/____'. "dd/mm/yyyy
uline.
data gv_r2 type t. "time-6 bytes
gv_r2 = sy-uzeit. "system field for application server current time
write / gv_r2. "hhmmmss
write /(8) gv_r2. "hh:mm:ss
write /(8) gv_r2 using edit mask '__-__-__'. "hh-mm-ss
uline.
write / sy-repid. "current program name
write / sy-uname. "login user name
write / sy-pagno. "current page no
write / sy-dynnr. "current screen no
REPORT Z930_PROG7.
3rd may
Example: Looping Statements, Continue and Exit statements
REPORT Z930_PROG8.
uline.
gv_y = 1.
write :/ 'While loop...'.
while gv_y <= 10.
if gv_y ne 4.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
endif.
gv_y = gv_y + 1.
endwhile.
uline.
gv_y = 1.
write :/ 'While loop...'.
while gv_y <= 10.
if gv_y eq 4.
gv_y = gv_y + 1.
continue.
endif.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
endwhile.
uline.
write :/ 'DO...enddo..First Syntax..'.
gv_y = 1.
do.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
if gv_y > 10.
exit.
endif.
enddo.
uline.
write :/ 'DO...enddo..Second Syntax..'.
gv_y = 1.
do 10 times. "suitable for executing statements repeatedly for fixed no of times
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
enddo.
Example: Case-Endcase
REPORT Z930_PROG9.
case p_ch.
when 1.
gv_res = p_x + p_y.
write :/ 'Sum is ',gv_res.
when 2.
gv_res = p_x - p_y.
write :/ 'Difference is ',gv_res.
when 3.
gv_res = p_x * p_y.
write :/ 'Product is ',gv_res.
when 4.
gv_res = p_x / p_y. "quotient
write :/ 'Division is ',gv_res.
when 5.
gv_res = p_x mod p_y. "remainder
write :/ 'Remainder is ',gv_res.
when others.
message 'Please enter choice as 1/2/3/4/5' type 'I'.
endcase.
REPORT Z930_PROG10.
check gv_r eq 0.
write :/ 'Even no'.
write :/ 'End of program'.
Example: Field-Symbols
REPORT Z930_PROG11.
uline.
*<abc> = gv_r. "runtime error-error at assignment
uline.
gv_r = 20.
write :/ 'Integer variable gv_r is ',gv_r,
/ 'Field Symbol <abc> is ',<abc>.
uline.
<abc> = 30.
write :/ 'Integer variable gv_r is ',gv_r,
/ 'Field Symbol <abc> is ',<abc>.
uline.
data gv_m type string value 'Gensoft'.
assign gv_m to <abc>.
write :/ 'Integer variable gv_r is ',gv_r,
/ 'Field Symbol <abc> is ',<abc>,
/ 'String gv_m is ',gv_m.
5th may
Basic Programming Complete Notes
int x=10;
char y;
float z;
int x,y,z;
scanf, cin,System.in.read
printf,cout,System.out.println
Syntax:
data [:] <variable name> <type/like> <data type> [value <initial value>]
[decimals <no.of decimals>]....
Syntax:
parameters [:] <variable name> <type/like> <data type> [default <default value>]
[obligatory] [lower case].....
3. Write: generates List processing screen(output screen) for displaying the result
Syntax:
4. Constants: used for declaring fixed value variables. It must be initialized at the time
of initialization itself.
Syntax:
Conditional statements:
1. if-else
Syntax:
if <condition 1>.
statements.
statements.
----
statements.
else.
statements.
endif.
Syntax:
case <variable>.
statements.
statements.
----
when others.
statements.
endcase.
3. Check:
Syntax:
check <condition>.
statements.
Looping statements:
1. While-endwhile
Syntax:
while <condition>.
statements.
endwhile.
2. Do-enddo
Syntax 1:
do.
statements.
<Exit condition>.
enddo.
Syntax 2:
do <n> times.
statements.
enddo.
3. Loop-endloop
syntax:
statements.
endloop.
4. Select-endselect
Syntax:
select <query>.
statements.
endselect.
Operators in ABAP:
Arithmetic Operators:
Logical Operators:
AND, OR
Relational Operators:
Access key --> 16 digit secured password used for modifying standard objects
Developer access key --> needs to be provided when we are trying to develop first object in the
registered user (one time task)
Execution of objects:
1. Save (ctrl + s)
Notes:
1. Parameter variable names should not exceed 8 characters and should not contain
special characters.
2. Parameters / Parameter is the statement used for generating selection screen for
reading the input values
3. Default is the option/addition used as part of parameters statement to provide default
values for selection screen fields
4. Obligatory is the option used as part of parameters statement to make a selection
screen field as mandatory
5. By default, numeric data types (integer(i), packed(p), float(f)) are right-justified and
character data types (character( c ), date (d), time (t) are left-justified).
6. We use : (colon chain operator) as part of ABAP statements whenever we perform
multiple operations using single keyword.
7. To check the DOCUMENTATION (for understanding the syntax of statement and its
related options), put the cursor on the relevant abap statement and press F1 key
8. No standard page heading is the option used as part of report statement to suppress
(remove) the default title display in the list processing screen.
9. To generate selection text for a parameter variable, follow the path given below.
10. To change the Date and time formats display, we can use the addition EDIT
MASK as part of write statement.
11. Integers cannot store decimal values, if any decimal value is stored in integer
variable; it will round off to nearest integer. To store the decimal values, we can use
packed data type and use the addition decimals to specify the no. of decimal positions.
Develop and activate the program first, choose the menu go to text elements
selection texts under selection texts tab, provide meaningful text for the parameter
variables, activate.
Reference:
ABAP System Fields:
These are provided by SAP itself and they start with SY-….. . The Values for these System fields
are assigned by SAP itself.
Numeric Values:
By default, Integers cannot store decimal values. If any Decimal value is assigned to
integer variable in single quotes, then the value will be rounded off to the nearest
integer and stored in the integer variable. To store decimal values, we can use P
(Packed) data type and while declaring packed variables, we need to use decimals
addition to specify number of decimal places.
Character Fields:
A variable declared as C (character) can store only single character by default, to store
more number of characters declare the variable as array of characters or as a string data
type.
Selection-screen elements
Selection-screen is used for reading the user input. As part of selection-screen we can design
following selection screen elements.
a. Labels(comment)
b. Input fields
c. Push buttons
d. Checkboxes
e. Radio buttons
f. Blocks
g. Tabbed blocks
Selection-screen begin of block <block name> [with frame title <title variable>.
Selection-screen elements.
As part of ABAP prog.lang, there are many events provided by SAP which are triggered at
different places. These events can be handled to provide dynamic features to the applications;
these events are raised by SAP itself.
1. Initialization.
2. At selection-screen output.
3. At selection-screen on <field>.
4. At selection-screen.
5. At selection-screen on value-request.
6. At selection-screen on help-request.
This is the first event triggered/raised whenever a selection-screen is displayed. This event is
triggered only once in the life time of a selection-screen.
At selection-screen output:
Case 1: Whenever the selection screen is displayed for the first time (triggers after the
initialization event)
This event can be handled to refresh the selection-screen elements dynamically. i.e screen
refreshing logic should be implemented as part of this event.
Parameters <radio button name> radiobutton group <group name> [user-command <function
code>].
This event is triggered whenever the user selects a radio button in the radio button group of a
selection screen. In this case, the function code of the radio button group is captured in the
system field SY-UCOMM and the radio button value is set to X .
At selection-screen:
This event is triggered whenever the user selects/deselects a checkbox of a selection screen. In
this case, the function code of the selected / deselected checkbox is captured in the system
field SY-UCOMM and the value of the checkbox is set to X (if selected) otherwise space (if
deselected).
This event is also triggered when the user performs the following actions on the selection
screen field.
a. Clicking a pushbutton.
At selection-screen on field:
a. This event is triggered whenever the user press enter key in the input field.
b. This event can be handled to validate the field.
Continue Statement:
Whenever continue statement is executed inside a loop, the statements after the continue
statement will be skipped i.e. the rest of the statements will not be executed for the current
iteration and the control jumps to next iteration for condition check. Before the continue
statement is executed, the iteration variable needs to be incremented / decremented
otherwise it leads to infinite execution.
Exit Statement:
Whenever the exit statement is executed inside a loop the control jumps out of the current
loop, if the exit statement is executed independently outside the loop, the control comes out of
the program execution i.e rest of the statements after exit statement will not be executed.
Check statement is used for condition check. If the check condition is true, it executes the
statements after check otherwise ignores it.
String Functions:
Note: Off-set logic is used for extracting the portion of the string.
Field-symbols are a special data structure used for holding any kind of data. i.e it is capable of
storing any kind of data. Field-symbol variable must be enclosed between < and > . We use
the keyword assign to assign a variable value to the field-symbol. Once a variable is assigned
to the field-symbol, there will be a pointer link between the variable and field-symbol, so any
changes made to the data of the variable will automatically reflect the value of field-symbol and
vice versa.
Exception Handling:
- 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 occur.
- 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(parent 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 .
REPORT Z930_PROG17.
INITIALIZATION.
* message 'initialization' type 'I'.
lb1 = 'First Number'.
lb2 = 'Second Number'.
t1 = 'Input Values'.
t2 = 'Operations'.
b1 = 'Addition'.
b2 = 'Difference'.
b3 = 'Product'.
b4 = 'Clear'.
b5 = 'Exit'.
at SELECTION-SCREEN.
case sy-ucomm.
when 'FC5'.
leave PROGRAM.
when 'FC4'.
clear : p_x,
p_y.
when 'FC1'.
clear gv_res.
gv_res = p_x + p_y.
* CONCATENATE 'Sum of Two numbers is ' gv_res into gv_str SEPARATED BY space..
gv_val = gv_res.
CONCATENATE 'Sum of Two numbers is ' gv_val into gv_str SEPARATED BY space..
message gv_str type 'I'.
when 'FC2'.
clear gv_res.
gv_res = p_x - p_y.
gv_val = gv_res.
CONCATENATE 'Difference of Two numbers is ' gv_val into gv_str SEPARATED BY space..
message gv_str type 'I'.
when 'FC3'.
clear gv_res.
gv_res = p_x * p_y.
gv_val = gv_res.
CONCATENATE 'Product of Two numbers is ' gv_val into gv_str RESPECTING BLANK
S.
message gv_str type 'I'.
endcase.
REPORT Z930_PROG18.
* Syntax 1 for declaring structure (work area) (line type) (row type)
data : begin of emp,
empno type i,
ename(20) type c,
empdesig(25) type c,
end of emp.
emp-empno = 6.
emp-ename = 'Ravi'.
emp-empdesig = 'Manager'.
emp-empno = 16.
emp-ename = 'Vamshi'.
emp-empdesig = 'Employee'.
Example: Standard Syntax for declaring Structures and Accessing Structure Fields, =
(Assignment), Move and Move-Corresponding statements
REPORT Z930_PROG19.
uline.
emp2 = emp1. "assignment operator
write :/ 'EMP2 structure after assignment.....'.
write :/ emp2-empno,emp2-ename,emp2-empdesig.
clear emp2.
write :/ 'EMP2 structure after clear.....'.
write :/ emp2-empno,emp2-ename,emp2-empdesig.
uline.
move emp1 to emp2.
write :/ 'EMP2 structure after move.....'.
write :/ emp2-empno,emp2-ename,emp2-empdesig.
clear emp2.
write :/ 'EMP2 structure after clear.....'.
write :/ emp2-empno,emp2-ename,emp2-empdesig.
uline.
move-CORRESPONDING emp1 to emp2.
write :/ 'EMP2 structure after move corresponding'.
write :/ emp2-empno,emp2-ename,emp2-empdesig.
clear emp2.
write :/ 'EMP2 structure after clear.....'.
write :/ emp2-empno,emp2-ename,emp2-empdesig.
Example: Copying Data between two structures – Different no and Different field names
REPORT Z930_PROG20.
clear emp.
emp-empno = 5.
emp-ename = 'Krishna Prasad'.
emp-empdesig = 'Manager'.
write :/ 'EMP structure.....'.
write :/ emp-empno,emp-ename,emp-empdesig.
uline.
types : begin of ty_dept,
deptno type i,
dname(10) type c,
end of ty_dept.
uline.
dept = emp.
write :/ 'DEPT Structure after assigning emp...'.
write :/ dept-deptno,dept-dname.
clear dept.
write :/ 'DEPT Structure after clear...'.
write :/ dept-deptno,dept-dname.
uline.
move emp to dept.
write :/ 'DEPT Structure after move...'.
write :/ dept-deptno,dept-dname.
clear dept.
write :/ 'DEPT Structure after clear...'.
write :/ dept-deptno,dept-dname.
uline.
move-CORRESPONDING emp to dept.
write :/ 'DEPT Structure after move-corresponding...'.
write :/ dept-deptno,dept-dname.
REPORT Z930_PROG21.
clear emp.
emp-empno = 5.
emp-ename = 'Krishna Prasad'.
emp-empdesig = 'Manager'.
write :/ 'EMP structure.....'.
write :/ emp-empno,emp-ename,emp-empdesig.
uline.
types : begin of ty_dept,
dname(10) type c,
deptno type i,
empno type i,
end of ty_dept.
uline.
*dept = emp. "syntax error
REPORT Z930_PROG22.
clear emp.
emp-empno = 5.
emp-ename = 'Krishna Prasad'.
emp-empdesig = 'Manager'.
write :/ 'EMP structure.....'.
write :/ emp-empno,emp-ename,emp-empdesig.
uline.
types : begin of ty_dept,
dname(10) type c,
deptno type i,
empno(3) type c,
end of ty_dept.
uline.
*dept = emp. "syntax error
REPORT Z930_PROG23.
clear emp.
emp-empno = '5'.
emp-ename = 'Krishna Prasad'.
emp-empdesig = 'Manager'.
write :/ 'EMP structure.....'.
write :/ emp-empno,emp-ename,emp-empdesig.
uline.
types : begin of ty_dept,
dname(10) type c,
deptno type i,
empno type i,
end of ty_dept.
uline.
*dept = emp. "syntax error
REPORT Z930_PROG24.
clear emp.
emp-empno = 'A5'.
emp-ename = 'Krishna Prasad'.
emp-empdesig = 'Manager'.
write :/ 'EMP structure.....'.
write :/ emp-empno,emp-ename,emp-empdesig.
uline.
types : begin of ty_dept,
dname(10) type c,
deptno type i,
empno type i,
end of ty_dept.
uline.
*dept = emp. "syntax error
In structures the memory allocation is continuous. All the fields are stored one after the
other.
The size of the structure is equal to sum of the sizes occupied by structure fields.
SYNTAX:
By default, structure fields are initialized to respective default values based on the data
types.
We can copy the data of one structure to another structure by using assignment operator,
move and move-corresponding statements.
In case of assignment (=) and move statement, it only checks for corresponding data types
of the fields and not for names and the no of fields. If any one of the corresponding field
data type is not matching it leads to syntax error.
MOVE CORRESPONDING:
It decreases the performance, because each field of the source structure is compared with
all the fields of the target structure which is time consuming and thereby decreases the
performance.
It may lead to run-time error i.e. While copying the data between two fields it only checks
for matching field s names but not for data types. If data types are not type compatible it
leads to run-time error.
Nested structure:
Syntax:
Syntax:
Types: begin of <type name>,
Field 1,
Field 2,
--- --- --
Field n,
End of <type name>.
Note: Types declaration doesn t allocate any memory; it only provides the template of
the fields (field names and their data types). Types keyword is used for creating user-
defined data type.
2. Based on Types declaration, we can create n no. of instances (structures/work
areas)
Syntax:
Field1,
Field2,
- - - --,
Field k,
0 -> 8kb,
1 ->16kb,
2-> 24kb,----…multiples of 8
Note: In the above syntax, the occurs <n> will specify the initial amount of memory that
needs to be allocated for the internal table. If the initial memory is utilized, the memory
automatically gets increased to the amount of initial size.
Note:
We generally use internal tables to store the data retrieved from database table s,
process the data and then displaying the formatted(processed) data / update it back to
database.
Append :
This statement copies the data from work area to the end of the internal table.
Loop:
The number of times the loop execution depends upon the loop condition and internal
table data.
SORT:
If the sort field is not specified, by default it will be sorted on first character field of
the internal table. If no character fields are available in the internal table, then sorting
will be done on first field of the internal table.
Sy-tabix is the system field which hold s the index position of the internal table.
Sy-index is the system field which stores the iteration value for the looping statements
like while end-while and do enddo .
Describe :
This statement counts the no of records of the internal table and stores the count value in the
system field sy-tfill.
If we use the lines addition as part of describe statement, the count value is stored inside the
program variable specified as part of lines addition.
Syntax:
Describe table <internal table> [ lines <variable> ].
Note: Occurs statement in declaring the internal table allocates initial memory for the internal
table, if the initial memory is utilized, the memory automatically gets extended to the amount
of initial size.
Note: We can use loop statement to process all records / records based on range of indexes /
records based on condition.
In case of above syntax the internal table can be declared either with header or without header.
The above syntax will copy only the structure but not the data.
To copy data from one internal table to other internal table we can use either append
lines statement or directly use the = operator / move statement with [ ] (in case of
internal table with headers).
Append lines: It will copy all the records / range of records (based on indexes) from source
to target internal table.
To delete the records from internal tables, we can use the following:
1. Refresh: It will delete all the records; it is always used only on internal table.
2. Clear: It will delete all records, use [ ] (for internal tables with header). Clear can be used
on normal variables or work areas also.
3. Free: It will delete all the records; it is always used only on internal table. The difference
between refresh and free is refresh clears the data but doesn t de-allocate the memory ,
whereas free statement clears the internal table and gets the internal table to initial
state.
4. Delete: Deletes the records of the internal table based on a condition
5. Delete adjacent duplicates: Deletes adjacent duplicate records from internal table
based on the comparing field. The pre-requisite for using this is the data in the internal
table should be sorted based on the comparing field (field specified in delete adjacent
duplicates statement).
In the first syntax and in second syntax we must use occurs keyword as part of
internal table declaration.
The occurs keyword will allocate some initial memory; this memory automatically gets
extended depending on the usage.
If the allocated memory is not utilized, then there will be memory wastage, to avoid this
we can use following standard syntax .
Step 1: Declare the required fields using the type s declaration. This declaration
provides a template of the internal table and work area.
Syntax:
Note: Types keyword is used for creating a user defined data type. It doesn t allocate any
memory, it only provides template of the fields (field name, field type)
Data : <internal table> type <standard table of>/<sorted table of>/ <hashed table of>
<type name> [with header line].
Note: The default internal table type is standard .
In the above syntax if the internal table is declared without header then perform step 3.
Step 3:
This work area (structure) can be a normal work area or a field symbol work area.
Note: If we use normal work area as part of loop, we need to use into and if we use field-
symbol work area as part of loop, we need to use assigning keyword.
If the read is successful the system field Sy-subrc is set to 0. Other wise 4.
Sy-subrc is a system field used for storing the execution status of ABAP statements.
Read statement can be used either based on the index or based on a condition.
Note: If the read is successful, sy-subrc is set to zero and the content of the record read
is copied to work area specified in read statement
Modify statement:
This statement is used for updating the internal table as well as database table. In case
of modifying the internal tables we need to modify referring to work area.
As part of using modify statement it is always recommended to use transporting
option so that only the fields specified in the transporting addition/option will be
compared between work area and corresponding record in the internal table body. If
the transporting option is not specified, all the fields will be compared between work
area and body which decreases performance.
Using the modify statement inside a loop will decrease the performance.
To overcome this, it is recommended to use the following:
A) Field symbol work area instead of normal work area so that any changes made to the
data of the field-symbol work area will automatically update the corresponding row in
the internal table (field-symbol work area will act as pointer). i.e explicitly we need not
use the modify statement.
B) Use modify statement outside loop using where clause referring to work area.
REPORT Z930_PROG25.
emp-empno = 6.
emp-ename = 'Ravi'.
emp-empdesig = 'Manager'.
append emp. "copies data from header to end of internal table body
clear emp.
emp-empno = 16.
emp-ename = 'Ashok'.
emp-empdesig = 'Employee'.
append emp.
clear emp.
emp-empno = 9.
emp-ename = 'Srinivas'.
emp-empdesig = 'Manager'.
append emp.
clear emp.
emp-empno = 11.
emp-ename = 'Praveen'.
emp-empdesig = 'Employee'.
append emp.
clear emp.
emp-empno = 14.
emp-ename = 'Suraj'.
emp-empdesig = 'Manager'.
append emp.
REPORT Z930_PROG26.
emp-empno = 6.
emp-ename = 'Ravi'.
emp-empdesig = 'Manager'.
append emp. "copies data from header to end of internal table body
clear emp.
emp-empno = 16.
emp-ename = 'Ashok'.
emp-empdesig = 'Employee'.
append emp.
clear emp.
emp-empno = 9.
emp-ename = 'Srinivas'.
emp-empdesig = 'Manager'.
append emp.
clear emp.
emp-empno = 11.
emp-ename = 'Praveen'.
emp-empdesig = 'Employee'.
append emp.
clear emp.
emp-empno = 14.
emp-ename = 'Suraj'.
emp-empdesig = 'Manager'.
append emp.
sort emp. "sorts on first character field if available, otherwise sorts on first field
write :/ 'Data in internal table after default sort...'.
loop at emp.
write :/ emp-empno,emp-ename,emp-empdesig.
endloop.
ULINE.
*data gv_cnt type i.
*describe table emp lines gv_cnt.
*write :/ 'No of records in emp...',gv_cnt. "(or)
describe table emp.
write :/ 'No of records in emp...',sy-tfill.
Example: Copying data between internal tables, clearing internal table data
REPORT Z930_PROG27.
emp-empno = 6.
emp-ename = 'Ravi'.
emp-empdesig = 'Manager'.
append emp.
clear emp.
emp-empno = 16.
emp-ename = 'Ashok'.
emp-empdesig = 'Employee'.
append emp.
clear emp.
emp-empno = 9.
emp-ename = 'Srinivas'.
emp-empdesig = 'Manager'.
append emp.
clear emp.
emp-empno = 11.
emp-ename = 'Praveen'.
emp-empdesig = 'Employee'.
append emp.
clear emp.
emp-empno = 14.
emp-ename = 'Suraj'.
emp-empdesig = 'Manager'.
append emp.
uline.
data emp2 like emp OCCURS 0 WITH HEADER LINE. "copies only fields(structure)
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2....',sy-tfill.
uline.
emp2 = emp. "copies data from header to header
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2....',sy-tfill.
uline.
emp2[] = emp[]. "copies data from body to body
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2....',sy-tfill.
uline.
clear emp2. "clears header
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2 after clear....',sy-tfill.
uline.
clear emp2[]. "clears body
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2 after clear[]....',sy-tfill.
uline.
append lines of emp to emp2.
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2 after append lines....',sy-tfill.
uline.
refresh emp2.
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2 after refresh....',sy-tfill.
uline.
append lines of emp from 2 to 4 to emp2.
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2 after append lines from source to target index....',sy-tfill.
uline.
free emp2.
DESCRIBE TABLE emp2.
write :/ 'No of records in emp2 after free....',sy-tfill.
Example: Standard Internal table with default Header line
REPORT Z930_PROG28.
*data t_emp type STANDARD TABLE OF ty_emp with HEADER LINE. "(or)
data t_emp type TABLE OF ty_emp with HEADER LINE. "default is standard
loop at t_emp.
write :/ t_emp-empno,
t_emp-ename,
t_emp-empdesig.
endloop.
Example: Standard Internal table without default Header line, Explicit Normal work area and
Explicit Field-symbol work area
REPORT Z930_PROG29.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
uline.
data t_emp2 type table of ty_emp.
DESCRIBE TABLE t_emp2.
write :/ 'No of records in t_emp2....',sy-tfill.
uline.
append lines of t_emp to t_emp2.
DESCRIBE TABLE t_emp2.
write :/ 'No of records in t_emp2 after appending lines of t_emp....',sy-tfill.
uline.
write :/ 'Data in internal table t_emp2...'.
*loop at t_emp2 into wa_emp.
* write :/ wa_emp-empno,
* wa_emp-ename,
* wa_emp-empdesig.
*endloop. "(or)
REPORT Z930_PROG30.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 15.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Karan'.
wa_emp-empdesig = 'Manager'.
insert wa_emp into t_emp index 2.
write :/ 'Data in internal table t_emp after insert into index 2..'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
clear wa_emp.
wa_emp-empno = 6.
wa_emp-ename = 'Mani'.
wa_emp-empdesig = 'Manager'.
insert wa_emp into table t_emp.
Example: Standard Internal table with non-unique key specification field and behavior of sort
statement
REPORT Z930_PROG31.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 15.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
uline.
*data t_emp2 type TABLE OF ty_emp with UNIQUE key empno. "syntax error
data t_emp2 type TABLE OF ty_emp with NON-UNIQUE key empno.
DESCRIBE TABLE t_emp2.
write :/ 'No of records in t_emp2....',sy-tfill.
uline.
append lines of t_emp to t_emp2.
DESCRIBE TABLE t_emp2.
write :/ 'No of records in t_emp2 after append lines....',sy-tfill.
uline.
write :/ 'Data in internal table t_emp2...'.
loop at t_emp2 into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
sort t_emp.
write :/ 'Data in internal table t_emp after default sort...'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
sort t_emp2. "sorts on key field - empno
write :/ 'Data in internal table t_emp2 after default sort...'.
loop at t_emp2 into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Rajesh'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp2.
uline.
write :/ 'Data in internal table t_emp2 after inserting duplicate key field value...'.
loop at t_emp2 into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
Example: Standard Internal table-Read Statement
REPORT Z930_PROG32.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 15.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kavitha'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
write :/ 'Data in internal table t_emp...'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
clear wa_emp.
read table t_emp into wa_emp index 2. "indexed search
if sy-subrc eq 0.
write :/ 'Record with index 2 is found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with index 2 not found...'.
endif.
uline.
clear wa_emp.
sort t_emp by empno.
read table t_emp into wa_emp with key empno = 3. "linear search/sequential search
if sy-subrc eq 0.
write :/ 'Record with empno 3 is found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with empno 3 is not found...'.
endif.
uline.
clear wa_emp.
read table t_emp into wa_emp with key empno = 9
TRANSPORTING empno ename.
if sy-subrc eq 0.
write :/ 'Record with empno 9 is found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with empno 9 is not found...'.
endif.
uline.
*clear wa_emp.
*read table t_emp into wa_emp with key empno = 5
* TRANSPORTING NO FIELDS. "warning because work area is specified
read table t_emp with key empno = 5
TRANSPORTING NO FIELDS.
if sy-subrc eq 0.
write :/ 'Record with empno 5 is found...'.
else.
write :/ 'Record with empno 5 is not found...'.
endif.
uline.
clear wa_emp.
read table t_emp into wa_emp
with key empno = 15 BINARY SEARCH.
if sy-subrc eq 0.
write :/ 'Record with empno 15 is found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with empno 15 is not found...'.
endif.
REPORT Z930_PROG33.
*data : t_emp type SORTED TABLE OF ty_emp, "syntax error as key is missing
*data : t_emp type SORTED TABLE OF ty_emp with NON-UNIQUE key empno, "(or)
data : t_emp type SORTED TABLE OF ty_emp with UNIQUE key empno,
wa_emp type ty_emp.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
Example: Sorted Internal tables – Append Statement – Runtime Error – Sorting Sequence not
ensured
REPORT Z930_PROG34.
data : t_emp type SORTED TABLE OF ty_emp with UNIQUE key empno,
wa_emp type ty_emp.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 11.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp. "leads to runtime error as sorting sequence not maintained
Example: Sorted Internal tables – Insert Statement – Sorting Sequence automatically taken
care by Insert
REPORT Z930_PROG35.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 11.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
*append wa_emp to t_emp. "leads to runtime error as sorting sequence not maintained
insert wa_emp into table t_emp.
Example: Sorted Internal tables – Append Statement – Runtime Error – Duplicate entries
found for unique key field
REPORT Z930_PROG36.
data : t_emp type SORTED TABLE OF ty_emp with UNIQUE key empno,
wa_emp type ty_emp.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
Example: Sorted Internal tables – Insert Statement - Duplicate entries ignored for unique key
field by Insert
REPORT Z930_PROG37.
data : t_emp type SORTED TABLE OF ty_emp with UNIQUE key empno,
wa_emp type ty_emp.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
*append wa_emp to t_emp. "leads to runtime error as duplicate key field value found
insert wa_emp into table t_emp.
REPORT Z930_PROG38.
data : t_emp type SORTED TABLE OF ty_emp with UNIQUE key empno,
wa_emp type ty_emp.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 10.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
*insert wa_emp into t_emp index 3. "runtime error
insert wa_emp into t_emp index 4.
uline.
clear wa_emp.
read table t_emp into wa_emp index 2. "indexed search
if sy-subrc eq 0.
write :/ 'Record with index 2 found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with index 2 not found...'.
endif.
uline.
clear wa_emp.
read table t_emp into wa_emp with key empno = 10. "linear search
if sy-subrc eq 0.
write :/ 'Record with empno 10 found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with empno 10 not found...'.
endif.
uline.
clear wa_emp.
read table t_emp into wa_emp with key empno = 10 BINARY SEARCH. "binary search
if sy-subrc eq 0.
write :/ 'Record with empno 10 found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with empno 10 not found...'.
endif.
REPORT Z930_PROG39.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
*append wa_emp to t_emp. "syntax error
insert wa_emp into table t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Mahesh'.
wa_emp-empdesig = 'Employee'.
insert wa_emp into table t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Manager'.
insert wa_emp into table t_emp.
clear wa_emp.
wa_emp-empno = 14.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
insert wa_emp into table t_emp.
clear wa_emp.
wa_emp-empno = 10.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
insert wa_emp into table t_emp.
sort t_emp.
uline.
write :/ 'Data after default sort....'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
clear wa_emp.
*read table t_emp into wa_emp index 2. "syntax error
read table t_emp into wa_emp with key empno = 10. "linear search
if sy-subrc eq 0.
write :/ 'Record with empno 10 found...'.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
else.
write :/ 'Record with empno 10 not found...'.
endif.
*read table t_emp into wa_emp with key empno = 10 BINARY SEARCH. "syntax error
Example: Modifying content of internal tables
REPORT Z930_PROG40.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 15.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kavitha'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 34.
wa_emp-ename = 'Kamal'.
wa_emp-empdesig = 'Supervisor'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 1.
wa_emp-ename = 'Kranthi'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 27.
wa_emp-ename = 'Ram'.
wa_emp-empdesig = 'Supervisor'.
append wa_emp to t_emp.
uline.
write :/ 'Data in internal table t_emp after using modify inside loop...'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
FIELD-SYMBOLS <abc> like line of t_emp.
loop at t_emp ASSIGNING <abc> where empdesig = 'Employee'.
<abc>-empdesig = 'Sr.Employee'.
endloop.
write :/ 'Data in internal table t_emp after changes to field symbol work area...'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
clear wa_emp.
wa_emp-empdesig = 'Sr.Supervisor'.
modify t_emp from wa_emp TRANSPORTING empdesig
where empdesig = 'Supervisor'.
write :/ 'Data in internal table t_emp after using modify with where clause...'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
REPORT Z930_PROG41.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 15.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kiran'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 9.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Kavitha'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 34.
wa_emp-ename = 'Kamal'.
wa_emp-empdesig = 'Supervisor'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 87.
wa_emp-ename = 'Soujash'.
wa_emp-empdesig = 'CEO'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 1.
wa_emp-ename = 'Kranthi'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 67.
wa_emp-ename = 'Rajneesh'.
wa_emp-empdesig = 'CEO'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 27.
wa_emp-ename = 'Ram'.
wa_emp-empdesig = 'Supervisor'.
append wa_emp to t_emp.
uline.
write :/ 'Data after deleting CEOs...'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
uline.
write :/ 'Data after using deleteing adjacent duplicate empdesig.....'.
loop at t_emp into wa_emp.
write :/ wa_emp-empno,
wa_emp-ename,
wa_emp-empdesig.
endloop.
DEBUGGING
To take the program to Debugging mode we need to set Break points in the
program.
A breakpoint is a signal to the system which stop s the program execution whenever it is
encountered.
We can set the breakpoint s in two ways:
F5 (Single step):
It executes single step at a time.
F6 (Execute):
It is similar to F5 but when F6 is pressed at the time of calling the block s (subroutine,
function module, method); the entire block will be executed as a single step without the
control going to block definition.
F7 (Return):
When F7 is pressed inside a block definition the control comes out
of the current block by executing the remaining steps of the block as a single step.
F8 (run to):
Note: We cannot debug the variable declarations; we can debug only the executable
statements.
It is recommended not to set the break-points by using break-point keyword. Because
there is a possibility that developer might forgot to remove the break-point keyword
before transporting the object to next configured client.
If it is transported as it is, the program execution will be halted and the control will be
taken to debugging mode which is an escalation in quality/production system.
MODULARIZATION TECHNIQUES
A block is a set/collection of statements which is defined only once and can be called / accessed
any no. of times.
Advantages of Modularization:
Increases reusability.
Subroutines
Include programs
Macros(HR-ABAP)
Function modules
Methods(OOPS ABAP)
Subroutines:
It is a block of statements, which is defined only once and can be called any number of times.
Internal subroutine
External subroutine
Internal subroutine:
statements.
Endform.
External subroutine:
They are defined in external programs and called from other programs.
Subroutine pool:
Syntax 1
Syntax 2
Note: External program can be either another executable program or subroutine pool.
1. Using
2. Changing
3. Tables
The parameters specified as part of subroutine definition are called as formal parameters and
the parameters specified at the time of calling the subroutine are called as actual parameters.
Using:
Using is the keyword used as part of subroutine definition and subroutine calling to deal with
standard data types as parameters.
The formal parameters and actual parameters names can be same or different.
The number of formal parameters depends upon the number of actual parameters.
The number of return parameters depends upon number of changing and tables parameters.
The changing and tables parameters can be used for both passing the values as well as
returning the values.
2. Pass by value.
Pass by reference:
In this, the address of actual parameters are copied to formal parameters. So, any changes
made to the formal parameters variables will automatically reflect the content of the actual
parameters.
Pass by value:
In this the values of actual parameters are copied to formal parameters. So, any changes made
to the data of formal parameters will not reflect the content of the actual parameters. For this,
we need to use the keyword value as part of formal parameters.
In this case, if we perform the operations like delete and modify on formal internal table with
where clause, we must specify the structure of the formal internal table and it is done by using
the keyword structure as part of subroutine definition.
In this case, any changes made to the data of the formal internal table, will automatically reflect
actual internal table data.
INCLUDE PROGRAMS:
It is a reusable repository object, which can be used for declaring global variables, subroutines,
module definitions and class definitions.
To use the components of include program inside other repository objects, we must include the
include program by using include keyword.
Syntax:
It is recommended to include the include program at the beginning of the repository object.
If the include program contains any block definitions (subroutine or module definitions or class
definitions) and if the include program is included at the beginning of the executable program,
it leads to syntax error statement is not accessible . To avoid this, explicitly we need to handle
the event ͞start-of-selection͟ after include statement to indicate the starting point of program
execution.
Function modules:
It is a set of statements which are defined only once and can be called any no. of times. We can
create custom function modules by using function builder tool (se37).
There are many standard function modules provided by SAP itself. These function modules can
be called/accessed in different programs by passing values to the appropriate parameters.
Function group:
Before creating custom function module, we need to create or consider a function group which
already exists.
This is called as top include program, which can be used for declaring global variables,
subroutine, module definitions and class definitions.
The components of the top include program can be accessed by all the function modules of
that particular function group.
It is reserved for SAP internal use. As part of this include, SAP generates sub includes (i.e),
whenever a new function module is created, a sub include will be generated on behalf of that
function module.
The no of sub includes depends upon the no. of function modules of that function group.
Statements.
Endfunction.
Before calling any function module, we must check the signature of the function module to
understand the parameter types, return values, default values, pass by value or pass by
reference, optional and mandatory parameters.
1. Import
2. Export
3. Tables
4. Changing
Import parameters:
Export parameters:
Changing parameters:
Acts as both import and export, we go for changing parameters when we need to use same
variable for passing the value as well as receiving the return value.
Tables:
Are used for dealing with internal tables as parameters to function modules , these internal
tables must refer to dictionary structures created in se11.
Example: Internal Vs External Subroutines, Passing parameters to subroutines, Subroutine
pool
Executable program
REPORT Z930_PROG42.
write :/ 'Welcome'.
perform sub1.
write :/ 'Hi'.
perform sub1.
write :/ 'Hello'.
perform sub1.
perform sub2.
write :/ 'Bye'.
uline.
*perform sub3. "syntax error as no internal subroutine sub3 is defined
perform sub3 in program z930_prog43.
perform sub4 in program z930_prog43. "(or)
perform sub4(z930_prog43).
uline.
*perform sub5 using 20 30. "syntax error as no internal subroutine sub5 is defined
perform sub5(z930_subpool) using 20 30. "actual parameters
*perform sub5(z930_subpool) using 12. "syntax error
data : gv_r1 type i value 10,
gv_r2 type i value 5,
gv_r3 type i.
perform sub6(z930_subpool) using gv_r1 gv_r2 CHANGING gv_r3.
write :/ 'Division is ',gv_r3.
form sub2.
write :/ 'Inside subroutine sub2....'.
endform.
form sub1.
write :/ 'CORE ABAP'.
write :/ 'OOPS ABAP'.
write :/ 'CROSS APPS'.
endform.
Executable program containing external subroutines
REPORT Z930_PROG43.
form sub3.
gv_res = gv_x + gv_y.
write :/ 'Sum is ',gv_res.
endform.
form sub4.
gv_res = gv_x - gv_y.
write :/ 'Difference is ',gv_res.
endform.
PROGRAM Z930_SUBPOOL.
REPORT Z930_PROG44.
clear wa_emp.
wa_emp-empno = 5.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 8.
wa_emp-ename = 'Srinivas'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 6.
wa_emp-ename = 'Ashok'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 4.
wa_emp-ename = 'Sourabh'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
REPORT Z930_PROG45.
write :/ 'Values of gv_x and gv_y after calling subroutine are :',gv_x,gv_y.
REPORT Z930_PROG46.
write :/ 'Values of gv_x and gv_y after calling subroutine are :',gv_x,gv_y.
form abc using value(m) value(n). "formal parameters
data lv_z type i. "local variable
lv_z = m.
m = n.
n = lv_z.
endform.
Example: Including Include Program containing only variable declarations
Include Program:
Executable Program:
REPORT Z930_PROG47.
include zincl1.
gv_x = 10.
gv_y = 20.
gv_z = gv_x + gv_y.
write :/ 'Sum is ',gv_z.
uline.
clear wa_emp.
wa_emp-empno = 6.
wa_emp-ename = 'Ravi'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 16.
wa_emp-ename = 'Vamshi'.
wa_emp-empdesig = 'Employee'.
append wa_emp to t_emp.
clear wa_emp.
wa_emp-empno = 3.
wa_emp-ename = 'Manoj'.
wa_emp-empdesig = 'Manager'.
append wa_emp to t_emp.
Include Program:
endform.
Executable Program:
REPORT Z930_PROG48.
include zincl2.
START-OF-SELECTION.
write :/ 'Begin of executable program....'.
perform sub1.
*perform sub2. "syntax error
perform sub2 using 10 2.
Example: Calling Function Module without any parameters
Executable program:
REPORT Z930_PROG49.
write :/ 'Begin of executable program.....'.
*call function 'z930fm1'. "RUNTIME ERROR - as F.M name specified in lower case
call function 'Z930FM1'.
REPORT Z930_PROG50.
REPORT Z930_PROG51.
REPORT Z930_PROG52.
uline.
clear : gv_r1,
gv_r2.
uline.
clear : gv_r1,
gv_r2.
REPORT Z930_PROG53.
REPORT Z930_PROG54.
if sy-subrc eq 0.
write :/ 'Division is ',gv_res.
elseif sy-subrc eq 1.
message 'Cannot divide by zero' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
To interact with the SAP Database from ABAP applications, we use two types of SQL (Standard
query language) statements.
1. Open SQL
2. Native SQL
Native SQL: Every database vendor provides their own set of SQL statements used for
interacting with their own databases. Native SQL statements are enclosed between
͚EXEC SQL͛ and ͚ENDEXEC͛.
Open SQL: is not specific to any database. i.e. they can be used to interact with any of
the databases. These open SQL statements are internally converted to native SQL by a
tool called as database interface.
But it is recommended to use Open sql only because in future if the customer changes
the database also, we need not modify the objects.
1. Analyze the db table and the required fields (field name, data types, sequence)
which needs to be retrieved
3. Retrieve the data from the database tables and store the same in the required target
variables
Select single: is an open sql statement used for retrieving single record from the
database table. Whenever we use select single, it is recommended to use where clause
in the select query comparing with primary key field to ensure appropriate record is
retrieved (if available).
Select..endSelect: is a open SQL statement used for retrieving multiple records from the
database. It is a looping statement, where in, for each select statement execution, it
retrieves single record, and the no. of times the select query execution depends on the
no. of records satisfying the condition. If there are more select queries, it increases
network traffic and thereby decreases performance. Because of this reason, it is
recommended to minimize the usage of select..endselect and instead use ͚select into
table͛ statement and retrieve the required no. of records using one select statement
execution and store the retrieved data into an internal table.
CURSORS:
A cursor is a data structure which can be used for holding multiple records.
Syntax:
Syntax:
Note: Only select statements can be associated with the cursors. Whenever a cursor is
opened, the select query associated with the cursor will be executed and the result of
the select query is stored in the cursor which is called as activeset.
Syntax:
Note: Fetch statement reads content of the current cursor line into target fields. If the
fetch is successful, sy-subrc is set to 0 otherwise 4.
Syntax:
Syntax:
EXEC SQL.
Open <cursor name> for <select query>.
ENDEXEC.
Syntax:
EXEC SQL.
Fetch next <cursor name> into <target fields>.
ENDEXEC.
Syntax:
EXEC SQL.
Close <cursor name>.
ENDEXEC.
This event is triggered when the user presses ͞F4͟ Key in a selection screen input field.
This event can be handled to provide ͞custom F4͞help for a selection screen input field. As part
of this event, we can call the function module F4IF_INT_TABLE_VALUE_REQUEST to populate
custom F4 values
This event is triggered when the user press ͞F1͟ key on a selection screen field.
This event can be handled to provide ͞custom f1 help͟ for the selection screen field.
Native Sql and Open Sql
REPORT Z930_PROG55.
select single
land1 name1 ort01
from kna1
into wa_kna1
where kunnr = p_kunnr.
if sy-subrc eq 0.
write :/ 'Customer Country :',wa_kna1-land1,
/ 'Customer Name :',wa_kna1-name1,
/ 'Customer City :',wa_kna1-ort01.
else.
write :/ 'No Customer'.
endif.
REPORT ZDB2.
EXEC SQL.
select land1, name1, ort01
from kna1
into :gv_land1,:gv_name1,:gv_ort01
where kunnr = :p_kunnr
endexec.
if sy-subrc eq 0.
write :/ 'Customer Found....'.
write :/ 'Customer Country :',gv_land1,
/ 'Customer Name :',gv_name1,
/ 'Customer City :',gv_ort01.
else. "sy-subrc eq 4
write :/ 'Customer Not Found'.
endif.
Reading multiple records
Example: Reading Multiple Records from Database Table – OPEN SQL (select into table)
REPORT Z930_PROG56.
Example: Custom F4 Help and Custom F1 Help for Selection-Screen Input Field
REPORT Z930_PROG57.
select single
land1 name1 ort01
from kna1
into wa_kna1
where kunnr = p_kunnr.
if sy-subrc eq 0.
write :/ 'Customer Country :',wa_kna1-land1,
/ 'Customer Name :',wa_kna1-name1,
/ 'Customer City :',wa_kna1-ort01.
else.
write :/ 'No Customer'.
endif.
1. Tables
2. Views
3. Data elements
4. Domains
5. Type Groups
6. Search Helps
7. Table Types
8. Lock objects
9. Structures
Master data:
Example:- Empno, ename, customer no, customer name ,bank account no, bank account holder
name, material data, vendor data.
Transaction data:
Enquiry form, quotation, purchase order document, sales order document, billing document,
delivery schedule document.
Every business document contains 1 header record and one or more item record s.
Key fields mandt (client), vbeln (billing document no), posnr (item no)
Other header and item tables: - Sales Documents (VBAK and VBAP),
Purchase Documents (EKKO and EKPO)
As part of database tables we can directly use the standard tables, enhance the
standard table (adding fields).
We can also create the custom tables for storing the customer specific data.
Primary key:
In SAP, every table must contain minimum 1 key field and max. 16 primary fields. Primary key
fields must be at the beginning of the table.
Based on the client concept, the database tables are classified into two types.
The tables which contains MANDT as first field is called client dependent.
The records in these tables are specific to the client i.e. the record inserted in one client will not
available in other client.
Eg: KNA1, MARA, LFA1, VBAK, VBAP, EKKO, EKPO, VBRK, VBRP
Table creation:
A table is dictionary object which is a collection of rows (records) and columns (fields)
iv. Declare and define events (if required) at the table maintenance level.
1. Delivery class.
Delivery class:
A -> application table used for storing master and transaction data.
Note:
In this we can only view the data but we can t perform the operations like insertion,
deletion and modification.
It supports all the operations i.e we can view, insert , delete and modify.
Technical settings:
1. Data class.
2. Size category
Data class:
It specifies the schema (partition) in which the table as to be stored. As an ABAP Consultant we
will use only Master Schema (APPL0) and Transaction schema (APPL1).
Size category:
It specifies the initial amount of memory that needs to be allocated for the database table.
When the initial memory is utilized, the memory gets extended automatically to the
amount of initial size.
In size category the range of number of data records depends upon structure of the
table .
Enhancement category:
Table maintenance:
After creating every database table, ABAP consultant must generate Table Maintenance.
The table maintenance allows the end user to maintain the table for performing the
operations like insertion, deletion, Modification and view the data (display).
A function group is an object which stores the objects related to table maintenance.
I.e. dependent objects (screens, subroutines, f.m s) related to table maintenance are
stored inside function group.
i. One step:
In one step only one screen is generated called as overview screen in which all the CRUD
(create, read, update and delete) operations are performed.
In two step, Two screens will be generated, overview screen and single screen.
In overview screen we can only view the data, delete the data and modify the data.
2. In SE11, navigate to the table, choose the menu utilities table maintenance
generator
Once a table maintenance is generated, we can maintain the table using the T-code
SM30 .
To minimize the process of table maintenance, we need to create custom t-code for
every table maintenance
SE93 .provide custom t-code (ZTEMP), create pro ide short te t … , hoose the
radiobutton Transaction with parameters Provide Transaction (SM30), select the checkbox
skip initial screen , in gui support select the checkbox sap gui for windows and provide
default values for the skipped screen at the end
Viewname z830emp
Update X
Note: For collecting screen field names, goto sm30 initial screen, press f1 in table/view field and
collect the screen field name, similarly put focus on maintain button, press f1 and collect the
function code (upd) (equal to update)
Note: Whenever we create t-code for any object, select the check box SAP GUI for windows ,
otherwise t-code cannot be used (incomplete).
Data element: is a reusable dictionary object which provides description for the field. I.e. the
description (labels) maintained at data element level will automatically appear on the screen
wherever the data element is referred. It can be created by referring to a direct data type /
referring to a domain. We can also associate a search help (f4 help) as part of data element.
Domain: is a reusable dictionary object which stores technical properties of the field like data
t pe, size, fi ed alues, alue ta le….
Note:
If it is client dependent table we have to give minimum two primary key fields otherwise if only
mandt is primary key field then we can maintain maximum of single record.
Once a dictionary structure is created, we can include the dictionary structure in other
dictionary structures / database tables by using .include keyword.
We can also include dictionary structures inside local structures of repository objects using the
statements include structure <structure name> or include type <structure name>
Dictionary structure:
REPORT ZUSEGLOBALSTR.
wa_emp-empno = 6.
wa_emp-ename = 'Ravi'.
wa_emp-jdate = sy-datum.
wa_emp-jtime = sy-uzeit.
wa_emp-empdesig = 'Manager'.
write :/ wa_emp-empno,
/ wa_emp-ename,
/ wa_emp-jdate,
/ wa_emp-jtime,
/ wa_emp-empdesig.
Note: Once a table maintenance is generated and later on if we make any changes to the table
like adding ne fields, hange in field la el/data t pe… , these changes will not reflect the
existing table maintenance. For reflecting these changes, we need to delete the existing table
maintenance and re-generate the same.
We can define and implement the events as part of table maintenance to handle user
actions.These events are implemented in the subroutine which is stored in a include program of
the function group.
Navigation: In the table maintenance screen, choose the menu environment modification
events, click on new entries button, provide the following
To define the subroutine, click on the corresponding editor button, choose new include,
continue.
form abc.
z730employee-jdate = sy-datum.
z730employee-jtime = sy-uzeit.
endform.
Note: After Implementing events at table level, we need to activate the function group of table
maintenance so that the include programs of that function group gets adjusted otherwise when
we maintain the table, it generates runtime error.
Type groups:
All the components in the type group must prefix with type group name followed by
_.
Inside the type group we can use only types and constant keywords.
To use the components of the type group inside the repository objects, We must
declare the type group by using the keyword type-pools" .
TYPE-POOL ZABC .
uline.
data wa_emp type zabc_emp.
wa_emp-empno = 6.
wa_emp-ename = 'Raju'.
wa_emp-empdesig = 'Manager'.
write :/ wa_emp-empno,
/ wa_emp-ename,
/ wa_emp-empdesig.
Indexes:
Primary index:
As a developer we can create only a secondary index and it can be created on non-
primary key fields.
Secondary indexes are of two types:
1. Unique. 2. Non-unique.
Views:
A view is a reusable dictionary object which doesn t exist physically i.e. it is virtual table
(IMAGINARY TABLE). The data in the view will be populated only in the runtime. i.e a view
doesn t hold any data by default. Views are used for hiding the original table names, hiding field
names, restricting the access to table data, to read data from one or more tables. Views are
created on top of database tables.
i. Database view
Database view:
A database view created on single table can be Read only (or) Read and Change . I.e.
the changes made to the data at the view level will automatically reflect the
corresponding base table and vice versa.
We go for projection view, whenever we need to share complete data of the base
table but with limited fields.
For both database and projection view s we can t generate Table Maintenance.
We create foreign key relationship between two tables to maintain data consistency. i.e
the data of one table is based on data of other table.
To create a foreign key relationship between two tables, the two tables must
contain at least one field which is having common domain and in one of the table
the common field should be a primary key field and this table is considered as check
table as it maintains unique values for that common field.
On the other table common field, we create foreign key which is called as foreign
key table.
I.E. We need to insert a child row (record in the foreign key table) only when there
is a corresponding record in parent record (records in parent table->check table).
Example:
Fields:
Fields:
empno zemp_num
ename zename
empdesig zempdesig
Maintenance view:
This is always created on single table, based on the foreign key table selected, SAP
proposes join condition.
Material tables:
Relationship:- Each Material of MARA table can contain zero / one /more plants in MARC.
EACH Material plant of MARC can contain zero / one / more storage
locations in MARD.
Whenever a table field or structure field contains curr (currency) or Quan (quantity) fields, we
must specify reference table and reference field.
The reference table can be same table (or) external table and reference field can be same table
field (or) external table field.
The reference data type for (curr) currency is cuky and reference data type for (quan) quantity
is unit .
A Table type can refer to a direct data type / line type (structure)/ reference type (class or
interface)
report z830_usettype1.
data gt_ttype type z830ttype1. "internal table
data gs_ttype like line of gt_ttype."work area/structure
gs_ttype = '10'.
append gs_ttype to gt_ttype.
gs_ttype = '20'.
append gs_ttype to gt_ttype.
gs_ttype = '30'.
append gs_ttype to gt_ttype.
report z830_usettype2.
gs_emp-empno = 5.
gs_emp-ename = 'ravi'.
gs_emp-empdesig = 'ceo'.
append gs_emp to gt_emp.
gs_emp-empno = 15.
gs_emp-ename = 'ramu'.
gs_emp-empdesig = 'ceo'.
append gs_emp to gt_emp.
gs_emp-empno = 3.
gs_emp-ename = 'krishna'.
gs_emp-empdesig = 'director'.
append gs_emp to gt_emp.
Lock Objects:
1. They are used for performing row-level locking of the table data
2. By Default, Object level locking (Repository / Dictionary objects) is taken care by SAP
itself. i.e only one user can edit an object at any point of time, other users can only read
the object.
3. Lock Objects names must start with EZ (or) EY and locking is done based on primary
key field/s
1. Exclusive / Write Lock In this, only one user can read or edit the locked record. If
other users request for the Exclusive lock, his request will be rejected but the request is
stored in the queue. Once the first user releases the exclusive lock, the exclusive lock
access is given to other user in the queue.
2. Shared / Read Lock: In this, multiple users can read the locked record and if a user
modifies the locked record, the modified data is not accessible to other users.
3. Exclusive but not cumulative: It is similar to Exclusive lock, but other users request is
not stored in the queue, but instead the others users have to send the fresh request.
LOCK OBJECTS CREATION AND USAGE
Activate, SAP generates 2 function modules, check them using go to menu lock modules
Using Lock objects in Executable programs:
report zlockcustomer.
if sy-subrc eq 1.
message 'Customer No is Locked' type 'E'.
endif.
at user-command.
case sy-ucomm.
when 'FC2'.
leave program.
when 'FC1'.
* Release the lock
call function 'DEQUEUE_EZLOCKCUSTOMER'
exporting
mode_kna1 = 'E'
mandt = sy-mandt
kunnr = p_kunnr.
endcase.
Note: To test Lock object functionality, run the above two programs in 2 sessions and provide
customer no in one session, execute, displays output. In another session, provide same
customer no, it says the record is locked. Now, in the first session unlock the record by clicking
on the user defined button release lock in the application toolbar and execute the same
customer in the second session, now it displays data.
Note: Set pf-status <status name> is used for creating user-defined GUI status and using this
we can invoke the menu painter tool (SE41) where we can manage the menu bar, standard
toolbar and application toolbar. Whenever we define our custom GUI status, SAP looses
functionality of some of the std.toolbar buttons , in order to enable them, assign a function
code and implement the logic in the at user-command event.When the user interacts with
menu bar items / std.toolbar buttons / appl. Toolbar buttons, SAP triggers AT USER-
COMMAND button and the corresponding function code will be captured in the system field
SY-UCOMM (function code is always captured in upper case).To Invoke the Menu painter tool,
double click on GUI status name in the set pf-status statement.
It is a reusable dictionary object used for providing list of values as input help to the user.
Once a Search help is created, we can associate the search help at 3 different levels:
1. Elementary Search Help provides single input path for list of values
report zattachsearchhelp.
Executable program: Attaching search help to the module pool screen input field properties:
Search Help Selection Method: As part of creating Elementary Search Help, We need to provide
the selection method. This selection method can be either a database table or database view or
help view. We go for database table when we need to get the entries of search help (f4 values)
from a single table. We go for views when we need to get the entries of search help (f4 values)
from multiple tables. In case of database view created on multiple tables, it implements inner
join and in case of help view created on multiple tables, it implements left outer join.
Table 1: ztest_emp
Table 1 entries:
REPORT ZUSEDBVIEW.
Data Class
Differences between dbview/prjview/mntncview
Inner Joins
Left Outer Join
Lock Objects
Locking-Object Level
View Cluster
selection method ---> table --> to get f4 values from single table
ZTEST_EMP->7 ZTEST_DEPT->3
DNO DEPTNO
10 10
10 20
20 50
20
30
30
40
10
10
20
20
10
10
20
20
30 0 space space
30 0 space space
40 0 space space
Select-options:
It generates a selection-screen for reading ranges of input values. It is an internal table created
in the run time by SAP based on the select-option field. It contains following structure:
͚E͛ considers values before lower limit and after upper limit
Note: In the above syntax, if the target field is referring to dictionary structure field,
then target dictionary structure should be declared explicitly using ͚tables͛ keyword.
͚Tables͛ KEYWORD will create work area with all the fields of the dictionary structure
which is a performance issue. Because of this reason, it is recommended not to declare
select-option referring to dictionary structure.
Ranges:
It is used for holding range of values. It is an internal table created in the run time based on the
field. It contains same structure as that of select-options:
Order by Clause: We can use order by clause in select query to retrieve the data in sorted order
of the specified order by field. It is recommended not to user order by clause, because it
performs sorting at the time of retrieving data from database which increases load on DB server
which degrades the performance. We can avoid by using sort statement on internal table as it
gets executed on application server.
REPORT Z930_PROG58.
Example: Select Options (Default values using ͚Initialization͛ Event, Order by Clause)
REPORT Z930_PROG59.
INITIALIZATION.
so_kunnr-low = '2000'.
so_kunnr-high = '2010'.
append so_kunnr.
so_kunnr-sign = 'I'.
so_kunnr-option = 'BT'.
so_kunnr-low = '3000'.
unpack so_kunnr-low to so_kunnr-low.
so_kunnr-high = '3010'.
unpack so_kunnr-high to so_kunnr-high.
append so_kunnr.
START-OF-SELECTION.
select kunnr land1 name1 ort01
from kna1
into table t_kna1
where kunnr in so_kunnr.
* order by kunnr DESCENDING. "not recommended as it increases burden on db server
if sy-subrc eq 0.
write :/ 'No of records :',sy-dbcnt.
sort t_kna1 by kunnr DESCENDING.
loop at t_kna1 into wa_kna1.
write :/ wa_kna1-kunnr,
wa_kna1-land1,
wa_kna1-name1,
wa_kna1-ort01.
endloop.
else.
write :/ 'No data'.
endif.
REPORT Z930_PROG60.
START-OF-SELECTION.
r_kunnr-sign = 'I'.
r_kunnr-option = 'BT'.
r_kunnr-low = '0000002000'.
r_kunnr-high = '0000002010'.
append r_kunnr.
r_kunnr-sign = 'I'.
r_kunnr-option = 'BT'.
r_kunnr-low = '0000003000'.
r_kunnr-high = '0000003010'.
append r_kunnr.
It is a process of retrieving the data from the database based on the user input, processing the
retrieved data, and displaying the data in summarized format so that the user can analyze the
data based on which business decisions are taken.
Types of Reports:
2. Hierarchical Report
Hierarchical Reports:
In this, the data is displayed in the form of parent(header data) and child(item data).
Vbak -> Sales Document Header data Fields vbeln , erdat , erzet , ernam
Each sales document of VBAK table can contain zero or one or more sales items in VBAP table.
Whenever we retrieve the data using select statement into an internal table which is already
containing data, then the existing contents of the internal table will be over written with the
latest retrieved data. We can avoid this by using appending corresponding fields into table (or)
appending table keyword as part of select statement.
Using Select statements inside loop-endloop will degrade the performance because the no. of
select statements execution depends on no. Of times the loop is iterated.
This can be avoided by using for all entries keyword as part of select statement. To use FOR
ALL ENTRIES in select queries there should be one logically related field between the target DB
table and source internal table and this field should be compared using where clause as part of
select query using for all entries .
Before using for all entries , check whether source internal table contains at least one entry.
As part of this, we use control break events which are also called as AT events. These events
are used only in loop- endloop.
At first: - This event is triggered when we are processing the 1st row of the internal table. This
event can be handled to provide heading for the report before displaying the data.
Syntax:
At first.
Statements.
Endat.
At new:-
This event is triggered at the beginning of a first row combination whenever a unique value is
encountered for the specified field. This event can be handled to generate sub heading at the
beginning of every unique value.
Syntax:
Statements.
Endat.
At end of:
This event is triggered at the end of the last row combination of every unique value for the
specified field. This event can be handled to generate subtotals at the end of every unique
value.
Syntax:
Statements.
Endat.
At last:
This event is triggered at the end of the last row of the internal table. This event can be
handled to generate footer for the report like grand total.
Syntax:
At last .
Statement.
Endat.
Sum statement:
Sum statement can be used as part of at end of and at last event. This statement will do the
sum of numeric fields of the corresponding rows and stores the sum value with in the same
field. This sum value can be accessed within the same events. i.e. the sum value will be
destroyed once a control comes out of the event.
On change of:
It is similar to at new event, but on change of event can be used in any of the looping
statements like while – endwhile. do enddo, select – endselect, loop-endloop whereas at new
can be used only inside loop-endloop.
Note:
The field specified in at new and at end of event should be at the beginning of the internal
table otherwise, these 2 events are triggered for every record of the internal table.
Select-options:
It generates a selection-screen for reading range of input values. It is an internal table created
in the run time based on the field. It contains following structure:
Default value is I
Default value is BT
Note: In the above syntax, if the target field is referring to dictionary structure field, then target
dictionary structure should be declared explicitly using tables keyword. Tables KEYWORD will
create work area with all the fields of the dictionary structure which is a performance issue.
Because of this reason, it is recommended not to declare select-option referring to dictionary
structure. The Recommended declaration is to declare a local variable referring to dictionary
structure field and then declare the select-options referring to local variable. We can use the
addition no-extension as part of select-option declaration to restrict the user to enter only
single range on the selection screen.
Ranges:
It is used for holding range of values. It is an internal table created in the run time based on the
field. It contains same structure as that of select-options:
Select..EndSelect: is a open SQL statement used for retrieving multiple records from the
database. It is a looping statement, where in, for each select statement execution, it retrieves
single record, and the no. of times the select query execution depends on the no. of records
satisfying the condition. If there are more select queries, it increases network traffic and
thereby decreases performance. Because of this reason, it is recommended to minimize the
usage of select..endselect and instead use select into table statement and retrieve the
required no. of records using one select statement execution and store the retrieved data into
an internal table.
Order by clause: is used in select query and it retrieves the data from database in sorted order
of the specified field. By default, it retrieves in ascending order, to retrieve in descending
order, we need to use the addition descending along with order by clause.
In classical interactive reporting: we can generate up to 21 lists. The first list is called as basic
list and the remaining 20 are called as secondary list.
SY-LSIND is the system field which stores the index OF NEXT LIST (secondary list). For the
basic list, index is zero and the secondary lists indexes ranges from 1 to 20.
1. At line-selection: This event is triggered when the user double clicks on a list value or a
single click on a hotspot list value. In this case, the line content where the user has
done the interaction is captured in the system field SY-LISEL and the line number is
captured in SY-LINNO .
2. Top-of-page: This event is triggered in the basic list and it can be handled to generate
the heading for the basic list.
3. Top-of-page during line-selection: This event is triggered in the secondary lists and it
can be handled to generate the heading for secondary list.
4. End-of-page: This event might be triggered in every list whenever the end of page is
reached. This event can be handled to generate the footer for the list pages.
Note:-
End-of-page event is triggered only when the end of page is reached, for this, we need
to control the number of lines per page. This is done by using line-count option as part
of report statement.
Note: If the no. of lines reserved for the page is consumed by TOP-OF-PAGE event or
TOP-OF-PAGE DURING LINE-SELECTION event itself, it leads to runtime error list page
overflow as the content cannot be fitted on the page.
No standard page heading: is the option used as part of report keyword which
suppresses the default page heading.
SY-LISEL - stores entire line content where the user has done the interaction.
Hotspot on: is an option used as part of write statement to display a column value as
hotspot (link to other).
Hide statement:
It is used after the write statement and it writes the value of a variable to the hide
memory area (invisible memory area).
This hide memory area gets refreshed whenever the at line-selection event is triggered
and it maintains only one value where the user has done the interaction. Based on this
value, we can get the content for the next list.
Get cursor field: It is used for identifying the field name and field value on the list where
the user has done the interaction..
It is used for setting the value of a parameter id in the global SAP memory. This value
can be retrieved by using get parameter id statement.
Joins:
Joins are used for retrieving data from multiple tables using one select query.
For retrieving data from multiple tables using joins, the compared fields between two tables
must have the same property i.e. data types and size must be same. The field names need not
be same.
i. Inner join:
In this, the left hand side table is compared with right hand side table.
As part of this comparison, the value of the compared field from the left hand side row will be
compared with all the rows of the right hand side table. If any matching row is found it picks the
rows from left hand side and right hand side tables. If no matching row is found in the right
hand side table, SAP ignores the left hand side row also.
It is similar to inner join but instead of ignoring the deficiency row, it picks the row from the
left hand side and the right hand side row fields is filled with 0 s and nulls(space) according
to data type.
Note: Instead of using joins in the select statement, it is recommended to create the views
on the corresponding tables and specify the view name as part of the select query.
Note: Line-size is the option as used as part of report statement to control the no. of
characters per line.
1. PBO
2. After User interaction in the runtime (enter key in input field, clicking a
button, selecting/deselecting a checkbox, selecting a radio button, selecting a value in
the dropdown)
a) PAI
b) PBO
4. Start-of-selection
5. End-of-selection
1. Load-of-program
2. Top-of-page
3. Initialization
1. At selection-screen
2. Start-of-selection
1. At selection-screen
2. At selection-screen output
Logical Databases:
Standard LDB s:- responsible for retrieving data from HR Database Tables.
1. Selection Program (Include Program) Responsible for generating the selection screen
for reading the user input (contains parameter and select-options declarations)
2. Database Program (Report Program) Responsible for retrieving data from DB tables
(contains select queries)
If a node is referring to a database table, then node name should be same as that of DB table.
1. Execute --> displays selection screen --> input values --> execute
Advantages:
Procedure:
1. Identify the program name (Report) which needs to be scheduled in the background.
2. Check whether the program contains selection screen, if it contains selection screen,
create one or more variants
d) define step
Note: Once the job is released , job gets executed depending on the job start
condition
Note: Once the job is executed, the output associated with the job will be stored as a
spool request which can be viewed through 'SP01' /
Business workplace
1. job_open
2. job_submit
3. job_close
Hierararchial Report- for all entires
Example: Hierarchical Report (Item Internal table data overwritten by select query in the
loop)
report z830rep1.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform displaysalesdata.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form getsalesitems .
loop at t_vbak into wa_vbak.
select vbeln posnr matnr
from vbap
into table t_vbap
where vbeln = wa_vbak-vbeln.
endloop.
endform. " GETSALESITEMS
form displaysalesdata .
loop at t_vbak into wa_vbak. "header internal table
format color 3.
write :/ wa_vbak-vbeln,
wa_vbak-erdat,
wa_vbak-erzet,
wa_vbak-ernam.
format color off.
loop at t_vbap into wa_vbap where vbeln = wa_vbak-vbeln. "item internal table
format color 7.
write :/5 wa_vbap-vbeln,
wa_vbap-posnr,
wa_vbap-matnr.
format color off.
endloop.
endloop.
endform. " DISPLAYSALESDATA
report z830rep2.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform displaysalesdata.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form getsalesitems .
loop at t_vbak into wa_vbak.
select vbeln posnr matnr
from vbap
appending table t_vbap
where vbeln = wa_vbak-vbeln.
endloop.
endform. " GETSALESITEMS
form displaysalesdata .
loop at t_vbak into wa_vbak. "header internal table
format color 3.
write :/ wa_vbak-vbeln,
wa_vbak-erdat,
wa_vbak-erzet,
wa_vbak-ernam.
format color off.
loop at t_vbap into wa_vbap where vbeln = wa_vbak-vbeln. "item internal table
format color 7.
write :/5 wa_vbap-vbeln,
wa_vbap-posnr,
wa_vbap-matnr.
format color off.
endloop.
endloop.
endform. " DISPLAYSALESDATA
Example: Hierarchical Report (For all Entries-To avoid select inside loop)
report z830rep3.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform displaysalesdata.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form getsalesitems .
* loop at t_vbak into wa_vbak.
* select vbeln posnr matnr
* from vbap
* appending table t_vbap
* where vbeln = wa_vbak-vbeln.
* endloop. "not recommended to write select inside loop
select vbeln posnr matnr
from vbap
into table t_vbap
for all entries in t_vbak
where vbeln = t_vbak-vbeln.
endform. " GETSALESITEMS
form displaysalesdata .
loop at t_vbak into wa_vbak. "header internal table
format color 3.
write :/ wa_vbak-vbeln,
wa_vbak-erdat,
wa_vbak-erzet,
wa_vbak-ernam.
format color off.
loop at t_vbap into wa_vbap where vbeln = wa_vbak-vbeln. "item internal table
format color 7.
write :/5 wa_vbap-vbeln,
wa_vbap-posnr,
wa_vbap-matnr.
format color off.
endloop.
endloop.
endform. " DISPLAYSALESDATA
Example: Control Break Events
start-of-selection.
perform getsalesitems.
if t_vbap is not initial.
perform displaysalesitems.
else.
message 'No Sales Items for given range' type 'I'.
endif.
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln in so_vbeln.
form displaysalesitems .
sort t_vbap by vbeln.
loop at t_vbap into wa_vbap.
at first.
write :/15 'SALES DOCUMENT ITEMS WITH PRICES' color 3.
uline.
endat.
at new vbeln.
format color 7.
write :/ 'Sales Document No :',wa_vbap-vbeln.
format color off.
endat.
format color 2.
write :/5 wa_vbap-posnr,
wa_vbap-matnr,
wa_vbap-netwr.
format color off.
at end of vbeln.
format color 1.
sum.
write :/ 'Sum of ',wa_vbap-vbeln,' is',wa_vbap-netwr under wa_vbap-netwr.
format color off.
endat.
at last.
format color 3.
sum.
write :/ 'Grand Total is ',wa_vbap-netwr under wa_vbap-netwr.
format color off.
endat.
endloop.
endform. " DISPLAYSALESITEMS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln in so_vbeln.
form displaysalesitems .
sort t_vbap by vbeln.
loop at t_vbap into wa_vbap.
at first.
write :/15 'SALES DOCUMENT ITEMS WITH PRICES' color 3.
uline.
endat.
* at new vbeln.
on change of wa_vbap-vbeln.
format color 7.
write :/ 'Sales Document No :',wa_vbap-vbeln.
format color off.
endon.
* endat.
format color 2.
write :/5 wa_vbap-posnr,
wa_vbap-matnr,
wa_vbap-netwr.
format color off.
at end of vbeln.
format color 1.
sum.
write :/ 'Sum of ',wa_vbap-vbeln,' is',wa_vbap-netwr under wa_vbap-netwr.
format color off.
endat.
at last.
format color 3.
sum.
write :/ 'Grand Total is ',wa_vbap-netwr under wa_vbap-netwr.
format color off.
endat.
endloop.
endform. " DISPLAYSALESITEMS
Example: Control Break events – At new <field name> (Not the First Field of the internal
table)
start-of-selection.
perform getsalesitems.
if t_vbap is not initial.
perform displaysalesitems.
else.
message 'No Sales Items for given range' type 'I'.
endif.
form getsalesitems .
select posnr vbeln matnr netwr
from vbap
into table t_vbap
where vbeln in so_vbeln.
endform. " GETSALESITEMS
form displaysalesitems .
sort t_vbap by vbeln.
loop at t_vbap into wa_vbap.
at first.
write :/15 'SALES DOCUMENT ITEMS WITH PRICES' color 3.
uline.
endat.
at new vbeln.
format color 7.
write :/ 'Sales Document No :',wa_vbap-vbeln.
format color off.
endat.
format color 2.
write :/5 wa_vbap-posnr,
wa_vbap-matnr,
wa_vbap-netwr.
format color off.
at end of vbeln.
format color 1.
sum.
write :/ 'Sum of ',wa_vbap-vbeln,' is',wa_vbap-netwr under wa_vbap-netwr.
format color off.
endat.
at last.
format color 3.
sum.
write :/ 'Grand Total is ',wa_vbap-netwr under wa_vbap-netwr.
format color off.
endat.
endloop.
endform. " DISPLAYSALESITEMS
Example: Select-EndSelect to retrieve multiple records
report z830rep7.
start-of-selection.
perform getcustomers.
if t_customers is not initial.
perform displaycustomers.
else.
message 'No Customers' type 'I'.
endif.
top-of-page.
write :/15 'CUSTOMER MASTER DATA' color 7.
end-of-page.
uline.
write :/15 'GENSOFT TECHNOLOGIES' color 3.
write :/20 'Page no :',sy-pagno color 1.
at line-selection.
case sy-lsind.
when 1.
* message 'Hi' type 'I'.
* write :/ 'Content of selected line is ',sy-lisel.
clear gv_kunnr.
gv_kunnr = sy-lisel+0(15). "offset logic-extracting portion of string
if gv_kunnr is not initial.
* unpack gv_kunnr to gv_kunnr. "(or)
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = gv_kunnr
importing
output = gv_kunnr.
perform getsalesorders.
if t_salesorders is not initial.
perform displaysalesorders.
else.
message 'No Sales Orders for selected customer' type 'I'.
endif.
endif.
when 2.
perform getsalesitems.
if t_salesitems is not initial.
perform displaysalesitems.
else.
message 'No Sales items' type 'I'.
endif.
when 3.
get cursor field gv_fname value gv_fvalue.
if gv_fname = 'WA_SALESITEMS-MATNR'.
set parameter id 'MAT' field gv_fvalue.
call transaction 'MM03'.
else.
message 'Please select only Material No' type 'I'.
endif.
endcase.
form getcustomers .
select kunnr land1 name1
from kna1
into table t_customers
where kunnr in so_kunnr.
endform. " GETCUSTOMERS
form displaycustomers .
uline.
format color 2.
write :/(16) 'Customer No',(7) 'Country','Customer Name'.
format color off.
uline.
format color 3.
loop at t_customers into wa_customers.
write :/(15) wa_customers-kunnr hotspot on,
sy-vline,
(6) wa_customers-land1,
sy-vline,
wa_customers-name1.
endloop.
format color 3.
endform. " DISPLAYCUSTOMERS
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_salesorders
where kunnr = gv_kunnr.
endform. " GETSALESORDERS
form displaysalesorders .
loop at t_salesorders into wa_salesorders.
write :/ wa_salesorders-vbeln,
wa_salesorders-erdat,
wa_salesorders-erzet,
wa_salesorders-ernam.
hide wa_salesorders-vbeln.
endloop.
endform. " DISPLAYSALESORDERS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_salesitems
where vbeln = wa_salesorders-vbeln.
endform. " GETSALESITEMS
form displaysalesitems .
loop at t_salesitems into wa_salesitems.
write :/ wa_salesitems-vbeln,
wa_salesitems-posnr,
wa_salesitems-matnr,
wa_salesitems-netwr.
endloop.
endform. " DISPLAYSALESITEMS
start-of-selection.
perform getcustomers.
if t_customers is not initial.
perform displaycustomers.
else.
message 'No Customers' type 'I'.
endif.
top-of-page.
write :/15 'CUSTOMER MASTER DATA' color 7.
end-of-page.
uline.
write :/15 'GENSOFT TECHNOLOGIES' color 3.
write :/20 'Page no :',sy-pagno color 1.
at line-selection.
case sy-lsind.
when 1.
* message 'Hi' type 'I'.
* write :/ 'Content of selected line is ',sy-lisel.
clear gv_kunnr.
gv_kunnr = sy-lisel+0(15). "offset logic-extracting portion of string
if gv_kunnr is not initial.
* unpack gv_kunnr to gv_kunnr. "(or)
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = gv_kunnr
importing
output = gv_kunnr.
perform getsalesorders.
if t_salesorders is not initial.
perform displaysalesorders.
else.
message 'No Sales Orders for selected customer' type 'I'.
endif.
endif.
when 2.
perform getsalesitems.
if t_salesitems is not initial.
perform displaysalesitems.
else.
message 'No Sales items' type 'I'.
endif.
when 3.
get cursor field gv_fname value gv_fvalue.
if gv_fname = 'WA_SALESITEMS-MATNR'.
set parameter id 'MAT' field gv_fvalue.
call transaction 'MM03'.
else.
message 'Please select only Material No' type 'I'.
endif.
endcase.
form getcustomers .
select kunnr land1 name1
from kna1
into table t_customers
where kunnr in so_kunnr.
endform. " GETCUSTOMERS
form displaycustomers .
uline.
format color 2.
write :/(16) 'Customer No',(7) 'Country','Customer Name'.
format color off.
uline.
format color 3.
loop at t_customers into wa_customers.
write :/(15) wa_customers-kunnr hotspot on,
sy-vline,
(6) wa_customers-land1,
sy-vline,
wa_customers-name1.
endloop.
format color 3.
endform. " DISPLAYCUSTOMERS
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_salesorders
where kunnr = gv_kunnr.
endform. " GETSALESORDERS
form displaysalesorders .
loop at t_salesorders into wa_salesorders.
write :/ wa_salesorders-vbeln,
wa_salesorders-erdat,
wa_salesorders-erzet,
wa_salesorders-ernam.
hide wa_salesorders-vbeln.
endloop.
endform. " DISPLAYSALESORDERS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_salesitems
where vbeln = wa_salesorders-vbeln.
endform. " GETSALESITEMS
form displaysalesitems .
loop at t_salesitems into wa_salesitems.
write :/ wa_salesitems-vbeln,
wa_salesitems-posnr,
wa_salesitems-matnr,
wa_salesitems-netwr.
endloop.
endform. " DISPLAYSALESITEMS
start-of-selection.
perform getcustomers.
if t_customers is not initial.
perform displaycustomers.
else.
message 'No Customers' type 'I'.
endif.
top-of-page.
write :/15 'CUSTOMER MASTER DATA' color 7.
uline.
end-of-page.
uline.
write :/15 'GENSOFT TECHNOLOGIES' color 3.
write :/20 'Page no :',sy-pagno color 1.
at line-selection.
case sy-lsind.
when 1.
* message 'Hi' type 'I'.
* write :/ 'Content of selected line is ',sy-lisel.
clear gv_kunnr.
gv_kunnr = sy-lisel+0(15). "offset logic-extracting portion of string
if gv_kunnr is not initial.
* unpack gv_kunnr to gv_kunnr. "(or)
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = gv_kunnr
importing
output = gv_kunnr.
perform getsalesorders.
if t_salesorders is not initial.
perform displaysalesorders.
else.
message 'No Sales Orders for selected customer' type 'I'.
endif.
endif.
when 2.
perform getsalesitems.
if t_salesitems is not initial.
perform displaysalesitems.
else.
message 'No Sales items' type 'I'.
endif.
when 3.
get cursor field gv_fname value gv_fvalue.
if gv_fname = 'WA_SALESITEMS-MATNR'.
set parameter id 'MAT' field gv_fvalue.
call transaction 'MM03'.
else.
message 'Please select only Material No' type 'I'.
endif.
endcase.
form getcustomers .
select kunnr land1 name1
from kna1
into table t_customers
where kunnr in so_kunnr.
endform. " GETCUSTOMERS
form displaycustomers .
format color 2.
write :/(16) 'Customer No',(7) 'Country','Customer Name'.
format color off.
uline.
format color 3.
loop at t_customers into wa_customers.
write :/(15) wa_customers-kunnr hotspot on,
sy-vline,
(6) wa_customers-land1,
sy-vline,
wa_customers-name1.
endloop.
format color 3.
endform. " DISPLAYCUSTOMERS
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_salesorders
where kunnr = gv_kunnr.
endform. " GETSALESORDERS
form displaysalesorders .
loop at t_salesorders into wa_salesorders.
write :/ wa_salesorders-vbeln,
wa_salesorders-erdat,
wa_salesorders-erzet,
wa_salesorders-ernam.
hide wa_salesorders-vbeln.
endloop.
endform. " DISPLAYSALESORDERS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_salesitems
where vbeln = wa_salesorders-vbeln.
endform. " GETSALESITEMS
form displaysalesitems .
loop at t_salesitems into wa_salesitems.
write :/ wa_salesitems-vbeln,
wa_salesitems-posnr,
wa_salesitems-matnr,
wa_salesitems-netwr.
endloop.
endform. " DISPLAYSALESITEMS
Transport management:
Every object that an ABAP consultant develops must be transported (moved) from
development client to quality client and then to production client.
For this, we need to store the object inside a transportable package, so that the object is
assigned to Transport request / Change Request.
A Transport request is a collection of one or more tasks.
Every task can be associated with one or more objects.
Every user should create their own task/s under main request for storing their respective
objects.
For Creating/Managing transport requests/tasks, we use Transport Organizer tool (SE09 /
SE10).
There are two types of transport requests:
Workbench Request Captures the changes made to repository objects (executable
programs, include programs / su routine pool…. / di tionary o je ts ta les, sear h
helps…..
Customizing Request Captures configuration changes / data related changes.
Status of the tasks:
Unclassified: The task which is not associated with any objects.
Development/Correction: It is a task which is under development i.e it contains atleast
one object.
Once the development is done i.e once all the objects assigned to us are finished with
the development, we need to release our task and send the screenshot of the same to
the owner of the request.
A Task can be released only when all the objects inside that task are in active state.
Once all the tasks are released, the owner of the request will release the main request
which indicates that the request is ready for transportation.
Transport Requests:
objects ---> save ===> local object ($tmp) --> default package provided by SAP
--> will not be assigned to change request
(transport request)
--> cannot be transported
---> package ---> assigned to change request
sapuser
gensoft
abc
xyz
lmn
1. WORKBENCH REQUEST --> CAPTURES CHANGES MADE TO CROSS-CLIENT
TABLES
(CLIENT INDEPENDENT)
REPOSITORY OBJECTS & DICTIONARY OBJECTS
PURPOSE:
Note: A module pool program can be created either with or without TOP include
program.
TOP include program can be used for declaring global variables, subroutine definitions
and module definitions.
A TOP include program must end with TOP .
A Module pool program cannot be executed directly; it needs to be associated with a
transaction code.
1. Create a module pool program in object navigator (SE80) (with top include-
recommended)
2. Create the initial screen using screen painter tool and provide the description and
choose the type of screen in Attributes tab
3. Design the screen layout with different elements (textfields, i/o fields,
che k o es,radio utto s,ta le o trol….) a d also set the appropriate properties for
each of the elements
4. Implement the events in the flowlogic by defining the corresponding modules
5. Repeat the steps 2,3,4 for each of the screens
6. Create the t-code for the module pool program by associating with the initial screen
of the transaction
This event can be handled to provide custom F1 help whenever a user presses F1 key
in/on the screen element.
Note: Whenever we need to refer to the screen element inside the program, we need to
declare a variable with the same name and type as that of screen element.
TABSTRIP CONTROL: A tabstrip control is a collection of TAB Buttons. Each Tab button
should be associated with a subscreen. A subscreen cannot be placed directly on top of
normal screen; it should be placed on top of a subscreen area. We can use same /
different subscreen areas for each tab.
A Subscreen area is a collection of subscreens.
Note: Whenever a normal screen/subscreen layout contains tabstrip control, it should
be declared explicitly by using controls keyword., otherwise it leads to runtime error
control not found .
Note: By Default, The first tab will be active in the Tabstrip control. We can use the
property ACTIVETAB of tabstrip control to activate a specific tab button in tabstrip
control. Each Tab should be associated with a subscreen. Since Subscreen cannot be
placed on top of normal screen, we need to place subscreen area in each tab and then
in the runtime, the subscreen will sit on TOP OF subscreen area. We can use
same/different subscreen area s FOR each tab. The no. of calls to CALL SUBSCREEN
statement depends on the no. of subscreen areas.
TABLE CONTROL:
It is used for displaying the data in the form of rows and columns.
Note: Whenever a screen / subscreen contains table control component and when we
do syntax check, it gives error as loop endloop is required in both PBO and PAI.
In order to avoid this error in the design time, initially provide loop and endloop in both
PBO and PAI events.
Controls <table control name> type tableview using screen <screen no>.
By default, Table control vertical scrolling property is disabled. To enable it, we need to
set the LINES property of table control.
1. Automatic Field validations: In this, the validations are performed by SAP itself based
on the properties of the screen field (transaction field) set at screen level(frontend) or
properties of the field maintained at dictionary level (database level). In this, the
validation messages are provided by SAP itself.
Validation messages:
1. If mandatory field value is not entered message will be provided by SAP fill in
all the required fields
2. If i valid ou tr ke / la guage ke / u its of easure e t … is e tered
message will be provided by SAP Invalid values (entry doesn t e ist i …..)
3. If invalid date is entered message will be provided by SAP invalid date
2. Flow logic validations: In this, the validations are performed by SAP itself based on the
values maintained for the field at the flow logic level. In this, the validation messages
are provided by SAP itself.
Flowlogic section:
Eg: field lfa1-land1 values ( AF , AR , IN )
Field mara-mtart values ( COUP , FGTR , ROH )
Note: If any of the screen field fails the flow logic validations, the other fields on the
screen will be disabled and doesn t allow the user to input the values in the other fields.
This can be avoided by grouping the logically related fields using chain-endchain
statement.
Eg:-
Flowlogic section:
Chain.
Field lfa1-lifnr.
Field lfa1-land1 values ( AF , AR , IN ).
Endchain.
chain.
field mara-matnr.
field mara-mtart values ('COUP','FGTR','ROH').
endchain.
3. Module pool validations: These validations are used for performing field specific
validations. In this, the validation messages must be provided by developer itself.
Syntax:
Flowlogic section:
Note: Define the module with validation logic and validation message in any of the
include programs.
At Exit-command module
Note: If a screen field fails any of the above validations, the user cannot exit the
transaction unless the validation is correct or in some cases user may require to
forcefully exit the transactions. For forceful exit, we need to consider a button whose
functionality should be similar to that of cancel button. For this, we need to set an
additional property for the button i.e FCTTYPE to E (function type to exit command)
along with the function code. Apart from this additional property, there should be
corresponding at exit-command module in the PAI event. As part of this module
definition, we need to implement the logic to exit the transaction forcefully. This at
exit-command module is executed only when the user clicks on the button whose
function type is set to E .
PAI event:
As part of module definition, implement the logic to exit the transaction (leave
program).
Displays screen ---> user will perform actions (click button,press enter key in i/o field,
---> based on action ---> SAP Triggers PAI event first and then
again triggers PBO event.
Every Business contains Business Documents like Enquiry, Quotation, Purchase Order, Sales
Order, Invoice, Delivery Schedule....
To Design these Business Documents Templates, We use word processing tools like SAP Scripts,
Smartforms, ADOBE Forms.
SMARTFORMS:
--> F.M will act as driver program/print program --> directly executed for testing
1. General Settings
b) Form Interface --> In this, we declare the parameters which needs to be passed to the
smartform while calling it (import, export, tables...)
c) Global definitions ---> In this, we declare the global variables (individual variables, work area,
internal table, types declaration...), provide select
statements
2. Pages and Windows --> In this, we design the pages layout and windows
Note: As part of driver program, it is recommended not to directly call the smartform F.M as
this F.M name depends on the client numbering formats of each client, so when we transport
the smartform to quality/production clients and when we activate the smartform there, it
generates new F.M whose name depends on the numbering sequence of that particular client.
So it is recommended to get the smartform F.M name dynamically and it is done by calling the
std.F.M 'SSF_FUNCTION_MODULE_NAME' which takes smartform name as input and returns
the associated smartform F.M name which is specific to that particular client.
Note: To skip the print dialog box while calling the smartform from driver program, we need to
prepare and pass the control parameters while calling the smartform F.M.
REPORT ZCALLSMFORM.
if sy-subrc eq 0.
* call the smartform
* call function gv_fname. "will not skip print dialog box
elseif sy-subrc eq 1.
message 'No Form exists' type 'I'.
elseif sy-subrc eq 2.
message 'No function module exists for smartform' type 'I'.
elseif sy-subrc eq 3.
message 'Unknown error' type 'I'.
endif.
For this, we need to specify the parameters in Form interface of smartforms and pass the value
for this parameter while calling the smartform F.M from driver program.
Requirement:
2. Based on this sales doc received, smartform should retrieve corresponding header
data(vbak) and item data(vbap) of the sales document and display the same
Primary key fields: mandt (client no), vbeln (sales doc no),
Relationship: Each Sales Doc of vbak table can contain one or more sales items in VBAP table
Eg:-
REPORT ZCALLSMFORM2.
smartform tables
smartforms requirement-exercise
TABLES IN SMARTFORMS
1. Create 4 windows
3 secondary windows
form interface :-
5. As part of header window, create text element and provide the following
6. As part of footer window, create text element and provide the following page
no : &sfsy-page&
7. As part of SalesItems window (main window), create table object
At table level, by default sap provides line type (%ltype1), rename this to meaningful
name(linetype1)
Right click on linetype1, create emptyline underneath, sap provides line type, rename it to
linetype2
Note : declare a work area as part of global definitions 'global data' tab
d) At the table level, create the table line as part of main area
Create text element as part of each cell and provide the symbol fields appropriately
Note: Specify variable 'lv_total' as part of initialization in the output parameter so that
'warning' 'lv_total͛ has no defined value is suppressed.
f) Specify the Calculation as part of table level
g) At the table level, create the table line as part of footer area
Create text element as part of the cell and provide the symbol fields appropriately
Driver Program.
REPORT ZCALLSMFORM3.
Requirement:
Displaying sales documents item data based on the range of sales documents passed to
smartforms
fields :
Form interface :-
tables parameters :
types tab :
initialization tab :-
t_sdoc t_vbap
t_vbap wa_vbap
under loop object --> create text element and place the symbol fields from work area wa_vbap
Loop object:
Text object in Event on Sort Begin:
REPORT ZCALLSMFORM4.
endif.
REPORT ZCALLSMFORM4_PDF.
Types Declarations:
Global variable declarations:
Global Data:
Initialization Tab:
Input Parameters Output Parameters
I_KUNNR T_VBAK
GV_SNO GV_SNO
GV_TOTPAGES GV_TOTPAGES
GV_REM GV_REM
Select Query: (Also, logic for generating count of no. of pages dynamically)
Table object in main window with line type 1 containing 5 cells (Table tab)
Create table line for Main area referring to table line ͚line type 1͛ 5 cells are created
create individual text elements in each cell for displaying data from work area ͚wa_vbak͛
In main area cell1, create program line (code object) for calculating serial no and marking the
reach of 10th record in each page
Note: Whenever we write the content to an existing standard text using the function module
͚SAVE_TEXT͛, SAP overwrites the standard text content with the new content.
Note: For Reading the standard text dynamically, we need to use the function module
͚READ_TEXT͛.
Note: For including the standard text in the smart form, we need to create a text object of type
͚Include Text͛ and provide the standard text information.
By Default, whenever we create Standard Text in ͚SO10͛, it is not captured as part of Change
Request as it will not prompt for any package at the time of creating it. So we need to assign
the standard text manually to a change request so that it can be transported. For this, we need
to run the standard program ͚RSTXTRAN͛, the pre-requisite for executing this standard report is
we need to create a task of type ͚CORRECTION͛ and provide the same at the time of executing
the standard report ͚RSTXTRAN͛. For this, first create a Workbench Request and a task in
Transport Organizer (SE09) and make the sure the task type is changed to
Development/Correction. For this, select the task, choose the menu ͚Request/Task͛ - change
type Development/Correction.
REPORT Z7AM_CREATE_STDTEXT.
REPORT Z7AM_CREATE_APPEND_STDTEXT.
template in smartforms
Alternative Object is used for condition check. We need to provide condition as part of
alternative object. Whenever an alternative object is created, SAP creates two sub nodes (true
and false). We can create relevant objects as part of true and false sub nodes. If the alternative
condition is satisfied, the objects associated with subnode ͚true͛ will be executed, otherwise the
objects associated with subnode ͚false͛ will be executed.
Initialization Tab:
Input Parameters:
I_kunnr wa_customer
Gv_cnt t_sales
Gv_cnt
Driver Program:
REPORT ZCALLSMFORM6.
INITIALIZATION.
t1 = 'Select an Option'.
lb1 = 'Customer No'.
perform get_smartform_fm.
if gv_fname is not INITIAL.
* prepare control parameters
wa_ctrl_param-no_dialog = 'X'.
wa_ctrl_param-preview = 'X'.
endif.
FORM GET_SMARTFORM_FM .
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZSMFORM6'
IMPORTING
FM_NAME = gv_fname.
ENDFORM. " GET_SMARTFORM_FM
FORM CALL_SMARTFORM .
call function gv_fname
EXPORTING
CONTROL_PARAMETERS = wa_ctrl_param
i_kunnr = p_kunnr
i_flag = gv_sel.
ENDFORM. " CALL_SMARTFORM
Scripts (SE71)
- As part of every business there are different documents exchanged on a daily basis.
- Some of the business documents are enquiry, quotation, purchase order, sales order,
invoice, shipping, delivery etc..
- By using SAP Scripts we can design new documents and modify the documents provided
by SAP.
- This print program is usually an executable program, as part of this we use the following
function modules.
a. Open_form.
b. Write _form.
c. Close_from.
d. Start_form
e. End_form
Open_form:
b. Language: it holds the language key in which the form NEEDS to be opened.
Write_form:
It is used for passing the data and invoking the windows in the form .
Close_form:
Note: If the F.M close_form is not called, form will be displayed and closed automatically. i.e
no preview will be available
The number of calls to the function module ͞write_form͟ depends upon number of elements,
number of windows in the form.
As part of repository objects we use system fields which represent some values.
1. System symbols.
2. Standard symbols.
3. Program symbols.
4. Text symbols.
System symbols
Standard symbols
Note: System symbols, Standard symbols, Program symbols are enclosed between ͞&<symbol
name>&͟
Text symbols: These are the variables defined as part of layout and they are also represented
by control commands.
Program Symbols: are used for passing parameters to SAP scripts from driver program. The
program symbol names in the layout and in the driver program must be same.
To Display images in SAP Scripts, we need to first upload the .bmp images using ͚SE78͛ and then
in order to display the image in the layout we need to create either Graphic object on the
layout or use the ͚BITMAP͛ control command in the window to include the bitmap image (insert
menu graphics)
Text elements:
write_form
close_form
open_form
write_form
end_form
-----
write_form
end_form
close_form
͚SE76͛ is the t-code used for translating scripts in to different languages. As part of this
translation, we can translate
a) Descriptions
b) Titles
c) Text in the windows
Note: Once the script is translated into different languages, as part of driver program, we
need to provide the system field ͚sy-langu͛ as part of language parameter in open_form
F.M..
Depending on the logon language, the appropriate language form is displayed. If the form
is not maintained in that language, then parent language form will be displayed.
Adobe Forms:
It is used for designing the template of Business Documents. Tool used is ͚Form Builder͛ (͚SFP͛ T-
code).
1. SAP Scripts --> Form Painter tool --> SE71 (supports only static forms, interaction is
not possible in runtime)
Procedure:
2. Smartforms --> smartforms (supports only static forms, interaction is not possible in runtime)
Procedure:
1. Layout design --> smartforms --> activate --> generates f.m --->execute
2. Driver Program / Print Program Executable program --> call smartform f.m which
will act as driver for calling the smartform
Procedure:
a) Declare parameters
b) Design the layout for the adobe form based on the adobe form
context
i) Executable program --> call Adobe Form F.M which will act as
driver for calling the adobe form
Procedure:
ii) webdynpro application ---> integrate the adobe form as part of 'interactiveformuielement'
(property 'templatesource' --> name of adobe form)
c) xml schema based interface --> can be used for interactive adobe form
Requirement
Map the adobe system fields (data and time) from adobe interface context to adobe
form context
3. Design the layout for the adobe form in the layout tab
Drag and drop the system fields (date and time) from adobe form context to adobe
layout
Place the text field on the adobe form layout and provide static text (Palettes Library
Standard text control)
REPORT ZCALLADOBEFORM1.
Import parameters:
Types declaration:
Map the import parameters and Global declarations from adobe interface context to
adobe form context
3. Design the layout for adobe form
Drag and drop the parameters i_vbeln, gs_vbak , gt_vbap from adobe form context on
to the layout, also provide the static text through text control
REPORT ZCALLADOBEFORM2.
BDC Techniques:
e) Identify the BDC technique which needs to be used for data transfer
a) GUI_UPLOAD (Recommended)
b) WS_UPLOAD (Deprecated)
c) UPLOAD (Deprecated)
To Write (Download) data from internal table to Local text file, we can use the
following F.M͛s
a) GUI_DOWNLOAD (Recommended)
b) WS_DOWNLOAD (Deprecated)
c) DOWNLOAD (Deprecated)
To Read data from Local excel file to internal table, we can use the following F.M's
1. ALSM_EXCEL_TO_INTERNAL_TABLE (or)
2. TEXT_CONVERT_XLS_TO_SAP
open dataset <path> for <file opening mode> in <text mode> / <binary mode>
encoding default [message <msg variable>].
Note:
Syntax to Get the position of the file pointer in Application Server File:
Syntax to Set the file pointer at desired position in Application Server File:
Processing Modes:
1. ͚A͛ (Display All) Foreground (default) All Records are displayed and
error records are validated after the user interaction on the screen.
2. ͚E͛ (Display Errors) All Records are displayed and error records are
validated as when they are displayed on the screen (explicit user
interaction not required).
3. ͚N͛ (Background, No Display)
Update Modes:
a) Tcode holds the t-code of the module pool transaction through which
the data is migrated
b) Dynprotab holds the BDCDATA internal table
Eg: - XK01 transaction (Vendor master data with bank details captured in table
control Tables LFA1 and LFBK)
XD01 transaction (Customer master data with bank details captured in table
control Tables KNA1 and KNBK)
Introduction:
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
----
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.
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.
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:
Method Parameters:
1. Declaration
syntax:
2. Implementation
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:
They can access any kind of components of the class (instance / static / constant /
types).
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:
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.
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.
- It is special because it is executed/called automatically whenever an object is
created (instance const) or whenever a class is loaded in the memory (static
const).
- They are always declared in public section.
- They never return any value.
- There are two types of constructors
1. Instance constructor.
2. Static constructor.
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 cannot contain any parameters or exceptions.
- It is not specific to any object.
- It is executed only once in the life time of every class. I.e. it is executed in either
of the following case.
- 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
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:
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:
- 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.
- Public class can be instantiated anywhere (within same class/ inside subclasses
/outside classes).
- Public class can be inherited.
- 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 class can be inherited.
- 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 protecting class is also created as protected by default.
- The subclass inheriting protected class can be created as explicit public class (or)
private class.
- Private classes:
- Create private is keyword used for creating the private classes.
- 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:
- 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.
- Interfaces cannot contain method implementations, it contains only method
declarations.
- A local class whichever want to implement an interface(local/global) , the class
must declare the interface in the public section by using interfaces keyword and
the class must implement all the interface methods, Otherwise the class should
be declared as abstract and also the methods which are not implemented
should be flagged (declared) as abstract. In these cases, we must consider
another class inheriting the abstract class and provide the implementation for the
abstract methods.
- The class which ever implements the interface is called as implementation class.
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
- Aliases declared inside interfaces are always public
- Aliases can be declared either in interfaces / in the 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.
class and object creation in different prog languages
oops syllabus
visibility sections of class components
report z730oops1.
uline.
write :/ 'Static attr.accessed using class name....'.
lcl_abc=>y = 5.
write :/ lcl_abc=>y.
*lcl_abc=>z = 15. "syntax error
uline.
write :/ 'First object ob1....'.
data ob1 type ref to lcl_abc. "reference
*ob1->x = 45. "runtime error
create object ob1. "object
*write :/ ob1=>x. "syntax error
write :/ ob1->x,ob1->y,ob1->z.
ob1->x = 12.
ob1->y = 7.
*ob1->z = 15. "syntax error
write :/ ob1->x,ob1->y,ob1->z.
write :/ 'Static attr.accessed using class name....'.
write :/ lcl_abc=>y.
uline.
write :/ 'Second object ob2....'.
data ob2 type ref to lcl_abc.
create object ob2.
write :/ ob2->x,ob2->y,ob2->z.
ob2->x = 22.
write :/ ob2->x,ob2->y,ob2->z.
Memory allocation for objects ob1 and ob2
Example: Local class with instance attributes and instance methods, ME Keyword
REPORT Z730OOPS2.
method set.
empno = 5. "(or)
* me->empno = 5.
ename = 'Ravi'. "(or)
* me->ename = 'Ravi'.
endmethod.
endclass.
START-OF-SELECTION.
report z730oops3.
start-of-selection.
write :/ 'First Object ob1....'.
data ob1 type ref to lcl_emp.
create object ob1.
uline.
write :/ 'Second Object ob2....'.
data ob2 type ref to lcl_emp.
create object ob2.
call method ob2->set
exporting
i_empno = p_empno
i_ename = p_ename.
report z730oops4.
endclass.
start-of-selection.
data ob1 type ref to lcl_sales.
create object ob1.
format color 1.
write :/ 'First Object ob1....'.
parameters p_vbeln type vbak-vbeln.
uline.
data ob2 type ref to lcl_sales.
create object ob2.
format color 3.
write :/ 'Second Object ob2....'.
*data wa_vbak type ty_vbak. "syntax error
data wa_vbak type lcl_sales=>ty_vbak.
report z730oops5.
endclass.
class lcl_sales implementation.
method getsalesdata.
select single vbeln erdat erzet ernam
from vbak
into e_vbak
where vbeln = i_vbeln.
if sy-subrc eq 0.
select vbeln posnr matnr
from vbap
into table e_vbap
where vbeln = i_vbeln.
endif.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to lcl_sales.
create object ob1.
format color 1.
write :/ 'First Object ob1....'.
parameters p_vbeln type vbak-vbeln.
uline.
data ob2 type ref to lcl_sales.
create object ob2.
format color 3.
write :/ 'Second Object ob2....'.
*data wa_vbak type ty_vbak. "syntax error
data wa_vbak type lcl_sales=>ty_vbak.
uline.
format color 7.
data ob3 type ref to lcl_sales.
create object ob3.
report z730oops6.
types:
begin of ty_vbap,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
end of ty_vbap .
types:
gt_vbap type table of ty_vbap .
types:
begin of ty_vbak,
vbeln type vbak-vbeln,
erdat type vbak-erdat,
erzet type vbak-erzet,
ernam type vbak-ernam,
end of ty_vbak .
Method Implementation:
method getsalesdata.
select single vbeln erdat erzet ernam
from vbak
into e_vbak
where vbeln = i_vbeln.
if sy-subrc eq 0.
select vbeln posnr matnr
from vbap
into table e_vbap
where vbeln = i_vbeln.
endif.
endmethod.
Executable program:
report z730oops7.
*START-OF-SELECTION. "optional
data ob type ref to z730class1.
create object ob.
report z730oops8.
method m2.
data m type ty_m value 18.
write :/ 'inside static method m2..'.
write :/ y.
write :/ z.
write :/ m.
* write :/ x. "syntax error
endmethod.
endclass.
start-of-selection.
write :/ 'Accessing methods using class name....'.
* call method lcl_abc=>m1. "syntax error
call method lcl_abc=>m2.
uline.
write :/ 'Accessing methods using object name....'.
data ob type ref to lcl_abc.
create object ob.
report z730oops9.
method m2.
write :/ 'Inside protected method m2 of abc...'.
endmethod.
method m3.
write :/ 'Inside private method m3 of abc...'.
endmethod.
endclass.
start-of-selection.
write :/ 'using object of pqr class...'.
data ob type ref to lcl_pqr.
create object ob.
call method ob->m4.
uline.
write :/ 'using object of xyz class...'.
data m type ref to lcl_xyz.
create object m.
method m1.
write :/ 'Inside public method m1 of abc...'.
endmethod.
method m2.
write :/ 'Inside protected method m2 of abc...'.
endmethod.
method m3.
write :/ 'Inside private method m3 of abc...'.
endmethod.
method m4.
write :/ 'inside public method m4 of pqr class...'.
data k type ref to z730abc.
create object k.
call method k->m1.
call method k->m2.
call method k->m3.
endmethod.
Executable program:
report z730oops10.
method m1.
write :/ 'inside instance method m1..'.
endmethod.
method m2.
write :/ 'inside static method m2..'.
endmethod.
Executable program:
report z730oops11.
z730class2=>x = 10.
call method z730class2=>m2.
initializing constructors
constructor purpose
report z730oops12.
method display.
write :/ empno,ename.
endmethod.
endclass.
start-of-selection.
write :/ 'First object ob1....'.
data ob1 type ref to lcl_emp.
create object ob1.
report z730oops13.
method display.
write :/ empno,ename.
endmethod.
endclass.
start-of-selection.
parameters : p_empno type i,
p_ename(20) type c.
uline.
write :/ 'Second object ob2....'.
data ob2 type ref to lcl_emp.
create object ob2
exporting
i_empno = p_empno.
report z730oops14.
method class_constructor.
write :/ 'inside static const..'.
endmethod.
endclass.
start-of-selection.
* lcl_abc=>x = 10. "also check by uncommenting
uline.
write :/ 'Second object ob2....'.
data ob2 type ref to lcl_abc.
create object ob2.
uline.
write :/ 'Third object ob3....'.
data ob3 type ref to lcl_abc.
create object ob3.
Inheritance
Inheritance example
diff between public,protected,private at component level
report z730oops15.
start-of-selection.
write :/ 'Object of cycle class ...'.
data ob1 type ref to lcl_cycle.
create object ob1.
uline.
write :/ 'Object of bike class ...'.
data ob2 type ref to lcl_bike.
create object ob2.
endmethod.
report z730oops16.
uline.
write :/ 'Object of bike class ...'.
data ob2 type ref to zcl_bike.
create object ob2.
report z730oops17.
report z730oops18.
method m1.
write :/ 'inside instance method m1 of vehicle class...'.
endmethod.
method m2.
write :/ 'inside static method m2 of vehicle class...'.
endmethod.
method display.
write :/ wheels,brakes.
endmethod.
endclass.
method display.
* call method super->display. "(or)
super->display( ).
write :/ color.
endmethod.
endclass.
method display.
super->display( ).
write :/ gears.
endmethod.
endclass.
start-of-selection.
write :/ 'Object of cycle class ...'.
data ob1 type ref to lcl_cycle.
create object ob1.
method m1.
write :/ 'inside public instance method m1 of super class'.
endmethod.
method m2.
write :/ 'inside public instance final method m2 of super class'.
endmethod.
method m3.
write :/ 'inside public static method m3 of super class'.
endmethod.
method m1.
call method super->m1.
write :/ 'inside public redefined instance method m1 of super class'.
endmethod.
Executable Program: For calling Redefined Global method
report z730oops19.
report z730oops20.
method class_constructor.
write :/ 'inside super class static constructor...'.
endmethod.
endclass.
start-of-selection.
*lcl_super=>x = 10.
*lcl_sub=>x = 12.
uline.
write :/ 'Second object of sub class...'.
data ob2 type ref to lcl_sub.
create object ob2.
uline.
write :/ 'Third object of sub class...'.
data ob3 type ref to lcl_sub.
create object ob3.
report z730oops21.
method class_constructor.
write :/ 'inside super class static constructor...'.
endmethod.
endclass.
start-of-selection.
*lcl_super=>x = 10.
*lcl_sub=>x = 10.
*lcl_super=>y = 10. "syntax error
*lcl_sub=>y = 10.
uline.
write :/ 'First object of sub class...'.
data ob1 type ref to lcl_sub.
create object ob1.
uline.
write :/ 'Second object of sub class...'.
data ob2 type ref to lcl_sub.
create object ob2.
uline.
write :/ 'Third object of sub class...'.
data ob3 type ref to lcl_sub.
create object ob3.
report z730oops22.
method class_constructor.
write :/ 'inside super class static constructor...'.
endmethod.
endclass.
method constructor.
write :/ 'inside sub class instance constructor...'.
call method super->constructor.
endmethod.
endclass.
start-of-selection.
*lcl_super=>x = 10.
*lcl_sub=>x = 10.
*lcl_super=>y = 10. "syntax error
*lcl_sub=>y = 10.
uline.
write :/ 'Second object of sub class...'.
data ob2 type ref to lcl_sub.
create object ob2.
uline.
write :/ 'Third object of sub class...'.
data ob3 type ref to lcl_sub.
create object ob3.
report z730oops23.
method constructor.
call method super->constructor
exporting
i_empno = i_empno
i_ename = i_ename.
endmethod.
method display.
write :/ empno,ename.
endmethod.
endclass.
start-of-selection.
parameters : p_empno type i,
p_ename(20) type c.
report z730oops24.
start-of-selection.
parameters : p_empno type i,
p_ename(20) type c.
report z730oops25.
start-of-selection.
data ob type ref to lcl_abc.
create object ob.
report z730oops26.
start-of-selection.
data ob type ref to lcl_abc.
*create object ob. "syntax error
*
data m type ref to lcl_xyz.
*create object m. "syntax error
report z730oops27.
*class lcl_pqr DEFINITION create public INHERITING FROM lcl_abc. "syntax error
*endclass.
*
*START-OF-SELECTION.
data ob type ref to lcl_abc.
*create object ob. "syntax error
**
*data m type ref to lcl_xyz.
**create object m. "syntax error
report z730oops28.
method display.
write :/ tableno,steward.
endmethod.
endclass.
method display.
call method super->display.
write :/ cqno,cqdate,cqamt.
endmethod.
endclass.
class lcl_creditcard definition inheriting from lcl_restaurant.
public section.
methods payment redefinition.
methods display redefinition.
protected section.
data : ccno type i,
ccexpdate type d,
ccamt type i.
endclass.
method display.
call method super->display.
write :/ ccno,ccexpdate,ccamt.
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.
format color 7.
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
Class: ZCL_CHEQUE Inheriting ZCL_RESTAURANT
Method Payment Redefined:
method PAYMENT.
cqno = 123.
cqdate = sy-datum.
cqamt = 1200.
endmethod.
method DISPLAY.
CALL METHOD SUPER->DISPLAY.
write :/ cqno,cqdate,cqamt.
endmethod.
method PAYMENT.
ccno = 543.
ccexpdate = sy-datum.
ccamt = 236.
endmethod.
method DISPLAY.
CALL METHOD SUPER->DISPLAY.
write :/ ccno,ccexpdate,ccamt.
endmethod.
Executable Program:
REPORT Z730OOPS29.
uline.
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 ---> Restaurant....'.
r = cq. "narrow casting or up casting
call method : r->store,
r->payment,
r->display.
uline.
format color 1.
write :/ 'Credit card class object....'.
data cc type ref to zcl_creditcard.
create object cc.
uline.
format color 6.
write :/ 'Credit card class object ---> Restaurant....'.
r = cc. "narrow casting or up casting
call method : r->store,
r->payment,
r->display.
REPORT Z730OOPS30.
interface rectangle.
data : length type i,
breadth type i.
methods : area,
perimeter.
endinterface.
interface square.
data side type i.
methods : area,
perimeter.
endinterface.
method constructor.
call method super->constructor.
rectangle~length = i_len.
rectangle~breadth = i_brd.
square~side = i_side.
endmethod.
method rectangle~area.
res = rectangle~length * rectangle~breadth.
write :/ 'Area of Rectangle is ',res.
endmethod.
method rectangle~perimeter.
res = 2 * ( rectangle~length + rectangle~breadth ).
write :/ 'Perimeter of Rectangle is ',res.
endmethod.
method square~area.
res = square~side * square~side.
write :/ 'Area of square is ',res.
endmethod.
method square~perimeter.
res = 4 * square~side.
write :/ 'Perimeter of square is ',res.
endmethod.
method area.
write :/ 'inside direct method area of impl. class...'.
endmethod.
ENDCLASS.
START-OF-SELECTION.
PARAMETERS : p_length type i,
p_brdth type i,
p_side type i.
method ZRECTANGLE~AREA.
res = zrectangle~length * zrectangle~breadth.
write :/ 'Area of Rectangle is ',res.
endmethod.
method ZRECTANGLE~PERIMETER.
res = 2 * ( zrectangle~length + zrectangle~breadth ).
write :/ 'Perimeter of Rectangle is ',res.
endmethod.
method ZSQUARE~AREA.
res = zsquare~side * zsquare~side.
write :/ 'Area of square is ',res.
endmethod.
method ZSQUARE~PERIMETER.
res = 4 * zsquare~side.
write :/ 'Perimeter of square is ',res.
endmethod.
method CONSTRUCTOR.
zrectangle~length = i_len.
zrectangle~breadth = i_brd.
zsquare~side = i_side.
endmethod.
method M1.
write :/ 'inside direct method m1 of impl.class....'.
endmethod.
Executable Program:
REPORT Z730OOPS31.
format color 3.
write :/ 'Implementation class object ob....'.
data ob type ref to zcl_impl.
create object ob
EXPORTING
i_len = p_len
i_brd = p_brd
i_side = p_side.
uline.
format color 1.
write :/ 'Implementation class object ----> Square Reference.'.
data s type ref to zsquare.
*create object s. "syntax error
s = ob. "narrow casting
call method : s->area,
s->perimeter.
REPORT Z730OOPS32.
interface intf1.
methods : m1,
m2,
m3.
ENDINTERFACE.
method intf1~m3.
write :/ 'Inside method m3 of interface intf1 implemented in class lcl_impl3..'.
endmethod.
method m4.
write :/ 'Inside direct method m4 of class lcl_impl2....'.
endmethod.
endclass.
START-OF-SELECTION.
format color 3.
write :/ 'Object of class lcl_impl2....'.
data ob type ref to lcl_impl2.
create object ob.
uline.
format color 7.
write :/ 'Object of class lcl_impl2 assigned to class lcl_impl1....'.
data k type ref to lcl_impl1.
* create object k. "syntax error
REPORT Z730OOPS33.
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 Z730OOPS34.
interface intf1.
* data : length type i value 10,
* breadth type i value 5. "syntax error
constants : length type i value 10,
breadth type i value 5.
methods : area,
perimeter.
endinterface.
START-OF-SELECTION.
data ob type ref to lcl_impl.
create object ob.
method ZINTF1~M1.
write :/ 'Inside method m1 of interface intf1..'.
endmethod.
method ZINTF1~M2.
write :/ 'Inside method m2 of interface intf1..'.
endmethod.
method ZINTF2~M3.
write :/ 'Inside method m3 of interface intf2..'.
endmethod.
Executable Program:
REPORT Z730OOPS35.
- Exception handling is a process of handling the Runtime Error s and continues 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 occur.
- 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.
Singleton class:
It is a class for which only one object can be created. It uses Singleton Design pattern.
Persistence service
It is used for storing the state of object (values of the object) permanently in the database.
By default, the life time of the object is local to the program i.e. once a program execution is
completed, memory allocated for the object will be destroyed.
Any database operation (CRUD operations) can be achieved by using persistent service .
Whenever a persistence class is created, SAP creates two more classes internally.
Base agent class: is a friend of persistence class and it is super class of ACTOR class.
By Default, Persistence class implements a std. interface IF_OS_STATE which is responsible for
storing the state of the object permanently in the database.
- In this, we need to consider a database table in which the primary key field of the table
is considered as Business key identity .
Table: z730emp
Fields:
Note: By default, Persistence class implements the interface if_os_state which is responsible
for storing the state of the object permanently.
3. Map the Persistence class with the Corresponding data base table. (goto persistence
representation)
Note:- We must Map all the fields of the db table to the persistence class (double click
on each field and click on set attribute values button)
Note: Once the mapping is done, all the fields of the table will be added as attributes of
the persistence class.
- Apart from this, SAP GENERATES GET_ Methods for all attributes and SET_ methods
for non-primary key fields.
- Getter method is used for reading the value of the attribute and Setter method is used
for setting the value to the attribute.
4. Activate the persistence class so that dependent classes also get activated.
5. As part of this activation, SAP generates the following methods as part of base agent
class.
1. Create _Persistent
2. Delete_Persistent.
3. Get_Persistent
- To access the above 3 instance Methods we require object of base agent class, but the
base agent class is created as Abstract class . So, it cannot be instantiated directly.
- The above 3 methods are public and they are inherited to sub class which is Actor Class
or Agent class.
- But, Actor class IS created as Private Class , so, it cannot be instantiated directly
outside.
- Actor class is created as Singleton class, so there is a possibility of creating one and only
one object. So in order to get the object of the Actor class we must follow the following
Procedure.
- As part of every Actor class, SAP Provides Static Public Attribute Agent . This attribute
is marked as Read only i.e this attribute will return a value whenever it is accessed.
- Whenever this attribute is accessed by using Actor class name , internally SAP Executes
Static Constructor of Actor class which is Responsible for creating singleton (single
object) of actor class, This object will be returned back to the static attribute agent, we
need to receive this returned object so that we can access the above 3 methods.
- In this we need to consider a database table whose first field is GUID and the
corresponding data element should be OS_GUID . The value for this field GUID will
be dynamically generated by SAP itself.
- We need to map the persistence class with this database table. After Mapping, except
GUID field all the remaining fields will be added as attributes of the persistence class.
- Apart from this, SAP Generates Getter & Setter methods as part of persistence class
for all the fields except GUID .
- When we activate the persistence class, SAP generates the following 3 Methods as part
of BASE AGENT CLASS .
1. Create_Persistent.
2. IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_OID
1. IF_OS_FACTORY~DELETE_PERSISTENT.
Table: Z8AMEMP
Fields:
EMPNO zeMPno
ENAME zename
EMPDESIG zempdesig
In persistence service using GUID the uniqueness of the object is controlled based on
the GUID field.
GET_PERSISTENT_BY_OID:
This method takes GUID as input and returns the object of the object class. This object class in
the runtime points to persistence class, so we need to type cast the object class object to
persistence class object. Using the persistence class object access the required getter methods.
DELETE_PERSISTENT:
This method takes the object of the interface if_os_state as input value, but we cannot
directly create objects for interfaces, so we need to analyze what is the implementation class
which is implementing this particular interface. As per the analysis, it is the persistence class
(zcl_9am_empl) which is implementing the interface if_os_state , so we can pass the object of
this persistence class as a parameter value. In order to get the object of persistence class, first
of all we have to check whether the GUID is existing or not this is done by calling the instance
method Get_Persistence_By_Oid .This method returns object of the object class, this object
class object needs to be type cast to persistence class object and pass that object as parameter
to Delete_Persistent .
2. if_os_transaction
3. if_os_transaction_manager
1. Get the transaction manager object: This is done by calling the static method
'get_transaction_manager' of the class 'cl_os_system'
2. Using the above transaction manager object, get the transaction object. This is done
by calling the instance method 'create_transaction' of the interface
'if_os_transaction_manager'
3. Using the above transaction object, mark the start of OO Transaction. This is done by
calling the 'start' method of the interface 'if_os_transaction'
5. Try to end the transaction by calling the instance method 'end' of the interface
'if_os_transaction'. If the transaction fails, cancel the transaction by calling the method 'undo'
of the interface 'if_os_transaction.
Note: The above steps are provided by SAP as part of interface documentation
IF_OS_TRANSACTION .
exception classes hierarchy
report z730oops36.
report z730oops37.
uline.
clear v_str.
format color 7.
call method k->if_message~get_longtext
receiving
result = v_str.
uline.
format color 1.
call method k->get_source_position
importing
program_name = v_pname
include_name = v_iname
source_line = v_pos.
report z730oops38.
start-of-selection.
parameters : p_x type i,
p_y type i.
report z730oops39.
start-of-selection.
parameters : p_x type i,
p_y type i.
data gv_z type i.
report z730oops40.
start-of-selection.
parameters : p_x type i,
p_y type i.
uline.
data k type ref to cx_sy_zerodivide.
data str type string.
try.
call method ob->m1
exporting
i_x = p_x
i_y = p_y
importing
e_z = gv_z.
catch cx_sy_zerodivide into k.
call method k->if_message~get_text
receiving
result = str.
format color 7.
write :/ 'Inside catch block....'.
write :/ 'Short exception message is ',str.
format color off.
endtry.
write :/ 'Division is ',gv_z.
uline.
try.
call method ob->m1
exporting
i_x = p_x
i_y = p_y
importing
e_z = gv_z.
catch cx_sy_zerodivide into k.
clear str.
call method k->if_message~get_longtext
receiving
result = str.
format color 1.
write :/ 'Inside catch block....'.
write :/ 'Long exception message is ',str.
format color off.
endtry.
write :/ 'Division is ',gv_z.
report z730oops41.
start-of-selection.
parameters : p_x type i,
p_y type i.
data gv_z type i.
if sy-subrc eq 0.
write :/ 'Division is ',gv_z.
elseif sy-subrc eq 1.
write :/ 'Cannot divide by zero...'.
else.
write :/ 'Unknown exception...'.
endif.
write :/ 'End of program...'.
method m1.
write :/ 'Begin of method m1...'.
if i_y eq 0.
raise myexception.
else.
e_z = i_x / i_y.
endif.
write :/ 'End of method m1...'.
endmethod.
Executable program:
report z730oops42.
if sy-subrc eq 0.
write :/ 'Division is ',gv_z.
elseif sy-subrc eq 12.
write :/ 'Cannot divide by zero'.
elseif sy-subrc eq 17.
write :/ 'Unknown error'.
endif.
report z730oops43.
try.
*condition check
raise exception type zcx_myexceptions
exporting
textid = zcx_myexceptions=>id1.
catch zcx_myexceptions into k.
format color 3.
write :/ 'EXCEPTION ID id1....'.
call method k->if_message~get_text
receiving
result = str.
write :/ str.
clear str.
call method k->if_message~get_longtext
receiving
result = str.
write :/ str.
format color off.
endtry.
uline.
try.
format color 7.
raise exception type zcx_myexceptions
exporting
textid = zcx_myexceptions=>id2.
catch zcx_myexceptions into k.
call method k->if_message~get_text
receiving
result = str.
write :/ str.
clear str.
call method k->if_message~get_longtext
receiving
result = str.
write :/ str.
endtry.
Example: Custom Exception classes using Message classes
Note: First create a Message class in SE91 with static and Dynamic messages
Now, Create a exception class in SE24 by selecting the checkbox message classes and create
two exception ids as part of Texts tab. Also create 4 attributes ATTR1 to ATTR4 as part of
Attributes tab. Map the exception id ID1 with static message 000 of message class and Map
the exception id ID2 with dynamic message 001 of message class. While mapping to dynamic
message , provide the attributes to map them to place holders of dynamic message.
Activate the exception class
Executable program:
report z730oops44.
try.
raise exception type ycx_myexceptions
exporting
textid = ycx_myexceptions=>id1.
catch ycx_myexceptions into k.
format color 3.
call method k->if_message~get_text
receiving
result = str.
clear str.
call method k->if_message~get_longtext
receiving
result = str.
uline.
try.
raise exception type ycx_myexceptions
exporting
textid = ycx_myexceptions=>id2
attr1 = 'Gensoft Technologies'
attr2 = 'SAP Technical Training'
attr3 = 'Hyderabad'
attr4 = sy-datum.
catch ycx_myexceptions into k.
format color 7.
call method k->if_message~get_text
receiving
result = str.
clear str.
call method k->if_message~get_longtext
receiving
result = str.
report z730oops45.
methods m1.
protected section.
class-data k type ref to lcl_singleton.
endclass.
method m2.
format color 7.
write :/ 'Object getting assigned to return reference in static method...'.
m = k.
format color off.
endmethod.
method m1.
format color 1.
write :/ 'Inside instance method m1..'.
format color off.
endmethod.
endclass.
start-of-selection.
data ob type ref to lcl_singleton.
* create object ob. "syntax error
ob = lcl_singleton=>m2( ).
call method ob->m1.
singleton class:- maximum of only one object --> singleton design pattern
static constructor
method class_constructor.
endmethod.
object state in db
persistent state
report z730oops46.
initialization.
t1 = 'Employee'.
lb1 = 'Employee No'.
lb2 = 'Employee Name'.
lb3 = 'Designation'.
t2 = 'Operations'.
perform get_actor_object.
form get_actor_object .
actor = zca_emp_pers=>agent.
endform. " GET_ACTOR_OBJECT
form create_persistent_object .
try.
call method actor->create_persistent
exporting
i_empno = p_empno
receiving
result = pers.
try.
call method pers->set_empdesig
exporting
i_empdesig = p_desig.
catch cx_os_object_not_found .
message 'Exception in setting empdesig' type 'I'.
endtry.
commit work.
endif.
catch cx_os_object_existing.
message 'Exception in creating persistent object' type 'I'.
endtry.
form read_persistent_object .
try.
call method actor->get_persistent
exporting
i_empno = p_empno
receiving
result = pers.
catch cx_os_object_not_found .
message 'Failed to read ename' type 'I'.
endtry.
try.
call method pers->get_empdesig
receiving
result = p_desig.
catch cx_os_object_not_found .
message 'Failed to read empdesig' type 'I'.
endtry.
endif.
catch cx_os_object_not_found .
message 'Failed to read persistent object' type 'I'.
endtry.
form update_persistent_object .
* check for existence of persistent object
try.
call method actor->get_persistent
exporting
i_empno = p_empno
receiving
result = pers.
catch cx_os_object_not_found .
message 'Failed to modify ename' type 'I'.
endtry.
try.
call method pers->set_empdesig
exporting
i_empdesig = 'ABAP Developer'.
catch cx_os_object_not_found .
message 'Failed to modify empdesig' type 'I'.
endtry.
commit work.
endif.
catch cx_os_object_not_found .
message 'Failed to read persistent object' type 'I'.
endtry.
form delete_persistent_object .
try.
call method actor->delete_persistent
exporting
i_empno = p_empno.
commit work.
catch cx_os_object_not_existing .
message 'Persistent object not found for deletion' type 'I'.
endtry.
endform. " DELETE_PERSISTENT_OBJECT
traditional abap:
ename
empdesig
PERS->EMPNO = WA-EMPNO.
PERS->ENAME = WA-ENAME.
PERS->EMPDESIG = WA-EMPDESIG.
CALL CREATE_PERSISTENT
ENDLOOP.
FROM DBTABLE
INTO WA
report z730oops47.
form get_actor_object .
actor = yca_emp_pers=>agent.
endform. " GET_ACTOR_OBJECT
form create_persistent_object .
try.
call method actor->create_persistent
receiving
result = pers.
try.
call method pers->set_ename
exporting
i_ename = p_ename.
catch cx_os_object_not_found .
message 'Exception in setting ename value' type 'I'.
endtry.
try.
call method pers->set_empdesig
exporting
i_empdesig = p_desig.
catch cx_os_object_not_found .
message 'Exception in setting empdesig value' type 'I'.
endtry.
commit work.
endif.
catch cx_os_object_existing .
message 'Exception in creating persistent object' type 'I'.
endtry.
endform. " CREATE_PERSISTENT_OBJECT
form read_persistent_object .
data ob type ref to object.
try.
call method actor->if_os_ca_persistency~get_persistent_by_oid
exporting
i_oid = p_guid
receiving
result = ob.
try.
call method pers->get_empno
receiving
result = p_empno.
catch cx_os_object_not_found .
message 'Empno not found' type 'I'.
endtry.
try.
call method pers->get_ename
receiving
result = p_ename.
catch cx_os_object_not_found .
message 'Ename not found' type 'I'.
endtry.
try.
call method pers->get_empdesig
receiving
result = p_desig.
catch cx_os_object_not_found .
message 'Empdesig not found' type 'I'.
endtry.
endif.
catch cx_os_object_not_found .
message 'Object Not found exception' type 'I'.
catch cx_os_class_not_found .
message 'Class Not found exception' type 'I'.
endtry.
endform. " READ_PERSISTENT_OBJECT
form update_persistent_object .
endform. " UPDATE_PERSISTENT_OBJECT
form delete_persistent_object .
endform. " DELETE_PERSISTENT_OBJECT
report z730oops48.
initialization.
t1 = 'Employee'.
lb1 = 'Guid'.
lb2 = 'Employee No'.
lb3 = 'Employee Name'.
lb4 = 'Designation'.
t2 = 'Operations'.
perform get_actor_object.
form get_actor_object .
actor = yca_emp_pers=>agent.
endform. " GET_ACTOR_OBJECT
form create_persistent_object .
try.
call method actor->create_persistent
receiving
result = pers.
try.
call method pers->set_ename
exporting
i_ename = p_ename.
catch cx_os_object_not_found .
message 'Exception in setting ename value' type 'I'.
endtry.
try.
call method pers->set_empdesig
exporting
i_empdesig = p_desig.
catch cx_os_object_not_found .
message 'Exception in setting empdesig value' type 'I'.
endtry.
commit work.
endif.
catch cx_os_object_existing .
message 'Exception in creating persistent object' type 'I'.
endtry.
endform. " CREATE_PERSISTENT_OBJECT
form read_persistent_object .
data ob type ref to object.
try.
call method actor->if_os_ca_persistency~get_persistent_by_oid
exporting
i_oid = p_guid
receiving
result = ob.
try.
call method pers->get_empno
receiving
result = p_empno.
catch cx_os_object_not_found .
message 'Empno not found' type 'I'.
endtry.
try.
call method pers->get_ename
receiving
result = p_ename.
catch cx_os_object_not_found .
message 'Ename not found' type 'I'.
endtry.
try.
call method pers->get_empdesig
receiving
result = p_desig.
catch cx_os_object_not_found .
message 'Empdesig not found' type 'I'.
endtry.
endif.
catch cx_os_object_not_found .
message 'Object Not found exception' type 'I'.
catch cx_os_class_not_found .
message 'Class Not found exception' type 'I'.
endtry.
endform. " READ_PERSISTENT_OBJECT
form update_persistent_object .
* check the existence of persistence object
data ob type ref to object.
try.
call method actor->if_os_ca_persistency~get_persistent_by_oid
exporting
i_oid = p_guid
receiving
result = ob.
commit work.
endif.
catch cx_os_object_not_found .
message 'Object Not found exception' type 'I'.
catch cx_os_class_not_found .
message 'Class Not found exception' type 'I'.
endtry.
form delete_persistent_object.
* check the existence of persistence object
data ob type ref to object.
try.
call method actor->if_os_ca_persistency~get_persistent_by_oid
exporting
i_oid = p_guid
receiving
result = ob.
* start OO Transaction
try.
call method o_trans->start.
try.
call method o_pers->set_empdesig
exporting
i_empdesig = v_desig.
catch cx_os_object_not_found .
message 'Failed to set empdesig' type 'I'.
endtry.
endif.
catch cx_os_object_existing .
message 'Exception in creating persistent object' type 'I'.
endtry.
catch cx_os_transaction .
message 'Exception in starting OO Transaction' type 'I'.
endtry.
report z730oops49.
*data ob type ref to z730_transaction.
*create object ob.
*call method ob->m1.
parameters : p_empno type z730emp-empno,
p_ename type z730emp-ename,
p_desig type z730emp-empdesig.
export p_empno to memory id 'A1'.
export p_ename to memory id 'A2'.
export p_desig to memory id 'A3'.
1. Generate the Selection screen for reading user input (Parameters / select-
options)
3. Retrieve the data from database table/s into internal tables/work areas using
Select Query
a. REUSE_ALV_LIST_DISPLAY
b. REUSE_ALV_GRID_DISPLAY
1. Declaration
2. Retrieve data
4. Display
It is an object which contains the information s of the fields display in the ALV Grid . This
information includes name of the field, position, label, grid, appearance etc. To specify the field
catalogue information using the dictionary structure, we need to use the importing parameter
I_STRUCTURE_NAME as part of the function module REUSE_ALV_GRID_DISPLAY . Whenever
this parameter is specified all the properties of the field are taken from dictionary itself.
The structure name passed must match with the format of internal table i.e. the no of fields
and sequence of fields in the structure and in the internal table must match otherwise it leads
to runtime error.
This function module takes the dictionary structure as input, generates the field catalogue
based on structure fields and returns the field catalogue which is of type internal table
SLIS_T_FIELDCAT_ALV .
Note: It is recommended to generate the Field catalog manually, as we have better flexibility
and control of the fields. For this, we need to prepare work area for each field and append the
same to the internal table of type SLIS_T_FIELDCAT_ALV .
- To handle events in ALV reports developed using function module we need to consider
the parameter IT_EVENTS as part of the F.M REUSE_ALV_GRID_DISPLAY .
- This internal table holds the events information (refer to the document of the
parameter IT_EVENTS to get the events list).
- As part of this subroutine definition, we need to implement the business logic related to
the event.
USER_COMMAND:-
This event is triggered when the user double clicks on ALV cell value (or) single click on hotspot
cell value. This event contains two parameters.
Note:
Step 1:
Step 2:
And execute.
Step 3:
In the next screen , in the top pane, choose pictures , and in bottom pane, ->doctype-
>expand->standard doc types->double click on screen entry->choose filename (logo
file) from local drive->continue.
Blocked Alv:
- Reuse_alv_block_list_init.
- Reuse_alv_block_list_append.
- Reuse_alv_block_list_display.
Procedure:
Step 1:
Reuse_alv_block_list_init .
Step 2:
Step 3:
Append the field catalog and the data to the blocked list using the function module
Reuse_alv_block_list_append .
Note:
Step 4:
Reuse_alv_block_list_display.
Note: Reuse_alv_events_get is the function module which returns list of events supported in
ALV function modules.
ALV Interactive Reporting using F.M, Image Display, Blocked List
report z730alvfm1.
include z730alvfm1_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform displaysalesorders.
else.
message 'No Sales Orders' type 'I'.
endif.
form displaysalesorders .
call function 'REUSE_ALV_GRID_DISPLAY'
tables
t_outtab = t_vbak
exceptions
program_error =1
others = 2.
if sy-subrc eq 1.
message 'Program error' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
endform. " DISPLAYSALESORDERS
Example: ALV Reporting using Function Module – Field Catalog info. Using Dictionary
Structure
report z730alvfm2.
include z730alvfm2_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform displaysalesorders.
else.
message 'No Sales Orders' type 'I'.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_structure_name = 'ZCVBAK'
tables
t_outtab = t_vbak
exceptions
program_error =1
others = 2.
if sy-subrc eq 1.
message 'Program error' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
endform. " DISPLAYSALESORDERS
Example: ALV Reporting using Function Module – Field Catalog generated using F.M and
Modified at Report Level
report z730alvfm3.
include z730alvfm3_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform fldcatsalesorders.
perform displaysalesorders.
else.
message 'No Sales Orders' type 'I'.
endif.
Include Program: Z730ALVFM3_INC
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = t_fldcat
tables
t_outtab = t_vbak
exceptions
program_error =1
others = 2.
if sy-subrc eq 1.
message 'Program error' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZCVBAK'
changing
ct_fieldcat = t_fldcat.
Example: ALV Reporting Using Function Module – Field Catalog manipulation using Field
Symbol Work area
report z730alvfm4.
include z730alvfm4_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform fldcatsalesorders.
perform displaysalesorders.
else.
message 'No Sales Orders' type 'I'.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = t_fldcat
tables
t_outtab = t_vbak
exceptions
program_error =1
others = 2.
if sy-subrc eq 1.
message 'Program error' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZCVBAK'
changing
ct_fieldcat = t_fldcat.
Example: ALV Reporting using Function Module – Field Catalog Generated Manually, Event
Handling Process in ALV F.M’s
report z730alvfm5.
include z730alvfm5_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform fldcatsalesorders.
perform prepareevents.
perform displaysalesorders.
else.
message 'No Sales Orders' type 'I'.
endif.
form displaysalesorders .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_CALLBACK_PROGRAM = 'Z730ALVSUBPOOL' "(or)
i_callback_program = sy-repid
it_fieldcat = t_fldcat
it_events = t_events
tables
t_outtab = t_vbak
exceptions
program_error =1
others = 2.
if sy-subrc eq 1.
message 'Program error' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
clear wa_fldcat.
wa_fldcat-fieldname = 'VBELN'.
wa_fldcat-col_pos = 1.
wa_fldcat-seltext_m = 'Sales Document'.
wa_fldcat-outputlen = 12.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERDAT'.
wa_fldcat-col_pos = 2.
wa_fldcat-seltext_m = 'Date of Creation'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERZET'.
wa_fldcat-col_pos = 3.
wa_fldcat-seltext_m = 'Time of Creation'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERNAM'.
wa_fldcat-col_pos = 4.
wa_fldcat-seltext_m = 'Name of Created User'.
wa_fldcat-outputlen = 25.
append wa_fldcat to t_fldcat.
form prepareevents .
clear wa_events.
wa_events-name = 'USER_COMMAND'.
wa_events-form = 'SALESITEMS'.
append wa_events to t_events.
endform. " PREPAREEVENTS
program z730alvsubpool.
report z730alvfm6.
include z730alvfm6_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform fldcatsalesorders.
perform prepareevents.
perform displaysalesorders.
else.
message 'No Sales Orders' type 'I'.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_CALLBACK_PROGRAM = 'Z730ALVSUBPOOL' "(or)
i_callback_program = sy-repid
it_fieldcat = t_fldcat
it_events = t_events
tables
t_outtab = t_vbak
exceptions
program_error =1
others = 2.
if sy-subrc eq 1.
message 'Program error' type 'I'.
elseif sy-subrc eq 2.
message 'Unknown error' type 'I'.
endif.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
clear wa_fldcat.
wa_fldcat-fieldname = 'VBELN'.
wa_fldcat-col_pos = 1.
wa_fldcat-seltext_m = 'Sales Document'.
wa_fldcat-outputlen = 12.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERDAT'.
wa_fldcat-col_pos = 2.
wa_fldcat-seltext_m = 'Date of Creation'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERZET'.
wa_fldcat-col_pos = 3.
wa_fldcat-seltext_m = 'Time of Creation'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERNAM'.
wa_fldcat-col_pos = 4.
wa_fldcat-seltext_m = 'Name of Created User'.
wa_fldcat-outputlen = 25.
append wa_fldcat to t_fldcat.
form prepareevents .
clear wa_events.
wa_events-name = 'USER_COMMAND'.
wa_events-form = 'SALESITEMS'.
append wa_events to t_events.
endform. " PREPAREEVENTS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln = wa_vbak-vbeln.
endform. " GETSALESITEMS
form fldcatsalesitems .
refresh t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'VBELN'.
wa_fldcat-col_pos = 1.
wa_fldcat-seltext_m = 'Sales Document'.
wa_fldcat-outputlen = 12.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'POSNR'.
wa_fldcat-col_pos = 2.
wa_fldcat-seltext_m = 'Item No'.
wa_fldcat-outputlen = 8.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'MATNR'.
wa_fldcat-col_pos = 3.
wa_fldcat-seltext_m = 'Material Number'.
wa_fldcat-outputlen = 20.
wa_fldcat-hotspot = 'X'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'NETWR'.
wa_fldcat-col_pos = 4.
wa_fldcat-seltext_m = 'Net Value'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
form reg_events .
refresh t_events.
clear wa_events.
wa_events-name = 'TOP_OF_PAGE'.
wa_events-form = 'HEADING'.
append wa_events to t_events.
clear wa_events.
wa_events-name = 'USER_COMMAND'.
wa_events-form = 'MATERIALS'.
append wa_events to t_events.
form heading.
* message 'top of page event' 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-key = 'Date :'.
wa_header-info = sy-datum.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'A'.
wa_header-info = 'SAP Technical Training'.
append wa_header to t_header.
form alvblocks .
* initialize the ALV Blocked list
call function 'REUSE_ALV_BLOCK_LIST_INIT'
exporting
i_callback_program = sy-repid.
form fldcatmaterialplants .
refresh t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'MATNR'.
wa_fldcat-col_pos = 1.
wa_fldcat-seltext_m = 'Material Number'.
wa_fldcat-outputlen = 20.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'WERKS'.
wa_fldcat-col_pos = 2.
wa_fldcat-seltext_m = 'Plant'.
wa_fldcat-outputlen = 10.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'EKGRP'.
wa_fldcat-col_pos = 3.
wa_fldcat-seltext_m = 'Purchase Group'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
form getmaterialplants .
select matnr werks ekgrp
from marc
into table t_marc
where matnr = wa_vbap-matnr.
endform. " GETMATERIALPLANTS
form fldcatmaterialstorage .
refresh t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'MATNR'.
wa_fldcat-col_pos = 1.
wa_fldcat-seltext_m = 'Material Number'.
wa_fldcat-outputlen = 20.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'WERKS'.
wa_fldcat-col_pos = 2.
wa_fldcat-seltext_m = 'Plant'.
wa_fldcat-outputlen = 10.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'LGORT'.
wa_fldcat-col_pos = 3.
wa_fldcat-seltext_m = 'Storage Location'.
wa_fldcat-outputlen = 15.
append wa_fldcat to t_fldcat.
form getmaterialstorageloc .
select matnr werks lgort
from mard
into table t_mard
where matnr = wa_vbap-matnr.
endform. " GETMATERIALSTORAGE
Example: Hierarchial ALV Report – Abort Error – Field Catalog Not Found
report z730alvfm7.
include z730alvfm7_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform regkeyinfo.
perform display.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
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 display .
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
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 regkeyinfo .
clear wa_keyinfo.
wa_keyinfo-header01 = 'VBELN'.
wa_keyinfo-item01 = 'VBELN'.
wa_keyinfo-header02 = ''.
wa_keyinfo-item02 = 'POSNR'.
endform. " REGKEYINFO
Example: Hierarchial ALV Report – Run Time error (As Field catalog Internal table and Data
Internal table fields structure is different)
report z730alvfm8.
include z730alvfm8_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform regkeyinfo.
perform fldcat.
perform display.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
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 display .
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
it_fieldcat = t_fldcat
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 regkeyinfo .
clear wa_keyinfo.
wa_keyinfo-header01 = 'VBELN'.
wa_keyinfo-item01 = 'VBELN'.
wa_keyinfo-header02 = ''.
wa_keyinfo-item02 = 'POSNR'.
endform. " REGKEYINFO
form fldcat .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZCVBAK'
changing
ct_fieldcat = t_fldcat.
Example: Hierarchial ALV Report – Field Catalog generated and merged using F.M
report z730alvfm9.
include z730alvfm9_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform regkeyinfo.
perform fldcat.
perform display.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
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 display .
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
it_fieldcat = t_fldcat
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 regkeyinfo .
clear wa_keyinfo.
wa_keyinfo-header01 = 'VBELN'.
wa_keyinfo-item01 = 'VBELN'.
wa_keyinfo-header02 = ''.
wa_keyinfo-item02 = 'POSNR'.
endform. " REGKEYINFO
form fldcat .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZCVBAK'
i_internal_tabname = 'T_VBAK'
changing
ct_fieldcat = t_fldcat.
report z730alvfm10.
include z730alvfm10_inc.
start-of-selection.
perform getsalesorders.
if t_vbak is not initial.
perform getsalesitems.
if t_vbap is not initial.
perform regkeyinfo.
perform fldcat.
perform display.
else.
message 'No Sales Items' type 'I'.
endif.
else.
message 'No Sales Orders' type 'I'.
endif.
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 display .
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
it_fieldcat = t_fldcat
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 regkeyinfo .
clear wa_keyinfo.
wa_keyinfo-header01 = 'VBELN'.
wa_keyinfo-item01 = 'VBELN'.
wa_keyinfo-header02 = ''.
wa_keyinfo-item02 = 'POSNR'.
endform. " REGKEYINFO
form fldcat .
clear wa_fldcat.
wa_fldcat-fieldname = 'VBELN'.
wa_fldcat-col_pos = 1.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Sales Doc'.
wa_fldcat-tabname = 'T_VBAK'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERDAT'.
wa_fldcat-col_pos = 2.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Date'.
wa_fldcat-tabname = 'T_VBAK'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERZET'.
wa_fldcat-col_pos = 3.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Time'.
wa_fldcat-tabname = 'T_VBAK'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'ERNAM'.
wa_fldcat-col_pos = 4.
wa_fldcat-outputlen = 20.
wa_fldcat-seltext_m = 'Person'.
wa_fldcat-tabname = 'T_VBAK'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'VBELN'.
wa_fldcat-col_pos = 5.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Person'.
wa_fldcat-tabname = 'T_VBAP'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'POSNR'.
wa_fldcat-col_pos = 6.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Item No'.
wa_fldcat-tabname = 'T_VBAP'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'MATNR'.
wa_fldcat-col_pos = 7.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Material'.
wa_fldcat-tabname = 'T_VBAP'.
append wa_fldcat to t_fldcat.
clear wa_fldcat.
wa_fldcat-fieldname = 'NETWR'.
wa_fldcat-col_pos = 8.
wa_fldcat-outputlen = 12.
wa_fldcat-seltext_m = 'Net Value'.
wa_fldcat-tabname = 'T_VBAP'.
append wa_fldcat to t_fldcat.
endform. " FLDCAT
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 .
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 .
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.
Splitter control
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 .
- This method contains two mandatory parameters.
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 .
- 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
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, loop the internal table and set the traffic light code for an
additional column.
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. In this case, we should not set the field EXCP_FNAME
in layout.
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
MC_EVT_MODIFIED 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 .
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 style_fname whose value is name of the
additional field which holds the style.
ALV Link
Example: ALV Reporting Using Classes – ABORT Error – Field Catalog Not Found
report z730alv1.
form displaysalesorders .
call method o_grid->set_table_for_first_display
changing
it_outtab = t_vbak.
endform. " DISPLAYSALESORDERS
flowlogic:
process before output.
module status_0100.
*
process after input.
module user_command_0100.
Screen Painter:
Menu Painter
Example: Generating Field Catalog referring to parameter I_STRUCTURE_NAME of the
method SET_TABLE_FOR_FIRST_DISPLAY
report z730alv2.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
i_structure_name = 'ZCVBAK'
changing
it_outtab = t_vbak.
endform. " DISPLAYSALESORDERS
report z730alv3.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call method o_grid->set_table_for_first_display
changing
it_outtab = t_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZCVBAK'
changing
ct_fieldcat = t_fcat.
endform. " FLDCATSALESORDERS
Example: Generating Field Catalog manually, Column Coloring, Column Styling, Excluding
Standard ALV Toolbar buttons / Toolbar, Layout settings
report z730alv4.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
is_layout = wa_layo
it_toolbar_excluding = t_functions
changing
it_outtab = t_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
clear wa_fcat.
* wa_fcat-fieldname = 'vbeln'. "runtime error in ecc 6.0
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-emphasize = 'C310'. "column coloring
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 = 15.
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 = 40.
wa_fcat-style = cl_gui_alv_grid=>mc_style_button.
append wa_fcat to t_fcat.
form excludebuttons .
clear wa_function.
wa_function = cl_gui_alv_grid=>mc_fc_find.
append wa_function to t_functions.
clear wa_function.
wa_function = cl_gui_alv_grid=>mc_fc_print.
append wa_function to t_functions.
form layout .
clear wa_layo.
wa_layo-zebra = 'X'. "alternate line coloring (striped pattern)
wa_layo-grid_title = 'SALES DOCUMENTS'.
* wa_layo-no_toolbar = 'X'. "excludes entire ALV Toolbar
endform. " LAYOUT
Example: ALV Row Coloring and ALV Cell Coloring in OOPS ALV
report z730alv5.
start-of-selection.
form getsalesorders .
select vbeln erdat erzet ernam netwr
from vbak
into table lt_vbak
where vbeln in so_vbeln.
if sy-subrc eq 0.
* append lines of lt_vbak to gt_vbak. "syntax error
loop at lt_vbak into ls_vbak.
clear gs_vbak.
gs_vbak-vbeln = ls_vbak-vbeln.
gs_vbak-erdat = ls_vbak-erdat.
gs_vbak-erzet = ls_vbak-erzet.
gs_vbak-ernam = ls_vbak-ernam.
gs_vbak-netwr = ls_vbak-netwr.
append gs_vbak to gt_vbak.
endloop.
endif.
endform. " GETSALESORDERS
form fldcat .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
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 = 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 = 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 = 12.
append wa_fcat to t_fcat.
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
is_layout = wa_layo
changing
it_outtab = gt_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form rowcoloring .
loop at gt_vbak assigning <abc>.
if <abc>-erdat = '19970121'.
<abc>-rowcolor = 'C110'.
elseif <abc>-erdat = '19970122'.
<abc>-rowcolor = 'C310'.
elseif <abc>-erdat = '19970123'.
<abc>-rowcolor = 'C710'.
elseif <abc>-erdat = '19970124'.
<abc>-rowcolor = 'C510'.
else.
<abc>-rowcolor = 'C610'.
endif.
endloop.
endform. " ROWCOLORING
form layout .
clear wa_layo.
wa_layo-info_fname = 'ROWCOLOR'. "row coloring
wa_layo-ctab_fname = 'CELLCOLOR'. "cell coloring
endform. " LAYOUT
form cellcoloring .
loop at gt_vbak assigning <abc>.
if <abc>-netwr < 10000.
clear wa_scol.
wa_scol-fname = 'VBELN'.
wa_scol-color-col = 3.
wa_scol-color-int = 1.
wa_scol-color-inv = 0.
append wa_scol to <abc>-cellcolor.
elseif <abc>-netwr >= 10000 and <abc>-netwr <= 15000.
clear wa_scol.
wa_scol-fname = 'VBELN'.
wa_scol-color-col = 7.
wa_scol-color-int = 1.
wa_scol-color-inv = 0.
append wa_scol to <abc>-cellcolor.
elseif <abc>-netwr > 15000 and <abc>-netwr <= 20000.
clear wa_scol.
wa_scol-fname = 'VBELN'.
wa_scol-color-col = 1.
wa_scol-color-int = 1.
wa_scol-color-inv = 0.
append wa_scol to <abc>-cellcolor.
else.
clear wa_scol.
wa_scol-fname = 'VBELN'.
wa_scol-color-col = 5.
wa_scol-color-int = 1.
wa_scol-color-inv = 0.
append wa_scol to <abc>-cellcolor.
endif.
endloop.
endform. " CELLCOLORING
Tree Control
Summary of Splitter, Tree, picture
report z730alv6.
* tree construction
perform tree_construction.
form tree_construction .
* prepare nodes
perform preparenodes.
* display nodes
perform displaynodes.
endform. " TREE_CONSTRUCTION
form preparenodes .
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 Order'.
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 Order'.
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 Order'.
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 Order'.
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 Order'.
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 Order'.
append wa_nodes to t_nodes.
form displaynodes .
call method o_tree->add_nodes
exporting
table_structure_name = 'ZTREESTR'
node_table = t_nodes.
endform. " DISPLAYNODES
Flowlogic:
On the layout, Place custom control and name it as CST (any name).
Splitter Control, Tree control and Picture Control
report z730alv7.
* tree construction
perform tree_construction.
* PICTURE
perform picture.
form tree_construction .
* prepare nodes
perform preparenodes.
* display nodes
perform displaynodes.
endform. " TREE_CONSTRUCTION
form preparenodes .
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 Order'.
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 Order'.
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 Order'.
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 Order'.
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 Order'.
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 Order'.
append wa_nodes to t_nodes.
form displaynodes .
call method o_tree->add_nodes
exporting
table_structure_name = 'ZTREESTR'
node_table = t_nodes.
endform. " DISPLAYNODES
form picture .
* link container (o_cont2) with picture control
create object o_pic
exporting
parent = o_cont2.
Flowlogic:
On the layout, Place custom control and name it as CST (any name).
report z730alv8.
start-of-selection.
call screen 100.
form getsalesorders .
select vbeln erdat erzet ernam netwr
from vbak
into table lt_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form fldcat .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
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 = 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 = 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 = 12.
append wa_fcat to t_fcat.
form layout .
clear wa_layo.
wa_layo-excp_fname = 'LIGHTS'.
endform. " LAYOUT
form traffic_lights .
loop at lt_vbak assigning <abc>.
if <abc>-netwr < 10000.
<abc>-lights = '1'. "red color
elseif <abc>-netwr >= 10000 and <abc>-netwr <= 30000.
<abc>-lights = '2'. "yellow color
else.
<abc>-lights = '3'. "green color
endif.
endloop.
endform. " TRAFFIC_LIGHTS
Flowlogic:
report z730alv9.
start-of-selection.
call screen 100.
form getsalesorders .
select vbeln erdat erzet ernam netwr
from vbak
into table lt_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form fldcat .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
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 = 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 = 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 = 12.
append wa_fcat to t_fcat.
endform. " FLDCAT
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
is_layout = wa_layo
changing
it_outtab = lt_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form layout .
clear wa_layo.
endform. " LAYOUT
form traffic_lights .
loop at lt_vbak assigning <abc>.
if <abc>-netwr < 10000.
<abc>-lights = '@08@'. "red color
concatenate <abc>-lights 'Red' into <abc>-lights separated by space.
elseif <abc>-netwr >= 10000 and <abc>-netwr <= 30000.
<abc>-lights = '@09@'. "yellow color
concatenate <abc>-lights 'Yellow' into <abc>-lights separated by space.
else.
<abc>-lights = '@0A@'. "green color
concatenate <abc>-lights 'Green' into <abc>-lights separated by space.
endif.
endloop.
endform. " TRAFFIC_LIGHTS
Flowlogic:
process before output.
module status_0100.
*
process after input.
module user_command_0100.
report z730alv10.
start-of-selection.
form getsalesorders .
select vbeln erdat erzet ernam netwr
from vbak
into table lt_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form fldcat .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
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 = 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.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'CURRKEY'.
wa_fcat-col_pos = 6.
wa_fcat-coltext = 'Currency'.
wa_fcat-outputlen = 10.
wa_fcat-drdn_hndl = 1.
wa_fcat-edit = 'X'.
append wa_fcat to t_fcat.
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
is_layout = wa_layo
changing
it_outtab = lt_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form layout .
clear wa_layo.
endform. " LAYOUT
form dropdown .
data : t_drop type lvc_t_drop,
wa_drop type lvc_s_drop.
clear wa_drop.
wa_drop-handle = 1.
wa_drop-value = 'INR'.
append wa_drop to t_drop.
clear wa_drop.
wa_drop-handle = 1.
wa_drop-value = 'USD'.
append wa_drop to t_drop.
clear wa_drop.
wa_drop-handle = 1.
wa_drop-value = 'GBP'.
append wa_drop to t_drop.
Flowlogic:
2. Event Business logic needs to implemented as part of custom class implementation (inside
event handler method)
3. They are raised by SAP itself depending on user actions (from the standard methods)
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
͚MC_EVT_MODIFIED͛ 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.
1. Identify the ALV Report which needs to be scheduled in background. If the report
execution contains selection screen, provide input values on selection screen and save
them as variant.
3. Start condition
Note: Once the job is released, job gets executed depending on the start condition.
Note: The background job execution status will be cancelled if the ALV report makes use of
custom control. The reason for this is the background processer cannot address the front-end
controls such as custom control. So we need to modify the ALV report accordingly to link the
ALV grid directly with docking container without using custom control. Docking container is
represented by the class ͚CL_GUI_DOCKING_CONTAINER͛.
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͛.
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͛.
To Associate Standard F1 help to an ALV column, we need to set the field ͚ref_table͛ and
͚ref_field͛ as part of field catalog. In this case, F1 help will be populated if the data element of
the ALV column is associated with documentation (field labels). To associate custom f1 help to
an ALV column, we need to handle the event ͚ONF1͛ of the class ͚CL_GUI_ALV_GRID͛.
report z730events1.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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.
In this the event handler method ͚M1͛ will not be executed as the handler is not registered.
report z730events2.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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.
In this the event handler method ͚M1͛ will not be executed as the handler is registered after
raising the event.
report z730events3.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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.
In this, the event handler method ͚M1͛ will not be executed as the wrong object is registered
(OB2), the actual object which is raising the event is ͚OB1͛.
report z730events4.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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.
In this, the event handler method ͚M1͛ will be executed as and when the event is raised in the
method m2 by the object OB1
report z730events5.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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.
In this, the event handler method ͚M1͛ will be executed as and when the event is raised in the
method m2 by the object OB1 (ME refers to current object in execution ob1 executing the
method ͚m2͛)
Example: Custom Event Handling – Scenario 6
report z730events6.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
method m3.
write :/ 'Inside instance event handler method m3'.
endmethod.
method m4.
write :/ 'Inside static event handler method m4'.
endmethod.
method m2.
write :/ 'Inside instance normal method m2-about to raise event'.
raise event e1.
endmethod.
endclass.
A event can be associated with multiple event handler methods. These event handler methods
can be within the same class or across classes. If the event handler method is instance, the
handler must be object and if the event handler method is static, the handler can be either
object or class name. The sequence of execution of event handler methods depends on
sequence of handler registrations.
report z730events7.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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 z730events8.
method m1.
write :/ 'Inside instance event handler method m1'.
endmethod.
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 z730events9.
method m1.
format color 3.
write :/ 'Inside event handler method m1, importing event parameter...'.
data : lv_name1 type kna1-name1,
lv_ort01 type kna1-ort01.
select single name1 ort01
from kna1
into (lv_name1,lv_ort01)
where kunnr = e_kunnr.
if sy-subrc eq 0.
write :/ 'Customer Name :',lv_name1,
/ 'Customer City :',lv_ort01.
else.
write :/ 'Customer Not found...'.
endif.
format color off.
endmethod.
method m2.
format color 7.
write :/ 'Inside event handler method m2, not importing event parameter...'.
format color off.
endmethod.
method m3.
format color 1.
write :/ 'Inside normal method m3, about to raise event...'.
* raise event e1. "syntax error as mandatory event parameter not exported
raise event e1
exporting
* e_kunnr = '0000001000'.
e_kunnr = i_kunnr.
endmethod.
endclass.
start-of-selection.
parameters p_kunnr type kna1-kunnr.
Declare 3 methods M1 , M2 , M3
Register Method M1 as event handler (select checkbox event handler for in detail view
button)
Implementation of methods:
method m1.
format color 3.
write :/ 'Inside event handler method m1, importing event parameter...'.
data : lv_name1 type kna1-name1,
lv_ort01 type kna1-ort01.
select single name1 ort01
from kna1
into (lv_name1,lv_ort01)
where kunnr = e_kunnr.
if sy-subrc eq 0.
write :/ 'Customer Name :',lv_name1,
/ 'Customer City :',lv_ort01.
else.
write :/ 'Customer Not found...'.
endif.
format color off.
endmethod.
method m2.
format color 7.
write :/ 'Inside event handler method m2, not importing event parameter...'.
format color off.
endmethod.
method m3.
format color 1.
write :/ 'Inside normal method m3, about to raise event...'.
* raise event e1. "syntax error as mandatory event parameter not exported
raise event e1
exporting
* e_kunnr = '0000001000'.
e_kunnr = i_kunnr.
endmethod.
report z730events10.
Example: Managing Standard ALV Toolbar (Enabling / Disabling Std. ALV toolbar buttons,
Adding Custom Buttons on Std. ALV Toolbar)
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 = 'FC2'.
wa_button-icon = '@08@'.
wa_button-quickinfo = 'Display 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.
case e_ucomm.
when 'FC2'.
message 'Clicked on Custom Menu Button' type 'I'.
when others.
message 'Clicked on other than Custom Menu Button' type 'I'.
endcase.
endmethod.
endclass.
start-of-selection.
form getsalesorders .
select vbeln erdat erzet ernam netwr
from vbak
into table lt_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form fldcat .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
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 = 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.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
is_layout = wa_layo
changing
it_outtab = lt_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form layout .
clear wa_layo.
endform. " LAYOUT
form reghandlers .
create object k.
set handler k->handle_toolbar for o_grid.
set handler k->handle_menu_button for o_grid.
endform. " REGHANDLERS
Flowlogic:
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 = 'FC2'.
wa_button-icon = '@08@'.
wa_button-quickinfo = 'Display 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.
case e_ucomm.
when 'FC2'.
* message 'Clicked on Custom Menu Button' type 'I'.
call method e_object->add_function
exporting
fcode = 'MI1'
text = 'Screen Painter'.
* Add a separator
call method e_object->add_separator.
* Add the above local menu object to the imported menu object
call method e_object->add_menu
exporting
menu = o_menu.
clear o_menu.
create object o_menu.
call method o_menu->add_function
exporting
fcode = 'MI5'
text = 'Create Purchase Order'.
* add the above local menu object as a submenu to imported menu object
call method e_object->add_submenu
exporting
menu = o_menu
text = 'Purchase Orders'.
when others.
message 'Clicked on other than Custom Menu Button' type 'I'.
endcase.
endmethod.
method handle_user_command.
case e_ucomm.
when 'FC1'.
* message 'Clicked on Normal button' type 'I'.
* identify the indexes of selected rows
refresh lt_rows.
call method o_grid->get_selected_rows
importing
et_index_rows = lt_rows.
start-of-selection.
form getsalesorders .
select vbeln erdat erzet ernam netwr
from vbak
into table lt_vbak
where vbeln in so_vbeln.
endform. " GETSALESORDERS
form fldcat .
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
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 = 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.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
form displaysalesorders .
call method o_grid->set_table_for_first_display
exporting
is_layout = wa_layo
changing
it_outtab = lt_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form layout .
clear wa_layo.
wa_layo-sel_mode = 'A'. "enables multiple row selection
endform. " LAYOUT
form reghandlers .
create object k.
set handler k->handle_toolbar for o_grid.
set handler k->handle_menu_button for o_grid.
set handler k->handle_user_command for o_grid.
endform. " REGHANDLERS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table lt_vbap
for all entries in temp_vbak
where vbeln = temp_vbak-vbeln.
endform. " GETSALESITEMS
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 No'.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Item Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
form displaysalesitems .
call method vbap_grid->set_table_for_first_display
changing
it_outtab = lt_vbap
it_fieldcatalog = t_fcat.
report z730alv12.
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.
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.
endclass.
start-of-selection.
call screen 100.
* tree construction
perform tree_construction.
* PICTURE
perform picture.
form tree_construction .
* prepare nodes
perform preparenodes.
* display nodes
perform displaynodes.
endform. " TREE_CONSTRUCTION
form preparenodes .
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 Order'.
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 Order'.
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 Order'.
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 Order'.
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 Order'.
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 Order'.
append wa_nodes to t_nodes.
form displaynodes .
call method o_tree->add_nodes
exporting
table_structure_name = 'ZTREESTR'
node_table = t_nodes.
endform. " DISPLAYNODES
form picture .
* link container (o_cont2) with picture control
create object o_pic
exporting
parent = o_cont2.
form reghandlers .
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.
Flowlogic:
Screen Layout:
event method
REPORT Z730ALV13.
START-OF-SELECTION.
call screen 100.
FORM GETEMP .
select * from zemp
into table t_emp.
ENDFORM. " GETEMP
FORM FLDCATEMP .
clear wa_fcat.
wa_fcat-fieldname = 'EMPNO'.
wa_fcat-coltext = 'Employee No'.
wa_fcat-col_pos = 1.
wa_fcat-outputlen = 10.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ENAME'.
wa_fcat-coltext = 'Employee Name'.
wa_fcat-col_pos = 2.
wa_fcat-outputlen = 25.
wa_fcat-edit = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EMPDESIG'.
wa_fcat-coltext = 'Designation'.
wa_fcat-col_pos = 3.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
FORM DISPLAYEMP .
CALL METHOD EMP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_emp
IT_FIELDCATALOG = t_fcat.
FORM REGHANDLERS .
create object ob.
set handler ob->handle_data_changed for emp_grid.
* register the event data_changed explicitly
CALL METHOD EMP_GRID->REGISTER_EDIT_EVENT
EXPORTING
* I_EVENT_ID = cl_gui_alv_grid=>mc_evt_modified. "single cell modification
I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter. "triggers only when enter key is pressed
ENDFORM. " REGHANDLERS
Flowlogic:
report z730alv14.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
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_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
clear wa_fcat.
* wa_fcat-fieldname = 'vbeln'. "runtime error in ecc 6.0
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 = 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 = 15.
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 = 40.
append wa_fcat to t_fcat.
form layout .
clear wa_layo.
wa_layo-zebra = 'X'. "alternate line coloring (striped pattern)
wa_layo-grid_title = 'SALES DOCUMENTS'.
endform. " LAYOUT
report z730alv15.
start-of-selection.
call screen 100.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
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_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
clear wa_fcat.
* wa_fcat-fieldname = 'vbeln'. "runtime error in ecc 6.0
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 = 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 = 15.
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 = 40.
append wa_fcat to t_fcat.
form layout .
clear wa_layo.
wa_layo-zebra = 'X'. "alternate line coloring (striped pattern)
wa_layo-grid_title = 'SALES DOCUMENTS'.
endform. " LAYOUT
form reghandlers .
create object ob.
set handler ob->handle_double_click for o_grid.
endform. " REGHANDLERS
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.
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 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 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 = 'Net Value'.
wa_fcat-outputlen = 10.
append wa_fcat to t_fcat.
endform. " FLDCATVBAP
form displaysalesitems .
call method vbap_grid->set_table_for_first_display
changing
it_outtab = t_vbap
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESITEMS
report z730alv16.
method handle_button_click.
* message 'button click' type 'I'.
clear wa_vbap.
read table t_vbap into wa_vbap
index es_row_no-row_id transporting matnr.
if sy-subrc eq 0.
perform getmaterialplants.
if t_marc is not initial.
call screen 300.
else.
message 'No Plants for selected material' type 'I'.
endif.
endif.
endmethod.
method handle_hotspot_click.
* message 'hotspot_click event' type 'I'.
clear wa_marc.
read table t_marc into wa_marc
index e_row_id-index
transporting matnr.
if sy-subrc eq 0.
set parameter id 'MAT' field wa_marc-matnr.
call transaction 'MM03'.
endif.
endmethod.
endclass.
start-of-selection.
call screen 100.
module status_0100 output.
if gv_flag = 0.
* check whether report is in foreground or background execution
gv_mode = cl_gui_alv_grid=>offline( ).
if gv_mode eq 0. "foreground execution
set pf-status 'ABC'.
* link custom container with custom control
create object o_cont
exporting
container_name = 'CST'.
* link ALV grid with custom container
create object o_grid
exporting
i_parent = o_cont.
else. "background execution
* link alv grid with docking container reference
create object o_grid
exporting
i_parent = o_dock.
endif.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
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_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form fldcatsalesorders .
refresh t_fcat.
clear wa_fcat.
* wa_fcat-fieldname = 'vbeln'. "runtime error in ecc 6.0
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 = 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 = 15.
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 = 40.
append wa_fcat to t_fcat.
endform. " FLDCATSALESORDERS
form layout .
clear wa_layo.
wa_layo-zebra = 'X'. "alternate line coloring (striped pattern)
wa_layo-grid_title = 'SALES DOCUMENTS'.
endform. " LAYOUT
form reghandlers .
create object ob.
set handler ob->handle_double_click for o_grid.
endform. " REGHANDLERS
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_temp_vbap
where vbeln = wa_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.
wa_fcat-tooltip = 'Sales Document Number'.
* wa_fcat-style = cl_gui_alv_grid=>mc_style_button. "will set for entire column
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 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 = 'Net Value'.
wa_fcat-outputlen = 10.
append wa_fcat to t_fcat.
endform. " FLDCATVBAP
* layout
perform layoutvbap.
* reg handlers
perform handlers_reg.
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.
endform. " DISPLAYSALESITEMS
form alvcellsbuttons.
refresh t_vbap.
loop at t_temp_vbap into wa_temp_vbap.
clear wa_vbap.
wa_vbap-vbeln = wa_temp_vbap-vbeln.
wa_vbap-posnr = wa_temp_vbap-posnr.
wa_vbap-matnr = wa_temp_vbap-matnr.
wa_vbap-netwr = wa_temp_vbap-netwr.
if wa_vbap-netwr >= 5000.
clear wa_styl.
wa_styl-fieldname = 'VBELN'.
wa_styl-style = cl_gui_alv_grid=>mc_style_button.
append wa_styl to wa_vbap-cellstyles.
endif.
append wa_vbap to t_vbap.
endloop.
endform. " ALVCELLSBUTTONS
form layoutvbap .
clear wa_layo.
wa_layo-stylefname = 'CELLSTYLES'.
endform. " LAYOUTVBAP
form handlers_reg .
create object ob.
set handler ob->handle_button_click for vbap_grid.
endform. " HANDLERS_REG
form getmaterialplants .
select matnr werks ekgrp from marc
into table t_marc
where matnr = wa_vbap-matnr.
endform. " GETMATERIALPLANTS
form fldcatmarc .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 15.
wa_fcat-hotspot = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Material Plant'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EKGRP'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Purchase Group'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
form displaymatplants .
call method marc_grid->set_table_for_first_display
changing
it_outtab = t_marc
it_fieldcatalog = t_fcat.
endform. " DISPLAYMATPLANTS
form reg_handlers .
create object ob.
set handler ob->handle_hotspot_click for marc_grid.
endform. " REG_HANDLERS
Executable Program:
report z730alv17.
include z730alv17_inc.
start-of-selection.
call screen 100.
Include Program:
method handle_top_of_page.
* message 'top' type 'I'.
call method e_dyndoc_id->add_text
exporting
text = 'Gensoft Technologies'.
form getsalesorders .
select vbeln erdat erzet ernam
from vbak
into table t_temp_vbak
where vbeln in so_vbeln.
if sy-subrc eq 0.
loop at t_temp_vbak into wa_temp_vbak.
clear wa_vbak.
wa_vbak-vbeln = wa_temp_vbak-vbeln.
wa_vbak-erdat = wa_temp_vbak-erdat.
wa_vbak-erzet = wa_temp_vbak-erzet.
wa_vbak-ernam = wa_temp_vbak-ernam.
append wa_vbak to t_vbak.
endloop.
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 = 7.
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 Doc'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Date'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Time'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 5.
wa_fcat-coltext = 'Person'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
form displaysalesorders .
call method vbak_grid->set_table_for_first_display
changing
it_outtab = t_vbak
it_fieldcatalog = t_fcat.
endform. " DISPLAYSALESORDERS
form reghandlers .
create object ob.
set handler ob->handle_data_changed for vbak_grid.
form getsalesitems .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
for all entries in lt_vbak
where vbeln = lt_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 Doc'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item No'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material'.
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.
endform. " FLDCATVBAP
form displaysalesitems .
if vbap_grid is initial.
* link vbap_grid with vbap_cont
create object vbap_grid
exporting
i_parent = vbap_cont.
* register handlers
perform reg_handlers.
* display sales items for first time
call method vbap_grid->set_table_for_first_display
changing
it_outtab = t_vbap
it_fieldcatalog = t_fcat.
else.
* refresh sales items grid
call method vbap_grid->refresh_table_display.
endif.
endform. " DISPLAYSALESITEMS
form reg_handlers .
create object ob.
set handler ob->handle_top_of_page for vbap_grid.
Example: F4 Help (Standard & Custom), F1 Help (Standard & Custom) for ALV Columns
REPORT Z730ALV18.
endclass.
case e_fieldname.
when 'EMPNO'.
message 'custom f4 help for empno' type 'I'.
* suppress std.f4 help for empno(if available)
er_event_data->m_event_handled = 'X'.
when 'ENAME'.
* message 'custom f4 help for ename' type 'I'.
* suppress std.f4 help for ename(if available)
er_event_data->m_event_handled = 'X'.
* logic for populating custom f4 values
select empno ename
from zemp
into table t_f4values.
if sy-subrc eq 0.
* populate custom f4 values
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'ENAME' "int.table field name
DYNPPROG = sy-repid
DYNPNR = sy-dynnr
DYNPROFIELD = 'ENAME' "ALV column name
VALUE_ORG = 'S'
TABLES
VALUE_TAB = t_f4values
RETURN_TAB = lt_retval.
method handle_onf1.
case e_fieldname.
when 'EMPDESIG'.
* suppress standard f1 help
er_event_data->m_event_handled = 'X'.
* logic for associating custom f1 help
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Custom F1 Help'
TXT1 = 'Employee Designation'
TXT2 = 'Table:ZEMP, Fieldname: EMPDESIG'.
endcase.
endmethod.
endclass.
START-OF-SELECTION.
call screen 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ABC'.
* link custom container with custom control
CREATE OBJECT CUST_CONT
EXPORTING
CONTAINER_NAME = 'CST'.
FORM GETEMP .
select * from zemp
into table t_emp.
ENDFORM. " GETEMP
FORM FLDCATEMP .
clear wa_fcat.
wa_fcat-fieldname = 'EMPNO'.
wa_fcat-coltext = 'Employee No'.
wa_fcat-col_pos = 1.
wa_fcat-outputlen = 10.
wa_fcat-ref_table = 'ZEMP'.
wa_fcat-ref_field = 'EMPNO'.
wa_fcat-f4availabl = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ENAME'.
wa_fcat-coltext = 'Employee Name'.
wa_fcat-col_pos = 2.
wa_fcat-outputlen = 25.
wa_fcat-ref_table = 'ZEMP'.
wa_fcat-ref_field = 'ENAME'.
wa_fcat-f4availabl = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'EMPDESIG'.
wa_fcat-coltext = 'Designation'.
wa_fcat-col_pos = 3.
wa_fcat-outputlen = 20.
append wa_fcat to t_fcat.
FORM DISPLAYEMP .
CALL METHOD EMP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = t_emp
IT_FIELDCATALOG = t_fcat.
FORM REGHANDLERS .
create object ob.
set handler ob->handle_onf4 for emp_grid.
set handler ob->handle_onf1 for emp_grid.
clear ls_f4.
ls_f4-fieldname = 'EMPNO'.
ls_f4-register = 'X'.
insert ls_f4 into table lt_f4.
clear ls_f4.
ls_f4-fieldname = 'ENAME'.
ls_f4-register = 'X'.
insert ls_f4 into table lt_f4.
Introduction:
The CL_SALV_TABLE class is part of the ALV Object Model which was introduced in Net Weaver
2004. Basically it is an encapsulation of the pre-existing ALV tools. For example the class
CL_SALV_TABLE actually wraps around the CL_GUI_ALV_GRID class for container
implementation, as well as the REUSE_ALV_GRID_DISPLAY and REUSE_ALV_LIST_DISPLAY
function modules for full screen display.
It was designed to be a single point of entry when using a specific ALV tool such as the ALV
table display, ALV hierarchical sequential list, and tree ALV. All of these individual ALV tools
have their own base class, for table it is the CL_SALV_TABLE, but all have a common look. A lot
of the methods are the same, with only some differences in the parameters of the methods
depending on the actual tool you are using.
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.
Tables displayed with ALV are not ready for input.
If you insert the table as grid in container, you are not able to use batch mode (background)
MVC Requirement
Design Pattern: is a set of rules using which the code can be implemented.
Design Patterns in ABAP Objects:
2. MVC Design Pattern - --> In this, we need to separate the business logic with presentation
logic
View ---> responsible for generating the content to the user (output)
3. Factory Design Pattern - ---> hides the complexity of instantiating the objects
MVC (Model View Controller) Design pattern: The aim of MVC design pattern is to separate
the business logic and presentation logic, so that in future, changes can be made to business
logic and presentation logic without having much dependency.
Requirement: Develop an interface using MVC Design pattern to display the sales orders data
in the selected format.
Attribute tab:
Note: ͚ZTVBAK͛ is table type associated with dictionary structure ͚ZCVBAK͛ with the fields vbeln,
erdat, erzet, ernam
Method tab:
After copying the standard dictionary structure ͚RSDSSELOPT͛ to the custom dictionary
structure ͚ZSTRERDAT͛, replace the data elements of low and high fields to ͚ERDAT͛.
Implementation for method ͚getsalesorders͛:
method getsalesorders.
select vbeln erdat erzet ernam
from vbak
into table gt_vbak
where erdat between i_erdat-low and i_erdat-high.
endmethod.
Attribute Tab:
Method tab:
Implementation for method ͚createmodelobject͛ :
method createmodelobject.
create object o_model.
endmethod.
T-code: SMARTFORMS
Save and activate the smartform Generates function module dynamically
report z730view.
initialization.
create object o_ctrl.
form getmodelobject .
call method o_ctrl->createmodelobject.
endform. " GETMODELOBJECT
form getdata .
call method o_ctrl->o_model->getsalesorders
exporting
i_erdat = so_erdat.
form displayalvreport .
data o_alv type ref to cl_salv_table.
try.
call method cl_salv_table=>factory "uses factory design pattern
importing
r_salv_table = o_alv
changing
t_table = o_ctrl->o_model->gt_vbak.
catch cx_salv_msg .
message 'Exception in creating ALV object' type 'I'.
endtry.
form displayclassicalreport .
data wa_vbak type zcvbak.
leave to list-processing.
format color 3.
loop at o_ctrl->o_model->gt_vbak into wa_vbak.
write :/ wa_vbak-vbeln,
wa_vbak-erdat,
wa_vbak-erzet,
wa_vbak-ernam.
endloop.
format color off.
endform. " DISPLAYCLASSICALREPORT
form displaysmartform .
* get the smartform function module name
data lv_fname type rs38l_fnam.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'Z730SFORM'
importing
fm_name = lv_fname.
In the program, choose goto menu text elements selection texts (construct appropriate
text)
CROSS-APPLICATIONS
RFC:
BAPI
ALE AND IDOCS
ENHANCEMENTS
Lsmw
RFC
RFC communication
1. Create a Function group in SE80 to store the function modules Function Group
name ZRFCGRP
2. Create a remote Function Module (SE37)
Source Code of Function Module:
FUNCTION ZGETCUSTOMER.
*types : begin of ty_kna1,
* name1 type kna1-name1,
* ort01 type kna1-ort01,
* end of ty_kna1.
*
*data wa_kna1 type ty_kna1.
*
*select single name1 ort01
* from kna1
* into wa_kna1
* where kunnr = i_kunnr.
*if sy-subrc eq 0.
* e_name1 = wa_kna1-name1.
* e_ort01 = wa_kna1-ort01.
*endif. "(or)
select single name1 ort01
from kna1
into (e_name1,e_ort01)
where kunnr = i_kunnr.
ENDFUNCTION.
REPORT ZCALLSRFC.
Summary :
Cross-Apps--> RFC
--> For Remote Function Modules, parameters are always passed by value
b) RFC Client --> system from where the remote F.M is called
2. Asynchronous RFC
3. Transactional RFC
Synchronous RFC:
Syntax:
[parameters list].
Asynchronous RFC:
Syntax:
[exporting parameters].
[importing parameters].
--- ---
-- ---
endform.
import :
export:
source code :
Executable program (RFC client program) to call above remote function in Synchronous
MODE:
REPORT ZCALLSRFC.
Executable program (RFC client program) to call above remote function in ASynchronous
MODE:
REPORT ZCALLARFC.
Note: Both for Synchronous RFC and Asynchronous RFC, RFC Server should be available at the
time of communication, otherwise call to Remote Function leads to runtime error.
TRFC Communication
in background task
[exporting parameters].
It is recommended to call only those F.M's in TRFC Mode which doesn't return any value.
In case of TRFC call, the remote server need not be available at the time of communication. In
this case, if the remote server is not available at the time of communication, the request is
stored in the db tables 'ARFCSSTATE' and 'ARFCSDATA'of the calling system (RFC Client).
After this, SAP schedules the program 'RSARFCSE' in the background which is executed for
every 15 minutes for 20/30 attempts for processing the request. Within these attempts, if the
remote server is not available, a fresh request needs to send.
Whenever a remote function is called in TRFC mode, we need to provide the statement 'commit
work' as part of calling program, so that the request is stored in the above db tables. We can
check the execution status of TRFC using 'SM58'.
TRFC Steps:
RFC server (EHP7)
1. Consider/create a db table
DB Table: ZCUSTOMERS
Fields:
import:
source code :
REPORT ZCALLTRFC.
wa_customer-f1 = '0000000101'.
wa_customer-f2 = 'Kiran'.
wa_customer-f3 = 'Mumbai'.
commit work.
Note: Before executing the above RFC client program, Switch off the Remote SAP Server (EHP7)
and then execute, SAP schedules a program RSARFCSE in the background as a background job
which gets executed every 15 minutes to check whether remote SAP server is switched on for
processing the request. Following is the status of Background job after successful execution.
Check the status of the background job using SM37.
Job log:
Update Function modules called using the addition in update task will not be executed
immediately; instead it is marked in VBLOG table for later execution. As part of program
execution, whenever commit work statement is executed, SAP picks the entry from VBLOG
table and then executes the update F.M. As part of update F.M execution, SAP executes all the
DB statements as a single LUW in a separate process called as UPDATE Work Process .
The Normal Function modules called using the addition in update task will lead to runtime
error.
2. Create update function module (attributes tab -->select 'update F.M' radiobutton)
FUNCTION ZCUSTOMERS_DML.
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
*"----------------------------------------------------------------------
* insert a customer
data wa_cust type zcustomers.
wa_cust-kunnr = '0000000103'.
wa_cust-name1 = 'Kranthi Kumar'.
wa_cust-ort01 = 'Hyderabad'.
REPORT ZCALLUPDATEFM.
write :/ 'Hello',
/ 'Welcome'.
commit work.
As long as we access BAPI from SAP Environment, it is just like calling a F.M
SAP ---> has provided many standard Business objects which are used for performing a
task (create / change / read sales order & purchase order, create / change
/ display material, create / change / display bank details...)
Example:
SW01 (Business object builder) is the t-code used for developing custom business object
/ view the components of standard business object.
4. Function module parameter references must start with 'BAPI' and these references must
refer to a whole structure / a structure field
6. Function Module source code should not contain the statements 'COMMIT WORK' /
'ROLLBACK', instead we can use the F.M's 'BAPI_TRANSACTION_COMMIT' /
'BAPI_TRANSACTION_ROLLBACK'
bapi access
BOR
Example: Create bank using Standard BAPI - Runtime error
report zbapi1.
Note: The above BAPI execution results in runtime error specify bank key
report zbapi2.
REPORT Z730BAPI3.
REPORT Z730BAPI4.
format color 3.
write :/ 'Bank Address data..'.
write :/ 'Bank name :',wa_baddr-bank_name,
/ 'Region :',wa_baddr-region,
/ 'Street :',wa_baddr-street,
/ 'City :',wa_baddr-city.
format color off.
uline.
write :/ 'Bank Execution status..'.
format color 7.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
format color off.
format color 1.
write :/ 'Bank Execution status...'.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
format color off.
uline.
format color 3.
loop at t_blist into wa_blist.
write :/ wa_blist-bank_ctry,
wa_blist-bank_key,
wa_blist-bank_name,
wa_blist-city.
endloop.
format color off.
REPORT Z730BAPI6.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type .....',wa_return-type,
/ 'Message ..',wa_return-message.
format color off.
Example: BAPI TO CREATE MATERIAL (BAPI ERROR – BASE UNIT OF MEASURE IS DEFINED AS
REQUIRED FIELD)
REPORT Z730BAPI7.
clear wa_makt.
wa_makt-langu = 'E'. "Language keys-T002
wa_makt-langu_iso = 'EN'.
wa_makt-MATL_DESC = 'This is Material in English'.
append wa_makt to t_makt.
clear wa_makt.
wa_makt-langu = 'D'. "Language keys-T002
wa_makt-langu_iso = 'DE'.
wa_makt-MATL_DESC = 'This is Material in German'.
append wa_makt to t_makt.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type .....',wa_return-type,
/ 'Message ..',wa_return-message.
format color off.
REPORT Z730BAPI8.
clear wa_makt.
wa_makt-langu = 'E'. "Language keys-T002
wa_makt-langu_iso = 'EN'.
wa_makt-MATL_DESC = 'This is Material in English'.
append wa_makt to t_makt.
clear wa_makt.
wa_makt-langu = 'D'. "Language keys-T002
wa_makt-langu_iso = 'DE'.
wa_makt-MATL_DESC = 'This is Material in German'.
append wa_makt to t_makt.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type .....',wa_return-type,
/ 'Message ..',wa_return-message.
format color off.
REPORT Z730BAPI9.
clear wa_makt.
wa_makt-langu = 'E'. "Language keys-T002
wa_makt-langu_iso = 'EN'.
wa_makt-MATL_DESC = 'This is Material in English'.
append wa_makt to t_makt.
clear wa_makt.
wa_makt-langu = 'D'. "Language keys-T002
wa_makt-langu_iso = 'DE'.
wa_makt-MATL_DESC = 'This is Material in German'.
append wa_makt to t_makt.
Example: Create Employee Communication Details (BAPI Status- Personel number not yet
assigned)
REPORT Z730BAPI10.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
format color off.
Example: Create Employee Communication Details (BAPI Status- Employee / Applicant not
locked)
REPORT Z730BAPI11.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
format color off.
REPORT Z730BAPI12.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
format color off.
* unlock employee
clear wa_return.
CALL FUNCTION 'BAPI_EMPLOYEET_DEQUEUE'
EXPORTING
NUMBER = v_empno
VALIDITYBEGIN = '19000101'
IMPORTING
RETURN = wa_return.
endif.
Example: Create Employee Communication Details
REPORT Z730BAPI13.
format color 3.
write :/ 'BAPI Execution status...'.
write :/ 'Type :',wa_return-type,
/ 'Message :',wa_return-message.
format color off.
* unlock employee
clear wa_return.
CALL FUNCTION 'BAPI_EMPLOYEET_DEQUEUE'
EXPORTING
NUMBER = v_empno
VALIDITYBEGIN = '19000101'
IMPORTING
RETURN = wa_return.
endif.
1003 --> 2
BAPI Extension
REPORT Z730BAPI14.
clear wa_partners.
wa_partners-partn_role = 'AG'.
wa_partners-partn_numb = '0000001000'.
append wa_partners to t_partners.
clear wa_items.
wa_items-itm_number = '10'.
wa_items-material = 'AM2-GTL'.
append wa_items to t_items.
format color 3.
write :/ 'BAPI Execution status...'.
loop at t_return into wa_return.
write :/ wa_return-type,
wa_return-message.
endloop.
format color off.
T-code : VA01
ExtensionIN --> used for passing data related to customer specific fields while calling
BAPI F.M
ExtensioOUT --> used for reading data related to customer specific fields while calling
BAPI F.M
15579
BAPIExtension-ExtensionIn Internal table
Additional Fields:
Dependent Structures:
Additional Fields:
Additional Fields:
zzcompname char 1
zzcompaddr char 1
Additional Fields:
Additional Fields:
zzcompname char 1
zzcompaddr char 1
Example: Creating Sales Order using Standard BAPI by passing data related to Customer
Specific Fields through Extensionin Parameter
REPORT Z730BAPI15.
clear wa_partners.
wa_partners-partn_role = 'AG'.
wa_partners-partn_numb = '0000001000'.
append wa_partners to t_partners.
clear wa_items.
wa_items-itm_number = '10'.
wa_items-material = 'AM2-GTL'.
append wa_items to t_items.
clear wa_extin.
wa_extin-structure = 'BAPE_VBAK'.
wa_extin-valuepart1 = wa_bape_vbak.
append wa_extin to t_extin.
clear wa_extin.
wa_extin-structure = 'BAPE_VBAKX'.
wa_extin-valuepart1 = wa_bape_vbakx.
append wa_extin to t_extin.
BAPI Extension:-
using this, we can pass data to customer specific fields while calling the standard
BAPI F.M's
1. customer include structure --> 'ci_....'---> additional fields --> 'zz' / 'yy'
dependent structures
Bapi extension
extensionin --> used for passing data to additional fields through BAPI
extensionout --> used for reading data related to additional fields through BAPI
report zbapi13.
clear wa_poitem.
wa_poitem-po_item = '00001'.
wa_poitem-material = '100-100'.
wa_poitem-plant = '1000'.
wa_poitem-stge_loc = '0001'.
wa_poitem-quantity = '15.000'.
append wa_poitem to t_poitem.
clear wa_poitemx.
wa_poitemx-po_item = '00001'.
wa_poitemx-material = 'X'.
wa_poitemx-plant = 'X'.
wa_poitemx-stge_loc = 'X'.
wa_poitemx-quantity = 'X'.
append wa_poitemx to t_poitemx.
format color 3.
write :/ 'BAPI Execution status...'.
loop at t_return into wa_return.
write :/ 'Type :',wa_return-type,
/ 'Message:',wa_return-message.
endloop.
format color off.
Procedure:
Custom Fields:
zzcompname zcompname char 20
Program:
report zbapi14.
clear wa_poitem.
wa_poitem-po_item = '00001'.
wa_poitem-material = '100-100'.
wa_poitem-plant = '1000'.
wa_poitem-stge_loc = '0001'.
wa_poitem-quantity = '15.000'.
append wa_poitem to t_poitem.
clear wa_poitemx.
wa_poitemx-po_item = '00001'.
wa_poitemx-material = 'X'.
wa_poitemx-plant = 'X'.
wa_poitemx-stge_loc = 'X'.
wa_poitemx-quantity = 'X'.
append wa_poitemx to t_poitemx.
clear wa_bapi_te_mepoheader.
wa_bapi_te_mepoheader-zzcompname = 'Gentech'.
wa_bapi_te_mepoheader-zzcompaddr = 'SRnagar'.
clear wa_bapi_te_mepoheaderx.
wa_bapi_te_mepoheaderx-zzcompname = 'X'.
wa_bapi_te_mepoheaderx-zzcompaddr = 'X'.
clear gs_extin.
gs_extin-structure = 'BAPI_TE_MEPOHEADER'.
gs_extin-valuepart1 = wa_bapi_te_mepoheader.
append gs_extin to gt_extin.
clear gs_extin.
gs_extin-structure = 'BAPI_TE_MEPOHEADERX'.
gs_extin-valuepart1 = wa_bapi_te_mepoheaderx.
append gs_extin to gt_extin.
format color 3.
write :/ 'BAPI Execution status...'.
loop at t_return into wa_return.
write :/ 'Type :',wa_return-type,
/ 'Message:',wa_return-message.
endloop.
format color off.
format color 3.
write :/ 'Bapi return status...'.
loop at t_return into wa_return.
write :/ 'Type ......',wa_return-type,
/ 'Message ...',wa_return-message.
endloop.
format color off.
format color 1.
write :/ 'PO Header data...'.
write :/ 'Company code :',wa_poheader-comp_code,
/ 'Document type:',wa_poheader-doc_type,
/ 'Vendor :',wa_poheader-vendor.
format color off.
report zbapi16.
format color 3.
write :/ 'Bapi return status...'.
loop at t_return into wa_return.
write :/ 'Type ......',wa_return-type,
/ 'Message ...',wa_return-message.
endloop.
format color off.
format color 1.
write :/ 'PO Header data...'.
write :/ 'Company code :',wa_poheader-comp_code,
/ 'Document type:',wa_poheader-doc_type,
/ 'Vendor :',wa_poheader-vendor.
format color off.
format color 7.
write :/ 'PO customer specific data...'.
loop at t_extout into wa_extout.
case wa_extout-structure.
when 'BAPI_TE_MEPOHEADER'.
wa_bapi_te_mepoheader = wa_extout-valuepart1.
endcase.
endloop.
BAPI Modifications :-
Business object : CompanyCode
and comp.name
TO BE : Modify the above bapi to accept the lower limit and upper
limit of company codes as input and return the comp.codes and their
names between the given range
procedure :-
zrfcgrp
2) copy the standard bapi F.M to custom f.m following bapi standards
structure : zbapibukrs
fields :
comp_code bukrs
c) Modify the source code of the copied F.M accordingly based on the
parameters passed.
choose method 'getlist --> click on 'program' button (Appl.toolbar) ,yes, displays
source code.
edit --> change release status --> object type --> implemented
edit --> change release status --> object type --> released
f) in the initial screen of SW01, release the business object and check the entry in BOR.
Note: Make sure the F.M, Business object should be saved in transportable package.
accessing sap business object from legacy appl
Event Builder:
Dim x As String
Form_Load event:
con.logon
End Sub
Button_click event:
inputparam.Value("empno") = Me.txtempno
inputparam.Value("ename") = Me.txtename
inputparam.Value("empdesig") = Me.txtdesig
inputparam.Value("deptno") = Me.txtdeptno
x = outputparam.Value("type")
If x = "S" Then
Else
End If
End Sub
Procedure :-
1. Create a Function Module using BAPI standards and release the F.M
'BAPIRET2' /
'BAPIRETURN' /
'BAPIRETURN1'
5. F.M --> parameter references should be--> structure / individual structure fields
7. F.M --> source code --> shouldn't contain commit work and rollback
'BAPI_TRANSACTION_ROLLBACK'
8. F.M --> should be transportable --> should be stored in transportable package and
assigned to change request
4.7 :-
1. Consider/CREATE a db table
table : z7amemp
fields :
import :
export :
source code :
if sy-subrc eq 0.
return-type = 'S'.
else.
return-type = 'E'.
endif.
endif.
function builder tool(se37),initial screen --> choose function module menu --> release --
> release
4.b) Redefine the std.methods 'existencecheck' and 'display' in the methods sectionselect
existencecheck method, choose 'edit' menu --> redefine.select display method, choose 'edit'
menu --> redefine.
4. c) select each method (existencecheck,display, our api method) one after the other and click
on 'program' button(appl.toolbar), save and comeback
4. d) select each method --> choose edit menu, change release status --> object type --> to
implemented select each method --> choose edit menu, change release status --> object type --
> to released
4. e) select each method --> choose edit menu, change release status --> object type
component--> to implemented select each method --> choose edit menu, change release status
--> object type component --> to released
parameters :
IEmp
Return
Customer exit classification
enhancement classification
enhancement meaning
enhancement procedure :
Additional functionality can be in the form of additional menu items, additional validations,
additional fields.
2. identify the transaction and the base program where the enhancement needs to be
implemented
'call customer-function', so that SAP will display the points (places) where
the string is used
SAP takes the control to the corresponding function module from where identify
the customer-exit name
note :
Procedure 2 :
SMOD can be used for identifying the components of the customer-exit and to read the
documentation.
Screen exits in customer-exits: (screen enhancements): Used for adding additional fields
specific to customer in the std. SAP screens.
These additional fields are generally placed in the subscreen reserved for customer
enhancement. This subscreen is placed on top of subscreen area. This subscreen is called by
SAP itself at the relevant place.
Customer specific fields are used to capture additional info. which is specific to customer.
Initially, we need to add these fields in the corresponding std.base table in the form of
customer include structure ('CI_...') or in the form of append structure. It is recommended to
following the CUSTOMER NAMESPACE naming standard for the customer specific fields.
According to customer namespace standards, the customer specific fields must start either with
'ZZ' / 'YY' otherwise we may face issues at the time of upgradation.
Every screen exit of a customer exit MAY/will be associated with 2 function exits.
1. PBO function exit --> can be implemented to provide default values for the customer
specific fields on the transaction
2. PAI function exit --> can be implemented to capture values entered by the user in the
runtime for the customer specific fields on the transaction.
Requirement: Enhance the Transaction 'MP01' to capture additional data (customer specific)
Transaction: MP01
Customer-exit: AMPL0001
Procedure:
Additional Fields:
(layout button-->appl.toolbar)
tables ampl.
*i_ampl-zzcompname = 'IMAX'.
*i_ampl-zzcompaddr = 'Ameerpet'.
i_ampl-zzcompname = 'IMAX'.
i_ampl-zzcompaddr = 'Ameerpet'.
ampl-zzcompname = i_ampl-zzcompname.
ampl-zzcompaddr = i_ampl-zzcompaddr.
*(or)
*ampl-zzcompname = 'IMAX1'.
*ampl-zzcompaddr = 'Srnagar'.
e_ampl-zzcompname = ampl-zzcompname.
e_ampl-zzcompaddr = ampl-zzcompaddr.
Requirement: Enhance the Transaction 'XD01' to make industry key field mandatory for Indian
customers
transaction : XD01
Customer-exit : SAPMF02d
Procedure:
message 'Please enter industry key in control data tab for indian customers' type 'E'.
endif.
Used for adding additional menu items specific to customer in the std. SAP menus.
These additional menu items are generally placed in the std. menu called as 'Extras'.
For these additional menu items, the function codes are provided by SAP itself and they start
with '+'.
As a developer, we are only responsible for providing menu item text and implementing the
action for that menu item.
The implementation for these menu items are done as part of corresponding function exit.
Transaction: MC94
Double click on each function code, provide function text (abap editor, function builder, class
builder......)
To implement the logic for these menu items, double click on function exit and implement the
following in the corresponding include program.
case sy-ucomm.
when '+CU1'.
when '+CU2'.
when '+CU4'.
when '+CU5'.
when '+CU6'.
when '+CU7'.
when '+CU8'.
when '+CU9'.
endcase.
Test the t-code 'MC94' (provide planning type as commit, press enter) --> choose active version
button, displays a screen and choose the menu 'extras' for additional menu items under
submenu 'customer functions'.
Transaction: FBL3N
BADI: FI_ITEMS_MENUE01
Implementation (SE19): Provide Functions texts for menu items
method IF_EX_FI_ITEMS_MENUE01~LIST_ITEMS01.
call transaction 'SE38'.
endmethod.
method IF_EX_FI_ITEMS_MENUE01~LIST_ITEMS02.
call transaction 'SE24'.
endmethod.
method IF_EX_FI_ITEMS_MENUE01~LIST_ITEMS03.
call transaction 'SE37'.
endmethod.
method IF_EX_FI_ITEMS_MENUE01~LIST_ITEMS04.
call transaction 'SEGW'.
endmethod.
Testing:
T-code FBL3N : Provide G/L account (1000) and company code(1000) and execute Displays
ALV Report , check the menu Extras for additional menu items
BADI's (Business Addin's):
1. BADI implementation name --> responsible for implementing the BADI definition
2. BADI Implementation class --> ''z/y'cl_im_<impl.name>' --> Responsible for
implementing the BADI interface
3. Filter values -->
4. Fallback class --> Associated with 'KERNEL' BADI s -->
Purpose of BADI:
Procedure 1:
2. In the main program, search for the string cl_exithandler=>get_instance', displays the lines
where the method is called. In the method Signature, identify the badi name by referring to the
parameter 'exit_name' (or) refer to the parameter 'instance'
Procedure 2:
Procedure 3:
1. In performance analysis tool (ST05), select the traces 'SQL Trace' and 'Table buffer
trace' and activate the trace
3. Come back to 'ST05' session, deactivate the trace and display the trace. Search for the
BADI's by providing the database views 'V_EXT_ACT' and 'V_EXT_IMP' in the objects field.
Requirement: While creating customers in XD01, for Indian customers, Industry key is
mandatory.
Transaction: XD01
First Implementation:
SE19 --> In 'create implementation' block , choose the radio button (new badi), provide the
enhancement spot name (customer_add_data), click on 'create impl.' --> It will prompt to
provide enhancement implementation, provide the enh.impl.
name(ZCUSTOMER_ADD_DATA_ENHIMPL),continue---> It will prompt to provide 'badi
implementaion name', provide badi impl.name(zcustomer_add_data_impl1) for the badi
definition 'customer_add_data',continue --> Double click on implementing class node and
provide the impl. class name (zcl_im_customer_add_data_impl1), press enter and create class -
-> In the Implementation class , double click on the method 'check_all_data' to implement the
method.
First implementation:
method if_ex_customer_add_data~check_all_data.
endmethod.
Second implementation:
method if_ex_customer_add_data~check_all_data.
endmethod.
Third implementation:
method if_ex_customer_add_data~check_all_data.
endmethod.
Fourth implementation:
Consolidated Example:
method IF_EX_CUSTOMER_ADD_DATA~CHECK_ALL_DATA.
message 'Please enter industry key for INDIAN Customers' type 'I'.
endif.
endmethod.
method IF_EX_CUSTOMER_ADD_DATA~PRESET_VALUES_CCODE.
E_KNB1-AKONT = '125000'.
endmethod.
Note: To test the second implementation, while creating customer in 'XD01' provide company
code (1000) in initial screen --> click on company code data button in Appl. toolbar -->
Recon.account field will be defaulted with the value '125000'.
enhancement spot --> container of one or more badi definitions--> each badi definition --->
associated with badi interface--> badi interface ---> associated with one or more abstract
methods
enhancement implementation --> container of one or more badi implementations--> each badi
implementation --> associated with badi implementation class --> badi implementation class -->
implements methods of badi interface
first implementation:
second implementation:
--> check_all_data,save_data
third implementation:
Fourth implementation:
--> check_all_data
customer_add_data
method IF_EX_CUSTOMER_ADD_DATA~CHECK_ADD_ON_ACTIVE .
if i_screen_group = 'Z1'.
e_add_on_active = 'X'.
endif.
endmethod.
Fields:
method IF_EX_CUSTOMER_ADD_DATA_CS~GET_TAXI_SCREEN .
if i_taxi_fcode = 'FC1'.
e_screen = '4000'.
e_program = 'ZCUSTPROG'.
endif.
endmethod.
Layout:
Standard BADI's:
a) BADI Name
b) BADI Interface
Procedure:
(Call badi....)
method ZIF_EX_CSTBADI~M1.
endmethod.
method ZIF_EX_CSTBADI~M1.
endmethod.
Requirements :-
1. SPRO ---> custom screen group --> Z1 ---> button (appl.toolbar) --> invisible
3. KNA1 --> append str --> zCMP --> 2 fields --> activate
std.badi :-
custom.badi :-
mp01
se51 --->
Filter type : c
method ZIF_EX_FTBADI~M1.
message 'Default implementation' type 'I'.
endmethod.
Executable Program:
REPORT ZTRIGGER_FTBADI.
Filter type : c
Select no check
Filter type : c
Select no check
Executable Program:
REPORT ZTRIGGER_FLTBADI.
se19 ---> std badi interface method impl ---> logic to trigger badi
impl5 ---> end users ---> u5,u6,u7.... ---> 10 % ---> fallback class impl.
IDOCS
ALE/IDOCS
NOTE
ALE is a technology used for generating, distributing and posting the idoc s.
IDOC is a SAP owns format used for carrying a data (container of data) from one place to other
place.
Note: Each Message type can be associated with multiple IDOC TYPES .
3. Idoc: Idoc is a runtime component which holds the data. Table EDIMSG (Output
Types and Assignment to IDoc Types).
4. Logical systems: These are the alternative names provided for the systems involved
in IDOC communication. A logical system is a client independent object.
Note: The No. of Logical systems depends on the No. of systems involved in IDOC
Communication.
5. Port number:- it is a unique number used for identify your resource on the system.
A partner profile for sender is a collection of receiver logical system, message type,
port number and IDOC type.
A partner profile for receiver is a collection of sender logical system, message type
and inbound process code. It is client dependent object.
7. Model view: It binds the sender and receivers logical systems along with the
message types.
Example:
The inbound program can be the function module / it can be work flow task.
10. Process code:- It acts as a identifier for inbound program. It is generally the first
four characters of message type .
Scenario:
Distributing master data (material data) from one client to another client through IDOC s
Setting at sender side:
1. Create two logical systems, one for sender and another on behalf of receiver.
Note:
Since logical systems are client independent we can create both logical systems
in one client itself, as both clients belongs to same server.
3. Create RFC destination for holding the details of receiver client (sm59).
19. Process the idocs if any error s in posting setting at sender side.
Structure of IDOC / Components of IDOC:
1. Control record:
It is like a envelope of a letter which contains the sender and receiver s information
which includes part er u er, essage type, ido type, port u er, et ….. .
2. Data record:
i. Admin section contains: the segment information like segment name and
segment number.
3. Status record:
It contains status of the idoc during it s journey from source to destination. Each
checkpoint is associated with status code.
IDOC Filtering:
It is a processing of filtering the IDOC s before distributing to the receivers. It can be filtered in 2
ways.
Data level filtering: This is configured as part of Model View in Sender System.
The pre-requisite for the segment filtering is the partner profiles of both sender and receiver
must exist in the sender system. It is always configure at sender side.
Make sure, the above partner profile 830SENDL is also created in 800 client (WE20).
Mandatory Segments cannot be filtered.
Processing error IDOC s:
Procedure: Analyze the error of IDOC & identify whether it is functional or technical issue. If it is
a functional issue, the functional consultant should configure the required settings and if it is a
technical issue, the ABAP consultant should address the same and then the ABAP consultant
can process the error IDOC by using Transaction code -> BD87/WE19.
BD87 Processes the existing error idoc without generating new IDOC.
WE19 ignores the existing error IDOC & generates new IDOC.
LSMW tool is used for migrating the data from legacy system to SAP.
In LSMW using IDOC, the LSMW tool picks the data from legacy system, generates IDOC s using
ALE technology and distributes the IDOC s to the configured SAP system.
In LSMW using IDOC, we require only one set of ALE objects which are specific to receiver.
1. Maintain object attribute: In this, choose the type of technique as IDOC and provide
appropriate message type and IDOC type.
3. Maintain source fields: In this, we need to declare the fields for the above structure
corresponding to the flat file fields.
4. Maintain structure relation: In this, we need to map the custom source structure with
the corresponding segment structure.
5. Maintain field mapping and conversion rule: In this, we need to MAP the fields of the
custom structure with the fields OF standard segment structure. We can also define the
rules FOR the mapped fields.
6. Maintain fixed values translations user define routines: In this, we implement the rules
which are defined above.
7. Specify files: In this, we need to specify the path of the files AND ITS PROPERTIES.
8. Assign files: In this, map the uploaded files to the corresponding source structures.
9. Read data: In this, data is read from flat file and it is stored in application server file
(LSMW.READ).
10. Display read data: In this, data is displayed from LSMW.READ file.
11. Convert data: In this, rules are executed on LSMW.READ file and converted data is
stored in LSMW.CONV file.
12. Display converted data: In this, data from LSMW.CONV file is displayed.
13. Start IDOC generation: In this, LSMW.CONV file is sent for IDOC generations.
14. Start IDOC processing: It processes the generated IDOCS and distributes to the
receiver.
15. Create IDOC Overview: It takes the control to WE02 and displays the generated IDOCS.
16. Start IDOC Follow-up: In this, we can re-process the error IDOC s (if-any) after
configuring the functional settings.
LSMW tool is used for Migrating the data from legacy system to SAP.
In LSMW using BAPI, the LSMW tool picks the data from legacy system, generates IDOC s using
ALE technology and BAPI API method and distributes the IDOC s to the configured SAP system.
In LSMW using BAPI, we require only one set of ALE objects which are specific to receiver.
LSMW SETTINGS:
1. Maintain object attribute: In this, choose the type of technique as BAPI and provide
business object type BUS1011 and method as Create , SAP proposes corresponding
message type (BANK_CREATE) and IDOC type (BANK_CREATE01).
3. Maintain source fields: In this, we need to declare the fields for the above structure
corresponding to the flat file fields.
4. Maintain structure relation: In this, we need to map the custom source structure
with the corresponding segment structure.
5. Maintain field mapping and conversion rule: In this, we need to MAP the fields of
the custom structure with the fields OF standard segment structure. We can also
define the rules FOR the mapped fields.
6. Maintain fixed values translations user define routines: In this, we implement the
rules which are defined above.
7. Specify files: In this, we need to specify the path of the files AND ITS PROPERTIES.
8. Assign files: In this, map the uploaded files to the corresponding source structures.
9. Read data: In this, data is read from flat file and it is stored in application server file
(LSMW.READ).
10. Display read data: In this, data is displayed from LSMW.READ file.
11. Convert data: In this, rules are executed on LSMW.READ file and converted data is
stored in LSMW.CONV file.
12. Display converted data: In this, data from LSMW.CONV file is displayed.
13. Start IDOC generation: In this, LSMW.CONV file is sent for IDOC generations.
14. Start IDOC processing: It processes the generated IDOCS and distributes to the
receiver.
15. Create IDOC Overview: It takes the control to WE02 and displays the generated
IDOCS.
16. Start IDOC Follow-up: In this, we can re-process the error IDOC s (if-any) after
configuring the functional settings.
We go for custom IDOC creation whenever we need to distribute customer specific data. For
this, we need to create all the IDOC related objects from the scratch.
NOTE
If the segment is a qualified segment, than the first field value of the SEGMENT will be
displayed as part of data record when the IDOCS are displayed.
Whenever a segment is created, a corresponding dictionary structure gets created with the
name of the segment.
Step 16: Link message type, IDOC type and function module (WE57).
1. Create a selection screen for accepting the range of employees, defaulting the
message type and a field for accepting receiver logical system.
3. Prepare the data record. In this prepare the segment name in the admin section and
actual data of the IDOC. After preparing the data record, pass the control record as
well as data record as a parameter to the function module
IDOC_MASTER_DISTRIBUTE , it generates a communication IDOC and returns the
same in an internal table which is of type EDIDC .
As part of inbound function module, there will be an internal table which carries the IDOC data.
We need to read this internal table corresponding to the segment and update the same to the
corresponding database table. If the update is successful, set the status code to 53 (application
document posted successfully) otherwise 51 (application document not posted successfully)
Change pointers:
- Change pointers are used for tracking the changes made to master data.
1. Globally (BD61).
RBDMIDOC (BD21):
It is the executable program which retrieves changes made to the master data and distributes
those changes to receivers.
Note:
Once change pointers are activated, the changes made to master data will be stored in
following tables.
Note: Whenever we run the program RBDMIDOC, SAP picks the data from above tables
and generates the appropriate no. of IDOC S and distributes these IDOC S to configure
receivers.
After distribution, the field PROCESS in the table BDCPS is set to X indicating that
the changes are distributed.
Not distributed.
IDOC archiving:
It is a process of compressing the IDOC s which are not in use. The purpose of archiving is to
improve the performance of application server and also to increase the disk space.
The IDOC s which are not in use as to be deleted on the regular basis. The IDOC s cannot be
deleted directly, so we must archive it before deletion. Whenever an IDOC is archived, an
archive file will be generated which is an input for deleting the IDOCS.
To archive the IDOC s we need to configure the physical path, so that the archived files are
stored in that path.
Procedure for archiving:
RSEXARCL is a report program for reloading the IDOCs from an archive file.
RSEXARCD is a report program for deleting the IDOCs stored in the archive file.
Note: we can use the t-code SARA for archiving the IDOC s. This T-code will schedule the
program RSEXARCA in the background for archiving the IDOC s based on the variant input
values.
Note:
At Receiver side, we need to change the status to 68 and at sender side; we need to change the
status to 31 which indicates ERROR IDOC-NO FURTHER PROCESSING .
- It is a process of creating a new message type from the existing message type.
- As part of this, all the corresponding IDOC types will be assigned to the new message
type automatically.
- As part of this new message type creation, we can select/deselect the required segment
and fields.
Distributing transaction data through IDOC s: This is done by configuring Message control.
Transaction data Pur hase Order data, Sales Order data, I voi e data…
- Message control is used for triggering outputs from applications and to control the
timing of output triggering
Port
SAP TO SAP using IDOC
SAP-NONSAP
Distrubuting Master IDOC - Material IDOC- Single Recipient-22nd Nov 2016 :
sapuser,sapabap123 sapuser,sapabap123
8AMSEND, 8AMRECV
2. Assign logical systems to source and receiver clients (T-CODE : sale / scc4)
(table : RFCDES)
8AMIDOCRFCDEST
(table : EDIPO)
A000000057
(table : EDMSG)
material matmas
customer debmas
vendor cremas
EDIMSG (table for links between message type and idoc types)
(table : TBD00)
8AMMODEL
(Table : EDPP1)
outbound parameters
8AMRECV
note :- check(confirm) whether above materials are not available in receiver client (810)
13. Run the selection program /outbound program FOR distributing the material data
through idoc
-----
15. If any error idocs are generated, analyse the error idoc and configure the functional
settings if required
16. Re-process the error idocs for distributing using t-code 'BD87'
+ inbound parameters
8AMSEND
18. If any error idocs are received, analyse the error idoc and configure the
functional settings if required
IDOC --> Container of data which can be used to carry the data from one System to another
System (SAP / NON-SAP)
IDOC data --> can be master data / transaction data / customer specific data
To Configure, Generate, Distribute and Post the IDOC's , we use ALE Technology.
In case of std. Master data / std. Transaction data , idoc related objects are provided by SAP
itself.
In case of customer specific data, idoc related objects should be manually created by ABAP
consultants.
idoc related objects :- idoc type, segment, message type, selection/outbound program,
inbound process code, posting / inbound program...
1. Message type --> indicates what type of data is stored inside idoc.
Business Objects Message Type
Material matmas
customer debmas
vendor cremas
---- ----
--> One message type can be associated with 'n' of idoc types
--> it provides the organized structure of the fields related to business object
t-code for viewing the link between message type and idoc type --> we82
table for viewing the link between message type and idoc type --> EDIMSG
3.Logical System : It is a unique name(alias name) assigned for the sender and receiver system
involved in idoc communication. They are client independent.
4. RFC Destination: It stores the details of receiver system like receiver ipaddress/hostname,
client no and logon credentials.
T-code: SALE / SM59
table: RFCDES
5. TRFC port (Transactional RFC port) : It is a unique no generated and it is used for identifying
a resource on the target system.
TRFC port is created on behalf of receiver and it is created on TOP of RFC destination.
T-code : WE21
Table: EDIPO
6. Model View: Is an object which stores sender and Receiver's info along with message type
and idoc filtering configuration.
Table: TBD00
7. Partner Profile: Stores information about partner system. It is created on top of partner
logical system. It is client dependent.
T-code: WE20
Table: EDPP1
8. Inbound process code : It is an identifier for inbound program. i.e it provides the link to the
inbound program for reading the incoming idoc. It is generally first four characters of
message type.
T-code: WE42
enhanement-idoc,bapi,transaction,table
Example: Enhancing Customer Master Transaction (XD01) to Capture Additional data specific
to business and also enhance the corresponding standard IDOC related to customer master to
distribute customer specific fields through IDOC
Additional Fields:
yycompname ycompname char 20
yycompaddr ycompaddr char 20
Pre-requisites:
method IF_EX_CUSTOMER_ADD_DATA~CHECK_ADD_ON_ACTIVE.
if i_screen_group = 'Y1'.
e_add_on_active = 'X'.
endif.
endmethod.
b) Now, Create a custom module program (ZMYCSTPROG) with subscreen 4000 and
place above customer specific fields
c) Implement the method get_taxi_screen of the badi CUSTOMER_ADD_DATA_CS
method IF_EX_CUSTOMER_ADD_DATA_CS~GET_TAXI_SCREEN.
if i_taxi_fcode = 'FC1'.
e_screen = '4000'.
e_program = 'ZMYCSTPROG'.
endif.
endmethod.
Note: Before implementing the above BADI method, In SE19 Properties tab provide
the filter value Y1
d) Activate and test by creating new customer in XD01 transaction. As part of this,
capture data for customer specific fields. Check the entry in KNA1 table.
IDOC Extension:
ENHANCED IDOC: standard segments (std.fields) + custom segment (customer specific fields)
Step 1: Add customer specific fields in the db table (APPEND STRUCTURE OR CUSTOMER
INCLUDE)
Table: KNA1
Additional Fields:
zzcompname zcompname char 20
zzcompaddr zcompaddr char 20
Step 2: Enhance the standard transaction (XD01) to display the above additional fields.
Step 4: Create the extended IDOC type with additional segment (we30).
Note: plug the above segment (YCMPSEG) under root segment 'E1KNA1M'
Save and release the extended idoc type
Step 5: link all objects (message type + basic idoc type + extended idoc type + release) (we82).
debmas + debmas07 + YCMPIDOC + 480
ALE SETTINGS:
Step 7: identify the enhancements (if available) in the standard selection program for capturing
the additional fields data while generating idocs.
Package: CGV
Function exits:
EXIT_SAPLVV01_001 --> Sender side (logic for retrieving additional data and appending to
standard IDOC data)
EXIT_SAPLVV02_001 --> Receiver side (logic for reading incoming data from customer specific
segments and updating the same to the relevant tables)
Implement the above two function exits by assigning the customer exit to a project using
CMOD t-code
case segment_name.
when 'E1KNA1M'.
read table idoc_data into wa_data
with key segnam = 'E1KNA1M'.
wa_e1kna1m = wa_data-sdata.
wa_data-segnam = 'YCMPSEG'.
wa_data-sdata = wa_mapping.
append wa_data to idoc_data.
endcase.
idoc_cimtype = 'YCMPIDOC'.
Activate the customer-exit implementation and generate the IDOC using the t-code BD12 ,
provide customer no as input, output type (message type), receiver logical system. Now, in the
IDOC generated, check whether custom segment is plugged in the data record of the IDOC.
6th Sep :
Sender side :-
Structure of idoc :-
sender side :-
control record --> edidc ---> work area --> prepared by developer
a) admin section
2. declare work area based on segment structure and assign the retrieved data to
segment work area fields
wa_emp-empno = lv_empno.
wa_emp-ename = lv_ename.
wa_emp-empdesig = lv_empdesig.
Assignment :-
sdata = wa_emp.
idoc type(matmas05)
segments(e1maram,e1maktm,e1marmm)
inbound program(idoc_input_matmas01)
table : zidocemp
fields :-
empno's : 1,2,3,4
8AMSEND,8AMRECV1
8AMIDOCDEST_810
A000000067
ZEMPSEG
fields :
(first field value of the segment) will be suffixed with the segment
name.
zempidoc
EMPMSG
EMPMODEL
8AMRECV1
Procedure : 758745
1. Create the selection screen for reading range of primary key fields
(empno), default message type(EMPMSG) ,and a field for reading partner
logical system(8AMRECV)
Sender program :-
report zsendemployeeidoc.
REPORT ZSENDEMPLOYEEIDOC.
REPORT ZSENDEMPLOYEEIDOC.
initialization.
start-of-selection.
ls_ctrl_rec-rcvprt = 'LS'.
ls_ctrl_rec-rcvprn = p_logsys.
ls_ctrl_rec-mestyp = p_mestyp.
ls_ctrl_rec-idoctp = 'ZEMPIDOC'.
if sy-subrc eq 0.
clear ls_emp_seg.
ls_emp_seg-empno = ls_emp-empno.
ls_emp_seg-ename = ls_emp-ename.
ls_emp_seg-empdesig = ls_emp-empdesig.
clear ls_data_rec.
ls_data_rec-segnam = 'ZEMPSEG'.
ls_data_rec-sdata = ls_emp_seg.
exporting
master_idoc_control = ls_ctrl_rec
tables
communication_idoc_control = lt_comm_idocs
master_idoc_data = lt_data_rec.
if sy-subrc eq 0.
commit work.
refresh lt_data_rec.
endif.
endloop.
endif.
write : / ls_comm_idocs-docnum.
endloop.
endif.
8AMSEND
ZREADEMPLOYEEIDO
3. Link message type and idoc type with the function module
(we57)
EMPM
Receiver program :-
Procedure :
case wa_data-segnam.
when 'ZEMPSEG'.
wa_emp_seg = wa_data-sdata.
move-corresponding wa_emp_seg to wa_emp_table.
endcase.
endloop.
if sy-subrc eq 0.
wa_status-docnum = wa_data-docnum.
wa_status-status = 53.
wa_status-msgty = 'EMPMSG'.
else.
wa_status-docnum = wa_data-docnum.
wa_status-status = 51.
wa_status-msgty = 'EMPMSG'.
endif.
IDOC Filtering :
1. data level filtering --> configured as part of model view (sender side)
8AMMAT100,P,ROH
8AMMAT101,F,AEM
8AMMAT102,P,FERT
8AMMAT103,I,COUP
8AMMAT104,O,P01
8ammat105,P,FERT
filter : filter cond ---> distribute ONLY those materials whose material type is either 'FERT' (or)
'COUP'
pre-requisite: 1. partner profile of both sender and receiver should be in sender system
8AMMAT100 P PLM
8AMMAT101 F VKHM
8AMMAT102 P FERT
8AMMAT103 B COUP
8AMMAT104 W FOOD
8AMMAT105 P FERT
lsmw using idoc
LSMW Tool is used for migrating data from legacy system file to SAP.
LSMW Techniques :-
t-code : LSMW
--> MSGFN,MATNR,MTART,MBRSH,MATKL,MEINS,GEWEI
makt.txt --> contains data related to segment 'E1MAKTM'
--> MSGFN,SPRAS,MAKTX,SPRAS_ISO
005,E,THIS IS 8AMIDOCMAT100,EN
005,8AMIDOCMAT100,ROH,P,001,KG,KG
ENHANCEMENT FRAMEWORK CLASSIFICATION
Enhancement Framework: is the new technique provided by SAP for enhancing SAP repository
objects. As part of this, there are 4 types of enhancements.
3. Class enhancements
4. Kernel BADI s
Source code enhancements: It is the process of enhancing the standard SAP source code by
plugging customer specific source code. There are 2 types of source code enhancements.
Implicit source code enhancements: In this, the enhancements can be done in the source code
of the standard SAP Repository objects and for this SAP has provided the enhancement options
at the following areas
Explicit source code enhancements: In this, the enhancement options have to defined and
implemented by Developer itself. It exists in two forms
Syntax:
Syntax:
statements.
end-enhancement-section.
Note: To implement Source code, function group and class enhancements, the object must be
opened in enhanceable mode.
Function Group Enhancements: In this, we can enhance standard function modules provided
by SAP. As part of this, we can do following enhancements