Anda di halaman 1dari 122

AB1003 ABAP reports Classical and interactive v1.

India SAP CoE, Slide 1

ABAP reports Classical and interactive


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 2

ABAP reports Classical and interactive


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 3

Introduction
Purpose
Reports are Programs that read data from the database, processes the data and displays the data to the required format.

Use
Reports are used in day to day business environment. For eg Displaying the purchase orders vendor wise Displaying the balance of vendors to be paid till a particular date Enhance the efficiency & transparency of Business Processes Sound Decision making with the control of master data and accurate reporting Relevant Documents immediately available for in case of drill down reports Multiple angles of Data representing and Forecasting Values

India SAP CoE, Slide 4

ABAP reports Classical and interactive


1 2

Introduction Syntax description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 5

Process Flow

India SAP CoE, Slide 6

Data Declaration

India SAP CoE, Slide 7

Defining Data Types


Defining Data Objects RevDeision: Defining Data Objects
Local types TYPES type_name TYPE ...Predefined ABAP types d t i p f n string c xstring x DATA do_ nameTYPEtype _name . Global types

Data objects are usually defined with the DATA statement After the name of the data object, a fully-specified type is assigned to it using the TYPE addition

DATA do_name_new LIKE do_name.

SAP AG 2002

India SAP CoE, Slide 8

Predefine ABAP Types


Fixed length Data type Numeric i f p Description Integer Float. point number Packed number Length in bytes 4 8 1 .. 16 1 .. 65535 1 .. 65535 8 6 Attributes Differ in: Rules for storage Value range Arithmetic used Character string operations (allowed for all types) + date calculations + time calculations

Character string type n Number sequence c Character sequence d Date t Time Variable Hexadecimal x

length

Hexadecimal code

1 .. 65535

Bit operations
Runtime system adjusts length dynamically

Character string type / hexadecimal string Character sequence xstring Hexadecimal code
SAP AG 2002

ABAP types d, t, i, f, string, and xstring are used directly to type data objects and are therefore called fully specified types. ABAP Types c, n, and x must include additional information before using them to define data objects:

India SAP CoE, Slide 9

Packed Numbers and Fixed Point Arithmetic

Packed Number

DATA: percentage(3) TYPE 2 VALUE (3) p DECIMALS DECIMALS 2 '12.34'.

Length in bytes: n bytes correspond to 2n - 1 digits

Number of decimal places

Fixed point arithmetic: "like using paper and pencil" Number 12,34 Internal representation 0 1
1 digit per half - byte

1234,56 78,5 1313,06

2 3

4 +
Sign

l l l

Permitted length: 1 to 16 bytes (= 1 to 31 digits)

Number of decimal places < number of digits, max. 15


Example: Length 3 bytes, 2 decimal places Value range: [ - 999.99,+999.99]

India SAP CoE, Slide 10

Recommendations for Using Numeric Data Types

Required:

Recommended predefined ABAP data type: Type i, since calculations using integer arithmetic are fastest

Integers only

Decimal numbers for business calculations

Type p

Decimal numbers for rough calculations performed on very small or very large numbers

Type F

India SAP CoE, Slide 11

Arithmetic Calculation
Operator
+, -, * , / , DIV MOD ** ABS CEIL FLOOR TRUNC

Meaning
Mathematical Remainder of integer division Powers Absolute value of argument Smallest integer value Largest integer value Integer part of argument

FRAC

Fraction part of argument

India SAP CoE, Slide 12

Predefined ABAP Types for Character Strings

Type Description Length Time

Type Date

Type

Type c Fixed - length char. string 1 .. 65535 characters Depends on Conversion

Sequence of digits 1 .. 65535 characters Digits Conversion

Type string Char. string of variable length

6 digits HHMMSS By clock Time arithmetic HH:MM:SS

8 digits YYYYMMDD By Gregorian calendar Date arithmetic Based on user default values

Variable
codepage Conversion

Value range Calculations Formatting options

The initial value of each character string with fixed length is a space character. The initial value of each character in a numeric string is a zero. The initial value of a date is '000000'. The initial value of a time is '000000'.

India SAP CoE, Slide 13

Character String Processing


Description and notes
Found: sy - subrc =0

FIND REPLACE TRANSLATE SHIFT CONDENSE OVERLAY CONCATENATE SPLIT

ABAP BBAP a b ap BAP AP ABAP ABAP AB AP

Search Search in in a a character character string string Position of search string using MATCH OFFSET off addition Replace first occurrence Replace all occurrences Move Remove space characters Overwrite : Spaces are overwritten by characters from the second character string Concatenate several character strings Split a character string

ABAP ABAP ABAP AP AB P AAAA AB

+ AP

ABCAP

All of the statements apart from TRANSLATE and CONDENSE set the system field sy-subrc

India SAP CoE, Slide 14

Type Groups in the ABAP Dictionary


Name of type group: Up to 5 characters; each type name and constant name starts with the name of the type group.

Type group

zmytp

Each type group, whose types and constants you want to use, must be specified in the ABAP program

zmytp . TYPE - POOL CONSTANTS zmytp _ const _name ... zmytp [ TYPES zmytp _type_name1 ... zmytp [ TYPES zmytp _type_name2 ... ...

] ]

Using a constant:

TYPE

POOLS: - POOLS var

zmytp TYPE

. zmytp _type1. _name. ]

ABAP program

[ DATA IF var ... ENDIF.

= zmytp zmytp

_ const

Type group used to define global constants To be able to use the types of a type group in a program, refer to the type group using the TYPE-POOLS statement

India SAP CoE, Slide 15

Defining Structures with Local Types


Definition of a structure type

TYPES: TYPES: name_type BEGIN OF s_ s_name_type, prename(25) TYPE c, surname(25) TYPE c, title(5) TYPE c, END OF s_name_type.
Definition of a structure with reference to a user -defined type

Definition of a structure with implicit type construction

DATA: s_name s_name TYPE s_name_type s_name_type .


Alternatives

DATA: DATA: BEGIN OF s_name, prename(25) TYPE c, surname(25) TYPE c, title(5) TYPE c, END OF s_name.

START-OF-SELECTION. s_name s_name-prename = 'Smith'. s_name s_name-surname = 'John'.

India SAP CoE, Slide 16

Internal Tables
The Internal Table - a Data Object of Variable Length
ABAP program

Elementary data objects

Structures

Static data objects (except for types STRING, XSTRING)

Internal table

At runtime, the runtime system allocates memory for the lines in the table as needed ( dynamic table extension )

India SAP CoE, Slide 17

Attributes of Internal Tables

CARRID Line index

CONNID

DISTANCE

DISTID

Line type

1 2 3 4 5 6

AA LH LH QF SQ UA

0017 0400 0402 0005 0866 0007

2.572 6.162 5.136 10.000 1.625 2.572

MI KM KM MI MI MI
2

Index access

Key access SQ 0866

Key definition
( Key fields ( Sequence ( Uniqueness

Table kind Standard table Sorted table Hashed table

Line type: You use the line type to specify which columns are to be included in your internal table. Key: The key is defined by: Specifying the columns that should belong to the key; the sequence; and whether or not the key should be unique or non-unique. Table kind: The table kind specifies the possible accesses.

India SAP CoE, Slide 18

Link ype Between Table KiiiiiIind and Access Type

Link Between Table Kind and Access Type


Index tables Hashed table

Table kind Index access n

STANDARD TABLE

SORTED TABLE

HASHED TABLE

Key access
Table scan

Binary search

Hash function

Uniqueness

NON - UNIQUE

UNIQUE | NON

- UNIQUE

UNIQUE

Access by

Mostly index

Mostly key

Key only

India SAP CoE, Slide 19

Ov of Operations Overview of

Operations
Standard table Sorted table Hashed table

SORT
Index access
n

INSERT READ TABLE MODIFY

Sort sequence could be violated

No index accesses to

DELETE
LOOP AT
Key access Append to end of table

hashed
tables

INSERT

READ TABLE
MODIFY DELETE LOOP AT

India SAP CoE, Slide 20

Field Symbols

Field Symbols
FIELD - SYMBOLS <fs> TYPE|LIKE . .. |TYPE A ASSIGN ... dataobject TO <fs>. UNASSIGN <fs>. ... <fs> IS ASSIGNED ... DATA int TYPE i VALUE 15. FIELD - SYMBOLS < fs _ int > TYPE i. ASSIGN int TO < fs _ int >. WRITE: / int , < fs _ int >. < fs _ int > = 17. WRITE: / int , < fs _ int >. UNASSIGN < fs _ int >. IF < fs _ int > IS ASSIGNED . WRITE: / int , < fs _ int >. ELSE. WRITE: / 'fieldsymbol not ENDIF. NY}. Generic or complete type specification
fs _ int
15

int

fs _ int

15

int

fs _ int

17

int

fs _ int

17

int

assigned'

( fna ).

SAP

AG 2002

Field symbols allow you to access an assigned data object - that is, all the accesses that you make to the field symbol are made to the data object assigned to it.
Use the ASSIGN statement to assign a data object to the field symbol <fs>. The statement UNASSIGN <fs>. sets the field symbol <fs> so that it points to nothing.
India SAP CoE, Slide 21

Introductory Statements for Programs


Program type
1 M F K J S T I

Introductory statement
REPORT PROGRAM FUNCTION-POOL CLASS-POOL CLASS-POOL PROGRAM TYPE-POOL -

India SAP CoE, Slide 22

Simple Reports
Attributes.
Source code Text elements Documentation Variants

Report Statement.
REPORT ZREPNAME [NO STANDARD PAGE HEADING] [LINE-SIZE col] [LINECOUNT n(m)] [MESSAGE-ID mid]. NO STANDARD PAGE HEADING - Suppresses output of the standard page header LINE-SIZE col - Creates a report with col columns per line. LINE-COUNT n(m) - Creates a report list with n lines per page, of which m lines are reserved for the END-OF-PAGE processing. SUBMIT <rep> [AND RETURN] [<options>]. starts the report whose name is stored in field <rep>

India SAP CoE, Slide 23

Text Symbols

Text symbols are simple text literal. They can be translated to any other Language. You can address text symbols in a program one of two ways: TEXT-<xxx> (xxx is a three digit character sequence) '<Text>'(<xxx>) (xxx is a three digit character sequence)

India SAP CoE, Slide 24

Write Statement
Syntax WRITE <f>. This statement writes field <f> to the current list in its standard output format. Example PROGRAM sapmztst. WRITE 'Hello, here I am!'.

India SAP CoE, Slide 25

Positioning WRITE Output on the List


Syntax WRITE AT [/][<pos>][(<len>)] <f>. where the slash '/' denotes a new line, <pos> is a number or variable up to three digits long denoting the position on the screen, <len> is a number or variable up to three digits long denoting the output length. In the default setting, you cannot create empty lines with the WRITE statement.

WRITE: 'One', / ' ', / 'Two'. This produces the following output: One Two

India SAP CoE, Slide 26

Formatting Options
Syntax WRITE .... <f> <option>.

Formatting options for all data types


Function Option LEFT-JUSTIFIED CENTERED RIGHT-JUSTIFIED UNDER <g> NO-GAP USING EDIT MASK <m> USING NO EDIT MASK NO-ZERO Output is left-justified. Output is centered. Output is right-justified. Output starts directly under field <g>. The blank after field <f> is omitted. Specifies format template <m>. Deactivates a format template specified in the ABAP Dictionary. If a field contains only zeros, these are replaced by blanks. For type C and N fields, leading zeros are replaced automatically.

India SAP CoE, Slide 27

Formatting Options
Formatting options for numeric fields Option Function

contd

NO-SIGN
DECIMALS <d> EXPONENT <e> ROUND <r>

The leading sign is not displayed on the screen.


<d> defines the number of digits after the decimal point. In type F fields, the exponent is defined in <e>. Type P fields are multiplied by 10**(-r) and then rounded.

CURRENCY <c>
UNIT <u>

Format according to currency <c> in table TCURX.


The number of decimal places is fixed according to unit <u> specified in table T006 for type P fields.

India SAP CoE, Slide 28

Write Options
ABAP/4 output Formatting.
Format Color n. Format Color n Intensified On. FORMAT COLOR OFF INTENSIFIED OFF INVERSE OFF Off.

Cont..

HOTSPOT OFF INPUT

India SAP CoE, Slide 29

Displaying Symbols and Icons on the List


You can output symbols or R/3 icons on a list by using the following syntax: Syntax WRITE <symbol-name> AS SYMBOL. WRITE <icon-name> AS ICON. To make symbols and icons available to your program, you must import the appropriate include or the more comprehensive include <LIST> in your program. INCLUDE <symbol>. INCLUDE <icon>.

WRITE: / 'Phone Symbol:', SYM_PHONE AS SYMBOL. SKIP. WRITE: / 'Alarm Icon: ', icon_alarm AS ICON. This produces the following output:

India SAP CoE, Slide 30

Blank Lines and Drawing Lines


Horizontal lines
You can generate horizontal lines on the output screen by using the following Syntax ULINE [AT [/][<pos>][(<len>)]].

Vertical lines
You generate vertical lines on the output screen by using the following Syntax WRITE [AT [/][<pos>]] SY-VLINE.

Blank lines
You can generate blank lines on the screen by using the following : Syntax SKIP [<n>].

India SAP CoE, Slide 31

Displaying Field Contents as Checkboxes


You can output the first character of a field as a checkbox on the output screen by using the following

Syntax
WRITE <f> AS CHECKBOX. If the first character of field <f> is an "X", the checkbox is displayed filled. If the first character is SPACE, the checkbox is displayed blank. DATA: flag1(1) TYPE c flag2(1) TYPE c flag3(5) TYPE c WRITE: / 'Flag 1 ', flag1 / 'Flag 2 ', flag2 / 'Flag 3 ', flag3 VALUE ' ', VALUE 'X', VALUE 'Xenon'. AS CHECKBOX, AS CHECKBOX, AS CHECKBOX. This produces the following output list:

India SAP CoE, Slide 32

Individual Page Header


To layout a page header individually, you must define it in the processing block following the event keyword TOP-OF-PAGE:
Syntax

TOP-OF-PAGE.
REPORT demo_list_page_heading NO STANDARD PAGE HEADING. TOP-OF-PAGE. WRITE: sy-title, 40 'Page', sy-pagno. ULINE. WRITE: / 'SAP AG', 29 'Walldorf, ',sy-datum, / 'Neurottstr. 16', / '69190 Walldorf/Baden'. ULINE. START-OF-SELECTION. DO 5 TIMES. WRITE / sy-index. ENDDO.

India SAP CoE, Slide 33

Determining the List Width


To determine the width of the output list, use the LINE-SIZE option of the REPORT statement. While creating the list, the system field SY-LINSZ contains the current line width. Syntax REPORT <rep> LINE-SIZE <width>.

REPORT demo_list_line_size LINE-SIZE 40. WRITE: 'SY-LINSZ:', sy-linsz. ULINE. DO 20 TIMES. WRITE sy-index. ENDDO. REPORT demo_list_line_size LINE-SIZE 60. WRITE: ULINE. DO 20 TIMES. WRITE sy-index. ENDDO.
India SAP CoE, Slide 34

'SY-LINSZ:', sy-linsz.

Determining the Page Length


To determine the page length of an output list, use the LINE-COUNT option of the REPORT statement. Syntax REPORT <rep> LINE-COUNT <length>[(<n>)]. If you specify the optional number <n>, the system reserves <n> lines of the page length for the page footer.
REPORT demo_list_end_of_page LINE-SIZE 40 LINE-COUNT 6(2) NO STANDARD PAGE HEADING. TOP-OF-PAGE. WRITE: 'Page with Header and Footer'. ULINE AT /(27). END-OF-PAGE. ULINE. WRITE: /30 'Page', sy-pagno. START-OF-SELECTION. DO 6 TIMES. WRITE / sy-index. ENDDO.
India SAP CoE, Slide 35

Programming Page Breaks


Unconditional Page Break To trigger a page break during list processing, use the basic form of the NEW-PAGE statement: Syntax

NEW-PAGE.
This statement ends the current page. All other output appears on a new page.
REPORT demo_list_new_page LINE-SIZE 40. TOP-OF-PAGE. WRITE: 'TOP-OF-PAGE', sy-pagno. ULINE AT /(17). START-OF-SELECTION. DO 2 TIMES. WRITE / 'Loop:'. DO 3 TIMES. WRITE / sy-index. ENDDO. NEW-PAGE. ENDDO.

India SAP CoE, Slide 36

Conditional Page Break- Defining a Block of Lines


To execute a page break on the condition that less than a certain number of lines is left on a page, use the RESERVE statement: Syntax

RESERVE <n> LINES.


REPORT demo_list_reserve LINE-SIZE 40 LINE-COUNT 8(2). END-OF-PAGE. ULINE. START-OF-SELECTION. DO 4 TIMES. WRITE / sy-index. ENDDO. DO 2 TIMES. WRITE / sy-index. ENDDO. RESERVE 3 LINES. WRITE: / 'LINE 1', / 'LINE 2', / 'LINE 3'.

India SAP CoE, Slide 37

Standard Page Headers of Individual Pages


The standard page header consists of list and column headers. To influence the representation of these individual components of the standard page header, use the following options. Syntax

NEW-PAGE [NO-TITLE|WITH-TITLE] [NO-HEADING|WITH-HEADING].


REPORT demo_list_new_page_options LINE-SIZE 40. WRITE: 'Page', sy-pagno. NEW-PAGE NO-TITLE. WRITE: 'Page', sy-pagno. NEW-PAGE NO-HEADING. WRITE: 'Page', sy-pagno. NEW-PAGE WITH-TITLE. WRITE: 'Page', sy-pagno. NEW-PAGE WITH-HEADING. WRITE: 'Page', sy-pagno.

India SAP CoE, Slide 38

Enabling Fields for Input


To make output fields input-enabled from within the program, use the FORMAT statement as follows: Syntax

FORMAT INPUT [ON|OFF].


REPORT demo_list_format_input. WRITE 'Please fill in your name before printing:'. WRITE / ' Enter name here ' INPUT ON. ULINE. WRITE 'You can overwrite the following line:'. FORMAT INPUT ON INTENSIFIED OFF. ULINE. FORMAT INPUT OFF INTENSIFIED ON.

India SAP CoE, Slide 39

Outputting Fields as Hotspots


If the user clicks once onto a hotspot field, an event is triggered (for example, AT LINE-SELECTION). To output areas as hotspots, use the following option of the FORMAT statement: Syntax

FORMAT HOTSPOT [ON|OFF].

REPORT demo_list_format_hotspot. INCLUDE <list>. START-OF-SELECTION. WRITE 'Now comes a'. FORMAT HOTSPOT ON COLOR 5 INVERSE ON. WRITE 'HOTSPOT'. FORMAT HOTSPOT OFF COLOR OFF. AT LINE-SELECTION. WRITE / 'New list AT-LINE-SELECTION'. SKIP. WRITE 'This is also a hotspot:'. WRITE icon_list AS ICON HOTSPOT.

India SAP CoE, Slide 40

IF Condition

Logical Expression
If < Cond>.
{statements}

Elseif.
{statements}

Endif.

India SAP CoE, Slide 41

India SAP CoE, Slide 42

India SAP CoE, Slide 43

SAP recommends that you only use CHECK within loops.

India SAP CoE, Slide 44

Storing Data Objects in Memory


EXPORT <f1> [FROM <g1>] <f2> [FROM <g2>] ... TO MEMORY ID <key>. To write data objects from an ABAP/4 program to ABAP/4 memory IMPORT <f1> [TO <g1>] <f2> [TO <g2>] ... FROM MEMORY ID <key>. To read data objects from ABAP/4 memory into an ABAP/4 program SET PARAMETER ID 'RID' FIELD <FIELD NAME1>. The system stores the value in <field name1> in the SPA parameter 'RID'. The field values saved globally in memory. GET PARAMTER ID 'RID' FIELD <FIELD NAME2>. The system reads the contents of 'RID' and transfers them to <FIELD NAME2>. The field values saved globally in memory.

India SAP CoE, Slide 45

Event Blocks in Executable Programs


When you run an executable program, the program flow is controlled by the external events in the ABAP runtime environment. The following diagram shows the sequence of the events:

The events in the gray box are only processed if you have entered a logical database in the program attributes. The AT SELECTION-SCREEN event is only processed if a selection screen is defined in the program or the logical database linked to the program. The other events occur when any executable program is run

India SAP CoE, Slide 46

Event Blocks in Executable Programs

contd.

The following events occur when you run a typical executable program with a logical database:

INITIALIZATION Before the standard selection screen is displayed AT SELECTION-SCREEN After user input on a selection screen has been processed, but while the selection screen is still active START-OF-SELECTION After the standard selection screen has been processed, before data is read from the database GET <TABLE> After the logical database has read an entry from the node <table> GET <TABLE> LATE After all of the nodes of the logical database have been processed that are below <table> in the database hierarchy END-OF-SELECTION After all data has been read by the logical database

India SAP CoE, Slide 47

Event Blocks in Executable Programs


List processor events:

contd.

TOP-OF-PAGE In list processing when a new page starts END-OF-PAGE - In list processing when a page ends AT LINE-SELECTION - Event is triggered by either the user double clicking a particular line or using F2 to select it AT PF<nn> - When the user triggers the predefined function code PF<nn> AT USER-COMMAND - When the user triggers a function code defined in the program TOP-OF-PAGE DURING LINE SELECTION - Event called during list processing when a detailed list is called

India SAP CoE, Slide 48

Initialization
Processed before the presentation of the selection screen Can be used to initialize values in the selection screen or to assign values to any parameters that appear on the selection screen

REPORT EVENT_DEMO. PARAMETERS DATUM TYPE SY-DATUM DEFAULT SY-DATUM. NODES SPFLI. INITIALIZATION. CITY_FR = 'NEW YORK'. CITY_TO = 'FRANKFURT'. CARRID-SIGN = 'I'. CARRID-OPTION = 'EQ'. CARRID-LOW = 'AA'. APPEND CARRID. DATUM+6(2) = '01'.

India SAP CoE, Slide 49

At Selection-Screen
Processing block is started after the user has specified all the criteria in the selection screen This event can also be called on a particular parameter or select-option using At Selection-Screen on <parameter or select-option>

India SAP CoE, Slide 50

Start-Of-Selection Processing block is executed after processing the selection screen All the data is selected in this block. All the main processing on the data except for interactive reporting is handled in this block.
End-Of-Selection Data which is selected and has been processed is printed to the screen in this block. List Processing happens in this block
REPORT EVENT_DEMO. NODES SPFLI. DATA: SPFLI_TAB TYPE SORTED TABLE OF SPFLI WITH UNIQUE KEY CITYFROM CITYTO CARRID CONNID, SPFLI_LINE TYPE SPFLI. START-OF-SELECTION. WRITE 'Demo program for END-OF-SELECTION'. SKIP. GET SPFLI FIELDS CARRID CONNID CITYFROM CITYTO. MOVE-CORRESPONDING SPFLI TO SPFLI_LINE. INSERT SPFLI_LINE INTO TABLE SPFLI_TAB.

END-OF-SELECTION. LOOP AT SPFLI_TAB INTO SPFLI_LINE. WRITE: / SPFLI_LINE-CITYFROM, SPFLI_LINE-CITYTO, SPFLI_LINE-CARRID, SPFLI_LINE-CONNID. ENDLOOP.

India SAP CoE, Slide 51

Leaving Event Blocks


Leaving Event Blocks Using STOP
If you use the STOP statement within an event block, the system stops processing the block immediately. The ABAP runtime environment triggers the next event according to the following diagram:

India SAP CoE, Slide 52

Leaving Event Blocks Using EXIT


From the START-OF-SELECTION event onwards, the system starts the list processor directly when the EXIT statement occurs, and displays the list. If the EXIT statement occurs in a loop using DO, WHILE, or LOOP, it is the loop that terminates, not the processing lock.

India SAP CoE, Slide 53

Leaving Event Blocks Using CHECK


If you use the CHECK <expr> statement within an event block but not within a loop, and the condition <expr> is not fulfilled, the system exits the processing block immediately.

India SAP CoE, Slide 54

Leaving a GET Event Block Using REJECT


The REJECT statement was specially developed for leaving GET event blocks. Unlike CHECK and EXIT, REJECT always refers to the current GET event block. The REJECT statement allows you to exit a GET event block directly from a loop or a subroutine.

India SAP CoE, Slide 55

Determining the Attributes of Lists


If you need to know the attributes of list levels that are not stored in system variables, you can use the DESCRIBE LIST statement. To retrieve the number of lines or pages of a list, use: DESCRIBE LIST NUMBER OF LINES|PAGES <n> [INDEX <idx>]. This statement writes the number of lines or pages of the list level <idx> into the variable <n>. If a list with index <idx> does not exist, the system sets SY-SUBRC unequal to 0, otherwise to 0. To retrieve the page number for a certain line number, use: DESCRIBE LIST LINE <lin> PAGE <pag> [INDEX <idx>]. This statement writes for list level <idx> the page number on which the list line number <lin> is found into the variable <pag>. SY-SUBRC is set as follows: If there is no list with the index <idx>, it is 8. If there is no line with number <line>, it is 4. Otherwise, it is 0.

India SAP CoE, Slide 56

Determining the Attributes of Lists


To retrieve the attributes of a certain page, use: DESCRIBE LIST PAGE <pag> [INDEX <idx>] [<options>]

contd

This statement retrieves for list level <idx> the attributes specified in <options> for page <pag>. SY-SUBRC is set as follows: If there is no list with the index <idx>, it is 8. If there is no page with number <pag>, it is 4. Otherwise, it is 0. The <options> of the statement are: LINE-SIZE <col>

writes the page width into the variable <col>.


LINE-COUNT <len> writes the page length into the variable <len>. LINES <lin>

writes the number of displayed lines into the variable <lin>.


FIRST-LINE <lin1> writes the absolute number of the first line into the variable <lin1>.

India SAP CoE, Slide 57

Determining the Attributes of Lists


The <options> of the statement (contd) TOP-LINES <top> writes the number of page header lines into the variable <top>. TITLE-LINES <ttl>

contd

writes the number of list header lines of the standard page header into the variable <ttl>. HEAD-LINES <head>

writes the number of column header lines of the standard page header into the variable <head>.
END-LINES <end> writes the number

India SAP CoE, Slide 58

The MESSAGE Statement


Using a Global Message Class If the introductory statement of a program contains the addition ... MESSAGE-ID <id>. and a message class <id> contained in table T100, you can use the MESSAGE statement as follows: MESSAGE <t><num> [WITH <f1> ... <f 4>] [RAISING <exc>]. where <t> is the single-character message type and <nnn> the three-digit message number.

Specifying the Message Statically To specify the message class, message number, and message type statically, use the following form of the MESSAGE statement:

MESSAGE <t><nnn>(<id>) [WITH <f1> ... <f4>] [RAISING <exc>].

India SAP CoE, Slide 59

The MESSAGE Statement


Specifying the Message Dynamically To specify the message class, message number, and message type dynamically, use the following form of the MESSAGE statement:

contd

MESSAGE ID <id> TYPE <t> NUMBER <n> [WITH <f1> ... <f4>] [RAISING <exc>]. where <id>, <t>, and <n> are fields containing the message class, message number, and message type respectively.

Messages and Exceptions Within function modules and methods, you can use the RAISING addition in the MESSAGE statement to trigger exception:

MESSAGE..... RAISING <exc>.


If the calling program does not handle the exception <exc> itself, the message is displayed, and the program continues processing in the manner appropriate to the message type and context

India SAP CoE, Slide 60

Message Types
A Termination 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. Depending on the program context, an error dialog appears or the program terminates. The message appears in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement. The program continues normally after the MESSAGE statement, and the message is displayed in the status bar of the next screen.

Error

Information

Status

Warning

Depending on the program context, an error dialog appears or the program terminates. 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.

Exit

India SAP CoE, Slide 61

Modularization Techniques
Procedures contain a set of statements, and are called from other ABAP programs

ABAP contains the following kinds of procedures:


Subroutines Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. You can use subroutines to write functions that are used repeatedly within a program. You can define subroutines in any ABAP program. Function Modules Function modules are for global modularization, that is, they are always called from a different program. Function modules contain functions that are used in the same form by many different programs. They are important in the R/3 System for encapsulating processing logic and making it reusable. Function modules must be defined in a function group, and can be called from any program.

India SAP CoE, Slide 62

Subroutines
Defining Subroutines A subroutine is a block of code introduced by FORM and concluded by ENDFORM. FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ] [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]. ... ENDFORM. <subr> is the name of the subroutine. The Parameter Interface Parameters Passed by Reference list these parameters after USING without the VALUE addition Parameters Passed by Value list these parameters after USING with the VALUE addition Passing by Value and Result If you want to return a changed output parameter from a subroutine to the calling program only after the subroutine has run successfully, use CHANGING for the <pass> option of the FORM and PERFORM

India SAP CoE, Slide 63

Subroutines
Calling Subroutines PERFORM... [USING ... <pi>... ] [CHANGING... <pi>... ].

Cont..

Static Variable If you want to keep the value of a local data object after exiting the subroutine, you must use the STATICS statement to declare it instead of the DATA statement. With STATICS you declare a data object that is globally defined, but only locally visible from the subroutine in which it is defined. STATICS f_text TYPE f_word VALUE 'INIT'.

India SAP CoE, Slide 64

Function modules

Calling Function Modules CALL FUNCTION <module> [EXPORTING f1 = a 1.... f n = a n] [IMPORTING f1 = a 1.... f n = a n] [CHANGING f1 = a 1.... f n = a n] [TABLES f1 = a 1.... f n = a n] [EXCEPTIONS e1 = r 1....en = rn [ERROR_MESSAGE = r E] [OTHERS = ro]].

Creating Function Modules (SE37) Attributes Parameter Interface Tables Exceptions Source Code

India SAP CoE, Slide 65

Function modules

Cont..

India SAP CoE, Slide 66

Function modules
Calling A Function modules - Pattern

Cont..

India SAP CoE, Slide 67

Function modules
Testing A Function modules SE37

Cont..

India SAP CoE, Slide 68

Logical databases
Advantages of a Logical Database

Program 1 Program 2 Query 3

Query 1 Query 2

Logical database
Program 4 Program 5

Program 3

- Provides a selection screen - Providesinput and authorization QuickView 1 checks - Reads data records
Query 4
QuickView 2 Program 6

A logical database is an ABAP program that reads data from the database and makes the data available
to other report programs.

India SAP CoE, Slide 69

Advantages of using Logical Database


Logical databases offer several advantages over other methods of data retrieval: The system generates a selection screen. The use of selection screen versions or variants provides the required flexibility. The programmer does not need to know the exact structure or relationship of the tables involved; the data is made available to the application program in primary key sequence. Data is formatted for output in the GET events. Performance improvements within logical databases directly affect all programs linked to the logical database without having to change the programs themselves. Maintenance and enhancements can be performed at a central location. Authorization checks are done in the logical database program rather than in the application program.

India SAP CoE, Slide 70

Logical databases

contd

A hierarchical structure determines the order in which the data is supplied to the programs.
Logical Database: Overview

ABAP ABAP Dictionary Dictionary

Hierarchical view

SPFLI SPFLI SFLIGHT SFLIGHT SBOOK SBOOK

F1S F1S

India SAP CoE, Slide 71

EEvents in Logical Databases

Events in logical database


sapbc405_ ldbd _events. START-OF-SELECTION
1 GET SPFLI GET SFLIGHT GET SBOOK GET SBOOK GET SBOOK GET SFLIGHT LATE GET SFLIGHT GET SBOOK GET SBOOK GET SFLIGHT LATE GET SPFLI LATE GET SPFLI DL 1984 27.03.2000 00002590 00002591 DL 1699 25.02.2000 00002568 00002569 00002570

REPORT ...

START-OF-SELECTION
1 SPFLI 1 SPFLI 5 2 SFLIGHT 2 SFLIGHT

2 3

3 3
4 2

4 SBOOK
3

4 SBOOK
3

3 3 4
5 1

SBOOK
3

SBOOK
3

SBOOK
3

END-OF-SELECTION

END-OF-SELECTION

The GET <node> event triggers whenever the logical database supplies data for this node. This means that GET events are processed several times, and that data has already been read from the database for these events. The sequence in which the GET events are processed is determined by the structure of the logical database. The GET <node> LATE event triggers when all subordinate nodes of node <node> have been processed, before the data is read for the next <node> (whenever a hierarchy level has been completed).

India SAP CoE, Slide 72

Selection Screen
Declaring Fields with PARAMETERS Declaring Fields with Parameters
PARAMETERS: <f>[TYPE <type>][DECIMALS <n>][LIKE <f1>][MEMORY ID < pid >] [OBLIGATORY][DEFAULT <value >][LOWER CASE][VALUE CHECK] [AS CHECKBOX] [RADIOBUTTON GROUP < grp >]
REPORT sapbc405_ sscd _checkbox_ radiobutton ... . PARAMETERS: pa_ carr LIKE sflight - carrid , pa_name AS CHECKBOX DEFAULT 'X', pa_ curr AS CHECKBOX DEFAULT 'X', pa_ lim _1 RADIOBUTTON GROUP lim pa_ lim _2 RADIOBUTTON GROUP lim pa_ lim _3 RADIOBUTTON GROUP lim CONSTANTS mark VALUE 'X' . * Check, if any checkbox has been selected IF pa_name EQ mark. ... . ENDDIF. IF pa_ curr EQ mark. ... . ENDDIF. * Check, which radiobutton CASE mark. WHEN pa_ lim _1. ... . WHEN pa_ lim _2. ... . WHEN pa_ lim _3. ... . ENDCASE. has been selected .

Airline , , . ! ! Output name Output local currency

AA

Price (local currency):

up to 500 500 to 1000

1000 to 1500

India SAP CoE, Slide 73

Selection Screen
Selections with SELECT - OPTIONS Selections with Select Options
SELECT - OPTIONS: < seltab > FOR <f>. REPORT sapbc405_ sscd _select_options . TABLES: sflight . SELECT -OPTIONS: so_ carr FOR sflight -carrid DEFAULT 'AA', so_ fldt FOR sflight -fldate .

contd..

Internal Table so_carr Airline Sign I Option EQ Low AA High Flight date AA to to

India SAP CoE, Slide 74

Selection Screen
Syntax of the SELECT -OPTIONS Statement

contd..

Syntax for SELECT-OPTIONS


SELECT-OPTIONS <seltab> FOR <f> DEFAULT <value> OPTION <xx> SIGN <x> DEFAULT <value1> TO <value2> MEMORY ID < pid> LOWER CASE OBLIGATORY NO-EXTENSION NO INTERVALS

MEMORY ID <pid>, the system retrieves the current value from SAP system memory and supplies it on the screen automatically OBLIGATORY generates a mandatory field. NO-EXTENSION suppresses multiple single or multiple range selections. NO INTERVALS suppresses the seltab-high (upper interval limit) entry on the selection screen.

India SAP CoE, Slide 75

Selection Screen
Formatting Selection Screen.

Cont..

...

SELECTION-SCREEN SKIP [<n>]. To produce blank lines on the selection screen SELECTION-SCREEN ULINE [[/]<pos(len)>] [MODIF ID <key>]. To underline a line or part of a line on the selection screen SELECTION-SCREEN COMMENT [/]<pos(len)> <name> [FOR FIELD <f>] [MODIF ID <key>]. To write text on the selection screen SELECTION-SCREEN BEGIN OF BLOCK <block> [WITH FRAME [TITLE <title>]][NO INTERVALS]. SELECTION-SCREEN END OF BLOCK <block>. To create a logical block of elements on the selection screen

India SAP CoE, Slide 76

Select Statement
Select Statement

SELECT <result> INTO <target> FROM <source> [WHERE <condition>] [GROUP BY <fields>] [ORDER BY <fields>]. ENDSELECT.

India SAP CoE, Slide 77

Select Statement
Reading the Whole Line SELECT * FROM EMP INTO TMPTABLE WHERE EMPNO = EMPNO ENDSELECT. Reading a Single Line SELECT SINGLE * FROM EMP WHERE EMPNO = EMPNO. Reading Lines Using Up To SELECT * FROM EMP WHERE EMPNO IN EMPNO UPTO N ROWS. ENDSELECT. Reading Single Columns SELECT NAME EMPNAME FROM EMP WHERE EMPNO = EMPNO. ENDSELECT. Reading Data Dynamically SELECT (TMPEMP) FROM (TBLNAME) WHERE EMPNO = EMPNO. ENDSELECT. CLIENT SPECIFIED, BYPASSING BUFFER.

India SAP CoE, Slide 78

Where Condition

<Condition>
EQ, = NE, <>, >< LT, < GT, > LE , <= GT , >= [NOT] BETWEEN [NOT] LIKE [NOT] IN

Meaning
Equal Not Equal Less Than Greater Than Less Than or Equal Greater Than or Equal Between Like Patten In

India SAP CoE, Slide 79

Select Statement
Specifying Internal Tables

Cont..

SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] <itab> ENDSELECT. SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab> SELECT * FROM INTO . FOR ALL ENTRIES IN Itab WHERE .. = Itab-..

Using JOIN
SELECT employee_name, manager_name FROM employees AS e INNER JOIN managers AS m ON e.manager_id = m.manager_id SELECT employee_name, manager_name FROM employees AS e OUTER JOIN managers AS m ON e.manager_id = m.manager_id

India SAP CoE, Slide 80

Select Statement

Cont..

Specifying a Database Table INSERT INTO <dbtab> [CLIENT SPECIFIED] <lines>. Inserting a Single Line INSERT INTO <target> VALUES <wa> . Inserting Several Lines INSERT <target> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS] . Specifying a Database Table UPDATE <dbtab> [CLIENT SPECIFIED] <lines>. Changing Lines Column by Column UPDATE <target> SET <set1> <set 2> ... WHERE <cond>. Overwriting Individual Lines From a Work Area UPDATE <target> FROM <wa> / TABLE <ITAB> Deleting Lines. DELETE [FROM] <target> <lines>. Changing a Database Table MODIFY dbtab FROM wa.

India SAP CoE, Slide 81

Database Statements
Committing Database Changes. COMMIT WORK. COMMIT WORK always concludes a database LUW and starts a new one. ROLLBACK WORK. ROLLBACK WORK always undoes all changes back to the start of the database LUW. Authorization Checks AUTHORITY-CHECK OBJECT <authorization object> ID <authority field 1> FIELD <field value 1>. ID <authority field 2> FIELD <field value 2>. ... ID <authority-field n> FIELD <field value n>. To check the authorization of the user of an ABAP program, use the AUTHORITYCHECK statement

India SAP CoE, Slide 82

SAP Locks
Why Set Locks?

Why Set Locks?


Program A Program B
Avoiding concurrent access to the same data

Program C

Tab 1 Tab 3 Tab 2

Tab 4 Tab 6 Tab 5

If several users are competing to access the same resource or resources, you need to find a way of synchronizing the access in order to protect the consistency of your data.

India SAP CoE, Slide 83

Lock Modules

Generating Lock Modules


Lock object
ESFLIGHT

Activate

Function module
ENQUEUE_ SFLIGHT (For setting locks )

Function module
DEQUEUE_ ESFLIGHT (For releasing locks )

Whenever a lock object is successfully activated, the system automatically generates one function module each for setting and releasing locks for entries in the table(s) specified in the lock object. The function modules have the following naming convention: ENQUEUE_<Lock-Object-Name> to set locks DEQUEUE_<Lock-Object-Name> to release locks

India SAP CoE, Slide 84

Interactive Process Flow

India SAP CoE, Slide 85

Program Program Flow Flowin inDetail DetailLists List


List Edit Goto System Help

SY-UCOMM %EX PRI P+ P...

DEMO: List ...

System programs F2

SY-UCOMM PICK
REPORT SAPBC405_... AT SELECTION. AT LINE LINE SELECTION.

If the report has a custom GUI and the user selects a menu option, the event AT USER-COMMAND is triggered. The function code assigned to the menu option can be evaluated using a CASE construct to determine which menu option was selected. If the user double-clicks on a report line, the AT LINE-SELECTION event is triggered. The event can also be triggered by single clicking on a report line and either pressing the Detail icon in the application tool bar, pressing F2, or entering the word PICK in the OK code field and pressing Enter.
India SAP CoE, Slide 86

Interactive Iists
Navigating Between Lists

Navigation Between Lists


DL 20

Up to 20 parallel detail lists can exist for each basic list. Each list has in its own individual memory area called a list buffer.

DL 2 DL 1

Basic list

double - click on line

India SAP CoE, Slide 87

Events: Overview

Events
*

Basic list

START -OF - SELECTION. GET ... . END -OF - SELECTION. TOP -OF - PAGE. * Detail lists

AT LINE -SELECTION.

AT USER -COMMAND.
TOP -OF - PAGE DURING LINE -SELECTION .

The events START-OF-SELECTION, GET, END-OF-SELECTION, TOP-OF-PAGE and END-OF-PAGE can be used only to create basic lists. Once you leave a basic list, these events are no longer processed. Detail lists are created using two basic events: AT LINE-SELECTION and AT USERCOMMAND. The event TOP-OF-PAGE DURING LINE-SELECTION is used to create headers for all detail lists.
India SAP CoE, Slide 88

Data Transport
Hide Area
HIDE: <f1>, <f2>, ... . DEMO: Data Transport: Hide Technique -------------------------------------------------------AA NEW YORK SAN FRANCISCO AZ ROME FRANKFURT AZ TOKYO ROME LH FRANKFURT NEW YORK REPORT sapbc405_ ilbd _hide . GET spfli FIELDS carrid connid cityfrom cityto . WRITE: / spfli -carrid , 10 spfli -cityfrom , (24) spfli -cityto . HIDE: spfli -carrid , spfli -connid . AT LINE - SELECTION. ...

HIDE Area

HIDE area of list level Line Field name 3 spfli -carrid 3 spfli -connid : : 6 spfli -carrid 6 spfli -connid : :

0 Value AA 0017 : LH 0400 :

The HIDE keyword is used to store data objects and their values so they can be made available when the User selects a report line. When a line is selected, the fields that were hidden are filled with the values that you hid for that line.

India SAP CoE, Slide 89

Line Selection: The HideHide Technique Line Selection : The Technique

DEMO: Data Transport:Hide Technique -------------------------------------------------------AA NEW YORK SAN FRANCI AZ ROME FRANKFURT AZ TOKYO ROME LH FRANKFURT NEW YORK

DEMO: Data Transport:Hide Technique -------------------------------------------------------LH 400 02.01.2002 1,332.00 DEM 03.28.2002 1,332.00 DEM 04.17.2002 1,332.00 DEM

The user selects a line for which data has been stored in the HIDE area. The runtime system evaluates field SY-LILLI to determine the selected line. The runtime system jumps to the point in the HIDE area where data for this line is stored. The runtime system then inserts all values stored for the selected line in the HIDE area into their corresponding fields. The runtime system processes the event AT LINE-SELECTION and its corresponding program processing block. A detail list is created.

SY-LILLI 6

5
REPORT SAPBC405_ILBD_HIDE . AT SELECTION . AT LINE LINE SELECTION. SELECT ... WHERE carrid = spfli-carrid LH AND connid = spfli-connid. 0400

HIDE area of list level 0 Line 3 3 : 6 6 : Field name spfli-carrid spfli-connid : spfli-carrid spfli-connid : Value AA 0017 : LH 0400 :

India SAP CoE, Slide 90

Field Selection

Field Selection

GET CURSOR FIELD <feld1> [VALUE <feld2>]. REPORT sapbc405_ ilbd _field_selection. DEMO: Field Selection -------------------------------------------------------CARRID CONNID CITYFROM AA 0017 NEW YORK AZ 0555 ROME AZ 0789 TOKYO LH 0400 FRANKFURT

DATA: ... , field_name (30), field_value (50). field_name(30), field_value(50). ... AT LINE - SELECTION. GET GET CURSOR CURSOR FIELD FIELD field_name field_name VALUE VALUE field_value field_value. . field_name. CASE field_name . WHEN 'SPFLI CARRID' . 'SPFLI - CARRID'. ... WHEN 'SPFLI CONNID' . 'SPFLI- CONNID'. ... ENDCASE.

DEMO: Field Selection LH: Lufthansa

DEMO: Field Selection LH 0400 19.05.2002 21.08.2002

GET CURSOR statement is used to create detail lists according to the cursor position. The parameter FIELD provides the name of an output field. The parameter VALUE provides the output value.

India SAP CoE, Slide 91

Reading and Modifying the List Line


READ - Reading a Line from a List Reads line number line of the list, usually after a line selection READ LINE line. READ LINE line OF CURRENT PAGE. READ LINE line OF PAGE pag READ CURRENT LINE MODIFY LINE n. Change a List Line INDEX idx - Changes the corresponding line in the list at list FIELD VALUE f1 FROM g1 ... fn FROM gn

level idx

WINDOW STARTING AT x1 y1 ENDING AT x2 y2. Displays the current secondary list as a modal dialog box only up to 20 windows

India SAP CoE, Slide 92

System Fields for Interactive System Fields for Interactive Listslist


SY SY-LILLI LILLI 1 1 2 2 3 3 4 4 SY SY-LINNO LINNO 5 5 6 6 7 7 8 8 9 9 10 10 1 1 2 2 3 3 4 4 2 SY SY-CUROW CUROW SY SY-CUCOL CUCOL 3 SY SY-CPAGE CPAGE 1 SY SY-PAGNO PAGNO

Basic list
SY SY-LSIND LSIND = =0 0 SY LISTI = 0 SY-LISTI = 0

DL 1
SY SY-LSIND LSIND = =1 1 SY SY-LISTI LISTI = = 0 0

DL 2
SY SY-LSIND LSIND = =2 2 SY LISTI = 1 SY-LISTI = 1

...

India SAP CoE, Slide 93

System Fields for Interactive Lists

SY-LSIND SY-LISTI SY-LILLI SY-CPAGE SY-CUCOL

Index for the current list Index of the last list displayed Absolute number of a selected line in the list displayed Number of the upper-most displayed line in the list displayed Number of the column in the window where the cursor was last positioned in the list displayed SY-CUROW Number of the line in the window where the cursor was last positioned in the list displayed SY-STACO Number of the first column displayed in the list displayed SY-STARO Number of the first visible line in the top displayed page (SY- PAGE) in the list displayed (not including header lines) SY-UCOMM Function code that triggered the interactive event in the list displayed SY-PFKEY Status of the list displayed

India SAP CoE, Slide 94

A Few More Points


Variants
Variants are input data which are filled in the selection screen and then saved so that at runtime the variant can be selected and then the entire selection screen is filled with the desired values. Background Processing When a program takes a long time to execute then one can execute the program in background so that a job is set up for that program. The job can be seen in transaction SM37. The job log gives the exact start time and the end time for the job. CATCH - Catching Runtime Errors CATCH SYSTEM-EXCEPTIONS except1 = rc1 ... exceptn = rcn. ENDCATCH. The CATCHENDCATCH block allows the programmer to catch ABAP runtime errors and assign these to a SY_SUBRC value Comments. Commented lines in the program start with asterisk (*) To comment a part of line use double codes ().

India SAP CoE, Slide 95

ABAP reports Classical and interactive


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 96

Simple Reports
Simple Reports

REPORT TEST. Initialization. Data : a type I value 10, b type I value 15, sum type I. start-of-selection. WRITE 'This is a statement *This is commented line *The write statement can also be written as. end-of-selection. WRITE 'This' & ' is ' & 'a statement'.
Sum = a + b. Write:/ sum.

India SAP CoE, Slide 97

Data Declaration
data: begin of it1 occurs 10, Name(10), Phno type i, end of it1. "has a header line

data it2 like it1 occurs 100. "doesn't have a header line data it3 like it1 occurs 100 with header line. "it does now

Name
Header

Phno

Internal Table Body

India SAP CoE, Slide 98

Data Declaration
DATA: PLAYER(35) TYPE C, NICKNAME(35), POINTS GAMES TYPE I AVERAGE(5) STARTER, ACQUIRED PLAYER(35) TYPE C NICKNAME ACQUIRED

Cont..

TYPE I. VALUE 10, TYPE P, TYPE D. VALUE CapGemini, LIKE PLAYER, LIKE SY-DATUM.

DATA:

DATA:

India SAP CoE, Slide 99

Data Declaration
CONSTANTS:TEAM1(20) TYPE C TEAM2 LIKE TEAM1 TOT_GAMES TYPE-POOLS Z400. TYPES: NAME(35) TYPE C, TEAMS(20) VALUE 76ers, VALUE Celtics, TYPE I

Cont..

VALUE 82.

TYPE C.

DATA:

PLAYER

TYPE NAME VALUE CapGemini, NICKNAME LIKE PLAYER.


TEAM1 TYPE TEAMS VALUE 76ers, TEAM2 LIKE TEAM1 VALUE Celtics.

CONSTANTS:

The CLEAR statement sets a field back to its initial value, not its default value.

India SAP CoE, Slide 100

Data Declaration

Cont..

Value Assignment DATA: TITLE(25), SORT_NAME(10), SALARY(10) TYPE N, CNVSALARY(10) TYPE N, GRID_LEVEL TYPE I.

MOVE President TO TITLE. MOVE 5 TO GRID_LEVEL. COMPUTE SALARY = 5000000. CNVSALARY = SALARY * 3. ADD 1000 TO SALARY.

India SAP CoE, Slide 101

Data Declaration

Cont..

Calculating Values.
DATA: COUNTER TYPE I, AMOUNT TYPE P VALUE 1000, SUM TYPE P, RESULT TYPE P, NUMBER(2) TYPE C VALUE 99, ROOT TYPE F. COUNTER = COUNTER + 2. RESULT = AMOUNT * COUNTER. SUM = RESULT + NUMBER COUNTER. RESULT = COUNTER * ( AMOUNT + NUMBER ). BREAK-POINT. Creates a breakpoints. ROOT = SQRT ( NUMBER + COUNTER ).

India SAP CoE, Slide 102

Select Statement

Select Statement.
Select * from bfpf into itab where bukrs = 0001 and belnr eq 00200689 gjahr gt 2005. Append itab. Clear itab. Endselect Select * from bfpf into table itab where bukrs = 0001 and belnr eq 00200689 gjahr gt 2005.

and

and

India SAP CoE, Slide 103

Select Statement

Cont..

Select Statement - Join. REPORT SELECT t1~carrid t1~connid t2~customid INTO (carrid, connid, custid) FROM sflight AS t1 INNER JOIN sbook AS t2 ON t1~carrid = t2~carrid WHERE t1~connid = t2~connid AND t1~fldate = t2~fldate. WRITE:/ carrid, connid, custid ENDSELECT.

India SAP CoE, Slide 104

Select Statement

Cont..

Select Statement FOR ALL ENTRIES.


Select * from BKPF into table it_bkpf where <conditions>. If it_bkpf[] is not initial. Select * from bseg into table it_bseg FOR ALL ENTRIES IN IT_BKPF WHERE BELNR = it_bkpf-belnr and BUKRS = it_bkpf-bukrs and GJAHR = it_bkpf-gjahr and BUZEI = it_bkpf-buzei.

Endif.

India SAP CoE, Slide 105

Field Symbols

Field Symbols REPORT demo_field_symbols_type . DATA: BEGIN OF line, col1(1) TYPE c, col2(1) TYPE c VALUE 'X', END OF line. FIELD-SYMBOLS <fs> LIKE line. ASSIGN line TO <fs>. MOVE <fs>-col2 TO <fs>-col1. WRITE:/ <fs>-col1

India SAP CoE, Slide 106

Internal Table
Internal Tables - Sorted REPORT TYPES: BEGIN OF line_type, f1, f2, END OF line_type. DATA: tab1 TYPE SORTED TABLE OF line_type WITH UNIQUE KEY f1 WITH HEADER LINE. tab1-f1 = Y. Tab1-f2 = 1. INSERT TABLE tab1. tab1-f1 = X. Tab1-f2 = 1. INSERT TABLE tab1. tab1-f1 = A. Tab1-f2 = 1. INSERT TABLE tab1. READ TABLE tab1 WITH TABLE KEY f1 = A. LOOP AT tab1. WRITE:/ tab1-f1, tab1-f2. ENDLOOP.

India SAP CoE, Slide 107

Internal Table
Internal Tables - Reading TYPES: BEGIN OF line_type, f1, f2, f3, END OF line_type.

Cont..

DATA: tab1 TYPE STANDARD TABLE OF line_type WITH KEY f1 f2, wa type line_type. wa-f1 = 'B'. wa-f2 = '5'. wa-f3 = '12.45'. READ TABLE tab1 FROM wa INTO wa. READ TABLE tab1 WITH TABLE KEY f1 = 'B' f2 = '5' INTO wa.

Work area wa

Wa before Wa after read


Internal Table tab1

India SAP CoE, Slide 108

Subroutines
TYPES: BEGIN OF LINE, COL1, COL2, END OF LINE. DATA: WA TYPE LINE, ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1, KEY(4) VALUE 'COL1'. WA-COL1 = 'X'. INSERT WA INTO TABLE ITAB. WA-COL1 = 'Y'. INSERT WA INTO TABLE ITAB. PERFORM DEMO USING ITAB. FORM DEMO USING P TYPE ANY TABLE. DATA: T_WA TYPE LINE. LOCAL VARIABLE FOR SUBROUTINE. READ TABLE P WITH TABLE KEY (KEY) = 'X' INTO WA. WRITE:/ T_WA-COL1. ENDFORM.

India SAP CoE, Slide 109

Subroutines
Data: begin of itab occurs, matnr like mara-matnr, mtart like mara-mtart, meins like mara-meins, End of itab. Perform get_data. Perform download_data. Form get_data. Select matnr mtart meins into table itab from mara up to 50 rows. Endform. Form download_data. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING FILENAME = 'c:\mara.txt' FILETYPE = 'ASC' TABLES DATA_TAB = itab. Endform.
India SAP CoE, Slide 110

Cont..

Catch - Endcatch
To code the first part of a CATCHENDCATCH block it is necessary to code CATCH SYSTEM EXCEPTIONS and specify one of the following: Error Class Specific error ID OTHERS, which traps all catchable runtime errors
DATA: [..] CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1. [..] MOVE char TO int. MOVE keyword to trigger CATCH [..] ENDCATCH. int type I, char(3) type C value ABC.

IF SY-SUBRC = 1. WRITE: / Conversion error has occurred. ENDIF.

India SAP CoE, Slide 111

Debugger
Execute

Run Completely Break Points Single Step

Variables
India SAP CoE, Slide 112

Debugger

Cont..
The scrollable field display contains the contents of up to eight fields. The contents of the three most important system fields are always displayed. This is the default display mode in the Debugger. See also Processing Fields Displays the contents of an internal table. This mode allows you to display and edit the entries in an internal table. See also Processing Internal Tables A scrollable display containing up to 30 breakpoints. Next to each breakpoint is a counter. You can also delete breakpoints in this display. See also Managing Dynamic Breakpoints You can set a watchpoint for a field so that the program is interrupted whenever the value of that field changes. This display mode contains a list of Watchpoints, the fields and programs to which they are assigned, the current values of the fields, and the conditions upon which the watchpoint is activated. See also Setting Watchpoints This mode displays the current sequence of events, and the sequence of calls up to the current breakpoint. The last active call is displayed at the top of the list; previous calls are listed in reverse chronological order. When an event (for example, START-OF-SELECTION) concludes, it is deleted from the display. This mode displays the structure of the program. It lists its events, subroutines, and modules, and shows which sections belong to which events. It also displays the section currently being processed. This mode displays the current Debugger settings. You can change the settings by selecting or deselecting various options. For further information, refer to Settings and Warnings

Fields

Table

Breakpoints

Watchpoints

Calls

Overview

Settings

India SAP CoE, Slide 113

Releasing Request
Releasing Your Transport Request SE09 Enter Your Login ID and view the Modifiable Requests Select Your Request and click on Release Directly.

India SAP CoE, Slide 114

ABAP reports Classical and interactive


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 115

Exercises - 1
Read a set of results from table EKPO. Create a selection screen with an input field for EKPO-EBELN (Document Number). Define a structure as a work area by referring to your table EKPO. Program a SELECT loop that reads the data specified by the user and places it in your work area. Using the WRITE statement within the SELECT loop, display the following fields: EBELP Item Number of Purchasing Document MATNR Material Number LGORT Storage Location MATKL Material Group MENGE Purchase order quantity MEINS Order Unit NETPR Net price To generate a line feed, precede the data object you want to display with the / character.Example:WRITE : / wa_EKPO-EBELP,

India SAP CoE, Slide 116

Exercises - 2
Create a list of all FI Documents between the dates entered by the user. Create a selection screen with an input field for BKPF-BUDAT (Document Date). Select BELNR (Document Number), BUKRS (Company Code) and GJAHR (Fiscal Year) from the table BKPF and correspondingly select BUZEI (Line item number), DMBTR (Amount). Within the loop, avail the vendor / customer a discount of 10% on DMBTR using the corresponding field of the work area. Append your work area to the internal table. Sort the internal table according to the net price. Display the following fields: BELNR Document Number BUKRS Company Code GJAHR Fiscal Year BUDAT Document Date BUZEI Document Item Number DMBTR Amount

India SAP CoE, Slide 117

Exercises - 3
Create a tabulated list of Vendors entered by the user. Create a selection screen with an input field for LFA1-LIFNR (Vendor). Select Vendors from the table LIFNR from the selection-screen. Display the list of vendors selected on the basic list. If the User chooses a particular Vendor Display this contact details with a HOTSPOT on his Name on a detailed list. If the user click in this hotspot call the transaction FBL2N (Vendor Balance) with the current fiscal year and skip the initial screen.

India SAP CoE, Slide 118

ABAP reports Classical and interactive


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 119

HelpMe

Tips and Tricks Additional Info

India SAP CoE, Slide 120

Tips and Tricks


Keep the Result Set Small

Minimize the Amount of Data Transferred


Minimize the Number of Data Transfers Minimize the Search Overhead Reduce the Database Load Use T-Code SE30 to view run time analysis of your program

For Example Code on each topic use T-Code ABAPDOCU.


Use Pretty Printer for code alignment. For SQL Trace Use T-Code ST05.

India SAP CoE, Slide 121

Additional Info

Use the below link for complete details on ABAP.


http://help.sap.com/saphelp_erp2004/helpdata/en/fc/eb2c46358411d1829f0000e829fbfe/frames et.htm

India SAP CoE, Slide 122

Anda mungkin juga menyukai