17
ABAP Course André Bögelsack, Valentin Nicolescu 1 ABAP Course Chapter 4 – Database accesses ecturer: André Bögelsack, UCC Technische Universität München uthor: Valentin Nicolescu, André Bögelsack

Abap course chapter 4 database accesses

  • Upload
    mkpatil

  • View
    2.797

  • Download
    2

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 1

ABAP Course

Chapter 4 – Database accesses

Lecturer: André Bögelsack, UCC Technische Universität MünchenAuthor: Valentin Nicolescu, André Bögelsack

Page 2: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 2

Copyright 2008 UCC TU München All rights reserved

Weitergabe und Vervielfältigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrückliche schriftliche Genehmigung durch HCC TU München nicht gestattet. In dieser Publikation enthaltene Informationen können ohne vorherige Ankündigung geändert werden.

Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® und SQL Server® sind eingetragene Marken der Microsoft Corporation. IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®, S/390®, AS/400®, OS/390® und OS/400® sind eingetragene

Marken der IBM Corporation. ORACLE® ist eine eingetragene Marke der ORACLE Corporation. INFORMIX®-OnLine for SAP und Informix® Dynamic ServerTM sind eingetragene Marken der Informix Software Incorporated. UNIX®, X/Open®, OSF/1® und Motif® sind eingetragene Marken der Open Group. Citrix®, das Citrix-Logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®, MultiWin® und andere hier erwähnte

Namen von Citrix-Produkten sind Marken von Citrix Systems, Inc. HTML, DHTML, XML, XHTML sind Marken oder eingetragene Marken des W3C®, World Wide Web Consortium, Massachusetts Institute of

Technology. JAVA® ist eine eingetragene Marke der Sun Microsystems, Inc. JAVASCRIPT® ist eine eingetragene Marke der Sun Microsystems, Inc., verwendet unter der Lizenz der von Netscape entwickelten und

implementierten Technologie. SAP, SAP Logo, R/2, RIVA, R/3, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit,

mySAP, mySAP.com und weitere im Text erwähnte SAP-Produkte und -Dienstleistungen sowie die entsprechenden Logos sind Marken oder eingetragene Marken der SAP AG in Deutschland und anderen Ländern weltweit. MarketSet und Enterprise Buyer sind gemeinsame Marken von SAP Markets und Commerce One.

Alle anderen Namen von Produkten und Dienstleistungen sind Marken der jeweiligen Firmen. Die Verwendung der Screenshots wurde mit dem jeweiligen Eigner abgesprochen.

Page 3: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 3

Agenda

1. Data dictionary2. SAP flight example3. Database operations in SAP4. SAP OpenSQL5. Types of database changes6. Types of entry help

Page 4: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 4

Data dictionary

• Data dictionary = global directory for data types• Assignment of help texts and explanations for data types in

different languages• ERM can be shown as a figure automatically• Most important objects: structure, table, data element and

domain

Page 5: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 5

Data dictionary

ZY_ID

ZY_ID

INT4

ZZ_ID

Domain

Data element

Data type

Field ZY_ID ZZ_ID

Structure Field

Field

Field

Table

Page 6: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 6

Data dictionary

• Menu path: Tools • ABAP Workbench • Development • Dictionary

• TA SE11• View, edit, delete, create tables, data types, domains definitions

etc.• Tables and views from the ABAP dictionary represent tables and

views from the database• User interface are generated automatically when changing views,

tables etc.• Table may be changed after they are created without losing data• SAP tables may be extended by APPEND structures

Page 7: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 7

Data browser

• Menu path: Tools • ABAP Workbench • Overview • Data Browser

• TA SE16• View table content• Add new entries to tables when adding is permitted for the table• Browse the entry help table content• Copy table content to transport request• Download table content

Page 8: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 8

Overview about all objects• Database table• View• Data type

– Data element– Structure– Database table– Table types– Views– Class / interface

• Type group• Domain• Search help• Lock object

Page 9: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 9

Visualization

• Foreign key relationships can be visualized in data dictionary• Table SFLIGHT

Page 10: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 10

SAP flight example

• Created and maintained by SAP to demonstrate database operations

• Contains exercise data for airline, flight connection number, flight date, airfare etc.

• Report for data generation: S_FLIGHT_MODEL_DATA_GENERATION

• SAP trainings, examples from books build refer to the flight example

Page 11: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 11

SAP flight example – table structure

MANDT

SPFLI

Connection Flight Reservation Plane

SFLIGHT SBOOK SAPLANE

CARRID

CONNID

AIRPFROM

AIRPTO

CITYFROM

CITYTO

COUNTRYFR

COUNTRYTO

MANDT

CARRID

CONNID

FLDATE

SEATSMAX

SEATSOCC

PRICE

CURRENCY

PLANETYPE

MANDT

CARRID

CONNID

FLDATE

BOOKID

CUSTOMID

LUGGWEIGH

WUNIT

CANCELLED

MANDT

PLANETYPE

SEATSMAX

TANKCAP

CAP_UNIT

WEIGHT

WIE_UNIT

OP_SPEED

SPEED_UNIT

Page 12: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 12

SAP OpenSQL• Independent from database

Application Server

ABAP-Interpreter DB-Interface

Database Server

SQL-Database

Data

Select * from

Exec SQL. Select * fromEnd Exec.

OpenSQL Native SQL

DB data DB data

Native SQL

DB data

Page 13: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 13

OpenSQL instructions

• Select:– SELECT / SELECT SINGLE– * / field 1 ..field n / – FROM table / view– INTO structure / internal table– WHERE condition

• Aggregation:– MAX, MIN, AVG– SUM, COUNT

• Joins:– Left outer join– Inner join– View

Page 14: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 14

Procedure for database access

General:• Be specific to decrease the load on the database• Access to database takes 10,000 time longer than access to buffers• Avoid table scans, use indexes

Procedure:1. Read database data into internal tables

• Internal tables are tables for holding data during runtime2. Change data per row

• Use workareas to hold one row of the table and change data in the workarea

3. Write changes back to database

Page 15: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 15

Procedure for database accessInternal tables and workareas:

Database

AA 0017LH 0400

LH 0400 Workarea(one row)

Internal table(selected content)

Database table(whole content)

wa_spfli

it_spfli

• Use the workarea to modify one data set

• Use the internal table to store the selected database content temporarily

• Internal tables are deleted after program is finished

• Use the database to read/write data

Page 16: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 16

Types of database changes

Modify instruction:MODIFY <dbtable> [CLIENT SPECIFIED] FROM <workarea>.MODIFY <dbtable> [CLIENT SPECIFIED] FROM TABLE <internaltable>

• Modify = Update – the command updates the database table if the database table already contains dataset

• Modify = Insert – the command inserts new datasets into the database table

Delete instruction:DELETE FROM <dbtable> WHERE [SQL statement].

Page 17: Abap course   chapter 4 database accesses

ABAP Course André Bögelsack, Valentin Nicolescu 17

Entry help• Entry help uses a table in the background• Predefined entry help for a table