selecting and working with data internal tables again l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Selecting and Working with Data (Internal Tables Again) PowerPoint Presentation
Download Presentation
Selecting and Working with Data (Internal Tables Again)

Loading in 2 Seconds...

play fullscreen
1 / 35

Selecting and Working with Data (Internal Tables Again) - PowerPoint PPT Presentation


  • 223 Views
  • Uploaded on

Selecting and Working with Data (Internal Tables Again). MINS298c Fall 1998 Chapters 10-12. Overview. Subroutines Internal Tables Again Select all, some, part Working with it once you got it Loop Read Forms Study Hints. Subroutines (Normal Scope). Line . Program DATA A, B, C.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Selecting and Working with Data (Internal Tables Again)' - Ava


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overview
Overview
  • Subroutines
  • Internal Tables Again
  • Select
    • all, some, part
  • Working with it once you got it
    • Loop
    • Read
  • Forms
  • Study Hints
subroutines normal scope
Subroutines (Normal Scope)

Line

Program

DATA A, B, C

According to normal

rules of “scope,” which

Write statements are

legal and which are not?

1

2

3

4

5

6

Write A

Write F

Form

DATA X, Y, Z

Write A

Write F

Form

DATA D, E, F

Write A

Write F

subroutines
Subroutines
  • Defined by FORM and ENDFORM
  • Executed with PERFORM verb
  • Can call by value or call by reference
    • by reference is implied
    • VALUE clause passes by value
  • ABAP does number and type checking at runtime
example
Example

ASSUME: x, y, and z are integer and

x = 4; y = 5; z =10

Write x, y, z.

Perform add_em changing value(x) y changing z.

Write x, y, z.

Form add_em a1 a2 changing a3.

a1 = a1 + 1.

a2 = a2 + 2.

a3 = a1 + a2.

internal tables
Internal Tables
  • TABLES defines which external database table your program uses
  • OCCURS statement creates an internal table
  • The clause WITH HEADER LINE creates a work area (WA) structure defined like the table
slide7

Header lines

tables flight

data: my_flight like flight occurs 0 times

with header line.

my program

flight table

slide8

Header lines

tables flight

data: my_flight like flight occurs 0 times

with header line.

my program

flight

flight table

slide9

Header lines

tables flight

data: my_flight like flight occurs 0 times

with header line.

my program

flight

flight table

my_flight

[my_flight]

getting data
Getting Data
  • SELECT … INTO
  • SELECT … APPENDING
  • INSERT … INDEX n
  • MOVE
slide11

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide12

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide13

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide14

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide15

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide16

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide17

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

slide18

SELECT … INTO

SELECT * FROM FLIGHT

INTO TABLE MY_FLIGHT.

my program

flight

flight table

my_flight

[my_flight]

working backwards
Working Backwards

Given the code below, what are the likely data, table or type statements required.

Identify the tables, the WAs, and data types

SELECT * FROM CUSTOMERS.

MOVE-CORRESPONDING CUSTOMERS TO CUSTOMER_CITIES.

APPEND CUSTOMER_CITIES.

ENDSELECT.

select and the where clause
SELECT and the WHERE clause
  • The WHERE clause limits the records selected to those matching the condition(s).
  • In general, a condition is composed of

table-name operator value

  • Standard Operators
    • eq, ne, lt, le, gt, ge
  • New Operators
    • between, like, in (list), selopt (Select-Option)
where examples
WHERE Examples

WHERE table-name operator value

WHERE order_date = ‘19990101’

WHERE cust_name like ‘E%’

WHERE cust_name line ‘B_ll’

WHERE cust_name like ‘E%’ AND

order_date = ‘19990101’

select statistics
SELECT statistics
  • System will keep track of and report some basic statistics based upon your SELECT statement
  • Statistics
    • COUNT counts valid records
    • MAX, MIN, AVG, SUM results on numeric fields
  • Usage
    • SELECT COUNT(*) FROM customers
    • SELECT MAX(inv-owed) FROM invoices
header vs table
Header vs Table

SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.

SELECT SINGLE * FROM CUSTOMERS WHERE ID = ‘00000017’.

All_Customers

Header

customers

Body

All_Customers

Header

customers

Body

selecting fields
Selecting Fields
  • SELECT db-field1 db-field2

INTO (itab-field1, itab-field2)

FROM db-table.

SELECT id name

INTO (cid,cname)

FROM customers

cid, cname

selecting fields25
Selecting Fields
  • ABAP uses the domains or data to permit selections by the user
  • Identify the variables you wish filled in and ABAP builds the interface at runtime
  • SELECT-OPTIONS command
how to work with internal tables
How to Work with Internal Tables
  • Sorting
    • SORT itab
    • SORT itab BY field1 field2 … .
  • Looping
    • uses header line or INTO clause
    • LOOP AT itab.
    • can be nested
    • can be selective
  • Read
sort itab by field1 field2
SORT itab BY field1 field2 … .

SORT my_table BY field1 field2 DESCENDING

field1 field2

ABC

ABC

ABC

DEF

XYZ

XYZ

XYZ

3

2

1

8

5

3

1

loop at itab
LOOP AT itab.

LOOP AT My_table.

WRITE: / My_Table-field1

ENDLOOP.

my_table

[my_table]

sy-tabix

loop at itab29
LOOP AT itab.

LOOP AT My_table.

WRITE: / My_Table-field1

ENDLOOP.

my_table

[my_table]

sy-tabix

loop at itab30
LOOP AT itab.

LOOP AT My_table.

WRITE: / My_Table-field1

ENDLOOP.

my_table

Field1

[my_table]

sy-tabix

loop at itab into wa
LOOP AT itab INTO wa.

LOOP AT My_table INTO holder.

WRITE: / My_Table-field1

ENDLOOP.

holder

[my_table]

sy-tabix

loop at itab into wa where condition
LOOP AT itab INTO waWHERE condition.

LOOP AT My_table INTO holder

WHERE amount_owed > ‘1000’.

WRITE: / My_Table-field1

ENDLOOP.

holder

[my_table]

sy-tabix

read table itab
READ TABLE itab
  • WITH KEY field condition
    • finds first occurrence of key field which matches the condition
    • can use BINARY SEARCH clause for binary search
  • INDEX n
    • direct read of the record at the location n
study hints
Study Hints
  • Concepts based
    • structures, fields, tables
    • multi-language
  • Verb basics
  • Types
  • Tables
    • with and w/o header lines
    • how to get data in
    • how to get data out
  • Simple loops
in class assignment
In Class Assignment
  • Write a program to identify the following information about the TABLE sflight:
    • average prices of tickets
    • the highest and lowest tickets available
    • number of records in the table.