Abap Class Notes: Topics Covered in The Document
Abap Class Notes: Topics Covered in The Document
Synta%&'
Dpdate +db table, from +wa,.
Dpdate +db table, from table +itab,.
E%&' update vbap from waOvbap.
E%&' update vbap from table itOvbap.
De"ete:'
:his statement is used to delete either a single record or multiple records from data
base table.
ABAP Page 60
Abap Class Notes
Sy'subrc M ? means all records are successfully deleted.
Sy'subrc NE ? means no records are deleted.
Synta%&'
Celete +db table, from +wa,.
Celete +db table, form table +itab,.
E%&' delete mara from waOmara.
E%&' delete mara from table itOmara.
Prere'uisites @or a#ove statements&'
Always wor7 with internal tables rather than wor7 areas to insert*update*modify data
into database table.
:he structure of internal table * wor7 area must be same as data base table.
E%&' data& iO7na> type standard table of 7na>.
Sstem varia#"es&'
:here are two system variables which are update automatic for each open s"l operations.
>. Sy'subrc.
@. Sy'dbcnt.
S2su#rc&'
8t is a system variable which stores the return code of an open s"l operation.
8f sy'subrc M ?. 8t menas the operation is successfully e%ecuted.
8f sy'subrc NE ?. 8t means the operation is failed.
S2d#cnt&'
8t is a system variable which stores the number of records successfully processed.
Note&' apart form these two we are having so many system variables which we can see in syst
table.
ABAP Page 61
Abap Class Notes
/.%odu"ari&ation.
!odulari5ation is a better techni"ue of dividing a main program in sub programs for a better
readability and reusability is called modulari5ation. !odulari5ation is achived using the
fallowing techni"ue.
>. 8nclude programs
@. 9unction modules
/. Subroutines
T. !acros (used in K3'ABAP module.
F. Class methods (used in --ABAP.
Inc"ude pro3rams&'
:hese programs contain a set of reusable statements.
:hese can not be e%ecuted independently.
:hese must be inserted in the main program for e%ecution
:hese programs are called as type (8) programs.
8t does not contain any parameters interfaces i.eB no importing no e%porting
parameters.
E%&' SAP!STFA is the standard program for sales order which contains n number of
include programs.
8nclude 5mainOprogOtop.
Creatin3 a inc"ude and ca""in3 the inc"ude in the eCecuta#"e pro3ram&'
.o to SE/0 and provide the progam name 45%%%%%%%%%6.
Clic7 on create.
.ive the description and in the program type select the type as ;include program<.
Clic7 on create
8t will create a program with the statement ;include 5%%%%.)
#rite the code which you want to reuse.
Save chec7 and activate.
.o to se/0 and provide the program name 5%%%%%%%%
Clic7 on create
.ive the description and in the program select the type as ;e%ecutable program<.
Clic7 on create
8t will create a program with the statement ;report 5%%%%).
Now in that program where ever you want write the code as
8nclude 5%%%%.
So that 8t will call the code at that position.
Save chec7 and activate.
ABAP Page 62
Abap Class Notes
/unction modu"es&'
8t is a repository obJects which contain ABAP logic or statements for doing a specific
tas7 or functionality.
9unction modules contain parameters interfaces i.eB importB e%portB changingB tables
etc.
:hese are mainly used for global modulari5ation.
9unction modules can be remote enable. i.eB they can access remote servers to fetch
the data.
9unction modules contain e%ceptions to catch certain type of errors.
/unction 3roup&'
8t is a group or container of function modules.
Every function module must be inserted in a function group.
/unction modu"e parameter inter@ace (se/G ro SE0?&'
Import&' input variables to function modules are called importing parameters.
ECport:' output variables from function modules are called as e%porting parameters.
Chan3in3&' variables which acts as importing and e%porting are called as changing
parameters.
Ta#"es&' internal tables which acts as importing and e%porting are called as tables
parameters.
ECceptions&' these are used to catch certain types of errors . E%ceptions are returns in sy'
subrc variable.
Source code&' it consist of ABAP code for doing a specific tas7.
Steps to create a @unction 3roup&'
#e can create function group either in SE/G*SE0?.
.o to SE0?
Select function group.
.ive the name as 5%%%%.
Press enter
Clic7 on yes
Provide the short description.
ABAP Page 63
Abap Class Notes
Clic7 on save
Activate the function group immediately.
Steps to create @unction modu"e&'
Business re"uirement&' develop a function module which displays customer details.
.o to SE/G.
.ive the name as 5%%%%%%.
Clic7 on create
.ive function groupB descriptionB clic7 on save
Provide the importing parameters as shown
8mO7unnr type 7na>'7unnr.
Provide the e%porting parameters as shown.
E%O7na> type 7na>.
Provide the e%ception as shown.
NoO7unnr type noO7unnr.
8nvalidO7unnr type invalidO7unnr.
#rite the below source code.
8f imO7unnr is initial.
3aise noO7unnr.
Else.
Select single H form 7na> into e7O7na>
#ehere 7unnr M imO7unnr.
8f sy'subrc M ?.
3aise invalidO7unnr.
Endif.
Endif.
SaveB activate and test it.
;sin3 @unction modu"e in pro3ram&'
Cata& waO7na> type 7na>.
Parameters& pO7unnr type 7na>'7unnr.
Call function (5%%%%)
E%porting
8mO7unnr M pO7unnr
8mporting
E%O7na> M waO7na>
ABAP Page 64
Abap Class Notes
E%ceptions
No'7unnr M >
8nvalid'7unnr M @
-thers M /.
8f sy'subrc M >.
!essage&)please enter customer no)B type (8).
Elseif sy'subrc M @.
!essage (please enter valied cust no)B type (8).
Elseif sy'subrc M /.
!essage (unprdictable error) type (8).
Endif.
#rite&* waO7na>'7unnrB waO7na>'name>.
Su#routines&'
Subroutines contains piece of ABAP code which one mainly used for readability and
reusability.
:hese one also used for local modulari5ation.
Synta%&' subroutines contains two steps.
>. Subroutine definition.
@. Subroutine implementation.
SntaC @or su#routine de@inition&'
Perform +subroutine, using +v>, +v@,
Changing +ch>, +ch@,
:bale +it>, +it@,.
SntaC @or su#routine imp"ementation&'
ABAP Page 65
Abap Class Notes
9orm +subroutine, using +v>, +v@,
Changing +ch>, +ch@,
:able +it>, +it@,.
UUU.
UUUU
UUUU.
Endform.
Tpes o@ su#routines&'
:here are two types of subroutines.
>. $ocal subroutine
@. .lobal subroutine
Loca" su#routine&' if subroutine definition and implementation i.eB perform and
formU..endform are available in same program then it is called as local sub routine.
1"o#a" su#routine&' if subroutine definition is available in one program and subroutine
implementation is available in another program then it is called as global subroutine or
e%ternal subroutines.
SntaC @or 3"o#a" su#routine&'
Perform +subroutine, program +program name,
using +v>, +v@,
Changing +ch>, +ch@,
:bale +it>, +it@,.
9orm +subroutine, using +v>, +v@,
Changing +ch>, +ch@,
:able +it>, +it@,.
ABAP Page 66
Abap Class Notes
UUU.
UUUU
UUUU.
Endform.
Parameters inter@ace or su#routines&'
;sin3&' 8mporting variables to sub routines one defined with using.
Chan3in3:' e%porting variables areB defined with changing.
Ta#"es&' internal tables for importing and e%porting one definition with tables.
Tpes o@ passin3 va"ues&'
:here are / types to send the values form subroutine definition to subroutine implementation.
>. Pass by value or call by value
@. Pass by reference
/. Pass by value and return.
Pass # re@erence&'
8n this typeB the actual and formal parameters will be referring to the same location.
8f any changes made to the formal parameters the actual parameters will also
effected.
ABAP Page 67
Abap Class Notes
Pass # va"ue&'
8n this type the actual and formal parameters will be referring to separate memory
locations.
8f any changes are made to the formal parameters it will not affect the actual
parameters.
Pass # va"ue and return&'
8n this type the actual and formal parameters will be referring to separate memory
locations.
8f any changes made to the formal parametersB the actual parameters will be changed
only when the last statement in the subroutine implementation or the entire subroutine
is e%ecuted.
ABAP Page 68
Abap Class Notes
ECamp"e on su#routine&'
Cata a type i.
A M >?.
#rite &* (before subroutine call (B A.
Perform passObyOref using A.
Perform passObyOvalue using A.
Perform passObyOvalueOreturn changing A.
#rite&* (after subroutine call)B A.
9orm passObyOref using fOa.
9Oa M fOa I >?.
Endform.
9orm passObyOref using value (fOa.
9Oa M fOa I >?.
Endform.
9orm passObyOvalueOreturn changing value (fOa.
9Oa M fOa I >?.
Endform.
ABAP Page 69
Abap Class Notes
Note&' creation for class and method are in the ooabap material.
%essa3es&'
All the messages are stored in a class called as message class.
SE>Q is the tcode for creating message class.
.enerally there will be a single message class for entire proJect.
%essa3e2id&'
8t is the 7eyword which is used to assign the message class to our report so thatB our
report can access all the messages in the message class.
Tpe o@ messa3es&'
:ype description
E error message
S success
# warning
8 information
A abort
Su#stutiona" parameters&'
(R) is the symbol use to substitute a variable or parameter in to the message.
#e can substitute a ma%imum of T substitution parameters.
Synta%&'
>. !essage +msg t%t, type +msg type,.
@. !essage +msg type, +msg no,
/. !essage +msg type, +msg no, with +su>,
+su@,
UUUU
Steps to create messa3e c"ass&'
.o to SEQ>.
.ive the name as 5%%%%.
Clic7 on create.
ABAP Page 70
Abap Class Notes
.ive description.
Clic7 on message tab.
Cefine the message as below.
!essage message short te%t.
? material does not e%it.
??> material number R does not e%it.
??@ R R R R
', clic7 on save.
;sin3 messa3e c"ass in report&'
3eport 5%%%%%% message'id 5%%%%%.
Cata waOmara type mara.
Parameters& pOmatnr type mara'matnr.
Select single H from mara
8nto waOmara
#here matnr M pOmatnr.
8f sy'subrc M ?.
#rite&* waOmara'matnr.
Eelse.
!essage (material does not e%it) type (E).
!essage 8???.
!essage 8??> with pOmatnr.
!essage 8??@ with (material) (does) (not) (e%it).
Endif.
Di@@erence #et5een inc"ude @unction modu"e and su#routine:2
8nclude function module subroutine
ABAP Page 71
Abap Class Notes
Can not be e%ecuted can be e%ecuted can not be e%ecuted
No parameter interface parameter interface parameter interface
No e%ception e%ception no e%ception
No 39C 39C no 39C.
ABAP Page 72