Академический Документы
Профессиональный Документы
Культура Документы
Learning Objectives
Agenda
Internal Tables
Strings, Field Symbols and
References
Coffee Break
Dynamic Token Specification
Program Generation
Summary
Q&A
Internal Tables
• Line Type
• Kind of Table
CARRID CONNID DISTANCE
• Key
• Kind of Uniqueness
AA 0017 2.572
LH 0400 6.162
LH 0400 6.162
access by index
QF 0005 1.000 5
SQ 0866 1.625
UA 0007 2.572 access by key
UA 0007
Any Table
Access n
LH 0400 6.162
LH 0400 6.162
<uniqueness> QF 0005 1.000
UNIQUE | NON-UNIQUE
SQ 0866 1.625
UA 0007 2.572
<key>
KEY <f1> ... <fn> |
DEFAULT KEY |
KEY TABLE_LINE
Standard tables
Processed mainly by index operations
Infrequent key operations (slow)
Operations with different keys
If RFC (Remote Function Call) functionality is required
Sorted tables
Access mainly by key (efficient)
Partial sequential processing (LOOP ... WHERE)
Infrequent index operations
Hashed tables
Access only by key (fast)
Key must be unique, no index operations possible
Syntax:
READ TABLE itab WITH name = 'Miller'
BINARY SEARCH.
2. page:
m
3. page:
4. page:
50
52
3. page
4. page
Table header
m 2. page
1 3 2 4 5 6 7 8 9 49 50 52 3. page
51
4. page
Free list
Hash function
Key Index in Hash array
Table header
Table body
Hash array 1 1. page
2
1
2 m 2. page
27 2
3. page
4. page
Empty table
8 bytes per table
Table body
C x L bytes (C = count of line, L = bytes per line)
Linear index
4 bytes per item
Tree-like index
approx. 6 bytes per item
Hash index
approx. 18 bytes per item (without DELETE/SORT)
approx. 30 bytes per item (with DELETE/SORT)
Goto ->
Display data object ->
Internal table
Settings ->
Memory Display on/off
Goto ->
Display condition ->
Memory use
Fill the three tables using three DO loops with the number of
entries specified by the PARAMETER. Calculate the run time of
all three loops and write the result devided by the count of
entries to the ABAP list for every table.
Now use a DO loop to READ WITH KEY each entry of the three
tables and calculate the run time for every table.
At the end, use a DO loop to READ with INDEX each entry of the
standard and sorted table and calculate the run time.
Strings,
Field Symbols, References
String Types
DATA:
str TYPE STRING,
xstr TYPE XSTRING.
Strings
Strings in ABAP:
Strings
Constructing strings
MOVE
CONCATENATE
...
Processing strings
SEARCH, REPLACE
SHIFT, CONDENSE
CA,CO,CS,CP
Strings
Keep in mind
Substr = str+5(10).
Strings
Keep in mind
STRUC2 is deep.
DATA: BEGIN OF STRUC2,
a(3) TYPE N, 1 2 3 String-Reference 4 5 6
b TYPE STRING,
c(3) TYPE N,
END OF STRUC2. A B C D E F G H I J
Goto ->
Display data object ->
String
Goto ->
Display condition ->
Memory use
Strings,
Field Symbols, References
Field Symbols
DATA:
DATA:
Text(20)
Text(20) TYPE
TYPE CC VALUE
VALUE 'Hello
'Hello world'.
world'.
FIELD-SYMBOLS:
FIELD-SYMBOLS:
<fs>
<fs> TYPE
TYPE ANY.
ANY.
ASSIGN
ASSIGN Text
Text TO
TO <fs>.
<fs>.
WRITE
WRITE // <fs>.
<fs>.
wa
Casting variants:
TYPES:
TYPES: MY_TYPE(9)
MY_TYPE(9) TYPE
TYPE C.
C.
DATA:
DATA: Field9(9)
Field9(9) TYPE
TYPE C,
C,
Field10(10)
Field10(10) TYPE
TYPE CC VALUE
VALUE '1234567890',
'1234567890',
TypeName(7)
TypeName(7) TYPE
TYPE CC VALUE
VALUE 'MY_TYPE'.
'MY_TYPE'.
FIELD-SYMBOLS:
FIELD-SYMBOLS: <fs>
<fs> TYPE
TYPE ANY.
ANY.
TypeName
TypeName == 'MY_TYPE'.
'MY_TYPE'.
Casting to dynamic type ASSIGN
ASSIGN Field10
Field10 TO
TO <fs>
<fs> CASTING
CASTING TYPE
TYPE (TypeName).
(TypeName).
Strings,
Field Symbols, References
Data References
Save pointers
Containers for arbitrary data objects e.g., tables of data references
Can be defined in the dictionary
Syntax
CREATE
CREATE DATA
DATA dref
dref TYPE
TYPE type.
type.
CREATE
CREATE DATA
DATA dref
dref TYPE
TYPE (typename).
(typename).
CREATE
CREATE DATA
DATA dref
dref TYPE
TYPE TABLE
TABLE OF
OF (typename).
(typename).
CREATE
CREATE DATA
DATA dref
dref LIKE
LIKE field.
field.
TYPES:
TYPES: BEGIN
BEGIN OF
OF struc,
struc,
aa TYPE
TYPE i,
i,
bb TYPE
TYPE cc LENGTH
LENGTH 8,
8, dref 36
36 ABC
ABC
END
END OF
OF STRUC.
STRUC.
DATA:
DATA: dref
dref TYPE
TYPE REF
REF TO
TO DATA,
DATA, <str>
<str>
tname
tname TYPE
TYPE string,
string,
str
str TYPE
TYPE struc,
struc,
int
int TYPE
TYPE i.
i.
FIELD-SYMBOLS:
FIELD-SYMBOLS: <int>
<int> TYPE
TYPE i,
i, 55
<str>
<str> TYPE
TYPE struc,
struc,
<f>
<f> TYPE
TYPE any.
any.
<int>
<int>
CREATE DATA dref TYPE struc.
ASSIGN dref->* TO <str>.
<str>-a = 36. <str>-b = 'ABC'.
GET REFERENCE OF int INTO ref. INSERT ref INTO TABLE itab.
GET REFERENCE OF float INTO ref. INSERT ref INTO TABLE itab.
GET REFERENCE OF name INTO ref. INSERT ref INTO TABLE itab.
Generic Types
Generic length C, N, X, P
CSEQUENCE, XSEQUENCE, CLIKE
ANY TABLE
TIP: If you need more information about the syntax and the
semantics of an ABAP statement use Online-Help by
pressing F1 and entering the first word of the statement.
Coffee Break
** Static
Static SORT
SORT statement
statement
SORT
SORT itab
itab BY
BY comp.
comp.
** Dynamic
Dynamic SORT
SORT statement
statement
name
name == 'COMP'.
'COMP'.
...
...
SORT
SORT itab
itab BY
BY (name).
(name).
** Dynamic
Dynamic ASSIGN
ASSIGN to
to constant
constant bb
name
name == 'B'.
'B'.
ASSIGN
ASSIGN (name)
(name) TO
TO <i>.
<i>.
WRITE:
WRITE: <i>.
<i>. "=2
"=2
TYPES:
TYPES: BEGIN
BEGIN OF
OF struc,
struc,
aa TYPE
TYPE i,
i,
bb TYPE
TYPE p,
p,
END
END OF
OF struc.
struc.
DATA:
DATA: dref
dref TYPE
TYPE REF
REF TO
TO DATA.
DATA.
FIELD-SYMBOLS:
FIELD-SYMBOLS: <dobj>
<dobj> TYPE
TYPE any.
any.
PERFORM
PERFORM DoSomething
DoSomething USING
USING dref
dref 'SFLIGHT'.
'SFLIGHT'.
ASSIGN
ASSIGN dref->*
dref->* to
to <dobj>.
<dobj>.
...
...
FORM
FORM DoSomething
DoSomething USING
USING dref
dref TYPE
TYPE REF
REF TO
TO DATA
DATA
tname
tname TYPE
TYPE string.
string.
** Create
Create aa data
data object
object of
of type
type 'tname'
'tname'
CREATE
CREATE DATA
DATA dref
dref TYPE
TYPE (tname).
(tname).
...
...
ENDFORM.
ENDFORM.
DATA:
DATA: itab
itab TYPE
TYPE TABLE
TABLE OF
OF ...,
...,
key1
key1 TYPE
TYPE string,
string,
key2
key2 TYPE
TYPE string,
string, ...
...
** Sort
Sort table
table dynamically
dynamically to
to set
set up
up aa dynamic
dynamic READ
READ with
with binary
binary search
search
SORT
SORT itab
itab BY
BY (key1)
(key1) (key2).
(key2).
READ
READ TABLE
TABLE itab
itab INTO
INTO wa
wa WITH
WITH KEY
KEY (key1)
(key1) == val1
val1 (key2)
(key2) == val2
val2
BINARY
BINARY SEARCH.
SEARCH.
TYPES:
TYPES: cond(72)
cond(72) TYPE
TYPE c.
c.
DATA:
DATA: wa
wa TYPE
TYPE spfli,
spfli,
condtab
condtab TYPE
TYPE TABLE
TABLE OF
OF cond.
cond.
** Fill
Fill the
the condition
condition table
table
APPEND
APPEND 'CARRID
'CARRID == ''LH''
''LH'' AND'
AND' TO
TO condtab.
condtab.
APPEND
APPEND 'CITYTO
'CITYTO == ''NEW
''NEW YORK''.'
YORK''.' TO
TO condtab.
condtab.
** Database
Database fetch
fetch with
with aa dynamic
dynamic WHERE
WHERE condition
condition
SELECT
SELECT ** FROM
FROM spfli
spfli INTO
INTO wa
wa WHERE
WHERE (condtab).
(condtab).
WRITE:
WRITE: // wa-carrid,
wa-carrid, wa-connid,
wa-connid, wa-cityfrom,
wa-cityfrom, wa-cityto.
wa-cityto.
ENDSELECT.
ENDSELECT.
DATA:
DATA: pname
pname TYPE
TYPE string,
string,
fname
fname TYPE
TYPE string.
string.
fname
fname == 'DO_SOMETHING'.
'DO_SOMETHING'.
pname
pname == 'UTILITIES'.
'UTILITIES'.
** External
External PERFORM
PERFORM
PERFORM
PERFORM (fname)
(fname) IN
IN PROGRAM
PROGRAM (pname)
(pname) USING
USING 999.
999.
Program Generation
..
Result .....
..... Persistent
..
generation
.....
by another process
..
Result .....
Program Generation
DATA:
code TYPE TABLE OF string,
prog(8) TYPE c,
msg(120) TYPE c,
lin(10) TYPE c,
wrd(10) TYPE c,
off(3) TYPE c.
IF sy-subrc <> 0.
WRITE: / 'Error during generation in line', lin,
/ msg, / 'Word:', wrd, 'at offset', off.
ENDIF.
DATA:
Code TYPE TABLE OF string.
CONSTANTS:
Rep(40) VALUE 'ZDYN1'.
Static statement
SELECT CARRID CITYTO CITYFROM
INTO wa
FROM SPFLI ~ 200 ms
WHERE CARRID = 'UA' AND
CITYFROM = 'NEW YORK' AND
CITYTO = 'SAN FRANCISCO'.
Dynamic statement
SELECT (ItabSelect)
INTO CORRESPONDING FIELDS OF wa ~ 300 ms
FROM (TabName)
WHERE (ItabWhere).
Code generation
SELECT CARRID CITYTO CITYFROM
INTO wa
FROM SPFLI ~ 25 000 ms
WHERE CARRID = 'UA' AND
CITYFROM = 'NEW YORK' AND
CITYTO = 'SAN FRANCISCO'.
SAP AG 2003, TechED_Basel / ABAP 254, Björn Mielenhausen/ 59
TIP: Use GET RUN TIME FIELD to get relative runtime (see
Exercise: Performance Analysis of Internal Tables).
Summary
Internal tables
Properties
Table kind
Strings
Field symbols
Copy free loop
Casting
References
Dynamic creating of data objects
Summary
Program generation
Transient
Persistent
Further Information
Online-Documentation:
Transaction ABAPDOCU
Books:
„ABAP Objects“ by Horst Keller
Further Information
Public Web:
www.sap.com
SAP Customer Services Network: www.sap.com/services/
Consulting Contact
Roy Wood, VP SAP Consulting
Questions?
Q&A
Feedback
Thank You !
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express
permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other
software vendors.
Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are registered trademarks of Microsoft
Corporation.
IBM®, DB2®, DB2 Universal Database, OS/2®, Parallel Sysplex®, MVS/ESA, AIX®, S/390®, AS/400®, OS/390®,
OS/400®, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere®, Netfinity®, Tivoli®, Informix
and Informix® Dynamic ServerTM are trademarks of IBM Corporation in USA and/or other countries.
ORACLE® is a registered trademark of ORACLE Corporation.
UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group.
Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®, MultiWin® and other
Citrix product names referenced herein are trademarks of Citrix Systems, Inc.
HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World Wide Web Consortium,
Massachusetts Institute of Technology.
JAVA® is a registered trademark of Sun Microsystems, Inc.
JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and
implemented by Netscape.
MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One.
SAP, R/3, mySAP, mySAP.com, xApps, xApp and other SAP products and services mentioned herein as well as their
respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all
over the world. All other product and service names mentioned are the trademarks of their respective companies.