ABAP Event Driven Programming
ABAP Event Driven Programming
Event-driven Programming
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.
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.
AT LINE-SELECTION
Basic list
Detail list 20
Detail list 2
Cancel
Detail list 1
Basic list
Back
Detail list 1
SY-LSIND = 1
Basic list
At Line Selection
Tables customers. Start-of-Selection. Select * from customers. write : / customers-name . Endselect. At line-selection. Write: You Choose : , customers-name.
Value
John Peter David
Dialog WP
TaskHandler
Local Memory
Memory Space
Customers Structure
ABAP Processor
3 | David | ....
DB Interface
Result Set Memory
Database Server
Database
5
At Line-selection
4 2
HIDE area of list level 1
Customers Structure
Value
John Peter David
3 | Peter | ....
3
Detail List
You choose : 00000002 Peter
5
At Line-selection
1
SY-LILLI = 2 HIDE area of list level 1 line Field name
2 2 3 customers-id customers-name customers-id
4
Customers Structure
Value
00000002 Peter 00000003
2 | Peter | ....
3
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)
Exercise
Basic List
zcustomers-id
Detail List
zcustomers
zcustomers-name
zsales-cust_id zsales-prod_id
zsales-qty
zsales
List Buffer
Customers Name ----------------------------John Peter David
Value
John Peter David
Detail List
You choose : Peter
5
At Line-selection
1
SY-LILLI = 4
4 2
HIDE area of list level 1
Customers Structure
Value
John Peter David
3 | Peter | ....
3
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.
... 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.
Column Selection
Exercise
Basic List
zsales
zsales-cust_id zsales-prod_id zsales-qty zsales-sale_id
zproducts
zproducts-p_id
Detail List
zproducts-on_hand zsalereps-sale_id
zsalereps
zsalereps-name
Program Example
START-OF-SELECTION. SELECT * FROM zcustomers. WRITE: / zcustomers-id COLOR 4 HOTSPOT, 15 zcustomers-name. HIDE: zcustomers-id,zcustomers-name. ENDSELECT. CLEAR zcustomers-id. Hide Level 1 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. Hide Level 2 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.
Basic List
SCARR
Exercise
Drill-down Level 1
SPFLI
Drill-down Level 2
SFLIGHT
Drill-down Level 3
SBOOK
GUI Interface
SET PF-STATUS . => GUI Status SET TITLEBAR . => GUI Title
AT USER-COMMAND Event
SET PF-STATUS TEST. ... AT USER-COMMAND. CASE sy-ucomm. WHEN CODE1. . WHEN CODE2. . ENDCASE.
%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
GUI TITLE
... SET TITLEBAR 0100.
ABAP Practice
Selection Screen
Selection Screen
parameters
Parameters
PARAMETERS: 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(5) TYPE N.
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.
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.
Check box
Parameters tmp as checkbox default X.
Radio Button
Parameters: test1 Radiobutton group grp1, test2 Radiobutton group grp1.
ABAP Exercise
select-options
Complex Selection (Select-options) Tables spfli. Select-options carrid for spfli-carrid. START-OF-SELECTION. Select * From spfli Where carrid in carrid. . .. Endselect.
Select-Options
( customers Smith name) M A John SELECT
Select * from customers where (name like M%) or (name = Smith) or (name between A and John).
Select-Options
Tables customers. Select-options sname for customers-name. START-OF-SELECTION. Select * from customers Where name in sname.
Value I = Include E = Exclude 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
John
SELECT-OPTIONS
sname
Sign I I I Option CP EQ BT Low M* Smith A High
Transform
Select * from customers where (name like M%) or (name = Smith) or (name between A and John).
John
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.
Select-options Options
Select-options sname for customers-name obligatory. Select-options sname for customers-name no-extension.
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.
ABAP Exercise
ABAP Exercise
ABAP Practice