chapter 05_retrieving data with select statements

14
IBM Global Business Services © IBM Corporation 2013 Retrieving Data with the SELECT Statement | Dec-2008 Retrieving Data with SELECT Statements

Upload: bakkalibilal

Post on 24-Dec-2015

9 views

Category:

Documents


0 download

DESCRIPTION

Chapter 05_Retrieving Data With SELECT Statements

TRANSCRIPT

IBM Global Business Services

© IBM Corporation 2013Retrieving Data with the SELECT Statement |

Dec-2008

Retrieving Data with SELECT Statements

IBM Global Business Services

© IBM Corporation 20132 Dec-2008Retrieving Data with the SELECT Statement |

Objectives

The participants will be able to: Retrieve information from the database using Open SQL.

Create basic Select statements for use in ABAP Code.

Describe the system field SY-SUBRC and properly use it in an ABAP Program.

IBM Global Business Services

© IBM Corporation 20133 Dec-2008Retrieving Data with the SELECT Statement |

DB

Retrieving Information From the Database

Data

John SmithMary

Stiles

Structured Query Language (SQL)----------------------------------------1. Data Manipulation Language (DML)2. Data Definition Language (DDL)3. Data Control Language (DCL)

IBM Global Business Services

© IBM Corporation 20134 Dec-2008Retrieving Data with the SELECT Statement |

Open SQL

Portable across various databases

Open SQL - a subset of standard SQL

IBM Global Business Services

© IBM Corporation 20135 Dec-2008Retrieving Data with the SELECT Statement |

The Basic SELECT Statement

DB

Mary Stiles

John Smith

Work Area

SELECT *FROM <table name>

[…..]

ENDSELECT.

IBM Global Business Services

© IBM Corporation 20136 Dec-2008Retrieving Data with the SELECT Statement |

Example Using the SELECT Statement

DATA: WA_KNA1 TYPE KNA1.

SELECT *

FROM KNA1

INTO WA_KNA1.

WRITE: / WA_KNA1-KUNNR, WA_KNA1-NAME1.

ENDSELECT.

IBM Global Business Services

© IBM Corporation 20137 Dec-2008Retrieving Data with the SELECT Statement |

The SELECT Statement with a WHERE Clause

DATA: WA_KNA1 TYPE KNA1.

SELECT *

FROM KNA1

INTO WA_KNA1

WHERE KTOKD = ‘0001’.

WRITE: / WA_KNA1-KUNNR, WA_KNA1-NAME1.

ENDSELECT.

IBM Global Business Services

© IBM Corporation 20138 Dec-2008Retrieving Data with the SELECT Statement |

SY-SUBRC

DATA: WA_KNA1 TYPE KNA1.

SELECT *

FROM KNA1

INTO WA_KNA1

WHERE KTOKD = ‘0001’.

WRITE: / WA_KNA1-KUNNR, WA_KNA1-NAME1.

ENDSELECT.

IF SY-SUBRC <> 0.

WRITE: / ‘No records found.’.

ENDIF.

IBM Global Business Services

© IBM Corporation 20139 Dec-2008Retrieving Data with the SELECT Statement |

The INTO Clause

DATA: WA_KNA1 TYPE KNA1.

SELECT KUNNR

NAME1

FROM KNA1

INTO (WA_KNA1-KUNNR, WA_KNA1-NAME1).

WRITE : / WA_KNA1-KUNNR, WA_KNA1-NAME1.

ENDSELECT.

IF SY-SUBRC <> 0.

WRITE: / ‘No records found.’.

ENDIF.

IBM Global Business Services

© IBM Corporation 201310 Dec-2008Retrieving Data with the SELECT Statement |

INTO CORRESPONDING-FIELDS

DATA: WA_KNA1.

SELECT KUNNR NAME1FROM KNA1INTO CORRESPONDING-FIELDS OF WA_KNA1.WRITE : / WA_KNA1-KUNNR, WA_KNA1-NAME1.ENDSELECT.

IF SY-SUBRC <> 0.

WRITE: / ‘No records found.’.

ENDIF.

IBM Global Business Services

© IBM Corporation 201311 Dec-2008Retrieving Data with the SELECT Statement |

Demonstration

Selection of data from a database table, checking sy-subrc and displaying the values in a report.

IBM Global Business Services

© IBM Corporation 201312 Dec-2008Retrieving Data with the SELECT Statement |

Practice

Selection of data from a database table, checking sy-subrc and displaying the values in a report.

IBM Global Business Services

© IBM Corporation 201313 Dec-2008Retrieving Data with the SELECT Statement |

Summary

SQL has three main components: Data Manipulation Language (DML):

Data Definition Language (DDL):

Data Control Language (DCL):

The DML provides the four basic data operations: Select (retrieve)

Insert

Update

Delete

Open SQL is a subset of standard SQL with a specific syntax recognised by ABAP.

IBM Global Business Services

© IBM Corporation 201314 Dec-2008Retrieving Data with the SELECT Statement |

Questions

What is SQL ? And What are different types of SQL ?

How values can be retrieved from a database table ?

Why SY-SUBRC check is required in the program ?