Anda di halaman 1dari 62

ABAP BASICS

SAP ABAP/4 Contents


SAP OVERVIEW & ARCHITECTURE
What is SAP?
Client/Server Architecture
R/3 Architecture
- Presentation Server
- Application Server
- Database Server
SAP R/3 Logon & Logging of
What is transaction coe & using transaction coe?
!etting help in the R3 s"ste#
Wor$ing %ith R/3 user sessions
What is A&AP & Wh" is A&AP?
ABAP/4 DEVELOPMENT WORKBENCH
'ools o( abap/) %or$bench
Control structures
String operations
*ser ialog+ selection screen
ABAP/4 DICTIONARY
'ables in abap/) ictionar"
Creation o( tables
Creation o( o#ains & ata ele#ent
Structures an vie%s
Search helps
Loc$ ob,ects
Logical atabase
DATA TYPES & DATA OBJECTS
Data t"pes
Data ob,ects
-ins o( ata ob,ects
WRITE STATEMENT
About %rite state#ent
.or#atting output
.or#atting options (or all ata t"pes
.or#atting options (or all nu#eric /els
MODULARIATION TECHNI!UES
Page 1 of 62
ABAP BASICS
Subroutines
.unction #oules
0nclues an #acros
REPORTS
Classical reports
o 1vents in Classical Reports
0nteractive reports
o 1vents in 0nteractive Reports
o 2enu Painter
AL3
o List Displa"
o !ri Displa"
TRANSACTION PRO"RAMMIN"
About transaction
Screen painter
2oule pool progra##ing
1vents in 2oule pool progra##ing
Creation o( co#ple4 transaction
.iel chec$s
D"na#icall" calling the screens
Sub screens
'able controls
DATA TRANS#ER
.ile 5anling
o .lat /le hanling
o Se6uential /le hanling
Recoring #etho
&DC
o Call transaction
o Session #etho
LS2W

SAP SCRIPTS
About sap scripts
La"out set
o Designing La"outs
o &arcoe printing
o Stanar te4t creation
o *sing Stanar te4t
Page 2 of 62
ABAP BASICS
Printing a co#pan" logo
o *ploaing logo7s to SAP 8'0..&&2P9
Control co##ans
Writing Driver progra#s
*sing SAP Stanar .or#s
:utput control
o :utput control creation
o :utput control use in stanar SAP transactions
Cop" stanar (or#s
SMART#ORMS
About S#art (or#s
Diference bet%een SAP Scripts & S#art (or#s
Designing the la"out set
Writing A&AP coe in s#art (or#s
*sing (or#s in SAP stanar applications
RUNTIME ANALYSIS AND S!L TRACE
Per(or#ance testing o( progra#
14tene s"nta4 chec$ 8SL0;9
A&AP tips & tic$s
CROSS APPLICATIONS
Distribute process
R.C
o Create R.C Destination
o 'est the connection
o Create R.C (unction #oules
o *se R.C (unction #oules
0Doc7s
o What is 0Doc?
o What is Seg#ent?
o 0Doc creation
o Seg#ent creation
o 0Doc Structure
o What is 0Doc t"pe?
o What is #essage t"pe?
o What is #essage control?
o What is partner (unction?
o .unction #oules in 0Doc7s
*ser-e4its
o Create enhance#ents
o Create pro,ects
Page 3 of 62
ABAP BASICS
o Writing coe in user-e4its
AL1
o Create o( Logical S"ste#s
o Create o( R.C Destination
o Create Port
o Create Partner Pro/le
o Distribute the s"ste#s
o Distribute 0Doc
o Distribute the ata
1D0
o Create Port
o Create Partner Pro/le
o Distribute the s"ste#s
o Distribute 0Doc
o Distribute the ata
&AP0
o &AP0 14plorer
o Diferent .unction #oules in it
Page 4 of 62
ABAP BASICS
TABLE OF CONTENTS
SOME FACTS ABOUT SAP 4
WORKING WITH R/3 SYSTEMF 6
SAP R/3 logon Scrn 6
Logg!ng O" #
U$!ng Tr%n$%c&!on Co' #
G&&!ng (l) !n &( R/3 $*$&+ ,-
Wor.!ng /!&( R/3 0$r $$$!on$ ,,
R/3 ARCHITECTURE ,,
Cl!n& / Sr1r %rc(!&c&0r ,2
T(r &!r %rc(!&c&0r o3 R/3 ,3
ABAP/4 4E5ELOPMENT WORKBENCH ,4
4ATA 4ICTIONARY ,6
A6o0& 4%&% 4!c&!on%r* ,6
A'1%n&%g$ ,6
T%6l$ !n ABAP/4 '!c&!on%r* ,7
Cr%&!on o3 &%6l 2-
Cr%&!ng 4o+%!n 2-
Cr%&!ng 4%&% El+n& 2-
GENERAL INTRO4UCTION TO ABAP/4 22
C(%r%c&r!$&!c$ o3 &( ABAP/4 )rogr%++!ng l%ng0%g$ 23
REPORTS 24
4IALOG PROGRAMS 28
4ATA TYPES AN4 4ATA OB9ECTS 26
Page 5 of 62
ABAP BASICS
4%&% T*)$ 26
4%&% O6:c&$ 2;
K!n'$ o3 4%&% O6:c&$ 2;
P%r%+&r$ 27
WRITE STATEMENT 3-
For+%&&!ng o0&)0& 3,
For+%&&!ng o)&!on$ 3or %ll '%&% &*)$ 32
For+%&&!ng o)&!on$ 3or n0+r!c <l'$ 32
BRANCHES 34
Br%nc(!ng /!&( IF $&%&+n& 34
Br%nc(!ng /!&( CASE $&%&+n& 38
LOOPING 36
Loo)!ng /!&( 4O $&%&+n& 36
Loo)!ng /!&( WHILE S&%&+n& 36
TRANSLATE co++%n' 37
In$r& $&%&+n& 48
U)'%& $&%&+n& 48
4l& $&%&+n& 46
Page 6 of 62
ABAP BASICS
So+ F%c&$ %6o0& SAP
After the Internet, SAP R/3 is one of the hottest topics in the computer industry and the
company that dee!oped it" It is targeted to most industries, manufacturing, retai!, oi!
# gas, pharmaceutica!, $an%ing, insurance, te!ecommunication, &ransport, chemica!
and so on" A!! ma'or hard(are )endors (ere fu!!y engaged to partner (ith SAP* A&#&,
+,--, .ompa/, I+0, Sun hae supported and certi1ed R/3 p!atform"
SAP has !ist of ma'or consu!tants a!! oer the (or!d !i%e Anderson .onsu!ting, Price
2aterhouse 3 .ooper # -y$rand, 4rnst # 5oung, 6P07 and many more"
&he company $ehind R/3 is SAP A7, founded $y four former I+0 emp!oyees in 1892"
&he company:s head/uarters are in 2a!!dorf, a sma!! 7erman to(n" &he company
name, SAP stands for S5S&40S, APP-I.A&I;<S and PR;=,.&S in data processing"
In 1882 R/3 (as introduced and in 1885 SAP A7 (as ran%ed 1fth among independent
soft(are endors" ;ne of the reasons for SAP:s success is that since it is a standard
pac%age, it can $e con1gured in mu!tip!e areas and adapted to speci1c need of a
company" &oday, more than 21,6>> customers in oer 12> countries run more than
68,9>> insta!!ations of SAP? soft(are" 2ith su$sidiaries in more than 5> countries, the
company is !isted on seera! e@changes, inc!uding the Aran%furt stoc% e@change and
<5S4 under the sym$o! BSAPC"
SAP has t(o main products in the $usiness soft(are mar%et, 0ainframe system R/2 and
.!ientDserer R/3" +oth are targeted to $usiness app!ication so!utions" Eere R indicates
R4A- &I04"
R/2 is SAP A7 mainframe soft(are that runs on I+0, Siemens and other compati$!e
e/uipment" &his type of so!ution cannot $e open, $ut (ith A-4 techno!ogy, R/2 can $e
!in%ed (ith R/3 system and share data" &his system is main!y targeted at enterprises
(ith dataDintensie and centra!iFed industries"
R/3 is the product that has rea!!y p!aced SAP A7 as the !eader in the country" &his
comp!e@ .!ient/serer system is core of our course" &he g!o$a! acceptance of R/3 is not
on!y $ecause it caters a!! comp!e@ needs of $usiness $ut a!so this internationa!
acceptance is $ecause of R/3:s internationa! app!ica$i!ity" Aor SAP this does not mean
haing soft(are aai!a$!e in diGerent !anguages, $ut a!so coering currency, ta@es,
-ega! practice concerning ER, Import/e@port regu!ations" SAP a!so a!ues its
customers and it is sho(n $y the comprehensie set of /ua!ity serices put $y SAP to
he!p customers during the process of imp!ementing and supporting the R/3 systems"
&hese serices inc!ude product informationH training, insta!!ation and upgrade serice
!i%e*
Page 9 of 62
ABAP BASICS
OSS= ;n!ine Serice System is one of the primary sources of serice and support
proided $y SAP" 2ith ;SS, customers can search the SAP information data$ase and
1nd so!utions for errors and pro$!ems (ith R/3 systems" 5ou can a!so su$mit your
pro$!ems to SAP"
Con$0l&!ng Sr1!c= (ith remote consu!ting serice customer receies immediate and
updated technica! support and ans(ers to their /uestions"
M%!n&n%nc $r1!c= &his is the $asic and most common type of support for
customers in technica! support and ans(ers to their /uestions"
In3or+%&!on Sr1!c= &hese are the arious information sources for receiing detai!ed
information a$out the R/3 system, mar%eting $rochures, system documentation,
training information and many more things"
Pr1n&!1 $r1!c$= &he primary one is the 4ar!y 2atch Serice, (hich ensures
successfu! and eGicient insta!!ation of the R/3 system in a!! phases" &his serice ma%es
regu!ar/performance chec%s and ana!yFes the system to identify potentia! pro$!ems,
he!p system managers and SAP administrators to tune the system" Soon after the 4ar!y
2atch session, SAP sends the customer a report (ith the resu!t of the ana!ysis and
recommendations for aoiding potentia! pro$!ems such as data$ase $ecoming fu!!"
So oera!! SAP R/3 is an open c!ient/serer soft(are system, designed to manage
$usiness information needs of an entire enterprise" &he (ho!e dataIo( of SAP R/3
(or%s in an integrated (ay, (hich means the data needs to $e entered 'ust once and the
system automatica!!y updates other !ogica!!y re!ated data"
Page J of 62
ABAP BASICS
WORKING WITH R/3 $*$&+
&he SAP R/3 presentation interface $ehaes ery simi!ar!y to any other typica! (indo(
app!ication and is a!so %no(n as SAP7,I" &he 1rst screen that you come across in R/3
system is SAP !ogon screen"
SAP R/3 logon Scrn
&his is the 1rst screen that appears (hen you use SAP !ogon uti!ity" It has four 1e!ds*
the c!ient, the user, the pass(ord and the !anguage"

Cl!n&= Eere you enter the c!ient num$er" &he c!ient is group of users (ho has simi!ar
rights" It can $e group of users in a $usiness entity or a (ho!e $usiness entity or a
(ho!e company"
U$r= &he name of the SAP user identi1cation" ,sers of the SAP system are c!ientD
speci1c, (hich means that user $e!onging to one c!ient is a!id to on!y the particu!ar
c!ient"
P%$$/or'= It is the pass(ord that has $een assigned $y the system administrator"
L%ng0%g= SAP R/3 system supports mu!tinationa! !anguage on the same system at
the same time, (hich is ery usefu! for mu!tinationa! companies (ith diGerent
$ranches in seera! countries and possi$!y using diGerent !anguages"
Page 8 of 62
ABAP BASICS
After entering a!! the 1e!ds press 4<&4R %ey and system (i!! ta%e you to 0AI< 04<,
screen"
,ser might get diGerent screens (hen he !ogs on, depending upon defau!t settings of
the user master record i"e", if user is =4)4-;P4R then the screen (hich he often (or%s
on is editor screen and he can go direct!y to this screen, if system administrator sets
this screen for the user"
Main features of any R/3 window are as follows:
R/3 standard (indo( e!ements $ehae e@act!y the same, as any other standard
(indo( app!ication (ou!d, !i%e minimiFing a screen, setting the actie (indo( etc"
Arom &;P to +;&&;0, R/3 (indo( can contain typica! e!ements such as chec%
$o@es, push $uttons, input 1e!ds and fo!!o(ing e!ements*
Mn0 6%r is the 1rst e!ement of the eery R/3 (indo(" It contains the menu item
corresponding to the particu!ar R/3 app!ication" &he t(o menu options S5S&40 and
E4-P are a!(ays present in eery R/3 (indo(" S5S&40 menu option contains a!!
uti!ities and functions, and is aai!a$!e to user at a!! the times" &he E4-P menu
contains a!! the aai!a$!e options for the diGerent types and methods of o$taining
on!ine he!p in the system"
S&%n'%r' &ool 6%r" &he second R/3 (indo( e!ement !$ )r$n& !n 1r* R/3
/!n'o/" It is nothing $ut a co!!ection of icons, (hich perform common functions
!i%e saing the o$'ect, e@it etc" &he arious icons on std" &oo! $ar are as fo!!o(s
Kfrom !eft to rightL*
En&r Co++%n' F!l' S%1 B%c.
E>!& C%ncl Pr!n& F!n'
F!n' N>& F!r$& P%g Pr1!o0$ P%g N>& P%g
L%$& P%g Hl)
A!! icons in R/3 (indo( app!ication support A;.,S property" It means, if you p!ace
cursor oer an icon, the system (i!! sho( the function of the icon"
A))l!c%&!on &ool 6%r= &he ne@t part of the screen contains icons most common!y
used in that particu!ar tas% or transaction"
S&%&0$ 6%r is the $ottom !ine of the screen and usua!!y sho(s errors or information
messages to the user" It a!so inc!udes other information such as system id, session
num$er, c!ient, serer name and the response time"
In 6&/n %))l!c%&!on &ool 6%r %n' $&%&0$ 6%r *o0 (%1 /or.!ng %r%? /(!c( !$
diGerent for diGerent screens"
Page 1> of 62
ABAP BASICS
Logg!ng O"
,ser can !og oG the R/3 system from any screen" &here are three (ays of !ogging oG the R/3
system, (hich are as fo!!o(s*
Arom the 0enu $ar choose S5S&40 -;7 ;AA" In this case, you get the !og oG
dia!og $o@, (hich informs the user that any data not saed (i!! $e !ost if continuing
(ith the !og oG procedure"
,se/<4M transaction code in the command 1e!d" &his is dangerous, since it does not
as% if you (ant to sae the data"
.!ic%ing on the 4MI& $utton on the R/3 initia! screen"
U$!ng Tr%n$%c&!on Co'
&he R/3 system proides an a!ternatie and eGicient (ay of se!ecting menu options for
moing around the tas%s and functions of the SAP system $y using transaction code
direct!y in the command 1e!d"
2hen moing (ith transaction, you can go to any part of the system $y mere!y typing a
transaction code in the command 1e!d, proided you hae authoriFation for that" &hat
transaction code is the fourDcharacter code associated (ith any tas%" +y typing the
transaction code and pressing 4<&4R %ey, the system ta%es you direct!y to the initia!
screen for transaction" 2heneer any transaction code is entered in the command 1e!d,
it gets stored in the $uGer memory" If you c!ic% on drop do(n arro(, system disp!ays
!ist of transaction code a!ready entered and you can se!ect from this !ist or enter ne(
one" &here are a!most t(e!e thousand and ninety four transactions in SAP" Aor eery
tas%, transaction code is associated and it can $e found $y
SYSTEM STATUS
Status (indo( is popped up (hich contains the transaction code in the trans 1e!d"
&hrough 4YNAMIC MENU@ It gies the !ist of tas%s" If you c!ic% on the top !ine of
the app!ication areas and pressing the search and search ne@t $utton (i!! gie you
the transaction code" /N /!ll &%. *o0 &o !n!&!%l $crn o3 R/3
Page 11 of 62
ABAP BASICS
Important transaction codes, (hich you (i!! $e using often, are*
E'!&or$
S439 Aunction +ui!der
S43J A+AP/4 4ditor
S441 0enu Painter
S451 Screen Painter
S491 Aorm Painter
4!c&!on%r*
S411 Initia! A+AP/4 dictionary maintain screen"
Bro/$r$
S4J> ;$'ect $ro(ser"
S416 =ata $ro(ser"
T$&!ng Tool$
S43> Runtime Ana!ysis
S&>5 SN- &race
Page 12 of 62
ABAP BASICS
G&&!ng (l) !n &( R/3 $*$&+
R/3 inc!udes many possi$i!ities to get on!ine he!p for a!most eery e!ement of the
system, users can get he!p for entire app!ication, for speci1c function, for de1nitions of
arious terms used in SAP, i"e", 7!ossary, messages, screens, 1e!ds etc"
5ou o$tain E4-P $y using any of the fo!!o(ing options*
Hl) 30nc&!on from the R/3 (indo(, (hich is compu!sory menu item of eery R/3
(indo("
A Icon of standard too! $ar"
F, 30nc&!on .*@
&he SAP system proides he!p on most 1e!ds that appear on the R/3 system" &o get he!p
on particu!ar 1e!d, position the cursor oer it and press he!p $utton or A1 function %ey"
Another (ay in (hich R/3 system proides he!p is (hen system disp!ays error messages
in the status $ar" =ou$!e c!ic%ing on the status $ar sho(s additiona! information a$out
the message"
Page 13 of 62
ABAP BASICS
Wor.!ng /!&( R/3 0$r $$$!on$
A ery important feature proided $y SAP" In R/3 system you can (or% (ith more than
one tas% at any gien point of time, $y means of opening sessions" 5ou can ca!! sessions
as independent R/3 (indo( (here you can perform other tas%s"
+y defau!t, a user can open NINE sessions simu!taneous!y and can (or% or moe
around (ith a!! sessions at the same time" Sessions can $e c!osed at any time, (ithout
haing to !og oG the system"
,ser can create ne( sessions from any(here as .R4A&4 S4SSI;< comes under
S5S&40 menu (hich is aai!a$!e in eery R/3 (indo("
SYSTEM CREATE SESSION ;r /O !n co++%n' <l'
&his (i!! open a ne( session or (indo( and (i!! p!ace it in front of a!! other (indo(s"
&o moe among sessions
Oust mouse c!ic% on any part of the R/3 (indo( to ma%e that session actie"
.om$ination of A-& P &A+ %ey"
R/3 Arc(!&c&0r
&he oera!! R/3 system inc!udes the fo!!o(ing components*
&he UPPER !ayer, the functiona! !ayer contains the diGerent $usiness app!ication" &he
integration of a!! app!ication depends upon $asis system" App!ications are dee!oped in
A+AP/4 -ang" KAdanced +usiness App!ication 3 the 4
th
generation !anguageL
&he R/3 $asis soft(are is the set of programs and too!s, (hich interfaces (ith the
operating, system, the under!ying data$ase, protoco!s and the presentation interface"
Page 14 of 62
;perating
System
=ata +ase <et(or%
+asis System
;r
0idd!e -ayer
+usiness
App!ications
ABAP BASICS
&his !ayer ena$!es a!! the app!ication to (or% e@act!y the same (ay no matter (hat
operating system or data$ase, the system is insta!!ed on" It is an independent !ayer and
ensures the integration of a!! modu!es" +esides a!! these speci1c 'o$s, +ASIS system
a!so contains fo!!o(ing components and thus proides more additiona! features"
A+AP/4 dee!opment (or%$ench, (hich in turn inc!udes many features !i%e
repository, data dictionary, (or%$ench organiFer, (hich (i!! $e discussed in !ater
part of the topics"
A+AP/4 !anguage, system administratie too!s, a!! these components are used to
contro!, tune the R/3 system"
Spoo! system manages the formatting of data for printing and passing it to the host
spoo! system"
0ai! system you can send and receie mai! from the outside (or!d KInternetL"
.ommunication interface to e@terna! system from R/3 system* 0anages
communication at the ;S !ee! K&.P/IPL, at the data$ase !ee! # $et(een
app!ications too" KRA., 4=I, and A-4L
=ata$ase interface 3 &his component supports diGerent Re!ationa! data$ases from
diGerent endors" &he main tas% of data$ase interface is to conert the SN- re/uest
from the SAP dee!opment enironment to the data$ase:s o(n SN- enironment"
+ac%ground processing (ith this faci!ity you can su$mit your program for
$ac%ground e@ecution"
+ASIS system contains the !ayered components that faci!itate the dee!opment of
c!ient/serer architecture"
Cl!n& / Sr1r %rc(!&c&0r
.!ient/Serer architecture is main!y a soft(are concept that inc!udes a set of serice
proiders and serice re/uesters" &he set of computers acts as serice proiders and is
ca!!ed as serer" &he sets of soft(are component, (hich act as serice re/uester, are
ca!!ed as c!ient"
In the c!ient/serer architecture, the data$ase acts !i%e a !i$rary c!er% retrieing $oo%s
from the she!f" &he user programs hae to re/uest data$ase for the data instead of
searching for the data themse!es" &his (ay there is no ris% of the users putting the
data out of order" If the desired data is in use, the data$ase ma%es the user (ait unti! it
is free"
&he ma'or adantage of the c!ient/serer architecture is that the serer is aai!a$!e for a
num$er of c!ients and there is distri$ution of (or% $et(een the c!ients and the serer"
&he user directs the re/uest to the c!ientH the c!ient in turn understands the user:s
re/uest and redirects the re/uest to the serer" &he serer retriees the data, gies it
to c!ient"
Page 15 of 62
ABAP BASICS
5ou can hae c!ient and serer on the same machine or on diGerent machines" 4ach
c!ient has a corresponding process inside the serer"
;ne of the most used c!ient/serer con1gurations (ith the R/3 system is the 3 tiered
architecture, (hich separates a system:s computer into 3 functiona! groups*
T(r &!r %rc(!&c&0r o3 R/3
=ata$ase Serer
App!ication Serer
Presentation Serer
K,n!i%e norma! .!ient/serer architecture (here you hae on!y t(o !ayers i"e", c!ient and
serer"L
.ommunication among the 3 tiers is accomp!ished $y standard protoco! serices !i%e
&.P/IP or .PI. K.ommon Programming Interface .ommunicationL"
In a$oe case data$ase serer stores the data centra!!y" +asica!!y contains data$ase
engine and associated processes" &he data$ase !ayers contain the data$ase system
used $y a!! serers"
App!ication serer contains soft(are components to run the program" It contains a SAP
%erne!, (hich can run A+AP/4 program"
&he presentation serer is your c!ient through (hich you send your re/uest to
app!ication serer" It is a!so ca!!ed as SAP graphica! user interfaces %no(n as SAP7,I
and is aai!a$!e in (indo(s 3"1, 2indo(s <&, 2indo(s 85, and 0acintosh" &hey a!!
!oo% simi!ar (hateer under!ying system they are running on"
Page 16 of 62
Database
Server
Application
Server
Application
Server
Application
Server
Presentation
Server
Presentation
Server
Presentation
Server
Presentation
Server
Presentation
Server
Presentation
Server
ABAP BASICS
&he SAP7,I inc!udes a!! graphica! capa$i!ities of (indo( interface (ith menu $ars, too!
$ars, focus property, and the entire mouse c!ic%ing operations"
&he R/3 system is open system in the sense that it can run on any operating system or
any data$ase and any communication techno!ogy" It means that*
R/3 system can run on any operating system p!atform such as ,<IM, <&, 85, AS/4>>"
It supports arious R=+0S such as SN- serer, ;rac!e, Informi@, =+2"
Standard 7,Is supported $y R/3 are 2indo(s 85, <&, 2indo(s 3"1, and 0acintosh"
SAP can use standard communication protoco!s &.P/IP, .PI., ;SA/=.4/=04 for
net(or%"
ABAP/4 41lo)+n& Wor.6nc(
&he dee!opment enironment of SAP R/3 system is fu!!y integrated set of arious
dee!opment too!s, data dictionary, and programming !anguage" Au!! integration of a!!
components means that changes in any part hae a direct and immediate eGect on a!!
app!ication using those components"
&he screen of A+AP/4 dee!opment (or%$ench !oo%s !i%e
Tool$ o3 ABAP/4 /or.6nc(
Page 19 of 62
ABAP BASICS
For )rogr%++!ng=
A+AP/4 dictionary =e1ning, maintaining and storing the data dictionary of the SAP
R/3 system stores a!! the dictionary o$'ects inc!uding ta$!es re!ationship and Ee!p
information" &ransaction code for this is S411"
A+AP/4 editor .reating and maintaining the A+AP/4 program, editing function
modu!es, !ogica! data$ase, and screens" &ransaction code is S43J"
Aunction !i$rary =e1ning and maintaining the A+AP/4 function modu!es"
&ransaction code is S439"
Screen painter =esigning and maintaining the screens in transaction" &ransaction
.ode is S451"
0enu painter =esigning and maintaining the means for graphica! user interface"
&ransaction code S441"
For N%1!g%&!ng=
;$'ect $ro(ser 0anaging and organiFing the dee!opment o$'ect in a hierarchica!
form" &ransaction code is S4J>"
A+AP/4 repository information <aigating and searching for the dictionary ;$'ects,
dee!opment o$'ects and re!ationship o$'ects" &ransaction code S4J4"
=ata $ro(ser <aigating in the data ta$!es of the data$ase" &ransaction code is S4
16"
For 460gg!ng=
S;- trace trac%ing the data$ase ca!!s from the system transaction and programs"
&ransaction code is S&>5"
=e$ugger Stopping the program and ana!yFing the resu!ts of the e@ecution of eery
program statement"
Runtime Ana!ysis Ana!yFing the performance the system ca!!s &ransaction code is
S43>
For Org%n!B!ng=
2or%$ench organiFer contro!!ing and %eeping trac% of dee!opment (or% and team
re!ated dee!opment pro'ects and managing ersions of dee!opment o$'ects"
&ransaction code is S4>8"
&ransport system performing and managing the transport of dee!opment o$'ect
across diGerent system" &ransaction code is S4>1
Page 1J of 62
ABAP BASICS
4%&% 4!c&!on%r*
&he A+AP/4dictionary is centra! (or%$ench repository uti!ity proiding the data
de1nition and the information re!ationship that are !ater used in a!! the $usiness
app!ication (ithin R/3
&he A+AP/4 dictionary can $e seen as a !ogica! representation or a superior !ayer oer
the physica! under!ying data$ase" &his data$ase must support the re!ationa! data mode!"
&his mode! is strict!y fo!!o(ed $y data dictionary"
A6o0& 4%&% 4!c&!on%r*
A =ata dictionary in computing terms is the $o0rc o3 !n3or+%&!on !n /(!c( $*$&+
'%&% !$ '<n'" &he data dictionary is the cn&r%l!B' %n' $&r0c&0r' $o0rc o3
!n3or+%&!on 3or 60$!n$$ %))l!c%&!on$@ 5ou can say that it is core of a (e!!D
structured dee!opment enironment"
&he e!ements that ma%e up a dictionary are %no(n as metadata" M&%'%&% !$ &( &r+
3or &( '%&% /(o$ 30nc&!on !$ &o '$cr!6 o&(r '%&%@ =ata in dictionary is not the
actua! data !i%e emp" name or emp" address $ut rather a type of data (hose function is
to de1ne the properties of the data such as type, !ength, and re!ationship"
A'1%n&%g$
Adantage of using data dictionary is aoiding inconsistencies (hen de1ning data type
that (i!! !ater $e used in diGerent app!ications" &his aoids redundancies"
2hen a type is de1ned in the dictionary, it is aai!a$!e to any program in the
app!ication" A change in the de1nition of a type of data in the dictionary automatica!!y
aGects any other data or program, (hich has this data"
Again, data dictionary is a fast and eGicient (ay to ans(er /uestions such as (hich
entries e@ist in a ta$!e of the data$ase, (hat the structure of ta$!e is"
Page 18 of 62
ABAP BASICS
Ac&!1%&!on o3 '!c&!on%r* o6:c&$
Aor a dictionary o$'ect to $e eGectie at runtime, that is, for a dictionary o$'ect to $e
aai!a$!e for use (ithin a program, transaction, and so on, it must $e in actie status"
Aor o$'ects to $ecome actie, R/3 inc!udes the A.&I)A&I;< function"
2hen a ta$!e or aggregated o$'ect is actiated, it is p!aced at the disposa! of the system
as a runtime o$'ect in a (ay that ma%es it aai!a$!e /uic%!y for the app!ication program
to access re!eant information of ne( actiated o$'ects"
2hen a dictionary o$'ect is modi1ed, that means that the o$'ect preious!y e@isted and
actiated" 5ou need to reactiate the o$'ect after modi1cation"
2hen mass actiation is performed massie!y, it might ta%e a /uite a !ong time" &hen it
shou!d $e in the $ac%ground system" &his type of actiation is %no(n as $ac%ground
actiation"
&he A+AP/4 =ata dictionary is the centra! component of A+AP/4 repository" A =ata
dictionary is centra!iFed and structured source of information for $usiness app!ication"
&he A+AP/4 dictionary is the core of the R/3 dee!opment system" It is the source of
eery de1nition, (ithin R/3, from the ery $asic domain to the company data mode!" It
is tota!!y integrated (ith other too!s of the dee!opment enironment !i%e screen
painter, menu painter, and editor"
Some of the main aai!a$!e functions in the A+AP/4 dictionary are as fo!!o(s*
Add, de!ete, modify, and manage the de1nition of the dictionary data"
Presere the data integrity"
+e the centra! source of information e"g" from the dictionary you get the information
a$out the de1ned re!ationship $et(een t(o ta$!es or een the directory te!!s
(hether ta$!e is actie or empty"
It a!so permits documentation of system data"
In the R/3 system instead of (or%ing (ith origina! o$'ects, you (or% (ith interna!
representation of o$'ects" 2ith this type of operation the system performance is
enhanced and has the adantage that the dee!opment too!s, screen interpreters a!(ays
access current data"
2hen any of the data dictionary o$'ects are used in other parts of the dee!opment
(or%$ench for e@amp!e, in program, programmer on!y has to enter a ta$!e name or 1e!d
name" &he system automatica!!y %no(s a!! the properties and information of the 1e!d"
Page 2> of 62
ABAP BASICS
&o ca!! A+AP/4 dictionary, from the main menu, Tool$ ABAP/4 /or.6nc( '%&%
'!c&!on%r* or n&r &r%n$%c&!on SE,,@
4%&% '!c&!on%r* o6:c&$=
T%6l= is a 2= data matri@ containing ro(s and co!umns" Ro(s contain data (hi!e
co!umn indicates 1e!ds" &a$!e can contain > or mu!tip!e ro(s"
S&r0c&0r* is a s%e!eta! ie( of a ta$!e" It contains the de1nition of co!umns and
don:t hae any contents" Structure is genera!!y a temp!ate $ased on (hich a ta$!e is
created" &he $asic diGerence $et(een structure and ta$!e is that the structure does
not e@ist at the under!ying data$ase system !ee!" Structure e@ists as de1nition in
the dictionary"
5!/$= A ie( is an imaginary ta$!e" It contains data, (hich is rea!!y stored in other
ta$!es" &he contents for the ie( are dynamica!!y generated (hen ca!!ed from
program"
Page 21 of 62
ABAP BASICS
4%&% l+n&= is de1nition of the properties and type for a ta$!e 1e!d" It is an
intermediate o$'ect $et(een the o$'ect type domain and the ta$!e 1e!d" A 1e!d in
R/3 system is a!(ays associated (ith a data e!ement, (hich at the same time is
re!ated to domain"
4o+%!n= is forma! de1nition of the data type from a technica! point of ie(" It sets
the attri$utes such as data type, !ength, possi$!e a!ue range and so on"
Loc. o6:c&$= &hese types of o$'ects are used for !oc%ing the access to data$ase
records in ta$!e" &his mechanism is used to enforce data integrity that is t(o users
cannot update the same data at the same time" 2ith !oc% o$'ects you can !oc% ta$!eD
1e!d or (ho!e ta$!e"
S%rc( Hl) O6:c&$= , (hich gies !ist of possi$!e a!ues for either primary %eys or
nonDprimary %eys"
T%6l$ !n ABAP/4 '!c&!on%r*
&a$!es are the $asic o$'ects in R/3 app!ication" &here are a!most J>>> ta$!es in R/3
system" Ao!!o(ing types of ta$!es are aai!a$!e
&ransparent ta$!es
Poo! ta$!es
.!uster ta$!es
Arom user point of ie(, a!! ta$!es are used to store data (hateer $e the type of ta$!e"
&here is no diGerence in the $ehaior or operation of these ta$!es" A!! of them can $e
managed $y using standard ;P4< SN-" Eo(eer from an administrator point of ie(
transparent ta$!e do e@ists (ith the same structure $oth in the dictionary as (e!! as in
the data$ase, e@act!y (ith the same data and 1e!ds" 2hi!e other t(o are not
transparent in the sense that they are not managea$!e direct!y using data$ase system
too!s" 5ou can access these ta$!es in R/3 enironment from the A+AP/4 dictionary" 5ou
cannot use natie SN- on these ta$!es" Poo! or c!uster ta$!es are !ogica! ta$!es, (hich
are arranged as records of transparent ta$!e"
A ta$!e is made up of ro(s and co!umns" 2hen the ta$!e is created, its co!umns are
namedH data type is supp!ied for each co!umn" &here can $e on!y one data a!ue in each
co!umn of each ro( in a ta$!e" Record or as it is ca!!ed in diGerent R=+0S is nothing
$ut group of 1e!ds" 2hi!e a co!umn is a 1e!d of a ta$!e, a ta$!e is an inde@ed 1!e" &he
main inde@ is ca!!ed as primary %ey, (hich can $e a sing!e 1e!d or com$ination of %eys
or 1e!ds" A primary %ey can $e de1ned as a 1e!d, (hich inde1nites a sing!e uni/ue
record of the ta$!e" A ta$!e cannot hae record (ith dup!icate primary %ey"
Page 22 of 62
ABAP BASICS
In any R=+0S, ta$!es are re!ated to each other" +ut to re!ate ta$!e to each other it is
necessary that one of the ta$!es contain some information of other ta$!e" 0ost!y ta$!es
are re!ated to each other through primary %eys" &he primary %ey of one ta$!e, if it
e@ists in other ta$!e then it is ca!!ed foreign %ey" &his type of data$ase management
system means that there is some redundancy of data" +ut using norma!iFation
procedures aai!a$!e can minimiFe it" ;ne of the most important functions of foreign
%ey is to ensure data integrity" Aor e@amp!e say you hae 40P ta$!e, (hich has 1e!ds*
emp" no", emp"name, dept"code, sa!ary and you hae =4P& ta$!es, (hich has dept"code
and dept"desc" &hen in =4P& ta$!e dept"code is primary %ey (hi!e dept"code in 40P
ta$!e is foreign %ey" If you enter dept"code for particu!ar emp!oyee in 40P ta$!e the
dept"code shou!d e@ist in =4P& ta$!e" System (i!! chec% the a!ue for dept"code in
=4P& ta$!e, and if does not e@ist then (i!! Iash error" In this case =4P& is ca!!ed chec%
ta$!e (hi!e 40P is foreign %ey ta$!e"
Cr%&!on o3 &%6l
Steps to create a ta$!e
.reate domain
.reate data e!ement
.reate actua! ta$!e
Cr%&!ng 4o+%!n
=omain as a!ready e@p!ained de1nes the technica! properties of a 1e!d such as type and
a!ue range" A domain can $e created from initia! screen of data dictionary $y c!ic%ing
on create and c!ic%ing domain Radio$utton" Parameters to $e passed are*
=ata type* 2here you need to enter the data type aai!a$!e in SAP"
Aie!d !ength* Aie!d !ength is the num$er of a!id position"
)a!ue ta$!e* <ame of a ta$!e to $e entered" &he 1e!ds referring to this domain may on!y
assume a!ues contained in the a!ue ta$!e"
;nce the domain is created, sae and actiate it, so that it can $e used for further
o$'ects K$asic ru!e of dictionaryL"
Cr%&!ng 4%&% El+n&
&he second step of ta$!e creation is to create data e!ement" It assigns a certain
meaning to the ta$!e 1e!d, (hich are de1ned using that data e!ement" A =ata e!ement
Page 23 of 62
ABAP BASICS
a!(ays needs to $e de1ned oer a domain and 1e!d is a!(ays de1ned oer a data
e!ement" &his a!!o(s a!! 1e!ds (ith same technica! properties to use the same data
e!ement"
Parameters to $e passed (hen creating a data e!ement*
Short te@t* 0andatory 1e!d"
=omain* A mandatory 1e!d" If the domain does not e@ist, SAP can ta%e you direct!y
to domain de1nition screen"
&e@t e!ement* 5ou can enter description is short or !ong te@t for the 1e!d" &his te@t
is used (hen
entering data for these 1e!ds"
Sae and actiate"
Cr%&!on o3 %c&0%l &%6l
Parameters to $e passed for creation of ta$!e*
Short description* 0andatory 1e!d"
=e!iery c!ass* As per ,ser Re/uirement
&a$!e 1e!ds* Specify (hether primary %ey" In this case it is mandatory to
enter data e!ement"
=ata c!ass* 4sta$!ishes the physica! area of the data$ase"
SiFe category* A!!o(s you to specify estimated space re/uirement for the ta$!e"
Aurther do(n under $uGering s/uare $o@, the system a!!o(s specifying (hether ta$!e is
going to $e $uGered" 2hen a ta$!e is $uGered, it is !oaded into the ta$!e $uGer from
the app!ication serer memory and it (i!! remain there unti! you s(itch oG or re$oot
system"
If the ta$!e is to $e $uGered, you need to specify the type of $uGering" Au!! is for entire
ta$!e (hi!e partia! is for on!y those records (hich are $eing accessed"
;nce the ta$!e is created, it has to $e generated or actiated to $e a$!e to access $y
other o$'ects !i%e programs"
Page 24 of 62
ABAP BASICS
Gnr%l In&ro'0c&!on &o ABAP/4
SAP origina!!y dee!oped the programming !anguage A+AP/4 KAdanced +usiness
App!ication ProgrammingL for interna! use to proide $est (or%ing conditions for
dee!opers" SAP constant!y improes the !anguage to adapt to the increasing
re/uirements of the $usiness app!ications" At present, A+AP/4 is the on!y too! for
dee!oping app!ications at SAP"
SAP customers use A+AP/4 for their o(n dee!opments" &he A+AP/4 =ee!opment
2or%$ench contains a!! too!s you need to create and maintain A+AP/4 programs"
A+AP/4 programs are not comp!ied $ut generated" =uring generation, the system
creates a soDca!!ed runtime o$'ect from the source code and the program attri$utes"
2hen you start the program, the system e@ecutes the runtime o$'ect"
A+AP/4, a fourth generation !anguage, contains a!! usua! contro! structures and
modu!ariFing concepts for structured programming" &he three parts of the A+AP/4
!anguage are*
Structure and e@ecution of A+AP/4 programs
+asic !anguage e!ements
Programming reports
Programming dia!ogs
Structure and execution of ABAP/4 programs are essentia!!y diGerent from entire!y
se/uentia! programming !anguages such as A;R&RA<, PAS.A-, or ." A+AP/4 instead
shares certain simi!arities (ith modu!ar, eentDorient programming !anguages such as
)isua! +asic or OA)A"
&he t(o most important statements concerning structure and e@ecution are*
An A+AP/4 program has a modu!ar structure"
Aor e@ecution, you need a specia! runtime enironment"
&his means, that A+AP/4 source te@ts a!(ays consist of a co!!ection of program modu!es
Kone sing!e modu!e in the easiest caseL or the se/uentia! set of statements" &he
indiidua! program modu!es consist of se/uentia! e!ements" &he set of statements of a
program modu!e is a!so ca!!ed processing $!oc%"
&he runtime enironment is responsi$!e for ca!!ing the indiidua! program modu!es one
after the other" &he runtime enironment is the ABAP/4 processor, (hich can
communicate (ith te list processor or te dialog processor, depending on the
program type"
Program Io( (ithin the indiidua! processing $!oc%s is se/uentia!, as you %no( it from
other se/uentia! programming !anguages Kfor e@amp!e, A;R&RA<, PAS.A- and .L"
Page 25 of 62
ABAP BASICS
2ithin the processing $!oc%s, you can use the genera! contro! statements for the
program Io(, such as IA, =;4S, 2EI-4, A+AP/4 does not contain 7;&; e!ements"
2e main!y use programs that consist of a sing!e processing $!oc% on!y and, therefore,
$ehae most !i%e!y !i%e programs of other se/uentia! programming !anguages" Aor
programming app!ications, the entire!y se/uentia! concept is not suGicient" SAP
distinguishes $et(een t(o genera! types of app!ication programs*
R)or&$= 5ou use reports to read data$ases and represent the resu!ts in !ists" Reports
are co!!ections of processing $!oc%s that the system ca!!s depending on eents"
4!%log )rogr%+$= 5ou can dia!og programs to e@ecute transactions, (hich usua!!y
read and change data$ases" =ia!og programs are co!!ections of processing $!oc%s KsoD
ca!!ed modu!e poo!sL that are ca!!ed $y a screen Io( !ogic" &he third part of the ,ser:s
7uide descri$es dia!og programming in detai!"
R)or&$ c%n c%ll '!%log )rogr%+$ %n' 1!c 1r$%@
In its easiest ersion, an A+AP/4 program contains one sing!e se/uentia! piece of coding
and, thus, one sing!e processing $!oc%"
C(%r%c&r!$&!c$ o3 &( ABAP/4 )rogr%++!ng l%ng0%g$
=ec!aratie e!ements for dec!aring data of diGerent type and structures"
;perationa! e!ements for manipu!ating data"
.ontro! e!ements to contro! processing Io("
A+AP/4 is mu!tiD!ingua!" &e@t e!ements such as tit!es, headings, and te@t $ody are
stored separate!y, independent of the program codes" &hus, you can change,
trans!ate, and maintain te@t e!ements (ithout haing no adapt the coding"
A+AP/4 supports $usinessDre!ated data types and operations" 5ou can e@ecute
ca!cu!ations using specia! data and time 1e!ds" &he system automatica!!y e@ecutes
a!! necessary type conersions"
A+AP/4 proides a num$er of functions for processing character strings"
A+AP/4 a!!o(s you to de1ne and ca!! su$routines" 5ou can een ca!! su$routines of
other programs" &here are diGerent (ays of ho( to pass parameters to and from the
Su$routines"
A+AP/4 contains a specia! type of su$routine, ca!!ed function modu!e" Aunction
modu!es are stored and maintained in a centra! !i$rary" &hey hae c!ear!y de1ned
data interfaces to the ca!!ing program" 5ou can test function modu!es in a standD
a!one mode independent of the ca!!ing program"
A+AP/4 contains an SN- su$set ca!!ed ;P4< SN-" ;P4< SN- a!!o(s you to read
and change data$ase ta$!es independent of the under!ying data$ase system"
Page 26 of 62
ABAP BASICS
A+AP/4 a!!o(s you to de1ne and process interna! ta$!es that e@ist on!y for the
e@ecution period of the program" Interna! ta$!es eGicient!y support the usage of
data$ase ta$!es and a!!o( you to imp!ement comp!e@ data structures in a program"
A+AP/4 a!!o(s you to store data not on!y in data$ases $ut a!so as se/uentia! 1!es on
app!ication and presentation serers"
REPORTS
Reports are A+AP/4 programs"
5ou use reports to ea!uation data from data$ase ta$!es" &he resu!ts of such an
ea!uation can $e disp!ayed on the screen or printed form"
Reports are standDa!one programs"
&he user can e@ecute reports direct!y ia the program name, for e@amp!e, $y
choosing System ? ,ti!ities ? Reporting"
A report program contains a co!!ection of processing $!oc%s for diGerent eents that
are a!(ays triggered e@terna!!y" In a report, you can react on eents $y
programming the corresponding processing $!oc%s or ignore the eents $y not
(riting the corresponding processing $!oc%s" A report itse!f neer creates eents"
Reports can use !ogica! data$ases or se!ect statements de1ned $y dee!oper"
Aor each app!ication, SAP supp!ies !ogica! data$ases" ;r you can easi!y create
!ogica! data$ase yourse!f"
4ent contro! of a report corresponds to a certain scheme*
2hen a report is e@ecuted, the A+AP/4 processor creates together (ith the !ogica!
data$ase used Kif anyL a se/uence of certain eents for (hich you can program
processing $!oc%s" &he chrono!ogy of the eents is Kmore or !essL
Steps ino!ed in creating a Report*
,@ Proc$$!ng &( $lc&!on $crn
After starting a report, the se!ection screen a!!o(s the user to enter !imits or
contro! a!ues for further report processing" &he report can contain seera!
processing $!oc%s for eents during se!ection screen processing, for e@amp!e, for
chec%ing the input a!ues"
2@ R%'!ng &( '%&%6%$
After se!ection screen processing come the eents for reading the data$ase"
4ither the report reads data from re!ationa! data$ases it using the corresponding
A+AP/4 statements Kopen SN-L or !eaes this tas% to a !ogica! data$ase" In the
!atter case, the !ogica! data$ase creates a se/uence of eents to a!!o( the report
to copy the data"
3@ E1%l0%&!ng '%&% %n' cr%&!ng l!$&$
Page 29 of 62
ABAP BASICS
=uring or after reading the data$ase the report creates the output !ist" =uring !ist
creation, seera! eents a!!o( you to !ayout the output !ist Kfor e@amp!e, !ayout the
page headerL"
4@ O0&)0&&!ng % l!$&
&he !ast part of the processing se/uence contro!!ed $y the A+AP/4 processor is
the !ist output on the screen or printer" 2hen disp!aying the !ist on the screen,
user can trigger other reports, that are interactie and are eent drien" Aor
e@amp!e, $y c!ic%ing the mouse" +y programming processing $!oc%s for these
eents, you change a norma! report to a soDca!!ed In&r%c&!1 r)or&" If a report
does not contain eent %ey(ords, the entire coding of the report $e!ongs to a
sing!e processing $!oc%, (hich is ca!!ed $y a standard eent" &his standard eent
is triggered direct!y after processing the se!ection screen"
4IALOG PROGRAMS
5ou use dia!og programs to e@ecute transactions" &he users of dia!og programs in
dia!og sessions read and change data$ase ta$!es" Apart from the actua! data
processing K;pen SN-L, update and en/ueue concepts are of great importance (hen
programming dia!ogs"
=ia!og programs are not standD a!one
&o e@ecute dia!og programs, they must $e !in%ed to at !east one screen that itse!f is
!in%ed to a transaction code" &he transaction code determines the initia! screen (ith
(hich the dia!og session starts"
=ia!og programs are contro!!ed $y screen Io( !ogic
&he actua! A+AP/4 dia!og program is a soDca!!ed modu!e poo!" A modu!e poo!
contains a co!!ection of dia!og modu!es that are ca!!ed $y the screen Io( !ogic"
&o each modu!e poo!, at !east one, $ut usua!!y seera! screens are a!!ocated" 4ach
screen has Io( !ogic" &he Io( !ogic consists of P+; Kprocess +efore outputL and PAI
Kprocess After InputL $!oc%s" &his Io( !ogic does not use the A+AP/4 programming
!anguage and the A+AP/4 4ditor too!, $ut a specia! statement set and the Screen
Painter too!, (hich you a!so use to !ayout screens" &he Io( !ogic main!y contains the
chrono!ogica!!y ordered ca!!s of the modu!es in the corresponding modu!e poo!"
!e collection of PB" #ow logic, screen, and PA$ #ow logic is called %ynamic
program &%ynpro'" A modu!e poo! must hae at !east one dynpro" 4ach screen of a
dia!og session thus is the isi$!e part of a dynpro, to (hich a!so the Io( !ogic
$e!ongs" &he processing !ogic of a dia!og session is stored in the corresponding
modu!e poo! in the form of A+AP/4 modu!es"
Page 2J of 62
ABAP BASICS
&he A+AP/4 modu!es in the modu!e poo! are separated into P+; and PAI modu!es"
&he P+; or PAI $!oc%s of the Io( !ogic of each dynpro of a modu!e poo! can ca!! each
P+; or PAI modu!e of this modu!e poo!"
5ou can use A+AP/4 statements in the processing !ogic of the modu!e poo! to contro!
the chrono!ogy of the diGerent dynpros" After starting a dia!og session ia the
transaction code, (hich is 1rm!y connected to a dynpro of the modu!e poo!, the
screen Io( !ogic passes user entries to the processing !ogic in the A+AP/4 modu!e
poo!" &he processing !ogic processes the user entries Kdata$ase accessesL and, if
re/uired, de1nes the appropriate su$se/uent screens"
Page 28 of 62
ABAP BASICS
4%&% T*)$ %n' 4%&% O6:c&$
=ata types and data o$'ects are essentia! components of the A+AP/4 type concepts"
+oth can $e dec!ared and maintained $y user" ,n!i%e other programming !anguages in
A+AP/4 you can create =A&A &5P4S independent!y"
4%&% T*)$
Are pure descriptions
<o memory is associated (ith data types"
=escri$es the technica! properties of data o$'ects"
Structure and de1nition c!assify data types" .an $e of*
1" 4!ementary or structured
2" Prede1ned or user de1ned
Pr'<n' U$rC'<n'
4-404<&AR5 ., =, A, I, <, P, &, M +ased upon
e!ementary =ata
types"
5ou can use direct!y 4"g",
&5P4S* num$er types
I" .an:t a!!ocate
memory to types"
S&R,.&,R4= Prede1ned types are
&A+-4S
,ser de1ned
structured types are
Aie!d String and
interna! ta$!es"
Page 3> of 62
ABAP BASICS
4%&% O6:c&$
=ata o$'ects are units created during runtime"
=ata o$'ect cannot e@ist (ithout data type"
;ccupies memory space"
K!n'$ o3 4%&% O6:c&$
,@ INTERNAL 4ATA OB9ECTS
L!&r%l
A !itera! has a 1@ed a!ue"
4@ 2RI&4* B2;R6 EAR=C
5%r!%6l$
=A&A statement is used to create aria$!es
4@ =A&A* <,0 &5P4 I
<,0 is a aria$!e dec!ared $y =A&A statement" Any aria$!e, (hich you use in
program, need to $e dec!ared $efore you use it and can $e done $y =A&A statement"
Eere aria$!e is dec!ared $y referring to e@isting data type"
)aria$!e can a!so $e dec!ared $y referring e@isting data o$'ect"
4@" 2e hae a!ready dec!ared <,0 $y =A&A statement"
=A&A* PRI.4 -I64 <,0"
Eere aria$!e is dec!ared $y using -I64 parameter, (hich te!!s system that price has
a!! the attri$utes of data o$'ect <,0 i"e", PRI.4 is a!so of type I"
&he main diGerence $et(een &5P4 and -I64 parameter (hen de1ning or dec!aring
the o$'ect is that &5P4 is used to refer e@isting =A&A &5P4 Ke!ementary or
structured or user de1nedL (hi!e -I64 is used to dec!are data o$'ects (ith reference
to e@isting =A&A ;+O4.&S"
Con$&%n&
.onstant is a data o$'ect, (hich contains 1@ed a!ue through out the program"
.onstant can $e dec!ared in program $y using .;<S&A<& statement"
4@" .;<S&A<&* I<& &5P4 I )A-,4 15"
Page 31 of 62
ABAP BASICS
In program a!ue of I<& cannot $e changed" If you gie a statement !i%e I<& Q 2>"
In this case system (i!! gie error"
2@ EDTERNAL 4ATA OB9ECTS
Are de1ned in ta$!es i"e", in A+AP/4 dictionary" 5ou can access this data from
ta$!e"
&A+-4S* SA-I7E&
=A&A* S4A&S -I64 SA-I7E&DS4A&S0AM"
3@ SYSTEMC4EFINE4 4ATA OB9ECTS
SPA.4 # S5S&40 )ARIA+-4S !i%e syDuname, syDdatum, # syDrepid"
4@ SPECIAL 4ATA OB9ECTS
PARA04&4RS* are aria$!e, (hich can accept a!ue from user"
S4-4.&I;<S .RI&4RIA* are specia! interna! ta$!es to accept a!ue range from
user"
N' 3or 4%&% &*)$=
.onsider the fo!!o(ing e@amp!e"
=A&A* fnameK2>L,
mnameK2>L,
!nameK2>L,
add1K2>L,
add2K2>L,
add3K2>L"
If you hae =A&A statement !i%e a$oe, and if you need to change the !ength of a!! the
1e!ds say from 2> to 25, then you need to change a!! the 1e!ds i"e", going through each
and eery statement"
+ut consider the fo!!o(ing case (here &5P4S has $een used"
&5P4S*strK2>L
=A&A*fname type str,
Page 32 of 62
ABAP BASICS
0name type str,
-name type str,
Add1 type str,
Add2 type str,
Add3 type str"
In this case if you need to change the !ength of a!! 1e!ds from 2> to 25" &hen 'ust
change the !ength of S&R and change (i!! $e reIected for a!! the 1e!ds"
If you de1ne a!! the types in &5P4DP;;- i"e", g!o$a! de1nition of a!! the types, you can
use these types any(here and in any program"
P%r%+&r$
Parameter statement is used to accept input from user" PARA04&4R statement is used
(hen you (ant user to enter data and depending upon (hat he enters you need to ta%e
action" &he parameter statement dec!ares the aria$!e and a!so a!!o(s system to accept
data into that aria$!e"
Synta@"
Parameters* num type I"
Eere parameter statement dec!ares the aria$!e and creates the se!ection screen on
(hich user enters the data i"e", in this case num is dec!ared of type I and user can enter
any num$er" 4ntered a!ue is stored in the same aria$!e and can $e used in program"
=ata* m type I
Parameters* num type I
0 Q num 3 5
2rite* / R&he num$er is:, m"
5ou can de1ne defau!t a!ues (ith parameter statement for e@amp!e
Parameter* num type I defau!t 12"
In this case (hen se!ection screen is disp!ayed the defau!t a!ue is disp!ayed" ,ser can
either use same a!ue or oer(rite the a!ue"
Parameter of type character and !ength Q 1, can $e disp!ayed as .hec%$o@ and
Radio$utton"
Parameter* .1 as .hec%$o@,
.2 as .hec%$o@"
Parameter* R1 Radio$utton group g1,
R2 Radio$utton group g1"
2hen parameter is de1ned as Radio$utton, it needs to $e attached to one group" ;n!y
one Radio$utton of one group can $e c!ic%ed"
Page 33 of 62
ABAP BASICS
4ery parameter can $e associated (ith !anguage dependent te@t that is disp!ayed on
the se!ection screen" &his can $e done (ith the he!p of te@t e!ements"
Page 34 of 62
ABAP BASICS
WRITE S&%&+n&
&he $asic APA+/4 statement for outputting data on the screen is 2RI&4"
Synta@*
2RI&4 S1e!dT SoptionT"
&his statement outputs the 1e!d SfT to the current !ist in its standard output format"
+y defau!t, the !ist is disp!ayed on the screen"
&he 1e!d S1e!dTcan $e any aria$!e or ta$!e 1e!d or 'ust !itera!"
PR;7RA0 U=40;
2RI&4* /RE4--;:"
2hen you start this program, the system !eaes the current screen i"e", your editor
screen and $ranches to the output screen, (hich is a!so ca!!ed as !ist screen*
&he !ist screen has the same name as the tit!e of the program speci1ed in the program
attri$utes" Airst !ine on the screen contains the !ist header" +y defau!t, the !ist header
is the same as the tit!e of the program" &he current page num$er K1L appears on the
right" &he !ist header is fo!!o(ed $y one !ine and then the output is disp!ayed"
2rite * RE4--;:"
2rite * R2;R6 EAR=:
;n the screen, the output is norma!!y !eft 'usti1ed" +ut in a$oe case, $ecause (e hae
used t(o 2RI&4 statements, the output 1e!ds are disp!ayed one after the other, each
separated $y one co!umn Ki"e", one $!an%L" If there is not enough space for an output
1e!d on the current !ine, a ne( !ine is started"
A!most a!! systemDde1ned 1e!ds are right 'usti1ed e@cept A-;A&, I<&474R, and
PA.64= i"e", num$er 1e!d" &he numeric data types A, P, and I are right 'usti1ed and
padded (ith $!an%s on the !eft" If there is suGicient space, thousands of separators are
a!so output" If a type P 1e!d contains decima! p!aces, the defau!t output !ength is
increased $y one"
2ith the data type =, the interna! format of a date diGers from its output format" 2hen
you use the 2RI&4 statement for outputting data, the system automatica!!y outputs
dates of type = in the format speci1ed in the user:s master record Ke"g" ==/00/5555 or
00/==/5555L"
Page 35 of 62
ABAP BASICS
For+%&&!ng o0&)0&
5ou can position the output of a 2RI&4 statement on the screen $y ma%ing a format
speci1cation $efore the 1e!d name as fo!!o(s*
Synta@*
2RI&4 A& V/WVSposTWVKS!enTLW SfT,
2here
Rthe s!ash:/R denotes a ne( !ine,
SposT is a num$er or aria$!e denoting the position on the screen,
S!enT is a num$er or aria$!e !ong denoting the output !ength"
Aor aria$!es you need to mention the A&, for direct a!ues it is not necessary"
=A&A* -4< &5P4 I )A-,4 1>,
P;S &5P4 I )A-,4 11,
&4M& K1>L )A-,4 R1234569J8>:
2RI&4 A& P;S K-4<L &4M&"
&his produces the fo!!o(ing output on the screenH
&he te@t 3 1234569J8> 3 appears in the te@t"
If the output !ength S!enT is too short, fe(er characters are disp!ayed" <umeric 1e!ds
are truncated on the !eft and pre1@ed (ith an asteris% KXL" A!! other 1e!ds are truncated
on the right, $ut no indication is gien that the 1e!d is shorter"
=A&A* <,0+4R &5P4 I )A-,4 1234569J8>,
&4M& K1>L )A-,4 Ra$cdefghi':"
2RI&4* K5L <,0+4R, /K5L &4M&"
&his produces the fo!!o(ing output*
9J8>
a$cde
In the defau!t setting, you cannot create empty !ines (ith the 2RI&4 statement"
2RI&4* R;ne:,
/R :,
/ R&(o:
Page 36 of 62
ABAP BASICS
&he output !oo%s as fo!!o(s*
;ne
&(o
&he system suppresses !ines that contain nothing $ut empty spaces"
5ou can use arious formatting options (ith the 2RI&4 statement"
Synta@
2RI&4YYYY S1e!dT SoptionT
For+%&&!ng o)&!on$ 3or %ll '%&% &*)$
"ption Purpose
-4A&DO,S&IAI4= ;utput is !eft 'usti1ed"
.4<&4R4= ;utput is centered"
RI7E&DO,S&IAI4= ;utput is right 'usti1ed"
<;D7AP &he $!an% after the 1e!d SfT is
omitted"
<;DU4R; If a 1e!d contains on!y Feros,
these are rep!aced $y $!an%s"
Aor type . and < 1e!ds, !eading
Feros are rep!aced automatica!!y"
For+%&&!ng o)&!on$ 3or n0+r!c <l'$
O)&!on P0r)o$
<;DSI7< &he !eading sign is not output"
=4.I0A-S SdT SdT de1nes the num$er of digits
after the decima! point"
4MP;<4<& SeT In type A 1e!ds, the e@ponent is
de1ned in SeT
R;,<= SrT &ype P 1e!ds are mu!tip!ied $y
1>XXKDrL and then rounded
.,RR4<.5 ScT Aormat according to currency
ScT in ta$!e &.,RM"
,<I& SuT &he num$er of decima! p!aces is
1@ed according to the unit
SuT speci1ed in ta$!e &>>6 for
type P 1e!ds"
Page 39 of 62
ABAP BASICS
Hor!Bon&%l l!n$
5ou can generate horiFonta! !ines on the output screen $y using the fo!!o(ing synta@*
Synta@
,-I<4
2i!! dra( a horiFonta! !ine"
,-I<4 K1>L
2i!! start dra(ing horiFonta! !ine from 1>
th
co!umn position"
2RI&4 at 1>K4>L S5D,-I<4
&his statement dra(s a horiFonta! !ine from 1>
th
position"
5r&!c%l l!n$
5ou generate ertica! !ines one the output screen $y using the fo!!o(ing synta@*
Synta@
2RI&4 VA& V/W VSposTWW S5D)-I<4"
Bl%n. l!n$
5ou can generate $!an% !ines on the screen $y using the fo!!o(ing synta@ *
Synta@
S6IP VSnum$erTW
Starting on the current !ine, this statement generates Snum$erT $!an% !ines on the
output screen" If no a!ue is speci1ed for Snum$erT, one $!an% !ine is output" In the
standard setting, you cannot create empty !ines (ith the 2RI&4 statement a!one"
&o position the output on a speci1c !ine on the screen use*
Synta@
S6IP &; -I<4 Snum$erT
&his statement a!!o(s you to moe the output position up(ards or do(n(ards"
Page 3J of 62
ABAP BASICS
Br%nc($
-i%e other higher programming !anguages, A+AP/4 proides standard %ey(ords to
contro! the Io( of a program"
,sua!!y A+AP/4 programs get e@ecuted statement $y statement" 0any times you need
to s%ip fe( statements depending upon certain conditions i"e", you change the Io( of
program" &his can $e done $y*
6r%nc(!ng EIF? CASEF
loo)!ng E4O? WHILEF
Eo(eer, un!i%e other !anguage (here you hae on!y interna! contro!, ABAP/4 (%$
!n&rn%l con&rol %n' >&rn%l con&rol o3 &( )rogr%+ Go/@
&he !n&rn%l con&rol is steered $y standard %ey(ords as mentioned a$oe" 5ou
de1ne this in your program code"
&he >&rn%l con&rol is stored $y eents" 4ents are generated either from other
A+AP/4 programs or from interactie user input K!i%e, for e@amp!e, using the mouse
to c!ic% on the screenL" &he system does not necessari!y process the statements in
the same se/uence as they are !isted in an A+AP/4 program" &his ma%es A+AP/4 an
eentDdrien programming !anguage" &he e@terna! contro! p!ays an important ro!e
main!y for report programs"
Br%nc(!ng /!&( IF $&%&+n&
&he IA statement a!!o(s you to '!1r& &( )rogr%+ Go/ &o % )%r&!c0l%r $&%&+n&
$!oc%, depending on a condition" &his statement $!oc% consists of a!! the commands
(hich occur $et(een an IA statement and the ne@t 4-S4IA, 4-S4, or 4<=IA statement"
Synta@
IAScondition1T
Sstatement $!oc%T
4-S4
Sstatement $!oc%T
4<=IA
If the 1rst condition is true, the system e@ecutes a!! the statements up to the end of the
1rst statement $!oc% and then continues processing after the 4<=IA statement"
Page 38 of 62
ABAP BASICS
&o introduce a!ternatie conditions, you can use 4-S4IA statements" If the 1rst
condition is fa!se, the system processes the fo!!o(ing 4-S4IA statement in the same
(ay as the IA statement" 4-S4 $egins a statement $!oc% (hich is processed if none of
the IA and 4-S4IA conditions is true" &he end of the !ast statement $!oc% must a!(ays
$e conc!uded (ith 4<=IA"
IA Scondition1T"
Sstatement $!oc%T
4-S4IA Scondition2T"
Sstatement $!oc%T
4-S4IA Scondition3T"
Sstatement $!oc%T
4-S4"
Sstatement $!oc%T
4<=IA"
A+AP/4 a!!o(s un!imited nesting of IA 3 4<=IA statement $!oc%s, $ut they must
terminate (ithin the same processing $!oc%" In other (ords, an IA 3 4<=IA $!oc%
cannot contain an eent %ey(ord"
Br%nc(!ng /!&( CASE $&%&+n&
&o e@ecute diGerent statement $!oc%s depending on the contents of particu!ar data
1e!ds, you can either use IA statement or the .AS4 statement as fo!!o(s*
Synta@
.AS4 SfT"
2E4< Sf1T"
Sstatement $!oc%T
2E4< Sf2T"
Sstatement $!oc%T
2E4< Sf3T"
Sstatement $!oc%T
2E4< ;&E4RS"
Sstatement $!oc%T
4<=.AS4"
&he system e@ecutes the statement $!oc% after the 2E4< statement if the contents of
SfT e/ua!s the contents of S1T, and continues processing after the 4<=.AS4
statement" &he statement $!oc% after the optiona! 2E4< ;&E4RS statement is
e@ecuted if the contents of SfT do not e/ua! any of the S1T contents" &he !ast
statement $!oc% must $e conc!uded (ith 4<=.AS4"
Page 4> of 62
ABAP BASICS
&he conditiona! $ranching using .AS4 is a shorter and simp!er form of simi!ar
processing (ith IA" 2hen you hae many conditions IA $ecomes more comp!icated in
such cases .AS4 is used"
Page 41 of 62
ABAP BASICS
LOOPING
Loo)!ng /!&( 4O $&%&+n&
If you (ant to (rite your name say for 1> times, you need to (rite 2RI&4 statement for
1> times"
2hen you (ant to process a statement more than once, you can (rite this statement
(ithin a !oop (ith the =; statement as fo!!o(s*
Synta@
=; 5 times"
2rite * / name"
4<==;"
&he system continues processing the statement $!oc% for 5 times introduced $y =; and
conc!uded $y 4<==;"
&he system 1e!d S5DI<=4M contains the num$er of times the !oop has $een processed
so in this case (hen the !oop is oer a!ue of syDinde@ (i!! $e 5"
In this case you %no( that, you (ant to perform 2RI&4 statement for 5 times" +ut that
is not the case a!(ays" 0any times you need to terminate the !oop depending upon
certain conditions" &his can $e done, $y using EDIT or STOP statement"
&he important point to remem$er (hen you don:t you use &I04S option, is to aoid
end!ess !oops (hen (or%ing (ith the =; statement" If you do not use the &I04S
option, inc!ude at !east one 4MI&, S&;P statement so that the system can !eae the !oop"
4MI& and S&;P ta%es you out of that !oop"
Loo)!ng /!&( WHILE S&%&+n&
If you (ant to process a statement $!oc% more than once as !ong as a condition is true,
you can program a !oop (ith the 2EI-4 statement as fo!!o(s*
Synta@
=A&A* 0 &5P4 I )A-,4 >"
2EI-4 0 S 1>"
2RI&4* / 0"
0 Q 0 P 1"
4<=2EI-4"
Page 42 of 62
ABAP BASICS
&he system continues processing the statement $!oc% introduced $y 2EI-4 and
conc!uded $y 4<=2EI-4 statements as !ong as 0 is !ess than 1> or unti! the system
1nds an 4MI&, S&;P"
&he system 1e!d SYCIN4ED contains the num$er of times the !oop has $een processed"
5ou can nest 2EI-4 !oops any num$er of times and a!so com$ine them (ith other
!oops"
4!"rnc 6&/n 4O loo) %n' WHILE is that in 2EI-4, condition is chec%ed 1rst
and if condition is true then !oop is e@ecuted (hi!e in =; !oop, the !oop gets e@ecuted
1rst if you don:t hae &I04S option and then the condition is chec%ed Kif you hae anyL"
5ou can hae nested =; and 2EI-4 or =; and IA or IA and IA or any possi$!e situation"
Page 43 of 62
ABAP BASICS
S&r!ng O)r%&!on$
A+AP/4 proides seera! %ey(ords for processing data o$'ects of type ., a!so %no(n as
character strings"
S(!3& co++%n'
&o shift the contents of a 1e!d, $y one position or one character you can use the SEIA&
statement" ,sing SEIA& a!!o(s you to shift 1e!d contents, $yteD$yD$yte or characterD$yD
character"
2ith the SEIA& statement, you can e@ecute the fo!!o(ing*
String Q RE4--;:"
String 1 Q RA-- ;A 5;,:"
String 2 Q R2;R6 EAR=:"
Shift string
Shift string1 $y 2 p!aces"
Shift string2 right"
Shift string1 $y 2 p!aces circu!ar"
&he output (i!! $e
4--; 3 +y defau!t if nothing is speci1ed then string is shifted $y one position"
- ;A 5;, 3 Eere the string is shifted $y 2 p!aces"
Z2;R6 EAR= 3 In this case the string is shifted to right $y one p!ace K(ith !eading
$!an%sL
6 EAR=2;R 3 In this case the string is shifted to the !eft so that 3 characters on the
!eft appear on the right"
R)l%c co++%n'
5ou use the R4P-A.4 statement"
Synta@
R4P-A.4Sstr!T2I&ESstr2TI<&;ScTV-4<7&ES1TW"
A+AP/4 searches the 1e!d ScT for the 1rst occurrence of the 1rst, S1T positions of the
pattern Sstr1T" If no !ength is speci1ed, it searches for the pattern Sstr1T in its fu!!
!ength"
&hen, the statement rep!aces the 1rst occurrence of the pattern Sstr1T in 1e!d
ScT(ith the string Sstr2T" If a !ength S!T (as speci1ed, on!y the re!eant part of the
pattern is rep!aced"
R4P-A.4 S&R1 2I&E S&R2 I<&; S&RI<7"
Page 44 of 62
ABAP BASICS
Eere (ho!e string is searched for string1 and is rep!aces (ith str2"
R4P-A.4 R#: 2I&E R0:
Eere the system searches string for # and rep!aces it (ith R0:"
TRANSLATE co++%n'
Synta@
&RA<S-A&4ScT &; ,PP4R .AS4"
&RA<S-A&4ScT &; -;24R .AS4"
&hese statements conert a!! !o(er case !etters in the 1e!d ScT to upper case or ice
ersa"
5ou can use &RA<S-A&4 to su$stitute the characters in a string !i%e rep!ace" +ut the
main diGerence $et(een &rans!ate and Rep!ace is that Rep!ace statement rep!aces on!y
one occurrence of particu!ar character (hi!e &rans!ate rep!aces a!! the occurrences of
the character"
2hen using su$stitution ru!es, use the fo!!o(ing synta@*
Synta@
&RA<S-A&4 ScT ,SI<7 SrT"
STRLEN co++%n'
&o determine the !ength of a character string up to the !ast character other than SPA.4,
use the $ui!tDin function S&R-4< as fo!!o(s*
Synta@
< Q S&R-4< K S&R L"
Eere < is de1ned in =A&A statement as type i"
S&R-4< processes any operand ScT as a character data type, regard!ess of its rea!
type" <o conersions are performed"
CON4ENSE co++%n'
&o de!ete superIuous $!an%s in character 1e!ds, use the .;<=4<S4 statement*
Synta@
.;<=4<S4 ScT V<;D7APSW"
&his statement remoes any !eading $!an%s in the 1e!d ScT and rep!aces other
se/uences of $!an%s $y e@act!y one $!an%" &he resu!t is a !eftD'usti1ed se/uence of
(ords, each separated $y one $!an%" If the addition <;D7APS is speci1ed, a!! $!an%s
are remoed"
CONCATENATE co++%n'
&o concatenate separate character strings into one, use the .;<.A&4<A&4 statement*
Synta@
Page 45 of 62
ABAP BASICS
.;<.A&4<A&4 Sc1T YScnT I<&; ScT VS4PARA&4= +5 SsTW"
&his statement concatenates the character 1e!ds Sc1T to ScnT and assigns the resu!t
to ScT"
&rai!ing $!an%s are ignored during this operation"
.;<.A&4<A&4 S&R R*: S&R2 I<&; S&RI<7"
Eere str, str2 and R*: is concatenated and resu!t is stored in string"
SPLIT co++%n'
&o sp!it a character string into t(o or more sma!!er strings, use the SP-I& statement*
Synta@
SP-I& ScT A& Sde!T I<&; Sc!TY"ScnT"
&his statement searches the character 1e!d ScT for de!imiter strings Sde!T and the
parts $efore and after the de!imiters are p!aced in the target 1e!ds Sc1TY"ScnT"
&o p!ace a!! fragments in diGerent target 1e!ds, you must specify enough target 1e!ds"
;ther(ise, the !ast target 1e!d is 1!!ed (ith the rest of the 1e!d ScT and sti!! contains
de!imiters"
SP-I& S&RI<7 A& R,: I<&; P1 P2 P3 P4"
Eere the string is sp!it at R,: and is put into strings p1, p2, p3, p4"
In ABAP/4? *o0 c%n $)c!3* o"$& 1%l0$ 3or l+n&%r* '%&% o6:c&$ !n %ll
$&%&+n&$? /(!c( )roc$$ &($ '%&% o6:c&$@
&o do so, specify the name of a data o$'ect in a statement as fo!!o(s*
Synta@
SfTVPSoTWVKS!TLW
&he operation of the statement is performed for the part of the 1e!d SfT that $egins at
position SoTP1 and has a !ength of S!T"
If the !ength S!T is not speci1ed, the 1e!d is processed for a!! positions $et(een SoT
and the end of the 1e!d"
String Q string1P3K4L"
Assuming that string1 Q Ra$cdefg'%:"
Eere string (i!! contain Rdefg:"
Page 46 of 62
ABAP BASICS
Page 49 of 62
ABAP BASICS
OPEN SHL
In the R/3 System, !ongD!ife data is stored in re!ationa! data$ase ta$!es" Structured
Nuery -anguage KSN-L (as created for accessing re!ationa! =ata$ase" SN- has t(o
statement types* =ata =e1nition -anguage K==-L statements and =ata 0anipu!ation
-anguage K=0-L statements"
&; inc!ude SN- statements in an A+AP/4 program, use <atie SN-" &o aoid
incompati$i!ities $et(een diGerent data$ase ta$!es and a!so to ma%e A+AP/4 program
independent of the data$ase system in use, SAP has created a set of separate SN-
statements ca!!ed ;pen SN-" ;pen SN- contains a su$set of standard SN- statements
as (e!! as some enhancements, (hich are speci1c to SAP" ,sing ;pen SN- ena$!es you
to access any data$ase ta$!es aai!a$!e to the SAP system regard!ess of the
manufacturer $e it ;rac!e, Informi@ etc"
&he diGerence $et(een ;pen SN- and <atie SN- is as fo!!o(s*
A data$ase interface trans!ates SAP:s ;pen SN- statements into SN- commands
speci1c to the data$ase in use" <atie SN- statements access the data$ase direct!y"
;pen SN- %ey(ords
6ey(ords ,sed for
S4-4.&* Reading =ata from =ata$ase &a$!es
I<S4R&* Adding -ines to =ata$ase &a$!es
,P=A&4* .hanging -ines in =ata$ase &a$!es
0;=IA5* Adding or .hanging -ines
=4-4&4* =e!eting -ines from =ata$ase &a$!es
2hen using ;pen SN- statements in an A+AP/4 program, you must ensure the
fo!!o(ing*
1L &he data$ase system $eing addressed must $e supported $y SAP"
2L &he data$ase ta$!es $eing addressed must $e de1ned in the A+AP/4 =ictionary"
Page 4J of 62
ABAP BASICS
Slc& $&%&+n&
&he fo!!o(ing system 1e!ds p!ay an important ro!e in ;pen SN- operations*
SYCSUBRC
As (ith other A+AP/4 statements, the return code a!ue in the system 1e!d S5DS,+R.
indicates after each ;pen SN- operation (hether or not the operation (as successfu!"
If an operation is successfu!, S5DS,+R. Q >" If an operation is unsuccessfu! 3 S5DS,+R.
ST >
SYC4BCNT
&he a!ue in the S5D=+.<& 1e!d indicates ho( many !ines (ere aGected $y the
operation or ho( many !ines hae a!ready $een processed"
&o read data from a data$ase ta$!e, use the S4-4.& command"
Synta@
S4-4.&S(hatT AR;0 Sta$!e nameT VI<&; Saria$!e, another ta$!eTW V2E4R4
SconditionTW"
&his statement has seera! $asic c!auses" 4ach c!ause is descri$ed in the fo!!o(ing
ta$!e"
S4-4.&S(hatT AR;0 Sta$!e nameT I<&; Saria$!es or another ta$!eT 2E4R4
SconditionT
&he S4-4.& c!ause de1nes (hether the resu!t of the se!ection is a sing!e !ine or a
(ho!e ta$!e, or fe( co!umns"
AR;0 Sta$!e nameT
&he AR;0 c!ause speci1es the data$ase ta$!e or ie( SsourceT from (hich the data is
to $e se!ected"
I<&; Saria$!e, another ta$!eT
&he I<&; c!ause determines the target area StargetT into (hich the se!ected data is to
$e read" It can a!so $e p!aced $efore the AR;0 c!ause" If you do not specify an I<&;
c!ause, the system uses the ta$!e (or% area" T( &%6l /or. %r% !$ % (%'r l!n?
/(!c( !$ %0&o+%&!c%ll* cr%&' 6* &( TABLES $&%&+n&@
Page 48 of 62
ABAP BASICS
2E4R4 SconditionT
&he 2E4R4 c!ause speci1es (hich !ines are to $e read $y specifying conditions for the
se!ection" .hoosing the -ines to $e Read"
Aor Se!ecting A!! data from ta$!e*
i"e", read a!! co!umns and a!! the ro(s from data$ase ta$!e
Synta@
S4-4.& X AR;0 Sta$!eT"
KEere you are not specifying 2E4R4 conditionL
Se!ecting A!! =ata from a Sing!e -ine
&o read a!! co!umns of a sing!e !ine from a data$ase ta$!e, use the S4-4.& statement as
fo!!o(s *
Synta@
S4-4.& SI<7-4 X AR;0 Sta$!eT YY 2E4R4 SconditionT YY
&he resu!t of this statement is a sing!e !ine" &o ma%e sure you retriee desired uni/ue
sing!e record, you must !in% a!! the 1e!ds (hich form the primary %ey of the data$ase
ta$!e $y A<= in the 2E4R4 condition"
Prere/uisite for S4-4.& SI<7-4
1" ,se a!! primary %eys in 2E4R4 condition"
2" A!(ays chec% for S5DS,+R."
3" .!ear (or%Darea for ta$!e"
Aggrg%& E>)r$$!on$
+y using aggregate e@pressions, you can e@tract characteristic data from a co!umn SaT
of the data$ase ta$!e"
"0AM* returns the ma@imum a!ue of the co!umn
"0I<* returns the minimum a!ue of the co!umn
"A)7* returns the aerage a!ue of the co!umn
Page 5> of 62
ABAP BASICS
"S,0* returns the sum a!ue of the co!umn
".;,<&* counts a!ues or !ines as fo!!o(s*
D.;,<&K X L returns the tota! num$er of !ines in the se!ection"
5ou must inc!ude spaces $et(een the parentheses and the arguments" &he arithmetic
operators A)7 and S,0 can on!y (or% (ith numeric 1e!ds"
Sometimes you retriee fe( co!umns form data$ase ta$!e i"e" you hae !ist in the
S4-4.& .!ause and I<&; .!ause"
If there is a !ist in the S4-4.& c!ause, you must use the I<&; c!ause (ith the S4-4.&
statement" 5ou can use either a (or% area S(aT or an interna! ta$!e Sita$T or !ist of
aria$!es as an argument,
Synta@
&A+-4S* SA-I7E&"
=A&A * .ARRI=I -I64 SA-I7E& D.ARRI=,
.;<<I= -I64 SA-I7E& 3.;<<I="
S4-4.& .ARRI= .;<<I= AR;0 SA-I7E& I<&; K.ARRI=1, .;<<I=1L" 2RI&4* /
.ARRI=!,.;<<I=1"
4<=S4-4.&"
0any times you retriee re!ated data from t(o or more ta$!es" In such cases you use
nested se!ects 6* l!n.!ng &%6l$ /!&( co++on )r!+%r* .*$" +ut as far as possi$!e
aoid using nested se!ects as time re/uired to access nested ta$!e is ery high"
Synta@
&A+-4S* SA-I7E&, S+;;6"
S4-4.& X AR;0 SA-I7E& 2E4R4 .ARRI= Q [-E["
S4-4.& X AR;0 S+;;6 2E4R4 .ARRI= Q SA-I7E& D.ARRI= A<=
.;<<I= Q SA-I7E& D.;<<II="
2RI&4* / SA-SI7E&D.ARRI=,SA-I7E&D.;<<I=,S+;;6D+;;6I=,
4<=S4-4.&"
4<=S4-4.&"
Some performance hints for ;pen SN- statements
6eep the se!ected dataset sma!!
6eep the num$er of se!ected data as sma!! as possi$!e to aoid unnecessary net(or%
transports" ,se the respectie ;pen SN- statements a!(ays (ith the 2E4R4
Page 51 of 62
ABAP BASICS
c!ause" Aoid comp!e@ 2E4R4 c!auses" &he system must sp!it up those into sing!e
statements for the data$ase system"
=o not use the !ogica! <;& in 2E4R4 c!auses $ut inerted operators instead"
&he !ogica! <;& is supported $y the data$ase inde@es"
6eep the transferred data sma!!
&ransfer on!y those co!umns of a data$ase ta$!e that you rea!!y need" Aoid
S4-4.&X if you do not (ant to read a!! co!umns of a data$ase" ,se a !ist in the
S4-4.& c!ause instead" ,se aggregate e@pressions in the S4-4.& c!ause to
perform ca!cu!ations instead transporting great amounts of data and ca!cu!ating
thereafter"
6eep the num$er of data$ase accesses sma!!
,se operations on pac%ages of data instead of operations on sing!e data if you (ant
to ana!yFe se!ected data more than once" &o do so, transfer the data in a sing!e
operation $et(een ta$!es and interna! ta$!es"
Aoid nested S4-4.& !oops" Instead, (or% (ith interna! ta$!es and S4-4.&
statements using the A;R A-- 4<&RI4S addition"
In$r& $&%&+n&
I<S4R& statement inserts a sing!e record into the data$ase ta$!e"
Synta@
&a$!es* sIight"
SIightDcarrid Q R-E:"
SIightDconnid Q R234:"
Insert sIight"
&a$!e sIight is inserted (ith the record" &he S5ZS,+R. is returned for this statement"
If the entry a!ready e@ists then the S5ZS,+R. is set to nonDFero a!ue and you can do
processing for e@isting record $y giing some error message"
U)'%& $&%&+n&
Page 52 of 62
ABAP BASICS
&o update data$ase ta$!e ,P=A&4 statement is used" &his a!!o(s you to change either
a sing!e record or seera! records"
5ou can use ,P=A&4 (hen you %no( (hich record you (ant to change" +ut if you do
not %no( (hether the primary %ey of the !ine you (ant to insert a!ready e@ists or not,
you can use the 0;=IA5 statement" &he 0;=IA5 statement changes e@isting !ines and
inserts !ines (hich do not e@ist"
SIightDcarrid Q R0<:"
SIightDconnid Q R454:"
,P=A&4 SA-I7E& (here .ARRI= Q R-E:"
;r
&A+-4S SA-I7E&"
,P=A&4 SA-I7E& S4& PRI.4 Q 11>>
2E4R4 .ARRI= Q R-E:"
Eere price of sIight (i!! get updated (ith ne( price 11>>"
4l& $&%&+n&
&o de!ete records from a data$ase ta$!e, you use the =4-4&4 statement"
=4-4&4 AR;0 SA-I7E& 2E4R4 .ARRI= Q R-E: A<= .;<<I= Q R454:"
2i!! de!ete the sing!e record (here conditions are met from SA-I7E&"
5ou can de!ete the mu!tip!e records from data$ase ta$!e $y putting a!! the records,
(hich you (ant to de!ete in interna! ta$!e" Aor e@amp!e
=4-4&4 SA-I7E& AR;0 &A+-4 I&A+"
In this case (hateer you hae in interna! ta$!e (i!! $e de!eted from SA-IE&"
<ote* append interna! ta$!e (ith a!! the entries, (hich you (ant to de!ete"
Page 53 of 62
ABAP BASICS
EDERCISES
SIMPLE WRITE STATEMENTS
1 2rite a program, (hich generates the mode! !ist as sho(n
,se these system 1e!ds in your program"
S5D=A&,0, S5D,U4I&, S5D,<A04
0aintain the !ist headings
12/12/89 AIRS& PR;7RA0
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
&his !ist is generated
on* 12/12/1889
at* 13*4>*35
$y* A+AP 1
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
2 .reate a !ist as sho(n
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
M5U .o" Pt" -td"
=ate* &oday:s date Page <o" 1
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
Program name* U=40;
Page 54 of 62
ABAP BASICS
SYMBOLS? ICONS AN4 FORMATTING
1 2rite a program to sho( the fo!!o(ing using system aria$!es
Khint* use inc!ude Ssym$o!T and inc!ude SiconT
Sym$o!s* Icons*
&e!ephone .hec%edH o%ay,
Aa@ machine =e!ete,
Eand pointing !eft,Print
Eand pointing right,
.aution,
4g * 2rite symZphone as sym$o!, Rte!ephone:"
2 2rite a program to sho( a string (ith diGerent $ac%ground co!ours"
eg"
(rite RE4A=4R: co!or co!Zheading"
Kco!Zheading is a$ap/4 name for grayish $!ue co!our" ;ther co!ours are
co!Z%ey for $!uish green, co!Znorma! for $right gray, co!Z$ac%ground for
gray, co!Zpositie for green, co!Znegatie for red, co!Zgroup for io!et and
co!Ztota! for ye!!o(L
3 ,se Aormat intensi1ed 3 format intensi1ed oG"
Aormat co!or Sco!orZnameT D format co!or oG"
Aormat inerse 3 Aormat inerse oG
4 Sho( current time and today:s date"
5 Sho( a a!ue R123456: as 12*34*56 using Rusing edit mas%:"
6 &a%e a num$er as R>>>>>11:" Suppress a!! !eading Feros"
9 Suppress a sign $efore a num$er"
Page 55 of 62
ABAP BASICS
GENERAL PROBLEMS
1 .reate an adding machine for num$ers"
&he t(o a!ues to $e added must $e entered on the se!ection screen as
parameters" ;utput the resu!t"
2 .reate the diiding machine for num$ers"
&he t(o a!ues must $e entered on the se!ection screen as parameters"
;utput the resu!t"
3 .reate your output as sho(n $e!o("
@
@ @
@ @ @
@ @ @ @
@ @ @ @ @
4 2rite a program to accept the t(o num$ers from the user and s(ap the a!ues"
5 =ec!are a string Recho: and design your output
e
e c
e c h
e c h o
e c h
e c
e
Page 56 of 62
ABAP BASICS
4OCEN44O? IFCELSEIFCELSECEN4IF? CASECEN4CASE
1 2rite a program (ith =o 3 4nddo !oop"
=isp!ay s/uares of num$ers 1 to 1>
1 1
2 4
3 8
2 2rite a program to accept a num$er Ksay 2L from user and create a mu!tip!ication
ta$!e"
2 @ 1 Q 2
2 @ 2 Q 4
YYYY
2 @ 1> Q 2>
3 Accept a num$er from user and 1nd Aactoria! of the same" If the num$er is
negatie then disp!ay some message"
4 2rite a program (ith =o 3 4nddo !oop for 1rst 2> num$ers"
D ;utput shou!d contain on!y 4en num$er
D ;dd num$ers shou!d not $e disp!ayed
5 Accept num$ers and choice R4)4<: or R;==: from the user and disp!ay the
num$ers in that range according to user:s choice"
6 2rite a program (ith =o 3 4nddo !oop for 1rst 2> num$ers"
D ;dd num$ers # 4en num$ers shou!d $e disp!ayed (ith a!ternate intensities"
K,se Aormat intensi1ed 3 on 3 oGL
9 .reate a ca!cu!ator, (hich performs the four $asic types of ca!cu!ations on t(o
(ho!e num$ers" &he t(o a!ues and the option are to $e entered on the se!ection
screen as parameters" ;utput the resu!t (ith 2 decima! p!aces"
J 2rite separate programs using R.;<&I<,4: and R4MI&: statements in =;D-;;P"
Page 59 of 62
ABAP BASICS
STRING OPERATIONS
1 Accept a string and determine its !ength
2 Accept a string # num$er" 2rite the string that many num$er of times"
3 Accept t(o strings and s(ap their contents"
4 Accept t(o strings and concatenate into one string"
5 Accept one string (ith de!imiter K , or H L and sp!it it into t(o strings"
6 Accept a string Ra$cdef: and use shift SstringT, shift SstringT right, shift SstringT
up to Rdef:"
9 Accept a string eg" App!e" .hange 1rst occurrence of Rp: to R$:"
Kuse Rrep!ace: commandL
J Accept a string eg" App!e" .hange a!! occurrences of Rp: to R$:"
Kuse Rtrans!ate: commandL
8 Accept t(o strings and compare the t(o strings using Rco:, Rca:, Rcs:
Rcp: Kout put sha!! $e Rtrue: or Rfa!se: for each comparison"L
1> Accept a string RA+.=4A:" ;utput on!y R=4A: using oGset command"
11 Accept 1rst name, !ast name and midd!e name
eg" <andamuri &ara%a Ramarao
disp!ay as <"&"Ramarao
12 Accept a string" .hange a!! occurrences of a to $"
13 Accept a num$er and s(ap 1rst and !ast digit of the same"
14 Accept a string and disp!ay the string in reerse order
15 Accept a string and chec% for pa!indrome
Page 5J of 62
ABAP BASICS
4ATE PROBLEMS
1 Accept a date ear!ier to today:s date and 1nd the diGerence in num$er of days"
2 Accept a date from user and disp!ay 1rst day of the month and !ast day of the
preious month"
3 Accept a date from user and add si@ months to the date"
4 Accept a date from user and conert month part to R'an:, Rfe$: etc", and disp!ay this
date"
5 2rite a program to accept month" =isp!ay num$er of days in tota! month"
0a%e use of
D &e@t e!ement for your se!ection screen $o@"
D Se!ection te@t
6 Accept $irth date from user and output age in years, months and days"
Page 58 of 62
ABAP BASICS
CHECK BODES AN4 RA4IO BUTTONS
1 2rite a program (ith
D Parameter as chec%$o@es
D If chec%$o@ 1 is c!ic%ed (rite c"$ 1 c!ic%ed e!se c"$ 1 not c!ic%ed"
D If chec%$o@ 2 is c!ic%ed (rite c"$ 2 c!ic%ed e!se c"$ 2 not c!ic%ed"
D If chec%$o@es 1 # 2 are c!ic%ed (rite c"$ 1 # c"$" 2 are c!ic%ed"
D If chec%$o@es 1 # 2 are not c!ic%ed (rite c"$ 1 # c"$" 2 are not c!ic%ed"
2 2rite a program (ith
D Parameters as t(o groups of Radio$uttons Kt(o Radio$uttons in each groupL"
D 7ie detai!ed coding as a$oe, to sho( the Radio$uttons and groups
D se!ected
3 2rite a program (ith
D Parameter as chec%$o@"
D If you c!ic% the chec%$o@ then disp!ay 1rst day of the ne@t year"
D If the chec%$o@ is not c!ic%ed then disp!ay !ast day of the current year"
4" 2rite a program (ith
D Parameter as group of 3 radio $uttons
D If 1rst radio $utton is c!ic%ed, disp!ay !ast day of the current month"
D If second radio $utton, disp!ay 1rst day of the ne@t month
D If third radio $utton, disp!ay date after si@ months"
Page 6> of 62
ABAP BASICS
SELECT STATEMENTS
1 -ist a!! the ro(s from the ta$!e )+A6"
2 -ist sing!e ro( from the ta$!e +6PA"
3 -ist up to 5 ro(s from the ta$!e +SIS"
4 -ist a!! 4R=A&s" Aor $etter reada$i!ity create a co!umn heading in the !ist
5 =isp!ay tota! amount for carrid R-E:" K&a$!es* SA-I7E&L
6 -ist a!! the Iights for (hich $oo%ing date is greater than :>1">6"1885:"
9 -ist a!! the Iights for (hich payments currency is R=40:"
J -ist a!! the Iights (here carrid is $et(een R-E: and RSN:"
8 Se!ect a sing!e record (here carrid Q R-E:, IightDno Q R>4>>: and
Idate Q :2J">2"188J:"
1> =isp!ay carrid, connid, Idate and !uggage (eight mu!tip!ied $y 2
11 -ist the ma@imum capacity, occupied seats and tota! of current $oo%ings for each
Iight in the fo!!o(ing format"
.arrier
id
0a@" capacity ;ccupied
seats
&ota! of current
$oo%ings
12 Arom the gien fromDcity and toDcity, !ist a!! the aai!a$!e on this route*
Arom* SfromDcityT &o* StoDcityT Ksay from Aran%furt to 0adrasL
K&a$!es* SPA-1L
.arrier
id
=eparture
&ime
Start Airport =estination Airport
Page 61 of 62
ABAP BASICS
OPEN SHL
1 Accept document no" from user and disp!ay particu!ars of Sa!es document"
K=efau!t document no" R>>1>>>>>31:L
K&a$!e* )+APL
.reated on* @@@@@
.reated $y* @@@@@
&ime* @@@@@
2 Accept Sa!es =ocument num$er from user and disp!ay corresponding materia!
no, description of that materia! and item category K&a$!e * )+APL
3 Accept materia! no" # item category $y defau!t PP1>> and 60< respectie!y
=isp!ay corresponding detai!s of sa!es document K&a$!e* )+APL
4 =isp!ay 1e!ds from +6PA"
=ocument type Q RA+: and
=ocument date Q :>5">2"188J:"
A!so disp!ay num$er of records se!ected"
5 =isp!ay .o" code, doc"no", acc"type, ta@ code"
0a%e use of se!ectDoptions to gie range of document type"
=isp!ay tit!e of your program at the end of program
6 Accept doc" no from user"
=isp!ay doc"no", doc"status, date of doc", doc"type"
9 =isp!ay sing!e record for document (here date Q :>5">2"188J:, type RQ RA+ and
document
no" Q R>1>>>>>>>6:"
J Accept p!ant from user eg" P-&P"
=isp!ay document detai!s for that p!ant !i%e doc"no", doc"status, date of document
etc",
Page 62 of 62

Anda mungkin juga menyukai