Escolar Documentos
Profissional Documentos
Cultura Documentos
Reports
Basic Functions of the ABAP Editor
Standard toolbar
Find and
Repeat Find
Syntax
SyntaxCheck
Check Execution (F8)
(Ctrl+F2) ABAP help (F1)
.
(Ctrl+F3)
(Ctrl+F1)
DATA Definitions
• DATA Statement
DATA <Name> TYPE or LIKE VALUE DECIMALS
- All variables used within the ABAP/4 program must be declared with DATA
statements
- <Name> up to 30 characters in length, containing any characters other than
(, ), +, ., :
- <TYPE> Indicates the variable type
Example:
DATA: p_bukrs LIKE bkpf-bukrs.
DATA i_val TYPE i VALUE 99.
DATA Definitions
• TYPES Statement
TYPES <name> TYPE or LIKE DECIMALS
SAP allows the creation of new user defined data types. And this does not
create a variable, BUT just a new type that can be used in creating a variable.
Example :
TYPES : cc LIKE bkpf-bukrs
DATA : c_cc TYPE cc.
TYPES
Example
• SELECT-OPTIONS allows specification of multiple values and ranges. This can only
be declared for fields within tables defined in the TABLES statement.
Example
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr.
Specifying Blank Lines
• To produce blank lines, the SKIP option is used.
Syntax
– SELECTION-SCREEN SKIP [<n>].
• To underline a line or part of a line, the ULINE option is
used.
Syntax
– SELECTION-SCREEN ULINE [[/]<pos(len)>]
• To write text on the selection screen, the COMMENT option
is used
Syntax
– SELECTION-SCREEN COMMENT [/]<pos(len)> <comm>
[FOR FIELD <f>]
Elements on a Single Line
• To position a set of parameters or comments on a single line on the selection
screen, the elements are declared in a block enclosed by the following two
statements:
SELECTION-SCREEN BEGIN OF LINE.
…
SELECTION-SCREEN END OF LINE.
Example
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-001. “ Text Symbol for Title
PARAMETERS: p1(3), p2(5), p3(1).
SELECTION-SCREEN END OF LINE.
Positioning in the Selection Screen
• To position the next parameter or comment on the selection screen, the
POSITION option is used.
• Syntax
– SELECTION-SCREEN POSITION <pos>.
• For <pos>, you can specify a number, POS_LOW, or POS_HIGH.
• To create a logical block of elements on the selection screen, mark the
beginning of the block with the BEGIN OF BLOCK option of the SELECTION-
SCREEN statement, then define the individual elements and mark the end of
the block with the END OF BLOCK option as shown below:
– SELECTION-SCREEN BEGIN OF BLOCK <block>
[WITH FRAME [TITLE <title>]]
[NO INTERVALS].
…
SELECTION-SCREEN END OF BLOCK <block>.
• Blocks can be nested.
Blocking Selection Screen
• Example
– SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-002.
PARAMETERS vendor RADIOBUTTON GROUP gr1.
PARAMETERS customer RADIOBUTTON GROUP gr1.
PARAMETERS material RADIOBUTTON GROUP gr1.
SELECTION-SCREEN END OF BLOCK rad1.
Data Definitions
• Internal Tables
DATA : BEGIN OF <name> OCCURS x,
(variable definitions)
END OF <name>.
In this example, t_tab2 will contain the fields field1 & field2.
Program Level Statements
• CLEAR Statement
– CLEAR <var1>.
– Initializes the var1 to Zero
• REFRESH Statement
– REFRESH <var1>.
– Deletes and Initializes the var1 to Zero
• This has differences only in Internal Tables with header line and
without header line.
• CLEAR will initialize the header line, if the Internal table is with
header line otherwise it is same as REFRESH.
Data Definitions
• Appending Internal Table
DATA : BEGIN OF t_tab1 OCCURS 0,
field1 TYPE C,
field2 TYPE C,
END OF t_tab1.
t_tab1-field1 = ‘A’.
t_tab1-field2 = ‘B’.
APPEND t_tab1.
CLEAR t_tab1.
t_tab1-field1 = ‘C’.
t_tab1-field2 = ‘D’.
APPEND t_tab1.
CLEAR t_tab1.
Internal Tables
t_tab1-field1 = ‘Y’.
t_tab1-field2 = ‘Z’.
Example
READ TABLE itab INDEX 1.
This will read the first line of Internal Table
READ TABLE itab INTO wrk_tab INDEX sy-tabix.
This will copy the line into another work area where current index is pointer
is pointing
READ TABLE itab WITH KEY lifnr eq ‘V001’ BINARY SEARCH
This will read the internal table with specified key in binary search mode
Internal Tables
– The internal table <Int. Tab.> is sorted by its standard key if the BY option is
– not used.
– If BY option is used, it will be sorted by the order of the fields <f1>, <f2>,.. <fn>
– By default, it will sort by ASCENDING,
– To sort in the descending order we have to specify as DESCENDING.
Reports
Type 1
• run on its own
• Can be started it in the R/3 system without a
transaction code
• Can be executed in background
REPORT ZFIRSPRG.
WRITE ‘This is the First Sample ABAP Program’.
WRITE / ‘This is in Second Line.’.
WRITE: / ‘This is in Third Line.’,
‘I am also in Third Line’.
/ - Line feed
: - Chain declaration.
REPORT Statement
• REPORT Statement
– LINE-SIZE - Specifies, in columns, the width of the list to be
displayed.
– LINE-COUNT - Specifies the no. of lines per page
– MESSAGE-ID - Allows the use of the Message statement
without explicitly specifying the message id.
– NO STANDARD PAGE HEADING - Builds a header for the list
displayed from your report by default.
Example :
REPORT ZTEST LINE-SIZE 250 LINE-COUNT 65.
WRITE / ‘Width of the Line Statement’.
WRITE Statement
– At Line Selection
– At User Command
Program Level Events
• INITIALIZATION.
– This event is triggered prior to the first display of the selection
screen.
Example
INITIALIZATION.
CLEAR s_blart.
s_blart-sign = ‘I’.
s_blart-option = ‘EQ’.
s_blart-low = ‘WA’.
APPEND s_blart.
CLEAR s_blart.
Initialisation
In itializin g th e S e lectio n S c re en
I N IT IA L I ZA TI ON .
R EP O R T s ap b c 4 s0 s5_c d_ i n i ti al iz at io n .
. ..
IINI
NI
N ITTI ALIZ
TIIAL IIZ
ZAT
AT
A TIIIO
OON..
NN.
MO VE : m ar k TO pa _ a l l .
A irline AA to LH
M O V E : ' I' T O s o_ca rr-s ig n,
ca rr-o pt io n, F lig h t d ate
' BT ' T O s o_ to
' AA ' T O s o_
ca rr-l ow ,
' LH ' T O s o_
ca rr-h ig h. O u tpu t ...
A P P E ND s oc_a rr.
CL EA R soc_a r r. S eats ...
M O V E : ' E ' TO s o_ c a r r- s ig n, O ccu p ied
'E Q' T O soc _a r r- o p ti on , A v aila ble
'D L' T O so _c ar r- lo w.
A ll
A PP EN D s o _c a r r.
. .. S ele ction C olors Ic on s
S A P A G19 99
Program Level Events
• AT SELECTION-SCREEN
– This event is processed after user presses “Enter” on the
selection screen. Its main purpose is to verify user input prior to
program execution. Used during validating the data entered by
the user
• AT SELECTION-SCREEN OUTPUT
– This event is processed before display of the selection screen.
Example
AT SELECTION SCREEN.
IF p_wrbtr < 1.
MESSAGE e999 WITH ‘Greater than 1.’
ENDIF.
Program Level Events
• START-OF-SELECTION.
– This event begins the main processing of the program. The event is
triggered upon the user pressing “Execute” on the selection screen.
Note : An implicit START-OF-SELECTION is defined by
the REPORT statement. Any code placed between the
REPORT statement and the first event declaration is
executed during the START-OF-SELECTION event.
• END-OF-SELECTION
– This event is triggered following the execution of the last statement in
the START-OF-SELECTION.
Note : STOP Statement causes an automatic branch to
END-OF-SELECTION.
Program Level Events
• TOP-OF-PAGE.
– This event is triggered by the first WRITE statement to display
data on a new page; it is not triggered by the NEW-PAGE
statement, but the first WRITE statement following a NEW-
PAGE.
• END-OF-PAGE.
– This event is triggered as soon as the LINE-COUNT reached.
NEW-PAGE statement causes this event to be ignored.
Program Level Event
• AT LINE-SELECTION.
– This event is activated from the displayed list when the user
selects “Choose” or double-clicks on a line.
• AT USER-COMMAND.
– This event gets activated when the user executes a function
defined within the menu for the displayed list.
Sample Report
Sample Report
Events in ABAP Runtime Environment
Control Statements
• IF…ELSE…ENDIF
• CASE….ENDCASE
• LOOP….ENDLOOP
• DO…..ENDDO
• WHILE….ENDWHILE
IF Statement
Option 3 :
Option 2 : IF <condition1>.
Option 1 :
IF <condition1>.
IF <condition1>
<statement block> <statement block>
<statement block>
ELSE. ELSEIF <condition2>.
ENDIF
<statement block> <statement block>
ENDIF. .....
ELSE.
<statement block>
ENDIF.
IF …
• IF <logical expression>
<logical expression> is one of the following :
F1 <operand> F2
Any logical or relational operators can be used.
F1 BETWEEN F2 AND F3
Field F1 is checked for the value between F2 and F3
F1 IS INITIAL
Field F1 is Initial I.e. Value is equals Zero
F1 IN <selection>
<selection> is an internal table of Select-Options.
NOT ( F1 IS INITIAL)
Field F1 is not Initial I.e. Value is not equals Zero
OPERANDS
= , EQ Equal to.
<>, ><, NENot Equal to.
>, GT Greater than.
<, LT Less than.
>=, =>, GE Greater than or equal to
<=, =<, LE Less than or equal to
CO Contains only. Left side contains only characters from right side.
CN Contains not only. Equivalent to NOT ( c1 CO c2 ).
CA Contains any. Left side contains at least one character from the right side.
NA Contains not any. Equivalent to NOT ( c1 CA c2 ).
CS Contains String. Left side contains the full string in right side.
NS Contains no string. Equivalent to NOT ( c1 CS c2).
CP Contains pattern. Similar to LIKE in WHERE clause. “*” matches any multiple characters,
the “+” matches a single character. Use the “#” to indicate the character immediately
following to be matched literally; For eg., to find an actual “*” in position 1, use “#*…”
NP Contains no pattern. Equivalent to NOT ( c1 CP c2 ).
CASE Statement
CASE <var>.
WHEN <val1>.
<statement block>
WHEN <val2>.
<statement block>
......
WHEN OTHERS.
<statement block>
ENDCASE.
CASE..
• Example
DATA: txt1 VALUE 'X',
txt2 VALUE 'Y',
txt3 VALUE 'Z',
strng VALUE 'A'.
CASE strng.
WHEN text1.
WRITE: / 'String is', txt1.
WHEN text2.
WRITE: / ’String is’, txt2.
WHEN text3.
WRITE: / ’String is’, txt3.
WHEN OTHERS.
WRITE: / ’String is not’, txt1, txt2, txt3.
ENDCASE.
The output appears as follows: String is not X Y Z
LOOP Statement
LOOP AT <itab>
FROM <n1>
TO <n2>
WHERE <logical expr>
ENDLOOP.
<itab> Internal Table within the program
<n1> If specified, the LOOP begins with record number n1.
<n2> If specified, the LOOP ends with record number n2.
WHERE Comparison to be performed before processing the statements.
Within the loop, the statements CHECK and EXIT can also be used; a
failed CHECK statement skips the processing of the current record and
returns to the top of the LOOP. EXIT resumes processing with the
statement immediately following the ENDLOOP.
Control Breaks in Loop
Example
LOOP AT itab.
AT FIRST.
WRITE : SY-ULINE.
ENDAT.
…….
ENDLOOP.
Control Breaks
Example
LOOP AT itab.
AT LAST.
WRITE : SY-ULINE.
ENDAT.
……
ENDLOOP.
Control Breaks
Example
AT NEW I_LIFNR.
WRITE : SY-ULINE
ENDAT.
Control Breaks
Example
AT END OF I_LIFNR.
SUM.
WRITE : SY-ULINE.
ENDAT.
Note : AT NEW and AT END OF only make sense for a sorted table.
Do Loop
Example
DO 2 TIMES.
Output
WRITE SY-INDEX. 1
SKIP. 123
DO 3 TIMES. 2
WRITE SY-INDEX. 123
ENDDO.
SKIP.
ENDDO.
WHILE Loop
• NEW-PAGE.
– This will trigger a new page to be displayed.
– This can be used to skip from the current page.
Data Retrieval
• Finally, the table name in the FROM clause can now be a variable; thus
SELECT * FROM (var1)
Joins
• Joins are more efficient than logical database and nested selects.