Sap Abap Quick Guide
Sap Abap Quick Guide
Sap Abap Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm
Copyright tutorialspoint.com
Let's start with the high level architecture of SAP system. The 3-tier
Client/Server architecture of a typical SAP system is depicted as
follows.
The Presentation layer consists of any input device that can be used
to control SAP system. This could be a web browser, a mobile device
and so on. All the central processing takes place in Application
server. The Application server is not just one system in itself, but it
can be multiple instances of the processing system. The server
communicates with the Database layer that is usually kept on a
separate server, mainly for performance reasons and also for security.
Communication happens between each layer of the system, from the
Presentation layer to the Database and then back up the chain.
ABAP programs reside inside the SAP database. They execute under
the control of the runtime system that is a part of the SAP kernel. The
run-time system processes all ABAP statements, controlling the flow
logic and responding to user events.
So, unlike C++ and Java, ABAP programs are not stored in separate
external files. Inside the database, ABAP code exists in two forms
Source code that can be viewed and edited with the ABAP
workbench tools.
Hello ABAP
Let's get started with the common "Hello World" example.
Each ABAP statement starts with an ABAP keyword and ends with a
period. Keywords must be separated by at least one space. It does not
matter whether or not you use one or several lines for an ABAP
statement.
You need to enter your code using the ABAP Editor that is a part of
ABAP Tools delivered with the SAP NetWeaver Application Server
ABAP alsoknownasAS ABAP .
Step 2 On the initial screen of the editor, specify the name of your
report in the input field PROGRAM. You may specify the name as
ZHELLO1. The preceding Z is important for the name. Z ensures that
your report resides in the customer namespace.
The customer namespace includes all objects with the prefix Y or Z. It
is always used when customers or partners create objects likeareport
to differentiate these objects from objects of SAP and to prevent name
conflicts with objects.
Step 3 You may type the report name in lower case letters, but the
editor will change it to upper case. So the names of ABAP objects are
Not case sensitive.
Step 4 After specifying the name of the report, click the CREATE
button. A popup window ABAP: PROGRAM ATTRIBUTES will pop up
and you will provide more information about your report.
You can complete your first report by entering the WRITE statement
below the REPORT statement, so that the complete report contains just
two lines as follows
REPORT ZHELLO1.
WRITE 'Hello World'.
Login Screen
After you log on to SAP server, SAP login screen will prompt for User
ID and Password. You need to provide a valid user ID and Password
and press Enter
theuseridandpasswordisprovidedbysystemadministrator . Following
ABAP Editor
You may just start the transaction SE38 enterS E38inC ommandF ield
to navigate to the ABAP Editor.
Following are the standard exit keys used in SAP as shown in the
image.
Following are the options for checking, activating and processing the
reports.
Log Off
Its always a good practice to Exit from your ABAP Editor or/and logoff
from the SAP system after finishing your work.
SAP ABAP - BASIC SYNTAX
Statements
ABAP source program consists of comments and ABAP statements.
Every statement in ABAP begins with a keyword and ends with a
period, and ABAP is Not case sensitive.
The syntax is
REPORT [Program_Name].
[Statements].
REPORT Z_Test123_01.
On the line below the REPORT statement, just type this statement:
Write ABAP Tutorial.
REPORT Z_Test123_01.
Colon Notation
Consecutive statements can be chained together if the beginning of
each statement is identical. This is done with the colon : operator and
commas, which are used to terminate the individual statements, much
as periods end normal statements.
WRITE 'Hello'.
WRITE 'ABAP'.
WRITE 'World'.
WRITE: 'Hello',
'ABAP',
'World'.
Like any other ABAP statement, the layout doesnt matter. This is an
equally correct statement
Comments
Inline comments may be declared anywhere in a program by one of the
two methods
Suppressing Blanks
The NO-ZERO command follows the DATA statement. It suppresses all
leading zeros of a number field containing blanks. The output is usually
easier for the users to read.
Example
REPORT Z_Test123_01.
50
Example
SKIP number_of_lines.
The output would be several blank lines defined by the number of lines.
The SKIP command can also position the cursor on a desired line on
the page.
Inserting Lines
The ULINE command automatically inserts a horizontal line across the
output. Its also possible to control the position and length of the line.
The syntax is pretty simple
ULINE.
Example
Messages
The MESSAGE command displays messages defined by a message ID
specified in the REPORT statement at the beginning of the program.
The message ID is a 2 character code that defines which set of 1,000
messages the program will access when the MESSAGE command is
used.
The messages are numbered from 000 to 999. Associated with each
number is a message text up to a maximum of 80 characters. When
message number is called, the corresponding text is displayed.
Following are the characters for use with the Message command
Error messages are normally used to stop users from doing things they
are not supposed to do. Warning messages are generally used to
remind the users of the consequences of their actions. Information
messages give the users useful information.
Example
Type Keyword
Byte field X
Text field C
Integer I
Floating point F
Packed number P
Some of the fields and numbers can be modified using one or more
names as the following
byte
numeric
character-like
The following table shows the data type, how much memory it takes to
store the value in memory, and the minimum and maximum value that
could be stored in such type of variables.
C 1 character 1 to 65535
D 8 characters 8 characters
character likedate
T 6 characters 6 characters
character liketime
I 4 bytes -2147483648 to
2147483647
F 8 bytes 2.2250738585072014E-
308 to
1.7976931348623157E+308
positive or negative
wherelen = f ixedlength
Example
REPORT YR_SEP_12.
DATA text_line TYPE C LENGTH 40.
text_line = 'A Chapter on Data Types'.
Write text_line.
The DATE type is used for the storage of date information and can
store eight digits as shown above.
consider only the grouping of elementary types. But you must be aware
of the availability of nesting of structures.
When the elementary types are grouped together, the data item can be
accessed as a grouped data item or the individual elementary type data
items structuref ields can be accessed. The table types are better
known as arrays in other programming languages. Arrays can be
simple or structure arrays. In ABAP, arrays are called internal tables
and they can be declared and operated upon in many ways when
compared to other programming languages. The following table shows
the parameters according to which internal tables are characterized.
2
Key
3
Access method
You must declare all variables before they can be used. The basic form
of a variable declaration is
Here <f> specifies the name of a variable. The name of the variable can
be up to 30 characters long. <type> specifies the type of variable. Any
data type with fully specified technical attributes is known as <type>.
The <val> specifies the initial value of the of <f> variable. In case you
define an elementary fixed-length variable, the DATA statement
automatically populates the value of the variable with the type-specific
initial value. Other possible values for <val> can be a literal, constant,
or an explicit clause, such as Is INITIAL.
Static Variables
Reference Variables
System Variables
Static Variables
Static variables are declared in subroutines, function modules,
and static methods.
You can also declare the internal tables that are linked to input
fields on a selection screen by using SELECT-OPTIONS
statement.
You cannot use special characters such as "t" and "," to name
variables.
The name of the variable cant be the same as any ABAP keyword
or clause.
Reference Variables
The syntax for declaring reference variables is
Example
CLASS C1 DEFINITION.
PUBLIC SECTION.
DATA Bl TYPE I VALUE 1.
ENDCLASS. DATA: Oref TYPE REF TO C1 ,
Dref1 LIKE REF TO Oref,
Dref2 TYPE REF TO I .
CREATE OBJECT Oref.
GET REFERENCE OF Oref INTO Dref1.
CREATE DATA Dref2.
Dref2* = Dref1*Bl.
In the above code snippet, an object reference Oref and two data
reference variables Dref1 and Dref2 are declared.
System Variables
ABAP system variables are accessible from all ABAP programs.
These fields are actually filled by the run-time environment.
The values in these fields indicate the state of the system at any
given point of time.
You can find the complete list of system variables in the SYST
table in SAP.
Example
REPORT Z_Test123_01.
WRITE:/'SY-ABCDE', SY-ABCDE,
/'SY-DATUM', SY-DATUM,
/'SY-DBSYS', SY-DBSYS,
/'SY-HOST ', SY-HOST,
/'SY-LANGU', SY-LANGU,
/'SY-MANDT', SY-MANDT,
/'SY-OPSYS', SY-OPSYS,
/'SY-SAPRL', SY-SAPRL,
/'SY-SYSID', SY-SYSID,
/'SY-TCODE', SY-TCODE,
/'SY-UNAME', SY-UNAME,
/'SY-UZEIT', SY-UZEIT.
SY-ABCDE ABCDEFGHIJKLMNOPQRSTUVWXYZ
SY-DATUM 12.09.2015
SY-DBSYS ORACLE
SY-HOST sapserver
SY-LANGU EN
SY-MANDT 800
SY-OPSYS Windows NT
SY-SAPRL 700
SY-SYSID DMO
SY-TCODE SE38
SY-UNAME SAPUSER
SY-UZEIT 14:25:48
Numeric Literals
Number literals are sequences of digits which can have a prefixed sign.
In number literals, there are no decimal separators and no notation
with mantissa and exponent.
183.
-97.
+326.
Character Literals
Character literals are sequences of alphanumeric characters in the
source code of an ABAP program enclosed in single quotation marks.
Character literals enclosed in quotation marks have the predefined
ABAP type C and are described as text field literals. Literals enclosed in
back quotes have the ABAP type STRING and are described as string
literals. The field length is defined by the number of characters.
Note In text field literals, trailing blanks are ignored, but in string
literals they are taken into account.
REPORT YR_SEP_12.
Write 'Tutorials Point'.
Write / 'ABAP Tutorial'.
REPORT YR_SEP_12.
Write `Tutorials Point `.
Write / `ABAP Tutorial `.
Tutorials Point
ABAP Tutorial
CONSTANTS Statement
We can declare the named data objects with the help of CONSTANTS
statement.
Following is the syntax
REPORT YR_SEP_12.
CONSTANTS PQR TYPE P DECIMALS 4 VALUE '1.2356'.
Write: / 'The value of PQR is:', PQR.
The output is
BEGIN OF EMPLOYEE,
Name(25) TYPE C VALUE 'Management Team',
Organization(40) TYPE C VALUE 'Tutorials Point Ltd',
Place(10) TYPE C VALUE 'India',
END OF EMPLOYEE.
Arithmetic Operators
Comparison Operators
Bitwise Operators
Character String Operators
Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same
way that they are used in algebra. The following list describes
arithmetic operators. Assume integer variable A holds 20 and variable
B holds 40.
2
S ubtraction
3
* M ultiplication
4
/ Division
5
MOD M odulus
REPORT YS_SEP_08.
DATA: A TYPE I VALUE 150,
B TYPE I VALUE 50,
Result TYPE I.
Result = A / B.
WRITE / Result.
Comparison Operators
Lets discuss the various types of comparison operators for different
operands.
1
= equalitytest . Alternate form is EQ.
2
<> I nequalitytest . Alternate form is NE.
4
< Lessthantest. Alternate form is LT.
5
>= Greaterthanorequals Alternate form is GE.
6
<= Lessthanorequalstest. Alternate form is LE.
7
a1 BETWEEN a2 AND a3 I ntervaltest
8
IS INITIAL
9
IS NOT INITIAL
Note If the data type or length of the variables does not match then
automatic conversion is performed. Automatic type adjustment is
performed for either one or both of the values while comparing two
values of different data types. The conversion type is decided by the
data type and the preference order of the data type.
Example 1
REPORT YS_SEP_08.
A is less than B
Example 2
REPORT YS_SEP_08.
DATA: A TYPE I.
IF A IS INITIAL.
WRITE: / 'A is assigned'.
ENDIF.
Bitwise Operators
ABAP also provides a series of bitwise logical operators that can be
used to build Boolean algebraic expressions. The bitwise operators can
be combined in complex expressions using parentheses and so on.
1
BIT-NOT
2
BIT-AND
3
BIT-XOR
For example, following is the truth table that shows the values
generated when applying the Boolean AND, OR, or XOR operators
against the two bit values contained in field A and field B.
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
1
CO C ontainsOnly
Checks whether A is solely composed of the characters in
B.
2
CN N otC ontainsON LY
3
CA C ontainsAN Y
4
NA N OT C ontainsAny
5
CS C ontainsaS tring
6
NS N OT C ontainsaS tring
7
CP C ontainsaP attern
It checks whether A contains the pattern in B.
8
NP N OT C ontainsaP attern
Example
REPORT YS_SEP_08.
DATA: P(10) TYPE C VALUE 'APPLE',
Q(10) TYPE C VALUE 'CHAIR'.
IF P CA Q.
1 WHILE loop
Repeats a statement or group of statements when a given
condition is true. It tests the condition before executing the
loop body.
2 Do loop
3 Nested loop
You may use one or more loops inside any another WHILE
or DO loop.
1 CONTINUE
Causes the loop to skip the remainder of its body and starts
the next loop pass.
2 CHECK
If the condition is false, then the remaining statements
after the CHECK are just ignored and the system starts the
next loop pass.
3 EXIT
1 IF Statement
3 Nested IF Statement
Creating Strings
The following declaration and initialization creates a string consisting
of the word 'Hello'. The size of the string is exactly the number of
characters in the word 'Hello'.
REPORT YT_SEP_15.
DATA my_Char(5) VALUE 'Hello'.
Write my_Char.
Hello
String Length
In order to find the length of character strings, we can use STRLEN
statement. The STRLEN function returns the number of characters
contained in the string.
Example
REPORT YT_SEP_15.
DATA: title_1(10) VALUE 'Tutorials',
length_1 TYPE I.
2
CONDENSE
3
STRLEN
4
REPLACE
5
SEARCH
6
SHIFT
7
SPLIT
Example
REPORT YT_SEP_15.
DATA: title_1(10) VALUE 'Tutorials',
title_2(10) VALUE 'Point',
spaced_title(30) VALUE 'Tutorials Point Limited',
sep,
dest1(30),
dest2(30).
CONDENSE spaced_title.
Write: / 'Condense with Gaps:', spaced_title.
Concatenation: TutorialsPoint
Concatenation with Space: Tutorials Point
Condense with Gaps: Tutorials Point Limited
Condense with No Gaps: TutorialsPointLimited
Note
ABAP provides two built-in types to work with dates and time
D data type
T data type
Both of these types are fixed-length character types that have the form
YYYYMMDD and HHMMSS, respectively.
Timestamps
In addition to these built-in types, the other two types TIMESTAMP
and TIMESTAMPL are being used in many standard application
tables to store a timestamp in the UTC format. Following table shows
the basic date and time types available in ABAP.
1
D
2
T
3
TIMESTAMP T ypeP Length8N odecimals
4
TIMESTAMPL T ypeP Length11Decimals7
REPORT YR_SEP_15.
DATA: date_1 TYPE D.
date_1 = SY-DATUM.
Write: / 'Present Date is:', date_1 DD/MM/YYYY.
The variable date_1 is assigned the value of the current system date SY-
DATUM. Next, we increment the date value by 6. In terms of a date
calculation in ABAP, this implies that were increasing the day
component of the date object by 6 days. The ABAP runtime
environment is smart enough to roll over the date value whenever it
reaches the end of a month.
REPORT YR_SEP_15.
DATA: time_1 TYPE T.
time_1 = SY-UZEIT.
REPORT YR_SEP_12.
DATA: stamp_1 TYPE TIMESTAMP,
In the above example, we are displaying the timestamp using the TIME
ZONE addition of the WRITE statement. This addition formats the
output of the timestamp according to the rules for the time zone
specified. The system field SY-ZONLO is used to display the local time
zone configured in the users preferences.
1
LEFT-JUSTIFIED
2
CENTERED
3
RIGHT-JUSTIFIED
4
UNDER <g>
5
NO-GAP
6
USING EDIT MASK <m>
7
NO-ZERO
1
NO-SIGN
Specifies that no leading sign is displayed on the screen.
2
EXPONENT <e>
3
ROUND <r>
4
CURRENCY <c>
5
UNIT <u>
For instance, the following table shows different formatting options for
the date fields
DD/MM/YY 13/01/15
MM/DD/YY 01/13/15
DD/MM/YYYY 13/01/2015
MM/DD/YYYY 01/13/2015
DDMMYY 130115
MMDDYY 011315
YYMMDD 150113
Here, DD stands for the date in two figures, MM stands for the month
in two figures, YY stands for the year in two figures, and YYYY stands
for the year in four figures.
WRITE: n, m.
WRITE: / n,
/ m UNDER n.
WRITE: / n NO-GAP, m.
DATA time TYPE T VALUE '112538'.
WRITE: / time,
/(8) time Using EDIT MASK '__:__:__'.
Tutorials Point
Tutorials
Point
TutorialsPoint
112538
11:25:38
TRY.
Try Block <Code that raises an exception>
CATCH
Catch Block <exception handler M>
. . .
. . .
. . .
CATCH
Catch Block <exception handler R>
CLEANUP.
Cleanup block <to restore consistent state>
ENDTRY.
Raising Exceptions
Exceptions can be raised at any point in a method, a function module, a
subroutine, and so on. There are two ways an exception can be raised
Catching Exceptions
Handlers are used to catch exceptions.
Attributes of Exceptions
1
Textid
2
Previous
3
get_text
4
get_longtext
5
get_source_position
Example
REPORT ZExceptionsDemo.
PARAMETERS Num_1 TYPE I.
start-of-selection.
Write: / 'Square Root and Division with:', Num_1.
write: /.
TRY.
IF ABS( Num_1 ) > 150.
RAISE EXCEPTION TYPE CX_DEMO_ABS_TOO_LARGE.
ENDIF.
TRY.
res_1 = SQRT( Num_1 ).
Write: / 'Result of square root:', res_1.
res_1 = 1 / Num_1.
Dictionary Tasks
ABAP Dictionary achieves the following
Example
Any complex user-defined type can be built from the 3 basic types in
the Dictionary. Customer data is stored in a structure Customer with
the components Name, Address and Telephone as depicted in the
following image. Name is also a structure with components, First name
and Last name. Both of these components are elementary because their
type is defined by a data element.
Creating Domains
Before you create a new domain, check whether any existing domains
have the same technical specifications required in your table field. If so,
we are supposed to use that existing domain. Lets discuss the
procedure for creating the domain.
Step 2 Select the radio button for Domain in the initial screen of the
ABAP Dictionary, and enter the name of the domain as shown in the
following screenshot. Click the CREATE button. You may create
domains under the customer namespaces, and the name of the object
always starts with Z or Y.
Step 3 Enter the description in the short text field of the
maintenance screen of the domain. In this case, it is Customer
Domain. Note You cannot enter any other attribute until you have
entered this attribute.
Step 4 Enter the Data Type, No. of Characters, and Decimal Places
in the Format block of the Definition tab. Press the key on Output
Length and it proposes and displays the output length. If you overwrite
the proposed output length, you may see a warning while activating the
domain. You may fill in the Convers. Routine, Sign and Lower Case
fields if required. But these are always optional attributes.
Step 6 Save your changes. The Create Object Directory Entry pop-up
appears and asks for a package. You may enter the package name in
which you are working. If you do not have any package then you may
create it in the Object Navigator or you can save your domain using the
Local Object button.
Step 2 Select the radio button for Data type in the initial screen of
the ABAP Dictionary, and enter the name of the data element as shown
below.
Step 3 Click the CREATE button. You may create data elements
under the customer namespaces, and the name of the object always
starts with Z or Y.
Step 4 Check the Data element radio button on the CREATE TYPE
pop-up that appears with three radio buttons.
Step 5 Click the green checkmark icon. You are directed to the
maintenance screen of the data element.
Step 8 Enter the fields for short text, medium text, long text, and
heading in the Field Label tab. You can press Enter and the length is
automatically generated for these labels.
Step 9 Save your changes. The Create Object Directory Entry pop-up
appears and asks for a package. You may enter the package name in
which you are working. If you do not have any package then you may
create it in the Object Navigator or you can save your data element
using the Local Object button.
A table can contain one or more fields, each defined with its data type
and length. The large amount of data stored in a table is distributed
among the several fields defined in the table.
1
Field name
This is the name given to a field that can contain a
maximum of 16 characters. The field name may be
composed of digits, letters, and underscores. It must begin
with a letter.
2
Key flag
3
Field type
4
Field length
5
Decimal places
6
Short text
Step 3 Click the Search Help icon beside the Delivery Class field.
Select A [Application table masterandtransactiondata] option.
Step 5 Select the Fields tab. The screen containing the options
related to the Fields tab appears.
Step 6 Enter the names of table fields in the Field column. A field
name may contain letters, digits, and underscores, but it must always
begin with a letter and must not be longer than 16 characters.
The fields that are to be created must also have data elements because
they take the attributes, such as data type, length, decimal places, and
short text, from the defined data element.
Step 7 Select the Key column if you want the field to be a part of the
table key. Lets create fields such as CLIENT, CUSTOMER, NAME,
TITLE and DOB.
Step 8 The first field is an important one and it identifies the client
which the records are associated with. Enter Client as the Field and
MANDT as the Data Element. The system automatically fills in the
Data Type, Length, Decimals and Short Description. The Client field is
made a key field by checking the Key box.
Step 9 The next field is Customer. Check the box to make it a key
field and enter the new Data Element ZCUSTNUM. Click the Save
button.
Step 12 Click inside the box and select NUMC type from the drop-
down menu. Enter the number 8 in the No. of characters field
amaximumof 8characters and enter 0 in Decimal places area. The
Output length of 8 must be selected and then press Enter. The NUMC
fields description must re-appear, confirming that this is a valid entry.
Step 17 Click Save. Go back to the table and Activate it. The
following screen appears.
A structure may have only a single record at run-time, but a table can
have many records.
Creating a Structure
Step 1 Go to transaction SE11.
Step 2 Click on the Data type option on the screen. Enter the name
'ZSTR_CUSTOMER1' and click on Create button.
Step 3 Select the option 'Structure' in the next screen and press
Enter. You can see 'Maintain / Change Structure' wizard.
Note: Here the component names start with Z as per the SAP
recommendation. Let's use data elements that we have already created
in the database table.
Step 6 You need to Save, Check and Activate after providing all the
components and component types.
Creating a View
Step 1 Select the View radio button on the initial screen of ABAP
Dictionary. Enter the name of the view to be created and then click
Create button. We entered the name of the view as ZVIEW_TEST.
Step 2 Select the projection view radio button while choosing view
type and click Copy button. The Dictionary: Change View screen
appears.
Step 6 After clicking the Copy button, all the selected fields for the
projection view are displayed on the Dictionary: Change View screen.
Step 9 Click the Execute icon. The output of the projection view
appears as shown in the following screenshot.
Step 2 The system will prompt for the search help type to be created.
Select the Elementary search help, which is default. The screen to
create elementary search help as shown in the following screenshot
appears.
Step 4 After the selection method is entered, the next field is the
Dialog type. This controls the appearance of the restrictive dialog box.
There is a drop-down list with three options. Let's select the option
'Display values immediately'.
Step 5 Next is the parameter area. For each Search help parameter
or field, these column fields have to be entered as per the
requirements.
Lock Mechanism
Following are the two main functions accomplished with the lock
mechanism
A program can communicate with other programs about data
records that it is just reading or changing.
A program can prevent itself from reading data that has just
been changed by another program.
Step 3 Enter the short description field and click on Tables tab.
Step 4 Enter the table name in Name field and select the lock mode
as Write Lock.
Step 5 Click on Lock parameter tab, the following screen will appear.
Step 6 Save and activate. Automatically 2 function modules will
generate. To check function modules, we can use Go to Lock
Modules.
Step 7 Click Lock Modules and the following screen will open.
The key fields of a table included in a Lock Object are called lock
arguments and they are used as input parameters in function modules.
These arguments are used to set and remove the locks generated by the
Lock Object definition.
The processing blocks called from outside the program and from
the ABAP run-time environment
i. e. , eventblocksanddialogmodules .
Local Macros
Global Include programs
Modularization through processing blocks called from ABAP programs
Subroutines
Function modules
FORM <subroutine_name>.
<statements>
ENDFORM.
Example
Step 1 Go to transaction SE80. Open the existing program and then
right-click on program. In this case, it is 'ZSUBTEST'.
REPORT ZSUBTEST.
PERFORM Sub_Display.
* Form Sub_Display
* --> p1 text
* <-- p2 text
FORM Sub_Display.
Write: 'This is Subroutine'.
Write: / 'Subroutine created successfully'.
ENDFORM. " Sub_Display
Step 4 Save, activate and execute the program. The above code
produces the following output
Subroutine Test:
This is Subroutine
Example
Go to transaction SE38. Create a new program ZMACRO_TEST along
with the description in the short text field, and also with appropriate
attributes such as Type and Status as shown in the following screenshot
REPORT ZMACRO_TEST.
DEFINE mac_test.
WRITE: 'This is Macro &1'.
END-OF-DEFINITION.
START-OF-SELECTION.
IF s1 = 'X'.
mac_test 1. ENDIF.
IF s2 = 'X'.
mac_test 2.
ENDIF.
IF s3 = 'X'.
mac_test 3.
ENDIF.
A Macro Program
This is Macro 2
If all checkboxes are selected, the code produces the following output
A Macro Program
other objects held in the function group. Let's consider the function
module SPELL_AMOUNT. This function module converts numeric
figures into words.
Step 3 To write the code for this, use CTRL+F6. After this, a window
appears where CALL FUNCTION is the first option in a list. Enter
'spell_amount' in the text box and click the continue button.
REPORT Z_SPELLAMOUNT.
data result like SPELL.
IF SY-SUBRC <> 0.
Write: 'Value returned is:', SY-SUBRC.
else.
Write: 'Amount in words is:', result-word.
ENDIF.
INCLUDE <program_name>.
INCLUDE statement has the same effect as copying the source code of
the include program <program_name> into another program. As
include program cant run independently, it has to be built into other
programs. You may also nest include programs.
Following are a couple of restrictions while writing the code for Include
programs
PROGRAM Z_TOBEINCLUDED.
Write: / 'This program is started by:', SY-UNAME,
/ 'The Date is:', SY-DATUM,
/ 'Time is', SY-UZEIT.
Step 2 Set the Type of the program to INCLUDE program, as shown
in the following screenshot.
Step 3 Click the Save button and save the program in a package
named ZINCL_PCKG.
REPORT Z_INCLUDINGTEST.
INCLUDE Z_TOBEINCLUDED.
The DATA statement is used to declare a work area. Let's give this the
name 'wa_customers1'. Rather than declaring one data type for this,
several fields that make up the table can be declared. The easiest way to
do this is using the LIKE statement.
INSERT Statement
The wa_customers1 work area is declared here LIKE the
ZCUSTOMERS1 table, taking on the same structure without becoming
a table itself. This work area can only store one record. Once it has
been declared, the INSERT statement can be used to insert the work
area and the record it holds into the table. The code here will read as
'INSERT ZCUSTOMERS1 FROM wa_customers1'.
The work area has to be filled with some data. Use the field names from
the ZCUSTOMERS1 table. This can be done by forward navigation,
double clicking the table name in the code or by opening a new session
and using the transaction SE11. The fields of the table can then be
copied and pasted into the ABAP editor.
IF SY-SUBRC = 0.
WRITE 'Record Inserted Successfully'.
ELSE.
WRITE: 'The return code is ', SY-SUBRC.
ENDIF.
Check the program, save, activate the code, and then test it. The output
window should display as 'Record Inserted Successfully'.
CLEAR Statement
CLEAR statement allows a field or variable to be cleared out for the
insertion of new data in its place, allowing it to be reused. CLEAR
statement is generally used in programs and it allows existing fields to
be used many times.
In the previous code snippet, the work area structure has been filled
with data to create a new record to be inserted into the ZCUSTOMERS1
table and then a validation check is performed. If we want to insert a
new record, CLEAR statement must be used so that it can then be filled
again with the new data.
UPDATE Statement
If you want to update one or more existing records in a table at the
same time then use UPDATE statement. Similar to INSERT statement,
a work area is declared, filled with the new data that is then put into
the record as the program is executed. The record previously created
with the INSERT statement will be updated here. Just edit the text
stored in the NAME and TITLE fields. Then on a new line, the same
structure as for the INSERT statement is used, and this time by using
the UPDATE statement as shown in the following code snippet
As UPDATE statement gets executed, you can view the Data Browser in
the ABAP Dictionary to see that the record has been updated
successfully.
MODIFY Statement
MODIFY statement can be considered as a combination of the INSERT
and UPDATE statements. It can be used to either insert a new record
or modify an existing record. It follows a similar syntax to the previous
two statements in modifying the record from the data entered into a
work area.
CLEAR wa_customers1.
When this is executed and the data is viewed in the Data Browser, a
new record will have been created for the customer number 100007
RALP H .
All SQL statements that are valid for the program interface of
the addressed database system can be listed between EXEC and
ENDEXEC, in particular the DDL datadef initionlanguage
statements.
These SQL statements are passed from the Native SQL interface
to the database system largely unchanged. The syntax rules are
specified by the database system, especially the case sensitivity
rules for database objects.
Example
SPFLI is a standard SAP Table that is used to store Flight schedule
information. This is available within R/3 SAP systems depending on
the version and release level. You can view this information when you
enter the Table name SPFLI into the relevant SAP transaction such as
SE11 or SE80. You can also view the data contained in this database
table by using these two transactions.
REPORT ZDEMONATIVE_SQL.
DATA: BEGIN OF wa,
connid TYPE SPFLI-connid,
cityfrom TYPE SPFLI-cityfrom,
cityto TYPE SPFLI-cityto,
END OF wa.
FORM loop_output.
WRITE: / wa-connid, wa-cityfrom, wa-cityto.
ENDFORM.
Internal tables only exist when a program is running, so when the code
is written, the internal table must be structured in such a way that the
program can make use of it. You will find that internal tables operate in
the same way as structures. The main difference being that structures
only have one line, while an internal table can have as many lines as
required.
They are hugely versatile. They can be defined using any number
of other defined structures.
Example
Assume that a user wants to create a list of contact numbers of various
customers from one or several large tables. The user first creates an
internal table, selects the relevant data from customer tables and then
places the data in the internal table. Other users can access and use this
internal table directly to retrieve the desired information, instead of
writing database queries to perform each operation during the run-
time of the program.
Lets create the fields on a new line. For instance, create name which
is declared as LIKE ZCUSTOMERS1-name. Create another field called
dob, LIKE ZCUSTOMERS1-dob. It is useful initially to give the field
names in internal tables the same names as other fields that have been
created elsewhere. Finally, declare the end of the internal table with
END OF <internal_tab>. as shown in the following code
DATA: BEGIN OF itab01 Occurs 0,
name LIKE ZCUSTOMERS1-name,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
Example
Step 1 Open the ABAP Editor by executing the SE38 transaction
code. The initial screen of ABAP Editor appears.
Step 2 In the initial screen, enter a name for the program, select the
Source code radio button and click the Create button to create a new
program.
REPORT ZINTERNAL_DEMO.
TYPES: BEGIN OF CustomerLine,
Cust_ID TYPE C,
Cust_Name(20) TYPE C,
END OF CustomerLine.
INSERT Statement
INSERT statement is used to insert a single line or a group of lines into
an internal table.
Example
REPORT ZCUSLIST1.
DATA: BEGIN OF itable1 OCCURS 4,
F1 LIKE SY-INDEX,
END OF itable1.
DO 4 TIMES.
itable1-F1 = sy-index.
APPEND itable1.
ENDDO.
itable1-F1 = -96.
INSERT itable1 INDEX 2.
LOOP AT itable1.
Write / itable1-F1.
ENDLOOP.
Skip.
LOOP AT itable1.
Write / itable1-F1.
ENDLOOP.
The above code produces the following outp
1
96-
2
3
4
1
96-
2
78-
3
78-
4
After each insert statement is executed, the system re-indexes all rows
below the one inserted. This introduces overhead when you insert rows
near the top of a large internal table. If you need to insert a block of
rows into a large internal table, prepare another table with the rows to
be inserted and use insert lines instead.
APPEND Statement
The APPEND statement is used to add a single row or line to an
existing internal table. This statement copies a single line from a work
area and inserts it after the last existing line in an internal table. The
work area can be either a header line or any other field string with the
same structure as a line of an internal table. Following is the syntax of
the APPEND statement that is used to append a single line in an
internal table
Example
REPORT ZCUSLIST1.
DATA: BEGIN OF linv Occurs 0,
Name(20) TYPE C,
ID_Number TYPE I,
END OF linv.
Melissa 105467
To copy the records, we can use a SELECT statement to select all of the
records from the table and then use MOVE statement that will move
the records from the original table into the new internal table into the
fields where the names correspond.
Example
REPORT ZCUSLIST1.
TABLES: ZCUSTOMERS1.
DATA: BEGIN OF itab01 Occurs 0,
name LIKE ZCUSTOMERS1-name,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
MARGARET 02.11.1994
The select loop fills each field one at a time, using the MOVE statement
to move the data from one tables field to the other. In the above
example, MOVE statements were used to move the contents of the
ZCUSTOMERS1 table to the corresponding fields in the internal table.
You can accomplish this action with just one line of code. You can use
the MOVECORRESPONDING statement.
It tells the system to move the data from the fields of ZCUSTOMERS1
to their corresponding fields in itab01.
Example
REPORT ZCUSTOMERLIST.
TABLES: ZCUSTOMERS1.
DATA: Begin of itab01 occurs 0,
customer LIKE ZCUSTOMERS1-customer,
name LIKE ZCUSTOMERS1-name,
title LIKE ZCUSTOMERS1-title,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
MARK 21.05.1981
JAMES 14.08.1977
AURIELE 19.06.1990
STEPHEN 22.07.1985
MARGARET 02.11.1994
This is made possible by the fact that both have matching field names.
When making use of this statement, you need to make sure that both
fields have matching data types and lengths. It has been done here with
the LIKE statement previously.
Here the entire line of the internal table is used as a search key. The
content of the entire line of the table is compared with the content of
the <internal_tab_field> field. If the values of the
<internal_tab_field> field are not compatible with the line type of the
table, these values are converted according to the line type of the table.
The search key allows you to find entries in internal tables that do not
have a structured line type, that is, where the line is a single field or an
internal table type.
When the COMPARING clause is used, the specified table fields <F1>,
<F2>....<Fn> of the structured line type are compared with the
corresponding fields of the work area before being transported. If the
ALL FIELDS clause is specified, the SAP system compares all the
components. When the SAP system finds an entry on the basis of a key,
the value of the SY-SUBRC variable is set to 0. In addition, the value of
the SY-SUBRC variable is set to 2 or 4 if the content of the compared
fields is not the same or if the SAP system cannot find an entry.
However, the SAP system copies the entry into the target work area
whenever it finds an entry, regardless of the result of the comparison.
Example
REPORT ZREAD_DEMO.
*/Creating an internal table
DATA: BEGIN OF Record1,
ColP TYPE I,
ColQ TYPE I,
END OF Record1.
Record1-ColP = 4.
Record1-ColQ = 12.
READ TABLE mytable FROM Record1 INTO Record1 COMPARING ColQ.
SY-SUBRC = 2
4 9
The Record1 work area is populated with 4 and 12 as values for the
ColP and ColQ fields respectively. The READ statement reads the line
of the table after comparing the value of the ColP key field with the
value in the Record1 work area by using the COMPARING clause, and
then copies the content of the read line in the work area. The value of
the SY-SUBRC variable is displayed as 2 because when the value in the
ColP field is 4, the value in the ColQ is not 12, but 9.
You may also specify a table key explicitly in the DELETE TABLE
statement by using the following syntax
Example
REPORT ZDELETE_DEMO.
DATA: BEGIN OF Line1,
ColP TYPE I,
ColQ TYPE I,
END OF Line1.
DATA mytable LIKE HASHED TABLE OF Line1
WITH UNIQUE KEY ColP.
DO 8 TIMES.
Line1-ColP = SY-INDEX.
Line1-ColQ = SY-INDEX + 4.
INSERT Line1 INTO TABLE mytable.
ENDDO.
Line1-ColP = 1.
DELETE TABLE mytable: FROM Line1,
WITH TABLE KEY ColP = 3.
LOOP AT mytable INTO Line1.
2 6
4 8
5 9
6 10
7 11
8 12
In this example, mytable has two fields, ColP and ColQ. Initially,
mytable is populated with eight lines, where the ColP contains the
values 1, 2, 3, 4, 5, 6, 7 and 8. The ColQ contains the values 5, 6, 7, 8, 9,
10, 11 and 12 because the ColP values are incremented by 4 every time.
The DELETE statement is used to delete the lines from mytable where
the value of the ColP key field is either 1 or 3. After deletion, the ColP
field of mytable contains the values 2, 4, 5, 6, 7 and 8, as shown in the
output. The ColQ field contains the values 6, 8, 9, 10, 11 and 12.
Has a state.
Has a unique identity.
May or may not display the behavior.
The state of an object can be described as a set of attributes and their
values. For example, a bank account has a set of attributes such as
Account Number, Name, Account Type, Balance, and values of all these
attributes. The behavior of an object refers to the changes that occur in
its attributes over a period of time.
Creating an Object
The object creation usually includes the following steps
Example
REPORT ZDEMO_OBJECT.
CLASS Class1 Definition.
Public Section.
DATA: text1(45) VALUE 'ABAP Objects.'.
METHODS: Display1.
ENDCLASS.
START-OF-SELECTION.
DATA: Class1 TYPE REF TO Class1.
CREATE Object: Class1.
Write:/ Class1->text1.
CALL METHOD: Class1->Display1.
ABAP Objects.
This is the Display method.
A class definition starts with the keyword CLASS followed by the class
name, DEFINITION and the class body. The definition of a class can
contain various components of the class such as attributes, methods,
and events. When we declare a method in the class declaration, the
method implementation must be included in the class implementation.
The following syntax shows how to implement a class
Attributes
Attributes are data fields of a class that can have any data type such as
C, I, F, and N. They are declared in the class declaration. These
attributes can be divided into 2 categories: instance and static
attributes. An instance attribute defines the instance specific state of
an object. The states are different for different objects. An instance
attribute is declared by using the DATA statement.
Static attributes define a common state of a class that is shared by all
the instances of the class. That is, if you change a static attribute in one
object of a class, the change is visible to all other objects of the class as
well. A static attribute is declared by using the CLASS-DATA
statement.
Methods
A method is a function or procedure that represents the behavior of an
object in the class. The methods of the class can access any attribute of
the class. The definition of a method can also contain parameters, so
that you can supply the values to these parameters when methods are
called. The definition of a method is declared in the class declaration
and implemented in the implementation part of a class. The METHOD
and ENDMETHOD statements are used to define the implementation
part of a method. The following syntax shows how to implement a
method
METHOD <m_name>.
..........
..........
ENDMETHOD.
Example
Report ZAccess1.
CLASS class1 Definition.
PUBLIC Section.
Data: text1 Type char25 Value 'Public Data'.
Methods meth1.
PROTECTED Section.
Data: text2 Type char25 Value 'Protected Data'.
PRIVATE Section.
Data: text3 Type char25 Value 'Private Data'.
ENDCLASS.
Start-Of-Selection.
Data: Objectx Type Ref To class1.
Create Object: Objectx.
CALL Method: Objectxmeth1.
Write: / Objectxtext1.
Public Method:
Public Data
Protected Data
Private Data
Public Data
Static Attributes
A Static attribute is declared with the statement CLASS-DATA. All the
objects or instances can use the static attribute of the class. Static
attributes are accessed directly with the help of class name like
class_namename_1 = 'Some Text'.
Example
Report ZStatic1.
CLASS class1 Definition.
PUBLIC Section.
CLASS-DATA: name1 Type char45,
data1 Type I.
Methods: meth1.
ENDCLASS.
Start-Of-Selection.
class1name1 = 'ABAP Object Oriented Programming'.
class1data1 = 0.
Data: Object1 Type Ref To class1,
Object2 Type Ref To class1.
Example
Report ZConstructor1.
CLASS class1 Definition.
PUBLIC Section.
Methods: method1, constructor.
ENDCLASS.
Method constructor.
Write: / 'Constructor Triggered'.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data Object1 Type Ref To class1.
Create Object Object1.
Constructor Triggered
ME Operator in Methods
When you declare a variable of any type in public section of a class, you
can use it in any other implementation. A variable can be declared with
an initial value in public section. We may declare the variable again
inside a method with a different value. When we write the variable
inside the method, the system will print the changed value. To reflect
the previous value of the variable, we have to use ME operator.
Report ZMEOperator1.
CLASS class1 Definition.
PUBLIC Section.
Start-Of-Selection.
Data objectx Type Ref To class1.
Create Object objectx.
CALL Method objectxmethod1.
Example
Report ZINHERITAN_1.
CLASS Parent Definition.
PUBLIC Section.
Data: w_public(25) Value 'This is public data'.
Methods: ParentM.
ENDCLASS.
Start-of-selection.
Data: Parent Type Ref To Parent,
Child Type Ref To Child.
Create Object: Parent, Child.
Call Method: ParentParentM,
childChildM.
Example
Report Zinheri_Redefine.
CLASS super_class Definition.
Public Section.
Methods: Addition1 importing g_a TYPE I
g_b TYPE I
exporting g_c TYPE I.
ENDCLASS.
Start-Of-Selection.
Parameters: P_a Type I, P_b TYPE I.
Data: H_Addition1 TYPE I.
Data: H_Sub TYPE I.
Data: Ref1 TYPE Ref TO sub_class.
Create Object Ref1.
Call Method Ref1Addition1 exporting g_a = P_a
g_b = P_b
Importing g_c = H_Addition1.
Write:/ H_Addition1.
After executing F8, if we enter the values 9 and 10, the above code
produces the following output
Redefinition Demo
29
Example
Report ZPolymorphism1.
CLASS class_prgm Definition Abstract.
PUBLIC Section.
Methods: prgm_type Abstract,
approach1 Abstract.
ENDCLASS.
EndMethod. ENDCLASS.
CLASS class_OO Definition
Inheriting From class_prgm.
PUBLIC Section.
Methods: prgm_type Redefinition,
approach1 Redefinition.
ENDCLASS.
CLASS class_OO Implementation.
Method prgm_type.
Write: 'Object oriented programming'.
EndMethod.
Method approach1.
Write: 'bottom-up approach'.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data: class_1 Type Ref To class_procedural,
class_2 Type Ref To class_OO.
class1_prgm = class_1.
New-Line.
CALL Method class_type_approachstart
Exporting
Exporting
class1_prgm = class_2.
Encapsulation by Interface
Encapsulation actually means one attribute and method could be
modified in different classes. Hence data and method can have
different form and logic that can be hidden to separate class.
Example
Report ZEncap1.
Interface inter_1.
Data text1 Type char35.
Methods method1.
EndInterface.
Start-Of-Selection.
Data: Object1 Type Ref To Class1,
Object2 Type Ref To Class2.
Designing Strategy
Most of us have learned through bitter experience to make class
members private by default unless we really need to expose them. That
is just good encapsulation. This wisdom is applied most frequently to
data members and it also applies equally to all members.
Interfaces are used when two similar classes have a method with the
same name, but the functionalities are different from each other.
Interfaces might appear similar to classes, but the functions defined in
an interface are implemented in a class to extend the scope of that
class. Interfaces along with the inheritance feature provide a base for
polymorphism. This is because a method defined in an interface can
behave differently in different classes.
INTERFACE <intf_name>.
DATA.....
CLASS-DATA.....
METHODS.....
CLASS-METHODS.....
ENDINTERFACE.
In this syntax, <intf_name> represents the name of an interface. The
DATA and CLASSDATA statements can be used to define the instance
and static attributes of the interface respectively. The METHODS and
CLASS-METHODS statements can be used to define the instance and
static methods of the interface respectively. As the definition of an
interface does not include the implementation class, it is not necessary
to add the DEFINITION clause in the declaration of an interface.
Note All the methods of an interface are abstract. They are fully
declared including their parameter interface, but not implemented in
the interface. All the classes that want to use an interface must
implement all the methods of the interface. Otherwise, the class
becomes an abstract class.
INTERFACE <intf_name>.
METHOD <intf_name~method_m>.
<statements>.
ENDMETHOD.
Example
Report ZINTERFACE1.
INTERFACE my_interface1.
Methods msg.
ENDINTERFACE.
Method add_number.
ADD 7 TO num.
EndMethod.
ENDCLASS.
Method speed1.
Add 4 To wheel1.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data object1 Type Ref To num_counter.
Data object1 Type Ref To num_counter.
Create Object object1.
The number is 7
Total number of wheels is 4
Example
REPORT ZEVENT1.
CLASS CL_main DEFINITION.
PUBLIC SECTION.
DATA: num1 TYPE I.
METHODS: PRO IMPORTING num2 TYPE I.
EVENTS: CUTOFF.
ENDCLASS.
START-OF-SELECTION.
DATA: main1 TYPE REF TO CL_main.
DATA: eventhandler1 TYPE REF TO CL_eventhandler.
1
INITIALIZATON
2
AT SELECTION-SCREEN
3
START-OF-SELECTION
4
END-OF-SELECTION
5
TOP-OF-PAGE
6
END-OF-PAGE
Example
Let's create a classical report. We will display the information stored in
the standard database MARA containsgeneralmaterialdata by using a
sequence of statements in ABAP editor.
REPORT ZREPORT2
LINE-SIZE 75
LINE-COUNT 30(3)
NO STANDARD PAGE HEADING.
Tables: MARA.
TYPES: Begin of itab,
End of itab.
APPEND MATS.
AT SELECTION-SCREEN. .
IF MATS-LOW = ' '.
MESSAGE I000(ZKMESSAGE).
ELSEIF MATS-HIGH = ' '.
MESSAGE I001(ZKMESSAGE).
ENDIF.
TOP-OF-PAGE.
WRITE:/ 'CLASSICAL REPORT CONTAINING GENERAL MATERIAL DATA
FROM THE TABLE MARA' COLOR 7.
ULINE.
WRITE:/ 'MATERIAL' COLOR 1,
24 'INDUSTRY' COLOR 2,
38 'UNITS' COLOR 3,
53 'MATERIAL TYPE' COLOR 4.
ULINE.
END-OF-PAGE.
START-OF-SELECTION.
SELECT MATNR MBRSH MEINS MTART FROM MARA
INTO TABLE it_ma WHERE MATNR IN MATS.
LOOP AT it_ma into wa_ma.
WRITE:/ wa_ma-MATNR,
25 wa_ma-MBRSH,
40 wa_ma-MEINS,
55 wa_ma-MTART.
ENDLOOP.
END-OF-SELECTION.
ULINE.
WRITE:/ 'CLASSICAL REPORT HAS BEEN CREATED' COLOR 7.
ULINE.
SKIP.
The above code produces the following output containing the general
material data from the standard table MARA
SAP ABAP - DIALOG PROGRAMMING
Dialog programming deals with the development of multiple objects.
All these objects are linked hierarchically to the main program and they
are executed in a sequence. Dialog program development makes use of
tools in the ABAP workbench. These are the same tools used in
standard SAP application development.
Screens
Module pools
Subroutines
Menus
Transactions
The Toolset
Screens are made up of screen attributes, screen layout, fields and flow
logic. The module pool consists of modularized syntax that is placed
inside include programs of the dialog program. These modules can be
invoked by the flow logic, which is processed by the dialog processor.
Step 2 Press Enter, choose With TOP INCL and click the Yes
button.
Step 3 Enter a name for your top include as ZSCRTOP and click the
green tick mark.
Step 4 Within the attributes screen, simply enter a title and click the
save button.
Step 2 Enter a screen number as '0211' and click the green tick mark.
Step 3 In the next screen, enter a short title, set to normal screen
type and click the save button on the top application toolbar.
Step 2 Add a Text Field and enter some text such as "Hello World".
Step 3 Save and activate the screen.
Creating Transaction
Step 1 To create a transaction code for your program, simply right
click on the program name and choose the option Create
Transaction and enter a transaction code as 'ZTRANEX'.
Step 2 Enter the transaction text, program and screen you have just
created ZSCREENEX & 0211 , and tick the SAPGUI for Windows
checkbox in the GUI support section.
The tool allows you to modify forms by using simple graphical tools
instead of using any programming tool. It means that a user with no
programming knowledge can configure these forms with data for a
business process effortlessly.
In a Smart Form, data is retrieved from static and dynamic tables. The
table heading and subtotal are specified by the triggered events and the
data is then sorted before the final output. A Smart Form allows you to
incorporate graphics that can be displayed either as part of the form or
as the background. You can also suppress a background graphic if
required while taking a printout of a form.
Some examples of standard Smart Forms available in SAP system are
as follows
Creating a Form
Lets create a form by using the SAP Smart Forms tool. You will also
learn how to add a node in the Smart Form and test the form in this
tutorial. Here we begin with creating a copy of the SF_EXAMPLE_01
form. The SF_EXAMPLE_01 form is a standard Smart Form available
in the SAP system.
Step 2 Select Smart Forms Copy or click the Copy icon to open
the Copy Form or Text dialog box.
Step 3 In the Target Object field, enter a name for the new form. The
name must begin with the Y or Z letter. In this case, the name of the
form is 'ZSMM1'.
Step 4 Click the Continue icon or press the ENTER key in the Copy
Form or Text dialog box so that the ZSMM1 form is created as a copy of
the predefined form SF_EXAMPLE_01.
Step 5 Click the Save icon. The name of the form is displayed in the
Form field on the initial screen of SAP Smart Forms.
Step 6 Click the Create button on the initial screen of SAP Smart
Forms. The ZSMM1 form appears in Form Builder.
Step 7 The first draft page is created with a MAIN window. All the
components of the new form are based on the SF_EXAMPLE_01
predefined form. You can just click a node in the Navigation menu to
view its content.
Step 2 Modify the text in the Text field to 'My_Text' and the text in
the Meaning field to 'Text_Demo'. Enter the text 'Hello
TutorialsPoint.....' in the text-editing box in the center frame of Form
Builder as shown in the following snapshot
Step 5 Activate and test the function module by clicking the Activate
and Execute icons. The parameters of the function module are
displayed in the initial screen of Function Builder.
Step 7 Specify the output device as 'LP01' and click the Print preview
button.
The SAP system comes with standard SAPscript forms that are
delivered with the SAP standard client generallyasclient000 . Following
are a few examples of standard SAPscript forms delivered with client
000
1
RVORDER01
2
RVDELNOTE
Packing List
3
RVINVOICE01
Invoice
4
MEDRUCK
Purchase Order
5
F110_PRENUM_CHCK
Prenumbered Check
Step 1 Open the Form Painter. You may request the screen either by
navigating the SAP menu or by using the SE71 transaction code.
Step 5 In the 'Copy Forms Between Clients' screen, enter the original
name of the form, 'RVINVOICE01', in the Form Name field, the
number of the source client '000' in the Source Client field, and the
name of the target form as 'ZINV_01' in the Target Form field. Make
sure that other settings remain unchanged.
Step 6 Next, click the Execute icon in the 'Copy Forms Between
Clients' screen. The 'Create Object Directory Entry' dialog box appears.
Click the Save icon.
Step 8 After clicking the Display button, the 'Form ZINV_01: Layout
of Page FIRST' window and the 'Form: Change Page Layout: ZINV_01'
screen appears as shown in the following screenshot.
Step 9 The 'Form ZINV_01: Layout of Page FIRST' window shows
the initial layout of the form. The layout of the form contains five
windows: HEADER, ADDRESS, INFO, INFO1, and MAIN. The
description of these windows can be accessed in PC Editor.
For instance, by just selecting the MAIN window and clicking the Text
icon in the 'Form: Change Page Layout: ZINV_01' screen, you can view
all the margin values as shown in the following screenshot
Step 2 Get the program name from the popup screen. The program
name is 'SAPLMGMM'.
The above steps produce the following output with the list of exits
available in the Material Master Creation.
1
USEREXIT_FIELD_MODIFICATION
2
USEREXIT_SAVE_DOCUMENT
3
USEREXIT_SAVE_DOCUMENT_PREPARE
Very useful to check input fields, put any value in the field
or show a popup to users and to confirm the document.
4
USEREXIT_MOVE_FIELD_TO_VBAK
5
USEREXIT_MOVE_FIELD_TO_VBAP
Used when user item changes are moved to SAP item work
area.
A User Exit serves the same purpose as Customer Exits but they are
available only for the SD module. The exit is implemented as a call to a
Function Module. User Exits are modifications to SAP standard
programs.
Example
REPORT ZUSEREXIT1.
TABLES:
TSTC, TSTCT,
TADIR, TRDIR, TFDIR, ENLFDIR,
MODSAPT, MODACT.
DATA:
JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE,
field1(30),
v_devclass LIKE TADIR-devclass.
PARAMETERS:
P_TCODE LIKE TSTC-tcode OBLIGATORY.
SELECT SINGLE *
FROM TSTC
WHERE tcode EQ P_TCODE.
IF SY-SUBRC EQ 0.
SELECT SINGLE *
FROM TADIR
IF SY-SUBRC NE 0.
SELECT SINGLE *
FROM TRDIR
WHERE name = TSTC-pgmna.
IF TRDIR-subc EQ 'F'.
SELECT SINGLE *
FROM TFDIR
WHERE pname = TSTC-pgmna.
SELECT SINGLE *
FROM ENLFDIR
WHERE funcname = TFDIR-funcname.
SELECT SINGLE *
FROM TADIR
WHERE pgmid = 'R3TR' AND
object = 'FUGR' AND
obj_name EQ ENLFDIR-area.
MOVE TADIR-devclass TO v_devclass.
ENDIF.
ENDIF.
ENDIF.
SELECT *
FROM TADIR
INTO TABLE JTAB
SELECT SINGLE *
FROM TSTCT
WHERE sprsl EQ SY-LANGU AND
tcode EQ P_TCODE.
WRITE:/1 SY-VLINE,
2 'Exit Name',
21 SY-VLINE ,
22 'Description',
95 SY-VLINE.
WRITE:/(95) SY-ULINE.
LOOP AT JTAB.
SELECT SINGLE * FROM MODSAPT
WHERE sprsl = SY-LANGU AND
name = JTAB-obj_name.
WRITE:/(95) SY-ULINE.
DESCRIBE TABLE JTAB.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , SY-TFILL.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'User Exit doesnt exist'.
ENDIF.
ELSE.
AT LINE-SELECTION.
GET CURSOR FIELD field1.
CHECK field1(4) EQ 'JTAB'.
SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
You can also create filter BADIs, which means BADIs are defined on
the basis of filtered data that is not possible with enhancement
techniques. The concept of BADIs has been redefined in SAP Release
7.0 with the following goals
The model defines an interface to the main system and the Web
Dynpro application can have an access to system data.
The view is responsible for showing the data in the web browser.
The controller resides between the view and the model. The
controller formats the model data to be displayed in the view. It
processes the user entries made by the user and returns them to
the model.
Advantages
Note
The component view displays all the administrative details for
the application including the description, the name of the person
who created it, the creation date, and the assigned development
package.