report layout report heading report body column heading report title

168
Report Layout Report Heading Report Body Column Heading Report Title

Upload: hector-clyde-mclaughlin

Post on 13-Dec-2015

237 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Report Layout Report Heading Report Body Column Heading Report Title

Report Layout

Report Heading

Report Body

Column Heading

Report Title

Page 2: Report Layout Report Heading Report Body Column Heading Report Title

Standard Page Heading

Standard Page Heading

Execute

Page 3: Report Layout Report Heading Report Body Column Heading Report Title

Report Statement : Standard Report Statement : Standard HeadingHeading

REPORT <Report Name> [NO STANDARD PAGE HEADING].

REPORT ztest1 NO STANDARD PAGE HEADING.

Page 4: Report Layout Report Heading Report Body Column Heading Report Title

No Standard Page Heading

Execute

Page 5: Report Layout Report Heading Report Body Column Heading Report Title

WRITE …Column Number…

WRITE: 10 ‘Hello’, 50 ‘World’.

Page 6: Report Layout Report Heading Report Body Column Heading Report Title

Report Statement : Line SizeReport Statement : Line Size

REPORT <Report Name> [LINE-SIZE no. of columns].

REPORT ztest LINE-SIZE 255 .

sy-linsz

Page 7: Report Layout Report Heading Report Body Column Heading Report Title

Exercise

Column : 50

Column : 170

Page 8: Report Layout Report Heading Report Body Column Heading Report Title

WRITE StatementWRITE Statement

*Write data WRITE ‘Hello World’.

WRITE : ‘OK’ , ‘Test data’.WRITE: /15(10) ‘ABCDEFGHIJKLMNOPQ’.WRITE /20 ‘Test data’.

Page 9: Report Layout Report Heading Report Body Column Heading Report Title

Breaking to a New LineBreaking to a New Line

*Write dataWRITE: / ‘First Line ’, ‘Data 1’, / ‘Second Line’,‘Data 2 ’, /(20 ) ‘Third Line’,‘Data 3 ’, /35 ‘Fourth Line’,‘Data 4 ’.

sy-colno

Page 10: Report Layout Report Heading Report Body Column Heading Report Title

Exercise

Column : 50Line : 1 Column :

170Line : 2

Page 11: Report Layout Report Heading Report Body Column Heading Report Title

Creating Lists ABAP statement that create list

WRITE ULINE SKIP

The complete report list will appears automatically at the end of the processing block

Page 12: Report Layout Report Heading Report Body Column Heading Report Title

List BufferList Buffer

Dialog WP

TaskHandler

Dynpro Processor

ABAP Processor

Local Memory

Memory Space

DB Interface

List Buffer

WRITE,SKIP,ULINE

User Context

Page 13: Report Layout Report Heading Report Body Column Heading Report Title

Inserting Blank Lines(SKIP)Inserting Blank Lines(SKIP)

*Skip StatementSKIP.WRITE : ‘Hello World’, sy-linno.SKIP.WRITE: ‘Test 1’.SKIP 5.WRITE : ‘Test 2’.

SKIP TO LINE 20. WRITE ‘This is line 20’.

Page 14: Report Layout Report Heading Report Body Column Heading Report Title

NEW-LINENEW-LINE

WRITE ‘Hello World’.NEW-LINE.WRITE ‘OK’.

WRITE ‘Hello World’.WRITE / ‘OK’.

=

Page 15: Report Layout Report Heading Report Body Column Heading Report Title

Exercise

Column : 50Line : 5

Column : 170Line : 7

Page 16: Report Layout Report Heading Report Body Column Heading Report Title

Inserting Horizontal Inserting Horizontal Lines(ULINE)Lines(ULINE)

* UlineWRITE: :::::: ::::: ’.ULINE /1(20).WRITE: /(20) sy-uline.WRITE: / sy-vline, 20 sy-vline.ULINE /(20).WRITE : / ‘This is an underlin:’.::::E.

Page 17: Report Layout Report Heading Report Body Column Heading Report Title

Frame Example

Page 18: Report Layout Report Heading Report Body Column Heading Report Title

FrameFrame

ULINE: /1(45).WRITE: /1 sy-vline, 'Column #1', 15 sy-vline, 'Column #2', 30 sy-vline, 'Column #3', 45 sy-vline.ULINE /(45).

Page 19: Report Layout Report Heading Report Body Column Heading Report Title

Exercise I

sy-datum

sy-uzeit

8020 55 80

Page 20: Report Layout Report Heading Report Body Column Heading Report Title

FORMAT StatementFORMAT Statement

FORMAT [COLOR <color>].

[COLOR OFF].

Page 21: Report Layout Report Heading Report Body Column Heading Report Title

FORMAT StatementFORMAT Statement

1FORMAT COLOR . : / ‘ ’, ‘’ 7. ::::: ::::.

Page 22: Report Layout Report Heading Report Body Column Heading Report Title

FORMAT COLORFORMAT COLOR

FORMAT COLOR col_heading. “ 1 FORMAT COLOR col_normal. 2“color FORMAT COLOR col_total. 3“color FORMAT COLOR col_key. 4“color FORMAT COLOR col_positive. 5“color FORMAT COLOR col_negative. 6“color FORMAT COLOR col_group. 7“color FORMAT COLOR col_background. “color 0

Page 23: Report Layout Report Heading Report Body Column Heading Report Title

Color Using Example

Page 24: Report Layout Report Heading Report Body Column Heading Report Title

Exercise I

Page 25: Report Layout Report Heading Report Body Column Heading Report Title

Text SymbolText Symbol

Text Element Text Symbols Text Symbol Text

Text 2

Text 1

REPORT ztest.

WRITE: text-001,

text-002.

001

002

Page 26: Report Layout Report Heading Report Body Column Heading Report Title

Text Symbol

WRITE: / text-001.WRITE: / text-001.WRITE: / text-001.WRITE: / text-001.WRITE: / text-001.

Page 27: Report Layout Report Heading Report Body Column Heading Report Title

CONSTANTSCONSTANTS

* Constant variableCONSTANTS ctext TYPE string VALUE ‘Hello World’. WRITE / ctext.WRITE / ctext.WRITE / ctext.WRITE / ctext.WRITE / ctext.

Page 28: Report Layout Report Heading Report Body Column Heading Report Title

Text Symbol : Language Translation

Page 29: Report Layout Report Heading Report Body Column Heading Report Title

Text Symbol : Language Translation

Page 30: Report Layout Report Heading Report Body Column Heading Report Title

Options of the WRITE StatementOptions of the WRITE Statement

* Write SyntaxWRITE var [NO-ZERO]

[NO-SIGN]

[NO-GROUPING]

[NO-GAP]

[DECIMALS no of decimals]

Page 31: Report Layout Report Heading Report Body Column Heading Report Title

Suppressing Zero With Blanks (NO-ZERO)Suppressing Zero With Blanks (NO-ZERO)

* No ZeroDATA: number(10) TYPE N VALUE 23.WRITE: number, number NO-ZERO.

Page 32: Report Layout Report Heading Report Body Column Heading Report Title

Suppressing Number(+ / -) SignSuppressing Number(+ / -) Sign

* No SignDATA: v_integer TYPE i VALUE -1.WRITE: v_integer, v_integer NO-SIGN.

Page 33: Report Layout Report Heading Report Body Column Heading Report Title

NO-GROUPINGNO-GROUPING

* No groupingDATA: v_integer TYPE i VALUE 120000.

WRITE: v_integer, v_integer NO-GROUPING.

Page 34: Report Layout Report Heading Report Body Column Heading Report Title

NO-GAPNO-GAP

* No gapWRITE: ‘Hello’ NO-GAP, ‘World’.

Page 35: Report Layout Report Heading Report Body Column Heading Report Title

DECIMALSDECIMALS

* DecimalsDATA: v_pack TYPE P DECIMALS 4 VALUE ‘1234.5678’.WRITE: v_pack, v_pack DECIMALS 2.

Page 36: Report Layout Report Heading Report Body Column Heading Report Title

Formatting OptionsFormatting Options

* Format options of WRITE statement* LEFT-JUSTIFIED for Numeric data* RIGHT-JUSTIFIED for Character data* CENTEREDDATA tmp1(20) VALUE ‘test’. WRITE: tmp1 CENTERED.

testtmp1

Page 37: Report Layout Report Heading Report Body Column Heading Report Title

STRLEN Built-in FunctionSTRLEN Built-in Function

DATA: tmp(20) VALUE ‘Test String’, count TYPE :.count = strlen( tmp ).WRITE count.

Page 38: Report Layout Report Heading Report Body Column Heading Report Title

Include Program You can create a program with program type include

program in the program attribute Include program do not have to have an introductory

statement During the syntax check and during program generation

by the ABAP compiler, the INCLUDE statement is replaced by the source text of the defined include program

DATA tmp(10).DATA tmp1 TYPE i. DATA tmp2 TYPE p.DATA tmp3.

Include Program : ZINCLUDE1

REPORT ztest1.INCLUDE zinclude1. …

REPORT ztest2.INCLUDE zinclude1. …

Page 39: Report Layout Report Heading Report Body Column Heading Report Title

Flow Control in ABAP

Page 40: Report Layout Report Heading Report Body Column Heading Report Title

Flow Control in ABAP Flow Control in ABAP

Branching ==> IF, CASE. Looping ==> DO, WHILE.

Page 41: Report Layout Report Heading Report Body Column Heading Report Title

IF StatementIF Statement

IF <Condition>. <Statement Block>ELSEIF <Condition>. <Statement Block>ELSEIF <Condition>. <Statement Block>ELSE. <Statement Block>ENDIF.

Page 42: Report Layout Report Heading Report Body Column Heading Report Title

IF StatementIF Statement

- IF sy mandt = ‘100’. WRITE: / ‘This is Production Client’.

-: :::: : := ‘ 800’ or sy-mandt = ‘805’. WRITE: / ‘This is Training Client’. WRITE / sy-mandt.ELSE. WRITE: / ‘This is Test Client’.ENDIF.

Page 43: Report Layout Report Heading Report Body Column Heading Report Title

CASE StatementCASE Statement

CASE <field>. WHEN <value1>. <Statement Block> WHEN <value2>. <Statement Block> ... WHEN OTHERS. <Statement Block> ENDCASE.

Page 44: Report Layout Report Heading Report Body Column Heading Report Title

CASE StatementCASE Statement

-CASE sy mandt. WHEN ‘100’. WRITE: / ‘This is Production Client’. WHEN ‘800’ or ‘805’. WRITE: / ‘This is Training Client’. WRITE / sy-mandt. WHEN OTHERS. WRITE: / ‘This is Test Client ’. ENDCASE.

Page 45: Report Layout Report Heading Report Body Column Heading Report Title

DO StatementDO Statement

DO. WRITE sy-index. IF sy-index = 3. EXIT. ENDIF. WRITE: sy-index.ENDDO.

Loop Counter

Page 46: Report Layout Report Heading Report Body Column Heading Report Title

DO StatementDO Statement

DO 10 TIMES. WRITE / sy-index.ENDDO.

Loop Counter

Page 47: Report Layout Report Heading Report Body Column Heading Report Title

WHILE StatementWHILE Statement

DATA: count TYPE i value 1.WHILE count <> 4. WRITE: sy-index. count = count + 1.ENDWHILE.

Loop Counter

WHILE sy-index <> 4. WRITE: sy-index.ENDWHILE.

Page 48: Report Layout Report Heading Report Body Column Heading Report Title

Logical ExpressionsLogical Expressions

>,GT<,LT>=, =>, GE<=, =<, LE=, EQ<>, ><, NEBETWEEN <value1> AND <value2>IS INITIAL

Page 49: Report Layout Report Heading Report Body Column Heading Report Title

Arithmetic OperatorsArithmetic Operators

+ , - , * , / , ** DIVMOD

Example :9 / 2 = 4.59 DIV 2 = 4.09 MOD 2 = 12 ** 4 = 16

Page 50: Report Layout Report Heading Report Body Column Heading Report Title

ABAP : Data Retrieval

Open SQL (SELECT)

Page 51: Report Layout Report Heading Report Body Column Heading Report Title

SAP System : 3 Tier Client/ServerSAP System : 3 Tier Client/Server

DB Server

SAP Application Server

SAP GUI Presentation

Server

SAP GUISAP GUI

Page 52: Report Layout Report Heading Report Body Column Heading Report Title

SAP SYSTEM (3 Tier Architecture)SAP SYSTEM (3 Tier Architecture)

Presentation Layer

(Windows based)

Application Layer

(Windows Server/UNIX)

Database Server

Database Layer

(Windows Server/UNIX)

M

SAP Instance

Oracle

Informix

DB2

MS SQL Server

MaxDB

G

Dispatcher

RequestQueue

D D B V S E

SAP Buffer(Shared Mem)

SAP GUI SAP GUI

Page 53: Report Layout Report Heading Report Body Column Heading Report Title

Database Server

Application Server

Dispatcher

RequestQueue

D D D B…

SAP Buffer

Program

User ContextArea

1

3

46

79

10

11

Report zpsm1.

Tables customers.

Select single * from customers

where id = 1.

Write: / customers-name.

5

Execute ABAP statement

Check Program in Program Buffer

Roll in

8

Load&Generate Program

SQL Request

Send List

Generate Screen(List)Send Request

Request List

2 Search for free WP

Store request to queue

Send request to WP

SAP GUI

REPOSRC

Report zpsm1.

Tables customers.

Select single * from customers

where id = 1.

Write: / customers-name.

SAP System : Dialog Processing

customers

Page 54: Report Layout Report Heading Report Body Column Heading Report Title

TaskHandler

DYNPRO Processor

ABAP Processor

Local Memory

Memory Space

DB Interface

List Buffer

Database Server

Dialog Work Process

User Context

Dialog Work Process Architecture

Result Set Memory

Page 55: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL SELECT ...

Page 56: Report Layout Report Heading Report Body Column Heading Report Title

Data Objects : Tables Data Objects : Tables StructureStructure

Memory Space

Structure

Tables Structure

Internal Table

Variable

Constants<Field-symbols>

Page 57: Report Layout Report Heading Report Body Column Heading Report Title

DB InterfaceDB Interface

Data

SAP Application Server

Local Memory

DataData

Dialog WP

TaskHandler

DB Interface

Result Set

DataData

Database Server

~ 32 KB in length

ABAP Processor

DYNPRO

Memory Space

List Buffer

Page 58: Report Layout Report Heading Report Body Column Heading Report Title

Example Tables in DB

carrid connid cityfrom cityto distance

LH 0400 LA NY 100

LH 0402 BK NY 540

SQ 0110 SQ BK 250

id name city

1 John New York

2 Peter Singapore

3 David

London

customersspfli

Page 59: Report Layout Report Heading Report Body Column Heading Report Title

Example Tables in DB

carrid connid fldate price

LH 0400 20010101

150

LH 0400 20010110

145

LH 0400 20010228

130

SQ 0110 20010226

75

sflight

Page 60: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Overview

SELECT <Column List> Which Columns?

FROM <table> Which Table?

INTO <destination> Where to place?

WHERE <condition> Which Lines?

Page 61: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Statement Select multiple records from database

Select single record from database

SELECT * FROM customers. …ENDSELECT.

SELECT SINGLE * FROM customers WHERE id = 1. …

Page 62: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Multiple Records : SPFLI

TABLES spfli.SELECT * FROM spfli. WRITE - -: / spfli carrid, spfli connid, spfli-cityfrom, spf -li cityto.ENDSELECT.

spfli-carrid spfli-connid spfli-cityfrom spfli-cityto

Page 63: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Multiple Records : SFLIGHT

TABLES sflight.SELECT * FROM sflight. WRITE : / sflight- carrid, sflight-connid, sflight-fldate, sflight-price.ENDSELECT.

sflight-carrid sflight-connid sflight-fldate sflight-price

Page 64: Report Layout Report Heading Report Body Column Heading Report Title

Exercise

CUSTOMERS-ID CUSTOMERS-NAME CUSTOMERS-CITY

Page 65: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Multiple Records : CUSTOMERS

TABLES customers.SELECT * FROM customers. WRITE : / customers- id, customers-name, customers-city.ENDSELECT.

Page 66: Report Layout Report Heading Report Body Column Heading Report Title

Dialog WPDialog WPDialog WP

TaskHandler

DYNPRO Processor

ABAP Processor

Database

Local Memory

DB InterfaceResult Set

Memory Space

List buffer

User Context

Page 67: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Statement Working Steps

1. Transform open SQL to DB SQL and return result set into result set work area

SELECT * FROM customers. …ENDSELECT.

SELECT * FROM customers;

2. Loop with data in result set and transfer each record to work area in memory space

SELECT * FROM customers. …ENDSELECT.

Table Structure in Memory Space

sy-subrc = 0

ABAP Processor

DB Interface

Page 68: Report Layout Report Heading Report Body Column Heading Report Title

Select Multiple Records : SPFLI

TABLES spfli.SELECT * FROM spfli. WRITE : / - -spfli carrid, spfli connid,

spfli-cityfrom,spf -li cityto.ENDSELECT.

Page 69: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Statement Working Steps

1. Transform open SQL to DB SQL and return result set into result set work area

SELECT * FROM spfli. …ENDSELECT.

SELECT * FROM spfli;

2. Loop with data in result set and transfer each record to work area in memory space

SELECT * FROM spfli. …ENDSELECT.

Table Structure in Memory Space

sy-subrc = 0

ABAP Processor

DB Interface

Page 70: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Multiple Records : CUSTOMERS

TABLES customers.SELECT * FROM customers. WRITE : / customers- id, customers-name, customers-city.ENDSELECT.

Page 71: Report Layout Report Heading Report Body Column Heading Report Title

SELECT INTO Table Structure

TABLES customers.SELECT * FROM customers INTO customers. WRITE : / customers- id, customers-name, customers-city.ENDSELECT.

Page 72: Report Layout Report Heading Report Body Column Heading Report Title

SELECT … INTO Work Area

DATA wa LIKE customers.SELECT * FROM customers INTO wa. WRITE : / wa- id, wa-name, wa-city.ENDSELECT.

Page 73: Report Layout Report Heading Report Body Column Heading Report Title

Table TRBAT

Page 74: Report Layout Report Heading Report Body Column Heading Report Title

SELECT … FROM …

TABLES trbat.SELECT * FROM trbat . WRITE : / trbat-function.ENDSELECT.

Page 75: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Statement : No Data Found

1. Transform open SQL to DB SQL and return result set into result set work area (If no data found in DB table)

SELECT * FROM trbat. …ENDSELECT.

SELECT * FROM trbat;

2. Go to statement after ENDSELECT

SELECT * FROM trbat. …ENDSELECT.

sy-subrc > 0

ABAP Processor

DB Interface

Page 76: Report Layout Report Heading Report Body Column Heading Report Title

SELECT … FROM …

TABLES trbat.SELECT * FROM trbat . WRITE : / trbat-function.ENDSELECT.IF sy-subrc <> 0. WRITE: / ‘No data found!!!’.ENDIF.

Page 77: Report Layout Report Heading Report Body Column Heading Report Title

SELECT Multiple Records

TABLES customers.SELECT * FROM customers. WRITE : / customers- id, customers-name, customers-city.ENDSELECT.IF - sy subrc <> 0.

WRITE : / ‘No Data Found’.ENDIF.

Page 78: Report Layout Report Heading Report Body Column Heading Report Title

Exercise I

customers-id customers-name

customers-city

Page 79: Report Layout Report Heading Report Body Column Heading Report Title

SELECT with WHERE Clause

Page 80: Report Layout Report Heading Report Body Column Heading Report Title

Loop Processing with Restriction

TABLES customers.SELECT * FROM customers WHERE city = ‘Bangkok’. WRITE : / customers- id, customers-name.ENDSELECT.IF - 0sy subrc <> . WRITE / ‘no data’.ENDIF.

Page 81: Report Layout Report Heading Report Body Column Heading Report Title

Loop Processing with RestrictionTABLES spfli.SELECT * FROM sssss WHERE cityfrom = ‘FRANKFURT’. WRITE - -: / spfli carrid, spfli cityto.ENDSELECT.IF - 0sy subrc <> . WRITE / ‘no data’.ENDIF.

Page 82: Report Layout Report Heading Report Body Column Heading Report Title

Select With Range

TABLES sflight.SELECT * FROM sflight WHERE price BETWEEN 100 AND

1000. WRITE: / sflight-carrid, sflight-connid, sflight-price.ENDSELECT.

Page 83: Report Layout Report Heading Report Body Column Heading Report Title

SELECT … With IN List

TABLES sflight.SELECT * FROM sflight WHERE price IN ( 100, 1000 ). WRITE: / sflight-carrid, sflight-

connid, sflight-price.ENDSELECT.

Page 84: Report Layout Report Heading Report Body Column Heading Report Title

SELECT … With TemplateTABLES customers.SELECT s* ROM customers WHERE name LIKE ‘_r%’. WRITE - -: / customers id,customers name.ENDSELECT.

Page 85: Report Layout Report Heading Report Body Column Heading Report Title

Select Single Record

Page 86: Report Layout Report Heading Report Body Column Heading Report Title

Select Single Record

TABLES customers.SELECT SINGLE * FROM customers

WHERE id = 1.IF -sssss s s s0

WRITE : / customers- id, customers-name, customers-ssss, customers-discount.

ELSE.WRITE : / ‘Data not found’.

ENDIF.

Page 87: Report Layout Report Heading Report Body Column Heading Report Title

Select Column List

Page 88: Report Layout Report Heading Report Body Column Heading Report Title

Select * : Example

SELECT *

bkpf-belnr bkpf-gjahr

Page 89: Report Layout Report Heading Report Body Column Heading Report Title

Select Column : Using Structure

bkpf-belnr bkpf-gjahr

Page 90: Report Layout Report Heading Report Body Column Heading Report Title

SELECT …* FROM …

TABLES customers.SELECT * FROM customers. WRITE : / customers-id, customers-name, customers-city.ENDSELECT.IF sy-subrc <> 0. WRITE: / ‘No data found’.ENDIF.

Page 91: Report Layout Report Heading Report Body Column Heading Report Title

Reading Selected Column DATA: BEGIN OF wa, id LIKE customers-id, name LIKE customers-name, city LIKE customers-city, END OF wa.

SELECT id name city INTO wa FROM customers. WRITE : / wa-id, wa-name , wa-city.ENDSELECT.IF - sy subrc <> 0. WRITE / ‘No Data found’.ENDIF.

customers-id customers-name customers-city

1

2

Page 92: Report Layout Report Heading Report Body Column Heading Report Title

Exercise I

customers-id customers-name

customers-city

ห้�ามใช้� SELECT *

Page 93: Report Layout Report Heading Report Body Column Heading Report Title

ABAP : Inner Join

Page 94: Report Layout Report Heading Report Body Column Heading Report Title

Flight Data Model

Page 95: Report Layout Report Heading Report Body Column Heading Report Title

Flight Data Model

Page 96: Report Layout Report Heading Report Body Column Heading Report Title

Tables Join

Question: Select carrid, connid and cityto from spfli and fldate,price from sflight where carrid = ‘LH’

spfli-carrid spfli-connid sflight-fldate spfli-cityto sflight-price

เงื่� อนไข : ให้�แสดงื่ข�อม�ลเฉพาะสายการบิ�น ‘LH’ เท่ าน!"น

Page 97: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL – Inner JoinTABLES: spfli,sflight.SELECT spfli~carrid spfli~connid sflight~fldate spfli~cityto sflight~price INTO (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) FROM spfli INNER JOIN sflight ON spfli~carrid = sflight~carrid AND spfli~connid = sflight~connid WHERE spfli~carrid = ‘LH’. WRITE: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price.ENDSELECT.

Page 98: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL – Inner JoinTABLES: A,B.SELECT A~a B~b B~c INTO (A-a,B-b,B-c) FROM A INNER JOIN B ON A~b = B~b. WRITE: / A-a,B-b,B-c.ENDSELECT.

a ba1 b1

a2 b2

Table : A

b cb1 c1

b2 c2

b3 c3

Table : B

A-a B-b B-c

Page 99: Report Layout Report Heading Report Body Column Heading Report Title

SELECT INNER JOIN Working Steps

1. Transform open SQL to DB SQL and return result set into result set work area

SELECT A~a B~b B~c ….FROM A INNER JOIN B …ENDSELECT.

SELECT A.a, B.b, B.c FROM A,B WHERE A.b = B.b;

2. Loop with data in result set and transfer each record to work area in memory space

SELECT A~a B~b B~c …ENDSELECT.

Tables Structure in Memory Space

sy-subrc = 0

ABAP Processor

DB Interface

Page 100: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL – Inner Join

a ba1 b1

a2 b2

Table : Ab cb1 c1

b2 c2

b3 c3

Table : B

A~a B~b B~ca1 b1 c1

a2 b2 c2

Single Result Table(Result set)

Select …

inner join..

Endselect.

Database

Server

Application Server

1

2

Page 101: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL – Alias Table Name

TABLES: spfli,sflight.SELECT a~carrid a~connid b~fldate a~cityto b~price INTO (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) FROM spfli AS a INNER JOIN sflight AS b ON a~carrid = b~carrid and a~connid = b~connid WHERE a~carrid = ‘LH’. WRITE: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price.ENDSELECT.

Page 102: Report Layout Report Heading Report Body Column Heading Report Title

Exercise : Sale Document

VBAK-VBELN VBAK-ERDAT VBAK-KUNNR VBAP-MATNR VBAP-NETWR

Document Number (VBAK-VBELN)‘0000004970’

Page 103: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL – Inner Join > 2 Tables

TABLES: A,B,C.SELECT A~a B~c C~y INTO (A-a,B-c,C-y) FROM A INNER JOIN B ON A~b = B~b INNER JOIN C ON C~x = B~c. WRITE: / A-a,B-c,C-y.ENDSELECT.

a b… …

Table : A

b c… ...

… ...

… …

Table : B

x y… ...

Table : CA-a B-c C-y

Page 104: Report Layout Report Heading Report Body Column Heading Report Title

Flight Data Model

Page 105: Report Layout Report Heading Report Body Column Heading Report Title

Open SQL – Inner Join > 2 Tables

REPORT ZINNERJOIN02 NO STANDARD PAGE HEADING.TABLES : sflight,sbook,scustom.SELECT a~carrid a~connid a~fldate b~bookid b~customid c~name b~luggweight INTO (sflight-carrid,sflight-connid,sflight-fldate, sbook-bookid,sbook-customid,scustom-name,sbook-luggweight) FROM sflight AS a INNER JOIN sbook AS b ON a~carrid = b~carrid AND a~connid = b~connid AND a~fldate = b~fldate INNER JOIN scustom AS c ON c~id = b~customid. WRITE : / sflight-carrid,sflight-connid,sflight-fldate, sbook-bookid,sbook-customid,scustom-name,sbook-luggweight.ENDSELECT.

SFLIGHT-CARRID SFLIGHT-CONNID SFLIGHT-FLDATE SBOOK-BOOKID SBOOK-CUSTOMID SCUSTOM-NAME SBOOK-LUGGWEIGHT

Page 106: Report Layout Report Heading Report Body Column Heading Report Title

Exercise : Sale Document

VBAK-VBELN VBAK-ERDAT KNA1-NAME1 VBAP-MATNR VBAP-NETWR

Document Number(VBAK-VBELN)

= ‘0000004970’

Page 107: Report Layout Report Heading Report Body Column Heading Report Title

Flight Data Model

Page 108: Report Layout Report Heading Report Body Column Heading Report Title

Flight Information : Inner Join

SFLIGHT-CARRID SCARR-CARRNAME SFLIGHT-CONNID SFLIGHT-FLDATE SBOOK-BOOKID SBOOK-CUSTOMID SCUSTOM-NAME SBOOK-LUGGWEIGHT

Page 109: Report Layout Report Heading Report Body Column Heading Report Title

Internal Table

Page 110: Report Layout Report Heading Report Body Column Heading Report Title

Data Objects : Internal TableData Objects : Internal Table

Memory Space

Structure

Tables Structure

Internal Table

Variable

Constants<Field-symbols>

Page 111: Report Layout Report Heading Report Body Column Heading Report Title

INTERNAL TABLEwa (Structure)

id name city

Internal Tabletab (Internal Table)

id name city

Header Line

Table Bodies

‘00000000’

‘00000000’

Structure

Page 112: Report Layout Report Heading Report Body Column Heading Report Title

Structure

DATA: BEGIN OF wa,id LIKE customers-id,name LIKE customers-name,city LIKE customers-city,

END OF wa.

wa- id = 1.wa-name = ‘John’.wa-city = ‘Bangkok’.

WRITE: / wa-id, wa-name.

Page 113: Report Layout Report Heading Report Body Column Heading Report Title

INTERNAL TABLE

DATA: BEGIN OF tab OCCURS 10,id LIKE customers-id,

name LIKE customers-name,city LIKE customers-city,

END OF tab.

Page 114: Report Layout Report Heading Report Body Column Heading Report Title

INTERNAL TABLE

DATA: BEGIN OF tab OCCURS 0,id LIKE customers-id,

name LIKE customers-name,city LIKE customers-city,

END OF tab.

Page 115: Report Layout Report Heading Report Body Column Heading Report Title

USING ABAP DICTIONARY STRUCTURE

DATA: BEGIN OF tab OCCURS 0.INCLUDE STRUCTURE customers.

DATA END OF tab.

Page 116: Report Layout Report Heading Report Body Column Heading Report Title

INTERNAL TABLE USING LIKE

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.

id name city

Header Line

Table Bodies

8 KB

tab (Internal Table)

‘00000000’

Page 117: Report Layout Report Heading Report Body Column Heading Report Title

Append And Read Data

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.tab-id = 1.tab-name = ‘John’.tab-city = ‘Bangkok’.APPEND tab.tab-id = 2.tab-name = ‘Peter’.tab-city = ‘London’.APPEND tab.LOOP AT tab. WRITE: / tab-id, tab-name, tab-city.ENDLOOP.

Page 118: Report Layout Report Heading Report Body Column Heading Report Title

Reading Data From Internal Table

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.SELECT * FROM customers INTO TABLE tab.IF sy-subrc = 0. LOOP AT tab. WRITE : / tab-id , tab-name,tab-city. ENDLOOP.ELSE. WRITE : / ‘No Data’.ENDIF.

Page 119: Report Layout Report Heading Report Body Column Heading Report Title

Access Database Without Internal Table

Page 120: Report Layout Report Heading Report Body Column Heading Report Title

Access Database Using Internal Table

Page 121: Report Layout Report Heading Report Body Column Heading Report Title

Access Database Using Internal Table

BKPF-BELNR BKPF-GJAHR

Page 122: Report Layout Report Heading Report Body Column Heading Report Title

SELECT <Column>… ENDSELECTSELECT <Column>… ENDSELECT

Dialog WP

TaskHandler

DYNPRO Processor

ABAP Processor

Database

Local Memory

Memory Space

DB Interface

00000001 John00000002 Peter00000003 David

List buffer

Result Set

3 | David

WA Structure

1

2

Page 123: Report Layout Report Heading Report Body Column Heading Report Title

SELECT …INTO TABLE …SELECT …INTO TABLE …Dialog WP

TaskHandler

DYNPRO Processor

ABAP Processor

Database

Local Memory

Memory Space

DB Interface

List buffer

Result Set

1

2

Internal Table

Page 124: Report Layout Report Heading Report Body Column Heading Report Title

Reading Data From Internal TableDATA: BEGIN OF tab OCCURS 0, id LIKE customers-id, name LIKE customers-name, END OF tab.

SELECT id name FROM customers INTO TABLE tab.

IF sy-subrc = 0. LOOP AT tab. WRITE - : / tab id, tab-name. ENDLOOP.ELSE. WRITE: / ‘No Data’.ENDIF.

1

2

3

customers-id customers-name

Page 125: Report Layout Report Heading Report Body Column Heading Report Title

Exercise I : Change

Using Internal Table

Page 126: Report Layout Report Heading Report Body Column Heading Report Title

SORTING INTERNAL TABLE (SORT)

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.…SORT tab BY name.SORT tab BY name ASCENDING

city DESCENDING.

Page 127: Report Layout Report Heading Report Body Column Heading Report Title

INTERNAL TABLE PROCESSING...LOOP AT tab. WRITE : / tab- d, tab-name.ENDLOOP. LOOP AT sab WHERE city = ‘Bangkok’. WRITE : / tab-id, tab-name.ENDLOOP. LOOP AT tab FROM 1 TO 10. WRITE : / -sy tabix ,tab-id, tab-name.ENDLOOP.

Record Pointer

Page 128: Report Layout Report Heading Report Body Column Heading Report Title

Internal Table Template Condition

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.

...LOOP AT tab WHERE name CP ‘+r*’....

Page 129: Report Layout Report Heading Report Body Column Heading Report Title

Reading Single Record

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE....SORT tab BY name city.READ TABLE tab

WITH KEY name = ‘John’ city = ‘Bangkok’ BINARY SEARCH.IF - sy subrc = 0 . WRITE : / tab- id, tab-name, tab-city, tab-telephone.ENDIF.

Page 130: Report Layout Report Heading Report Body Column Heading Report Title

Reading Single Record using Index

...READ TABLE tab INDEX 3.Is - sy subrc = 0. WRITE : / tab-id, tab-name.

ENDIF.

Page 131: Report Layout Report Heading Report Body Column Heading Report Title

DELETING Data in INTERNAL TABLE

CLEAR tab.

REFRESH tab.

FREE tab.

DATA tab LIKE sflight OCCURS 0 WITH HEADER LINE.

Page 132: Report Layout Report Heading Report Body Column Heading Report Title

SELECT … INNER JOIN

TABLES: scarr,spfli.SELECT spfli~carrid scarr~carrname spfli~connid INTO (spfli-carrid, scarr-carrname, spfli~connid) FROM spfli INNER JOIN scarr ON spfli~carrid = scarr~carrid. WRITE: / spfli-carrid, scarr-carrname , spfli~connid.ENDSELECT.

SPFLI-CARRID SCARR-CARRNAME SPFLI-CONNID

Page 133: Report Layout Report Heading Report Body Column Heading Report Title

Inner Join using Internal Table

DATA: BEGIN OF tab OCCURS 0, carrid LIKE spfli-carrid, carrname LIKE scarr-carrname, connid LIKE spfli-connid, END OF tab. SELECT spfli~carrid scarr~carrname spfli~connid INTO TABLE tab FROM spfli INNER JOIN scarr ON spfli~carrid = scarr~carrid.…LOOP AT tab. WRITE: / tab-carrid,tab-carrname,tab-connid.ENDLOOP.

SPFLI-CARRID SCARR-CARRNAME SPFLI-CONNID

Page 134: Report Layout Report Heading Report Body Column Heading Report Title

Exercise : Using Internal Table

VBAK-VBELN VBAK-ERDAT VBAK-KUNNR VBAP-MATNR VBAP-NETWR

Document Number(VBAK-VBELN)

= ‘0000004970’

Page 135: Report Layout Report Heading Report Body Column Heading Report Title

Event-driven Programming

Page 136: Report Layout Report Heading Report Body Column Heading Report Title

Application Driven Programming

REPORT ztest.DATA: today TYPE D.today = ‘19991231’.today = today + 1.WRITE: / today.

Page 137: Report Layout Report Heading Report Body Column Heading Report Title

Event-Driven Programming

DATA tmp TYPE i.AT LINE-SELECTION. WRITE: / ‘This is ’. WRITE : ‘Detail List’.START-OF-:ELECTION. WRITE: / ‘This is ’. WRITE: / ‘Basic List’.

Page 138: Report Layout Report Heading Report Body Column Heading Report Title

Events

START-OF-SELECTION. AT LINE-SELECTION. INITIALIZATION. AT SELECTION-SCREEN.

Page 139: Report Layout Report Heading Report Body Column Heading Report Title

AT LINE-SELECTION Event(Drill-down Report)

Page 140: Report Layout Report Heading Report Body Column Heading Report Title

Database Server

Application Server

Dispatcher

RequestQueue

D D D B…

SAP Buffer

Program

User ContextArea

1

3

46

79

10

11

Report zpsm1.

Tables customers.

Select single * from

customers where id = 1.

Write: / customers-name.

5

Execute ABAP statement

Check Program in Program Buffer

Roll in

8

Load&Generate Program

SQL Request

Send List

Generate Screen(List)Send Request

Request List

2 Search for free WP

Store request to queue

Send request to WP

SAP GUI

..

D010S

Report zpsm1.

Tables customers.

Select single * from

customers where id = 1.

Write: / customers-name.

SAP System : Dialog Processing

customers

12Roll out

Page 141: Report Layout Report Heading Report Body Column Heading Report Title

TaskHandler

DYNPRO Processor

ABAP Processor

Local Memory

Memory Space

DB Interface

List Buffer

Database Server

Dialog Work Process

User Context

Dialog Work Process Architecture

Result Set Memory

Server

Page 142: Report Layout Report Heading Report Body Column Heading Report Title

Database Server

Application Server

Dispatcher

RequestQueue

D D D B…

SAP Buffer

Program

User Context Area

1

3

46

79

10

11

Report zpsm1.

Tables customers.

Select single * from

customers where id = 1.

Write: / customers-name.

5

Execute ABAP statement

Check Program in Program Buffer

Roll in

8

Load&Generate Program

SQL Request

Send List

Generate Screen(List)Send Request

Request List

2 Search for free WP

Store request to queue

Send request to WP

SAP GUI

..

D010S

Report zpsm1.

Tables customers.

Select single * from

customers where id = 1.

Write: / customers-name.

Dialog Processing : Roll Out

customers

12Roll out

Page 143: Report Layout Report Heading Report Body Column Heading Report Title

AT LINE-SELECTION

START-OF-SELECTION. WRITE : ‘ ’ .AT LINE-SELECTION. WRITE : ‘Detail ’ .

(Basic list)

DoubleClickWRITE, ULINE

Page 144: Report Layout Report Heading Report Body Column Heading Report Title

AT LINE-SELECTION

1. Double Click 2. Choose Button

3. Hotspot

Page 145: Report Layout Report Heading Report Body Column Heading Report Title

Navigating Between Lists

Basic list

Detail list 20Exit

Detail list 1

Detail list 2

ABAP Editor

Back

Cancel

Page 146: Report Layout Report Heading Report Body Column Heading Report Title

Runtime Error : Detail List > 20

Page 147: Report Layout Report Heading Report Body Column Heading Report Title

Detail List and SY-LSIND

START-OF-SELECTION. WRITE : ‘Basic List’.

AT LINE-SELECTION. CASE -sy lsind. WHEN 1. WRITE : ‘Detail List :’,sy-lsind. WHEN2 . WRITE : ‘Detail List :’,sy-lsind. ENDCASE.

Detail list : 2SY-LSIND = 2

Detail list : 1SY-LSIND = 1

Basic list

Page 148: Report Layout Report Heading Report Body Column Heading Report Title

At Line Selection

TABLES customers.START-OF-SELECTION. SELECT * FROM customers. WRITE - : / customers name . ENDSELECT.AT LINE-SELECTION. WRITE : ‘You Choose :’ , custom

-ers name.

Page 149: Report Layout Report Heading Report Body Column Heading Report Title

At Line Selection(Hide Statement)

TABLES customers.START-OF-SELECTION. SELECT * FROM customers. WRITE -: / customers name.

HIDE -customers name. ENDSELECT.AT LINE-SELECTION. WRITE -: ‘You Choose :’,customers n

ame.

HIDE area of list level 1

line Field name Value1 customers-name John 2 customers-name Peter

3 customers-name David

JohnPeterDavid

List Buffer

Page 150: Report Layout Report Heading Report Body Column Heading Report Title

Hide Area in ListHide Area in ListDialog WP

TaskHandler

DYNPRO Processor

ABAP Processor

Database

Local Memory

Memory Space

DB Interface

List buffer

Result Set Memory

Database Server

Application Server

3 | David | ....

Customers Structure

JohnPeterDavid

Basic List

HIDE area of list level 1line Field name Value1 customers-name John 2 customers-name Peter3 customers-name David

Page 151: Report Layout Report Heading Report Body Column Heading Report Title

At Line Selection(Hide Statement)

HIDE area of list level 1

line Field name Value1 customers-name John 2 customers-name Peter

3 customers-name David

JohnPeterPeterDavid

You choose : Peter

Basic List Detail List

SY-LILLI = 2

3 | Peter | ....

Customers Structure

1

2

3

4

At Line-selection

5

Page 152: Report Layout Report Heading Report Body Column Heading Report Title

HIDE area of list level 1line Field name Value1 customers-id 00000001 1 customers-name John

2 customers-id 000000022 customers-name Peter

At Line Selection(Hide Statement)

TABLES customers.START-OF-SELECTION. SELECT * FROM customers. WRITE : / customers-id, -customers name. HIDE: customers-id, -customers name. ENDSELECT.AT LINE-SELECTION. WRITE : ‘You Choose :’ , customers-id, -customers name.

00000001 John00000002 Peter00000003 David

List Buffer

Page 153: Report Layout Report Heading Report Body Column Heading Report Title

At Line Selection(Hide Statement)

HIDE area of list level 1

line Field name Value… … …2 customers-id 00000002 2 customers-name Peter

3 customers-id 00000003…

00000001 John00000002 Peter00000002 Peter00000003 David

You choose : 00000002 Peter

Basic List Detail List

SY-LILLI = 2

2 | Peter | ....

Customers Structure

1

2

3

4

At Line-selection

5

Page 154: Report Layout Report Heading Report Body Column Heading Report Title

At Line Selection

TABLES: spfli,sflight.START-OF-SELECTION. SELECT * FROM spfli. WRITE: / spfli-carrid, spfli-connid,

spfli-cityto. HIDE: spfli-carrid, spfli-connid. ENDSELECT.AT LINE-SELECTION. SELECT * FROM sflight WHERE

carrid = spfli-carrid AND connid

= spfli-connid. WRITE: / spfli-carrid, spfli-

connid,sflight-fldate. ENDSELECT.

Basic List (SPFLI)

Detail List (SFLIGHT)

ZATLINE4

Page 155: Report Layout Report Heading Report Body Column Heading Report Title

Exercise : Flight Information

Basic List

Drill-down Level 1

SCARR

SPFLI

Page 156: Report Layout Report Heading Report Body Column Heading Report Title

Good ProgramDATA: BEGIN OF tab_spfli OCCURS 0, carrid LIKE spfli-carrid, connid LIKE spfli-connid, cityto LIKE spfli-cityto, END OF tab_spfli.DATA: BEGIN OF tab_sflight OCCURS 0, carrid LIKE sflight-carrid, connid LIKE sflight-connid, fldate LIKE sflight-fldate, END OF tab_sflight.

START-OF-SELECTION. SELECT carrid connid cityto FROM spfli INTO TABLE tab_spfli. IF sy-subrc = 0. LOOP AT tab_spfli. WRITE: / tab_spfli-carrid,tab_spfli-connid, tab_spfli-cityto. HIDE: tab_spfli-carrid,tab_spfli-connid. ENDLOOP. ELSE. WRITE: / 'No data found'. ENDIF.

AT LINE-SELECTION. CASE sy-lsind. WHEN 1. SELECT carrid connid fldate INTO TABLE tab_sflight FROM sflight WHERE carrid = tab_spfli-carrid AND connid = tab_spfli-connid. LOOP AT tab_sflight. WRITE: / tab_sflight-carrid,tab_sflight-connid, tab_sflight-fldate. ENDLOOP. ENDCASE.

Page 157: Report Layout Report Heading Report Body Column Heading Report Title

Exercise : Sale DocumentBasic List

Drill-down Level 1

VBAK

VBAP

Page 158: Report Layout Report Heading Report Body Column Heading Report Title

Selection Screen

Page 159: Report Layout Report Heading Report Body Column Heading Report Title

Selection Screen

PARAMETERS Statement SELECT-OPTIONS

Statement

Page 160: Report Layout Report Heading Report Body Column Heading Report Title

PARAMETERS

Page 161: Report Layout Report Heading Report Body Column Heading Report Title

PARAMETERSPARAMETERS: tmp1(10) TYPE c, tmp2(10) TYPE c LOWER CASE, tmp3 LIKE sy-datum DEFAULT sy-datum, tmp4 TYPE d DEFAULT '19991231', tmp5 TYPE i, tmp6 TYPE p DECIMALS 2, tmp7(5) TYPE n,

airline1(3), airline2 LIKE spfli-carrid.DATA id LIKE customers-id.

START-OF-SELECTION. WRITE: / tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,airline1,airline2,id.

Page 162: Report Layout Report Heading Report Body Column Heading Report Title

PARAMETERS Example

TABLES customers.PARAMETERS pid LIKE customers-id.START-OF-SELECTION. SELECT SINGLE * FROM customers WHERE id = pid. IF sy-subrc = 0. WRITE: / customers-name. ELSE. WRITE: / ‘No data found’. ENDIF.

Page 163: Report Layout Report Heading Report Body Column Heading Report Title

Selection-Text By default , the System displays the

name of the selection as text on the Selection Screen

You Should use the Text element/Selection texts function to store a text line for each Selection Criterion.

Page 164: Report Layout Report Heading Report Body Column Heading Report Title

PARAMETERS : Check box

PARAMETERS :: : AS CHECKBOX DEFAULT ‘X’.

Page 165: Report Layout Report Heading Report Body Column Heading Report Title

PARAMETERS : Radio Button

PARAMETERS: test1 RADIOBUTTON GROUP grp1,

test2 RADIOBUTTON GROUP grp1.

Page 166: Report Layout Report Heading Report Body Column Heading Report Title

RADIOBUTTON : SAP ECC 6.0

Page 167: Report Layout Report Heading Report Body Column Heading Report Title

Required Field with PARAMETERS

PARAMETERS tmp LIKE sy-datum OBLIGATORY.

Page 168: Report Layout Report Heading Report Body Column Heading Report Title

ABAP Exercise