Вы находитесь на странице: 1из 274

BEGINNERS GUIDE

TO SAP ABAP

AN INTRODUCTION TO PROGRAMMING SAP
APPLICATIONS USING ABAP


PETER MOXON



PUBLISHED BY:
SAPPROUK Limited
Copyright 2012 by Peter Moxon. All rights reserved.
http://www.saptraininghq.com


Copyright, Legal Notice and Disclaimer:
All rights reserved.
No part of this publication may be copied, reproduced in any format, by any means,
electronic or otherwise, without prior consent from the copyright owner and
publisher of this book.
This publication is protected under the US Copyright Act of 1976 and all other
applicable international, federal, state and local laws, and all rights are reserved,
including resale rights: you are not allowed to give or sell this Guide to anyone else.
If you received this publication from anyone other than saptraininghq.com, you've
received a pirated copy. Please contact us via e-mail at support at saptraininghq.com
and notify us of the situation.

Although the author and publisher have made every reasonable attempt to achieve
complete accuracy of the content in this Guide, they assume no responsibility for
errors or omissions. Also, you should use this information as you see fit, and at your
own risk. Your particular situation may not be exactly suited to the examples
illustrated here; in fact, it's likely that they won't be the same, and you should adjust
your use of the information and recommendations accordingly.

This book is not affiliated with, sponsored by, or approved by SAP AG. Any
trademarks, service marks, product names or named features are assumed to be the
property of their respective owners, and are used only for reference. There is no
implied endorsement if we use one of these terms.
____________________________________________


iv
!"#$% '( )'*+%*+,
Contact the Author 12
Introduction 13
How to Use This Book 14
Chapter 1: SAP System Overview 15
SAP System Architecture 15
Environment for Programs 18
Work rocesses 19
1he ulspaLcher 19
1he uaLabase lnLerface 20
First look at the ABAP Workbench 22
First Look 23
A8A ulcLlonary 27
A8A LdlLor 27
luncLlon 8ullder 27
Menu alnLer 28
Screen alnLer 28
Cb[ecL navlgaLor 28
Chapter 2: Data Dictionary 29
Introduction 29
Creating a Table 29
CreaLlng llelds 33
uaLa LlemenLs 34
uaLa uomalns 36
Technical Settings 45
Entering Records into a Table 48

v
Viewing the Data in a Table 51
Chapter 3 55
Creating a Program 55
Code Editor 57
Write Statements 62
CuLpuL lndlvldual llelds 71
Chaining Statements Together 72
Copy Your Program 73
Declaring Variables 75
Constants 78
Chapter 4 79
Arithmetic Addition 79
Arithmetic Subtraction 80
Arithmetic Division 81
Arithmetic Multiplication 81
Conversion Rules 82
Division Variations 83
1he sLandard form of dlvlslon. 83
1he lnLeger form of dlvlslon. 83
1he remalnder form of dlvlslon. 84
Chapter 5 Character Strings 85
Declaring C and N Fields 85
uaLa Lype C. 83
uaLa Lype n. 86
String Manipulation 87
Concatenate 87

vi
Condense 88
nC-CAS 89
Find the Length of a String 89
Replace 90
Search 90
SLA8CP Lxample 1 91
SLA8CP Lxample 2 91
SLA8CP Lxample 3 92
SLA8CP Lxample 4 92
Shift 93
Split 94
SubFields 96
Chapter 6 Debugging Programs 98
Fields mode 102
System Variables 103
Table Mode 103
Breakpoints 105
Static Breakpoints 107
Watchpoints 108
Ending a Debug Session 111
Chapter 7: Working with Database Tables 113
Making a Copy of a Table 113
Add New Fields 116
Foreign Keys 117
Append Structures 122
Include Structures 124

vii
Key Fields 127
Deleting Fields 130
Deleting Tables 133
Chapter 8 Working with Other Data Types 136
Date and Time Fields 136
Date Fields in Calculations 138
Time Fields in Calculations 141
Quantity and Currency Fields in Calculations 142
Chapter 9 Modifying Data in a Database Table 146
Authorisations 146
Fundamentals 146
Database Lock Objects 148
Using Open SQL Statements 149
Using Open SQL Statements 5 Statements 150
Insert Statement 151
Clear Statement 155
Update Statement 157
Modify Statement 158
Delete Statement 160
Chapter 10 Program Flow Control and Logical Expressions 164
Control Structures 164
If Statement 164
Linking Logical Expressions Together 169
Nested If Statements 169
Case Statement 170
Select Loops 171

viii
Do Loops 172
Nested Do Loops 175
While Loops 178
Nested While Loops 179
Loop Termination CONTINUE 180
Loop Termination CHECK 181
Loop Termination EXIT 182
Chapter 11 Selection Screens 184
Events 184
Intro to Selection Screens 185
Creating Selection Screens 186
At Selection Screen 187
Parameters 188
uLlAuL1 189
C8LlCA1C8? 190
AuLomaLlc CeneraLlon of urop-uown flelds 190
LCWL8 CASL 191
Check Boxes and Radio Button Parameters 192
Select-Options 193
Select-Option Example 196
Select-Option Additions 200
Text Elements 200
Variants 203
Text Symbols 209
Text Messages 211
Skip Lines and Underline 216

ix
Comments 218
Format a Line and Position 219
Element Blocks 221
Chapter 12 Internal Tables 223
Introduction 223
Types of Internal Tables 224
SLandard 1ables 224
SorLed 1ables 223
Pashed 1able 223
Internal Tables - Best Practice Guidelines 225
Creating Standard and Sorted Tables 226
Create an Internal Table with Separate Work Area 227
Filling an Internal Table with Header Line 228
Move-Corresponding 232
Filling Internal Tables with a Work Area 234
Using Internal Tables One Line at a Time 235
Modify 236
Describe and Insert 236
Read 238
Delete Records 239
Sort Records 240
Work Area Differences 241
Loops 241
Modlfy 242
lnserL 242
8ead 242

x
ueleLe 242
Delete a Table with a Header Line 243
CLLA8 243
8Ll8LSP 243
l8LL 243
Delete a Table with a Work Area 244
Chapter 13 Modularizing Programs 245
Introduction 245
Includes 246
Procedures 249
Sub-Routines 250
asslng 1ables 234
asslng 1ables and llelds 1ogeLher 233
Sub-Routines - External Programs 256
Function Modules 257
Function Modules Components 258
ALLrlbuLes 1ab 262
lmporL 1ab 262
LxporL 1ab 263
Changlng 1ab 263
1ables 1ab 263
LxcepLlons 1ab 263
Source Code 1ab 264
Function Module Testing 264
Function Modules - Coding 267


xi



12
Contact the Author

As the reader of this book you are my most important critic and commentator. I
would love to hear from you to let me know what you did and did not like about this
book, as well as to what you think I could do in future books to make them stronger.
E-mail: pete@sappro.co.uk
Please note that although I cannot personally help you learn SAP ABAP, I am
available for corporate hire for project management, technical lead and mentoring
programs.

Refer to my website http://www.saptraininghq.com to see all the training material I
have available and to get a good overview of my expertise.



13
INTRODUCTION
Introduct|on
1hls book has been wrlLLen wlLh SA Super-user and ConsulLanLs ln mlnd. WheLher your
currenL [ob LlLle ls funcLlonal consulLanL, sysLem supporL analysL, buslness consulLanL,
pro[ecL manager for someLhlng enLlrely dlfferenL, lf you are responslble for all have an
lnLeresL ln creaLlng A8A programs, Lhen Lhls book ls for you.
Much of Lhe book ls wrlLLen ln Lhe "!"#$%"" sLyle and wlll allow anybody Lo follow along
and creaLe A8A programs from scraLch. lL ls wrlLLen ln such a way LhaL each chapLer
bullds on Lhe lasL so LhaL you become famlllar ln loLs of dlfferenL aspecLs of SA A8A
programmlng Lo enable you Lo Lhen sLarL creaLlng your own programs and undersLand
programs you wlll flnd ln your own SA sysLem.
1he prlnclples and guldellnes apply across all SA modules wheLher you're wrlLlng
programs for P8, ll, Su or one of Lhe many oLher modules wlLhln SA.
Cver my years of worklng wlLh SA sysLems l have had Lhe greaL pleasure of worklng wlLh
some Lop-noLch funcLlonal and Lechnlcal consulLanLs who know how Lo documenL, plan
and develop SA programs of all Lypes. Llkewlse l have had Lhe unpleasanL experlence of
worklng wlLh lower quallLy consulLanLs, who elLher race Lhrough or sLumble and sLuLLer
Lhrough Lhelr SA work copylng and pasLlng from one program or anoLher resulLlng ln
dlfflculL Lo supporL programs. 1hls ulLlmaLely ofLen resulLs ln pro[ecL delays and cosL
overruns.
1he alm of Lhls book ls Lo help you undersLand how SA A8A programs are puL LogeLher
and developed so LhaL you wlll produce deLalled conclse undersLandable and funcLlonal
programs LhaL correspond wlLh your speclflcaLlons and mosL lmporLanLly dellvered on
Llme and on budgeL.

14
INTRODUCTION
now to Use 1h|s 8ook
1here are several ways Lo go Lhrough Lhls book and Lhe besL way depends on your
slLuaLlon.
lf you are new Lo wrlLlng SA programs Lhen l suggesL sLarLlng aL Lhe very beglnnlng and
worklng Lhrough each chapLer one afLer anoLher.
lf you are famlllar wlLh some SA A8A programmlng Lhen you may wanL Lo use Lhe Lable
of conLenLs and [ump Lo Lhe chapLer LhaL lnLeresLs you, buL remember each chapLer bullds
on Lhe prevlous chapLer so some of Lhe examples shown do requlre you Lo have
knowledge of Lhe daLabase Lables we creaLe ln Lhls book.

15
SAP SYSTEM OVERVIEW
Chapter 1: SA System Cverv|ew
We wlll sLarL ouL by coverlng Lhe hlgh-level archlLecLure of an SA sysLem, lncludlng Lhe
Lechnlcal archlLecLure and plaLform lndependence. We wlll dlg lnLo Lhe envlronmenL LhaL
our A8A programs run ln, whlch lnclude Lhe work processes and Lhe baslc sLrucLures of
an A8A program. 1hen we can focus on a runnlng SA sysLem, dlscuss Lhe buslness
model overvlew, and begln looklng aL Lhe A8A workbench.
SA System Arch|tecture
llrsL, Lhe 1echnlcal ArchlLecLure of a Lyplcal SA sysLem wlll be dlscussed, before movlng
on Lo Lhe Landscape ArchlLecLure, and a dlscusslon of why Lhe landscape should be broken
lnLo mulLlple sysLems.
1hls dlagram shows Lhe 3-Ller CllenL/Server archlLecLure of a Lyplcal SA sysLem:



16
SAP SYSTEM OVERVIEW
AL Lhe Lop ls Lhe resenLaLlon server, whlch ls any lnpuL devlce LhaL can be used Lo conLrol
an SA sysLem (Lhe dlagram shows Lhe SA Cul, buL Lhls could equally be a web browser,
a moblle devlce, and so on). 1he resenLaLlon layer communlcaLes wlLh Lhe AppllcaLlon
server, and Lhe AppllcaLlon server ls Lhe 'bralns' of an SA sysLem, where all Lhe cenLral
processlng Lakes place. 1he AppllcaLlon server ls noL [usL one sysLem ln lLself, buL can be
made up of mulLlple lnsLances of Lhe processlng sysLem. 1he AppllcaLlon server, ln Lurn,
communlcaLes wlLh Lhe uaLabase layer.
1he uaLabase ls kepL on a separaLe server, malnly for performance reasons, buL also for
securlLy, provldlng a separaLlon beLween Lhe dlfferenL layers of Lhe sysLem.
CommunlcaLlon happens beLween each layer of Lhe sysLem, from Lhe resenLaLlon layer,
Lo Lhe AppllcaLlon server, Lo Lhe uaLabase, and Lhen back up Lhe chaln, Lhrough Lhe
AppllcaLlon server agaln, for furLher processlng, unLll flnally reachlng Lhe resenLaLlon
layer.

A Lyplcal Landscape ArchlLecLure - 1yplcal here ls sub[ecLlve, ln pracLlcal Lerms Lhere ls noL
really any such Lhlng as a sLandard, 'Lyplcal' landscape archlLecLure whlch mosL companles

17
SAP SYSTEM OVERVIEW
use. Powever, lL ls common Lo flnd a uevelopmenL sysLem, a 1esLlng sysLem and a
roducLlon sysLem:

1he reason for Lhls ls falrly slmple. All Lhe lnlLlal developmenL and LesLlng ls done on a
uevelopmenL sysLem, whlch ensures oLher sysLems are noL affecLed. Cnce developmenLs
are aL a sLage where Lhey may be ready Lo be LesLed by an exLernal source, or someone
wlLhln Lhe company whose role ls Lo carry ouL LesLlng, Lhe developmenLs are moved, uslng
whaL ls called a 1ransporL SysLem, Lo Lhe nexL sysLem (here, Lhe 1esLlng sysLem).
normally, no developmenL aL all ls done on Lhe LesLlng sysLem, lL ls [usL used for LesLlng
Lhe developmenLs from Lhe developmenL sysLem. lf everyLhlng passes Lhrough Lhe 1esLlng
sysLem, a 1ransporL sysLem ls used agaln Lo move Lhe developmenLs lnLo Lhe roducLlon
envlronmenL. When code enLers Lhe roducLlon envlronmenL, Lhls ls Lhe sLage aL whlch lL
ls Lurned on, and used wlLhln Lhe buslness lLself.
1he landscape archlLecLure ls noL separaLed [usL for developmenL purposes, Lhe company
may have oLher reasons. 1hls could be Lhe quanLlLy of daLa ln Lhe roducLlon sysLem,
whlch may be Loo greaL Lo be used ln Lhe developmenL envlronmenL (normally Lhe
uevelopmenL and 1esLlng sysLems are noL as large as Lhe roducLlon sysLem, only needlng
a subseL of daLa Lo LesL on). Also, lL could be for securlLy reasons. More ofLen Lhan noL,
companles do noL wanL developers Lo see llve producLlon daLa, for daLa securlLy reasons
(for example, Lhe sysLem could lnclude employee daLa or sales daLa, whlch a company
would noL wanL people noL employed ln Lhose areas Lo see). normally, Lhen, Lhe
uevelopmenL and 1esLlng sysLems would have Lhelr own seL of daLa Lo work wlLh.
1he Lhree sysLems descrlbed here, normally, are a mlnlmum. lL can lncrease Lo four
sysLems, perhaps wlLh Lhe addlLlon of a 1ralnlng sysLem, or perhaps mulLlple pro[ecLs are
runnlng slmulLaneously, meanlng Lhere may be Lwo separaLe uevelopmenL sysLems, or
1esLlng sysLems, even perhaps a ConsolldaLlon sysLem before anyLhlng ls passed Lo Lhe
roducLlon envlronmenL. 1hls ls all, of course, dependenL on Lhe company, buL commonly
each sysLem wlLhln Lhe Landscape archlLecLure wlll have lLs own AppllcaLlon server and lLs
own uaLabase server, ensurlng plaLform lndependence.


18
SAP SYSTEM OVERVIEW
Lnv|ronment for rograms

nexL, we have Lhe envlronmenL whlch programs run ln, Lhe Work rocesses, and Lhe
sLrucLure of an A8A program.

WlLhln an SA sysLem, or aL leasL Lhe example used here, Lhere are Lwo Lypes of programs,
8eporLs and Dynpros.
8eporLs, as Lhe name would suggesL, are programs whlch generaLe llsLs of daLa. 1hey may
lnvolve a small amounL of lnLeracLlvlLy, buL malnly Lhey supply daLa Lo Lhe fronL-end
lnLerfaces, Lhe SA Cul and so on. When a user runs a reporL, Lhey Lyplcally geL a selecLlon
screen. Cnce Lhey enLer Lhelr selecLlon parameLers and execuLe Lhe reporL, Lhey normally
cannoL lnLervene ln Lhe execuLlon of Lhe program. 1he program runs, and Lhen dlsplays
Lhe ouLpuL.
Dynpros are sllghLly dlfferenL. 1hey are dynamlc programs, and allow Lhe user Lo
lnLervene ln Lhe execuLlon of Lhe program, by processlng a serles of screens, called

19
SAP SYSTEM OVERVIEW
ulalogue screens. 1he user deLermlnes Lhe flow of Lhe program lLself by chooslng whlch
buLLons or flelds Lo lnLeracL wlLh on Lhe screen. 1helr acLlon Lhen Lrlggers dlfferenL
funcLlons whlch have been coded wlLhln Lhe flow loglc of Lhe program. Whlle reporLs are
belng creaLed, lnLerfaces are also Lo be generaLed whlch are classed as uynpros, for all
Lhe selecLlon crlLerla.
MosL of Lhe work done by people lnvolved wlLh A8A ls done wlLhln 8eporL programs, and
even Lhough Lhese programs are labelled '8eporLs', Lhey do noL always generaLe ouLpuL.
1he 8eporL programs are Lhere Lo process Lhe loglc, readlng and wrlLlng Lo Lhe uaLabase,
ln order Lo make Lhe sysLem work.
-'./ 0.'1%,,%,
Lvery program LhaL runs ln an SA sysLem runs on whaL are called Work rocesses, whlch
run on Lhe AppllcaLlon server. Work rocesses Lhemselves work lndependenLly of Lhe
compuLer's operaLlng sysLem and Lhe uaLabase LhaL lL lnLeracLs wlLh, glvlng Lhe
lndependence dlscussed earller wlLh regard Lo Lhe 1echnlcal archlLecLure. When an SA
sysLem ls lnlLlally seL up, Lhe basls consulLanLs (who lnsLall Lhe sysLem, keep lL runnlng,
manage all Lhe memory and so on) conflgure SA ln such a way LhaL lL auLomaLlcally seLs
Lhe number of Work rocesses programs use when Lhey sLarL, Lhe equlvalenL of seLLlng up
a pre-deflned number of channels or connecLlons Lo Lhe uaLabase sysLem lLself, each of
whlch Lend Lo have Lhelr own seL of properLles and funcLlons.
!2% 34,5"+12%.
?ou mlghL come across someLhlng referred Lo as Lhe ulspaLcher. 1he SA sysLem has no
Lechnlcal llmlLs as Lo Lhe number of users who can log on and use lL, generally Lhe number
of users who can access an SA sysLem ls much larger Lhan Lhe number of avallable Work
rocesses Lhe sysLem ls conflgured for. 1hls ls because noL everybody ls sendlng
lnsLrucLlons Lo Lhe AppllcaLlon server aL exacLly Lhe same Llme. 8ecause of Lhls, users
cannoL be asslgned a cerLaln number of processes whlle Lhey are logged on.
1he ulspaLcher conLrols Lhe dlsLrlbuLlon of Lhe Work rocesses Lo Lhe sysLem users. 1he
ulspaLcher keeps an eye on how many Work rocesses are avallable, and when a user
Lrlggers a LransacLlon, Lhe ulspaLcher's [ob ls Lo provlde LhaL user wlLh a Work rocess Lo
use. 1he ulspaLcher Lrles Lo opLlmlse Lhlngs as far as posslble, so LhaL Lhe same Work
rocess recelves Lhe sequenLlal ulalogue sLeps of an appllcaLlon. lf Lhls ls noL posslble, for
example because Lhe user Lakes a long Llme beLween cllcklng dlfferenL aspecLs of Lhe

20
SAP SYSTEM OVERVIEW
screen, lL wlll Lhen selecL a dlfferenL Work rocess Lo conLlnue Lhe processlng of Lhe
ulalogue program. lL ls Lhe Work rocess whlch execuLes an appllcaLlon, and lL ls Lhe Work
rocess whlch has access Lo Lhe memory areas LhaL conLaln all of Lhe daLa and ob[ecLs an
appllcaLlon uses. lL also makes Lhree very lmporLanL elemenLs avallable.
1he flrsL ls Lhe uynpro processor. All uynpro programs have flow and processlng loglc, and
lL ls Lhe uynpro processor's [ob Lo handle Lhe flow loglc. lL responds Lo Lhe user's
lnLeracLlons, and conLrols Lhe furLher flow of Lhe program dependlng on Lhese
lnLeracLlons. lL ls responslble for ulalogue conLrol and Lhe screen lLself, buL lL ls lmporLanL
Lo remember LhaL lL cannoL perform calculaLlons, lL ls purely Lhere Lo manage Lhe flow
loglc of a program.
1he nexL lmporLanL elemenL ls Lhe A8A processor, whlch ls responslble for Lhe processlng
loglc of Lhe programs. lL recelves screen enLrles from Lhe uynpro processor, and LransmlLs
Lhe screen ouLpuL Lo Lhe program. lL ls Lhe A8A processor whlch can perform Lhe loglcal
operaLlons and arlLhmeLlcal calculaLlons ln Lhe programs. lL can check auLhorlsaLlons, and
read and wrlLe Lo Lhe uaLabase, over Lhe uaLabase lnLerface.
!2% 3"+"#",% 6*+%.("1%
1he uaLabase lnLerface ls Lhe Lhlrd lmporLanL elemenL. lL ls a seL of A8A sLaLemenLs LhaL
are uaLabase lndependenL. WhaL Lhls means ls LhaL a seL of A8A sLaLemenLs can be used
LhaL, ln Lurn, can communlcaLe wlLh any Lype of uaLabase LhaL has been lnsLalled when
Lhe sysLem was seL up. WheLher Lhls ls, for example, a MlcrosofL SCL server or an Cracle
uaLabase, you can use Lhe same A8A sLaLemenLs, called Cpen SCL, Lo conLrol Lhe enLlre
uaLabase readlng and wrlLlng over Lhe uaLabase lnLerface. 1he greaL advanLage of Lhls ls
LhaL Lhe A8A sLaLemenLs have encapsulaLlon, meanlng Lhe programmers do noL need Lo
know whlch physlcal uaLabase sysLem Lhe A8A sysLem Lhey are uslng acLually supporLs.
1here are Llmes when you may wanL Lo use a speclflc SCL sLaLemenL naLlve Lo Lhe
daLabase whlch ls lnsLalled. A8A ls deslgned ln such a way LhaL lf Lhls Lype of codlng ls
necessary, Lhls faclllLy ls avallable. lL ls posslble Lo dlrecLly access Lhe uaLabase Lhrough
Lhe programs uslng naLlve SCL sLaLemenLs, buL Lhls ls noL encouraged. normally, when
sysLems are seL up, Lhe sysLem admlnlsLraLor wlll forbld Lhese pracLlces, due Lo Lhe
securlLy and sLablllLy rlsks Lo Lhe sysLem whlch may be lnLroduced. lf you are golng Lo be
programmlng A8A, make sure Cpen SCL ls used, because Lhen anyone subsequenLly
looklng aL Lhe programs wlll undersLand whaL ls Lrylng Lo be achleved.

21
SAP SYSTEM OVERVIEW


22
SAP SYSTEM OVERVIEW
I|rst |ook at the A8A Workbench
lL ls now Llme Lo Lake a flrsL look aL an SA A8A program. 1he followlng secLlon wlll look
aL Lhe SA SysLem and lnLroduce Lhe A8A Workbench. 8uL before dolng so, leL's Lake a
look aL Lhe sLrucLure of an A8A program.

Llke many oLher programmlng languages, A8A programs are normally sLrucLured lnLo
Lwo parLs.

1he flrsL ls whaL ls consldered Lo be Lhe ueclaraLlon secLlon. 1hls ls where you deflne Lhe
daLa Lypes, sLrucLures, Lables, work area varlables and Lhe lndlvldual flelds Lo be used
lnslde Lhe programs. 1hls ls also where you would declare global varlables LhaL wlll be
avallable LhroughouL Lhe lndlvldual subsecLlons of Lhe program. When creaLlng an A8A
program, you do noL only declare global varlables, buL you also have Lhe opLlon Lo declare

23
SAP SYSTEM OVERVIEW
varlables LhaL are only valld wlLhln speclflc secLlons lnslde Lhe programs. 1hese secLlons
are commonly referred Lo as lnLernal rocesslng 8locks.
1he ueclaraLlon parL of Lhe program ls where you deflne Lhe parameLers used for Lhe
selecLlon screens for Lhe reporLs. Cnce you have declared Lables, global varlables and daLa
Lypes ln Lhe ueclaraLlon secLlon of Lhe program, Lhen comes Lhe second parL of Lhe A8A
program, where all of Lhe loglc for Lhe program wlll be wrlLLen. 1hls parL of an A8A
program ls ofLen spllL up lnLo whaL are called rocesslng 8locks.
1he rocesslng 8locks deflned wlLhln programs can be called from Lhe uynpro processor,
whlch were dlscussed prevlously, dependlng on Lhe speclflc rules creaLed wlLhln Lhe
program. 1hese rocesslng 8locks are almosL always [usL small secLlons of programmlng
loglc whlch allow Lhe code Lo be encapsulaLed.
I|rst Look
When logged lnLo an SA sysLem lL wlll look someLhlng slmllar Lo Lhe lmage below.

1he way Lhe SA Cul looks may vary, Lhe menu Lo Lhe slde may be dlfferenL, buL here Lhe
dlsplay show a mlnlmal menu Lree whlch wlll be used LhroughouL Lhls book.
1he flrsL Lhlng Lo do here ls look aL Lhe A8A Workbench. 1o access Lhls, you use Lhe menu
on Lhe lefL hand slde. Cpen Lhe SA menu, choose 1ools and open Lhe A8A Workbench,
where Lhere wlll be four dlfferenL opLlons.

24
SAP SYSTEM OVERVIEW

1he flrsL Lhlng Lo look aL ls a qulck overvlew of how Lo run a LransacLlon ln SA. 1here are
Lwo ways Lo do Lhls. llrsLly, lf Lhe overvlew folder ls opened, any lLem whlch does noL look
llke a folder lLself, ls a LransacLlon whlch can be run. ln Lhls lnsLance, we can see Lhe Cb[ecL
navlgaLor:

uouble cllck Lhls, and Lhe LransacLlon wlll open:

25
SAP SYSTEM OVERVIEW

1o exlL ouL of Lhe LransacLlon, cllck Lhe 8ack buLLon:
1he second way of runnlng a LransacLlon ls Lo enLer Lhe LransacLlon code lnLo Lhe
LransacLlon code lnpuL area:

A useful Llp Lo become famlllar wlLh Lhe names of LransacLlons ls Lo look aL Lhe LxLras
menu --> open SeLLlngs and ln Lhe dlalogue box whlch appears, selecL Lhe opLlon 'ulsplay
Lechnlcal names' and cllck Lhe 'ConLlnue' lcon:

26
SAP SYSTEM OVERVIEW

1he menu Lree wlll be refreshed, and when Lhe 'Cvervlew' folder ls opened, Lhe
LransacLlon codes wlll be made vlslble. lL ls now posslble Lo become famlllar wlLh Lhem,
and enLer Lhem dlrecLly lnLo Lhe LransacLlon code lnpuL area:


now, a sLep-by-sLep look wlll be Laken Lhrough Lhe ma[or LransacLlons of Lhe A8A
Workbench Lo become famlllar wlLh, and use, as an A8A developer.

27
SAP SYSTEM OVERVIEW
7870 341+4'*".9
Cne Lhlng mosL programs wlll have ln common ls LhaL Lhey wlll read and wrlLe daLa Lo and
from Lhe uaLabase Lables wlLhln Lhe SA sysLem. 1he A8A Workbench has a LransacLlon
Lo allow Lhe creaLlon of uaLabase Lables, vlew Lhe flelds whlch make up Lhese Lables and
browse Lhe daLa lnslde. 1hls ls called Lhe A8A ulcLlonary. 1he A8A ulcLlonary can be
found by expandlng Lhe A8A Workbench menu Lree --> 'uevelopmenL'. 1he LransacLlon
code Lo run Lhe A8A dlcLlonary dlrecLly ls SL11:

7870 :;4+'.
1he nexL and probably mosL commonly used parL of Lhe A8A Workbench ls Lhe A8A
LdlLor, whlch much of Lhls course wlll focus upon. 1he A8A LdlLor ls where all of Lhe code
ls creaLed, Lhe loglc bullL and, by uslng forward navlgaLlon (a funcLlon wlLhln an SA
sysLem whlch wlll be dlscussed laLer), funcLlon modules deflned, screens creaLed and so
on. 1he A8A LdlLor can be found under Lhe 'uevelopmenL' menu, as shown above and
wlLh LransacLlon code SL38.
<=*1+4'* 8=4$;%.
1he nexL lmporLanL parL of Lhe Workbench ls Lhe luncLlon 8ullder, whlch ls slmllar Lo Lhe
A8A LdlLor. lLs maln funcLlon ls Lo deflne speclflc Lasks LhaL can be called from any oLher
program. lnLerfaces are creaLed ln Lhe luncLlon 8ullder, where Lhe dlfferenL daLa
elemenLs and dlfferenL Lypes of Lables are deflned, LhaL can be passed Lo and from Lhe
luncLlon whlch ls bullL. 1he luncLlon 8ullder wlll be dlscussed a llLLle laLer on, when Lhe
programs creaLed are encapsulaLed lnLo funcLlon modules. 1he luncLlon 8ullder can be

28
SAP SYSTEM OVERVIEW
called wlLh LransacLlon code SL37.
>%*= 0"4*+%.
1he nexL lLem Lo look aL here ls called Lhe Menu alnLer, whlch can be found ln Lhe 'user
lnLerface' folder lnslde Lhe 'uevelopmenL' menu, or wlLh LransacLlon code SL41. 1hls ls a
Lool whlch can be used Lo generaLe menu opLlons, buLLons, lcons, menu bars, LransacLlon
lnpuL flelds, all of whlch can Lrlgger evenLs wlLhln Lhe program. ?ou can deflne wheLher
evenLs are Lrlggered uslng a mouse cllck, or wlLh a keyboard-based shorLcuL. lor example,
ln Lhe Lop menu bar here, Lhe 'Log off' buLLon can be seen, whlch can be Lrlggered by uslng
(ShlfL + l3):

?1.%%* 0"4*+%.
Whlle Lhe Menu alnLer ls used for bulldlng menu lLems, menu bars and so on, Lhe nexL
lLem on Lhe llsL ls Lhe Screen alnLer, LransacLlon code SL31, whlch allows you Lo deflne
Lhe user lnpuL screen, meanlng LhaL you can deflne LexL boxes, drop-down menus, llsL
boxes, lnpuL flelds, Labbed areas of Lhe screen and so on. lL allows you Lo deflne Lhe whole
lnLerface whlch Lhe user wlll evenLually use, and behlnd Lhe lnlLlal elemenLs LhaL are puL
on Lhe screen, you can also deflne Lhe lndlvldual funcLlons whlch are called when Lhe user
lnLeracLs wlLh Lhem.
@#A%1+ B"C4D"+'.
1he lasL lLem Lo look aL here ls Lhe Cb[ecL navlgaLor, a Lool whlch brlngs LogeLher all Lhe
prevlous Lools, provldlng a hlghly efflclenL envlronmenL ln whlch Lo develop programs.
When bulldlng large programs, wlLh many funcLlon modules, many screens, Lhe Cb[ecL
navlgaLor ls Lhe ldeal Lool Lo use Lo navlgaLe around Lhe developmenL. lL can be found ln
Lhe 'Cvervlew' menu of Lhe A8A Workbench, wlLh LransacLlon code SL80.
1hese are Lhe maln feaLures of Lhe A8A Workbench lnLeracLed wlLh durlng Lhls course. ln
Lhe SA menu Lree, Lhere are evldenLly many more LransacLlons whlch can be used Lo help
develop programs, buL Lhese cover Lhe vasL ma[orlLy of developmenL Lools whlch wlll be
used.


29
DATA DICTIONARY
Chapter 2: Data D|ct|onary

Introduct|on
1hls chapLer wlll focus speclflcally on Lhe uaLa ulcLlonary. 1hls ls Lhe maln Lool used Lo
look aL, undersLand and enhance Lhe uaLabase and uaLabase Lables whlch are used by Lhe
SA sysLem. ?ou can vlew sLandard Lables dellvered by SA uslng Lhls Lool, creaLe new
Lables and enhance Lhe exlsLlng Lables dellvered by SA wlLh new flelds. 1here are many
oLher feaLures lnvolved ln Lhe uaLa ulcLlonary, buL Lhe focus here wlll be on Lhe baslc ones
so as Lo bulld on Lhls laLer on when creaLlng A8A programs.
llrsL, a daLabase Lable wlll be creaLed, lnvolvlng Lhe creaLlon of flelds, daLa elemenLs and
domalns. An explanaLlon of whaL each of Lhese ls, and why Lhey are necessary Lo Lhe
Lables bullL wlll be glven. uurlng Lhe bulldlng of Lhe Lables, Lhe Lools used Lo check for
errors wlll be shown. Cnce Lhese errors are eradlcaLed, Lhe Lables can be acLlvaLed so LhaL
Lhey can be used wlLhln Lhe sysLem.
AfLer Lhls, a look wlll be Laken aL malnLalnlng Lhe Lechnlcal seLLlngs of Lhe Lable creaLed,
whlch wlll allow Lhe enLry of daLa, before flnally looklng aL Lhe daLa whlch has been
enLered uslng sLandard SA LransacLlons avallable ln Lhe SA sysLem.
Creat|ng a 1ab|e
WlLh Lhe SA Cul open, you wlll be able flnd Lhe uaLa ulcLlonary ln Lhe SA menu Lree.
1hls ls done vla Lhe 1ools menu. Cpen Lhe A8A Workbench and cllck Lhe 'uevelopmenL'
folder, where Lhe A8A ulcLlonary can be found and double-cllcked. AlLernaLlvely, use Lhe
LransacLlon code SL11:
now, Lhe lnlLlal screen of Lhe A8A ulcLlonary wlll appear:

30
DATA DICTIONARY

1o creaLe a Lable, selecL Lhe 'uaLabase Lable' opLlon. ln Lhls exerclse a LransparenL Lable
wlll be creaLed. CLher Lypes of Lable do exlsL (such a clusLer Lables and pool Lables), buL aL
Lhls early sLage Lhe LransparenL Lable varleLy ls Lhe lmporLanL one Lo focus upon.
1he Lable name musL adhere Lo Lhe cusLomer-deflned name space, meanlng LhaL Lhe
name musL begln wlLh Lhe leLLer Z or ?, mosL commonly Lhls wlll be Z. ln Lhls example, Lhe
Lable wlll show a llsL of employees wlLhln a company, so, ln Lhe 'uaLabase Lable' area, Lype
'ZLMLC?LLS' and cllck Lhe 'CreaLe' buLLon.
Cnce Lhls ls done, a new screen wlll appear:

31
DATA DICTIONARY


ln Lhe 'ShorL LexL' fleld, a descrlpLlon for Lhe Lable musL be lncluded, enLer 'Lmployees':

ln Lhe 'uellvery and MalnLenance' Lab (whlch opens by defaulL), look aL Lhe 'uellvery class'
secLlon, selecL Lhe fleld and Lhen cllck Lhe drop-down buLLon, where a llsL of uellvery
classes wlll be shown and selecLed:

32
DATA DICTIONARY

lor Lhe Lable belng creaLed here, choose 'AppllcaLlon Lable', as Lhe daLa held ln Lhe Lable
flLs Lhe descrlpLlon 'masLer and LransacLlon daLa'.
ln Lhe fleld below Lhls, labelled 'uaLa 8rowser/1able vlew MalnL.', choose Lhe
'ulsplay/MalnLenance allowed' opLlon, whlch wlll allow for daLa enLry dlrecLly lnLo Lhe
Lable laLer on. lL should look llke Lhls:

8efore golng any furLher, cllck Lhe 'Save' buLLon:
A wlndow appears LlLled 'CreaLe Cb[ecL ulrecLory LnLry'.
nearly all developmenL work done wlLh SA ls usually done wlLhln a developmenL
envlronmenL, before belng moved on Lo, for example, a quallLy assurance envlronmenL
and on furLher Lo producLlon. 1hls wlndow allows you Lo choose Lhe approprlaLe
uevelopmenL class whlch ls supporLed by oLher sysLems where Lhe work may be moved
on Lo. ln Lhls example scenarlo, Lhough, developmenLs wlll noL be moved on Lo anoLher
sysLem, so cllck 'Loca| ob[ect', so as Lo lndlcaLe Lo Lhe sysLem (vla Lhe phrase '$1M' whlch
appears) LhaL Lhe ob[ecL ls only Lo exlsL wlLhln Lhe developmenL sysLem and noL Lo be
LransporLed elsewhere. Cnce Lhls ls done, Lhe sLaLus bar aL Lhe boLLom wlll show LhaL Lhe
ob[ecL has been saved:

33
DATA DICTIONARY

1o check everyLhlng has worked as we wanL, selecL Lhe 'Co Lo' menu and selecLs Lhe
'Cb[ecL dlrecLory enLry' opLlon, a slmllar pop-up box Lo Lhe prevlous one wlll appear,
where Lhe 'uevelopmenL class' fleld wlll show '$1M', conflrmlng Lhls has been done
correcLly.
).%"+4*D <4%$;,
1he nexL sLep ls Lo begln creaLlng lleld names for Lhe Lable, ln Lhe 'llelds' Lab:

llelds, unllke Lhe name of Lhe Lable, can begln wlLh any leLLer of Lhe alphabeL, noL [usL Z
and ? and can conLaln up Lo 16 characLers.

34
DATA DICTIONARY
1ables musL lnclude aL leasL one key fleld, whlch ls used laLer for Lhe searchlng and sorLlng
of daLa, and Lo ldenLlfy each record as belng unlque.
An lnlLlal value can be asslgned Lo each fleld, for example, ln Lhe case of a fleld called
mployee closs you could say Lhe ma[orlLy of employees are 8egular SLaff ('S'), buL some
are ulrecLors, wlLh a code of 'u'. 1he sLandard lnlLlal value would be 'S', buL Lhe user could
change some of Lhese Lo a 'u' laLer on.
3"+" :$%E%*+,
Lvery lleld ln Lhe Lable ls made up of whaL ls called a uaLa LlemenL, whlch deflnes speclflc
aLLrlbuLes of each fleld.
1he flrsL lleld Lo be creaLed here ls an lmporLanL one wlLhln an SA sysLem, and ldenLlfles
Lhe cllenL whlch Lhe records are assoclaLed wlLh. ln Lhe lleld name, enLer 'CllenL', and ln
Lhe uaLa LlemenL, Lype 'MAnu1'. 1hls uaLa LlemenL already exlsLs ln Lhe sysLem, and afLer
enLerlng lL, Lhe sysLem auLomaLlcally fllls ln Lhe uaLa 1ype, Lhe LengLh, number of
ueclmals and ShorL LexL for Lhe uaLa LlemenL lLself. Lnsure LhaL Lhe 'CllenL' fleld ls made a
key fleld ln Lhe Lable by checklng Lhe 'key' box.
1he nexL fleld wlll be called 'Lmployee'. Agaln, check Lhe box Lo make Lhls a key fleld, and
enLer Lhe new uaLa LlemenL 'ZLLnuM' (uaLa LlemenLs broadly musL adhere Lo Lhe
cusLomer name space by beglnnlng wlLh Z or ?). Cnce Lhls ls done, cllck Lhe save buLLon.
nexL, because Lhe uaLa LlemenL 'ZLLnuM' does noL yeL exlsL, lL musL be creaLed. lf you Lry
Lo acLlvaLe or even check Lhe Lable (vla Lhe 'Check' buLLon), an error message ls
dlsplayed:

unLll Lhe uaLa LlemenL 'ZLLnuM' ls creaLed, lL cannoL be used wlLhln Lhe sysLem. 1o do
Lhls, forward navlgaLlon ls used. uouble-cllck Lhe new uaLa LlemenL, and a wlndow
labelled 'CreaLe uaLa elemenL' appears. Answer '?es' Lo Lhls, and Lhe 'MalnLaln uaLa
LlemenL' wlndow comes up.

35
DATA DICTIONARY




36
DATA DICTIONARY
ln Lhe 'ShorL LexL' area, enLer 'Lmployee uaLa LlemenL'. nexL, Lhe LlemenLary daLa Lype,
called Lhe 'uomaln', musL be deflned for Lhe new uaLa elemenL. uomalns musL adhere Lo
Lhe cusLomer name space, so ln Lhls lnsLance Lhe same name as Lhe uaLa elemenL wlll be
glven: 'ZLLnuM', (Lhough glvlng boLh Lhe same name ls noL lmperaLlve). Agaln, forward
navlgaLlon wlll be used Lo creaLe Lhe uomaln.
3"+" 3'E"4*,
uouble-cllck Lhe enLry ('ZLLnuM') ln Lhe uomaln area, and agree Lo save Lhe changes
made. now, Lhe 'CreaLe Cb[ecL ulrecLory LnLry' wlndow wlll re-appear and agaln lL ls
lmporLanL Lo save Lhls developmenL Lo Lhe '$1M' developmenL class, vla Lhe 'save' or
'local ob[ecL' buLLon vlslble ln Lhls wlndow.
AfLer dolng Lhls, a wlndow wlll appear sLaLlng LhaL Lhe new uomaln 'ZLLnuM' does noL
exlsL. Choose '?es' Lo creaLe Lhe uomaln, and ln Lhe wlndow whlch appears, Lype lnLo Lhe
'ShorL LexL' box a descrlpLlon of Lhe uomaln. ln Lhls example, 'Lmployee uomaln':


37
DATA DICTIONARY
1he 'ueflnlLlon' Lab, whlch, as shown above, opens auLomaLlcally. 1he flrsL avallable fleld
here ls 'uaLa Lype', cllck lnslde Lhe box and selecL Lhe drop-down menu, and a number of
generlc daLa Lypes already exlsLlng wlLhln Lhe A8A dlcLlonary wlll appear.
1he 'nuMC' Lype ls Lhe one Lo be used here for the Employee data, a character string
with only digits. Once this selection is double-cllcked, lL wlll appear ln Lhe 'uaLa Lype' area
ln Lhe 'ueflnlLlon' Lab.
nexL, ln Lhe 'no. characLers' fleld, enLer Lhe number 8, lndlcaLlng LhaL Lhe fleld wlll conLaln
a maxlmum of 8 characLers, and ln Lhe 'ueclmal places' area, enLer 0. An CuLpuL lengLh of
8 should be selecLed, and Lhen press LnLer.
1he 'nuMC' fleld's descrlpLlon should re-appear, conflrmlng LhaL Lhls ls a valld enLry.
nexL, selecL Lhe 'value range' Lab, whlch ls vlslble nexL Lo Lhe 'ueflnlLlon' Lab [usL used:

1hls ls where you seL valld value ranges for Lhe uomaln creaLed. Cnce Lhls ls seL, any
subsequenL user enLerlng values ouLslde Lhe valld value range wlll be shown an error

38
DATA DICTIONARY
message and be requesLed Lo enLer a valld enLry. Pere, Lhere are Lhree opLlons.
llrsL, where you can see 'Slngle values', lL ls posslble Lo enLer a llsL of lndlvldual
valld values whlch can be enLered by Lhe user.
Second, 'lnLervals', where you can enLer a lower and upper llmlL for valld values,
for example 1 and 9, whlch saves Lhe efforL of enLerlng 9 lndlvldual slngle values ln
Lhe 'Slngle values' secLlon.
LasL, Lhe 'value Lable' box vlslble aL Lhe boLLom. When Lhere are a large number of
posslble enLrles, Lhls ls a common meLhod (Lo do Lhls you musL speclfy a compleLe
valld value Lable enLry llsL, ln whlch case lL ls also necessary Lo lnLroduce forelgn
keys Lo Lhe Lable, Lo ensure Lhe user's enLrles are LesLed agalnsL Lhe value sLored
ln Lhe value Lable creaLed).
1hls example uomaln, however, does noL requlre any value range enLry, so [usL cllck Lhe
save buLLon and, agaln, asslgn lL as a 'Local ob[ecL'.
1he nexL sLep ls Lo AcLlvaLe Lhe ob[ecL, allowlng oLher uaLa elemenLs Lo use Lhls domaln
golng forward. ln Lhe Loolbar cllck Lhe small maLchsLlck lcon (also accesslble by presslng
C18L +l3).
A pop-up wlndow appears, llsLlng Lhe 3 currenLly lnacLlve ob[ecLs:

lL may be posslble Lo acLlvaLe all of Lhe ob[ecLs LogeLher, buL Lhls ls noL advlsed. ln a Lyplcal
developmenL envlronmenL, a number of people wlll be creaLlng developmenLs
slmulLaneously, and qulLe ofLen, oLhers' ob[ecLs wlll appear ln Lhls llsL.
AL Lhls polnL, lL ls only Lhe uomaln whlch ls Lo be acLlvaLed, Lhe Lop enLry labelled 'uCMA',
wlLh Lhe name 'ZLLnuM'. When Lhls ls hlghllghLed, cllck Lhe green Llck conLlnue buLLon.
1he wlndow should dlsappear, and Lhe sLaLus bar wlll dlsplay Lhe message 'Cb[ecL(s)

39
DATA DICTIONARY
acLlvaLed'
now lL ls posslble Lo proceed wlLh Lhe creaLlon of Lhe Lable. lorward navlgaLlon was used
for generaLlng Lhe uomaln, so cllck Lhe '8ack' buLLon, or press l3 Lo reLurn Lo Lhe
'MalnLaln uaLa LlemenL' screen. As Lhe domaln ls acLlve, Lhe descrlpLlon enLered
prevlously should appear by Lhe area where 'ZLLnuM' was Lyped, along wlLh oLher
uomaln properLles whlch have been creaLed:


nexL, Lhe lleld labels musL be creaLed, so cllck LhaL Lab. 1he lleld labels enLered here wlll
appear as fleld labels ln Lhe flnal Lable. ln Lhls example Lhey should read 'Lmployee', or
beLLer, 'Lmployee number'. lf Lhls does noL flL wlLhln Lhe area glven, [usL Lallor lL so LhaL lL
sLlll makes sense, for example Lyplng 'Lmployee n' lnLo Lhe 'ShorL' lleld label box. Cnce
Lhe LexL has been puL lnLo Lhe lleld label spaces, press enLer, and Lhe 'LengLh' secLlon wlll
auLomaLlcally be fllled ln:



40
DATA DICTIONARY
Cnce Lhls ls compleLe, Save and AcLlvaLe Lhe elemenL vla Lhe Loolbar aL Lhe Lop. 1he
lnacLlve ob[ecLs wlndow wlll reappear, where Lwo lnacLlve ob[ecLs wlll remaln. PlghllghL
Lhe uaLa elemenL (labelled 'u1LL') and cllck Lhe green Llck
ConLlnue buLLon aL Lhe boLLom.
Agaln, Lhe sLaLus bar should dlsplay 'Cb[ecL(s) acLlvaLed'.
ress Lhe back buLLon Lo reLurn Lo Lhe 1able malnLenance screen. Pere you wlll now see
LhaL Lhe 'LMLC?LL' column has Lhe correcL uaLa 1ype, LengLh, ueclmals and ShorL LexL,
Lhus lndlcaLlng Lhe successful creaLlon of a uaLa elemenL and uomaln belng used for Lhls
lleld.

nexL, Lhe same pracLlces wlll be used Lo creaLe four addlLlonal flelds.
1he nexL fleld Lo creaLe should be LlLled 'Su8nAML'. 1hls Llme lL should oot be selecLed as
a key fleld, so do noL check Lhe box. 1he uaLa elemenL, ln Lhls lnsLance, ls labelled
'ZSu8nAML':

now, forward navlgaLlon wlll agaln be used. uouble-cllck ZSURNAME; choose '?es' Lo
save Lhe Lable and '?es' agaln Lo creaLe Lhe new uaLa elemenL. 1he 'MalnLaln uaLa
LlemenL' wlndow wlll appear whlch wlll be famlllar from Lhe prevlous sLeps.
ln Lhe 'ShorL LexL' box Lhls Llme Lype 'Surname uaLa LlemenL' and LlLle Lhe new domaln

41
DATA DICTIONARY
'ZSu8nAML':

uouble-cllck Lhe new domaln and save Lhe uaLa elemenL, asslgnlng lL a 'Local ob[ecL' and
Lhen choose '?es' Lo creaLe Lhe new uomaln.
1he uomaln malnLenance screen wlll reappear. LnLer Lhe shorL LexL 'Surname' and, Lhls
Llme, Lhe uaLa Lype Lo selecL ls 'CPA8', a CharacLer sLrlng.
1he number of characLers and ouLpuL lengLh should boLh be seL Lo 40, Lhen press enLer Lo
be sure everyLhlng has worked, and cllck Lhe AcLlvaLe buLLon.



42
DATA DICTIONARY
noLe LhaL Lhe Save buLLon has noL been pressed Lhls Llme, as Lhe AcLlvaLe buLLon wlll also
save Lhe work auLomaLlcally. Lnsure you asslgn Lhe ob[ecL Lo Lhe $1M developmenL class
as usual.
ln Lhe AcLlvaLe menu, selecL Lhe ob[ecL (Lhe domaln (labelled 'uCMA') named
'ZSu8nAML') Lo be acLlvaLed, and cllck Lhe green Llck conLlnue buLLon. 1he sLaLus bar
should read 'Cb[ecL saved and acLlvaLed'.
lollowlng Lhls, cllck 8ack or l3 Lo reLurn Lo Lhe MalnLaln uaLa elemenL screen. Lnsure Lhe
domaln aLLrlbuLes have appeared (ShorL LexL, uaLa Lype, LengLh and so on). ln Lhe lleld
Label Lab, enLer 'Surname' ln each box and press LnLer Lo auLomaLlcally flll Lhe 'LengLh'
boxes and Lhen acLlvaLe Lhe uaLa elemenL (ln Lhe AcLlvaLe menu, Lhe 'u1LL' ob[ecL named
'ZSu8nAMLS'), checklng Lhe sLaLus bar Lo ensure Lhls has occurred wlLh any errors:

Agaln, press 8ack Lo reLurn Lo Lhe MalnLaln 1able screen, where Lhe new uaLa elemenL wlll
be vlslble:

43
DATA DICTIONARY

1he nexL fleld Lo be creaLed ls LlLled 'lC8LnAML', and Lhe daLa elemenL 'ZlC8LnAML'.
Cllck Lo creaLe Lhe uaLa elemenL and follow Lhe sLeps above agaln.
ln Lhe MalnLaln uaLa LlemenL screen, Lhe ShorL LexL should read 'lorename uaLa LlemenL'
and Lhe domaln 'ZlC8LnAML'. Save Lhls and choose '?es' Lo creaLe Lhe domaln.
1he domaln's shorL LexL should read 'lorename'. use Lhe CPA8 daLa Lype agaln and a
LengLh and CuLpuL lengLh of 40. nexL, AcLlvaLe Lhe uomaln as before.
8eLurn Lo Lhe MalnLaln uaLa LlemenL screen. 1ype 'lorename' lnLo Lhe four lleld label
boxes. ress eotet Lo flll Lhe lengLh boxes and Lhen AcLlvaLe Lhe uaLa LlemenL named
'ZlC8LnAML' as before. Co back agaln Lo see Lhe Lable:


44
DATA DICTIONARY
1he nexL fleld wlll be called '1lLle' and Lhe uaLa LlemenL 'Z1l1LL', follow Lhe sLeps above
agaln Lo creaLe Lhls fleld wlLh Lhe followlng lnformaLlon:
1he uaLa elemenL shorL LexL should read '1lLle uaLa LlemenL' and Lhe domaln should be
named 'Z1l1LL'.
1he uomaln ShorL LexL should be '1lLle' and Lhe uaLa Lype ls agaln 'CPA8'. 1hls Llme Lhe
LengLh and CuLpuL lengLh wlll be 13.
1he lleld labels should all read '1lLle'.
AcLlvaLe all of Lhese and go back Lo vlew Lhe new, flfLh fleld ln Lhe 1able.
1he flnal fleld whlch wlll be creaLed for Lhls Lable ls for uaLe of 8lrLh. ln Lhe lleld box Lype
'uC8' and creaLe Lhe uaLa elemenL 'ZuC8' uslng Lhe sLeps from Lhe prevlous secLlon and
Lhls lnformaLlon:
1he uaLa elemenL shorL LexL should read 'uaLe of 8lrLh uaLa LlemenL' and Lhe domaln
should be named 'ZuC8'.
1he uomaln ShorL LexL should be 'uaLe of 8lrLh' and Lhe uaLa Lype ls, Lhls Llme, 'uA1S',
afLer whlch an lnformaLlon box wlll appear Lo conflrm Lhls. Cllck Lhe green Llck Lo conLlnue:


45
DATA DICTIONARY

lor Lhe uA1S daLa Lype, Lhe LengLh and CuLpuL lengLhs are seL auLomaLlcally aL 8 and 10
(Lhe CuLpuL lengLh ls longer as lL wlll auLomaLlcally ouLpuL dlvlders beLween Lhe day,
monLh and year parLs of Lhe daLe).
1he lleld labels should all read 'uaLe of 8lrLh', excepL Lhe 'ShorL' label where Lhls wlll noL
flL, so [usL Lype 'uC8' here. AcLlvaLe Lhe uomaln and uaLa elemenL, and reLurn Lo Lhe
Lable.

1echn|ca| Sett|ngs
Cnce Lhls has been saved, Lhe nexL sLep ls Lo move on Lo malnLalnlng Lhe Lechnlcal seLLlngs
of Lhe 1able. 8efore creaLlng Lhe flnal uaLabase Lable, SA wlll need some more
lnformaLlon abouL Lhe Lable belng creaLed.
SelecL '1echnlcal seLLlngs' vla Lhe Loolbar above Lhe Lable, Lhrough Lhe 'Co Lo' menu, or

46
DATA DICTIONARY
wlLh Lhe shorLcuL C18L+SPll1+l9.
Pere, lL ls lmporLanL Lo Lell Lhe sysLem whaL uaLa class ls Lo be used, so selecL Lhe drop
down buLLon. 1here are flve dlfferenL opLlons, wlLh accompanylng descrlpLlons. lor Lhls
Lable, selecL Lhe flrsL, labelled 'AL0', and double-cllck lL:


lor Lhe 'Slze caLegory' fleld, agaln cllck Lhe drop-down buLLon. Pere, you have Lo make an
esLlmaLe as Lo Lhe amounL of daLa records whlch wlll be held wlLhln Lhe Lable so LhaL Lhe
sysLem has some ldea of how Lo creaLe Lhe Lables ln Lhe underlylng daLabase. ln Lhls
lnsLance, lL wlll be a relaLlvely small amounL of lnformaLlon, so selecL Lhe flrsL slze
caLegory, labelled 0:

47
DATA DICTIONARY

8elow Lhls are Lhe 8ufferlng opLlons. Pere, '8ufferlng noL allowed' should be selecLed:

1hls prevenLs Lhe Lable conLenLs from belng loaded lnLo memory for readlng, sLopplng Lhe
Lable from belng read ln advance of Lhe selecLlon of Lhe records ln Lhe program. ?ou may,
correcLly, polnL ouL LhaL lL may be advanLageous Lo hold Lhe Lable ln Lhe memory for
speed efflclency, buL ln Lhls example, Lhls ls noL necessary. lf speed was an lssue ln a
developmenL, bufferlng would Lhen be swlLched on, ensurlng Lhe daLa ls read lnLo
memory. ln Lhe case of large Lables whlch are accessed regularly buL updaLed
lnfrequenLly, Lhls ls Lhe opLlon Lo choose.
noLhlng else on Lhe 'MalnLaln 1echnlcal SeLLlngs' screen needs Lo be fllled aL Lhls polnL, so
cllck Save and Lhen go back Lo Lhe Lable lLself. lf all of Lhls ls successful, Lhen Lhe Lable
should now be ln a poslLlon Lo be acLlvaLed and Lhe enLry of records can begln. Cllck Lhe
AcLlvaLe lcon Lo acLlvaLe Lhe Lable and check Lhe sLaLus bar, whlch should agaln read
'Cb[ecL AcLlvaLed'.


48
DATA DICTIONARY
Lnter|ng kecords |nto a 1ab|e
now LhaL Lhe Lable has been creaLed, daLa can be enLered. 1o do Lhls, enLer Lhe 'uLlllLles'
menu, scroll Lo '1able conLenLs', and Lhen 'CreaLe LnLrles':

A uaLa-enLry screen wlll appear whlch has auLomaLlcally been generaLed from Lhe Lable
creaLed. 1he fleld names correspond here Lo Lhe Lechnlcal names glven when we creaLed
Lhem. 1o change Lhese Lo Lhe lleld labels whlch we seL up, enLer Lhe 'SeLLlngs' menu and
selecL 'user arameLers'. 1hls faclllLy allows you Lo Lallor how Lables look for your own
speclflc user lu. SelecL Lhe 'lleld label' radlo buLLon and cllck 'ConLlnue':


49
DATA DICTIONARY
1he lleld labels creaLed wlll now appear as Lhey were deflned when creaLlng Lhe Lable:

1he Lmployee number fleld ls llmlLed Lo 8 characLers, and Lhe daLa Lype was seL Lo nuMC,
so only numerlcal characLers can be enLered. CreaLe a record wlLh Lhe followlng daLa:
Lmployee number: '10000001'
Surname: '8rown'
lorename: 'SLephen'
1lLle: 'Mr'
uaLe of 8lrLh: '16.02.1980':

ress LnLer and Lhe sysLem wlll auLomaLlcally puL Lhe names ln upper case, and valldaLe
each fleld Lo ensure Lhe correcL values were enLered:

50
DATA DICTIONARY

Cllck Save and Lhe sLaLus bar should sLaLe 'uaLabase record successfully creaLed'. nexL,
cllck Lhe '8eseL' buLLon above Lhe daLa enLry flelds Lo clear Lhe flelds for Lhe nexL enLry.
CreaLe anoLher record wlLh Lhe followlng daLa:
Lmployee number '10000002'
Surname '!ones'
lorename 'Amy'
1lLle 'Mrs'
uaLe of 8lrLh '181169'.
noLe LhaL Lhls Llme Lhe uaLe of 8lrLh has been fllled ln wlLhouL Lhe approprlaLe dlvlders.
When LnLer ls pressed, Lhe sysLem auLomaLlcally valldaLes all flelds, correcLlng Lhe uaLe of
8lrLh fleld Lo Lhe correcL formaLLlng lLself:


51
DATA DICTIONARY

Save, 8eseL, and Lhen furLher records can be enLered followlng Lhe same sLeps:

noLe LhaL lf daLes are enLered ln Lhe wrong formaL, an error message wlll appear ln Lhe
sLaLus bar:


V|ew|ng the Data |n a 1ab|e
now LhaL daLa has been enLered lnLo Lhe Lable, Lhe flnal few sLeps wlll allow Lhls daLa Lo
be vlewed.
Pavlng enLered several daLa records ln Lhe manner dlscussed prevlously, cllck Lhe 8ack key
Lo reLurn Lo Lhe 'ulcLlonary: ulsplay 1able' screen. 1o vlew Lhe Lable creaLed wlLh Lhe daLa
enLered, from Lhe 'uLlllLles' menu, selecL '1able conLenLs' and Lhen 'ulsplay':

52
DATA DICTIONARY

A selecLlon screen wlll Lhen appear, allowlng you Lo enLer or choose fllLer values for Lhe
flelds you creaLed. 1he selecLlon screen ls very useful when you have loLs of daLa ln your
Lable. ln Lhls case, Lhough, only flve records have been enLered, so Lhls ls unnecessary.
Powever, for example lf you were Lo only wanL Lo focus on a slngle employee number, or
a small range, Lhese flgures can be selecLed from Lhls screen:

1o vlew all of Lhe records, do noL enLer any daLa here. !usL cllck Lhe 'LxecuLe' buLLon,
whlch ls dlsplayed ln Lhe Lop lefL corner of Lhe lmage above, or use Lhe shorLcuL l8. ?ou
wlll now see a screen showlng Lhe daLa records you enLered ln Lhe prevlous secLlon:

53
DATA DICTIONARY

lf furLher flelds were Lo exlsL, Lhe screen would scroll furLher Lo Lhe rlghL, meanlng noL all
flelds could be dlsplayed slmulLaneously due Lo fleld slze properLles.
lf you wanL Lo see all of Lhe daLa for one record, double-cllck on Lhe record and Lhls wlll be
shown. AlLernaLlvely, several records can be scrolled Lhrough by selecLlng Lhe deslred
records vla Lhe check-boxes Lo Lhe lefL of Lhe 'CllenL' column and Lhen cllcklng Lhe 'Choose'
lcon on Lhe Loolbar:
1hese can Lhen be lndlvldually vlewed and scrolled Lhrough wlLh Lhe 'nexL enLry' buLLon:


1o reLurn Lo Lhe full Lable Lhen, slmply cllck Lhe 8ack buLLon, or press l3.
LxperlmenL wlLh Lhe Lable creaLed, uslng Lhe Loolbar's range of opLlons Lo fllLer and sorL
Lhe lnformaLlon ln a number of ways:

54
DATA DICTIONARY

lor example, Lo organlse alphabeLlcally by forename, cllck Lo selecL Lhe 'lorename' fleld,
and Lhen cllck Lhe 'SorL ascendlng' buLLon:
1here are a number of Lhlngs whlch can be achleved ln Lhls Lable vlew, and lL can be a
useful Lool for checklng Lhe daLa wlLhln an SA sysLem wlLhouL golng Lhrough Lhe
LransacLlon screens Lhemselves.


55
YOUR FIRST ABAP PROGRAM
Chapter 3
Creat|ng a rogram
1o begln creaLlng a program, access Lhe A8A LdlLor elLher vla LransacLlon code SL38, or
by navlgaLlng Lhe SA menu Lree Lo 1ools A8A Workbench uevelopmenL, ln whlch
Lhe A8A LdlLor ls found. uouble-cllck Lo execuLe.
A noLe Lo begln: lL ls advlsable Lo keep Lhe programs creaLed as slmple as posslble. uo noL
make Lhem any more compllcaLed Lhan ls necessary. 1hls way, when a program ls passed
on Lo anoLher developer Lo work wlLh, flx bugs and so on, lL wlll be far easler for Lhem Lo
undersLand. Add as many commenLs as posslble Lo Lhe code, Lo make lL slmpler for
anyone who comes Lo lL laLer Lo undersLand whaL a program ls dolng, and Lhe flow of Lhe
loglc as lL ls execuLed.
1he program name musL adhere Lo Lhe cusLomer namlng convenLlons, meanlng LhaL here
lL musL begln wlLh Lhe leLLer Z. ln conLlnuaLlon of Lhe example from Lhe prevlous chapLer,
in this instance the program will be titled Z_Employee_List_01, which should be typed
into the Program field on the initial screen of the ABAP Editor. Ensure that the Source
code button is checked, and then click Create:

56
YOUR FIRST ABAP PROGRAM

A Program Attributes window will then appear. In the Title box, type a description of
what the program will do. In this example, My Employee List Report. The Original
language should be seL Lo Ln, Lngllsh by defaulL, [usL check Lhls, as lL can have an effecL on
Lhe LexL enLrles dlsplayed wlLhln cerLaln programs. Any LexL enLrles creaLed wlLhln Lhe
program are language-speclflc, and can be malnLalned for each counLry uslng a LranslaLlon
Lool. 1hls wlll noL be examlned aL lengLh here, buL ls someLhlng Lo bear ln mlnd.
In the Attributes section of the window, for the Type, click the drop-down menu and
select Executable program, meaning that the program can be executed without the use
of a LransacLlon code, and also LhaL lL can be run as a background [ob. 1he Status selected
should be Test program, and the Application should be Basis. These two options help
Lo manage Lhe program wlLhln Lhe SA sysLem lLself, descrlblng whaL Lhe program wlll be
used for, and also Lhe program developmenL sLaLus.
lor now, Lhe oLher flelds below Lhese should be lefL empLy. arLlcularly ensure LhaL Lhe
Editor Lock box is left clear (selection of this will prevent the program from being edited).
Unicode checks active should be selected, as should Fixed point arithmetic (wlLhouL
Lhls, any packed-declmal flelds ln Lhe program wlll be rounded Lo whole numbers). Leave
the Start using variant box blank. Then, click the Save button.

57
YOUR FIRST ABAP PROGRAM

1he famlllar Create Object Directory Entry box from the previous section should appear
now, click the Local object option as before to assign the program to the temporary
developmenL class. Cnce Lhls ls achleved, Lhe codlng screen ls reached.
Code Ld|tor
Pere, focus wlll be puL on Lhe codlng area. 1he flrsL seL of llnes vlslble here are commenL
llnes. 1hese seven llnes can be used Lo begln commenLlng Lhe program. ln A8A,
commenLs can appear ln Lwo ways. llrsLly, lf a * ls placed aL Lhe beglnnlng of a llne, lL
Lurns everyLhlng Lo lLs rlghL lnLo a commenL.

58
YOUR FIRST ABAP PROGRAM

noLe LhaL Lhe * musL be ln Lhe flrsL column on Lhe lefL. lf lL appears ln Lhe second column
or beyond, Lhe LexL wlll cease Lo be a commenL.
A comment can also be written within a line itself, by using a . Where this is used,
everyLhlng Lo Lhe rlghL agaln becomes a commenL. 1hls means LhaL lL ls posslble Lo add
commenLs Lo each llne of a program, or aL leasL a few llnes of commenLs for each secLlon.

1he nexL llne of code, vlslble above, beglns wlLh Lhe word 8LC81. 1hls ls called a
S1A1LMLn1, and Lhe 8LC81 sLaLemenL wlll always be Lhe flrsL llne of any execuLable
program creaLed. 1he sLaLemenL ls followed by Lhe program name whlch was creaLed
prevlously. 1he llne ls Lhen LermlnaLed wlLh a full sLop (vlslble Lo Lhe lefL of Lhe commenL).
Lvery sLaLemenL ln A8A musL be followed by a full sLop, or perlod. 1hls allows Lhe
sLaLemenL Lo Lake up as many llnes ln Lhe edlLor as lL needs, so for example, Lhe 8LC81
sLaLemenL here could look llke Lhls:


59
YOUR FIRST ABAP PROGRAM
As long as Lhe perlod appears aL Lhe end of Lhe sLaLemenL, no problems wlll arlse. lL ls Lhls
perlod whlch marks where Lhe sLaLemenL flnlshes.
lf you requlre help wlLh a sLaLemenL, place Lhe cursor wlLhln Lhe sLaLemenL and choose
the Help on... button in the top toolbar:

A wlndow wlll appear wlLh Lhe A8A keyword auLomaLlcally fllled ln. Cllck Lhe conLlnue
buLLon and Lhe sysLem wlll dlsplay help on LhaL parLlcular sLaLemenL, glvlng an explanaLlon
of whaL lL ls used for and Lhe synLax. 1hls can be used for every A8A sLaLemenL wlLhln an
SA sysLem. AlLernaLlvely, Lhls can be achleved by cllcklng Lhe cursor wlLhln Lhe
sLaLemenL, and presslng Lhe l1 key:

60
YOUR FIRST ABAP PROGRAM

A further tip in this vein is to use the ABAP Documentation and Examples page, which
can be accessed by enLerlng LransacLlon code A8AuCCu lnLo Lhe LransacLlon code fleld.
1he menu Lree Lo Lhe lefL hand slde on Lhls screen allows you Lo vlew example code, whlch
ones own code can later be based upon. This can either be copied and pasted into the
A8A edlLor, or experlmenLed wlLh lnslde Lhe screen lLself uslng Lhe LxecuLe buLLon Lo run
Lhe example code:

61
YOUR FIRST ABAP PROGRAM

8eLurnlng Lo Lhe A8A edlLor now, Lhe flrsL llne of code wlll be wrlLLen. Cn Lhe llne below
Lhe 8LC81 sLaLemenL, Lype Lhe sLaLemenL: #&'() HELLO SAP WORLD+

1he wrlLe sLaLemenL wlll, as you mlghL expecL, wrlLe whaLever ls ln quoLes afLer lL Lo Lhe
ouLpuL wlndow (Lhere are a number of addlLlons whlch can be made Lo Lhe wrlLe
sLaLemenL Lo help formaL Lhe LexL, whlch we wlll reLurn ln a laLer chapLer).
Save Lhe program, and check Lhe synLax wlLh the Check button in the toolbar (or via CTRL
+ F2). The status bar should display a message reading Program Z_EMPLOYEE_LIST_01 is
syntactically correct. Then, click the Activate button, which should add the word Active
nexL Lo Lhe program name. Cnce this is done, click the Direct processing button to test
Lhe code:

62
YOUR FIRST ABAP PROGRAM

1he reporL LlLle and Lhe LexL ouLpuL should appear llke Lhls, compleLlng Lhe program:


Wr|te Statements
now LhaL Lhe flrsL program has been creaLed, lL can be expanded wlLh Lhe addlLlon of
furLher A8A sLaLemenLs. use Lhe 8ack buLLon Lo reLurn from Lhe LesL screen Lo Lhe A8A
edlLor.
Pere, Lhe Lables whlch were creaLed ln Lhe A8A ulcLlonary durlng Lhe flrsL sLage wlll be
accessed. 1he flrsL sLep Loward dolng Lhls ls Lo lnclude a Lables sLaLemenL ln Lhe program,
whlch wlll be placed below Lhe 8LC81 sLaLemenL. lollowlng Lhls, Lhe Lable name whlch

63
YOUR FIRST ABAP PROGRAM
was creaLed ls Lyped ln, z_employee_llsL_01, and, as always, a perlod Lo end Lhe
sLaLemenL:

Whlle noL essenLlal, Lo keep Lhe formaL of Lhe code unlform, Lhe reLLy rlnLer faclllLy can
be used. Click the Pretty Printer button in the toolbar to automatically alter the text in
llne wlLh Lhe reLLy rlnLer seLLlngs (whlch can be accessed Lhrough Lhe uLlllLles menu,
SeLLlngs, and Lhe reLLy rlnLer Lab ln Lhe A8A LdlLor secLlon):

Cnce Lhese seLLlngs have been applled, Lhe code wlll look sllghLly Lldler, llke Lhls:

64
YOUR FIRST ABAP PROGRAM

LeL us now reLurn Lo Lhe 1A8LLS sLaLemenL. When Lhe program ls execuLed, Lhe 1A8LLS
sLaLemenL wlll creaLe a Lable sLrucLure ln memory based on Lhe sLrucLure prevlously
deflned ln Lhe A8A ulcLlonary. 1hls Lable sLrucLure wlll lnclude all of Lhe flelds prevlously
creaLed, allowlng Lhe records from Lhe Lable Lo be read and sLored ln a Lemporary
sLrucLure for Lhe program Lo use.
1o reLrleve from our daLa dlcLlonary Lable and place Lhem lnLo Lhe toble sttoctote, Lhe
SLLLC1 sLaLemenL wlll be used.
1ype ,-.-/% 0 1&"2 34)256"7))46'8(49:+ 1hls ls Lelllng Lhe sysLem Lo selecL everyLhlng
(Lhe * refers Lo all-flelds) from Lhe Lable. 8ecause Lhe SLLLC1 sLaLemenL ls a loop, Lhe
sysLem musL be Lold where Lhe loop ends. 1hls ls done by Lyplng Lhe sLaLemenL
LnuSLLLC1. now we have created a select loop lets do something with the data we have
are looplng Lhrough. Pere, Lhe W8l1L command wlll be used agaln. 8eplace Lhe #&'()
HELLO ,;< =>?.@. line with #&'() 34)256"7))46'8(49:. Lo wrlLe every row of Lhe
Lable Lo Lhe ouLpuL wlndow:

Check the code with the Check button, and it will state that there is a syntax error:

65
YOUR FIRST ABAP PROGRAM

1he cursor wlll have moved Lo Lhe 1A8LLS sLaLemenL whlch was ldenLlfled, along wlLh Lhe
above warning. The name Z_EMPLOYEE_LIST_01 appears to be incorrect. To check this,
open a new sesslon vla Lhe new Sesslon buLLon ln Lhe Loolbar . LxecuLe Lhe A8A
Dictionary with transaction code SE11, search for Z* in the Database table box and it will
brlng back Lhe Lable ZLMLC?LLS, meanlng LhaL Lhe lnlLlal Lable name
Z_LMLC?LL_LlS1_01 was wrong. Close Lhe new sesslon and Lhe synLax error wlndow and
Lype in the correct table name ZEMPLOYEES after the 1A8LLS sLaLe. ?our screen should
look llke Lhls:

Save Lhe program and check Lhe code, ensurlng Lhe synLax error has been removed, and
Lhen cllck Lhe 1esL buLLon (l8) and Lhe ouLpuL wlndow should dlsplay every row of Lhe
Lable:


66
YOUR FIRST ABAP PROGRAM
Look aL Lhe daLa ln Lhe ouLpuL wlndow. 1he sysLem has auLomaLlcally puL each llne from
Lhe Lable on a new row. 1he W8l1L sLaLemenL ln Lhe program dld noL know LhaL each row
was Lo be ouLpuL on a new llne, Lhls was forced by some of Lhe defaulL seLLlngs wlLhln Lhe
sysLem regardlng screen seLLlngs, maklng Lhe llne lengLh correspond Lo Lhe wldLh of Lhe
screen. lf you Lry Lo prlnL Lhe reporL, lL could be LhaL Lhere are Loo many columns or
characLers Lo flL on a sLandard sheeL of A4. WlLh Lhls ln mlnd, lL ls advlsable Lo use an
addlLlon Lo Lhe 8LC81 sLaLemenL regardlng Lhe wldLh of each llne.
8eLurn Lo Lhe program, cllck Lhe 8LC81 sLaLemenL and press Lhe l1 key and observe Lhe
LlnL SlZL addlLlon whlch can be lncluded:

ln Lhls example, add Lhe LlnL-SlZL addlLlon Lo Lhe 8LC81 sLaLemenL. Pere, Lhe llne wlll be
llmlLed Lo 40 characLers. Pavlng done Lhls, see whaL dlfference lL has made Lo Lhe ouLpuL
wlndow. 1he llnes have now been broken aL Lhe 40 characLer llmlL, LruncaLlng Lhe ouLpuL

67
YOUR FIRST ABAP PROGRAM
of each llne:


8ear Lhese llmlLs ln mlnd so as Lo avold auLomaLlc LruncaLlon when prlnLlng reporLs. lor a
sLandard sheeL of A4 Lhls llmlL wlll usually be 132 characLers. When Lhe llmlL ls seL Lo Lhls
for Lhe example Lable here, Lhe full Lable returns, but the line beneath the title My
mployee llst kepott displays the point at which Lhe ouLpuL ls llmlLed:

nexL, Lhe program wlll be enhanced somewhaL, by addlng speclflc formaLLlng addlLlons Lo
Lhe W8l1L sLaLemenL. llrsL, a llne break wlll be lnserLed aL Lhe beglnnlng of every row LhaL
ls ouLpuL.

68
YOUR FIRST ABAP PROGRAM
uupllcaLe Lhe prevlous SLLLC1 LnuSLLLC1 sLaLemenL block of code and place a / afLer
Lhe W8l1L sLaLemenL. 1hls wlll Lrlgger a llne break:

Save and execuLe Lhe code. 1he ouLpuL wlndow should now look llke Lhls:

1he flrsL SLLLC1 loop has creaLed Lhe flrsL flve rows, and Lhe second has ouLpuL Lhe nexL
flve.
8oLh look ldenLlcal. 1hls ls due Lo Lhe LlnL-SlZL llmlL ln Lhe 8LC81 sLaLemenL, causlng Lhe
flrsL flve rows Lo creaLe a new llne once Lhey reached 132 characLers. lf Lhe LlnL-SlZL ls
lncreased Lo, for example 332, Lhe effecLs of Lhe dlfferenL W8l1L sLaLemenLs wlll be
vlslble:


69
YOUR FIRST ABAP PROGRAM
1he flrsL flve rows, because Lhey do noL have a llne break ln Lhe W8l1L sLaLemenL, have
appeared on Lhe flrsL llne up unLll Lhe polnL aL whlch Lhe 332 characLer llmlL was reached
and a new llne was forced. 1he flrsL four records were ouLpuL on Lhe flrsL llne. 1he 3
Lh

record appears on a llne of lLs own followed by Lhe second seL of flve records, havlng had
a llne break forced before each record was ouLpuL.
8eLurn Lhe LlnL-SlZL Lo 132, before some more formaLLlng ls done Lo show Lhe separaLlon
beLween Lhe Lwo dlfferenL SLLLC1 loops.
Above Lhe second SLLLC1 loop, Lype A.BC-. 1hls means underllne.

Cllck Lhe uLlnL sLaLemenL and press l1 for furLher explanaLlon from Lhe uocumenLaLlon
window, which will state Writes a continuous underline in a new line. Doing this will
help separaLe Lhe Lwo dlfferenL SLLLC1 ouLpuLs ln Lhe code creaLed. LxecuLe Lhls, and lL
should look llke so:

uupllcaLe Lhe prevlous SLLLC1 LnuSLLLC1 sLaLemenL block of code agaln, lncludlng Lhe

70
YOUR FIRST ABAP PROGRAM
uLlnL, Lo creaLe a Lhlrd SLLLC1 ouLpuL. ln Lhls Lhlrd secLlon, remove Lhe llne break from
the WRITE statement and, on the line below, type WRITE /. This will mean LhaL a new
llne wlll be ouLpuL aL Lhe end of Lhe prevlous llne. LxecuLe Lhls Lo see Lhe dlfference ln Lhe
Lhlrd secLlon:


now, creaLe anoLher SLLLC1 loop by dupllcaLlng Lhe second SLLLC1 loop. 1hls Llme Lhe
W8l1L sLaLemenL wlll be lefL lnLacL, buL a new sLaLemenL wlll be added before Lhe SLLLC1
loop: ,DB<, whlch means Lo sklp a llne. 1hls can have a number added Lo lL Lo speclfy how
many llnes Lo sklp, ln Lhls case 2. lf you press l1 Lo access Lhe documenLaLlon wlndow lL
wlll explaln furLher, lncludlng Lhe ablllLy Lo sklp Lo a speclflc llne. 1he code for Lhls secLlon
should look llke Lhe flrsL lmage, and when execuLed, Lhe second:

71
YOUR FIRST ABAP PROGRAM


Cur program should now look as shown below. CommenLs have been added Lo help
dlfferenLlaLe Lhe examples.

@=+5=+ 6*;4C4;="$ <4%$;,
CreaLe anoLher SLLLC1 sLaLemenL. 1hls Llme, lnsLead of ouLpuLLlng enLlre rows of Lhe
Lable, lndlvldual flelds wlll be ouLpuL. 1hls ls done by speclfylng Lhe lndlvldual fleld afLer
Lhe W8l1L sLaLemenL. Cn a new llne afLer Lhe SLLLC1 sLaLemenL add Lhe followlng llne
=?B%- E 3)256"7))8$8F&GH2)+ 8epeaL Lhls ln Lhe same SLLLC1 loop for flelds lorename
and uC8. 1hen execuLe Lhe code:

72
YOUR FIRST ABAP PROGRAM


1o Lldy Lhls up a llLLle remove Lhe E from Lhe lasL 2 W8l1L sLaLemenLs whlch wlll make all 3
flelds appear on 1 llne.


Cha|n|ng Statements 1ogether
We have used Lhe W8l1L sLaLemenL qulLe a loL up Lo now and you wlll see lL appear on a
regular basls ln many sLandard SA programs. 1o save Llme, Lhe W8l1L sLaLemenLs can be

73
YOUR FIRST ABAP PROGRAM
chalned LogeLher, avoldlng Lhe need Lo dupllcaLe Lhe W8l1L sLaLemenL on every llne.
1o do Lhls, dupllcaLe Lhe prevlous SLLLC1 loop block of code. AfLer Lhe flrsL W8l1L
sLaLemenL, add I 1hls Lells Lhe SA sysLem LhaL Lhls W8l1L sLaLemenL ls golng Lo wrlLe
mulLlple fields (or text literals). After the zemployees-surname fleld change Lhe perlod
(.) Lo a comma (,) and remove Lhe second and Lhlrd W8l1L sLaLemenLs. Change Lhe second
perlod (.) Lo comma (,) also buL leave Lhe lasL perlod (.) as ls Lo lndlcaLe Lhe end of Lhe
sLaLemenL. 1hls ls how we chaln sLaLemenLs LogeLher and can also be used for a number
of oLher sLaLemenLs Loo.

LxecuLe Lhe code, and Lhe ouLpuL should appear exacLly Lhe same as before.
Copy our rogram
Lets now swlLch focus a llLLle and look aL creaLlng flelds wlLhln Lhe program. 1here are
Lwo Lypes of fleld Lo look aL here, varlables and ConsLanLs.
llrsLly, lL wlll be necessary Lo generaLe a new program from Lhe A8A LdlLor. 1hls can be
done elLher wlLh Lhe sLeps from Lhe prevlous secLlon, or by copylng a pasL program. 1he
laLLer opLlon ls useful lf you plan on reuslng much of your prevlous code. 1o do Lhls,
launch LransacLlon SL38 agaln and enter the original programs name into the Program
fleld of Lhe InlLlal screen, and Lhen cllck Lhe Copy buLLon (C18L + l3):

74
YOUR FIRST ABAP PROGRAM

A wlndow wlll appear asklng for a name for Lhe new program, ln Lhls lnsLance, enLer
J4-K<.>L--4.B,%4M in the Target rogram lnpuL box, Lhen press Lhe Copy buLLon. 1he
nexL screen wlll ask lf any oLher ob[ecLs are Lo be copled. Slnce none of Lhe ob[ecLs here
have been creaLed ln Lhe flrsL program, leave Lhese blank, and cllck Copy. The Create
Object Directory Entry screen wlll Lhen reappear and, as before you should asslgn Lhe
entry to Local object. The status bar will confirm the success of the copy:

The new program name will then appear in the Program text box of the ABAP Editor
lnlLlal screen. now cllck Lhe Change buLLon Lo enLer Lhe codlng screen.
1he copy funcLlon wlll have reLalned Lhe prevlous reporL name ln Lhe commenL space aL
Lhe Lop of your program and ln Lhe lnlLlal 8LC81 sLaLemenL, so lL ls lmporLanL Lo
remember Lo updaLe Lhese. Also, deleLe Lhe LlnL-SlZL llmlL, so LhaL Lhls does noL geL ln Lhe
way of LesLlng Lhe program.

75
YOUR FIRST ABAP PROGRAM

8ecause Lhere are a number of SLLLC1 and W8l1L sLaLemenLs ln Lhe program, lL ls worLh
looklng aL how Lo use Lhe fasL commenL faclllLy. 1hls allows code Lo be, ln pracLlcal Lerms,
removed from Lhe program wlLhouL deleLlng lL, maklng lL lnLo commenLs, usually by
lnserLlng an asLerlsk (*) aL Lhe beglnnlng of each llne. 1o do Lhls qulckly, hlghllghL Lhe llnes
Lo be made lnLo commenL and hold down C18L + <. 1hls wlll auLomaLlcally commenL Lhe
lines selected. Alternatively, the text can he highlighted and then in the Utilities menu,
select Block/Buffer and then Insert Comment *. The selected code is now converted to
commenL:

ueleLe mosL of Lhe code from Lhe program now, reLalnlng one secLlon Lo conLlnue worklng
wlLh.
Dec|ar|ng Var|ab|es
A fleld ls a Lemporary area of memory whlch can be glven a name and referenced wlLhln
programs. llelds may be used wlLhln a program Lo hold calculaLlon resulLs, Lo help conLrol
Lhe loglc flow and, because Lhey are Lemporary areas of sLorage (usually held ln Lhe 8AM),
can be accessed very fast, helping to speed up the programs execution. There are, of
course, many oLher uses for flelds.

76
YOUR FIRST ABAP PROGRAM
1he nexL quesLlon Lo examlne ls LhaL of varlables, and how Lo declare Lhem ln a program.
A varlable ls a fleld, Lhe values of whlch change durlng Lhe program execuLlon, hence of
course Lhe Lerm varlable.
1here are some rules Lo be followed when deallng wlLh varlables:
1hey musL begln wlLh a leLLer.
Can be a maxlmum slze of 30 characLers,
CannoL lnclude + , : or ( ) ln Lhe name,
CannoL use a reserved word.
When creaLlng varlables, lL ls useful Lo ensure Lhe name glven ls meanlngful. namlng
varlables Lhlngs llke A1, A2, A3 and so on ls only llkely Lo cause confuslon when oLhers
come to work with the program. Names like, in the example here, Surname, Forename,
DOB are much better, as from the name it can be ascerLalned exacLly whaL Lhe fleld
represenLs.
varlables are declared uslng Lhe uA1A sLaLemenL. 1he flrsL varlable Lo be declared here
wlll be an lnLeger fleld. 8elow Lhe secLlon of code remalnlng ln your program, Lype Lhe
sLaLemenL DA1A followed by a name for Lhe fleld - |nteger01. 1hen, Lhe daLa Lype musL be
declared uslng Lhe word 1L and for lnLegers Lhls ls referred Lo by Lhe leLLer |. 1ermlnaLe
Lhe sLaLemenL wlLh a perlod.

1ry anoLher, Lhls Llme named packed_dec|ma|01, Lhe daLa Lype for whlch ls p. A packed
declmal fleld ls Lhere Lo help sLore numbers wlLh declmal places. lL ls posslble Lo speclfy
Lhe number of declmal places you wanL Lo sLore. After the p, type the word dec|ma|s and
Lhen Lhe number deslred, ln Lhls lnsLance, 2 (packed declmal can sLore up Lo 14 declmal
places). 1ype all of Lhls, Lhen save Lhe program:


77
YOUR FIRST ABAP PROGRAM
1hese daLa Lypes used are called elemenLary. 1hese Lypes of varlables have a flxed lengLh
ln A8A, so lL ls noL necessary Lo declare how long Lhe varlables need Lo be.
1here ls anoLher way of declarlng varlables, vla Lhe LIkL addlLlon Lo Lhe uA1A sLaLemenL.
ueclare anoLher varlable, Lhls Llme wlLh Lhe name packed_dec|ma|02 buL, raLher Lhan
uslng Lhe 1?L addlLlon Lo deflne Lhe fleld Lype, use Lhe word LlkL, followed by Lhe
previous variables name packed_decimal01. This way, you can ensure subsequenL
varlables Lake on exacLly Lhe same properLles as a prevlously creaLed one. Copy and pasLe
Lhls several Llmes Lo creaLe packed_declmal03 and 04.
lf you are creaLlng a large number of varlables of Lhe same daLa Lype, by uslng Lhe LlkL
addlLlon, a loL of Llme can be saved. lf, for example, Lhe uLClMALS parL were Lo need Lo
change Lo 3, lL would Lhen only be necessary Lo change Lhe number of declmals on Lhe
orlglnal varlable, noL all of Lhem lndlvldually:

AddlLlonally, Lhe LlkL addlLlon does noL only have Lo refer Lo varlables, or flelds, wlLhln Lhe
program. lL can also refer Lo flelds LhaL exlsL ln Lables wlLhln Lhe SA sysLem. ln Lhe Lable
we creaLed Lhere was a field named Surname. Create a new variable called
new_surname uslng Lhe uA1A sLaLemenL. When deflnlng Lhe daLa Lype use Lhe LlkL
addlLlon followed by zemp|oyees-surname. ueflnlng flelds Lhls way saves you from havlng
Lo remember Lhe exacL daLa Lype form every fleld you have Lo creaLe ln Lhe SA sysLem.

Check Lhls for synLax errors Lo make sure everyLhlng ls correcL. lf Lhere are no errors
remove Lhe oew_sotoome, pockeJ_Jeclmol02, 0J and 04 flelds as Lhey are no longer
needed.
WlLh anoLher addlLlon whlch can be made Lo Lhe uA1A sLaLemenL, one can declare lnlLlal
values for Lhe varlables deflned ln Lhe program. lor Lhe lnLeger01 variable, after TYPE
i, add Lhe followlng addlLlon: VALUL 22. 1hls wlll auLomaLlcally asslgn a value of 22 Lo

78
YOUR FIRST ABAP PROGRAM
lnLeger01 when Lhe program sLarLs.
lor packed declmal flelds Lhe process ls sllghLly dlfferenL. 1he vALuL here musL be
speclfled wlLhln slngle quoLaLlon marks, 5.5 as wlLhouL Lhese, Lhe A8A sLaLemenL would
be LermlnaLed by Lhe perlod ln Lhe declmal. noLe LhaL one ls noL [usL llmlLed Lo poslLlve
numbers. lf you wanL Lo declare a value of a negaLlve number, Lhls ls enLlrely posslble:

Constants
A consLanL ls a varlable whose assoclaLed value cannoL be alLered by Lhe program durlng
lLs execuLlon, hence Lhe name. ConsLanLs are declared wlLh Lhe CCnS1An1S sLaLemenL
(where Lhe uA1A sLaLemenL appeared for varlables). When wrlLlng code Lhen, Lhe
consLanL can only ever be referred Lo, lLs value can never change. lf you do Lry Lo change a
ConsLanLs value wlLhln Lhe program, Lhls wlll usually resulL ln a runLlme error.
1he synLax for declarlng consLanLs ls very slmllar Lo LhaL of declarlng varlables, Lhough
Lhere are a few dlfferences. ?ou sLarL wlLh Lhe sLaLemenL CCNS1AN1S. use Lhe name
myconstant01 for Lhls example. Clve lL a Lype p as before wlLh 1 declmal place and a value
of 6.6. Copy and pasLe and Lry anoLher wlLh Lhe name myconstant02, Lhls Llme a
standard integer (type |) with a value of 6:

(A oote. ooe coooot Jefloe coostoots fot Joto types \51klNC5, tefeteoces, lotetool tobles
ot sttoctotes cootololoq lotetool tobles.)


79
ARITHMETIC
Chapter 4

Ar|thmet|c Add|t|on
now LhaL Lhe ablllLy Lo creaLe varlables has been esLabllshed, Lhese can be used for
calculaLlons wlLhln a program. 1hls chapLer wlll begln by looklng aL some of Lhe slmple
arlLhmeLlcal calculaLlons wlLhln A8A.
Cur program wlll be Lldled up by removlng Lhe Lwo consLanLs whlch were [usL creaLed. lf a
program needs Lo add Lwo numbers LogeLher and each number ls sLored as lLs own unlque
varlable, Lhe producL of Lhe Lwo numbers can be sLored ln a brand new varlable LlLled
result.
Create a new DATA statement, name this resu|t and use the LIKE statement to give it the
same properLles as packed_declmal01, LermlnaLlng Lhe llne wlLh a perlod.
To add two numbers together, on a new line, type resu|t = |nteger01 +
packed_dec|ma|01. Cn a new llne enLer, WkI1L resu|t. Activate and LesL Lhe program,
and Lhe resulL wlll appear ln Lhe ouLpuL screen:



80
ARITHMETIC
%N'GO8 (" &)2)2P)&: lor any arlLhmeLlcal operaLlon, Lhe calculaLlon lLself musL appear Lo
Lhe rlghL of Lhe =, and Lhe varlable Lo hold Lhe resulL Lo Lhe lefL. 1hls ensures LhaL only Lhe
result variable will be updated in the execution. If the variable titled result had been
asslgned a value prlor Lo Lhe calculaLlon, Lhls would be overwrlLLen wlLh Lhe new value.
Spaces musL always be lnserLed on elLher slde of Lhe = and + slgns. 1hls applles Lo all
arlLhmeLlcal operaLors, lncludlng parenLheses ( ), whlch wlll sLarL Lo be used as Lhe
calculaLlons become more compllcaLed. noLe LhaL one space ls Lhe mlnlmum, and mulLlple
spaces can be used, whlch may help ln llnlng code up Lo make lL more readable, and
lndeed where calculaLlons may be deflned over many llnes of code.
lL ls noL [usL Lhe producLs of varlables whlch can be calculaLed ln calculaLlons, buL also
lndlvldual llLeral values, or a mlxLure of Lhe Lwo, as shown here:

Ar|thmet|c Subtract|on
1o subLracL numbers, Lhe same meLhod ls used, replaclng Lhe + wlLh a -. Copy and pasLe
Lhe prevlous calculaLlon and make Lhls change. Also, Lo make Lhls slmpler Lo undersLand,
change Lhe value of packed_declmal01 from -3.3 Lo 3.3. Cne can see by dolng Lhls Lhe way
LhaL changlng Lhe lnlLlal varlable wlll alLer Lhe calculaLlon.
LxecuLe Lhe code:



81
ARITHMETIC
Ar|thmet|c D|v|s|on
1o dlvlde numbers, Lhe same meLhod ls followed, buL Lhe arlLhmeLlcal operaLor Lhls Llme
wlll be a ]


Ar|thmet|c Mu|t|p||cat|on
1o mulLlply, Lhe operaLor ls a *


AddlLlonally Lo Lhese meLhods, Lhe sLaLemenLs ADD, SU81kAC1, DIVIDL and MUL1IL
can be used. 1he synLax for Lhese ls sllghLly dlfferenL. 8eneaLh Lhe flrsL calculaLlon (where
lnLeger01 and packed_declmal01 where added), wrlLe a new llne of code
ADD 8 to resu|t. (lgnore Lhe commenL llne ln Lhe lmage):


Whlle Lhls ls a leglLlmaLe meLhod for calculaLlons, lL musL be added LhaL Lhls ls very rarely
used, as Lhe lnlLlal meLhod ls much slmpler.

82
ARITHMETIC
Convers|on ku|es
ln Lhls program, dlfferenL daLa Lypes have been used when declarlng varlables. lL ls Lhe
responslblllLy of Lhe programmer Lo ensure Lhe daLa Lypes used are compaLlble wlLh one
anoLher when used for calculaLlons or movlng daLa Lo and from ob[ecLs. Cne should noL
aLLempL calculaLlons wlLh varlables and numbers whlch do noL maLch.
lor example, a varlable deflned as an lnLeger cannoL be mulLlplled by a characLer, as Lhese
Lwo daLa Lypes are lncompaLlble. 1hls would cause Lhe sysLem Lo generaLe synLax and
runLlme errors when Lhe program ls execuLed. Whlle SA has bullL ln auLomaLlc daLa Lype
converslons for many of Lhe sLandard daLa Lypes wlLhln A8A, Lhere are scenarlos where
Lhe lnbullL converslon rules are noL approprlaLe. lL ls lmporLanL Lo become famlllar wlLh
Lhe lnbullL converslon rules and know when Lo manlpulaLe Lhe daLa prlor Lo uslng Lhem ln
calculaLlons. Pere, some examples of converslon rules wlll be glven, so LhaL Lhey can be
used LhroughouL programs creaLed.
Converslon rules are pre-deflned loglc LhaL deLermlne how Lhe conLenLs of Lhe source fleld
can be enLered lnLo a LargeL fleld. lf one aLLempLs Lo lnserL an lnLeger fleld conLalnlng Lhe
value of 1 Lo a characLer sLrlng, Lhe bullL-ln converslon rules wlll deLermlne exacLly how
Lhls should be done wlLhouL any synLax or runLlme errors.
For example, create a DATA statement with the name num1 of 1L p (packed declmal)
wlLh DLCIMALS 2 and a VALUL of 3.33. 1hen creaLe anoLher varlable wlLh Lhe name
resu|t1 of type | (integer). Attempt the calculation resu|t1 = num1. The conversion
rule here would round Lhe number Lo Lhe closesL lnLeger, ln Lhls case 3.


As you work wlLh dlfferenL daLa Lypes, Lhese klnds of converslon rules wlll ofLen be applled
auLomaLlcally, and lL ls up Lo you, Lhe programmer, Lo undersLand Lhese converslon rules

83
ARITHMETIC
and Lhe daLa Lypes used wlLhln Lhe program Lo ensure no runLlme errors occur.
D|v|s|on Var|at|ons
now, a sllghL sLep back wlll be Laken Lo dlscuss Lhe dlvlslon operaLor furLher. ln A8A,
Lhere are Lhree ways ln whlch numbers can be dlvlded:
1he sLandard resulL wlLh declmal places
1he remalnder resulL
1he lnLeger resulL.
!2% ,+"*;".; ('.E '( ;4C4,4'*F
Create 2 variables, numa and numb, with values of S.4S and 1.48 respecLlvely, Lhen
creaLe the variable resu|t2 (also with 2 decimal places). Then insert the calculation
resu|t2 = numa ] numb. followed by a WkI1L sLaLemenL for resulL2. LxecuLe Lhe
program.


!2% 4*+%D%. ('.E '( ;4C4,4'*F
Copy Lhe lnlLlal calculaLlon, change the initial variables to numc and numd and the
resulting variable to resu|t3. For integer division, rather than using the standard ], use
Lhe operaLor DIV. 1hls will give the result of the calculations integer value, without the
declmal places.

84
ARITHMETIC


!2% .%E"4*;%. ('.E '( ;4C4,4'*F
Follow the steps from the integer form, this time with nume, numf and resu|t4. For
Lhls Lype of dlvlslon, Lhe arlLhmeLlcal operaLor should be MCD. 1hls, when execuLed, wlll
show Lhe remalnder value.





85
CHARACTER STRINGS
Chapter S Character Str|ngs
Dec|ar|ng C and N I|e|ds
1hls chapLer wlll dlscuss characLer sLrlngs. When creaLlng programs, flelds deflned as char-
acLer sLrlngs are almosL always used. ln SA, Lhere are Lwo elemenLary daLa Lypes used for
characLer sLrlngs. 1hese are daLa Lype C, and daLa Lype N.
3"+" +95% )F
uaLa Lype C varlables are used for holdlng alphanumerlc characLers, wlLh a mlnlmum of 1
characLer and a maxlmum of 63,333 characLers. 8y defaulL, Lhese are allgned Lo Lhe lefL.
8egln Lhls chapLer by creaLlng a new program. From the ABAP Editors initial screen, cre-
aLe a new program, named 2_Character_Str|ngs. Title this Character Str|ngs Lxam-
p|es, set the Type to Lxecutab|e program, the Status to 1est program, the ApplicaLlon
to 8as|s, and Save.
Create a new DATA field, name this mychar and, without any spaces following this, give
a number for Lhe lengLh of Lhe fleld ln parenLheses. 1hen, lnclude a space and deflne Lhe
1?L as c

1hls ls Lhe long form of declarlng a Lype c fleld. 8ecause Lhls fleld ls a generlc daLa Lype,
Lhe sysLem has defaulL values whlch can be used so as Lo avold Lyplng ouL Lhe full lengLh of
Lhe declaraLlon. lf you create a new field, named mychar2 and wlsh Lhe fleld Lo be 1
characLer ln slze, Lhe defaulL fleld slze ls seL Lo 1 characLer by defaulL, so Lhe slze ln brack-
eLs followlng Lhe name ls unnecessary. Also, because Lhls characLer fleld ls Lhe defaulL
Lype used by Lhe sysLem, one can even avold deflnlng Lhls. ln Lhe case of mychar2, Lhe
varlable can be deflned wlLh only Lhe fleld name. 1he code ln Lhe lmage below performs
exactly the same as if it was typed data mychar2(1) type c:


86
CHARACTER STRINGS
ln Lhe prevlous chapLer, the table zemployees included various fields of type c, such as
zsurname. If one uses the TABLES statement followed by zemployees, then by double-
cllcklng Lhe Lable name Lo use forward navlgaLlon and vlew Lhe Lable, one can see LhaL Lhe
surname field is of data type CHAR, with length 40. This declaration can be replicated
wlLhln Lhe A8A program:

8eLurn Lo Lhe program, and ln place of mychar2, create a new field named zemp|oy-
ees1, with a length of 40 and Lype c. 1hls wlll have exacLly Lhe same effecL as Lhe prevlous
declaraLlon. 8eferrlng back Lo prevlous chapLer, anoLher way of dolng Lhls would be Lo use
Lhe LlkL sLaLemenL Lo declare zemployees (or Lhls Llme zemployees2) as havlng Lhe same
properties as the surname field in the table:

3"+" +95% BF
1he oLher common generlc characLer sLrlng daLa Lype ls n. 1hese are by defaulL rlghL-
allgned. lf one looks aL Lhe lnlLlal Lable agaln, uslng forward navlgaLlon, Lhe fleld named
employee, which refers to employee numbers, is of the data type NUMC, with a length
of 8. nuMC, or Lhe number daLa Lype, works slmllarly Lo Lhe characLer daLa Lype, excepL
wlLh Lhe lnbullL rule Lo only allow Lhe lncluslon of numerlc characLers. 1hls daLa Lype, Lhen,
ls ldeal when Lhe fleld ls only Lo be used for numbers wlLh no lnLenLlon of carrylng ouL cal-
culaLlons.

To declare this field in ABAP, create a new DATA field named znumber1, TYPE n. Agaln,
alLernaLlvely Lhls can be done by uslng Lhe LlkL sLaLemenL Lo refer back Lo Lhe orlglnal
fleld ln Lhe Lable.


87
CHARACTER STRINGS
Str|ng Man|pu|at|on
Llke many oLher programmlng languages, A8A provldes Lhe funcLlonallLy Lo lnLerrogaLe
and manlpulaLe Lhe daLa held ln characLer sLrlngs. 1hls secLlon wlll look aL some of Lhe
popular sLaLemenLs whlch A8A provldes for carrylng ouL Lhese funcLlons:
ConcaLenaLlng SLrlng llelds
Condenslng CharacLer SLrlngs
llndlng Lhe LengLh of a SLrlng
Searchlng for Speclflc CharacLers
1he SPll1 sLaLemenL
SpllLLlng CharacLer SLrlngs
Subllelds
Concatenate
1he concaLenaLe sLaLemenL allows Lwo characLer sLrlngs Lo be [olned so as Lo form a Lhlrd
sLrlng. llrsL, Lype Lhe sLaLemenL CCNCA1LNA1L lnLo Lhe program, and follow Lhls by specl-
fylng Lhe fields, here f1, f2 and so on. Then select the destination which the outpuL
string should go to, here d1. If one adds a subsequent term, [separated by sep] (sep
here ls an example name for Lhe separaLor fleld), Lhls wlll allow a speclfled value Lo be ln-
serLed beLween each fleld ln Lhe desLlnaLlon fleld:

Note. lf tbe Jestlootloo flelJ ls sbottet tboo tbe ovetoll leoqtb of tbe lopot flelJs, tbe cbot-
octet sttloq wlll be ttoocoteJ to tbe leoqtb of tbe Jestlootloo flelJ, so eosote wbeo osloq
tbe cONcA1NA1 stotemeot, tbe sttloq Joto type ls beloq oseJ, os tbese coo bolJ ovet
65,000 cbotoctets.
As an example, observe Lhe code ln Lhe lmage below.

88
CHARACTER STRINGS

1he flrsL 3 flelds should be famlllar by now. 1he fourLh ls Lhe separaLor fleld, here agaln
called sep (the size of sep has not been defined here, and so it will take on the default
whlch Lhe sysLem uses - 1 character). The last field is titled destination, 200 characters
long and of daLa Lype c.
8elow Lhls secLlon ls Lhe CCnCA1LnA1L sLaLemenL, followed by Lhe flelds Lo comblne Lo-
geLher lnLo Lhe desLlnaLlon fleld. 1he W8l1L sLaLemenL ls Lhen used Lo dlsplay Lhe resulL.
LxecuLlng Lhls code wlll ouLpuL Lhe followlng:

noLe LhaL Lhe LexL has been allgned Lo Lhe lefL, as lL ls uslng daLa Lype c. Also, Lhe code dld
noL lnclude Lhe SLAkA1LD 8 addlLlon, and so Lhe words have been concaLenaLed wlLh-
ouL spaces. 1hls can be added, and spaces wlll appear ln Lhe ouLpuL:


Condense
nexL, Lhe CCnuLnSL sLaLemenL. CfLen an A8A program wlll have Lo deal wlLh large LexL
flelds, wlLh unwanLed spaces. 1he CCnuLnSL sLaLemenL ls used Lo remove Lhese blank
characLers.
now, observe Lhe code below:

89
CHARACTER STRINGS

1hls should, of course, be mosLly famlllar from Lhe lasL secLlon, wlLh Lhe addlLlon of Lhe
new, 20-character spaced_name field, with large spaces between the individual words.
8elow we have an example of uslng Lhe CCnuLnSL sLaLemenL uslng our new varlable:

1he CCnuLnSL sLaLemenL wlll remove Lhe blank spaces beLween words ln Lhe varlable,
leaving only 1 characters space:

!"#$%&'
An opLlonal addlLlon Lo Lhe CCnuLnSL sLaLemenL ls NC-GAS, whlch as you may guess,
removes all spaces from our varlable.


I|nd the Length of a Str|ng
1o flnd Lhe lengLh of a sLrlng, a funcLlon raLher Lhan a sLaLemenL ls used. Added beneaLh
the previous data fields here, is a new one titled |en, with a TYPE |, so as Lo [usL hold Lhe
lnLeger value of Lhe sLrlng lengLh.


90
CHARACTER STRINGS
1he code Lo flnd Lhe lengLh of Lhe surname field and display it in the len field appears
like this, with str|en deflnlng Lhe funcLlon:

1he ouLpuL, Lhen, wlll appear llke Lhls:

kep|ace
8elow l have creaLed Lhe surname2 fleld and ls 40 characLers ln lengLh. noLe LhaL no
1?L has been deflned, so Lhe sysLem wlll use Lhe defaulL Lype, c:

Some LexL ls Lhen moved lnLo Lhe fleld afLer whlch Lhe kLLACL sLaLemenL ls used Lo re-
place Lhe comma wlLh a perlod:


Cne Lhlng Lo noLe here ls LhaL Lhe 8LLACL sLaLemenL wlll only replace Lhe flrsL occurrence
in the string. So if, for example, the surname2 field read Mr, Joe, Smith, only the first
comma would be changed. All occurrences of commas could be replaced by maklng use
of a wblle loop, whlch wlll be dlscussed laLer on.
Search
nexL, a look wlll be Laken aL searchlng for speclflc characLer sLrlngs wlLhln flelds. unsur-
prlslngly, Lhe sLaLemenL SLAkCn ls used for Lhls.

91
CHARACTER STRINGS
All LhaL ls needed ls Lo enLer SLAkCn followed by Lhe fleld whlch ls Lo be searched, ln Lhls
lnsLance Lhe surname2 fleld. 1hen Lhe sLrlng whlch ls Lo be searched for, for example,
Ioe:

noLe LhaL here no varlable has been declared Lo hold Lhe resulL. ln Lhe case of Lhe SLA8CP
sLaLemenL, Lwo system variables are used. The first is sy-subrc, which identifies whether
the search was successful or not, and the second is sy-fdpos, which, if the search is suc-
cessful, ls seL Lo Lhe poslLlon of Lhe characLer sLrlng searched for ln sotoome2. 8elow, a
small reporL ls creaLed Lo show Lhe values of Lhe sysLem varlables.

?:7G)H :I"E5$% J
1he flrsL SLA8CP sLaLemenL, below, lndlcaLes LhaL Lhe surname2 fleld ls belng searched,
for Lhe character string Joe . 1he Search sLaLemenL wlll lgnore Lhe blank spaces. 1he
ouLpuL wlll show Lhe sLrlng belng searched for, followed by Lhe sysLem varlables and Lhe
value resulLs. ln Lhls case, Lhe search should be successful.

?:7G)H :I"E5$% K
1he nexL example ls very slmllar, buL Lhe full sLops elLher slde of .Ioe . mean that the
blank spaces Lhls Llme wlll noL be lgnored and Lhe sysLem wlll search for Lhe full sLrlng,
including the blanks. Here, the search will be unsuccessful, as the word Ioe in the
5otoome2 fleld ls noL followed by four blank spaces.


92
CHARACTER STRINGS
?:7G)H :I"E5$% L
1hls Lhlrd search uses a wlld card character * and wlll search for any words endlng ln
|th. This, again, should be successful.

?:7G)H :I"E5$% M
1he lasL example also uses Lhe wlld card faclllLy, Lhls Llme Lo search for words beglnnlng
wlLh Sm|, which again should be successful. Compare the places in the code where the *
appears ln Lhls and Lhe prevlous example.

8un a LesL on Lhese searches, and ouLpuL reLurns as follows:

When Lhe sy-subrc = 0 Lhls refers Lo a successful search. When sy-subrc = 4 ln Lhe second
example Lhls lndlcaLes LhaL Lhe search was unsuccessful.

93
CHARACTER STRINGS
ln Lhe flrsL search, Lhe sy-fdpos value of 3 refers Lo Lhe Lhlrd characLer ln Lhe surname2
fleld, tbe offset, and Lhe search Lerm appears one characLer afLer Lhls. 1he fallure of Lhe
second search means LhaL a 0 ls dlsplayed ln Lhe sy-fdpos fleld. 1he value of 7 ln Lhe sy-
fdpos flelds for Lhe flnal two searches both mean that the word Smith was found, corre-
spondlng Lo Lhe search Lerms, and LhaL Lhe searched word appears 1 characLer afLer Lhe
offseL value.
Sh|ft
1he SnII1 sLaLemenL ls a slmple sLaLemenL LhaL allows one Lo move Lhe conLenLs of a
character string left or right, character by character. In this example, a fields contents will
be moved Lo Lhe lefL, deleLlng leadlng zeros. ueclare a new uA1A varlable as follows:
emp|_num, 10 characters long, and set the content of the field to 00006S4321, filling
all 10 characLers of Lhe fleld:


uslng Lhe SPll1 sLaLemenL, Lhen, Lhe 4 zeros whlch begln Lhls characLer sLrlng wlll be re-
moved, and Lhe resL moved across Lo Lhe lefL. 1ype Lhe sLaLemenL SPll1, followed by Lhe
fleld name. ueflne LhaL lL ls Lo be shlfLed Lo Lhe lefL, deleLlng leadlng zeros (dont forget
Lhe help screen can be used Lo vlew slmllar addlLlons whlch can be added Lo Lhls sLaLe-
menL). 1hen lnclude a W8l1L sLaLemenL so LhaL Lhe resulL of Lhe SPll1 sLaLemenL can be
ouLpuL. 1o Lhe rlghL of Lhe number here, Lhere wlll be four spaces, whlch have replaced
Lhe leadlng zeros:



94
CHARACTER STRINGS
lf no addlLlon Lo Lhe SPll1 sLaLemenL ls speclfled, Lhe sysLem wlll by defaulL move every-
Lhlng [usL one characLer Lo Lhe lefL, leavlng one space Lo Lhe rlghL:


1he CIkCULAk addlLlon Lo Lhe SPll1 sLaLemenL wlll cause, by defaulL, everyLhlng Lo move
one space Lo Lhe lefL agaln, buL Lhls Llme Lhe characLer whlch ls dlsplaced aL Lhe beglnnlng
of Lhe sLaLemenL wlll reappear aL Lhe end, raLher Lhan leavlng a blank space:


Sp||t
1he SLl1 sLaLemenL ls used Lo separaLe Lhe conLenLs of a fleld lnLo Lwo or more flelds.
Cbserve Lhe code below:


95
CHARACTER STRINGS
The first section contains several DATA statements, mystr|ng, a1, a2, a3 and
sep2, along with their lengths and types. Sep2 here ls a separaLor fleld, wlLh a value of
**.
mystr|ng is then given a value of 1234** A8CD **6789, followed by a comment line
(whlch Lhe program wlll lgnore), Lhen a W8l1L sLaLemenL, so LhaL Lhls lnlLlal value appears
ln Lhe ouLpuL followed by a blank llne, uslng Lhe Skl sLaLemenL.
1he SLl1 sLaLemenL appears, followed by Lhe name of Lhe sLrlng whlch ls Lo be spllL. 1he
A1 addition appears next, telling the program that, where sep2 appears (remember the
value of this is **), the field is to be spllL. lollowlng Lhls, Lhe IN1C Lhen speclfles Lhe
flelds whlch Lhe spllL fleld ls Lo be wrlLLen Lo. 1he sllghLly odd poslLlonlng of Lhe spaces ln
the value of mystring will, when the statement is output, make clear the way that the
SLl1 sLaLemenL populaLes Lhe flelds whlch Lhe daLa ls puL lnLo. LxecuLe Lhe code, and Lhls
ls Lhe resulL:

?ou can see LhaL Lhe lnlLlal fleld has been spllL lnLo a1, a2 and a3 exacLly where Lhe ** ap-
peared, leavlng a leadlng space ln Lhe flrsL Lwo flelds, buL noL ln Lhe Lhlrd. AddlLlonally, on
closer lnspecLlon Lhere are blank spaces followlng Lhe numbers ln each fleld up Lo lLs de-
flned lengLh, whlch ls 10.
1hls nexL example shows Lhe lnlLlal value of mystring now is made into a comment line,
and Lhe commenL llne becomes parL of Lhe code:


96
CHARACTER STRINGS
mystring now contains the original contents plus a furLher seL of characLers. Whlle Lhe
conLenLs are sLlll Lo be spllL lnLo 3 flelds, Lhe daLa suggesLs lL should be spllL lnLo 4. ln Lhls
case, wlLh less flelds Lhan Lhose deflned, Lhe sysLem wlll lnclude Lhe remalnder of Lhe
sLrlng ln Lhe flnal fleld. noLe LhaL lf Lhls fleld ls noL long enough for Lhe remalnder, Lhe re-
sulL would be LruncaLed.

SubI|e|ds
WlLhln A8A, you have Lhe opLlon of referrlng Lo speclflc characLers wlLhln a fleld. 1hls ls
referred Lo as processlng 8FP1')6Q8, whereby a specific characters position within its field
ls referenced. Agaln, observe Lhe code below:

1o sLarL wlLh, new uATA variables are declared, |nt_te|ephone_num, country_code
and te|ephone_num, along with lengths and types. Following this, a character string is
asslgned Lo lnL_Lelephone_num, a W8l1L sLaLemenL for Lhls sLrlng and a blank llne.

97
CHARACTER STRINGS
nexL, Lhe subfleld processlng appears. 1he flrsL llne sLaLes Lhe coootty_coJe fleld ls Lo be
fllled wlLh Lhe flrsL 3 characLers of Lhe lot_telepbooe_oom fleld, lndlcaLed by Lhe number
ln brackeLs.
1hen, Lhe fleld telepbooe_oom ls Lo be fllled wlLh 13 characLers of Lhe lot_telepbooe_oom
fleld, sLarLlng afLer Lhe 4
Lh
characLer. 1he +4 parL of Lhe code here refers Lo where Lhe fleld
ls Lo begln. 1hen we have W8l1L sLaLemenLs for boLh of Lhe flelds.
1hls lasL example lndlcaLes LhaL Lhe speclflc characLers of lot_telepbooe_oom moved Lo
Lhe coootty_coJe fleld wlll be replaced, afLer Lhe flrsL characLer, by Lhe llLeral, 2-characLer
value 01, showing that a subfield can itself be edited and updated without changing the
lnlLlal fleld. 1he resulLs should look llke Lhls:

Subflelds are regularly used ln SA Lo save Llme on creaLlng unnecessary varlables ln
memory. lL ls [usL as easy Lo use Lhe subfleld synLax.



98
DEBUGGING PROGRAMS
Chapter 6 Debugg|ng rograms

1hls chapLer wlll lnLroduce Lhe A8A debugger, and wlll lnLroduce some of Lhe Lools whlch
can be used Lo ensure LhaL Lhe programs you creaLe funcLlon as lnLended. lL wlll also show
ways Lo hlghllghL loglc bugs ln programs LhaL cannoL be ldenLlfled by Lhe synLax checker.
1he flrsL sLep here ls Lo load a program whlch has been used prevlously, and whlch ac-
cesses Lhe daLabase Lable whlch has been creaLed regardlng employee records. lf you
have been followlng along wlLh lnsLrucLlons, load program Z_Employee_List_01 lnLo Lhe
A8A LdlLor.
1he program conLalns a number of SLLLC1 loops, whlch ln Lurn wrlLe Lhe conLenLs of Lhe
Lable belng read Lo Lhe ouLpuL screen ln several ways, separaLed by uLlnL sLaLemenLs:

Pavlng examlned Lhe code, reLurn Lo Lhe fronL screen of Lhe A8A edlLor.

99
DEBUGGING PROGRAMS
llrsLly, on Lhls screen you will notice there is a Debugging button in the toolbar (also ac-
cesslble wlLh SPll1+l3):

Cllck Lhls wlLh Lhe program name ln Lhe program lnpuL LexL box Lo sLarL a new debugglng
sesslon. When Lhls opens, a blue arrow should be vlslble, polnLlng aL Lhe flrsL llne of code
ln Lhe program:

An alLernaLlve way of sLarLlng a debugglng sesslon ls Lo dlsplay Lhe code lLself from Lhe
lnlLlal screen, selecL a llne of code and seL a breakpolnL. 1hls ls done by, havlng selecLed a
llne, cllcklng Lhe SLop lcon:
1hls seLs a breakpolnL for LhaL llne. When Lhe program ls Lhen execuLed Lhe execuLlon wlll
pause hlghllghLlng Lhe llne LhaL has Lhe 8reakpolnL seL enLerlng Lhe debugglng sesslon.
usually, Lhls ls Lhe easlesL meLhod Lo use, as one wlll ofLen have a good ldea of where Lhe

100
DEBUGGING PROGRAMS
lssues ln a program are allowlng you Lo focus on speclflc areas of code sLralghL away,
raLher Lhan sLarLlng from Lhe very beglnnlng of a program as Lhe prevlous meLhod does:


1here are Lwo Lypes of breakpolnL whlch can be seL ln a program. SLaLlc (whlch wlll be ex-
amlned laLer) and dynamlc. A dynamlc breakpolnL ls Lhe klnd whlch was used above, and
Lhese are only valld for Lhe currenL sesslon. lf one leaves Lhe SA Cul and reLurns laLer,
any dynamlc breakpolnLs seL wlll no longer exlsL. A breakpolnL can also be seL by double-
cllcklng any sLaLemenL wlLhln Lhe debugglng sesslon lLself. 1o Lhen remove Lhese ln Lhe
sesslon, slmple double-cllck Lhe sLop lcon appearlng ad[acenL Lo Lhem.
?ou wlll noLlce LhaL a number of buLLons appear aL Lhe Lop of Lhe debugglng screen:

1hese buLLons allow for dlfferenL modes of Lhe A8A debugger Lo be enLered. 1he defaulL
mode here ls llelJs.
The Single step button, the first on the left in the row above the modes, also accessible
wlLh l3, allows one Lo go Lhrough Lhe code wlLhln Lhe debugger llne-by-llne, or lndeed as
lLs name would suggesL, slngle sLeps. As one presses Lhe buLLon, Lhe blue arrow on Lhe lefL
of Lhe code wlll move down one llne aL a Llme.
1he nexL buLLon along is the Execute button, with a shortcut of F6. This allows for inde-
pendenL secLlons of code Lo be execuLed, such as funcLlon modules or forms. 1hls can be
very useful. lf a program lncludes exlsLlng secLlons of code already creaLed ln an SA sys-

101
DEBUGGING PROGRAMS
Lem whlch are known Lo be correcL, Lhere ls no need Lo debug Lhem. 1hese can Lhen be
execuLed lndependenLly, whlle oLher parLs are debugged Lo flnd speclflc problems.
The next button is the Return function (F7). This can be very useful if one forgets to use
the Execute function. If one goes through the lines of a program step-by-sLep, uslng Lhe
l3 key Lo sLep lnLo a worklng funcLlon module, whlch may conLaln many llnes of code, lL ls
llkely Lhe case LhaL lL does noL need Lo be debugged (because you know Lhls funcLlon
module already exlsLs). resslng Lhe l3 key endlessly Lo go Lhrough Lhe llnes of code here
ls unnecessary when one wanLs Lo sLep ouL of Lhls funcLlon module and access Lhe parLs
which require debugging. Using the Return button, all of the code within a specific func-
Llon can be execuLed, reLurnlng Lo Lhe llne of code whlch calls LhaL funcLlon.
The fourth in the row is the Continue option (F8). This allows one Lo conLlnue Lhe pro-
gram wlLhouL golng Lhrough sLep-by-sLep, llne-by-llne. When Lhls buLLon ls pressed, Lhe
program execuLes and Lhe ouLpuL screen ls shown. 1hls buLLon can also be used Lo [usL
access a selecLed llne of code, where Lhe cursor ls poslLloned. lf one poslLlons Lhe cursor ln
a llne of code and presses conLlnue, Lhe blue arrow ln Lhe debugger wlll appear dlrecLly
nexL Lo LhaL llne. lf you Lhen press conLlnue agaln, Lhe program wlll be execuLed.
1he nexL opLlon ln Lhls row of Lhe Loolbar is Display list, accessible with CTRL+F12. This
Lakes you Lo Lhe ouLpuL screen as lL currenLly sLands wlLhln Lhe debug sesslon. Pere, Lhe
code has been execuLed Lo ouLpuL Lhe resulL of Lhe flrsL SLLLC1 sLaLemenL ln Lhe program:

1hls funcLlon allows you Lo see Lhe resulLs of Lhe reporLs whllsL Lhe program ls ln mld-flow.
The last option here is Create watchpoint (SHIFT + F8). Watchpoints will be returned to
soon.

102
DEBUGGING PROGRAMS
I|e|ds mode
The Fields mode of the ABAP debugger allows the contents of fields to be checked and
modlfled as Lhe program ls debugged. 1hls can be accessed elLher by double-cllcklng Lhe
field name within the code itself, or entering it into the Field names section below the
code:

noLe LhaL, slnce here a Lable ls lnvolved, ln Lhe fleld name secLlon Lhe name of Lhe Lable
musL flrsL be speclfled, followed by a -, Lhen Lhe name of Lhe fleld. 1he fleld conLenLs wlll
be fllled ln auLomaLlcally. As you sLep Lhrough code llne-by-llne ln Lhe SLLLC1 loop, Lhe
LexL held ln each fleld wlll change as each loop compleLes and moves onLo Lhe nexL record
ln Lhe Lable. 1hls secLlon allows for 8 flelds Lo be monlLored aL any Llme. llelds 3 - 8 can be
made vlslble vla Lhe navlgaLlon buLLons ln Lhe mlddle (to tbe tlqbt of tbe oombets 1 4).
CfLen when debugglng a program, you may wanL Lo manually change Lhe conLenLs of
flelds. 1hls can be achleved by replaclng Lhe LexL ln Lhe fleld conLenLs area, Lhen cllcklng
the Change field contents icon, marked with a pencil. Doing this can save a lot of time,
avoldlng havlng Lo exlL Lhe debugglng sesslon mulLlple Llmes Lo enLer new values lnLo
flelds elsewhere:

103
DEBUGGING PROGRAMS

System Var|ab|es
At the bottom of the debugger screen, are 3 fields, named SY-SUBRC, SY-TABIX and SY-
DBCNT:

noLe LhaL Lhe value boxes here are greyed-ouL, meanlng LhaL Lhey cannoL be changed
manually. 1hese are sysLem flelds, belonglng Lo a Lable called S?S1. 1hls sysLem Lable ln-
cludes many sysLem flelds whlch are fllled ln aL runLlme. 1hese sysLem flelds are fllled ln
auLomaLlcally whlle Lhe program ls execuLed. MosL sLaLemenLs wlLhln A8A wlll cause
Lhese sysLem flelds Lo be fllled wlLh 0 when execuLed successfully. lL ls lmporLanL Lo re-
member LhaL Lhese flelds are compleLely sLaLemenL-dependenL, meanlng LhaL Lhey wlll
conLaln dlfferenL values dependlng on whlch sLaLemenL ls execuLed. 1hese sysLem codes
and varlables wlll be looked aL ln greaLer depLh laLer.
1ab|e Mode
1he second mode along from Lhe llelds buLLon on Lhe lefL of Lhe screen ls 1able mode.
Cllck Lhls buLLon and Lhe code remalns, buL the bottom section changes to include an In-
ternal table entry, and a single row:

lnLernal Lables have noL yeL been covered ln depLh, buL, puL slmply, an lnLernal Lable ls a
Lable of records whlch ls sLored ln memory whlle Lhe program ls runnlng. 1able mode al-
lows one Lo lnLerrogaLe Lhe records and flelds of each record ln an lnLernal Lable. As wlLh

104
DEBUGGING PROGRAMS
llelds mode, Lhe lnLernal Lable can elLher be double-cllcked ln Lhe code, or manually en-
tered into the Internal table box.
lf one does Lhls for zemployees, then, a new window appears, displaying the table
name, lLs lndlvldual flelds and Lhelr conLenLs:

1hlngs do look sllghLly dlfferenL Lo normal here, as a Lable sLrucLure ls belng shown, raLher
Lhan an acLual lnLernal Lable. 1hls resulLs ln Lhe debugger showlng Lhe Lable sLrucLure as
above, llsLlng Lhe lndlvldual flelds numbered 1 6 and Lhelr conLenLs. When vlewlng an
lnLernal Lable ln Lhls mode, one wlll see a number of records for each lnLernal Lable wlLh
Lhelr conLenLs. 1hese records can Lhen be double-cllcked Lo move Lo Lhe above layouL,
showlng Lhe lndlvldual flelds for each record. 1hls wlll be reLurned Lo laLer.
ln Lhls screen, Lhe code remalns, buL Lhe area ln whlch lL ls dlsplayed ls very small. Cne can
conLlnue Lo lnLerrogaLe Lhe code llne-by-llne as before sLlll, buL Lhls may prove dlfflculL. lL
ls usually slmpler Lo check 1able mode for Lhe lnformaLlon requlred, and Lhen cllck back Lo
llelds mode Lo conLlnue Lhe debug sesslon.


105
DEBUGGING PROGRAMS
8reakpo|nts
Cllck Lhe 8reakpolnL mode buLLon ln Lhe A8A debugger screen. 1hls allows you Lo see a
llsL of Lhe lndlvldual breakpolnLs whlch have been seL. uouble-cllcklng any breakpolnL ln
Lhe 8reakpolnLs Lable wlll remove LhaL breakpolnL from Lhe llsL:

1hls breakpolnL Lable can be very useful, parLlcularly when one ls ln a large program wlLh
many breakpolnLs seL. lL allows one Lo revlew Lhe breakpolnL, and allows for Lhe removal
of breakpolnLs whlch are no longer deslred.
lL ls lmporLanL Lo remember LhaL breakpolnLs (and lndeed WaLchpolnLs) are only valld for
Lhe lengLh of Lhe currenL debug sesslon. When you exlL your sesslon, Lhe breakpolnLs wlll
be deleLed. Powever, an opLlon does exlsL allowlng you Lo save breakpolnLs (and, agaln,
WaLchpolnLs) before closlng a debug sesslon, keeplng Lhem acLlve for Lhe nexL Llme Lhe
program ls Lo be debugged, savlng Lhe hassle of recreaLlng Lhem. 1hls ls done by enLerlng

106
DEBUGGING PROGRAMS
the Breakpoint menu in the top Loolbar and choosing Save. All of Lhe breakpolnLs saved
wlll Lhen remaln unLll Lhey are manually removed, or unLll Lhe end of your SA sesslon.

lf one ls ln Lhe A8A edlLor, lL ls posslble Lo see an overvlew of all Lhe dynamlc break-
polnLs seL ln Lhe program by accesslng Lhe followlng menu opLlon: uLlllLles 8reakpolnLs
ulsplay:


107
DEBUGGING PROGRAMS

1he opLlons aL Lhe boLLom of Lhls breakpolnL Lable allow one Lo deleLe selecLed break-
polnLs wlLhouL enLerlng Lhe debugger and breakpolnLs can be navlgaLed Lo ln Lhe program
lLself (wlLhln Lhe A8A edlLor) by double cllcklng Lhem ln Lhls Lable.
Stat|c 8reakpo|nts
SLaLlc breakpolnLs were brlefly alluded Lo earller. 1hese refer Lo a llne of code wrlLLen lnLo
a program whlch forces Lhe program Lo enLer debug mode aL Lhe speclflc llne chosen. 1o
do Lhls, Lhe sLaLemenL 8kLAk-CIN1 ls used. When Lhe code ls execuLed, Lhe debug ses-
slon wlll sLarL wlLh Lhe usual blue arrow cursor polnLlng aL Lhe locaLlon of Lhe sLaLlc break-
polnL.


108
DEBUGGING PROGRAMS

Cnce Lhls sLaLemenL ls embedded ln a program, lL ls acLlve for all users. 1hls ls largely un-
deslrable, as oLhers runnlng Lhe program, who do noL wanL Lo debug Lhe code, would be
faced wlLh Lhe breakpolnL seL by an lndlvldual user. 8e careful noL Lo leave Lhls sLaLemenL
llne ln programs whlch wlll be LransporLed Lo oLher sysLems.
Watchpo|nts
Cllck Lhe WaLchpolnLs buLLon ln Lhe A8A debugger. 1he program code wlll be vlslble
above Lhe WaLchpolnLs Lable ln Lhe lower half of Lhe screen. 8reakpolnLs have prevlously
been dlscussed, and can be very useful, buL are noL always Lhe ldeal Lool Lo use Lo pause
code execuLlon, lnLerrogaLe Lhe conLenLs of lndlvldual flelds and lnLernal Lables and ana-
lyse the programs logic.
lmaglne Lhe program was processlng a Lable conLalnlng 1000 records, and one wanLed Lo
debug Lhe loglc only when a cerLaln condlLlon occurs. 1hls condlLlon ls dependenL upon
Lhe daLa held ln Lhe records belng processed. 8y uslng breakpolnLs, one would have Lo
debug each lndlvldual record, obvlously Laklng a huge amounL of Llme. Pere, WaLchpolnLs
become useful. uslng Lhese, one can Lell Lhe program Lo sLop ln Lhe same manner LhaL lL
would for a breakpolnL, buL lnsLead of sLopplng aL a speclflc llne of code, lL would sLop
based on Lhe value ln a fleld. ln Lhls example Lhen, lf Lhls value occurred only ln Lhe 200
Lh

llne of Lhe Lable, a waLchpolnL would allow Lhe flrsL 199 records Lo be sklpped over.
A watchpoint is created with the Create watchpoint button, seen above Lhe llsL of modes
ln Lhe WaLchpolnL mode screen, or wlLh SPll1 + l8.
Cnce Lhls ls done, a dlalogue box wlll appear, wlLh Lhe program name fllled ln auLomaLl-
cally. Pere you need Lo enLer Lhe name of Lhe fleld Lo be waLched. ln Lhe
Z_LMLC?LL_LlS1_01 example here, we wlll enLer Lhe sotoome fleld. 1he formaL ls 1A-
8l_NAM-lllu_NAM. nexL, Lhe relaLlonal operaLor ls Lo be seL. ln Lhls example, a sur-

109
DEBUGGING PROGRAMS
name with the value Mills will be sought, so the operator here is an =. This can be se-
lecLed from a drop-down menu, where one can also vlew oLher poLenLlal relaLlonal opera-
Lors. 1he boLLom fleld, Lhen, should be fllled ln wlLh Lhe value Lo be waLched for.
noLe LhaL one does noL have Lo use a speclflc value ln Lhe boLLom fleld, buL can geL a
waLchpolnL Lo compare a fleld agalnsL anoLher fleld wlLhln Lhe program. 1o do Lhls Lhe
Comparison field box should be checked, and the field name typed into the box rather
Lhan a speclflc value.
Cllck Lhe green Llck Lo conLlnue and creaLe Lhe waLchpolnL, and Lhe enLry wlll have been
added Lo Lhe llsL aL Lhe boLLom of Lhe screen:



110
DEBUGGING PROGRAMS

Cbserve Lhe boxes below Lhe WaLchpolnLs llsL here. 1hey are currenLly empLy, buL when
the program is executed, it will pause once a value of Mills is reached in the surname
fleld and Lhls wlll be lncluded ln Lhe box.
1he ouLpuL before Lhe program ls execuLed looks llke Lhls:

noLe LhaL Lhe surname Mllls appears ln Lhe flfLh row down. When Lhe program ls execuLed
with the Mills watchpoint set, the first four records wlll be wrlLLen Lo Lhe screen before
pauslng aL Lhe flfLh, when Mllls ls dlsplayed.

?ou wlll see LhaL Lhe blue arrow cursor has paused aL Lhe SLLLC1 loop ln Lhe code.

111
DEBUGGING PROGRAMS

LnLer zemployees-surname ln Lhe llelds mode of Lhe debugger Lo vlew Lhe conLenLs of Lhe
fleld. You will see the field contains MILLS. Also ln Lhe WaLchpolnLs mode, Lhe boLLom
fleld wlll now be fllled:


Lnd|ng a Debug Sess|on
1here are Lwo ways Lo sLop debugglng a program. 1he flrsL ls Lo use Lhe l8 key Lo run Lhe
program all Lhe way Lhrough Lo Lhe end. keep ln mlnd Lhough, LhaL lf any break or WaLch-
polnLs are seL, Lhe execuLlon wlll llkely pause and have Lo be sLarLed agaln, perhaps mulLl-
ple Llmes. Also Lhls meLhod depends enLlrely upon Lhe program execuLlng successfully. lf
any runLlme errors are caused, Lhe debug sesslon wlll LermlnaLe and reLurn you Lo Lhe SA
menu screen.
The alternative way of stopping the debugger is to enter the Debugging menu and
choose Restart. This way, no more of the program will be executed, and you can reLurn
to the ABAP Editors initial screen:

112
DEBUGGING PROGRAMS




113
ENHANCING DATABASE TABLES
Chapter 7: Work|ng w|th Database 1ab|es

Mak|ng a Copy of a 1ab|e
1hls chapLer wlll look aL ways ln whlch one can change Lhe LransparenL Lables creaLed ear-
ller. lL ls lmporLanL Lo know how Lo do Lhls, and Lhe lmpllcaLlons of addlng and Laklng away
flelds for Lhe underlylng daLa ln a daLabase Lable.
Lets take a look aL Lhe ZLMLC?LLS Lable creaLed ln ChapLer 2. ln Lhe SA Cul, key ln
LransacLlon code SL11 Lo access Lhe A8A dlcLlonary, Lhen dlsplay Lhe Lable:

lL ls lmporLanL Lo reallse LhaL whenever one wanLs Lo change a daLabase Lable, Lhere ls a
rlsk of loslng daLa, especlally where key flelds ln Lhe Lable are belng affecLed. 1he daLabase
sysLem lLself wlll Lry Lo deLermlne wheLher ad[usLmenLs can be made by deleLlng and cre-
aLlng new lLems whlch change Lhe underlylng daLabase caLalogue, or wheLher whaL has
already deflned has Lo be re-lmplemenLed.
CulLe ofLen, when worklng wlLh large Lables, one has Lo manage Lhe manlpulaLlon of Lhe
daLa oneself, so as Lo be sure LhaL daLa ls noL losL. ueleLlng flelds ls qulLe a slmple Lask, Lhe
Lable sLrucLure and lLs conLenLs can add cerLaln compllcaLlons. 8efore sLarLlng any daLa-
base change Lasks, lL ls lmporLanL Lo mlLlgaLe agalnsL as many rlsks as posslble, and sLarL

114
ENHANCING DATABASE TABLES
by uslng a copy of Lhe daLabase Lable, allowlng one Lo LesL ouL any changes one may wanL
Lo make, wlLhouL affecLlng Lhe lnlLlal Lable and lLs underlylng daLa.
When you copy a daLabase Lable, lL ls only Lhe sLrucLure lLself whlch ls copled, meanlng
only lLs properLles - flelds and so on, noL Lhe acLual daLa.
SLep back Lo Lhe lnlLlal SL11 screen. WlLh ZLMLC?LLS ln Lhe uaLabase Lable fleld, cllck
Lhe Copy buLLon, Lhen glve Lhe new Lable of 2LMLCLLS2. The Create Object Directory
Entry box will appear and as before, select Local Object:


A copy of Lhe Lable has now been creaLed. Choose dlsplay aL Lhe SL11 screen and Lhe copy
wlll appear. 1he tables status wlll read as New. It must be activated, so click the Change
buLLon (Lhe encll lcon ln Lhe Loolbar), and Lhen AcLlvaLe:

noLe LhaL all of Lhe flelds ln Lhe Lable, slnce Lhey have been copled, are already acLlve. 1hls
ls why lL ls only Lhe Lable lLself whlch has Lo be acLlvaLed here. lf you Lry Lo look aL Lhe La-

115
ENHANCING DATABASE TABLES
ble, you wlll flnd Lhere are no conLenLs, because only Lhe sLrucLure was copled, noL Lhe
underlylng daLa. 1o creaLe records, from Lhe Utilities menu, select Table Contents and
then Create Entries to display the screen where the records for the table can be creaLed
as before.

lnserL some records, cllck Lhe ConLenLs buLLon, and Lhen vlew Lhe new Lable:


116
ENHANCING DATABASE TABLES

Add New I|e|ds
nexL, a new fleld wlll be added. 1hls wlll be a non-key fleld and wlll be called INI1IALS.
CreaLe a new uaLa elemenL for Lhls named Zlnl1lALS uslng forward navlgaLlon. lor Lhe
daLa elemenL, seL Lhe shorL LexL Lo Initials and seL Lhe domaln Lo CPA803 (a characLer
sLrlng of lengLh 3). ln Lhe Field label boxes type Initials, then activate the DaLa elemenL.
1he Lable should now have a new fleld llke Lhls:

CreaLe anoLher 3 more new flelds and conflgure Lhem as follows:
lleld Name CLnuL8
! SeL Lhe uaLa elemenL to ZCLnuL8. Configure the data element as follows:
ShorL LexL: Gender
uomaln: CPA801
lleld labels seL Lo Gender
SALA8?
! SeL Lhe uaLa elemenL Lo ZSALA8?
Short text: Salary
uomaln: CURR9 (1bls bos o leoqtb of 9, wltb 2 Jeclmol ploces)
lleld labels set to Salary.
Cne Lhlng Lo noLe abouL Lhe Salary fleld ls LhaL, because lL ls a currency, anoLher fleld for
Lhls currency musL be creaLed and aLLached Lo ZSALA8? Lo lndlcaLe whaL currency Lhe sal-
ary ls ln. lf you Lry Lo acLlvaLe Lhe Lable wlLhouL dolng Lhls, an error message wlll appear
asklng for a reference fleld Lo speclfy Lhe currency.

117
ENHANCING DATABASE TABLES
CreaLe a new fleld called LCu88LnC?. Currency flelds should already exlsL ln Lhe sysLem,
so Lhe uaLa elemenL here wlll be a pre-exlsLlng one named CUkC. 1ype Lhls, press enLer
and Lhe remalnlng flelds should flll ln auLomaLlcally, leavlng Lhe new secLlon of Lhe Lable
looklng llke Lhls:

nexL, Lhe sysLem musL be Lold LhaL Lhe Salary fleld ls referenclng Lhe Currency fleld. Above
Lhe Lable wlll be able Lo see a tab labelled Currency/Quantity Fields. Click this and the
Lable wlll be shown wlLh Lwo boxes Lo be fllled ln for Lhe Salary fleld, slnce lL has already
been specified that the domain for this field is Currency. In the Reference table column
enLer the name of the table, ZEMPLOYEES2 and in the Reference field column, the
name of the new Currency Key, ECURRENCY. Now the Lable can be acLlvaLed error free.

Iore|gn keys
As shown earller enLer a new record. ?ou wlll see LhaL Lhe currency key does noL offer any
klnd of drop-down menu, here for Lhls example, Lype C8, lndlcaLlng CreaL 8rlLlsh ounds:

118
ENHANCING DATABASE TABLES

Save Lhe record, and Lhen reLurn Lo Lhe deslgn of Lhe Lable, where we can now add some
error-checklng Lo ensure LhaL valld enLrles are made ln Lhe Currency key fleld.
1o enable error-checklng on Lhe currency key fleld, we need Lo make use of a lorelgn key.
1hese are used Lo ensure LhaL only valld values can be enLered lnLo a fleld. use forward
navlgaLlon on Lhe Cu8C? daLa elemenL. Look aL Lhe uaLa Lype Lab and you wlll see LhaL Lhe
daLa elemenL refers Lo a sLandard SA domaln, WAL8S:

uouble-cllck Lhe WAL8S domaln Lo use forward navlgaLlon agaln. Look at the Value range
tab in this window, a Value table box is visible at the boLLom, labelled 1Cu8C:


119
ENHANCING DATABASE TABLES
A value Lable can be used Lo deLermlne Lhe enLrles LhaL can be made ln Lhe fleld based on
Lhls domaln. uouble-cllck 1Cu8C Lo agaln use forward navlgaLlon and Lhls value Lable wlll
be dlsplayed.

use Lhe daLa browser Lo look aL Lhe daLa ln Lhls Lable. lf you scroll down, Lhe C8 value
from before can be found, among a number of oLhers. 1hls Lable can be used Lo ensure
LhaL, ln fuLure, only enLrles found ln Lhls Lable can be enLered lnLo our new Lable ZLM-
LC?LLS2


120
ENHANCING DATABASE TABLES
Return to the Maintain table screen for ZEMPLOYEES2, highlight the ECURRENCY field,
and cllck Lhe lorelgn key buLLon vlslble ln Lhe Loolbar above:
Choose Yes in the box which appears and a Create Foreign Key window will emerge.
Type the short text Check Currency Field. A small table is visible, detailing the two key
flelds from Lhe 1Cu8C Lable and Lhe ZLMLC?LLS2 Lable. 1he opLlon ls avallable Lo ensure
LhaL Lhe forelgn key maLches boLh flelds, so LhaL when Lhe user ls allowed Lo selecL an en-
Lry, Lhe records reLurned wlll only be valld for Lhe CllenL whlch ls belng worked ln.
Pere Lhough, Lhe CllenL ls noL Lo be chosen as parL of Lhe key, so selecL Lhe Check-box
Generic for the top row, whlch refers Lo Lhe CllenL, and remove Lhe LexL from Lhe Lwo
boxes on Lhls row where Lhls ls posslble. 1hen cllck Lhe Copy buLLon. 1he forelgn key wlll
be creaLed:


121
ENHANCING DATABASE TABLES
AcLlvaLe Lhe Lable, and Lhen browse Lhe daLa. now, selecL Lhe currency key and elLher
press Lhe l4 key or selecL Lhe drop-down box LhaL appears, dlsplaylng all valld enLrles for
Lhls fleld. lf you were ln record change mode you wlll Lhen be able Lo selecL a value from
Lhe Lable and see lL updaLe your zemployees 2 record. 1ry lL ouL and selecL uSu (uS uol-
lar).



122
ENHANCING DATABASE TABLES


Append Structures
Pavlng looked aL forelgn keys, Lhe nexL Lhlng Lo look aL are Append sLrucLures. 1hese can
be used Lo add addlLlonal flelds. 1hls ls Lhe preferred meLhod for malnLalnlng SA dellv-
ered Lables and qulLe ofLen for cusLomer-speclflc Lables. lf one does noL use Append sLruc-
Lures, problems can arlse lf, for example, a new verslon of SA ls used whlch does noL cor-
respond wlLh aspecLs of Lhe Lables already creaLed, resulLlng ln serlous errors.
Append sLrucLures glve a safe way Lo enhance Lables. When Lhese are used, Lhe lnlLlal La-
ble remalns unchanged, removlng any rlsk of changes belng overwrlLLen laLer lf a dlfferenL
verslon of SA ls used. CulLe ofLen, a Lable may have mulLlple Append sLrucLures applled
Lo lL, because dlfferenL developmenL needs have arlsen as Llme has gone by and people
have wanLed Lo add furLher flelds Lo Lhe sLandard SA Lables.
In the SE11 Maintain Table screen, go to the Append structure button on the right of the
Lop Loolbar:


123
ENHANCING DATABASE TABLES
Cllck Lhls, and Lhe sysLem wlll suggesL a name, ZAZLMLC?LLS2 (noLe LhaL Lhls, agaln,
musL begln wlLh a Z). AccepL Lhls and you wlll be presenLed wlLh whaL looks llke an empLy
table structure. Enter the Short text Extra Fields For Employees, and Lhen move down Lo
Lhe Lable.
Note that the first field now is called Component. This is where new fields are created.
Powever, lL may be useful Lo dlfferenLlaLe beLween flelds creaLed ln Lhe maln Lable, and
Lhe new componenLs creaLed here ln Lhe Append sLrucLure. Slnce boLh musL comply wlLh
Lhe cusLomer name rules, where Z was used ln Lhe maln Lable, here use ZZ.
For the first component, a Department field will be created. Type in the Component box
ZZDEPT and the same again in Component type. For Lhls ComponenL Lype, use forward
navlgaLlon ln Lhe same way LhaL lL was used for Lhe uaLa elemenL before, double-cllcklng
Lo creaLe. Save Lhe Append sLrucLure as a local ob[ecL when prompLed, and Lhen selecL Lo
creaLe a uaLa elemenL when prompLed subsequenLly.
The familiar data element screen will now appear. Type Department for the short text,
use CHAR10 for the domain and Department again for the Field labels, then activate the
daLa elemenL. SLep back Lo Lhe Append sLrucLure screen, Lhen AcLlvaLe:

8eLurn Lo Lhe maln Lable screen, where a new row dlsplaylng Lhe Append sLrucLure wlll
have been creaLed. 1o Lhen access Lhls sLrucLure, slmply double-cllck Lhe row. ln Change
mode only the .APPEND line will be visible by defaulL, buL ln ulsplay mode Lhe flelds cre-
aLed wlLhln Lhls wlll appear below:

124
ENHANCING DATABASE TABLES

1hls ls a very useful way Lo add new flelds Lo a Lable wlLhouL affecLlng Lhe sLrucLure of Lhe
Lable lLself. lf one Lhen browses Lhe daLa as normal, a new column wlll have been called
Department. Data can then be enLered lnLo Lhls fleld [usL llke lL can for any oLher:

Inc|ude Structures
lnclude sLrucLures are slmllar Lo Append sLrucLures, wlLh Lhe maln dlfference belng LhaL
Lhey are re-usable ob[ecLs and can be llnked Lo many oLher Lables, A8A programs, dla-
logue programs and sLrucLures. lL ls lmporLanL Lo keep ln mlnd LhaL lnclude sLrucLures
musL be flaL sLrucLures, meanlng LhaL Lhey cannoL hold any addlLlonal sLrucLure wlLhln
Lhem, and LhaL Lhe maxlmum lengLh of Lhe flelds wlLhln an lnclude sLrucLure ls 16 charac-
Lers.
1here ls no lnclude sLrucLure buLLon ln Lhe way LhaL Lhere ls an Append sLrucLure buLLon.
1o creaLe one, flrsL ensure Change mode ls selecLed. Where Lhe cursor ls placed ls lmpor-
LanL here, as wherever Lhe cursor ls when Lhe lnclude sLrucLure ls creaLed, lL wlll be cre-
aLed one row above. lf you wanL Lhe lnclude sLrucLure Lo be parL of Lhe Lable key, lL musL
appear aL Lhe Lop, because all Lable flelds used as a Lable key need Lo be grouped LogeLher
aL Lhe Lop. ln Lhls lnsLance Lhough, lL wlll [usL be lnserLed above Lhe Append sLrucLure.
Place the cursor on the .APPEND row, select the Edit menu, then Include and Insert.


125
ENHANCING DATABASE TABLES
ln Lhe wlndow LhaL appears, enter ZEMPL in the Structure fleld and cllck Lhe conLlnue
buLLon. A warnlng box wlll appear sLaLlng LhaL Lhls ls noL yeL acLlve, dlsmlss Lhls, and Lhe
lnclude sLrucLure should now appear ln Lhe Lable:


1o add a fleld Lo Lhls, use forward navlgaLlon as before, double-cllcklng where .INCLUDE
ZEMPL appears, save and choose Yes to create Lhe sLrucLure. 1he screen whlch Lhen ap-
pears ls very slmllar Lo Lhe Append sLrucLure screen.
Type the Short text Employee Include and begin to create a field (the boxes are, like in
the Append structure, labelled Component), this time for location, called ZZLCCA1, and
use ZLOCAT for the Component type. Use forward navigation again to create this Data
element with Short text Location, the domain CHAR10 and Location again for the Field
labels, Lhen AcLlvaLe Lhls as usual. AcLlvaLe Lhe lnclude sLrucLure once Lhe fleld has been
creaLed and reLurn Lo Lhe maln Lable Lo see Lhe lnclude sLrucLure locaLed [usL where we
wanLed lL, above Lhe Append sLrucLure:

AcLlvaLe Lhe Lable now, and vlew Lhe conLenLs. 1he LocaLlon column should now be vlsl-
ble, and Lhese records can now be edlLed and creaLed llke any oLher:

126
ENHANCING DATABASE TABLES


lf one swlLches Lo ulsplay mode, Lhe fleld creaLed ln Lhe lnclude sLrucLure can be seen ln
Lhe conLexL of Lhe maln Lable, albelL ln a dlfferenL colour:

127
ENHANCING DATABASE TABLES

ln Change mode, Lhese flelds can be seen by selecting the .INCLUDE row and clicking the
Expand include icon (the same works for the Append structure also):

key I|e|ds
lf you wanL Lo add or remove flelds whlch are deslgnaLed key flelds, Lhen lL ls lmporLanL Lo
Lake lnLo conslderaLlon whaL wlll be golng on ln Lhe daLabase lLself. All of Lhe new ele-
menLs whlch have been creaLed for Lhls Lable have Lhelr feaLures applled by Lhe sysLem Lo
Lhe A8A dlcLlonary, noL Lhe underlylng daLabase. When any key fleld ls ad[usLed, Lhe sys-
Lem has Lo apply changes Lo Lhe underlylng daLabase lLself. lf Lhere ls daLa ln Lhe Lable,
and key flelds are changed, Lhls can have unlnLended consequences.

128
ENHANCING DATABASE TABLES
lf you lnLroduce a new key fleld, Lhls wlll probably noL have a large effecL. Powever, lf one
makes a key fleld no longer a key fleld, Lhls wlll requlre conslderaLlon, because lf Lhere ls a
loL of daLa ln Lhe underlylng daLabase, by Laklng away a key fleld, dupllcaLe records could
be lnLroduced. CorrupL daLa or records belng deleLed from Lhe Lable can also happen here.
Lets see how we can add, remove and alLer flelds wlLhouL Lhese hazards.
Cpen the full ZEMPLOYEES2 table in the ABAP Dictionary Maintain Table screen. Lets
change Lhe Surname field by Lurnlng lL lnLo a key fleld.
Check Lhe Lwo boxes (key and lndex) by SURNAME and Activate the table. When you now
vlew Lhe Lable conLenLs, Lhe surname column wlll be a darker colour, lndlcaLlng LhaL lL ls
now a key fleld. 8eyond Lhls Lhough, lL appears very llLLle has changed:


Now, uncheck the boxes on the Maintain Table screen, to make it no longer a key field.
When you Lry Lo acLlvaLe Lhe Lable an error message appears, refuslng Lo acLlvaLe Lhe La-
ble as daLa may be losL wlLh Lhe removal of a key fleld:


129
ENHANCING DATABASE TABLES
1o acLlvaLe Lhe Lable agalnsL whaL seem Lo be Lhe wlshes of Lhe sysLem (afLer all, one
knows Lhe daLa wlll be flne as Lhe surname fleld has noL been operaLlng as a key fleld aL
any polnL prevlously), a dlfferenL LransacLlon musL be used.
lrom Lhe Utilities menu, select Database utility, or use transaction code SE14. A new
screen wlll appear:

1hls LransacLlon leLs us auLomaLlcally ad[usL Lhe daLa held ln our Lable when maklng ad-
[usLmenLs Lo Lhe daLabase Lable sLrucLure. LnvlronmenLs where Lables are belng worked
on may conLaln a huge number of records. WlLh Lhls ln mlnd, Lhls LransacLlon can be exe-
cuLed as a background process. Powever, for our example Lhe Direct opLlon ls Lhe opLlon

130
ENHANCING DATABASE TABLES
Lo choose because we know we have very few records ln our daLabase Lable. SelecL Lhls,
and then click Activate and adjust database with Save data radlo buLLon selecLed. Say
Yes when the box asks Request: Adjust and noLlce Lhe sLaLus bar should lndlcaLe Lhe
success of Lhls execuLlon. 1hen, step back to the Maintain Table screen and you wlll see
Lhe Lable should be AcLlve wlLh Lhe surname fleld no longer key.
1o lnserL a new fleld as parL of Lhe Lable key, you musL be able Lo ad[usL Lhe locaLlon of
flelds on Lhe screen. lor example, lf you wanLed Lo creaLe a new fleld above Lhe surname
fleld, you would highlight the row and then click the Insert row icon in the toolbar. 1bls
toolbot olso locloJes Cut, Copy and Paste options, allowing for rows to be moved up
ooJ Jowo lf tbete ls o oeeJ to Jo tbls:


De|et|ng I|e|ds
Whlle lnfrequenL, occaslonally Lhere may be a need Lo remove a fleld from a Lable. When
dolng Lhls, lL ls lmporLanL Lo Lake speclal care, as daLa can be losL ln Lhe process. CerLalnly
ln Lhe case of key flelds.
lf, for example, Lhe Currency key fleld was removed from our Lable, Lhe forelgn key rela-
Llonshlp Lo Lhe 1Cu8C Lable would be removed. As Lhe SALA8? fleld has Lo have a relaLed
Currency key Lhls would cause Lhe Lable Lo no longer conLlnue worklng, and llkely make
Lhe ZLMLC?LLS2 Lable become lnacLlve.
When deleLlng flelds lL ls lmporLanL Lo ask oneself wheLher Lhe daLa belng held ln Lhe Lable
ls belng used elsewhere, and wheLher lLs deleLlon wlll have furLher consequences. lf you
do Lry Lo deleLe flelds whlch are belng used elsewhere, Lhe SA sysLem should Lry Lo pre-
venL Lhls, or aL leasL lssue a sLern warnlng. 1hls ls noL necessarlly Lo be relled upon Lhough,
so always ensure Lo check manually whaL Lhe effecLs of deleLlon are llkely Lo be. Also, lf

131
ENHANCING DATABASE TABLES
you do deleLe flelds, Lhe Lable wlll have Lo be ad[usLed vla Lhe SL14 LransacLlon Lo be acLl-
vaLed agaln.
Create a new field, above .INCLUDE, named ZAWESOME. Use a previously created Data
elemenL, here Z1l1LL [usL Lo save Llme, and acLlvaLe Lhe Lable:

CreaLe a new record ln Lhe Lable. 1he daLa here ls noL lmporLanL and wlll be deleLed, so
Lhe conLenL can be anyLhlng:



132
ENHANCING DATABASE TABLES
now, Lo deleLe Lhe fleld, highlight it in the Maintain Table screen, and click the Remove
row icon, in the toolbar next to Insert row. The row will disappear, but when you Lry Lo
acLlvaLe Lhe Lable, an error message wlll appear:

1ransacLlon SL14 musL agaln be used Lo ad[usL Lhe Lable so Lhe change can be applled. lol-
low Lhe same sLeps as ln Lhe prevlous secLlon Lo perform Lhls Lask. Cnce Lhls ls compleLe,
vlew Lhe Lable agaln. 1he column has dlsappeared, and Lhe daLa whlch was conLalned
wlLhln lL losL:

1o see whaL happens when a key fleld ls deleLed, reLurn Lo Lhe A8A ulcLlonary lnlLlal
screen and make a copy of ZLMLC?LLS2, called, unsurprlslngly, ZLMLC?LLS3. uoloq tbls
wlll ollow tbe 2MllO52 toble to oot be JomoqeJ lo tbls tlsky ptoceJote. AcLlvaLe Lhe
new Lable (which, dont forget, will be empty of records). As before, again make the Sur-
name fleld a key fleld. now creaLe some records for Lhls Lable:


133
ENHANCING DATABASE TABLES
1o save Llme creaLlng new records, Lhe same daLa was repllcaLed here, wlLh only sllghL
changes Lo Lhe key flelds. 8emember LhaL lL ls only one key fleld per enLry whlch musL be
unlque for LhaL parLlcularly record Lo be unlque lLself.
now, Lhe surname fleld wlll be deleLed, and Lhe effecLs of deleLlng Lhls key fleld observed.
8y removlng Lhls key fleld, Lhe only unlque daLa whlch wlll be held for each record wlll be
Lhe Lmployee number and CllenL. Slnce SMl1P and SMl1P2, and Anu8LWS and An-
u8LWS-2 have Lhe same Lmployee number and CllenL, Lhese wlll no longer hold unlque
key fleld daLa, leavlng dupllcaLe records, whlch Lhe sysLem wlll noL allow.
8emove Lhe Surname fleld, Lry Lo acLlvaLe Lhe Lable, and error messages wlll appear. Co
Lhrough SL14 Lo ad[usL Lhe Lable for acLlvaLlon. When you now vlew Lhe Lable, Lhe Sur-
name fleld ls gone, and Lwo records have been losL, leavlng only one of Lhe Lwo records
for each of Lhe Lwo Lmployee numbers used:

De|et|ng 1ab|es
Cne wlll noL ofLen have Lo deleLe an enLlre daLabase Lable, for largely Lhe same reasons as
were ouLllned above for flelds. lf Lhls does have Lo be done lL ls lmporLanL Lo remember
that ones own customer-speclflc Lables are Lhe only ones whlch can be deleLed, SA de-
llvered Lables cannoL be deleLed. 8ecause ZLMLC?LLS3 has only [usL been creaLed, and
noLhlng else depends on Lhls Lable, lL can be deleLed wlLhouL consequences.
1o check wheLher a Lable can be deleLed wlLhouL causlng unlnLended consequences else-
where in the system, return to the ABAP Dictionarys initial screen. Because the original
ZLMLC?LLS Lable was used ln Lhe programs whlch have been creaLed, use Lhls as a LesL.
lnserL Lhls lnLo Lhe uaLabase Lable fleld on the screen and then click the Where-used list
lcon from Lhe Loolbar.

134
ENHANCING DATABASE TABLES

Cnce Lhls ls cllcked, a dlalogue box wlll appear offerlng a llsL of check-boxes. 1hls wlll Lhen
search all of Lhe dlfferenL areas of Lhe SA sysLem selecLed for references Lo Lhe Lable
ZEMPLOYEES. To execute this search click the Continue icon. Choose Yes to the pop-up
box, and walL whlle Lhe sysLem complles Lhe search resulLs, whlch here show LhaL Lhls La-
ble ls belng used currenLly by 2 programs:

Pavlng done Lhls, one now knows LhaL lf Lhe ZLMLC?LLS Lable were Lo be deleLed, Lhese
programs would become lnacLlve. 8y double-cllcklng Lhese enLrles, one can see Lhe code
ln Lhe program where ZLMLC?LLS ls referred Lo, and lf you double-cllck on any llne of
Lhe program, lL wlll open Lhe program aL LhaL llne of code ln Lhe A8A LdlLor. 1he Where-
used buLLon ls a very useful Lool, whlch can be lnvaluable noL [usL when deleLlng pro-
grams, buL ln many oLher scenarlos.
lf you were Lo Lry Lo deleLe ZLMLC?LLS, Lhe sysLem would noL allow Lhls course of acLlon
and would prevenL lL from happenlng unLll all Lhe programs LhaL are dependenL upon lL
were elLher edlLed Lo remove references or deleLed alLogeLher Lhemselves.
Slnce noLhlng depends upon ZLMLC?LLS3, Lhls can be deleLed. WlLh Lhe correcL name ln
the Database table field, click the Delete button in the toolbar:

135
ENHANCING DATABASE TABLES

A box appears sLaLlng LhaL Lhe daLa conLalned ln Lhe Lable would also be deleLed. lf you
cllck Lhe green Llck lcon Lhls Llme, Lhe sysLem would reLurn Lo Lhe maln screen wlLh Lhe
Lable sLlll lnLacL. lf Lhe mlddle buLLon, lllusLraLed wlLh Lhe Lrashcan lcon ls cllcked, Lhls wlll
proceed wlLh Lhe deleLlon. Cnce Lhls ls done, Lhe sLaLus bar should conflrm Lhe acLlon. lf
you Lry Lo dlsplay Lhe Lable now, lL does noL exlsL. Cnce Lhe deleLlon ls compleLed, lL can-
noL be undone:



136
WORKING WITH OTHER DATA TYPES
Chapter 8 Work|ng w|th Cther Data 1ypes

Date and 1|me I|e|ds
1hls secLlon wlll look aL some oLher daLa Lypes whlch can be used ln A8A. So far, numerlc
flelds have been used for performlng calculaLlons, and characLer sLrlngs have been exam-
lned along wlLh Lhe ways Lhese can be manlpulaLed wlLh A8A sLaLemenLs. now, daLe and
Llme flelds wlll be looked aL.
LnLer Lhe A8A edlLor (wlLh LransacLlon SL38) and make a copy of Lhe prevlous program,
alLer Lhe commenL secLlons, and remove mosL of Lhe code:


137
WORKING WITH OTHER DATA TYPES

uaLe and Llme flelds are noL sLored as numerlc daLa Lypes, buL lnsLead as characLer daLa
Lypes. LffecLlvely, Lhey are characLer sLrlngs whlch can be used ln calculaLlons. 1hls ls
made posslble by Lhe lnbullL auLomaLlc daLa Lype converslons whlch have prevlously been
dlscussed. !usL llke any oLher daLa Lype, Lhe uA1A sLaLemenL ls used Lo declare Lhese
flelds.
For a date field, the data type is referred to with d, and is limited to 8 characters. The
flrsL 4 of Lhese represenL Lhe year, Lhe nexL 2 Lhe monLh, and Lhe flnal 2 Lhe day. 1he
vALuL addlLlon ls used Lo speclfy Lhls, and lf lL ls noL used Lhen Lhe value, by defaulL, ls
asslgned as 8 zeros. ln Lhe example below, Lhe daLe ls Lhe 1
sL
of !anuary, 2012:


138
WORKING WITH OTHER DATA TYPES
1he LlkL sLaLemenL, of course, can also be used. S?-uA1uM ls a sysLem varlable, whlch
always holds the value of the systems date. Below, my_date2 is defined in the same
way as Lhls sysLem varlable:

1lme flelds work slmllarly, buL Lhls Llme are llmlLed Lo 6 characLers. 1he flrsL 2 refer Lo Lhe
hour, Lhe second 2 Lhe mlnuLe, and Lhe flnal 2 Lhe second. Agaln, Lhe defaulL value wlll be
6 zeros. The data type this time is t. Again, the LIKE statement can be used, here for the
systems time field, referred to with SY-uZLl1:

We can Lhen use Lhe W8l1L sLaLemenL Lo ouLpuL Lhe fleld conLenLs:


noLe LhaL ln Lhe flrsL row Lhe my_daLe fleld has reversed lLself Lo Lhe formaL uuMM????.
ln Lhe second, no value was asslgned Lo Lhe fleld, so Lhe sysLem has ouLpuL Lhe defaulL
zeros. However, as this was defined like the systems date variable, it has included perlods
ln Lhe formaLLlng. 1hls also applles Lo Lhe my_Llme2 fleld, where colons have appeared
beLween Lhe places where Lhe Llme values would ordlnarlly be.
Date I|e|ds |n Ca|cu|at|ons


139
WORKING WITH OTHER DATA TYPES
Some examples of performlng calculaLlons wlLh daLe and Llme flelds wlll now be looked aL.
uslng Lhese flelds ln calculaLlons ls common pracLlce wlLhln programmlng buslness sys-
Lems, as one wlll ofLen have Lo, for example, flnd Lhe dlfference beLween Lwo daLes Lo de-
llver lnvolce daLes, dellvery daLes and so on. Pere, examples wlll be looked aL so as Lo flnd
new daLes, and flnd Lhe dlfference beLween Lwo daLes.
Use the DATA statement to declare a start date for an employee, called empl_sdate, and
Lhen give this a value of 20090515. Then create another field called todays_date and
define the value of this as sy-datum, the system variable, which should then include the
daLe on LhaL parLlcular day:


Next, a calculation will be added, so as to work out this employees length of service. Cre-
ate a new variable named LOS, include a DATA statement giving LOS a data type i
and then define LOS as the calculation todays_date empl_sdate. Then, add a WRITE
statement for this variable, which will include the employees length of service in the ouL-
puL. Cnce Lhls ls compleLe, execuLe Lhe code:



If one wants to add, for example, 20 days to todays date, the same value is used for to-
days_daLe (Lhe sysLem varlable, sy-datum). Create another variable, called days_count
with an integer value of 20, and another called fut_date. This variables value should
then be defined as todays_date + days_count, then ad a W8l1L sLaLemenL Lo ouLpuL Lhe

140
WORKING WITH OTHER DATA TYPES
fuL_daLe. Dont forget also to add the data types above (i for days_count and d for
fuL_daLe). 1he ouLpuL should give the date 20 days on from todays date, which here is the
7
Lh
of AugusL, 2012:



Subflelds can be used for daLe flelds ln exacLly Lhe same way as Lhey were used before. ln
Lhe nexL example, a daLe fleld wlll be changed Lo represenL Lhe 20
Lh
day of Lhe currenL
monLh. Copy Lhe Lodays_daLe varlable, Lhen add a new llne of code whlch changes Lhe lasL
two figures of todays_date to the value 20, and a WRITE statement. Also, ouLpuL Lhe sys-
Lem daLe so as Lo compare Lhe Lwo:


ln Lhls nexL example, Lhe lasL day of Lhe prevlous monLh wlll be esLabllshed. use Lhe Lo-
days_daLe varlable agaln, Lhls Llme uslng Lhe subfleld meLhod above Lo change Lhls Lo rep-
resenL Lhe flrsL day of Lhe currenL monLh. 1hen on a new llne of code, subLracL one from
Lhls, so LhaL Lhe Lodays_daLe varlable ls now Lhe flnal day of Lhe prevlous monLh:



141
WORKING WITH OTHER DATA TYPES
1|me I|e|ds |n Ca|cu|at|ons
CalculaLlons llke Lhose above can also be performed wlLh Llme flelds.
In the examples, employees clocking in and out times will be used. Use DATA staLemenLs
to declare the variables clock_in and clock_out as type t, along with others seen in
Lhe lmage below, whlch wlll be used for calculaLlons Lo work ouL Lhe dlfferences beLween
Llmes ln seconds, mlnuLes and hours, all of an lnLeger Lype:

Asslgn values to clock_in and clock_out of 073000 and 160000 respectively. Then, to
work out the difference between the two in seconds, use the calculation clock_out -
clock_in and assign this value to seconds_diff. Then include some WRITE statements Lo
ouLpuL Lhls lnformaLlon:


1o esLabllsh Lhe dlfference ln mlnuLes, slmply use Lhe seconds_dlff value, and dlvlde Lhls
by 60, and Lhen Lo esLabllsh Lhe hours dlfference, follow Lhls by dlvldlng mlnuLes_dlff by
60:


142
WORKING WITH OTHER DATA TYPES

noLe LhaL here, Lhe 310 mlnuLes do noL, ln facL, equal 9 hours exacLly, Lhe sysLem has
rounded Lhe number. 1hls ls because Lhe hours_dlff varlable was declared as an lnLeger. lf
Lhe daLa Lype for Lhls ls changed Lo a packed declmal, Lhe value would have been esLab-
llshed as Lhe more accuraLe 8.3 hours:


uant|ty and Currency I|e|ds |n Ca|cu|at|ons
now, a look wlll be Laken aL uslng quanLlLy and currency flelds ln calculaLlons. ln A8A,
Lhese are LreaLed Lhe same as packed number flelds. Currency flelds musL be declared as
data type p, bearlng ln mlnd how many declmal places are requlred. 1hls ls lmporLanL, as
havlng Lhe rlghL number of declmal places can have a large lmpacL on Lhe accuracy of cal-
culaLlons.
Quite often in a program, one wants to create ones own variables for quantity and cur-
rency flelds. lL ls usually beLLer, however, Lo assoclaLe Lhese flelds wlLh Lhe daLa Lypes of
Lhose ln a Lable creaLed ln Lhe A8A dlcLlonary. 1hls ls because Lhe A8A dlcLlonary wlll
already have deflned Lhe correcL fleld lengLh and number of declmal places for Lhese. lor
example, Lhe Salary fleld ln Lhe Lable creaLed prevlously had deflned Lwo declmal places. lf
a currency fleld ln a program ls declared Lo maLch Lhls fleld buL Lhe daLa Lype ln Lhe pro-
gram ls seL manually Lo 2 declmal places and Lhe number of declmal places ln Lhe Lable
was Lo change, Lhe program would no longer operaLe properly here. lor Lhls reason, lL ls
usually preferable Lo use Lhe LlkL sLaLemenL for Lhese flelds.
In this example a new variable named my_salary has been declared uslng Lhe LlkL
sLaLemenL:

8ecause Lhls fleld ln Lhe program ls llnked Lo Lhe fleld ln Lhe Lable, Lhe sysLem wlll ensure
Lhese daLa Lypes are kepL ln sync. 1here are Lwo aspecLs Lo Lhls process, Lhe number of

143
WORKING WITH OTHER DATA TYPES
declmal places, and Lhe assoclaLed currency (or quanLlLy) keys. lf you look aL Lhe Cu88
daLa Lype ln Lhe A8A dlcLlonary, you wlll see LhaL Lhls ls sLored as a declmal - 9 characLers
and 2 declmal places. ?ou can also see LhaL lLs lnLernal formaL ls A8A Lype p, packed
declmal:



AddlLlonally, dont forget that the salary field and its currency data type always refer to
Lhe currency key fleld, ln Lhe Lable called LCu88LnC?. ulLlmaLely, Lhen, when one ls de-
clarlng flelds ln A8A, lL ls lmporLanL Lo reference Lhese Lo Lhe assoclaLed flelds ln a Lable,
and when worklng wlLh currencles, Lhe currency key fleld wlll always be Lhere and should
be Laken lnLo accounL. 1he same applles Lo quanLlLy flelds. 1he only dlfference ls Lhelr daLa
Lype ls CuAn, and raLher Lhan a currency key, wlll always have a unl1 assoclaLed wlLh
Lhem.
Now, using calculations from the currency field, an employees tax and net pay amounts
wlll be esLabllshed, so declare Lwo more uA1A sLaLemenLs for Lhese flelds, agaln referenc-
lng Lhe salary fleld ln Lhe Lable. Also add a Lax percenLage varlable, of Lype p wlLh 2 decl-
mals:

Add a 1A8LLS sLaLemenL so LhaL Lhe program knows Lo refer Lo Lhe ZLMLC?LLS2 Lable,
Lhen observe Lhe calculaLlons ln Lhe code below:

144
WORKING WITH OTHER DATA TYPES


llrsL, Lhe Lax percenLage ls esLabllshed. 1hls ls ln Lhls example 20, so for Lhe means of Lhe
calculaLlons ls wrlLLen as 0.20. 1hen Lhe code wlll selecL records from Lhe ZLMLC?LLS2
Lable, and wrlLe Lhe surnames, salarles and currencles for Lhese. nexL, Lhe Lax amounL ls
esLabllshed, by mulLlplylng Lhe Lax percenLage by Lhe salary. neL pay ls equal Lo Lhe salary,
mlnus Lhe Lax amounL. 1hen add a W8l1L sLaLemenL Lo ouLpuL Lhe resulLs Lhe end of Lhe
SLLLC1 loop. 1he ouLpuL should look llke Lhls (where salarles and currencles are noL pre-
senL ln Lhe Lable, go back and edlL Lhe records ln your Lable Lo puL some values):

1he surname, salary and currency for each record are wrlLLen on Lhe flrsL llne, followed by
Lhe Lax amounL and neL pay on Lhe followlng llne. 1o make Lhls look Lldler, descrlpLlve LexL
can be added Lo Lhe W8l1L sLaLemenLs ln Lhe code:

145
WORKING WITH OTHER DATA TYPES





146
MODIFYING DATA IN DATABASE TABLES
Chapter 9 Mod|fy|ng Data |n a Database 1ab|e

Author|sat|ons
When wrlLlng programs uslng open SCL, one has Lo bear ln mlnd Lhe concepLs of auLhorl-
saLlon ln an SA sysLem. An SA sysLem has lLs own securlLy Lools Lo ensure LhaL users can
only access daLa whlch Lhey are auLhorlsed Lo see. 1hls lncludes lndlvldual flelds as well as
lndlvldual records. 1he way auLhorlsaLlons are seL up can also llmlL how daLa ls used,
wheLher a user can only dlsplay daLa or wheLher Lhey can modlfy lL. All Lhe rules perLaln-
lng Lo Lhls are sLored as auLhorlsaLlon ob[ecLs. 1hese wlll noL be examlned ln greaL deLall
here, buL ordlnarlly users are asslgned Lhelr own auLhorlsaLlon proflle (or composlLe pro-
flle) agalnsL Lhelr user record, whlch for lnformaLlonal purposes ls managed Lhrough
LransacLlon code Su01.
1hls proflle Lhen glves Lhe user Lhe correcL rlghLs wlLhln Lhe program Lo Lhen carry ouL
Lhelr [ob and SA dellvers many predeLermlned user proflles wlLh Lhe base sysLem. 1he
sysLem admlnlsLraLors can Lhen use and enhance Lhese Lo be applled Lo users. Cnce a user
has one of Lhese proflles, Lhe sysLem wlll Lell Lhem wheLher or noL Lhey can execuLe a
LransacLlon when Lhey Lry Lo do Lhls. lor example, LransacLlon SL38, Lhe A8A edlLor,
could be Lweaked so LhaL whlle some users may be able Lo access lL, perhaps Lhey can only
do so ln dlsplay mode, or perhaps Lhey can dlsplay and debug Lhe code, buL noL change lL
Lhemselves.
Where speclflc auLhorlsaLlons have noL been lmplemenLed, programs can be made Lo
carry ouL an auLhorlLy check, uslng Lhe sLaLemenL Au1PC8l1?-CPLCk. 1hls musL be used lf
a program or LransacLlon ls noL sufflclenLly proLecLed by Lhe sLandard auLhorlsaLlon pro-
flles already seL up ln Lhe sysLem.
Whlle, Lhls wlll noL be examlned ln greaL deLall here (Lhe Loplc ls huge ln lLself), lL ls lmpor-
LanL Lo bear auLhorlsaLlons ln mlnd when worklng ln SA.
Iundamenta|s
So far, readlng daLa from daLabase Lables has been looked aL, now modlfylng and deleLlng
Lhls daLa wlll be examlned. 1here are some lmporLanL concepLs Lo keep ln mlnd here, for

147
MODIFYING DATA IN DATABASE TABLES
example, Lhe archlLecLure of Lhe sysLem. lf one has a Lhree-Ller archlLecLure (wlLh a pres-
enLaLlon layer, an appllcaLlon server and an underlylng daLabase), you musL bear ln mlnd
LhaL Lhere may be a very large number of users accesslng Lhe daLa aL any one Llme. lL ls
lmporLanL Lo ensure LhaL programs creaLed do noL cause any problems ln Lhe resL of Lhe
sysLem and LhaL Lhe mosL recenL verslon of Lhe daLa held on Lhe daLabase ls accessed
when a program runs. lf records are consLanLly belng updaLed, programs musL be able Lo
read and work wlLh daLa whlch ls currenL ln Lhe sysLem. lorLunaLely, mosL of Lhls work ls
done automatically by the SAP system, and one doesnt have to worry too much about the
underlylng Lechnologles relaLed Lo how daLa ls locked and so on.
Cne of Lhe key Lools whlch can be used ls Cpen SCL. 1hls acLs as an lnLerface beLween Lhe
programs creaLed and Lhe daLabase. 8y uslng Cpen SCL, one can read and modlfy daLa,
and also buffer daLa on Lhe appllcaLlon server, whlch reduces Lhe number of daLabase ac-
cesses Lhe sysLem has Lo perform. lL ls Lhe daLabase lnLerface whlch ls also responslble for
synchronlslng Lhe buffers wlLh Lhe daLabase Lables aL predeLermlned lnLervals.
When one ls creaLlng programs lL ls lmporLanL Lo keep ln mlnd LhaL lf daLa ls buffered, and
Lhls buffered daLa ls subsequenLly read, lL may noL always be up Lo daLe. So, when Lables
are creaLed, Lhey musL be creaLed ln such a way LhaL Lhe sysLem ls Lold LhaL bufferlng can
or cannoL be used, or LhaL lL can only be used ln cerLaln slLuaLlons. When Lhe example La-
bles were creaLed earller, Lhe sysLem was Lold noL Lo use bufferlng. uslng Lhls seLLlng
means LhaL every Llme daLa ls read from a Lable, lL wlll always use Lhe mosL up Lo daLe re-
cords.
8ufferlng can be useful for Lables whlch hold masLer daLa and conflguraLlon seLLlngs, be-
cause Lhls klnd of daLa does noL geL updaLed regularly. When one ls worklng wlLh Lransac-
Llonal daLa however, one wanLs Lhls daLa Lo be as up Lo daLe as posslble. lf LransacLlonal
daLa ls belng used ln a conLexL where Lables are uslng bufferlng, lL ls lmporLanL Lo ensure
LhaL programs relaLed Lo Lhls can Lake Lhls lnLo accounL, and make sure LhaL Lhe buffer ls
updaLed wlLh new daLa when Lhls ls needed.
When one uses Cpen SCL sLaLemenLs ln a program, Lables can only be accessed Lhrough
Lhe A8A dlcLlonary. 1hls acLs as an lnLerface, one does noL access Lhe Lables dlrecLly
Lhrough programs. 1hls ls noL a problem however, as when one uses Cpen SCL sLaLe-
menLs, lL works [usL Lhe same as lf one was accesslng Lhe daLabase dlrecLly. Cpen SCL
manages lLs lnLerface wlLh Lhe daLabase by lLself, wlLhouL Lhe need for Lhe user Lo do any-

148
MODIFYING DATA IN DATABASE TABLES
Lhlng here. SLaLemenLs can be coded [usL as Lhough Lhey had dlrecL access Lo Lhe Lables,
Lhough wlLh Lhe underlylng knowledge LhaL by uslng Cpen SCL, Lhe daLa ls ln facL belng
accessed Lhrough Lhe A8A dlcLlonary wlLh a bullL-ln level of safeLy Lo ensure Lhe A8A
code does noL have a dlrecL effecL on Lhe SA daLabase sysLem lLself.
Database Lock Cb[ects
now, locklng concepLs wlll be consldered. 1hls refers Lo locklng daLa ln daLabase Lables
and Lhere are Lwo baslc Lypes of locklng whlch musL be kepL ln mlnd. llrsL of all, daLabase
locks. 1hese lock daLa ln a physlcal daLabase. When a record ls updaLed, a lock ls seL on
Lhls, Lhen when lL ls updaLed Lhe lock ls released. lL ls Lhere Lo ensure LhaL, once seL, Lhe
daLa can only be accessed and updaLed by Lhose auLhorlsed Lo do so. When released, lL
can be accessed more wldely.
1hese locks, Lhough, are noL sufflclenL ln an SA sysLem, and are generally only used when
a record ls belng modlfled ln a slngle sLep dlalogue process. 1hls process refers Lo any Llme
LhaL Lhe daLa ln a daLabase can be updaLed ln a slngle sLep, on a slngle screen. ln Lhls case,
Lhe daLa can be locked, updaLed and released very qulckly.
As you work more wlLh SA, Lhe lnsufflclency of daLabase locks wlll become clearer, be-
cause LransacLlons ln an SA sysLem ofLen occur over mulLlple sLeps. lf, for example, an
employee record ls added Lo Lhe sysLem, one may have Lo flll ln many screens of daLa. 1he
user ln Lhls case wlll only wanL Lhe record Lo be added Lo Lhe sysLem aL Lhe end of Lhe lasL
screen, once all of the data in all of the screens has been input. If just the first screens
data was saved into the database, then the seconds, and so on, one by one, if the user
were Lo qulL halfway Lhrough Lhe process, an lnvalld and unflnlshed record would be ln
Lhe daLabase.
1hls demonsLraLes Lhe hazard of uslng daLabase locks wlLh mulLl-sLep dlalogue processes.
lor Lhese lnsLances, SA has lnLroduced a new klnd of lock, lndependenL of Lhe daLabase
sysLem. 1hese are called lock ob[ecLs, and allow daLa records Lo be locked ln mulLlple da-
Labase Lables for Lhe whole duraLlon of Lhe SA LransacLlon, provlded LhaL Lhese are llnked
ln Lhe A8A dlcLlonary by forelgn key relaLlonshlps.
SA lock ob[ecLs form Lhe basls of Lhe lock concepL, and are fully lndependenL of daLabase
locks. A lock ob[ecL allows one Lo lock a record for mulLlple Lables for Lhe enLlre duraLlon
of an SA LransacLlon. lor Lhls Lo work, Lhe Lables musL be llnked LogeLher uslng forelgn

149
MODIFYING DATA IN DATABASE TABLES
keys. 1he A8A dlcLlonary ls used Lo creaLe lock ob[ecLs, whlch conLaln Lhe Lables and key
flelds whlch make up a shared lock.
When Lhe lock ob[ecL ls creaLed, Lhe sysLem auLomaLlcally creaLes Lwo funcLlon modules,
whlch wlll be dlscussed laLer. 1hese funcLlon modules are slmply modularlsed A8A pro-
grams LhaL can be called from oLher programs. 1he flrsL of Lhese has Lhe acLlon of seLLlng a
lock, and the second releases this lock. It is the programmers responsibility to ensure that
Lhese funcLlon modules are called aL Lhe correcL place ln Lhe program. When a lock ls seL,
a lock record ls creaLed ln Lhe cenLral lock Lable for Lhe enLlre SA sysLem. All programs
musL adhere Lo uslng Lhe SA lock concepL Lo ensure LhaL Lhey seL, deleLe and query Lhe
lock Lable LhaL sLores Lhe lock records for Lhe relevanL enLrles.
Lock ob[ecLs wlll noL be dlscussed much furLher, however subsequenL programs creaLed,
Lables accessed and so on here wlll be done on Lhe assumpLlon LhaL Lhey are noL Lo be
used outside of ones own system.
Us|ng Cpen SL Statements
now, some of Lhe Cpen SCL sLaLemenLs whlch can be used ln programs wlll be looked aL.
As menLloned before, Cpen SCL sLaLemenLs allow one Lo lndlrecLly access and modlfy
daLa held ln Lhe underlylng daLabase Lables. 1he SLLLC1 sLaLemenL, whlch has been used
several Llmes prevlously, ls very slmllar Lo Lhe sLandard SCL SLLLC1 sLaLemenL used by
many oLher programmlng languages. WlLh Cpen SCL, Lhese klnds of sLaLemenLs can be
used ln A8A programs regardless of whaL Lhe underlylng daLabase ls. 1he sysLem could
be runnlng, for example, an Cracle daLabase, a MlcrosofL SCL daLabase, or any oLher, and
by uslng Cpen SCL ln programs ln con[uncLlon wlLh Lhe A8A dlcLlonary Lo creaLe and
modlfy daLabase Lables, one can be cerLaln LhaL Lhe A8A code wlll noL have any lssues
accesslng Lhe daLa held by Lhe speclflc Lype of daLabase Lhe SA sysLem uses.
When Lhe flrsL daLabase Lable was creaLed prevlously, Lhe fleld MAnu1 was used, repre-
senLlng Lhe cllenL number and formlng parL of Lhe daLabase Lable key, hlghllghLed below:


150
MODIFYING DATA IN DATABASE TABLES
Cne may Lhlnk LhaL, glven Lhe lmporLance of Lhls fleld, lL would have Lo be used ln A8A
programs when uslng Cpen SCL sLaLemenLs, however, lL does noL. AlmosL all Lables wlll
include this hidden field within them, and the SAP system is built in such a way thaL a
fllLer ls auLomaLlcally applled Lo Lhls fleld, based on Lhe cllenL lu belng used. lf one ls
logged ln, for example, Lo cllenL 100, Lhe sysLem wlll auLomaLlcally fllLer all records ln Lhe
daLabase on Lhls cllenL key and only reLurn Lhose for cllenL 100. When Cpen SCL ls used ln
Lhe programs one creaLes, Lhe sysLem manages Lhls fleld lLself, meanlng lL never has Lo be
lncluded ln any selecLlons or updaLe sLaLemenLs used ln programs. Also, Lhls carrles Lhe
beneflL of securlLy ln Lhe knowledge LhaL any Cpen SCL sLaLemenL execuLed ln a program
wlll only affecL Lhe records held ln Lhe currenL cllenL.
Us|ng Cpen SL Statements S Statements
1here are 3 baslc Cpen SCL sLaLemenLs whlch wlll be used regularly ln programs from here
forward. 1hese are SLLLC1, lnSL81, uuA1L, MCull? and uLLL1L.
1he SLLLC1 sLaLemenL has, of course, already been used. 1hls sLaLemenL allows
one Lo selecL records from daLabase Lables whlch wlll Lhen be used ln a program.
lnSL81 allows new records Lo be lnserLed lnLo a daLabase Lable.
uuA1L allows records whlch already exlsL ln Lhe Lable Lo be modlfled.
MCull? performs a slmllar Lask Lo updaLe, wlLh sllghL dlfferences whlch we wlll
dlscuss shorLly.
uLLL1L, of course, allows records Lo be deleLed from a Lable.
Whenever any of Lhese sLaLemenLs are used ln an A8A program, lL ls lmporLanL Lo check
wheLher Lhe acLlon execuLed has been successful. lf one Lrles Lo lnserL a record lnLo a da-
Labase Lable, and lL ls noL lnserLed correcLly or aL all, lL ls lmporLanL Lo know, so LhaL Lhe
approprlaLe acLlon can be Laken ln Lhe program. 1hls ls done uslng a sysLem fleld whlch
has already been used: S?-Su88C. When a sLaLemenL ls execuLed successfully, Lhe S?-
Su88C fleld wlll conLaln a value of 0, so Lhls can be checked for and, lf lL appears, one can
conLlnue wlLh Lhe program. lf lL ls noL successful, however, Lhls fleld wlll conLaln a dlffer-
enL value, and dependlng on Lhe sLaLemenL, Lhls value can have dlfferenL meanlngs. lL ls
Lherefore lmporLanL Lo know whaL Lhe dlfferenL reLurn codes are for Lhe dlfferenL A8A
sLaLemenLs, so as Lo recognlse problems and Lake Lhe correcL course of acLlon Lo solve
Lhem. 1hls may sound dlfflculL, buL wlLh pracLlce wlll become second-naLure.

151
MODIFYING DATA IN DATABASE TABLES
Insert Statement
1he SLLLC1 sLaLemenL has already been used, so here lL wlll be sklpped for now Lo focus
on Lhe lnSL81 sLaLemenL. ln Lhls example Lhen, a new record wlll be lnserLed lnLo Lhe
ZLMLC?LLS Lable. llrsLly, Lype lnSL81, followed by Lhe Lable name, and Lhen a perlod:

uolng Lhls, one musL always Lype Lhe Lable name, a variables name cannot be used in-
sLead. use Lhe check sLaLemenL (ll) Lo lnclude an S?-Su88C check, Lelllng Lhe sysLem Lo do
lf Lhls does noL equal 0:

1hls ls Lhe slmplesL form of Lhe lnSL81 sLaLemenL, and noL necessarlly Lhe one whlch ls
encouraged. uslng Lhls form ls no longer sLandard pracLlce, Lhough one may come across
lL lf worklng wlLh older A8A programs.
ln Lhe above sLaLemenL, noLhlng ls speclfled Lo be lnserLed. 1hls ls where Lhe concepL of
Lhe work area enLers. 1he sLaLemenL here expecLs a work area Lo exlsL whlch has been
creaLed when an lnLernal Lable was declared. 1hls Lype of work area ls ofLen referred Lo as
a header record:

1he Lable above shows Lhe yellow area as a sLandard Lable conLalnlng four records and
Lhelr respecLlve flelds, Lhe area above ln grey ls Lhe header record, whlch ls sLored ln
memory and ls Lhe area whlch ls accessed when Lhe Lable ls referenced from a program
only by lLs Lable name. lf an lnSL81 sLaLemenL ls execuLed, whaLever ls conLalned ln Lhe
header record wlll be lnserLed lnLo Lhe Lable lLself. 1he header record does noL exlsL ln Lhe

152
MODIFYING DATA IN DATABASE TABLES
Lable, lL ls [usL an area sLored ln memory where a currenL record can be worked wlLh,
hence Lhe Lerm work area. When someone refers Lo Lhe Lable only by lLs Lable name, lL ls
Lhe header record whlch ls referred Lo, and Lhls can become confuslng. Cne Lhlnks LhaL
one ls referenclng Lhe Lable lLself, buL ln facL lL ls Lhe header record whlch ls belng worked
wlLh, a record held ln memory wlLh Lhe same sLrucLure as Lhe Lable. A8A ob[ecLs, whlch
are lmporLanL when one geLs Lo a more advanced sLage ln A8A, wlll noL allow a header
record Lo be referred Lo, so lL ls lmporLanL noL Lo do Lhls. Peader records were used com-
monly for Lhls ln Lhe pasL, buL as noLed prevlously, Lhls ls no longer Lhe way Lhlngs are
done.
1o avold confuslon when worklng wlLh lnLernal Lables should programs musL work wlLh
separaLe work areas, whlch are perhaps slmllar ln sLrucLure Lo a header record, buL noL
aLLached Lo Lhe Lable, wlLh a separaLe name. 1hese are separaLe sLrucLures from Lhe lnlLlal
Lable, whlch are creaLed ln a program.

1o declare a work area the DATA statement is used. Give this the name wa_employees.
now, raLher Lhan declarlng one daLa Lype for Lhls, several flelds whlch make up Lhe Lable
wlll be declared. 1he easlesL way Lo do Lhls ls Lo use Lhe LlkL sLaLemenL.
So here, Lhe wa_employees work area ls declared LlkL Lhe zemployees Lable, Laklng on Lhe
same sLrucLure wlLhouL becomlng a Lable lLself. 1hls work area wlll only sLore one record.
Cnce Lhls ls declared, Lhe lnSL81 sLaLemenL can be used Lo lnserL Lhe work area and Lhe
record it holds into the table. The code here will read INSERT zemployees FROM
wa_employees:


153
MODIFYING DATA IN DATABASE TABLES
AJJltlooolly, osloq tbls fotm of tbe lN5k1 stotemeot ollows yoo to speclfy tbe toble oome
osloq o votloble losteoJ. lt ls lmpottoot to oote bete tbot lf ooe ls Joloq tbls, tbe votloble
most be sottoooJeJ by btockets.
now, Lhe work area musL be fllled wlLh some daLa. use Lhe fleld names from Lhe
zemployees Lable. 1hls can be done by forward navlgaLlon, double-cllcklng Lhe Lable name
ln Lhe code, or by openlng a new sesslon and uslng SL11. 1he flelds of Lhe Lable can Lhen
be copy & pasted into the ABAP editor and the work areas fields populated as in the
lmage below:

1he check sLaLemenL can Lhen be formulaLed as follows, meanlng LhaL lf Lhe record ls ln-
serLed correcLly, Lhe sysLem wlll sLaLe Lhls, lf noL Lhen Lhe S?-Su88C code whlch wlll noL
equal zero ls wlll be dlsplayed:

Check Lhe program, save, and acLlvaLe Lhe code, Lhen LesL lL. 1he ouLpuL wlndow wlll dls-
play:

lf you check Lhe records ln your Lable vla Lhe Data Browser screen in the ABAP dictionary,
a new record wlll be vlslble:

154
MODIFYING DATA IN DATABASE TABLES

lor pracLlce use Lhe A8A debugger Lo execuLe Lhe code sLep-by-sLep. llrsL, deleLe Lhe
record from Lhe Lable ln Lhe A8A dlcLlonary and puL a breakpolnL ln Lhe code aL Lhe be-
glnnlng of Lhe record enLry Lo Lhe work area:

now execuLe Lhe program. 1he breakpolnL wlll cause program execuLlon Lo pause aL your
breakpolnL and Lhe debugger wlll open:

llrsLly, use Lhe llelds mode Lo vlew Lhe work area sLrucLure. uouble cllck Lhe
wa_employees after the DATA statement and it will appear in the Field names box at the
boLLom. AL Lhls polnL Lhe work area ls compleLely empLy, evldenced by Lhe zeros ln Lhe
ad[acenL box. 1o dlsplay Lhe full sLrucLure, double cllck Lhe wa_employees ln Lhe lefL box:


155
MODIFYING DATA IN DATABASE TABLES

1hen, execuLe each llne of code sLarLlng from Lhe breakpolnL uslng Lhe l3 key, Lhe flelds
wlLhln Lhls sLrucLure vlew are fllled one by one:

8eLurn Lo Lhe llelds vlew before execuLlng Lhe lnSL81 sLaLemenL, and observe Lhe S?-
Su88C fleld aL Lhe boLLom of Lhe wlndow. lL dlsplays a value of 0. lf Lhere are any prob-
lems ln Lhe execuLlon, Lhls wlll Lhen change (4 for a warnlng, 8 for an error). Clven LhaL
Lhls code has already been successful, you already know LhaL lL wlll remaln 0. Cnce Lhe
program has been execuLed ln Lhe debugger, refresh Lhe Lable ln Lhe uaLa 8rowser screen
agaln, and Lhe record wlll be vlslble.
C|ear Statement
AL Lhls polnL, Lhe CLLA8 sLaLemenL wlll be lnLroduced. ln A8A programs, one wlll noL al-
ways slmply see Lhe program sLarL aL Lhe Lop, lnserL one daLa record and conLlnue on.

156
MODIFYING DATA IN DATABASE TABLES
Loops and Lhe llke wlll be seL up, allowlng, for example, many records Lo be lnserLed aL
once. 1o do Lhls, varlables and sLrucLures are re-used repeaLedly. 1he CLLA8 sLaLemenL
allows a fleld or varlable Lo be cleared ouL for Lhe lnserLlon of new daLa ln lLs place, allow-
lng lL Lo be re-used. 1he CLLA8 sLaLemenL ls cerLalnly one whlch ls used commonly ln pro-
grams, as lL allows exlsLlng flelds Lo be used mulLlple Llmes.
ln Lhe prevlous example, Lhe work area sLrucLure was fllled wlLh daLa Lo creaLe a new re-
cord Lo be lnserLed lnLo Lhe zemployees Lable, Lhen a valldaLlon check performed. lf one
Lhen wanLs Lo lnserL a new record, Lhe work area code can Lhen be copy & pasLed below
Lhls. Powever, slnce Lhe work area sLrucLure ls already full, Lhe CLLA8 sLaLemenL musL be
used so LhaL lL can Lhen be fllled agaln wlLh Lhe new daLa.
1o do Lhls, Lhe new llne of code would read CLEAR wa_employees.
lf you [usL wanLed Lo clear speclflc flelds wlLhln your sLrucLure you [usL need Lo speclfy Lhe
lndlvldual flelds Lo be cleared, as ln Lhe example below, clear Lhe employee number fleld.
new daLa can Lhen be enLered lnLo Lhe work area agaln:

8emember LhaL Lhe employee number ls a key fleld for Lhe zemployees Lable, so as long as
Lhls ls unlque, dupllcaLe lnformaLlon could be enLered lnLo Lhe oLher flelds. lf one Lrles Lo
enLer Lhe same employee number agaln Lhough, Lhe sy-subrc fleld wlll dlsplay a warnlng
wlLh Lhe number 4.
?ou can see Lhe operaLlon of Lhe CLLA8 sLaLemenL ln debug mode. 1he Lhree lmages be-
low dlsplay Lhe Lhree sLages of lLs operaLlon on Lhe fleld conLenLs as Lhe code ls execuLed:

157
MODIFYING DATA IN DATABASE TABLES



Update Statement
1he uuA1L sLaLemenL allows one or more exlsLlng records ln a Lable Lo be modlfled aL
Lhe same Llme. ln Lhls example lL wlll [usL be applled Lo one, buL for more Lhe same prlncl-
ples generally apply.
!usL as wlLh Lhe lnSL81 sLaLemenL, a work area ls declared, fllled wlLh Lhe new daLa whlch
ls Lhen puL lnLo Lhe record as Lhe program ls execuLed.
ueleLe Lhe record creaLed wlLh Lhe CLLA8 sLaLemenL as before. Pere, Lhe record prevl-
ously creaLed wlLh Lhe lnSL81 sLaLemenL wlll be updaLed. Copy & pasLe Lhe work area and
Lhen alLer, Lhe LexL sLored ln Lhe Su8nAML and lC8LnAML flelds. 1hen on a new llne, Lhe
same sLrucLure as for Lhe lnSL81 sLaLemenL ls used, buL Lhls Llme uslng uuA1L:


158
MODIFYING DATA IN DATABASE TABLES
As Lhls ls run llne-by-llne ln debug mode, you can see Lhe lleld conLenLs change as lL ls
execuLed:


Cnce Lhe uuA1L sLaLemenL has been execuLed you can vlew Lhe uaLa 8rowser ln Lhe
A8A ulcLlonary Lo see LhaL Lhe record has been changed successfully:

Mod|fy Statement
1he MCull? sLaLemenL could be sald Lo be llke a comblnaLlon of Lhe lnSL81 and uuA1L
sLaLemenLs. lL can be used Lo elLher lnserL a new record or modlfy an exlsLlng one. Cener-
ally, Lhough Lhe lnSL81 and uuA1L sLaLemenLs are more wldely used for Lhese purposes,
slnce Lhese offer greaLer clarlLy. uslng Lhe MCull? sLaLemenL regularly for Lhese purposes
ls generally consldered bad pracLlce. Powever, Llmes wlll arlse where lLs use ls approprl-
aLe, for example of one ls wrlLlng code where a record musL be lnserLed or updaLed de-
pendlng on a cerLaln slLuaLlon.

159
MODIFYING DATA IN DATABASE TABLES
unsurprlslngly, Lhe MCull? sLaLemenL follows slmllar synLax Lo Lhe prevlous Lwo sLaLe-
menLs, modlfylng Lhe record from Lhe daLa enLered lnLo a work area. When Lhls sLaLemenL
ls execuLed, Lhe key flelds lnvolved wlll be checked agalnsL Lhose ln Lhe Lable. lf a record
wlLh Lhese key fleld values already exlsLs, lL wlll be updaLed, lf noL Lhen a new record wlll
be creaLed.
ln Lhe flrsL secLlon of code ln Lhe lmage below, slnce employee number ls Lhe key fleld,
and 10000006 already exists, the record for that employee number will be updated with
Lhe new name ln Lhe code. A valldaLlon check ls performed nexL. 1he CLLA8 sLaLemenL ls
Lhen used so a new enLry can be puL lnLo Lhe work area, and Lhen employee 10000007 ls
added. Slnce Lhls ls a new, unlque key fleld value, a new record wlll be lnserLed, and an-
oLher valldaLlon check execuLed:



160
MODIFYING DATA IN DATABASE TABLES
When Lhls ls execuLed, and Lhe daLa Lhen vlewed ln Lhe uaLa 8rowser, employee number
10000006 wlll have been updaLed wlLh Lhe new name, eLer norLhmore, and a new re-
cord wlll have been creaLed for number 10000007, Susan SouLhmore:

De|ete Statement
1he lasL sLaLemenL Lo be looked aL ln Lhls secLlon ls Lhe uLLL1L sLaLemenL. Cne musL be
careful uslng Lhls, because lf used lncorrecLly, Lhere ls Lhe posslblllLy of wlplng Lhe enLlre
conLenLs of Lhe Lable, however, as long as lL ls used correcLly, Lhere should be no problem
of Lhls sorL.
unllke Lhe prevlous SCL sLaLemenLs, Lhe uLLL1L sLaLemenL does noL Lake lnLo accounL
mosL flelds, only Lhe prlmary key fleld. When you wanL Lo deleLe a record from a Lable, Lhe
sysLem only needs Lo be Lold whaL Lhe prlmary key fleld value for LhaL record ls.
ln Lhls example, Lhe lasL record creaLed, for Lhe employee Susan SouLhmore wlll be de-
leLed. lor Lhe zemployees Lable, Lhere are Lwo key flelds, Lhe cllenL fleld and Lhe employee
number. 1he cllenL fleld ls dealL wlLh auLomaLlcally by Lhe sysLem, and Lhls never has Lo be
lncluded ln programs, so Lhe lmporLanL fleld here ls Lhe employee number fleld. 1he syn-
Lax Lo deleLe Lhe lasL record creaLed ln Lhe prevlous secLlon would be Lhls:

1he l8CM addlLlon ln Lhe lasL llne ensures only Lhe record referred Lo by lLs key fleld ln
Lhe work area wlll be deleLed. Agaln, a valldaLlon check ls performed Lo ensure Lhe record
ls deleLed successfully. When Lhls ls run ln debug mode you can see Lhe flelds whlch are
fllled wlLh Lhe creaLlon of Lhe record are cleared as Lhe CLLA8 sLaLemenL execuLes.
AfLer Lhe employee number ls fllled agaln Lhe uLLL1L sLaLemenL ls execuLed. 1he codes
ouLpuL wlndow wlll lndlcaLe Lhe success of Lhe deleLlon and Lhe record wlll no longer ap-
pear ln Lhe 8rowser vlew of Lhe Lable:

161
MODIFYING DATA IN DATABASE TABLES





162
MODIFYING DATA IN DATABASE TABLES

1he record ls now gone from Lhe Lable.
1here ls anoLher form of Lhe uLLL1L sLaLemenL whlch can be used. ?ou are noL [usL re-
sLrlcLed Lo uslng Lhe Lable key Lo deleLe records, loglc can also be used. So, raLher Lhan
uslng Lhe work area Lo speclfy a key fleld, and uslng Lhe l8CM addlLlon Lo Lhe uLLL1L
sLaLemenL, one can use Lhe WPL8L addlLlon Lo Lell Lhe program Lo deleLe all records
where a cerLaln fleld maLches a cerLaln value, meanlng LhaL lf one has several records
whlch maLch Lhls value, all of Lhem wlll be deleLed.
1he nexL example wlll demonsLraLe Lhls. All records wlLh Lhe surname 8towo wlll be de-
leLed. 1o be able Lo demonsLraLe Lhls, creaLe a second record conLalnlng a surname of
8rown, save Lhls and vlew Lhe daLa:


1he code for Lhe new uLLL1L sLaLemenL should Lhen look llke Lhls. noLe Lhe addlLlonal
l8CM whlch musL be used ln Lhls lnsLance:

163
MODIFYING DATA IN DATABASE TABLES

When Lhls code ls execuLed, boLh records conLalnlng a Surname of 8rown wlll be deleLed.


Note tbot, lf ooe oses tbe followloq plece of coJe, wltboot speclfyloq tbe loqlc oJJltloo, oll
of tbe tecotJs wlll lo foct be JeleteJ.



164
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
Chapter 10 rogram I|ow Contro| and Log|ca|
Lxpress|ons

Contro| Structures
1hls secLlon wlll look aL program flow conLrol and loglcal expresslons. lL could be argued
LhaL Lhls ls really Lhe maln aspecL of A8A programmlng, where Lhe real work ls done.
Pow one sLrucLures a program uslng loglcal expresslons wlll deLermlne Lhe compleLe flow
of Lhe program and ln whaL sequence acLlons are Laken.
llrsL, a look wlll be Laken aL conLrol sLrucLures. When a program ls creaLed lL ls broken up
lnLo many Lasks and subLasks. Cne conLrols how and when Lhe secLlons of a program are
execuLed uslng loglcal expresslons and condlLlonal loops, ofLen referred Lo as conLrol
sLrucLures.
If Statement
Copy you program prevlous chapLer ln whlch Lo LesL some of Lhe loglc whlch ls Lo be bullL.
Pere l copy Lhe program Z_CLnSCL_1 Lo Z_LCClC_1:

8emove all of Lhe code from Lhe program, leavlng only Lhe flrsL example lnSL81 sLaLemenL
and lLs valldaLlon LesL.
When one Lalks of conLrol sLrucLures, Lhls refers Lo large amounLs of code whlch allows
one Lo make declslons, resulLlng ln a number of dlfferenL ouLcomes based on Lhe declslons
Laken. 1ake a look aL Lhe ll sLaLemenL Lo explaln Lhe baslc loglc aL work here.

165
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
1he ll sLaLemenL ls probably Lhe mosL common conLrol sLrucLure, found ln [usL abouL
every programmlng language. 1he synLax may vary beLween languages, buL lLs use ls [usL
abouL unlversal:

1hls ll sLaLemenL Lells Lhe program LhaL ll (a loglcal expresslon), do someLhlng. 1he LLSL
addlLlon means LhaL should Lhls loglcal expresslon noL occur, do someLhlng else. 1hen Lhe
sLaLemenL ls ended wlLh Lhe Lnull sLaLemenL.
1he ll and Lnull sLaLemenLs belong LogeLher, and every conLrol sLrucLure creaLed wlll
Lake a slmllar form, wlLh a sLarL and an end. ConLrol sLrucLures can be very large, and may
conLaln oLher, smaller conLrol sLrucLures wlLhln Lhem, havlng Lhe sysLem perform Lasks
wlLhln Lhe framework of a larger Lask. 1he code beLween Lhe sLarL and end of a conLrol
sLrucLure deflnes Lhe subLasks wlLhln lL. 1asks can be repeaLed, ln whaL are called loops.
lrom here on, conLrol sLrucLures wlll be used Lo conLrol Lhe flow, creaLe Lasks, subLasks
and branches wlLhln a program, and Lo perform loops.
Comment out all of the preceding code, and click the Pattern button, in the toolbar by
reLLy rlnLer. A window will appear, and just select the Other pattern fleld, and Lype
IF. The structure of an IF statement will then appear in the code, which can be followed
as a gulde:

166
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS


Create a DATA statement, 15 characters of type c, and name this surname. Then on a
new line give this the value SMITH. Then edit the auLo-generaLed ll sLaLemenL so LhaL lL
looks llke Lhls.

167
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS

The IF statement here takes the form that if the value of surname is SMITH, text will be
displayed stating Youve won a car! (noLe LhaL an aposLrophe cannoL be placed correcLly
in Youve without making the code invalid). Then execuLe Lhe code. 1he resulL should be:

nexL, Lhls wlll be exLended Lo lnclude Lhe LLSLll sLaLemenL whlch has been commenLed
out above. Change the value of surname to BROWN. Then, add to the ELSEIF statement
so that if the value of surname is BROWN, the output text will read Youve won a
boat!:


ln Lhls example, Lhe flrsL ll sLaLemenL was noL Lrue, as Lhe surname was noL SmlLh. Pence
Lhls branch was noL execuLed. 1he LLSLll sLaLemenL was Lrue, so Lhe LexL ouLpuL asslgned

168
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
here appeared. 1he LLSLll sLaLemenL can be added Lo an ll sLaLemenL any number of
Llmes, Lo deslgnaLe Lhe acLlon Laken ln a number of slLuaLlons:

Depending on what the value of surname is at any given time, a different branch will be
execuLed.
1here ls also Lhe LLSL sLaLemenL. 1hls ls used for Lhe lasL plece of Lhe ll block, and ls used
lf none of Lhe values ln Lhe ll and LLSLll sLaLemenL are maLched. 1he full block of code ls
shown below:

With this block as it is now, there will always be an output, regardless of the value of sur-
name, every possibility is now taken care of. 1he value wlll elLher maLch one of Lhe flrsL
four, or the ELSE statements text will be dlsplayed. 1he ll sLaLemenL ls very lmporLanL for
deLermlnlng Lhe flow of a program and wlll be used on a regular basls.


169
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
L|nk|ng Log|ca| Lxpress|ons 1ogether
1here are a whole seL of A8A operaLors whlch can be used wlLh loglc sLaLemenLs. WlLh
Lhe ll sLaLemenL so far Lhe equals (=) operaLor has been used. 1he followlng can also be
used here:

(ftom left to tlqbt. epool to, NO1 epool to, less tboo, qteotet tboo, less tboo Ok epool to,
qteotet tboo Ok epool to. 1bese coo olso be wtltteo wltb tbelt text epolvoleots, lo otJet.
O, N, l1, C1, l, C. 1be text vetsloos ote oot commooly oseJ.)
Loglcal expresslons can be llnked wlLh Lhe operaLors C8, Anu and nC1. lor example, one
could add Lo Lhe prevlous ll sLaLemenL:

C8 and nC1 operaLe can also be used ln exacLly Lhe same way
Nested If Statements
nesLed ll sLaLemenLs allow one Lo lnclude ll sLaLemenLs lnslde oLher ll sLaLemenLs, for
example:

Pere, Lhe flrsL ll sLaLemenL wlll dlscounL records where Lhe Surname fleld value does noL
equal SMITH. lor all records with a Surname = SMITH, Lhe second ll sLaLemenL checks
Lo see if the record being processed has a Forename = JOHN. If it does Lhe message
Youve won a car! wlll be ouLpuL Lo Lhe screen. lf noL, a consolaLory message wlll be ouL-
puL lnsLead.

170
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
?ou are noL llmlLed Lo [usL one nesLed ll sLaLemenL. nesLlng can conLlnue down as many
levels / branches as ls requlred by Lhe program belng wrlLLen, for example:

Also, you do noL slmply have Lo nesL sLaLemenLs one afLer anoLher, buL can puL any oLher
sLaLemenLs you need beLween, as long as Lhe conLrol sLrucLures are LermlnaLed correcLly
wlLh, ln Lhls case, Lhe Lnull sLaLemenL.
Case Statement
When loglcal expresslons are creaLed, and llnked LogeLher, lL ls always lmporLanL Lo make
Lhe code as readable as posslble. CeneraLlng many loglcal expresslons on one llne can of-
Len be confuslng. Whlle Lhe code wlll sLlll work wlLhouL problems, lL ls preferable Lo sLruc-
Lure your code across mulLlple llnes and make use of oLher conLrol sLrucLures lf posslble.
1hls ls where Lhe CASL sLaLemenL can help. 1hls does slmllar work Lo Lhe ll sLaLemenL buL
wlLh Lhe flexlblllLy Lo make Lhe code much more readable, buL ls aL Lhe same Llme llmlLed
Lo one loglcal expresslon. Pere ls an example code block for Lhe CASL sLaLemenL:

Llke Lhe ll sLaLemenL, here Lhe conLenLs of Lhe surname fleld are searched by Lhe CASL
sLaLemenL, checklng lLs conLenLs and performlng an acLlon. 1he WPLn addlLlon ls used Lo
check Lhe fleld for dlfferenL values, and WPLn C1PL8S accounLs for all values whlch are

171
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
noL speclfled elsewhere. 1he LnuCASL sLaLemenL closes Lhls conLrol sLrucLure. 1hls ls ln
many ways much easler Lo read Lhan a large amounL of nesLed lls and LLSLlls.
?ou also have Lhe faclllLy Lo nesL mulLlple CASL sLaLemenLs.

Se|ect Loops
1hls nexL secLlon wlll dlscuss lLeraLlon sLaLemenLs, oLherwlse known as looplng sLaLe-
menLs. 1hese are used Lo execuLe a block of A8A code mulLlple Llmes.
CreaLe anoLher new program and call lL Z_l1L8A1lCnS_1.
1here are varlous ways Lo loop Lhrough blocks of code ln an A8A program, and Lhese can
be separaLed lnLo Lhose whlch have condlLlons aLLached and Lhose whlch do noL. 1he
SLLLC1 sLaLemenL ls a form of loop whlch has already been used. 1hls sLaLemenL allows
you Lo lLeraLe Lhrough a record seL.

1he asLerlsk (*) Lells Lhe program Lo selecL everyLhlng from Lhe zemployees Lable, and Lhls
ls followed by a W8l1L sLaLemenL Lo wrlLe Lhe Lable Lo Lhe ouLpuL screen. 1he SLLLC1 loop

172
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
closed wlLh LnuSLLLC1, aL whlch polnL Lhe loop reLurns Lo Lhe sLarL, wrlLlng each record ln
Lurn unLll Lhere are no more records Lo process ln Lhe Lable.
1hls lasL example had no condlLlons aLLached. 1o add a condlLlon ls qulLe slmple:

Pere, only records where Lhe surname ls Mllls wlll be selecLed and wrlLLen Lo Lhe ouLpuL
screen:

Do Loops
1he uC loop ls a slmple sLaLemenL, here declare uC. Add a W8l1L sLaLemenL, and Lhen
LnuuC:

?ou wlll noLlce Lhere ls noLhlng Lo Lell Lhe loop Lo end. lf one Lrles Lo execuLe Lhe code, Lhe
program wlll geL sLuck ln a conLlnuous loop endlessly wrlLlng ouL Hello Lo Lhe ouLpuL
screen. 1he LransacLlon musL be sLopped and Lhe code amended. A mechanlsm musL be
added Lo Lhe uC loop Lo Lell lL when Lo sLop processlng Lhe code lnslde lL. Pere, Lhe 1lMLS
addlLlon ls used. Amend Lhe code as follows so LhaL Lhe sysLem knows Lhe loop ls Lo be
processed 13 Llmes. Also here a new llne has been added before Hello:


173
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS

1he uC sLaLemenL ls useful for repeaLlng a parLlcular Lask a speclflc number of Llmes. !usL
remember Lo always lnclude Lhe 1lMLS addlLlon.
now Lry some processlng wlLh the DO loop. Create a DATA variable named a, of Lype ln-
Leger, and seL Lhe value of Lhls Lo 0. 1hen, lnslde Lhe uC loop, lnclude Lhe slmple calcula-
tion a = a + 1.

1he sysLem also conLalns lLs own lnLernal counLer for how many Llmes a uC loop ls exe-
cuLed, whlch can be seen when Lhls ls execuLed ln debug mode. SeL a breakpolnL on Lhe
DO line, then execute the code, keeping an eye on the a field in the Field names section,
and also includes sy-index in one of these fields. ?ou wlll see LhaL a keeps a runnlng
counL of how many Llmes Lhe uC loop execuLes as well as Lhe sysLem varlable sy-lndex.
1he values wlll be Lhe same for boLh, golng up by 1 each Llme Lhe loop compleLes. 1he sy-
index variable will in fact update a line of code before the a varlable, as lL counLs Lhe uC
loops, and the a refers to the calculation on the next line of code:

174
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS


noLe LhaL here Lhe blue arrow cursor has moved down a llne ln Lhe second lmage, execuL-
lng Lhe nexL llne of code. lf one adds a new llne Lo Lhe W8l1L sLaLemenL ln Lhe lnlLlal code,
Lhe ouLpuL wlndow wlll appear llke Lhls:

175
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS

Nested Do Loops
uC loops can also be nesLed. lf Lhls ls done, each nesLed loop wlll have lLs own sy-lndex
creaLed and monlLored by Lhe sysLem. 8e aware LhaL when nesLlng many loops, lL ls lm-
porLanL Lo conslder how much work Lhe sysLem ls belng asked Lo do.
Add Lo Lhe W8l1L sLaLemenL from Lhe prevlous secLlon a small amounL of LexL readlng
Outer Loop cycle: before outputting the value of a. This will allow a to be monitored.
1hen, under Lhe W8l1L sLaLemenL, add a new uC sLaLemenL Lo creaLe Lhe lnner loop cycle,
as below, as well as addlng Lhe exLra daLa varlables. 1he maln loop wlll execuLe 13 Llmes,
buL wlLhln each of Lhese loops, Lhe nesLed loop wlll execuLe 10 Llmes. 1he varlable named
c will count how many times the loop has occurred. Around 150 loops will execute here.
Whlle Lhe SA sysLem wlll cerLalnly be able Lo handle Lhls lnsLanLly, you should bear ln
mlnd LhaL lf Lhls number was slgnlflcanLly larger and lncluded more lnLenslve processlng
Lhan slmple counLlng, Lhls could Lake much longer:

176
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS

SeL a breakpolnL and execuLe Lhls code ln debug mode, keeplng an eye on Lhe values of a,
b, c and sy-lndex ln Lhe llelds mode. As Lhe uC loop ls enLered, Lhe sy-lndex fleld wlll be-
gln counLlng. Pere, Lhe lnner loop has [usL occurred for Lhe 10
Lh
Llme, noLed by Lhe 10 ln
sy-index (and indeed the value of b).


177
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
1hen Lhe full loop has compleLed once, Lhe sy-index field displays 1 and the c field has
been fllled ln:

AfLer Lhe second full loop, sy-index and a will display 2, b will be 10 again (as its value is
reset to 0 at the beginning of each loop) and c will display 20 represenLlng Lhe number of
calculaLlons compleLed all LogeLher:

AfLer Lhe full 13 ouLer loops are compleLed, lL wlll look llke Lhls:

178
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS

The value of a is then added to c to give the total number of both outer and inner loops
compleLed:

When Lhe resulLs are vlewed ln Lhe ouLpuL wlndow, Lhe lasL full loop wlll look llke Lhls:

Wh||e Loops
1he nexL looplng sLaLemenL Lo be examlned ls Lhe WPlLL loop. 1hls dlffers from Lhe uC
loop ln LhaL lL checks for a predeflned condlLlon wlLhln Lhe loop before execuLlng any
code. All Lhe code beLween Lhe WPlLL and LnuWPlLL sLaLemenLs wlll be repeaLed as long
as Lhe condlLlons are meL. As soon as Lhe condlLlon ls false Lhe loop LermlnaLes. Pere,
agaln Lhe sy-lndex fleld can be monlLored Lo see how many Llmes Lhe loop has execuLed.


179
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
So here, the loop will again cause the value of a to take the form of incremental counL-
lng, and each time the loop is executed the value of a will be written. The loop will con-
Llnue as long as Lhe value of a ls noL equal Lo 13, and once lL ls, lL wlll sLop:

lf one runs Lhls ln Lhe debugger mode one wlll see LhaL on Lhe 13
Lh
loop, when Lhe value of
a is 15, the code inside the statement is skipped over and the cursor jumps straight from
WPlLL Lo LnuWPlLL.
Nested Wh||e Loops
!usL as wlLh uC loops, WPlLL loops can be nesLed. 1he process ls exacLly Lhe same for
boLh. 8elow ls an example of nesLed WPlLL loop sLaLemenLs.

1he ouLpuL for Lhls code would appear exacLly Lhe same as our nesLed uC loop example.
The values of b have also been indented slightly here for ease of reading:

180
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS


Loop 1erm|nat|on CCN1INUL
up unLll now, Lhe loop sLaLemenLs seL up have been allowed Lo use Lhe condlLlons lnslde
Lhem Lo deLermlne when Lhey are LermlnaLed. A8A also lncludes LermlnaLlon sLaLemenLs
whlch allow loops Lo be ended premaLurely. 1here are Lwo caLegorles of Lhese, Lhose
whlch apply Lo Lhe loop and Lhose whlch apply Lo Lhe enLlre processlng block ln whlch Lhe
loop occurs.
llrsL, we wlll looks aL how Lo LermlnaLe Lhe processlng of a loop. 1he flrsL sLaLemenL of
lmporLance here ls Lhe CCn1lnuL sLaLemenL. 1hls allows a loop pass Lo be LermlnaLed
uncondlLlonally. As Lhe synLax shows, Lhere are no condlLlons aLLached Lo Lhe sLaLemenL
lLself. lL Lells Lhe program Lo end processlng of Lhe sLaLemenLs ln Lhe loop aL Lhe polnL
where lL appears and go back Lo Lhe beglnnlng of Lhe loop agaln. lf lL ls lncluded wlLhln a
loop, any sLaLemenLs afLer lL wlll noL be execuLed.
lor Lhe slmple uC loop ,lnclude an ll sLaLemenL whlch lncludes CCn1lnuL lnslde lL, llke
Lhls:


181
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
WlLh Lhls code, Lhe second lLeraLlon of Lhe loop (when Lhe sy-lndex fleld, llke Lhe value of
a, wlll read 2) wlll hlL Lhe CCn1lnuL sLaLemenL and go back Lo Lhe Lop, mlsslng Lhe W8l1L
sLaLemenL. When Lhls ls ouLpuL, Lhe lncremenLal counLlng wlll go from 1 Lo 3. As wltb
mooy of tbese stotemeots, lo Jeboq moJe, tbe opetotloo coo be obsetveJ mote closely by
execotloq tbe coJe lloe by lloe.

Loop 1erm|nat|on CnLCk
1he CPLCk sLaLemenL works slmllarly Lo Lhe CCn1lnuL sLaLemenL, buL Lhls Llme allows
you Lo check speclflc condlLlons. When Lhe loglc of a CPLCk sLaLemenL ls deflned, lf Lhe
condlLlon ls noL meL, any remalnlng sLaLemenLs ln Lhe block wlll noL be execuLed and
processlng wlll reLurn Lo Lhe Lop of Lhe loop. lL can be LhoughL of as a comblnaLlon of Lhe
ll and CCn1lnuL sLaLemenLs. 1o use Lhe CPLCk sLaLemenL Lo achleve Lhe same ends as ln
Lhe example above, Lhe synLax would look llke Lhls:

1he program wlll check LhaL Lhe sy-lndex fleld does noL conLaln a value equal Lo 2, and
where lL does noL, wlll conLlnue execuLlng Lhe code. When lL does conLaln 2, Lhe condlLlon
aLLached wlll noL be Lrue and Lhe CPLCk sLaLemenL wlll cause Lhe loop Lo sLarL agaln, mlss-
lng Lhe W8l1L sLaLemenL. 1hls can be execuLed ln debug mode Lo closely observe how lL
works. 1he ouLpuL wlndow, once Lhls ls compleLe, wlll agaln appear llke Lhls:

182
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS

When you are looklng aL programs creaLed by oLher people, do noL be surprlsed Lo see Lhe
CPLCk sLaLemenL used ouLslde loops. lL ls noL only used Lo LermlnaLe a loop pass, buL can
check, and LermlnaLe oLher processlng blocks aL any polnL lf lLs parLlcular condlLlons are
noL meL. ?ou musL be aware of where Lhe CPLCk sLaLemenL ls belng used, as puLLlng lL ln
Lhe wrong place can even cause Lhe enLlre program Lo LermlnaLe. lor example here, Lhe
sLaLemenL wlll only allow processlng Lo conLlnue lf Lhe value of a ls equal Lo 1. Slnce Lhe
value of a equals 0, lL wlll always LermlnaLe Lhe program before Lhe uC loop ls reached:

Loop 1erm|nat|on LkI1
1he Lxl1 sLaLemenL can also be used Lo LermlnaLe loops. 1hls agaln allows Lhe loop Lo be
LermlnaLed lmmedlaLely wlLhouL condlLlons. unllke Lhe CCn1lnuL sLaLemenL Lhough, lL
does noL Lhen reLurn Lo Lhe beglnnlng of a loop buL, LermlnaLes Lhe loop enLlrely once lL ls
reached. 1he program wlll Lhen conLlnue process Lhe code lmmedlaLely followlng Lhe eoJ
sLaLemenL of Lhe loop.

183
PROGRAM FLOW CONTROL AND LOGICAL EXPRESSIONS
lf Lhe exlL sLaLemenL ls used wlLhln a nesLed loop, lL wlll only be LhaL nesLed loop whlch ls
LermlnaLed and Lhe sLaLemenL followlng Lhe end of Lhe nesLed loop wlll execuLe nexL ln
Lhe hlgher level loop. AddlLlonally lL can, llke Lhe CPLCk sLaLemenL, be used ouLslde loops,
Lhough agaln one musL be careful dolng Lhls.
ln Lhe nexL example, regardless of Lhe number of Llmes Lhe uC sLaLemenL ls Lold Lo be
execuLed, on Lhe Lhlrd loop when Lhe sy-lndex fleld conLalns Lhe number 3, Lhe loop wlll
be LermlnaLed and Lhe sLaLemenL afLer LnuuC wlll be execuLed, writing Filler to the
ouLpuL screen.




184
SELECTION SCREENS
Chapter 11 Se|ect|on Screens
Lvents
lor selecLlon screens Lo be bullL and used ln a program, Lhe flrsL Lhlngs Lo undersLand are
evenLs. LvenLs are processlng blocks, secLlons of code speclflc Lo Lhe selecLlon screens.
1he sLrucLure of an evenL sLarLs wlLh Lhe evenL keyword, buL does noL have an endlng
keyword. 1he end of Lhe evenL block of code ls lmpllclL, because Lhe beglnnlng of Lhe nexL
evenL wlll LermlnaLe Lhe flrsL, or Lhe code lLself wlll end.
When execuLable programs are run, Lhey are conLrolled by a predeflned process ln Lhe
runLlme envlronmenL, and a serles of processes are called one afLer anoLher. 1hese proc-
esses Lrlgger evenLs, for whlch evenL blocks can be deflned wlLhln Lhe program. When a
program sLarLs, cerLaln evenLs work ln a cerLaln order.

AL Lhe Lop level ls Lhe SA resenLaLlon Server (usually Lhe SA Cul), seen by Lhe end user,
wlLh lLs selecLlon screen and llsL ouLpuL. When a program sLarLs, from Lhe lefL, wlLh Lhe
declaraLlon of global varlables, Lhe sysLem wlll check Lo see lf any processlng blocks are
lncluded and wlll follow Lhe sequence of evenLs deLalled above Lo execuLe Lhese.

185
SELECTION SCREENS
1he lnlLlallzaLlon evenL block of code wlll only be run once, and wlll lnclude Lhlngs llke Lhe
seLLlng up of lnlLlal values for flelds ln Lhe selecLlon screen. lL wlll Lhen check wheLher a
selecLlon screen ls lncluded ln Lhe program. lf aL leasL one lnpuL fleld ls presenL, conLrol
wlll be passed Lo Lhe selecLlon screen processor.
1hls wlll dlsplay Lhe screen Lo Lhe user, and lL can Lhen be lnLeracLed wlLh. Cnce Lhls ls
complete, the at selection screen event block will process the information, and this is
where one can wrlLe code Lo check Lhe enLrles whlch have been made. lf lncorrecL values
have been enLered, Lhe code can caLch Lhese and can force Lhe selecLlon screen Lo be dls-
played agaln unLll correcL values are enLered. Lrror messages can be lncluded so LhaL Lhe
user Lhen knows where correcLlons musL be made.
The start of selection event block then takes control once Lhe selecLlon screen ls fllled
correcLly. 1hls can conLaln code for, for example, seLLlng up Lhe values of lnLernal Lables or
flelds. 1here are oLher evenL blocks, whlch are vlslble ln Lhe dlagram and Lhere could be a
number of oLhers. 1he ones dlscussed here Lhough, Lend Lo be Lhe maln ones whlch would
be used when worklng wlLh selecLlon screens Lo capLure user lnpuL, whlch wlll Lhen be
used Lo process Lhe resL of Lhe program.
Cnce all of Lhese evenL blocks have been processed, conLrol ls handed Lo Lhe llsL proces-
sor, whlch wlll ouLpuL Lhe reporL Lo Lhe screen for Lhe user Lo see. 1he llsL screen occa-
sionally can be interactive itself, and the code in the event block at line selection visible
ln Lhe dlagram Lakes responslblllLy for Lhls.
1hls chapLer wlll focus on creaLlng Lhe selecLlon screen and maklng sure Lhe user enLers
Lhe correcL values for Lhe reporL, as well as ensurlng Lhe selecLlon screen has a good lnLer-
face.
Intro to Se|ect|on Screens
A8A reporLs have 2 Lypes of screens, selecLlon screens and llsL ouLpuL screens. 1he ouL-
puL wlndow has already been used Lo produce llsL ouLpuL screens. SelecLlon screens are
very commonly used. lndeed, when enLerlng Lhe A8A edlLor, you are uslng a Lype of se-
lecLlon screen:

186
SELECTION SCREENS

We wlll focus on reproduced Lhls Lype of screen for use by our programs. 1hese wlll allow
Lhe user Lo selecL daLa whlch wlll be used as parameLers ln Lhe program. When one cre-
aLes a selecLlon screen, ln facL a dlalogue screen ls belng creaLed, buL one does noL have
Lo wrlLe Lhe dynpro code oneself. Cnly speclflc sLaLemenLs need Lo be used, and Lhe sys-
Lem wlll Lake care of Lhe screen flow loglc lLself.
LlsL screens and selecLlon screens are boLh dlalogue programs. Lvery one of Lhese has aL
leasL one dynpro whlch ls held ln whaL ls called a module pool. A dynpro reporL program
called standard selection screen is called and controlled automatically by the runtime
envlronmenL whlle Lhe program ls execuLed. 1he dynpro number lLself ls 1000. 1he user
wlll only see Lhe screen when Lhe programmer lncludes Lhe parameLers ln Lhelr program
uslng speclflc A8A sLaLemenLs. lL ls Lhese A8A sLaLemenLs whlch cause Lhe screen Lo be
generaLed and dlsplayed Lo Lhe user. 1hls means lL ls easy for Lhe programmer Lo sLarL
wrlLlng Lhelr own programs wlLhouL havlng Lo Lhlnk abouL code Lo conLrol Lhe screen.
Creat|ng Se|ect|on Screens
CreaLe a brand new program ln Lhe A8A edlLor, called Z_SC8LLnS_1.
llrsL, Lhe lnlLlallzaLlon evenL wlll be looked aL. 1hls ls Lhe flrsL Lhlng Lo be Lrlggered ln a
program. ln Lhls example, lmaglne one wanLed Lo know Lhe lasL employee number whlch
was used Lo creaLe a record ln Lhe zemployees Lable. 1he lnlLlallzaLlon evenL ls Lhe correcL
place for Lhls Lype of code, so LhaL Lhls lnformaLlon can Lhen be dlsplayed on Lhe selecLlon
screen, alerLlng Lhe user LhaL values greaLer Lhan Lhls should noL be enLered as Lhey wlll
noL reLurn resulLs.

187
SELECTION SCREENS
8egln by declarlng Lhe 1A8LLS sLaLemenL for zemployees. 1hen declare a uA1A sLaLemenL
Lo hold Lhe value of Lhe lasL employee number LhaL has been used ln Lhe Lable. 1hls can be
done wlLh a work area declared LlkL Lhe employee number fleld of Lhe Lable.
1ype INI1I1IALI2A1ICN., Lo begln Lhe evenL block, followed by a SLLLC1 sLaLemenL
where all records from zemployees are selecLed, and Lhe work area ls populaLed wlLh Lhe
employee number fleld:

1hen add a W8l1L sLaLemenL for Lhe work area Lo ouLpuL Lo Lhe screen afLer Lhe loop.
noLe LhaL as Lhe SLLLC1 sLaLemenL ls a loop and does noL conLaln a W8l1L sLaLemenL ln-
slde lL, Lhe W8l1L sLaLemenL aL Lhe end only wrlLes Lhe flnal employee number whlch
populaLes wa_employee, Lhe lasL one whlch was used.

At Se|ect|on Screen
1he at se|ect|on screen evenL ls Lhe nexL evenL block ln Lhe process. 1hls wlll always be
execuLed, lf presenL, before Lhe reporL can be processed. 1hls, Lhen, would be Lhe ldeal
place Lo check Lhe value whlch has been enLered by Lhe user as a new employee number.
1he enLry screen wlll be looked aL laLer, buL here some code wlll be wrlLLen whlch wlll al-
low some klnd of error message Lo be shown lf an lncorrecL value ls enLered, Lelllng Lhe
user Lo correcL Lhelr enLry.
1he A8AML1L8S sLaLemenL wlll be used, Lhough wlll noL be gone ln deLall unLll laLer. 1hls
sLaLemenL, allows you Lo declare a parameLer lnpuL box whlch wlll appear on Lhe screen.
1hls works slmllarly Lo a uA1A sLaLemenL - PARAMETERS: my_ee LIKE zemployees-

188
SELECTION SCREENS
employee., declaring the parameter as having the same properLles as Lhe employee
number fleld.
1hen declare Lhe A1 SLLLC1ICN-SCkLLN evenL. 1hls ls declared wlLh Lhe addlLlon CN, and
my_ee added. 1hls speclfles LhaL Lhe 'aL selecLlon screen' block refers speclflcally Lo Lhls
parameLer.
AfLer Lhls, an ll sLaLemenL can be wrlLLen, dlsplaylng an error message lf Lhe parameLer
value my_ee enLered by Lhe user ls greaLer Lhan Lhe value held ln wa_employee, Lhe lasL
employee number used:

As menLloned earller, Lhere ls no need Lo LermlnaLe evenL blocks, as Lhey are LermlnaLed
auLomaLlcally when a new one beglns. Pence, Lhe lnl1lALlZA1lCn block ends as soon as
Lhe A1 SLLLC1lCn-SC8LLn block beglns.
arameters
now, Lhe A8AML1L8S sLaLemenL wlll be looked aL ln greaLer deLall. Pavlng deflned Lhe
my_ee varlable uslng Lhls sLaLemenL, Lhe sysLem wlll now auLomaLlcally know LhaL a selec-
Llon screen ls golng Lo be generaLed. 1hls sLaLemenL ls all LhaL ls necessary Lo dlsplay a
fleld ln a selecLlon screen. lf you dlsplay [usL Lhe A8AML1L8S varlable on Lhe screen, lL
wlll appear llke Lhls:

189
SELECTION SCREENS

1he synLax for A8AML1L8S ls very slmllar Lo Lhe uA1A sLaLemenL. A name ls glven Lo Lhe
varlable, a Lype can be glven or Lhe LlkL sLaLemenL can be used Lo glve Lhe same proper-
Lles as anoLher fleld already declared. An example appears below, followed by Lhe ouLpuL
screen when Lhls ls execuLed:


1he uC8 parameLer Lakes on Lhe same aLLrlbuLes as Lhe uO8 fleld ln Lhe Lable, Lo Lhe ex-
LenL LhaL lL wlll even offer a drop-down box Lo selecL a daLe. 1he my_oombt parameLer ls
noL relaLed Lo anoLher fleld as has been declared as an lnLeger Lype parameLer. AddlLlon-
ally, noLe LhaL parameLer names are llmlLed Lo 8 characLers. Also, [usL llke Lhe uA1A
sLaLemenL, a parameLer can hold any daLa Lype, wlLh Lhe one excepLlon, floaLlng polnL
numbers. ?ou wlll noLlce also LhaL Lhe parameLers ln Lhe ouLpuL are auLomaLlcally glven
LexL labels. 1he name of Lhe parameLer from Lhe program, converLed Lo upper case ls used
by defaulL.
now, some addlLlons Lo Lhe A8AML1L8S sLaLemenL wlll be examlned.
)*+%,-.
lf you add Lhls Lo Lhe end of Lhe sLaLemenL follow by a value, Lhe value wlll appear ln Lhe
lnpuL box on Lhe ouLpuL screen glvlng a Jefoolt value LhaL Lhe user can change lf Lhey
wlsh.


190
SELECTION SCREENS

"/-0$%."12
1o make Lhe fleld mandaLory for Lhe user, Lhe addlLlon C8LlCA1C8? ls used. A small Llck-
box wlll Lhen appear ln Lhe fleld when empLy, Lo lndlcaLe LhaL a value musL be lnserLed
here. lf one Lrles Lo enLer Lhe reporL wlLh Lhls empLy, Lhe sLaLus bar wlll dlsplay a message
Lelllng Lhe user an enLry musL appear ln Lhls fleld:



7=+'E"+41 N%*%."+4'* '( 3.'5O3'P* (4%$;,
lor Lhe nexL parameLer, Lhe zemployees2 Lable wlll be used. 1hls musL be added Lo Lhe
1A8LLS sLaLemenL aL Lhe Lop of Lhe program. A new parameLer, named my_g here ls seL
up for gender:

Slnce a number of values allowed Lo be enLered for Lhe gender fleld have been suggesLed
ln Lhe Lable lLself, a drop down box wlll appear by Lhe parameLer ln Lhe ouLpuL wlndow.
Pere one can see Lhe A8A dlcLlonary worklng ln Landem wlLh Lhe program Lo ensure LhaL
values enLered lnLo parameLers correspond wlLh values whlch have been seL for Lhe fleld
ln Lhe Lable:


191
SELECTION SCREENS

lf one manually Lypes an llleglLlmaLe enLry lnLo Lhe gender box, an error message wlll noL
appear. Pere, Lhe vALuL CPLCk addlLlon ls useful, as lL wlll check any enLry agalnsL Lhe
valld value llsL whlch ls creaLed ln Lhe A8A dlcLlonary. now lf one Lrles Lo enLer an lnvalld
value for Lhe fleld, an error message ls shown ln Lhe sLaLus bar:


(Aftet tbls exomple, tbe zemployees2 toble ooJ qeoJet potometet coo be temoveJ.)
Q@-:G )7?:
8y defaulL parameLer names are converLed Lo upper case, Lo geL around Lhls one musL use
Lhe LCWL8 CASL addlLlon. CreaLe a new parameLer named my_surn and make lL LlkL
zemployees-sotoome field. Give this a default value of BLOGS and then add the LOWER
CASL addlLlon. When Lhls ls ouLpuL, 8LCCS sLlll appears ln upper case, buL lower case leL-
Lers can be added Lo Lhe end of lL. lf Lhese were enLered wlLhouL Lhe LCWL8 CASL addl-
Llon, Lhey would auLomaLlcally converL Lo upper case:



192
SELECTION SCREENS
1here are oLher addlLlons whlch can be lncluded wlLh parameLers, buL Lhese are generally
Lhe mosL common ones. 1o look aL oLhers, one can slmply selecL Lhe A8AML1L8S sLaLe-
menL, and press l1 for Lhe A8A help screen, whlch wlll explaln furLher addlLlons whlch
can be used.
Check 8oxes and kad|o 8utton arameters
Check boxes and radlo buLLons can boLh be used Lo slmpllfy Lhe Lask of daLa enLry for Lhe
end user. 1hese are boLh forms of parameLers.
A check box must always be of the character type c with a length of 1. The contents
stored in this parameter will either be an x, when it is checked, or empLy when lL ls blank.
ueflne a new parameLer called my_box1. Slnce Lhls ls Lype c, Lhe Lype does noL have Lo be
declared. The field name is then followed by as checkbox. Note that the output differs
sllghLly from oLher parameLers by seelng Lhe box on Lhe lefL and Lhe LexL Lo lLs rlghL:


8adlo buLLons are anoLher common meLhod for conLrolllng Lhe values sLored ln flelds. A
normal parameLer fleld allows any value Lo be enLered, whlle a check box llmlLs Lhe values
Lo 2. 8adlo buLLons, however, glve a group of values whlch Lhe user musL choose one op-
Llon from. Agaln, Lhese are of daLa Lype c wlLh 1 characLer.
1o creaLe a group of 3 radlo buLLons, 3 parameLer flelds musL be seL up. Lach radlo buLLon
musL be glven a name, in this example to select between colours (dont forget, parameter
names are limited to 8 characters), followed by radiobutton. These are Lhen llnked Lo-
gether by adding the word group, followed by a name for the group, here grp1. This
can be seen ln Lhe lmage below:

193
SELECTION SCREENS


Se|ect-Cpt|ons
nexL we wlll Lake a look aL SLLLC1-C1ICNS. arameLers are useful for allowlng Lhe user
Lo selecL lndlvldual values.. Powever, when mulLlple values are requlred, raLher Lhan seL-
Llng up many dlfferenL parameLers, Lhe selecL-opLlons sLaLemenL can be used.
1he flrsL Lhlng Lo conslder here ls LhaL lnLernal Lables wlll be used Lo sLore Lhe values en-
Lered by Lhe user. A deLalled dlscusslon regardlng lnLernal Lables wlll be reLurned Lo, buL
for now, only whaL ls necessary for selecL opLlons wlll be looked aL.
When a user wanLs Lo enLer mulLlple lndlvldual values, or selecL a value range, Lhese musL
be sLored ln a Lable ln memory whlch Lhe program can use. 1he lnLernal Lables Lo be used
here are, slmllarly Lo parameLers, llmlLed Lo 8 characLers and conLaln 4 flelds whlch are
defined when the statement is created. These fields are s|gn, opt|on, |ow and
h|gh. The image below demonstrates the structure of this table:

When a user makes a cholce, fllllng ln a selecLlon fleld on Lhe screen, wheLher Lhls ls a sln-
gle value or a range of values, a record ls generaLed and puL lnLo Lhls lnLernal Lable. 1hls
Lable allows Lhe user Lo enLer as many records as Lhey wlsh, whlch can Lhen be used Lo
fllLer Lhe daLa.

194
SELECTION SCREENS
The sign field has a data type of c, and a length of 1. The data stored in this field deter-
mlnes, for each record, wheLher lL ls Lo be lncluded or excluded from Lhe resulL seL LhaL
the final report selects from. The possible values to be held in this field are I and E, for
inclusive and exclusive.
The option field also has a type of c, but this time a length of 2. This field holds the se-
lecLlon operaLor, such as LC, nL, C1, L1, CL, LL (ln order, as dlscussed prevlously: equal Lo,
noL equal Lo, greaLer Lhan, less Lhan, greaLer Lhan or equal Lo, less Lhan or equal Lo), as
well as C and n. lf a wlld card sLaLemenL ls lncluded here (such as * or +), Lhe sysLem wlll
defaulL Lhls Lo C.
The low field holds the lower limit for a range of values a user can enter, while the
high field is the upper limit. The type and length of these will be the same as those for
Lhe daLabase Lable Lo whlch Lhe selecLlon crlLerla are llnked.
1he reason for uslng selecL-opLlons ls LhaL parameLers only allow for one lndlvldual spe-
clflc value Lo be used. lf for example, one ls uslng parameLers Lo selecL from Lhe uC8 fleld
ln Lhe zemployees Lable, Lhese are very speclflc and so are llkely Lo reLurn, aL besL, one
resulL, requlrlng Lhe user Lo know Lhe exacL daLe of blrLh for every employee. 1he selecL-
opLlons sLaLemenL allows one Lo seL value ranges, wlld cards and so on so LhaL any selec-
Llon wlLhln LhaL wlll reLurn resulLs.
llrsL, Lype Lhe sLaLemenL SLLLC1-C1lCnS and Lhen glve a name Lo Lhe fleld Lo be fllled,
for example my_dob. 1o declare Lhe Lype, Lhe addlLlon ICk ls used. 1hls Lhen llnk Lhls Lo
zemployees-dob:

When this is output, 2 fields will appear, plus a Multiple selection button:

A value range can be selecLed by enLerlng Lhe low value lnLo Lhe lefL fleld and Lhe hlgh
value ln Lhe rlghL fleld. 1hese Lwo flelds boLh lnclude calendar drop down menus, maklng

195
SELECTION SCREENS
entry here even easier. If the multiple selection button ls cllcked, a new pop-up box ap-
pears:

1he flelds here allow mulLlple slngle records, or value ranges Lo be searched for, as well as,
in the case of the latter two tabs, excluded from ones search results. All of the fields here
as well correspond Lo Lhe lnlLlal daLa Lype, and so wlll all feaLure calendar drop-downs.
1he buLLons along Lhe boLLom add funcLlonallLy, allowlng values Lo be copled and pasLed
lnLo Lhe rows avallable, and lndeed Lo creaLe and deleLe rows among oLher opLlons. Addl-
Llonally on Lhe selecLlon screen, lf one rlghL-clicks either field and chooses options, a list
of Lhe loglcal operaLors wlll be offered, allowlng furLher cusLomlsaLlon of Lhe value ranges
selecLed. 1hls can also be done ln Lhe mulLlple selecLlon box:


196
SELECTION SCREENS

8y fllllng ln Lhe flelds offered vla Lhe SLLLC1-C1lCnS sLaLemenL on Lhe selecLlon screen,
each of Lhe flelds of Lhe lnLernal Lable can Lhen be fllled dependlng on Lhe opLlons chosen,
Lelllng Lhe sysLem exacLly whlch values lL should (and should noL) be searchlng for.
Se|ect-Cpt|on Lxamp|e
WlLh Lhe selecL-opLlons deflned, some code wlll now be added.
CreaLe a SLLLC1 sLaLemenL, selecLlng all Lhe records from zemployees. 1hen, lnslde Lhe
loop, add an ll sLaLemenL, so LhaL lf a record from Lhe zemployees Lable maLches Lhe
value range selecLed aL Lhe selecLlon screen, Lhe full record ls wrlLLen ln Lhe ouLpuL screen.
1he ln addlLlon ensures LhaL only records whlch meeL Lhe crlLerla of my_dob, held ln Lhe
lnLernal Lable, wlll be lncluded, and where Lhey do noL, Lhe loop wlll begln agaln:

197
SELECTION SCREENS

uL a breakpolnL on Lhe SLLLC1 sLaLemenL, so LhaL you can watch the codes operation in
debug mode. When you execuLe Lhe code Lhe selecLlon screen wlll be dlsplayed. lnlLlally,
do noL enLer any values for Lhe uC8 fleld. LxecuLe Lhe program and Lhe debugger wlll ap-
pear. uouble cllck Lhe my_dob fleld ln Lhe flelJ mode. lL wlll be shown Lo be empLy and an
lcon wlll appear Lo Lhe lefL lndlcaLlng LhaL lL represenLs an lnLernal Lable. lf Lhls ls double
cllcked, Lhe conLenLs of Lhe lnLernal Lable are shown. Pere, all flelds are empLy as no val-
ues were lnserLed:


8un Lhrough Lhe code and all of Lhe records from Lhe Lable should be wrlLLen Lo Lhe ouL-
puL screen, as no speclflc selecLlon crlLerla were seL.
8un Lhe program agaln buL Lhls Llme lnclude a value ln Lhe uC8 fleld of Lhe selecLlon
screen. 1hls one corresponds Lo one of Lhe records ln Lhe Lable:


As Lhe selecL loop ls processed, evenLually a maLchlng record wlll be found. When Lhls oc-
curs, raLher Lhan sklp back Lo Lhe beglnnlng of Lhe loop, Lhe W8l1L sLaLemenL ls execuLed:

198
SELECTION SCREENS


8un Lhe program agaln buL Lhls Llme Lry uslng Lhe mulLlple selecLlon Lool Lo selecL several
values for Lhe uC8 fleld, as well as excludlng some:


199
SELECTION SCREENS

1he lnLernal Lable now conLalns several enLrles for values Lo search for and Lo exclude
from lLs search:

1he records sLored ln Lhe selecL-opLlon Lable for my_dob show Lhe dlfferenL Lypes of daLa
Lhe sysLem uses Lo fllLer records dependlng on Lhe enLrles we make ln Lhe mulLlple selec-
Llons wlndow. Cnce Lhe program ls fully execuLed Lhe ouLpuL wlndow Lhen appears llke
Lhls:


200
SELECTION SCREENS
Se|ect-Cpt|on Add|t|ons
As wlLh mosL sLaLemenLs, Lhere are a number of addlLlons whlch can be appended Lo SL-
LLC1-C1lCnS. Slmllarly Lo A8AML1L8S, one can here use C8LlCA1C8? and LCWL8
CASL, and oLhers ln exacLly Lhe same way. unlque Lo Lhls sLaLemenL, however, ls NC-
Lk1LNSICN, whlch prevenLs Lhe mulLlple selecLlon opLlon from belng offered Lo Lhe user.
1he ablllLy Lo selecL a value range sLlll exlsLs, buL exLendlng Lhls vla mulLlple selecLlons ls
prevenLed:


1ext L|ements
We have already Louched on Lhe facL LhaL when parameLers and selecL-opLlons are de-
clared Lhe flelds are labelled wlLh Lhe Lechnlcal names glven ln Lhe code. 1hese flelds sLlll
musL be referenced uslng Lhe Lechnlcal name. Powever, lL wlll be much preferable for Lhe
user Lo see some more descrlpLlve LexL. Lets see how we can do this by using Text Ele-
menLs.
Lvery A8A program ls made up of sub-ob[ecLs, llke LexL elemenLs. When one coples a
program, Lhe llsL of opLlons offered asks whlch parLs of Lhe program one wanLs Lo copy.
1he source code and LexL elemenLs here are mandaLory, Lhese are Lhe elemenLs whlch are
essenLlal Lo Lhe program.
When LexL elemenLs are creaLed, Lhey are creaLed ln text pools, whlch hold all of Lhe LexL
elemenLs of Lhe program. Lvery program creaLed ls language lndependenL, meanlng LhaL
Lhe LexL elemenLs creaLed can be qulckly and easlly LranslaLed Lo oLher languages wlLhouL
Lhe need for Lhe source code Lo be changed.
1here are Lhree klnds of LexL elemenLs whlch can be used ln a program, selecLlon LexLs,
menLloned above, are one. 1he oLher Lwo are LexL symbols and llsL headlngs. 1exL symbols
can be creaLed for a program so LhaL one does noL have Lo hard code llLerals lnLo Lhe
source code. LlsL headlngs, as Lhe name lndlcaLes, refer Lo Lhe headlngs used when creaL-
lng a reporL. 8y uslng Lhese lnsLead of hard codlng Lhem lnLo Lhe program, one can be cer-
Laln LhaL Lhey wlll be LranslaLed lf Lhe program ls Lhen used ln anoLher language. Also, lf

201
SELECTION SCREENS
Lhe headlngs need Lo be changed laLer on, one can [usL change Lhe llsL headlngs seL raLher
Lhan golng lnLo Lhe code and dolng Lhls manually.
SelecLlon LexLs allow LexL elemenLs Lo be dlsplayed on Lhe screen so LhaL Lhe user does noL
have Lo see Lhe Lechnlcal names for flelds and Lhe llke. 1here are several ways Lo navlgaLe
Lo Lhe screen where Lhese can be creaLed and changed. AL Lhe lnlLlal A8A edlLor screen,
Lhere ls ln facL an opLlon for creaLlng LexL elemenLs:

AlLernaLlvely, lf one ls already lnslde Lhe program, Lhls can be reached through the Goto
menu, Text elements and select Selection texts:

lf Lhls ls cllcked, a screen wlll appear where selecLlon LexLs can be creaLed for all of Lhe
Lechnlcal fleld names whlch appear aL Lhe selecLlon screen:

202
SELECTION SCREENS

1he Lhlrd column here is for Dictionary reference, which recognises that some of these
flelds are llnked Lo flelds already creaLed ln Lhe A8A dlcLlonary. lf one checks Lhls box and
cllcks save, Lhe fleld names from Lhe lnlLlal flelds and Lhe A8A dlcLlonary auLomaLlcally
appear. ?ou can of course choose noL Lo use Lhe LexL here and overwrlLe lL yourself.

lor Lhe oLhers flelds, Lhe LexL musL be manually Lyped ln, up Lo a 30 characLer llmlL:

203
SELECTION SCREENS

1exL LlemenLs musL Lhen be acLlvaLed and once Lhls ls done, Lhey are auLomaLlcally saved
and wlll appear on Lhe selecLlon screen ln place of Lhe Lechnlcal names. 1he ouLpuL screen
wlll now look llke Lhls:

Var|ants
When a user fllls ln a selecLlon screen, Lhere ls Lhe opLlon of savlng Lhe enLry. 1hls ls called
a varlanL:


204
SELECTION SCREENS
Cnce Lhls ls done, a new screen appears. As long as a name and descrlpLlon are glven, Lhls
can be saved for use laLer on:

Cnce saved a new buLLon appears on Lhe selecLlon screen nexL Lo Lhe execuLe buLLon,
named Get var|ant allowing the varlanL enLry Lo be recalled.


205
SELECTION SCREENS
A box appears allowlng a varlanL Lo be selecLed and when selecLed, Lhe flelds are popu-
laLed wlLh Lhe daLa from LhaL parLlcular enLry. AnoLher way Lo creaLe varlanLs ls vla Lhe
lnlLlal A8A edlLor screen.
Choose the Variants option. A new varlanL name can be enLered and Lhen Lhe varlanL can
be creaLed:

Once Create is clicked, Lhe selecLlon screen appears and you can proceeds as normal,
savlng Lhe aLLrlbuLes of Lhe new varlanL once Lhe enLrles have been made. ?ou can Lhen
choose beLween dlsplaylng and changing the values and attributes of the variant (Values
will show the selection screen, Attributes the screen below. These two views can be
swlLched beLween):

206
SELECTION SCREENS

The Cn|y for background process|ng check box allows you Lo Lell Lhe sysLem Lo only use
Lhls varlanL as parL of a background [ob. Pere, a [ob can be scheduled Lo run overnlghL so
Lhe program does noL ln facL have Lo be monlLored.
The rotect var|ant option prevents other users from being able to select this variant and
uslng lL on Lhelr reporLs.
Cn|y d|sp|ay |n cata|og effecLlvely makes Lhe varlanL lnacLlve, lL wlll exlsL, buL when a
user vlews Lhe drop-down menu of exlsLlng varlanLs, lL wlll noL appear.

207
SELECTION SCREENS
1he Field attributes secLlon allows Lhe llsL of posslble aLLrlbuLes dlsplayed Lo be asslgned
Lo Lhe flelds ln Lhe boLLom secLlon of Lhe screen, vla Lhe check boxes. LxperlmenL wlLh Lhe
dlfferenL opLlons avallable and see Lhe resulLs. lor example, you can see that the Re-
quired field check box for Employee number has been filled here, as this was labelled
C8LlCA1C8? ln Lhe program. 1he s and one S whlch appear by Lhe flelds slmply refer Lo
wheLher each fleld ls a parameLer or selecL-opLlon.
Choose rotect f|e|d for the Date of Birth field, lL wlll no longer be posslble Lo change Lhe
value seL unLll such Llme as Lhls box ls un-checked. ln Lhe lmage below you can see Lhls
fleld has been greyed ouL and cannoL be changed:


When large selecLlon screens are creaLed, users wlll regularly creaLe varlanLs so LhaL, lf
necessary, Lhe same daLa can be used repeaLedly when runnlng reporLs, savlng Lhe Llme lL
would Lake Lo flll ln Lhe lnformaLlon agaln and agaln. unnecessary flelds, or flelds whlch
wlll always hold Lhe same value can be proLecLed so LhaL fllllng ln Lhe screen becomes a
much slmpler and less Llme consumlng Lask for Lhe end user.
At the ABAP editors initial screen, there is in fact a button which allows the program to
run wlLh a varlanL, directing one straight to the selection screen with the variants values
already presenL:

208
SELECTION SCREENS

1he A8A edlLor wlll llkely noL be accessed by Lhe user buL reporLs can be accessed vla Lhe
System menu, Services, and then Reporting. Selecting this presents Lhe ABAP: Execute
Program screen, which could be described as a cut-down verslon of Lhe A8A edlLor
screen, mlnus Lhe edlLlng funcLlonallLy. lrom here Lhe program can agaln elLher be exe-
cuLed dlrecLly or execuLed uslng a varlanL whlch can be selecLed from Lhe menu whlch ls
offered:


209
SELECTION SCREENS

lf Lhe program ls execuLed dlrecLly and Lhe user Lhen wanLs Lo use a varlanL, Lhls can also
be done via the Goto menu:

1ext Symbo|s
We wlll now Lake a look aL oLher LexL ob[ecLs sLarLlng wlLh 1exL Symbols. 1hese are used Lo
replace llLerals ln a program. lor example, when Lhe W8l1L sLaLemenL ls used, one can
choose Lo use LexL symbols Lo reuse LexL whlch has already been seL up. 1hls also glves Lhe
added funcLlonallLy of belng able Lo use LranslaLed LexL wlLhln Lhe program. 1hls allows
hard coded llLerals Lo be avolded and LexL symbols used ln Lhelr place.
1exL symbols effecLlvely funcLlon as placeholders for LexL. So, raLher Lhan having WkI1L:
/ Surname. multiple times in the code, you can avold uslng Lhe llLeral by using WkI1L:
] text-001. which here would refer to a text symbol which can be set up wlLh Lhe LexL
Surname itself.


210
SELECTION SCREENS
Text symbols are always declared with the word text followed by a dash and a three digit
number. 1hls means LhaL up Lo 1000 LexL symbols can LheoreLlcally be used ln a program,
of whlch each one can be LranslaLed lnLo as many languages as one wlshes. Cne Lhlng Lo
remember here ls LhaL LexL symbols are always llmlLed Lo 132 characLers ln lengLh.
1o creaLe a LexL symbol, you can use Lhe Goto menu, select Text elements and then
Text symbols, or you can use forward navlgaLlon. !usL double-click text-001. A window
wlll Lhen appear asklng lf you wanL to create this object, select Yes. The Text Elements
wlndow wlll Lhen appear and LexL can be enLered for Lhe new LexL symbol.

Here, include the word Surname. The column on the left references the LexL symbol ld
001. 1he two columns on the right note the texts length and maximum length:

1hls can Lhen be acLlvaLed and you can sLep back Lo Lhe program. lf Lhe code ls Lhen exe-
cuted, the word Surname will be output twice, the first from the WRITE statement with
Lhe llLeral, Lhe second from Lhe W8l1L sLaLemenL wlLh Lhe newly creaLed LexL symbol:

lL ls advlsable Lo use LexL symbols raLher Lhan llLerals as ofLen as posslble as lL ls much eas-
ler Lo change Lhe LexL symbol once Lhan Lo slfL Lhrough Lhe code Lo flnd and change many
llLeral values. AddlLlonally, uslng LexL symbols glves Lhe added beneflL of LranslaLablllLy.

211
SELECTION SCREENS
1ext Messages
1he nexL Lhlng Lo be examlned here ls messages. When one wanLs Lo glve feedback Lo Lhe
user, llLerals can be used, buL as sLaLed above, Lhls ls Lo be avolded as far as posslble. 1o
use messages Lhen, Lhese musL flrsL be sLored ln a message class, whlch ls ln Lurn sLored ln
a daLabase Lable called 1100.
At the ABAP dictionarys initial screen, type T100 into the database table field and choose
Display:

lf one vlews Lhe conLenLs of Lhls, one can see Lhe four flelds dlsplayed. Cne for language
(here u, referrlng Lo Cerman), one for Lhe appllcaLlon area, one for Lhe message code and
one for Lhe message LexL:

1o creaLe new messages Lo be used ln your program, forward navlgaLlon can be used, or
Lhe LransacLlon SL91 can be dlrecLly accessed:

212
SELECTION SCREENS

llrsL, creaLe a message class. 1hese musL agaln follow Lhe cusLomer name space rules,
here beglnnlng wlLh Lhe leLLer Z. Lets call this 2MLS1 and choose CreaLe. Messages are
dlsLlncL from LexL elemenLs as Lhey are noL Lhemselves parL of Lhe program creaLed. 1hey
exlsL lndependenLly. 1hey are lnsLead sLored ln Lhe 1100 Lable. 1hls means LhaL messages
can be reused across many programs.
1he aLLrlbuLes musL be fllled ln, creaLlng a shorL LexL. 1hen, ln Lhe messages Lab, Lhe LexL
Lo be used can be creaLed:


213
SELECTION SCREENS
8emember LhaL, when Lhe A1 SLLLC1lCn-SC8LLn evenL was creaLed, an ll sLaLemenL was
used so LhaL lf Lhe employee number glven by Lhe user was greaLer Lhan Lhe lasL employee
number used ln Lhe Lable, a message would be dlsplayed. Pere, Lhe LexL for LhaL message
can be creaLed:

Cnce Lhe LexL ls enLered, lL can be saved.
1here are a number of message Lypes whlch can be used, as Lhls Lable explalns:
A
Termination
Message
The message appears in a dialog box, and the program terminates.
When the user has confirmed the message, control returns to the
next-highest area menu.
E
Error
Message
Depending on the program context, an error dialog appears or the
program terminates.
I
Information The message appears in a dialog box. Once the user has confirmed
the message, the program continues immediately after the !"##$%"
statement.
S
Status
Message
The program continues normally after the !"##$%" statement, and
the message is displayed in the status bar of the next screen.
W
Warning Depending on the program context, an error dialog appears or the
program terminates.
X
Exit No message is displayed, and the program terminates with a short
dump. Program terminations with a short dump normally only occur
when a runtime error occurs. Message type X allows you to force a
program termination. The short dump contains the message ID.

lor Lhls example, Lype L, an error message, wlll be used. uependlng on where Lhls Lype of
message ls used, lL wlll have a dlfferenL effecL. Pere, lL wlll be used aL Lhe aL selecLlon-
screen and the programs execution will pause, Lhe error message wlll be dlsplayed and

214
SELECTION SCREENS
Lhe user wlll be allowed Lo amend Lhelr enLry. When Lhe new enLry appears, Lhe evenL wlll
begln agaln. lf an error message ls used elsewhere, ouLslde of an evenL ln Lhe maln body
of Lhe code, when Lhls ls Lrlggered Lhe program wlll LermlnaLe enLlrely.
To include the newly created message in the code, then, the syntax is MESSAGE
e000(ZMES1). The e refers to the error message type, the 000 to the number assigned
Lo Lhe message in the message class, and then ZMES1 to the class itself:

1he lnl1lALlZA1lCn evenL wlll populaLe wa_employee wlLh Lhe lasL, hlghesL employee
number used ln Lhe Lable, and Lhen, aL Lhe A1 SLLLC1lCn-SC8LLn evenL, Lhe value en-
Lered can be checked agalnsL Lhls. lf lL ls hlgher, Lhe error message wlll dlsplay. ?ou can
monlLor Lhese values ln debug mode Lo waLch Lhe code ln acLlon. Pere, Lhe number ls
hlgher so, once execuLed, Lhe selecLlon screen wlll be reLurned Lo and Lhe message dls-
played ln Lhe sLaLus bar:




215
SELECTION SCREENS
Cnce a leglLlmaLe, lower value ls enLered, Lhe program wlll conLlnue as normal wlLhouL
Lrlggerlng Lhe error message.
An addlLlon whlch can be used wlLh Lhe MLSSACLS sLaLemenL ls WI1n. Pere, a fleld can be
speclfled, for example Lo dlsplay Lhe lnvalld value whlch was enLered by Lhe user ln Lhe
message lLself. 1he Wl1P addlLlon allows up Lo 4 parameLers Lo be lncluded ln Lhe error
message. 1o do Lhls, one musL ensure Lhe error message ls compaLlble.
CreaLe anoLher message ln Lhe message class screen, Lhls Llme wlLh an & characLer. When
used ln con[uncLlon wlLh Lhe Wl1P addlLlon, Lhls characLer wlll Lhen be replaced by Lhe
value ln Lhe speclfled parameLer:

Save the new message, add WITH my_ee to the MLSSACLS sLaLemenL and change Lhe
number of Lhe message referenced ln Lhe code Lo Lhe new 001 message:


As messages creaLed are noL speclflc Lo Lhe program lLself, buL can be used across Lhe en-
Llre sysLem, lL ls usually worLh checklng lf an approprlaLe message for Lhe Lask you are per-
formlng already exlsLs, raLher Lhan conLlnually seLLlng up new messages.

216
SELECTION SCREENS
Sk|p L|nes and Under||ne
now, a look wlll be Laken aL formaLLlng selecLlon screens. 1hls wlll allow Lhe screen Lo be a
loL easler Lo navlgaLe and so on for Lhe end user. arameLers and selecL-opLlons have al-
ready been seL up, buL as yeL no layouL opLlons have been lmplemenLed allowlng Lhe sys-
Lem Lo place Lhe ob[ecLs by lLself. 1hls ls generally noL sufflclenL. lor example, when a
group of radlo buLLons appear, Lhey should be dlsLlncL and poslLloned ln a group on Lhelr
own, clearly separaLed from oLher parLs of Lhe screen.
1he SLLLC1lCn-SC8LLn sLaLemenL, and lLs assoclaLed addlLlons allow Lhls klnd of formaL-
Llng Lo be done. Cne musL locaLe where ln Lhe code Lhe screen layouL beglns Lo be re-
ferred Lo. Pere, Lhls ls aL Lhe Lop when A8AML1L8S ls declared. ln Lhe llne above Lhls,
Lype Lhe sLaLemenL SLLLC1lCn-SC8LLn. AddlLlons musL Lhen be added.
llrsL, Lo add blank llnes you can use Lhe Skl addlLlon, followed by Lhe number of llnes Lo
be sklpped. lf you only wanL Lo sklp 1 llne Lhen Lhe number can be omlLLed as Lhls ls Lhe
defaulL values. 1hls llne of code musL Lhen be moved Lo Lhe place where you wanL Lhe llne
Lo be sklpped. lace lL under Lhe my_ee parameLer. noLe LhaL Lhe A8AML1L8S chaln ls
now broken, so anoLher A8AML1L8S sLaLemenL musL be added:


217
SELECTION SCREENS

1o add a horlzonLal llne, Lhe uLlnL addlLlon can be used:


1here are furLher addlLlons whlch can be added Lo uLlnL Lo deLermlne lLs poslLlon and
lengLh. 1he code ln Lhe lmage below seLs Lhe poslLlon of Lhe llne Lo Lhe 40Lh characLer
from Lhe lefL of Lhe screen, and lLs lengLh ls seL Lo 8 characLers:

218
SELECTION SCREENS


Comments
CommenLs allow LexL Lo be placed on screen wlLhouL creaLlng new flelds. 1he SLLLC1lCn-
SC8LLn sLaLemenL ls agaln used, wlLh Lhe addlLlon CCMMLn1. Slmllar addlLlons Lo uLlnL
can be used Lo seL Lhe poslLlon and lengLh of Lhe commenL. 1hls ls Lhen followed by elLher
a LexL elemenL whlch has already been seL, or a fleld name. 1hls ls noL declared wlLh a
uA1A sLaLemenL, buL ls deLermlned by Lhe lengLh whlch Lhe commenL ls seL. Pere, Lhe LexL
elemenL text001 is used, which reads Surname, and this will appear 40 characLers from
Lhe lefL:


lf you do noL wanL Lo use a LexL elemenL, a new fleld can be creaLed here. Copy Lhe lnlLlal
SLLLC1lCn-SCREEN statement and add the new variable comm1. This variable is cur-
renLly empLy and musL be glven a value. 1hls musL be added ln Lhe lnl1lALlZA1lCn parL of
the code, so that it is initialised when the program starts. Here, write comm1 = Hello
SAP.:

219
SELECTION SCREENS




Iormat a L|ne and os|t|on
now, lets take a look at how Lo formaL a slngle llne on Lhe selecLlon screen. When lndl-
vldual llnes for Lhe selecLlon screen are deflned, Lhe sLarL and end of Lhese llnes musL be
declared, and ln beLween Lhese llnes Lhe parameLers and selecL-opLlons appear.
Above Lhe formaLLlng code already creaLed, type SLLLC1ICN-SCkLLN 8LGIN CI LINL.,
and then underneath SLLLC1ICN-SCkLLN LND CI LINL. Anything appearing between
Lhese sLaLemenLs wlll now all appear on Lhe same llne. 1hen, alLer Lhe formaLLlng code
sllghLly so LhaL Lhls wlll work, removlng Lhe uLlnL sLaLemenL, movlng Lhe LexL001 com-
menL (which reads Surname) to the first space on the line, and the comm1 comment
(reading Hello SAP) to the 20
Lh
space and change Lhe lengLh of Lhls Lo 10 characLers. Also,
remove Lhe /n whlch puL Lhese on a new llne. llnally, add a new A8AML1L8S sLaLemenL
beneath the second comment in the code, named ABC, with a length of 5:


220
SELECTION SCREENS

?ou can now see LhaL Lhe code beLween Lhe 8LCln and Lnu Cl LlnL sLaLemenLs now all
appears on one llne, lLs formaLLlng deLermlned by Lhe poslLlons and lengLhs asslgned Lo
each sLaLemenL. noLe LhaL here Lhe parameLer was noL auLomaLlcally glven a descrlpLlon
(Lhe Lechnlcal name of Lhe fleld) as oLhers have been. 1hls ls because speclflc commenLs
have been used on Lhe same llne. When you are formaLLlng a llne ln Lhls way, he com-
menLs can be used Lo acL as descrlpLlons for Lhe fleld.
AnoLher addlLlon, whlch can only be used wlLhln 8LCln and Lnu Cl LlnL, ls CSl1lCn.
1hls ls noL commonly used because Lhls can effecLlvely be seL by alLernaLe meLhods, as
above. Powever, lf one deslres, Lhe poslLlon of Lhe nexL elemenL can be seL separaLely.
Pere, Lhe parameLer wlll appear 30 spaces lnLo Lhe new llne:


Note tbot bete tbe tecbolcol oome stlll Joes oot oppeot, os tbe potometet ls stlll betweeo
tbe 8ClN ooJ Nu Ol llN stotemeots.
1here ls also a furLher opLlon whlch can be lncluded wlLh Lhe CSl1lCn addlLlon. 1he de-
faulL poslLlons of parameLers and selecL-options on the screen are referred to as pos|t|on
|ow for the left hand side, where standard parameters and the low end of value ranges
appear, and pos|t|on h|gh for the right hand side, where the upper end of a value range
would appear. 1hese defaulL poslLlons can be used wlLh Lhe CSl1lCn addlLlon. 1o place a
parameter in the position high position, you would lnclude pos_h|gh aL Lhe end of Lhe
sLaLemenL:

221
SELECTION SCREENS


?ou can see that the parameter now matches up with the position high default value
when compared Lo Lhe upper end of Lhe uaLe of 8lrLh value range. unsurprlslngly, Lhls ls
replaced wlLh pos_|ow to make it correspond to the default position low column.
L|ement 8|ocks
When you are creaLlng selecLlon screens, lL ls common pracLlce Lo group cerLaln flelds Lo-
geLher. ?ou can make use of Lhese elemenL blocks, whlch wlll draw frames around Lhe cer-
Laln groups of flelds whlch are deslgnaLed. 1hese frames can Lhen be glven frame labels.
8ear ln mlnd when looklng aL Lhese lL ls posslble Lo nesL elemenL blocks wlLhln oLher ele-
menL blocks, allowlng lndlvldual secLlons of Lhe selecLlon screen Lo be subdlvlded.
1he synLax for Lhls ls very slmllar Lo LhaL of 8LCln and Lnu Cl LlnL. Above where Lhese
statements were tested before, add the code SLLLC1ICN-SCkLLN 8LGIN CI 8LCCk, fol-
lowed by a name for this block, here myblock1. To then add a frame to the block, Lhe
WI1n IkAML addlLlon ls Lhen used. 1he frame can Lhen be glven a LlLle uslng, llke com-
menLs, elLher a LexL elemenL or separaLely deflned varlable. 1hls ls done afLer Lhe Wl1P
l8AML addlLlon, addlng 1I1LL and then, here text-001, which as before conLaln Lhe val-
ues Surname.

222
SELECTION SCREENS
Pavlng done all of Lhls, you musL remember Lo Lhen use Lnu Cl 8LCCk followed by Lhe
block name so LhaL Lhe sysLem knows whlch block ls endlng:


LlemenL blocks, when used correcLly, add conLexL Lo Lhe selecLlon screen, maklng lL easler
for Lhe end user Lo undersLand Lhe screen enLry requlremenLs.


223
INTERNAL TABLES
Chapter 12 Interna| 1ab|es

Introduct|on
ueallng wlLh lnLernal Lables ls one of Lhe mosL lmporLanL parLs of worklng wlLh A8A. ln-
Lernal Lables have been hlnLed aL brlefly before, buL noL examlned ln any greaL depLh. 1hls
chapLer wlll do preclsely LhaL. lf one ls worklng ln A8A ln any way aL all, lL ls cruclal Lo un-
dersLand lnLernal Lables, as almosL every program wlll use Lhem. ?ou have Lo undersLand
boLh Lhe old meLhod of uslng header llnes, and Lhe new meLhod uslng separaLe work ar-
eas. SA has exlsLed a long Llme, and whlle pracLlces change, one wlll sLlll ofLen flnd old
meLhods belng used. When one ls creaLlng new programs, Lhough, Lhe newer meLhod ls
always Lo be used.
lnLernal Lables only ever exlsL when a program ls runnlng, so when Lhe code ls wrlLLen, Lhe
lnLernal Lable musL be sLrucLured ln such a way LhaL Lhe program can make use of lL. ?ou
wlll flnd LhaL lnLernal Lables operaLe ln Lhe same way as sLrucLures. 1he maln dlfference
belng LhaL SLrucLures only have one llne, whlle an lnLernal Lable can have as many as re-
qulred.
lnLernal Lables are used for many purposes ln A8A. 1hey can be used Lo hold resulLs of
calculaLlons Lo Lhen use laLer ln Lhe program, hold records and daLa so LhaL Lhls can be
accessed qulckly raLher Lhan havlng Lo access Lhls daLa from daLabase Lables, and a greaL
number of oLher Lhlngs. 1hey are hugely versaLlle, as Lhey can be deflned uslng any num-
ber of oLher deflned sLrucLures, allowlng, for example, many Lables Lo be grouped Lo-
geLher and Lhen placed lnLo one lnLernal Lable.
1he baslc form of Lhese conslsLs of a Lable body, whlch ls all of Lhe records wlLhln Lhe La-
ble, and a header record ln Lhe case of Lhe older-sLyle lnLernal Lable. ln Lhe case of Lhe
newer sLyle of lnLernal Lable, Lhe header record ls absenL and replaced by a separaLe work
area. 1he header llne or work area ls used when you read a record from Lhe lnLernal Lable,
provldlng a place for Lhls current record Lo be placed whlch can Lhen be accessed dl-
recLly. 1he header llne or work area ls also used and populaLed lf you need Lo add a new
record Lo Lhe Lable, whlch ls Lhen Lransferred from Lhe sLrucLure Lo Lhe Lable body lLself.

224
INTERNAL TABLES
revlously, Lhe 1A8LLS sLaLemenL has been used Lo lnclude a Lable whlch has been creaLed
ln Lhe A8A dlcLlonary ln a program. lnLernal Lables, on Lhe oLher hand, have Lo be de-
clared Lhemselves. When Lhls ls done, you musL also declare wheLher a header record or
separaLe work area wlll be used.
When creaLlng new programs wlLh lnLernal Lables lL ls besL pracLlce Lo use separaLe work
areas. uslng a header record has a number of resLrlcLlons, for example, you are noL able Lo
creaLe mulLl-dlmenslonal Lables. We wlll noL be cover mulLl-dlmenslonal Lables aL lengLh
here, buL lf you plan Lo go furLher wlLh A8A, Lhey wlll become lmporLanL.
1here are some resLrlcLlons on Lhe records whlch can be held ln lnLernal Lables. 1he archl-
LecLure of an SA sysLem llmlLs Lhe slze of lnLernal Lables Lo around 2C8. lL ls also lmpor-
tant to bear in mind how powerful ones SAP system is (Lhe hardware and operaLlng sys-
Lem). lL ls generally besL pracLlce Lo keep lnLernal Lables as small as posslble, so as Lo avold
Lhe sysLem runnlng slowly as lL sLruggles Lo process enormous amounLs of daLa.
1ypes of Interna| 1ab|es
now Lhe dlfference beLween Lhe older and newer sLyle lnLernal Lables has been men-
Lloned, from here on, assume LhaL lL ls Lhe newer klnd whlch ls belng dlscussed - oo lotet-
ool toble wltb o wotk oteo.
An lnLernal Lable can be made up of a number of flelds, correspondlng Lo Lhe columns of a
Lable, [usL as ln Lhe A8A dlcLlonary a Lable was creaLed uslng a number of flelds. key
flelds can also be used wlLh ln lnLernal Lables and when creaLlng Lhese lnLernal Lables offer
sllghLly more flexlblllLy. ln Lhe A8A dlcLlonary, uslng key flelds ls lmperaLlve Lo unlquely
ldenLlfy each record. WlLh lnLernal Lables, one can speclfy a non-unlque key, allowlng any
number of non-unlque records Lo be sLored, allowlng dupllcaLe records Lo be sLored lf re-
qulred.
ulfferenL Lypes of lnLernal Lables can also be creaLed, so LhaL daLa can be accessed ln Lhe
mosL efflclenL manner posslble.
?+"*;".; !"#$%,
llrsL, Lhere are stooJotJ tobles. 1hese glve Lhe opLlon of accesslng records uslng a Lable
key or an lndex. When Lhese Lables are Lhen accessed uslng a key, Lhe larger Lhe lnLernal
Lable ls, Lhe longer lL wlll Lake Lo access Lhe records. 1hls ls why Lhe lndex opLlon ls also
avallable. SLandard Lables do noL glve Lhe opLlon of deflnlng a unlque key, meanlng Lhe

225
INTERNAL TABLES
posslblllLy of havlng ldenLlcal llnes repeaLed many Llmes LhroughouL Lhe Lable. AddlLlon-
ally, Lhough, Lhls means LhaL sLandard Lables can be fllled wlLh daLa very qulckly, as Lhe
sysLem does noL have Lo spend Llme checklng for dupllcaLe records. SLandard Lables are
Lhe mosL commonly used Lype of lnLernal Lable ln SA sysLems.
?'.+%; !"#$%,
AnoLher Lype of lnLernal Lable ls Lhe sorLed Lable. WlLh Lhese, a unlque key can be deflned,
forclng all records ln Lhe Lable Lo be unlque, removlng dupllcaLlon. 1hese can agaln be ac-
cessed vla Lhe key or lndex. As Lhe records are all unlque, uslng Lhe Lable key Lo flnd re-
cords ls much qulcker wlLh sorLed Lables, Lhough sLlll noL Lhe fasLesL ln all slLuaLlons. lL ls
ofLen preferable Lo use a sorLed Lable over a sLandard Lable, glven Lhe fasLer access speeds
and Lhe facL LhaL Lhls klnd of Lable wlll sorL records lnLo a speclflc sequence. 1hls glves one
a subsLanLlal performance lncrease when accesslng daLa.
H",2%; !"#$%
1he flnal Lype of lnLernal Lable Lo be dlscussed here ls a hashed Lable. WlLh Lhese, an lndex
ls noL used Lo access Lhe daLa, only a unlque key. When lL comes Lo speed, Lhese are llkely
Lo be Lhe preferred opLlon. 1hese are recommended parLlcularly when one ls llkely Lo be
creaLlng Lables whlch wlll be very large, as accesslng daLa ln large Lable ls llkely Lo be falrly
laboured when uslng sLandard or sorLed Lables. 1hese Lables use a speclal hash algorlLhm
Lo ensure Lhe fasL response Llmes Lo readlng records are malnLalned no maLLer how many
records are held.
uesplLe Lhe speed of hashed Lables, you wlll however flnd LhaL sLandard and sorLed Lables
are generally used slgnlflcanLly more ln SA programs. 8ecause of Lhls, Lhe ma[orlLy of fo-
cus here wlll be puL on Lhese.
Interna| 1ab|es - 8est ract|ce Gu|de||nes
As SA has been around a long Llme, many programs exlsL LhaL conform Lo uslng Lhe older
sLyle lnLernal Lable. ?ou musL be aware of Lhls wlLhouL falllng lnLo bad hablLs and uslng
Lhls sLyle. lL ls now consldered besL pracLlce Lo always use Lhe newer sLyle of lnLernal Lable
ln SA, ensurlng LhaL Lhe programs creaLed wlll be conLlnue Lo be usable ln Lhe fuLure,
once Lhe older sLyle has been compleLely abandoned. 8oLh old and new sLyles wlll be dls-
cussed here, so LhaL you galn a degree of famlllarlLy wlLh Lhe old sLyle whlch perslsLs ln
places, buL when creaLlng programs of your own, Lhe new sLyle should always be used.

226
INTERNAL TABLES
Creat|ng Standard and Sorted 1ab|es
CreaLe a new program ln Lhe A8A edlLor called Z_LMLC?LLS_LlS1_03 Lo use for Lhe
creaLlon of lnLernal Lables. 1o begln Lo declare an lnLernal Lable, Lhe uA1A sLaLemenL ls
used. 1he program musL be Lold where Lhe Lable beglns and ends, so use Lhe 8LCln Cl
sLaLemenL, Lhen declare the table name, here |tab01 (itab is a commonly used shorthand
when creaLlng Lemporary Lables ln SA). AfLer Lhls, Lhe CCCUkS addlLlon ls used, followed
by a number, here 0. CCCu8S Lells SA LhaL an lnLernal Lable ls belng creaLed, and Lhe 0
here sLaLes LhaL lL wlll noL conLaln any records lnlLlally. lL wlll Lhen expand as lL ls fllled
wlLh daLa:

On a new line, create a field called surname, which is declared as LIkL zemp|oyees-
surname. CreaLe anoLher fleld called dob, LIkL zemp|oyees-dob. lL may be useful lnlLlally
Lo glve Lhe fleld names ln lnLernal Lables Lhe same names as oLher flelds whlch have been
creaLed elsewhere. 8y dolng Lhls, laLer on Lhe MCVLCCkkLSCNDING sLaLemenL can be
used Lo move daLa from one Lable Lo anoLher. llnally, declare Lhe end of Lhe lnLernal Lable
is declared with LND CI |tab01.

1he sLrucLure of Lhe lnLernal Lable ls now creaLed, and code can be wrlLLen Lo flll lL wlLh
records. uslng Lhe CCCu8S sLaLemenL above, Lhls auLomaLlcally Lells Lhe sysLem LhaL an
olJ style lnLernal Lable wlLh a header record ls belng used.
As menLloned earller, lL ls advlsable Lo always creaLe Lhe new sLyle of lnLernal Lable, allow-
lng A8A ob[ecLs and so on Lo be used. WlLh Lhe new sLyle of ob[ecL-orlenLed program-
mlng lL ls encouraged Lo keep all Lhe ob[ecLs of your code separaLe, so LhaL Lhey can be
reused ln oLher programs and so on. 1o creaLe Lhe new sLyle of lnLernal Lable, Lhe code ls
sllghLly dlfferenL, separaLlng ouL Lhe lndlvldual daLa ob[ecLs, llke bulldlng blocks, whlch can
Lhen be puL LogeLher Lo creaLe new daLa ob[ecLs laLer and so on. 1he manner ln whlch Lhls
ls done may seem slgnlflcanLly more laborlous, buL when you are worklng wlLh larger,
more compllcaLed programs, Lhe beneflLs wlll be clear.

227
INTERNAL TABLES
Create an Interna| 1ab|e w|th Separate Work Area
lnsLead of uslng Lhe uA1A sLaLemenL, Lhls Llme sLarL by deflnlng a ||ne type, uslng Lhe
1LS sLaLemenL. lollowlng Lhls, Lhe 8LGIN CI sLaLemenL ls used, followed by a name,
here ||ne01_typ. Below this, the surname and dob fields from above can be creaLed as
before. 1hen Lhe LND CI sLaLemenL ls used Lo end Lhe llne Lype deflnlLlon:

8aLher Lhan deflnlng Lhe enLlre Lable sLrucLure aL once, here only Lhe sLrucLure of one llne
ls deflned. 1he Lable lLself has noL yeL been deflned. As a resulL of Lhls, Lhe CCCu8S sLaLe-
menL has noL been used.
Cnce Lhe llne has been deflned, nexL you deflne Lhe tab|e type. Agaln, use Lhe 1?LS
statement, followed this time by the table, here |tab02_typ (oote tbe 4(75 oJJltloo to
tbe eoJ os lt ls ooly tbe toble type beloq JefloeJ, oot tbe toble ltself). lollow Lhls wlLh
1L S1ANDAkD 1A8LL CI ||ne01_typ., Lelllng Lhe sysLem lL wlll be a sLandard Lable
conLalnlng Lhe sLrucLure of Lhe llne-Lype deflned above:

ln place of Lhe CCCu8S clause used for Lhe old sLyle of Lable, you can opLlonally add Lo Lhe
end of the line INI1IAL SI2L (n) where (n) would be a number corresponding to the size
you lnlLlally wanL Lhe Lable Lo be. Powever, Lhls ls compleLely opLlonal and ls noL fre-
quenLly used.
lf you wanL Lo creaLe a sotteJ toble, the STANDARD in the above line is replaced with
SORTED. ?ou Lhen have to specify the table key, with the addition WI1n UNIUL kL
(f|e|d name) where (field name) would be one of the flelds seL up ln Lhe llne Lype deflnl-
tion, in this example surname. If you wanL more Lhan one key fleld, Lhese are slmply Lhen
separaLed by commas:


228
INTERNAL TABLES
nexL, Lhe Lable lLself musL be declared. As Lhe Lable Lype deflned was based on Lhe llne
Lype prevlously deflned, Lhe Lable lLself wlll be based on Lhe Lable Lype. Pere, Lhe uA1A
statement returns, followed by the name of the table, |tab02, and the 1L of Lable Lo be
used - |tab02_typ:

?ou sLlll have Lhe opLlon Lo use a header llne, buL Lhls musL be expllclLly sLaLed when cre-
aLlng an lnLernal Lable ln Lhls way. 1o do Lhls, you slmply add WI1n nLADLk LINL Lo Lhe
code above. 1hls ls however, as sLaLed several Llmes already, generally noL advlsable.
1he flnal Lhlng Lo do when creaLlng an lnLernal Lable Lhls way ls declare Lhe work area
whlch wlll be used ln con[uncLlon wlLh Lhe Lable. 8emember LhaL Lhe work area ls com-
pleLely separaLe from Lhe Lable, whlch has now already been creaLed, allowlng one Lo
work wlLh Lhe daLa from Lhe Lable ln a way whlch ls removed from lL. 1hls also allows for,
lf one wanLs, Lhe same work area Lo be used for mulLlple Lables, as long as Lhey have Lhe
same sLrucLures, an example of reuslng Lhe code.
1o declare wotk Ateo, agaln use Lhe uA1A sLaLemenL followed by Lhe work area name,
here wa_|tab02. After this, the TYPE statement is used to specify the line type, here we
can use the one already defined as line01_typ:

Whlle Lhe manner ln whlch Lhe old sLyle Lable ls creaLed may cerLalnly seem easler, Lhe
newer meLhod ls much beLLer and much more flexlble. lor example, havlng wrlLLen all of
Lhe above code, lf one Lhen wanLed Lo creaLe a new Lable wlLh Lhe same sLrucLure, only
one new llne of code would have Lo be wrlLLen, slnce Lhe llne and Lable Lypes have already
deflned. 1he table |tab03, for example, could be creaLed slmply by addlng one llne of
code:

I||||ng an Interna| 1ab|e w|th neader L|ne


229
INTERNAL TABLES
When you are readlng a record from an lnLernal Lable wlLh a header llne, LhaL record ls
moved from Lhe Lable lLself lnLo Lhe header llne. lL ls Lhen Lhe header llne LhaL you pro-
gram works wlLh. 1he same applles when creaLlng a new record. lL ls Lhe header llne wlLh
whlch you work wlLh and from whlch Lhe new record ls senL Lo Lhe Lable body lLself.
8elow appears some sllghLly more exLenslve code for an old-sLyle lnLernal Lable, whlch can
Lhen be populaLed:

1he flelds should broadly be famlllar. 1he only new one here ls |os, represenLlng leoqtb
of setvlce, an integer type with a default value of 3.
1o sLarL Lo flll Lhls Lable, you can use a SLLLC1 sLaLemenL Lo selecL all of Lhe records from
Lhe zemp|oyees Lable and Lhen use IN1C CCkkLSCNDING IILLDS CI 1A8LL |tab01.,
whlch wlll move Lhe records from Lhe orlglnal Lable lnLo Lhe new lnLernal Lable lnLo Lhe
flelds where Lhe names correspond. 1hls Lype of selecL sLaLemenL ls called an ottoy fetcb,
as lL feLches all of Lhe records aL once, and places Lhem ln a new locaLlon. noLlce LhaL
Lhere ls no LnuSLLLC1 sLaLemenL here - lL ls noL a loop LhaL ls creaLed:

As Lhe new los fleld does noL have a correspondlng fleld ln Lhe zemployees Lables, every
record wlll have Lhls fleld populaLed wlLh Lhe los default value of 3. Add a W8l1L sLaLe-
menL for lLab01-surname below [usL Lo asslsL ln Lhe debug sesslon comlng up. SeL a break-
polnL on Lhe SLLLC1 sLaLemenL, and execuLe Lhe code Lo enLer debug mode and observe
Lhe code as lL works.

230
INTERNAL TABLES
lf you vlew Lhe lnLernal Lable before execuLlng Lhe nexL llne of code here, you can see LhaL
lL ls currenLly empLy. 1he llne wlLh Lhe haL lcon represenLs Lhe currenL conLenLs of Lhe
header llne and below Lhls, Lhe llnes of Lhe lnLernal Lable wlll be fllled ln. As you execuLe
Lhe array feLch, all of Lhe llnes of Lhe lnLernal Lable are fllled aL once:


A dlfferenL way of fllllng Lhe Lable would be wlLh Lhe code below, Lhls Llme wlLh a selecL
loop fllllng each fleld one aL a Llme, uslng Lhe MCvL sLaLemenL Lo move Lhe daLa from one
tables field to the oLher. noLe LhaL los ls noL presenL here slnce lL does noL have a fleld ln
Lhe zemployees Lable.

231
INTERNAL TABLES

lf you debug Lhls code, you can see how lL operaLes llne-by-llne as opposed Lo Lhe array
feLch whlch dld all of Lhe records aL once. As you execuLe Lhe flrsL MCvL sLaLemenL, lL ls
vlslble LhaL Lhe flrsL employee number appears ln Lhe header record of Lhe lnLernal Lable:

SLepplng Lhrough Lhe code you wlll see Lhe oLher flelds gradually appear ln Lhe header llne
unLll Lhe end of Lhe SLLLC1 loop ls reached. Powever, once Lhls happens, slnce no code
has been lncluded Lelllng Lhe program Lo append Lhe daLa ln Lhe header record Lo Lhe ln-
Lernal Lable, Lhls wlll slmply be overwrlLLen by Lhe nexL lLeraLlon of Lhe loop. 1hls ls a
common mlsLake when uslng header llnes and can be avolded by uslng Lhe ALND
sLaLemenL.
8efore Lhe LnuSLLLC1 sLaLemenL add another line of code reading ALND |tab01., tell-
lng Lhe sysLem Lo add Lhe conLenLs of Lhe header llne Lo Lhe lnLernal Lable.

232
INTERNAL TABLES



Move-Correspond|ng
ln Lhe example, Lhe MCvL sLaLemenL was used several Llmes Lo move Lhe conLenLs of Lhe
zemployees Lable Lo Lhe correspondlng flelds ln Lhe lnLernal Lable. lL ls posslble however
Lo accompllsh Lhls acLlon wlLh [usL one llne of code. ?ou can use Lhe MCVL-
CCkkLSCNDING sLaLemenL. The syntax for this is simply MCVL-CCkkLSCNDING
zemp|oyees 1C |tab01., telling the system to move the daLa from Lhe flelds of
zemployees Lo Lhelr correspondlng flelds ln lLab01. 1hls ls made posslble by Lhe facL LhaL
boLh have maLchlng fleld names. When maklng use of Lhls sLaLemenL you need Lo make
sure LhaL boLh flelds have maLchlng daLa Lypes and lengLhs. 1hls has been done here wlLh
Lhe LlkL sLaLemenL prevlously, buL lf lL ls noL, Lhe resulLs could be unpredlcLable:


233
INTERNAL TABLES
nexL, copy Lhe code wlLh whlch Lhe lLab01 Lable was creaLed Lo creaLe anoLher lnLernal
Lable called lLab02. 1hls Llme, Lhe flelds wlll be populaLed wlLh an lnCLuuL sLaLemenL, so
remove Lhe flelds beLween Lhe 8LCln Cl and Lnu Cl sLaLemenLs and replace Lhem wlLh
the code INCLUDL S1kUC1UkL |tab01. This will create a new table with the same struc-
Lure:

?ou are noL llmlLed Lo uslng Lhe sLrucLure of anoLher lnLernal Lable, anoLher Lable creaLed
in the ABAP dictionarys structure could be used wlLh Lhe same sLaLemenL:

uslng Lhls meLhod can save a loL of Llme codlng, and can be enhanced furLher allowlng you
Lo lnclude mulLlple sLrucLures wlLhln one lnLernal Lable, as below (Lhough Lhls example
would, ln facL, [usL lnclude Lwo of each column as zemployees and lLab01 have effecLlvely
Lhe same sLrucLures):

As long as Lhe sLrucLures used have prevlously been deflned ln Lhe sysLem, Lhls sLaLemenL
can be used Lo lnclude many sLrucLures wlLhln newly creaLed lnLernal Lables. ?ou can also
add new daLa sLaLemenLs as were prevlously used Lo declare lnLernal Lable sLrucLures, ex-
Lendlng Lhe sLrucLures whlch have been lncluded wlLh new flelds.
Lets return to the array fetch meLhod of populaLlng lnLernal Lables. ?ou wlll noLe LhaL
when uslng Lhls meLhod, all of flelds were fllled slmulLaneously, wlLhouL uslng Lhe header
record. 1hls ls a very effecLlve and qulck meLhod Lo use, glven LhaL Lhere ls no loop, so re-
cords do noL have Lo be wrlLLen Lo Lhe Lable one aL a Llme:


234
INTERNAL TABLES
AddlLlonally, you do noL have Lo use Lhe * whlch selecLs all of Lhe flelds of zemployees, buL
can speclfy Lhe lndlvldual flelds you wanL Lo move ln Lhls way. See Lhe example below:

I||||ng Interna| 1ab|es w|th a Work Area
now, lf you are, followlng Lhe newer meLhod of uslng lnLernal Lables, Lhe header record ls
Lo be bypassed enLlrely and Lhe Lable fllled from a separaLe work area.
8eLurn Lo Lhe code whlch was shown above for creaLlng a Lable wlLh Lhe new meLhod,
shown below:

Pere, Lhe 5lc1 sLaLemenL ls used agaln. Slnce Lhe llne Lype only lncludes Lwo flelds, only
those two fields should be selected. Once theyre selected, lN1O ls used wlLh Lhe work
area speclfled as Lhe area Lo populaLe. An AllNu sLaLemenL ls added Lo move Lhe daLa
from Lhe work area lnLo Lhe Lable lLself. llnally, Nu5lc1 ls used:

An array feLch can also be used Lo populaLe Lhe lnLernal Lable. noLe LhaL here you can sLlll
use Lhe * Lo selecL all of Lhe records ln zemployees, buL as Lhe lnLernal Lable has only Lwo
of Lhese correspondlng flelds, Lhe resL wlll [usL be lgnored:

235
INTERNAL TABLES

Us|ng Interna| 1ab|es Cne L|ne at a 1|me
now you know how Lo flll lnLernal Lables wlLh daLa, a look wlll be Laken aL how Lo use Lhe
daLa ln Lhem llne-by-llne.
lnLernal Lables are [usL sLored ln memory, so cannoL be dlrecLly accessed, Lhelr conLenLs
can only be read vla Lhe work area, uslng a loop. 1he way Lhls ls done ls sllghLly dlfferenL
from daLabase Lables and, raLher Lhan uslng SLLLC1 and LnuSLLLC1, LCC and LNDLCC
are used lnsLead.
lltst, tobles osloq o beoJet lloe. Add some new code Lo your program as follows. 8egln Lhe
LCC and specify the internal table by adding A1 |tab01. Code is then added to achieve
Lhe deslred ouLcome and Lhe loop ls closed wlLh LNDLCC. lor example:

lf you execuLe code ln debug mode, you wlll see LhaL for each loop pass, Lhe header llne
(represenLed by Lhe haL lcon) ls fllled wlLh daLa before belng wrlLLen Lo Lhe ouLpuL screen:


236
INTERNAL TABLES

Mod|fy
now a look wlll be Laken aL how records ln Lhe Lable can be changed wlLh Lhe MCDII
statement. Using the code below, the IF statement will check whether an entrys surname
matches the set value of JONES. Where it does match, this will be updated to the new
value of SMITH in the header line. The MODIFY statement will then update the inLernal
Lable lLself wlLh Lhe new value. noLe LhaL Lhe MCull? sLaLemenL here wlll noL creaLe a
brand new record, buL wlll replace Lhe exlsLlng !CnLS record ln Lhe Lable. lf a MCull?
sLaLemenL ls used ln a loop, lL ls always Lhe currenL llne whlch ls changed. 1hls should noL
be done lf you are Lrylng Lo modlfy key flelds of an lnLernal Lable LhaL uses a unlque key. lf
Lhe MCull? sLaLemenL ls used ouLslde of a loop, Lhe record lndex number musL be specl-
fled. 1he way ln whlch Lhe sLaLemenL ls used here can only be used ln Lables wlLh lndex
Lables or header llnes:

Descr|be and Insert
ln Lhe same loop, Lhe uLSC8l8L 1A8LL sLaLemenL wlll be used. 1hls sLaLemenL can be used
Lo flnd ouL lnformaLlon abouL Lhe conLenL of an lnLernal Lable, lncludlng Lhe number of
records Lhe Lable holds, Lhe reserve memory space used, and Lhe Lype of Lable lL ls. lo
ptoctlce yoo ootmolly ooly evet teolly see tbls beloq oseJ to floJ oot tbe fltst of tbese tbtee
pleces of lofotmotloo tbooqb.

237
INTERNAL TABLES
Beneath the ENDIF, add the line of code DLSCkI8L 1A8LL |tab01 LINLS ||ne_cnt. The
LINLS parL of Lhls sLaLemenL ls used Lo requesL Lhe value of Lhe number of llnes conLalned
ln Lhe internal table, and ||ne_cnt is a new variable (of type i) set up to hold Lhls value.
up unLll now, Lhe ALnu sLaLemenL has been used Lo add records Lo Lhe Lable. 1hls
auLomaLlcally lnserLs Lhe new record aL Lhe end of Lhe Lable. lf you wanL Lo add a record
somewhere ln Lhe mlddle, Lhe INSLk1 sLaLemenL should be used, along wlLh Lhe Lable lo-
Jex oombet, Lo speclfy Lhe poslLlon where a new record ls Lo be lnserLed. lor example, lf
you used Lhe lndex number 10, Lhe new record would appear beLween Lhe 9
Lh
and 10
Lh

records ln Lhe Lable.
The syntax used here is INSLk1 |tab01 INDLk (n) where (n) is the index number where
you wanL Lo lnserL Lhe new record. ln Lhe example below, (n) ls represenLed by llne_cnL,
so Lhe new record wlll be lnserLed aL Lhe llne maLchlng Lhe lndex number whlch corre-
sponds Lo Lhe value of llne_cnL. 1he new record wlll be lnserLed on Lhe llne before Lhe lasL
llne of Lhe Lable:

lf you execuLe Lhe code ln debug mode, you wlll see Lhe surname !CnLS ls modlfled Lo
become SMl1P. 1he uLSC8l8L sLaLemenL ls Lhen Lrlggered and lloe_cot glven a value of 3.
now, Lhe lasL record ln Lhe Lable ls LhaL wlLh Lhe surname nC81PMC8L, employee num-
ber 10000006, so once Lhe loop compleLes, Lhls ls Lhe record held ln Lhe header llne. 1he
lnSL81 sLaLemenL, Lhen wlll add a copy of Lhls record aL Lhe 3
Lh
llne of Lhe Lable. kemem-
bet tbot, os tbls ls o stooJotJ type toble, Jopllcote tecotJs ote olloweJ. 8ecause you are ln
debug mode you can alLer the header records values can be manually altered in debug
mode, so a new, non-dupllcaLe record can ln facL be creaLed, wlLh Lhe surname 8LCCS and
employee number 10000007. 1he lmage below shows Lhe header record and lnLernal La-
ble [usL before and afLer Lhe lnSL81 sLaLemenL ls execuLed:

238
INTERNAL TABLES


kead
1he 8LAu sLaLemenL ls anoLher way ln whlch you can access Lhe records of an lnLernal La-
ble, allowlng you Lo read speclflc lndlvldual records from Lhe Lable. Clven LhaL Lhese ex-
amples are uslng Lhe old sLyle meLhod and as such uslng a header llne, Lhls record wlll be
senL Lo Lhe header llne and accessed from Lhere.
1he way LhaL Lhe lnLernal Lable has been declared wlll affecL Lhe way ln whlch a 8LAu
statements code is wrlLLen, bear Lhls ln mlnd. uependlng on wheLher Lhe Lable has a
unlque key or noL wlll also change how Lhe 8LAu sLaLemenL ls speclfled. lor a sLandard
table without a unique key, the records index number is used:

1he 8LAu sLaLemenL ls generally Lhe fasLesL way you can access Lhe records of an lnLernal
Lable, and uslng Lhe lndex number ls Lhe fasLesL way Lo use Lhls sLaLemenL. lL can be up Lo
14 Llmes fasLer Lhan a Lable key. Powever, you do noL always know Lhe lndex number of
Lhe record whlch ls Lo be read. lf you are uslng a Lable key, Lhe synLax would be as follows:

239
INTERNAL TABLES

1hls can also be done wlLh non-unlque keys, buL Lhls can become problemaLlc. lor exam-
ple, lf you used surname as your Lable key and Lhe Lable conLalned 3 surnames whlch
were Lhe same, Lhe sysLem sequenLlally reads Lhe records resulLlng ln Lhe flrsL occurrence
be read.
1hls Lype of code, parLlcularly wlLh key flelds, can also be used wlLh sorLed and hashed
Lables, whlch conLaln unlque key flelds.
De|ete kecords
1o deleLe records from an lnLernal Lable, you slmply use Lhe DLLL1L sLaLemenL. 1hls can
be used Lo deleLe elLher lndlvldual records or groups of records from a Lable. 1he fasLesL
way of achlevlng Lhls ls by speclfylng a Lable lndex. noLe Lhls only applles Lo sLandard and
sorLed Lables as only Lhese Lwo Lypes of Lables have an lndex. 1he synLax ls as follows:

1he header llne ls noL used aL all. 1he record Lo be deleLed ls dlrecLly accessed vla lLs lndex
number.
1hls sLaLemenL can also be used lnslde a loop:

1he code here wlll ldenLlfy any record wlLh Lhe surname SMl1P and deleLe lL. As you do
noL know Lhe lndex number of SMl1P beforehand, Lhe sysLem varlable sy-|ndex ls used,
whlch ls always seL Lo Lhe lndex number of Lhe currenL loop, so when Lhe SMl1P record
appears, sy-|ndex wlll maLch lLs lndex number and Lhe record wlll be deleLed.

240
INTERNAL TABLES
1he uLLL1L sLaLemenL should noL be used wlLhouL Lhe lnuLx addlLlon. lf used ouLslde of a
loop resulL ln a runLlme error, causlng Lhe program Lo crash. lnslde a loop, lL musL be pre-
senL Lo adhere Lo fuLure releases of Lhe A8A synLax.
AnoLher addlLlon Lo Lhe uLLL1L sLaLemenL ls Lhe WnLkL clause. 1here are Llmes where
when you wlll noL know Lhe lndex number of Lhe record you wanL Lo deleLe, so more code
wlll have Lo be added. 1he WPL8L addlLlon ls useful here, and can be comblned wlLh
oLher loglc Lo locaLe Lhe record(s) whlch should be deleLed. uslng Lhls, you musL always be
as speclflc as posslble, oLherwlse daLa whlch should noL be deleLed can be. 1he synLax
should look llke Lhls:

noLe LhaL lf Lhere are mulLlple records whlch maLch Lhe loglcal expresslon, Lhey wlll all be
deleLed.
Sort kecords
1he sLaLemenL used Lo sorL records ln an lnLernal Lable ls, unsurprlslngly, SC81. 1he baslc
synLax ls very slmple:

WlLhouL any addlLlons, Lhls wlll sorL Lhe records ln ascendlng order by Lhe tables unlque
key. 1hls works for sorLed and hashed Lables. lor a sLandard Lable, you musL use Lhe 8
addlLlon Lo speclfy whlch flelds Lo sorL by:

1hls would sorL Lhe Lable alphabeLlcally ln ascendlng order by Lhe fleld Su8nAML. 8ear ln
mlnd LhaL SA sysLems work wlLh a wlde varleLy of languages all aL Lhe same Llme, so lf
you are sorLlng by language-speclflc crlLerla, AS 1Lk1 should be added beLween Lhe Lable
name and 8? addlLlon.
?ou are noL llmlLed Lo sorLlng [usL by one fleld, you can llsL up Lo 230 flelds lf deslred. ln
Lhls example, lC8LnAML ls added. noLe LhaL lL ls noL necessary Lo separaLe Lhese wlLh
commas:

241
INTERNAL TABLES

Clven Lhe poslLlon of AS 1Lx1 ln Lhe sLaLemenL, Lhls wlll be applled Lo all flelds whlch are
speclfled. lf you only wanLed AS 1Lx1 Lo apply Lo forename, lL would be placed afLer Lhe
forename:

8y defaulL, Lhe sysLem wlll sorL records ln ascendlng order. 1hls can be changed Lo de-
scendlng as shown:

Work Area D|fferences
Pavlng been Lhrough Lhe sLaLemenLs wlLh whlch one can work wlLh lnLernal Lables wlLh a
header record, Lhe old sLyle, now Lhe dlfferences ln uslng Lhese meLhods wlLh Lhe new,
encouraged sLyle of operaLlng wlLh a separaLe work area wlll be looked aL
Q''5,
llrsL, lets look at the dlfferences ln readlng daLa ln a loop. Pere, Lhe loop wlll read each
record from Lhe lnLernal Lable and place each record lnLo Lhe work area lnsLead of Lhe
header llne. 8ecause Lhe work area ls compleLely separaLe from Lhe lnLernal Lable, Lhe
work area you wanL Lo use wlLhln Lhe loop musL be speclfled. 1he IN1C addlLlon ls used Lo
speclfy Lhe work area Lhe record ls Lo be read lnLo:

ln Lhls example Lhe records wlll be read one record aL a Llme lnLo Lhe work area
wa_|tab02, Lhen Lhe conLenLs of Lhe surname fleld wlll be wrlLLen Lo Lhe ouLpuL screen.

242
INTERNAL TABLES
>';4(9
uslng Lhe MCDII sLaLemenL wlLh Lhls klnd of lnLernal Lable Lhe sLaLemenL musL speclfl-
cally reference Lhe work area. 1he example below shows our prevlous MCull? sLaLemenL
example alLered Lo work wlLh a work area:

6*,%.+
When worklng wlLh Lhe lnSL81 sLaLemenL wlLh Lhls Lype of lnLernal Lable, noLhlng needs
Lo change Lo Lhe uLSC8l8L sLaLemenL. 1he only change ls Lo Lhe lnSL81 sLaLemenL. Pere
Lhe new record held ln wa_lLab02 ls Lo be lnserLed ln1C Lhe lnLernal Lable lLab02:

G%";
1he 8LAu sLaLemenL agaln follows a slmllar loglc, lnslsLlng LhaL Lhe work area ls also refer-
enced ln Lhe code:


3%$%+%
!usL as Lhe uLLL1L sLaLemenL does noL requlre any reference Lo Lhe header record Lo
work, nor does lL requlre any reference Lo Lhe work area. 1he sLaLemenL deleLes records
from Lhe Lable dlrecLly by Lhelr lndex number or oLher key, so operaLes no dlfferenLly aL all
here.

243
INTERNAL TABLES
De|ete a 1ab|e w|th a neader L|ne
When worklng wlLh lnLernal Lables, you wlll ofLen come upon slLuaLlons where lL ls neces-
sary Lo deleLe all of Lhe records ln a Lable ln one go, dependlng upon Lhe speclflc Lask you
Lrylng Lo compleLe. lor example, lf you flll an lnLernal Lable ln a hlgh level loop, you wlll
wanL Lhe Lable Lo be empLy when lL comes Lo Lhe nexL lLeraLlon. 1hls secLlon wlll explaln
how Lo deleLe lnLernal Lables and Lhelr conLenLs, flrsL for Lhose wlLh header llnes, Lhen for
Lhose wlLh work areas.
1here ls a cerLaln sequence of Lasks you should adhere Lo when deleLlng Lhe conLenLs of
an lnLernal Lable wlLh a header llne. llrsL, you should ensure Lhe header llne ls clear, Lhen
LhaL Lhe body of Lhe Lable ls clear.
)Q:7G
1o do Lhe flrsL of Lhese Lasks, use Lhe CLLAk sLaLemenL, followed by Lhe Lable name. 1hls
wlll clear ouL Lhe header llne only, and seL Lhe header-llne flelds Lo Lhelr lnlLlal value. 1o
clear Lhe body of Lhe Lable, Lhe sLaLemenL ls used agaln, only Lhls Llme followed by [], de-
leLlng all of Lhe records ln Lhe Lable lLself:

G:<G:?H
AlLernaLlvely, Lhe kLIkLSn sLaLemenL can be used. 1hls wlll clear all records from Lhe La-
ble, buL you musL bear ln mlnd LhaL lL does noL clear Lhe header record, whlch wlll sLlll
conLaln values:

<G::
?ou could also use Lhe IkLL sLaLemenL, wlLh Lhe same synLax as 8Ll8LSP. 1hls sLaLemenL
noL only clears ouL Lhe lnLernal Lable, buL also frees up Lhe memory whlch lL was uslng. lL
does noL mean Lhe Lable ceases Lo exlsL enLlrely, buL no longer ls operaLlng ln memory.
WlLh Lhls sLaLemenL, llke 8Ll8LSP, Lhe header llne ls unaffecLed, so Lhe flrsL CLLA8 sLaLe-
menL musL always be used ln con[uncLlon wlLh boLh of Lhese:


244
INTERNAL TABLES
De|ete a 1ab|e w|th a Work Area
1o deleLe lnLernal Lables whlch are uslng work areas, slmllar meLhods are used. Powever,
as Lhe work area ls an enLlrely dlfferenL sLrucLure, any code wrlLLen whlch wlll affecL Lhe
lnLernal Lable wlll noL affecL Lhe work area, and vlce versa.
1he CLLA8 sLaLemenL above, when used on a Lable wlLhouL a header llne, wlll clear Lhe
whole conLenLs of Lhe Lable wlLhouL needlng Lo add Lhe []. 8emember LhaL anoLher CLLA8
sLaLemenL musL be used Lo empLy Lhe work area. 1he same applles Lo Lhe 8Ll8LSP and
l8LL sLaLemenLs. 1he synLax above wlll work, and a furLher CLLA8 sLaLemenL musL be
used Lo empLy Lhe work area. ln Lhe examples below, assume lLab01 and wa_lLab01 refer
Lo Lhe newer sLyle lnLernal Lable and lLs work area:


245
MODULARIZING PROGRAMS
Chapter 13 Modu|ar|z|ng rograms

Introduct|on
As has been dlscussed before, lL ls good pracLlce when uslng SA Lo keep your programs as
self-conLalned and easy Lo read as posslble. 1ry Lo spllL large, compllcaLed Lasks up lnLo
smaller, slmpler ones by placlng each Lask ln lLs own separaLe, lndlvldual module whlch
Lhe developer can concenLraLe on wlLhouL oLher dlsLracLlons. Modularlzlng your code al-
lows slngle Lasks Lo be focussed upon one aL a Llme, wlLhouL Lhe dlsLracLlon and confuslon
whlch can be caused lf Lhe code you are worklng wlLh ls ln Lhe mlddle of a large, compll-
caLed sLrucLure. uolng Lhls makes Lhe program much easler Lo work wlLh and debug. Cnce
a small, modularlzed secLlon of code ls compleLe, debugged and so on, lL does noL subse-
quenLly have Lo be reLurned Lo, meanlng Lhe developer can Lhen move on and focus on
oLher lssues.
CreaLlng lndlvldual source code modules also prevenLs one from havlng Lo repeaLedly
wrlLe Lhe same sLaLemenLs agaln and agaln, whlch ln Lurn makes Lhe code easler Lo read
and undersLand for anyone comlng Lo lL for Lhe flrsL Llme. 1hls ls also useful when lL comes
Lo supporL. Anyone laLer havlng Lo supporL Lhe program wlll agaln flnd Lhe code much
more comprehenslble lf lL ls wrlLLen Lhls way.
lL ls lmporLanL Lo concenLraLe on Lhe deslgn of a program. 8aLher Lhan sLarLlng Lo code a
soluLlon sLralghL away, a soluLlon should be mapped ouL, uslng pseudo-code or flow-
charLs for example. Cnly when Lhe deslgn makes sense should Lhe codlng exerclse begln.
Pavlng a soluLlon deslgn also helps when modularlzlng a program, because Lhls allows you
Lo see how Lhe program can be spllL up lnLo separaLe pleces, allowlng you Lo Lhen focus on
Lhe lndlvldual pleces of developmenL one plece aL a Llme.
ln Lhe chapLer coverlng selecLlon screens, modularlzaLlon was hlnLed aL wlLh Lhe use of
processlng blocks. Powever, modularlzaLlon ln your own programs ls noL [usL llmlLed Lo
processlng blocks. 1he SA sysLem allows for a number of Lechnlques Lo be used Lo break
a program up lnLo smaller, more manageable secLlons of code.
1hls chapLer wlll look aL Lhe Lools SA provldes for achlevlng Lhls.

246
MODULARIZING PROGRAMS
Inc|udes
When Lalklng abouL modularlzaLlon, whaL we are really Lalklng abouL ls Laklng a sequence
of A8A sLaLemenLs and placlng Lhem ln Lhelr own, separaLe module. We can then call
Lhls code module from our program.
Pere, some code whlch has been used prevlously wlll be modularlzed. 8elow ls Lhe code
for Lhe second lnLernal Lable whlch was creaLed, Lhe one wlLh a work area, followed by
some loglc whlch wlll perform Lasks lnvolvlng Lhe lnLernal Lable:



247
MODULARIZING PROGRAMS
llrsL, we wlll look aL lnCLuuL programs. INCLUDEs are made avallable globally wlLhln an
SA sysLem and Lhelr sole purpose ls modularlzlng code. 1hey are slmple Lo deflne and
accepL no parameLers. 8elow Lhe 8LC81 sLaLemenL, flll ln Lhe sLaLemenL for declarlng an
lnclude. 1ype INCLUDL and Lhen deflne a name, here 2_LMLCLL_DLIINI1ICNS:

1hls sLaLemenL ls Lelllng Lhe program Lo locloJe Lhe lnCLuuL program wlLhln our orlglnal
program. 1here are Lwo ways of creaLlng Lhls new lnCLuuL program. ?ou can Lype Lhe
name into the ABAP editors initial screen and select the Attributes radio button, fol-
lowed by Create. Then, when the window appears asking what kind of program this is,
select INCLUDE program:

1he second meLhod ls by uslng forward navlgaLlon. ln Lhe code wlndow, double-cllck
2_LMLCLL_DLIINI1ICNS and select Yes to create the new object. Save as Local ob-
ject as before, and then you wlll be presenLed wlLh a new, blank codlng screen where Lhe
lnCLuuL program code can be Lyped/lnserLed:

248
MODULARIZING PROGRAMS

8emember, Lhe lnCLuuL program ls a separaLe flle on Lhe SA sysLem so can be lncluded
ln any oLher program. 1he lnCLuuL program musL be acLlvaLed lLself, and when you acLl-
vaLe any program LhaL lncludes lL, lL wlll always check Lo see lf Lhe lnCLuuL program ls
acLlve Loo. lf noL, error messages wlll appear. A slmple way Lo acLlvaLe boLh aL once ls Lo
selecL boLh ln Lhe menu offered when acLlvaLlng Lhe maln program:

ln Lhe maln program, commenL ouL Lhe secLlon where Lhe lloe type ls deflned, and copy &
pasLe lL lnLo Lhe lnCLuuL program:

249
MODULARIZING PROGRAMS


8ecause Lhe lnCLuuL program has been declared ln Lhe maln program above, Lhe pro-
gram wlll conLlnue Lo work as normal. 1hls ls an example of a way ln whlch code can be
effecLlvely ouLsourced Lo an lnCLuuL program, removlng LhaL code from servlce ln Lhe
maln program and hence maklng LhaL program less densely populaLed wlLh code. 1hls
does noL have Lo be used only for daLa declaraLlons as ln Lhls case. lL ls commonly used for
secLlons of programs whlch lnvolve program loglc Loo.
rocedures
lf you wanL Lo spllL programs lnLo separaLe funcLlonal modules, procedures can be used.
1hese are processlng blocks whlch are called from Lhe maln A8A program, and come ln
Lhe form of sub-rout|nes, sub-programs, and funct|on modu|es.
Sub-rouLlnes and sub-programs are malnly used for local modularlzaLlon of code, mean-
lng small, modular, self-conLalned unlLs of code called from Lhe program ln whlch Lhey are
deflned. 1hese can Lhen, lf necessary, be used many Llmes ln Lhe program wlLhouL havlng
Lo be Lyped ouL repeaLedly. luncLlon modules, on Lhe oLher hand, allow you Lo creaLe
modular blocks of code whlch are held separaLely from an A8A program and can be
called from any oLher program.
Sub-rouLlnes are locol, and funcLlon modules are qlobol, and boLh Lypes of procedure are
commonly used ln SA sysLems. 1he laLLer, Lhough, are probably Lhe more wldely used of

250
MODULARIZING PROGRAMS
Lhe Lwo. luncLlon modules can be used Lo encapsulaLe all of Lhe processlng loglc used
wlLhln Lhe buslness sysLem, and SA has ensured LhaL Lhey can be used boLh by Lhelr own
developers and SAPs customers.
lnCLuuL programs cannoL accepL any parameLers, procedures dlffer here, and have an
lnLerface for Lransferrlng daLa from Lhe calllng program Lo Lhe procedure lLself. 8ecause
daLa can be passed lnLo a procedure, Lhls means LhaL you can deflne daLa deflnlLlons
wlLhln Lhe procedure lLself whlch are only avallable Lo LhaL procedure.
Sub-kout|nes
Cne of Lhe greaL beneflLs of uslng sub-rouLlnes ls LhaL lL helps Lo modularlze program code
lnslde Lhe acLual program, glvlng Lhe program sLrucLure.
1o creaLe a sub-rouLlne, forward navlgaLlon ls used. Copy, and Lhen commenL ouL, Lhe ar-
ray feLch SLLLC1 sLaLemenL from Lhe lnLernal Lable code above:

Above Lhe commenLed-ouL secLlon, use Lhe sLaLemenL LkICkM. 1hls sLaLemenL ls used
Lo perform a sub-rouLlne. 1hen a name for Lhe sub-rouLlne ls added. Pere, slnce Lhls code
fllls Lhe lLab02 lnLernal Lable, call Lhe sub-routine |tab02_f||| as shown:

uouble-cllck Lhe sLaLemenL Lhen Lo use forward navlgaLlon and creaLe Lhe sub-rouLlne.
Answer Yes to Lhe dlalog box and a wlndow appears asklng where Lhe sub-rouLlne ls Lo
be creaLed. A cholce ls offered beLween Lhe maln program, Lhe lnCLuuL program and a
new lnCLuuL program whlch can be creaLed. SelecL Lhe maln program here. Cnce Lhls ls
done, code block starting with form and ending with endform. ls creaLed locaLed aL Lhe
end of your program, where Lhe code for Lhe sub-rouLlne can be fllled ln. asLe ln Lhe code
for Lhe array feLch, and Lhe sub-rouLlne ls creaLed:

251
MODULARIZING PROGRAMS

When Lhe L8lC8M sLaLemenL ls reached as Lhe program execuLes, Lhe sub-rouLlne cre-
aLed wlll be Lrlggered, meanlng LhaL Lhe array feLch ls performed ln exacLly Lhe same way
as previously. Once endform. is reached, processing returns to the next staLemenL fol-
lowlng L8lC8M and conLlnues as normal, LermlnaLlng aL Lhe end. 1hough Lhe sub-
rouLlne does appear aL Lhe boLLom of Lhe code, Lhe sysLem can ldenLlfy lL as a sub-rouLlne
and hence lL wlll noL be execuLed agaln.
up unLll now, only global varlables have been dlscussed. 1hese are varlables whlch are
deflned as ln Lhe program lLself, usually aL Lhe Lop of Lhe program and, ln Lhls lnsLance, Lhe
lnCLuuL program. 1hese varlables, lncludlng lnLernal Lables and so on, can be accessed
LhroughouL Lhe program. lf varlables are declared only ln sub-rouLlnes, however, Lhese are
consldered local varlables. 1hese can only be accessed wlLhln Lhe slngle sub-rouLlne where
Lhey are declared. Cnce conLrol passes back Lo Lhe maln body of Lhe program, local varl-
ables can no longer be referenced.
Clven LhaL Lhese varlables only have Lo be declared wlLhln sub-rouLlnes, raLher Lhan Lhe
whole program, memory usage ls kepL Lo a mlnlmum. AddlLlonally, Lhese can be useful ln
helplng keep everyLhlng self-conLalned and modularlzed. As menLloned prevlously, sub-
rouLlnes have an lnLerface, and Lhese local varlables can be used ln Lhe lnLerface.
1o declare a local varlable, one slmply uses Lhe uA1A sLaLemenL as normal wlLhln Lhe sub-
routine. Declare one of these named zemp|, which is LIkL zemp|oyees-surname. 1hls
new varlable can now only be referenced by oLher code whlch appears ln Lhe sub-rouLlne,
beLween fotm and eoJfotm. ?ou can also declare a varlable Lo be used ln Lhe lnLerface. ln

252
MODULARIZING PROGRAMS
dolng Lhls, Lhe sysLem ls belng Lold LhaL daLa wlll be Lransferred Lo Lhe sub-rouLlne daLa
lnLerface.
CreaLe code for a second sub-routine, called |tab_02_f|||_aga|n and above this create 2
new uA1A flelds, as shown ln Lhe example below, Lelllng Lhe new sub-rouLlne Lo use Lhe
new daLa flelds. 1hen use forward navlgaLlon Lo creaLe Lhls sub-rouLlne:


noLe Lhe dlfference ln how Lhe new sub-rouLlne appears. 1hls form has now been gener-
aLed lncludlng Lwo flelds whlch wlll Lhen be used ln Lhe lnLerface. lL ls advlsable here Lo
rename Lhe flelds ln Lhe sub-rouLlne so you know whaL Lhey refer Lo:

noLlce LhaL Lhere ls no daLa Lype for Lhese flelds, slnce Lhey are Laken from Lhe flelds ref-
erenced ln Lhe L8lC8M sLaLemenL, however, Lhey wlll Lake on Lhe same properLles as
Lhose flelds. Add some new code Lo Lhe form as shown below. 1he values of p_zsurname
and p_zforename wlll be wrlLLen, Lhen Lhe value of p_zsurname changed to abcde:

253
MODULARIZING PROGRAMS

Lnsure Lhese flelds hold some daLa by glvlng z_fleld1 and z_fleld2 values ln Lhe maln pro-
gram:

When Lhe L8lC8M sLaLemenL ls execuLed, Lhese values wlll be passed Lhrough Lo Lhe
flelds ln Lhe sub-rouLlne. Add a breakpolnL above Lhls and run Lhe program can be run ln
debug mode.
?ou can see z_fleld1 and z_fleld2 are fllled wlLh Lhelr lnlLlal values:

nexL, Lhe sub-rouLlne ls enLered and Lhe values of Lhese flelds are passed ln vla Lhe lnLer-
face, so LhaL Lhe local varlables here Lake on Lhe same values as Lhose ln Lhe maln pro-
gram:

1he Lwo W8l1L sLaLemenLs are Lhen execuLed, followed by Lhe change ln value for
p_zsurname. Because the field is used in the interface, the global variable, z_field1s value
also changes:

254
MODULARIZING PROGRAMS

When uslng flelds ln Lhe lnLerface, lL ls lmporLanL Lo keep Lhls ln mlnd. Any flelds aLLached
Lo Lhe USING addlLlon LhaL are changed ln Lhe sub-rouLlne wlll also be changed ln Lhe pro-
gram.
0",,4*D !"#$%,
Sub-rouLlnes are noL llmlLed Lo only passlng lndlvldual flelds. lnLernal Lables can also be
passed, as well as a comblnaLlon of boLh flelds and Lables. When passlng flelds Lhough,
one musL always geL Lhe sequence of fleld names correcL, as lL ls Lhe sequence whlch wlll
deLermlne whlch fleld ls passed Lo Lhe lnLerface varlable of Lhe form.
CreaLe a new sub-rouLlne called |tab02_wr|te. 1hen, use Lhe 1A8LLS addlLlon Lo speclfy
Lhe Lable Lo be passed, here |tab02:

8emovlng any unnecessary code, Lhe form wlll look llke Lhls:

uslng Lhe 1A8LLS addlLlon, Lhe program ensures LhaL Lhe conLenLs of Lhe lnLernal Lable are
Lransferred Lo Lhe subrouLlne and sLored ln Lhe lnLernal Lable p_|tab_02. Cnce Lhls sub-
rouLlne ls processed, Lhe conLenLs of Lhe local lnLernal Lable are Lhen passed back Lo Lhe
global lnLernal Lable.

255
MODULARIZING PROGRAMS
noLe LhaL Lhls meLhod ls for a Lable wlLhouL a header llne. lf Lhls code was used wlLh an
old-sLyle lnLernal Lable, only Lhe header llne would be passed Lo Lhe Lable. 1o pass Lhe full
Lable, you need Lo add [] aL Lhe end of Lhe sLaLemenL.
When an lnLernal Lable ls passed lnLo a sub-rouLlne, Lhe local lnLernal Lable ls always de-
clared wlLh a header llne. WrlLe some code and Lhen debug Lhe program Lo see Lhls. 1he
code below wlll loop Lhrough Lhe records of Lhe lnLernal Lable, sendlng Lhe conLenLs Lo a
Lemporary work area and Lhen wrlLlng Lhe conLenLs of Lhe surname fleld Lo Lhe ouLpuL
screen:

When analysed ln debug mode, Lhe lLab02 Lable does noL have a header record, buL
p_lLab02 does:


SLlll, slnce a new work area was creaLed for Lhe LCC sLaLemenL Lo follow, Lhe header re-
cord becomes lrrelevanL.
0",,4*D !"#$%, "*; <4%$;, !'D%+2%.
now, a comblnaLlon of flelds and Lables wlll be passed lnLo a subrouLlne aL Lhe same Llme.
CreaLe anoLher L8lC8M sLaLemenL, called |tab02_mu|t|. 8eLaln Lhe 1A8LLS sLaLemenL,
buL Lhen add Lhe uSlnC sLaLemenL afLerwards:

256
MODULARIZING PROGRAMS

use forward navlgaLlon Lo generaLe Lhe form.

?ou can Lhen use wrlLe code Lo lnLeracL wlLh boLh flelds and Lhe Lable.
Sub-kout|nes - Lxterna| rograms
Sub-rouLlnes were lnlLlally deslgned for modularlzlng and sLrucLurlng a program, buL Lhey
can be exLended so LhaL Lhey can be called exLernally from oLher programs. Cenerally Lo
do Lhls, Lhough, one should creaLe funcLlon modules lnsLead.
lf you do wanL Lo creaLe exLernal sub-rouLlnes, however, Lhls ls posslble. 1here are Lwo
ways ln whlch a sub-rouLlne can be called from an exLernal program. 1he flrsL of Lhese ls
Lhe one whlch should really always be used lf dolng Lhls, as Lhls ls compaLlble wlLh Lhe use
of A8A ob[ecLs.
lf you wanL Lo call a sub-rouLlne called sub_1, held in a program called zemployee_hire,
Lhe code would look llke Lhls. noLe LhaL addlLlons can sLlll be used wlLh Lhls meLhod:

1he dlfference here ls LhaL Lhe sub-rouLlne ls belng called from a separaLe program ln Lhe
SA sysLem.
1he second form ls very slmllar, and works Lhe same wlLh addlLlons and so on, Lhe pro-
gram ls [usL lncluded ln brackeLs. keep ln mlnd Lhough Lhls form of Lhe code cannoL be
used wlLh A8A ob[ecLs:

Calllng exLernal sub-rouLlnes ls noL common pracLlce, sub-rouLlnes Lend Lo sLay lnLernal Lo
Lhe program and where you wanL Lo call sub-rouLlnes ln exLernal programs, Lhls ls usually
done vla funcLlon modules.

257
MODULARIZING PROGRAMS
Iunct|on Modu|es
luncLlon modules make up a ma[or parL of an SA sysLem, because for years SA have
modularlzed code uslng Lhem, allowlng for code re-use, flrsL by Lhemselves and Lhelr de-
velopers, Lhen by cusLomers.
luncLlon modules refer Lo speclflc procedures whlch are deflned ln funcLlon groups, and
can be called from any oLher A8A program. 1he funcLlon group acLs as a klnd of conLalner
for a number of funcLlon modules whlch would loglcally belong LogeLher, for example, Lhe
funcLlon modules for an P8 payroll sysLem would be puL LogeLher lnLo a funcLlon group.
SA sysLems have Lhousands of funcLlon modules avallable for use ln programs, so lf you
search around Lhe sysLem lL wlll ofLen be posslble Lo flnd pre-exlsLlng modules for Lhe
Lasks you may be asked Lo code.
1o look aL how Lo creaLe funcLlon modules, Lhe funcLlon bullder musL be looked aL. 1hls ls
found vla Lhe menu aL Lhe very beglnnlng of Lhe sysLem, vla Lhe SA menu 1ools
A8A Workbench uevelopmenL. 1here one wlll flnd Lhe funcLlon bullder, wlLh Lransac-
Llon code SL37:

258
MODULARIZING PROGRAMS

8efore dlvlng lnLo an example of how Lo use a funcLlon module we need look aL how func-
Llon modules are puL LogeLher, so as Lo undersLand how Lo use Lhem ln a program.
Iunct|on Modu|es Components
1he lnlLlal screen of Lhe funcLlon bullder appears llke Lhls:


259
MODULARIZING PROGRAMS
8aLher Lhan Lyplng Lhe full name here, parL of a funcLlon module name wlll be Lyped wlLh
a wlld card characLer Lo demonsLraLe Lhe way funcLlon modules can be searched for. 1ype
*amounL* and Lhen press Lhe l4 key. 1he resulLs of Lhe search wlll Lhen be dlsplayed ln a
new wlndow:


1he funcLlon modules are dlsplayed ln Lhe llnes wlLh a blue background and Lhelr funcLlon
groups ln Lhe plnk llnes above. lf you would llke Lo look furLher aL Lhe funcLlon group ISCC,
Lhe Cb[ecL navlgaLor screen (se80) can be used. 1hls screen can ln facL be used Lo navlgaLe
many ob[ecLs held ln Lhe SA sysLem, noL only funcLlon modules buL programs and so on,
uslng Lhe menus on Lhe lefL hand slde of Lhe screen. Pere, we can see a llsL of funcLlon
modules (and oLher ob[ecLs) held ln Lhe funcLlon group lSCC:

260
MODULARIZING PROGRAMS

1he four whlch showed up ln Lhe *amounL* search are presenL, along wlLh a number of
oLhers. lf double-cllck any of Lhese funcLlon modules, Lhe code for LhaL funcLlon module
wlll appear on screen Lo Lhe rlghL of Lhe menu:

261
MODULARIZING PROGRAMS

8eLurn back Lo Lhe funcLlon bullder screen, do Lhe *amounL* search agaln and Lhls Llme
selecL Lhe funcLlon module SLLL_AMCUN1. uouble-cllck lL and choose ulsplay.
1he code wlll Lhen appear ln a screen slmllar Lo LhaL of Lhe A8A edlLor. 1here are, how-
ever, a serles of Labs along Lhe Lop whlch wlll now be looked aL.

262
MODULARIZING PROGRAMS

7++.4#=+%, !"#
1hls shows Lhe funcLlon group and some descrlpLlve LexL for Lhe funcLlon module, as well
as some options for the function modules processing type, plus some general daLa.
6E5'.+ !"#
1hls llsLs Lhe flelds whlch wlll be used ln Lhe daLa lnLerface whlch are passed lnLo Lhe func-
Llon module from Lhe calllng program. 1hese flelds are Lhen used by Lhe funcLlon module
code:


263
MODULARIZING PROGRAMS
1ake noLe of Lhe dlfferenL column labels. 1he flfLh column, wlLh a checkbox, ls labelled
Cpt|ona|, meaning that Lhese flelds do noL have Lo be passed lnLo Lhe funcLlon module
by Lhe calllng program. More ofLen Lhan noL Lhough, Lhere wlll be aL leasL one mandaLory
fleld.
:I5'.+ !"#
1hls speclfles Lhe flelds whlch are senL back Lo Lhe calllng program once Lhe funcLlon mod-
ules code has been processed:

)2"*D4*D !"#
1hls llsLs flelds whlch can be cbooqeJ by Lhe funcLlon module.
!"#$%, !"#
Llke sub-rouLlnes, wlLh funcLlon modules you are noL resLrlcLed Lo only passlng ln flelds,
buL can also pass ln lnLernal Lables.
:I1%5+4'*, !"#
1hls Lab llsLs excepLlon lnformaLlon whlch can be passed back Lo Lhe calllng program,
whlch lndlcaLe wheLher Lhe funcLlon module was execuLed successfully or noL. 1hls ls
where speclflc error messages for can be deflned Lo ldenLlfy any speclflc errors or warn-
lngs LhaL occur durlng code execuLlon LhaL need Lo be passed back Lo Lhe calllng program
Lo allow Lhe programmer Lake Lhe necessary course of acLlon.


264
MODULARIZING PROGRAMS
?'=.1% )';% !"#
1he flnal Lab ls Lhe source code lLself for Lhe funcLlon module, whlch appears auLomaLl-
cally when one opens lL from Lhe funcLlon bullder screen. Pere, you can examlne Lhe code
ln depLh so as Lo deLermlne whaL exacLly Lhe funcLlon module ls dolng.
WlLh pre-exlsLlng funcLlon modules you generally do noL even have Lo look aL Lhls, as you
should know whaL daLa Lhe funcLlon module ls supposed Lo send back.
1be fooctloo moJole lo tbls exomple coovetts oometlc flqotes loto wotJs, so tbete ls llttle
oeeJ to exomloe tbe coJe lo Jeptb lf ooe olteoJy koows wbot tbe ootpot ls to be.
Iunct|on Modu|e 1est|ng
As luncLlon Modules are creaLed as separaLe ob[ecLs, Lhere are Lools you can use Lo LesL
funcLlon modules wlLhouL havlng Lo wrlLe Lhe code Lo call Lhem. !usL as programs can be
LesLed and Lhelr ouLpuL checked, you can do exacLly Lhe same wlLh funcLlon modules. 1hls
ls done wlLh Lhe l8 key or Lhe same 1esL/LxecuLe lcon found ln your own programs. ln
facL, you dont even have Lo be wlLhln Lhe funcLlon module Lo do LesL lL ouL. lL can be done
from the initial SE37 screen once the modules name appears in the appropriate field:

1esL ouL Lhe funcLlon module uslng Lhe 1esL buLLon as shown above.

265
MODULARIZING PROGRAMS

As all flelds are opLlonal, Lhls can Lhen be execuLed wlLhouL lnpuLLlng any daLa.

Slnce Lhe amounL ln Lhe lmporL parameLers was 0, Lhe exporL parameLers Lhen read ZL8C.
lf you cllck Lhe small buLLon ln Lhe voloe colomo of Lhe exporL parameLers, Lhe resulLs are
broken lnLo Lhelr lndlvldual exporL flelds.

266
MODULARIZING PROGRAMS

1he number lnpuL was 0, Lhe declmal value was 0 and a currency was noL speclfled, so Lhe
WC8u ouLpuL ls slmply ZL8C.
Lets run the test again but this time enLer some daLa lnLo Lhe AMCun1 fleld and Cu8-
8LnC? fleld. 1hen execuLe Lhe LesL agaln.




267
MODULARIZING PROGRAMS

1hls ouLpuL may look odd, buL when Lhe buLLon ls pressed you wlll see LhaL, as G8 has 2
dec|ma|s, Lhe value S6 has been lncluded ln Lhe dec|ma|s column raLher Lhan Lhe number
column:

lf you were Lo selecL a currency whlch does noL use declmals, Lhe full number would ap-
pear.
1he ablllLy Lo LesL funcLlon modules ln Lhls way ls a greaL Llme saver for Lhe programmer,
as lL allows you Lo conflrm wheLher a funcLlon module wlll compleLe Lhe Lasks you wanL
before generaLlng Lhe code Lo use lL ln your program.
Iunct|on Modu|es - Cod|ng
now we have successfully LesLed Lhe funcLlon module and know whaL lL does, lets see
how we would call lL from an A8A program.
ln SL38, creaLe a new program called 2_MCD_2. LnLer some code so LhaL a parameLer can
be seL up where a value can be enLered:

(1be text elemeot text-001 here reads Enter a Value)

268
MODULARIZING PROGRAMS

now a value can be enLered lnLo Lhe selecLlon screen, Lhe value can be passed on Lo Lhe
function module. To write the code for this, the Pattern button can be used (also
C18L+l6). lL ls advlsable Lo always use Lhls as lL reLurns all Lhe varlables you need Lo use
auLomaLlcally. Cnce Lhls ls cllcked, a wlndow appears where CALL lunC1lCn ls Lhe flrsL
opLlon ln a llsL. ln Lhe LexL box, enter spe||_amount, the function modules name, and
cllck Lhe conLlnue buLLon:

A8A code ls Lhen generaLed auLomaLlcally:

269
MODULARIZING PROGRAMS

noLe LhaL a large amounL of Lhe code ls lnlLlally commenLed ouL. 1hls ls because all of Lhe
flelds ln Lhe funcLlon module spe||_amount are opLlonal. MandaLory flelds would noL be
commenLed ouL. 1he commenL characLer should be removed lf LhaL fleld ls Lhen Lo be
used. Pere, only Lhe AMCun1 fleld wlll be lmporLed Lo Lhe funcLlon module.
noLe Lhe poslLlon of Lhe perlod beLween Lhe CALL lunC1lCn sLaLemenL, lLs addlLlons and
Lhe ll sLaLemenL below. lL appears enLlrely on lLs own llne. lL appears Lhere as Lhe sysLem
does noL know how much of Lhe lnlLlally commenLed ouL code ls Lo be used.
1he ll sLaLemenL was also lncluded auLomaLlcally so as Lo follow besL pracLlces expecLlng
Lhe programmer Lo and check wheLher Lhe funcLlon module was execuLed successfully. As
has been dlscussed before, lf sy-subrc does noL equal zero, Lhere ls generally a problem of
some klnd, so a message can be lncluded Lo lndlcaLe Lhls. Pere, dependlng on Lhe prob-
lem, lL wlll be fllled wlLh one of Lhe numbers deflned ln Lhe LxCL1lCnS parL of Lhe func-
Llon module.
Enhance the IF statement to include a code to WRITE a message to the screen to say The
function module returned a value of: , sy-subrc., then add the LLSL addlLlon, so as Lo
wrlLe Lhe correcL resulL ouL when Lhe funcLlon module ls successful. 1hls should Lhen read
WRITE: The amount in words is: Here, a new variable must be set up to hold the value
reLurned from Lhe funcLlon module. Call this resu|t.

270
MODULARIZING PROGRAMS
1he varlable whlch Lhe funcLlon module reLurns ls called IN_WCkDS, so seL up Lhe corre-
spondlng varlable ln Lhe program called resulL. use forward navlgaLlon Lo check Lhe daLa
Lype and lengLh of ln_WC8uS so LhaL resulL can be seL up Lo maLch. When you do Lhls you
wlll see LhaL ln_WC8uS ls deflned uslng Lhe LlkL sLaLemenL Lo refer Lo a sLrucLure called
SLLL.

The same can then be used for the new result variable in the main program. Use a DATA
statement to declare result LIKE the spell structure. As result is defined LIKE a structure
wlLh a mlx of daLa Lypes, lL ls unllkely LhaL Lhe W8l1L sLaLemenL wlll process lL correcLly. lf
you Lry Lo use Lhls a synLax error wlll appear:

8emember LhaL when Lhe funcLlon module was LesLed? WhaL was reLurned was noL ln facL
only a characLer fleld, buL a serles of numbers as well. lf you scroll Lo Lhe far rlghL of Lhe
LesL resulLs screen you would see several more flelds were presenL.
1hls means you need Lo look aL Lhe sLrucLure of SLLL, and flnd Lhe componenL whlch ap-
plles Lo ln_WC8uS:

271
MODULARIZING PROGRAMS

1he componenL ls WCkD, so all you need Lo do ls add WC8u Lo Lhe end of Lhe W8l1L
sLaLemenL for resulL.
1he flnal Lhlng Lo be changed ls Lo feed ln Lhe correcL value whlch Lhe funcLlon module wlll
Lhen lmporL. 1he AMCUN1 fleld ln Lhe code currenLly equals 0. Change Lhls Lo Lhe mynum
varlable used for Lhe selecLlon screen.
1he flnal code should appear llke Lhls and can be LesLed:

272
MODULARIZING PROGRAMS




273
MODULARIZING PROGRAMS
Pavlng compleLed Lhls example, Lhese guldellnes can be followed for pracLlcally any func-
Llon module ln SA and, once you have goL Lo grlps wlLh how funcLlon modules work, lL
should noL be Loo blg a leap Lo Lhen creaLe your own when necessary.


274
MODULARIZING PROGRAMS
?ou have reached Lhe end of Lhls
book but dont stop learning about
SA.

!"#"$ bttp.//www.sopttolol oqbp.com/book-potcbose-tbookyoo $& '"() &*$
+,&*$ $-. #/.0"+1 ,&(*# &''.2 '&2 +11 2.+).2# &' $-. ,&&3 +# 4.11 +# 2.+)
+11 $-. +))"$"&(+1 $2+"("(5 6+$.2"+1 &( $-. 4.,#"$.7

Вам также может понравиться