You are on page 1of 28

GUIDE

TO SAP ABAP

AN INTRODUCTION TO P ROGRAMMING SAP


APPLICATIONS USING ABAP

PETER M OXON

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.
____________________________________________
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

First look at the ABAP Workbench 22


First Look 23

Chapter 2: Data Dictionary 29


Introduction 29
Creating a Table 29

Technical Settings 45
Entering Records into a Table 48

iv
Viewing the Data in a Table 51
Chapter 3 55
Creating a Program 55
Code Editor 57
Write Statements 62

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

Chapter 5 Character Strings 85


Declaring C and N Fields 85

String Manipulation 87
Concatenate 87

v
Condense 88

Find the Length of a String 89


Replace 90
Search 90

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

vi
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

vii
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

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

viii
Comments 218
Format a Line and Position 219
Element Blocks 221
Chapter 12 Internal Tables 223
Introduction 223
Types of Internal Tables 224

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

ix
Delete a Table with a Header Line 243

Delete a Table with a Work Area 244


Chapter 13 Modularizing Programs 245
Introduction 245
Includes 246
Procedures 249
Sub-Routines 250

Sub-Routines - External Programs 256


Function Modules 257
Function Modules Components 258

Function Module Testing 264


Function Modules - Coding 267

x
xi
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.

12
INTRODUCTION

13
INTRODUCTION

14
SAP SYSTEM OVERVIEW

15
SAP SYSTEM OVERVIEW

16
SAP SYSTEM OVERVIEW

17
SAP SYSTEM OVERVIEW

18
SAP SYSTEM OVERVIEW

19
SAP SYSTEM OVERVIEW

20
SAP SYSTEM OVERVIEW

21
SAP SYSTEM OVERVIEW

22
SAP SYSTEM OVERVIEW

23
SAP SYSTEM OVERVIEW

24
SAP SYSTEM OVERVIEW

25
SAP SYSTEM OVERVIEW

26
SAP SYSTEM OVERVIEW

27
SAP SYSTEM OVERVIEW

28

You might also like