abap event-driven programming &selection screen

66
ABAP Chapter 4 Event-driven Programming Selection Screen

Upload: y-z-mercan

Post on 31-Oct-2014

82 views

Category:

Education


7 download

DESCRIPTION

You can find more SAP ABAP documents at http://sapdocs.info/category/sap/abap/

TRANSCRIPT

Page 1: ABAP Event-driven Programming &Selection Screen

ABAP Chapter 4

Event-driven Programming Selection Screen

Page 2: ABAP Event-driven Programming &Selection Screen

Event-driven Programming

Page 3: ABAP Event-driven Programming &Selection Screen

Application Driven Programming

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

Page 4: ABAP Event-driven Programming &Selection Screen

Event-Driven Programming

Data tmp type i.- -Start of Selection.

Write: / ‘This is ’. Write: / ‘Basic List’.

-At line selection. Write: / ‘This is ’. Write: ‘Detail List’.

Page 5: ABAP Event-driven Programming &Selection Screen

Events

START-OF-SELECTION. END-OF-SELECTION. TOP-OF-PAGE. TOP-OF-PAGE DURING LINE-

SELECTION. END-OF-PAGE. AT LINE-SELECTION. AT USER-COMMAND. INITIALIZATION. AT SELECTION-SCREEN.

Page 6: ABAP Event-driven Programming &Selection Screen

AT LINE-SELECTION Event(Drill-down Report)

Page 7: ABAP Event-driven Programming &Selection Screen

AT LINE-SELECTION

- -Start of selection. Write : ‘Basic List’.

-At Line selection. Write : ‘Detail List’.

Basic list

DoubleClick

Page 8: ABAP Event-driven Programming &Selection Screen

Navigating Between Lists

Basic list

Detail list 20Exit

Detail list 1

Detail list 2

ABAP Editor

Back

Cancel

Page 9: ABAP Event-driven Programming &Selection Screen

Detail List and SY-LSIND

Start-of-selection. write: ‘Basic List’.

-AT Line selection. CASE -sy lsind. WHEN 1. write: ‘Detail List #1’. 2 22

write: ‘Detail List #2’. .

Detail list 2SY-LSIND = 2

Detail list 1SY-LSIND = 1

Basic list

Page 10: ABAP Event-driven Programming &Selection Screen

At Line Selection

Tables customers.- -Start of Selection.

Select * from customers. - write : / customers name . Endselect.

-At line selection. Write: ‘You Choose :’ , custome

-rs name.

Page 11: ABAP Event-driven Programming &Selection Screen

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 name.

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 12: ABAP Event-driven Programming &Selection Screen

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 13: ABAP Event-driven Programming &Selection Screen

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 14: ABAP Event-driven Programming &Selection Screen

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 15: ABAP Event-driven Programming &Selection Screen

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 16: ABAP Event-driven Programming &Selection Screen

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)

Page 17: ABAP Event-driven Programming &Selection Screen

Exercise

zcustomers

zsales

Basic List

Detail Listzcustomers-id

zcustomers-namezsales-cust_id

zsales-prod_id

zsales-qty

Page 18: ABAP Event-driven Programming &Selection Screen

Hide Statement (Report Heading)

Tables customers.Top-of-page. write: / ‘Customers Name’. uline.

- -Start of Selection. Select * from customers. -write : / customers name.

-Hide customers name. Endselect.

-At line selection. -Write: ‘You Choose :’ , customers name.

HIDE area of list level 1

line Field name Value3 customers-name John 4 customers-name Peter

5 customers-name David

Customers Name-----------------------------JohnPeterDavid

List Buffer

Page 19: ABAP Event-driven Programming &Selection Screen

At Line Selection(Hide Statement)

HIDE area of list level 1

line Field name Value3 customers-name John 4 customers-name Peter

5 customers-name David

Customers Name-----------------------------JohnPeterPeterDavid

You choose : Peter

Basic List Detail List

SY-LILLI = 4

3 | Peter | ....

Customers Structure

1

2

3

4

At Line-selection

5

Page 20: ABAP Event-driven Programming &Selection Screen

Invalid Line Selection …TOP-OF-PAGE. …Hide: spfli-carrid, spfli-connid.…Endselect.Clear: spfli-carrid,spfli-connid.At Line-selection. Select * From sflight Where carrid = spfli-carrid

and connid = spfli-connid. Write: / spfli-carrid, spfli-

connid ,sflight-fldate. Endselect. Clear: spfli-carrid,spfli-connid.

Page 21: ABAP Event-driven Programming &Selection Screen

Page Heading

- -Start of selection. Write: ‘Basic List’.

-At Line selection. Write: ‘Detail List’.

- -Top of page. -Write: ‘Header Basic List’.

- - -Top of page During Line selection. -Write: ‘Header Detail List’.

Page 22: ABAP Event-driven Programming &Selection Screen

Detail List Page Heading...top-of-page during line-selection. case sy-lsind. when 1. write: / ‘Detail List Header #1’. when 2. write: / ‘Detail List Header #2’. endcase...........

Page 23: ABAP Event-driven Programming &Selection Screen

Column Selection...data: fieldname(30)....start-of-selection. select * from spfli. write: / spfli-carrid,15 spfli-connid, 25 spfli-cityto. hide: spfli-carrid,spfli-connid. endselect.at line-selection. case sy-lsind. when 1. get cursor field fieldname. case fieldname. when 'SPFLI-CARRID'. select single * from scarr where carrid = spfli-carrid. if sy-subrc = 0. write: / spfli-carrid,scarr-carrname. endif. when 'SPFLI-CONNID'. select * from sflight where carrid = spfli-carrid and connid = spfli-connid. ...

Page 24: ABAP Event-driven Programming &Selection Screen

Column Selection : Value...data: fieldname(30),fieldvalue(30)....start-of-selection. select * from spfli. write: / spfli-carrid,15 spfli-connid, 25 spfli-cityto. hide: spfli-carrid,spfli-connid. endselect.at line-selection.case sy-lsind. when 1. get cursor field fieldname value fieldvalue. case fieldname. when 'SPFLI-CARRID'. select single * from scarr where carrid = spfli-carrid. if sy-subrc = 0. write: / spfli-carrid,scarr-carrname. endif. when 'SPFLI-CONNID'. ...

Page 25: ABAP Event-driven Programming &Selection Screen

Creating List in Modal Dialog Box

...at line-selection. window starting at 10 10 ending at 65 20. select * from sflight where carrid = spfli-carrid and connid = spfli-connid. write: / sflight-carrid,sflight-connid,sflight-

fldate. endselect. ...

Page 26: ABAP Event-driven Programming &Selection Screen

ExerciseBasic List

Detail List

zsales

zsalerepszproducts

zsales-cust_id

zsales-prod_id

zsales-qty

zsales-sale_id

zsalereps-sale_id

zsalereps-namezproducts-on_hand

zproducts-p_id

Page 27: ABAP Event-driven Programming &Selection Screen

Drill-Down 2 Levels Example

12

Detail list level 1 (ZSALES)

Detail list level 2 (ZPRODUCTS)

Basic list (ZCUSTOMERS)

Page 28: ABAP Event-driven Programming &Selection Screen

Program ExampleSTART-OF-SELECTION. SELECT * FROM zcustomers. WRITE: / zcustomers-id COLOR 4 HOTSPOT, 15 zcustomers-name. HIDE: zcustomers-id,zcustomers-name. ENDSELECT. CLEAR zcustomers-id.

AT LINE-SELECTION. CASE sy-lsind. WHEN 1. GET CURSOR FIELD fieldname. IF fieldname = 'ZCUSTOMERS-ID'. SELECT * FROM zsales WHERE cust_id = zcustomers-id. IF sy-dbcnt = 1. WRITE: / zcustomers-id,15 zcustomers-name,30 zsales-prod_id HOTSPOT, 45 zsales-qty. HIDE: zsales-prod_id. ELSE. WRITE: /30 zsales-prod_id HOTSPOT, 45 zsales-qty. HIDE: zsales-prod_id. ENDIF. ENDSELECT. CLEAR: zcustomers-id,zsales-prod_id. ENDIF. WHEN 2. GET CURSOR FIELD fieldname. IF fieldname = 'ZSALES-PROD_ID'. SELECT SINGLE * FROM zproducts WHERE p_id = zsales-prod_id. IF sy-subrc = 0. WRITE: / zproducts-p_id,15 zproducts-prod_name,38 zproducts-on_hand. ENDIF. CLEAR zsales-prod_id. ENDIF. ENDCASE.

Hide Level 1

Hide Level 2

Drill Down Level 1

Drill Down Level 2

Page 29: ABAP Event-driven Programming &Selection Screen

ExerciseBasic List

Drill-down Level 1

Drill-down Level 2

Drill-down Level 3

SCARR

SPFLI

SFLIGHT

SBOOK

Page 30: ABAP Event-driven Programming &Selection Screen

GUI Interface (User Interface)

Page 31: ABAP Event-driven Programming &Selection Screen

GUI Interface - SET PF STATUS …. => GUI

Status SET TITLEBAR …. =>

GUI Title

Page 32: ABAP Event-driven Programming &Selection Screen

AT USER-COMMAND Event

SET PF-STATUS ‘TEST’. ...AT USER-COMMAND. CASE -sy ucomm. WHEN ‘CODE1’. . WHEN ‘CODE2’. . ENDCASE.

Page 33: ABAP Event-driven Programming &Selection Screen

Standard Toolbar : System Function System function do not trigger event AT USER-

COMMAND %EX = Exit %PC = Save to file %SC = Find %SC+ = Find next %ST = Save in report tree BACK = Back RW = Cancel PRI = Print P- = Scroll to previous page P-- = Scroll to first page P+ = Scroll to next page P++ = Scroll to last page

Page 34: ABAP Event-driven Programming &Selection Screen

Alternative with AT USER-COMMAND

REPORT ZRSDEM002. . START-OF-SELECTION - SET PF STATUS ‘BASE’. . . -AT USER COMMAND. -CASE SY UCOMM. WHEN ‘CARR’. SET PF_STATUS SPACE. “Set to standard GUI

interface . WHEN ‘FLIG’. - SET PF STATUS ‘FLIG’. WRITE … . .

Page 35: ABAP Event-driven Programming &Selection Screen

GUI Status Excluding Function Code

REPORT ztest. ... - SET PF STATUS ‘0100’. ... -AT USER COMMAND. -CASE SY UCOMM. WHEN ‘LIST’. - SET PF STATUS ‘0100’ excluding ‘LIST’. . WHEN ‘DISP’. - SET PF STATUS ‘0100’ excluding ‘DISP’. WRITE … . ....

Page 36: ABAP Event-driven Programming &Selection Screen

GUI Status Excluding Function Code

REPORT ztest.DATA exctab(10) occurs 0 with header line. ....START-OF-SELECTION. - SET PF STATUS ‘0100’. ... exctab = ‘LIST’. APPEND exctab. exctab = ‘TEST’. APPEND exctab. ...

-AT USER COMMAND. -CASE SY UCOMM. WHEN ‘LIST’. - SET PF STATUS ‘0100’ excluding exctab.

Page 37: ABAP Event-driven Programming &Selection Screen

GUI TITLE ... SET TITLEBAR ‘0100’.

Page 38: ABAP Event-driven Programming &Selection Screen

ABAP Practice

Page 39: ABAP Event-driven Programming &Selection Screen

Selection Screen

Page 40: ABAP Event-driven Programming &Selection Screen

Selection Screen

PARAMETERS Statement SELECT-OPTIONS

Statement

Page 41: ABAP Event-driven Programming &Selection Screen

parameters

Page 42: ABAP Event-driven Programming &Selection Screen

Parameters

PARAMETERS 1: tmp (10) TYPE C, 210tmp ( ) TYPE C lower case, 3tmp LIKE sy-datum default

sy-datum, 4tmp TYPE D 2222222 199912‘31’,

5tmp TYPE i, tmp6(5) TYPE N.

Page 43: ABAP Event-driven Programming &Selection Screen

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 44: ABAP Event-driven Programming &Selection Screen

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 45: ABAP Event-driven Programming &Selection Screen

Check box

Parame ters tmp as checkbo x default ‘X’.

Page 46: ABAP Event-driven Programming &Selection Screen

Radio Button

Parameters: test1 Radiobutton group grp1,

test2 Radiobutton group grp1.

Page 47: ABAP Event-driven Programming &Selection Screen

Required field with Parameters

Parameters tmp like sy-datum obligatory.

Page 48: ABAP Event-driven Programming &Selection Screen

ABAP Exercise

Page 49: ABAP Event-driven Programming &Selection Screen

select-options

Page 50: ABAP Event-driven Programming &Selection Screen

Complex Selection (Select-options)

Tables spfli.- Select options carrid for spfli-car

rid.START-OF-SELECTION.

Select * From spfli Where carrid in carrid. . . .Endselect.

Page 51: ABAP Event-driven Programming &Selection Screen

Select-Options

“ต้�องการให้�แสดงข้�อมู�ล customers ข้องล�กค้�าที่��มู�ชื่��อ(ค้อล�มูน์� name ) ข้��น์ต้�น์ด�วยต้�ว ‘M’ และล�กค้�าที่��ชื่��อ ‘Smith’ และล�กค้�าที่��ชื่��ออย�"ระห้ว"าง ‘A’ ก�บ ‘John’ โดยใชื่�ค้%าส��ง SELECT”

*Select from customers 22( ‘ % ’ ) 22( = ‘’) 2( ‘ ’ ‘ John’).

Page 52: ABAP Event-driven Programming &Selection Screen

Select-Options

Tables customers.Select-options sname for customers-name.START-OF-SELECTION.Select * from customers Where name in sname.

Page 53: ABAP Event-driven Programming &Selection Screen

Internal Structure of Select-options

sname

Sign Option Low High

Page 54: ABAP Event-driven Programming &Selection Screen

Internal Structure of Select-options Field Value . Sign I = Include E = Exclude Option BT = Between CP = Contains Pattern EQ = Equal GT = Greater Than LT = Less Than GE = Grater Than or Equal LE = Less Than or Equal NE = Not Equal NB = Not Between

Page 55: ABAP Event-driven Programming &Selection Screen

Internal Structure of Select-options

snameSign Option Low High

I CP M* I EQ Smith I BT A John

Page 56: ABAP Event-driven Programming &Selection Screen

SELECT-OPTIONS

Sign Option Low High

I CP M* I EQ Smith I BT A John

sname

Select * from customers where name in sname.

*Select from customers 22( ‘ % ’ ) 22( = ‘ ’ ) 2( ‘ ’ ‘ John’).

Transform

Page 57: ABAP Event-driven Programming &Selection Screen

INITIALIZATION Event

Tables Customers.- -Select options sname for customers name.

Initialization. - sname sign = ‘I’. - sname option = ‘EQ’. - sname low = ‘Smith’. append sname.

- -Start of Selection. Select * from customers Where name in sname.

Page 58: ABAP Event-driven Programming &Selection Screen

Select-options Options

Select-options sname for customers-name obligatory. Select-options sname for customers-name no-extension.

Select-options sname for customers-name no intervals.

Page 59: ABAP Event-driven Programming &Selection Screen

Designing Selection Screen

Selection-screen begin of block test with frame Title text-001. . Selection-screen uline. Selection-screen skip 3. Selection-screen comment 3(10) text-001. Parameters month(2) type n. .Selection-screen end of block test.

Page 60: ABAP Event-driven Programming &Selection Screen

Designing Selection Screen

selection-screen begin of line. selection-screen comment 1(7) text-001. selection-screen position 9. parameters month(2) type n. selection-screen comment 16(6) text-002. parameters year(4) type n.selection-screen end of line.

Page 61: ABAP Event-driven Programming &Selection Screen

Designing Selection Screen

Selection-screen begin of block name1 with frame title text-001. Selection-screen begin of line. Parameters test1 radiobutton group test default ‘X’. Selection-screen comment 4(10) text-002. Selection-screen position 35. Parameters tcheck as checkbox. Selection-screen comment 37(15) text-003. Selection-screen end of line. Selection-screen begin of line. Parameters test2 radiobutton group test. Selection-screen comment 4(10) text-004. Selection-screen end of line.Selection-screen end of block name1.

Page 62: ABAP Event-driven Programming &Selection Screen

ABAP Exercise

Page 63: ABAP Event-driven Programming &Selection Screen

Checking User Input

Tables customers. Data pcode _len type i.

-Parameters pcode like customers postcode. - At selection screen.

pcode _len = strlen( pcode ). if pcode _len <> 5. message e000(38) with ‘Please enter postcode 5 characters’. endif.

- -Start of Selection. select * from customers where postcode = pcode. …

Page 64: ABAP Event-driven Programming &Selection Screen

ABAP Exercise

Page 65: ABAP Event-driven Programming &Selection Screen

ABAP Program Processing Steps

TABLES sflight.PARAMETERS nextday LIKE sy-datum.INITIALIZATION. nextday = sy-datum + 1.AT SELECTION-SCREEN . IF nextday < sy-datum. MESSAGE e000(38) WITH ‘Please enter date >= today’. ENDIF.START-OF-SELECTION. SELECT * FROM sflight WHERE ... fldate = nextday… …

Page 66: ABAP Event-driven Programming &Selection Screen

ABAP Practice