Presentation is loading. Please wait.

Presentation is loading. Please wait.

SELECT-OPTIONS. SELECT-OPTIONS Syntax TABLES customers. SELECT-OPTIONS id FOR customers-id. START-OF-SELECTION.

Similar presentations


Presentation on theme: "SELECT-OPTIONS. SELECT-OPTIONS Syntax TABLES customers. SELECT-OPTIONS id FOR customers-id. START-OF-SELECTION."— Presentation transcript:

1 SELECT-OPTIONS

2 SELECT-OPTIONS Syntax TABLES customers. SELECT-OPTIONS id FOR customers-id. START-OF-SELECTION.

3 SELECT-OPTIONS “ ต้องการให้แสดงข้อมูล customers ของ ลูกค้าที่มีชื่อ ( คอลัมน์ name) ขึ้นต้นด้วย ตัว ‘M’ และลูกค้าที่ชื่อ ‘Smith’ และลูกค้า ที่ชื่ออยู่ระหว่าง ‘A’ กับ ‘John’ โดยใช้ คำสั่ง SELECT” SELECT * FROM customers WHERE (name LIKE ‘M%’) OR (name = ‘Smith’) OR (name BETWEEN ‘A’ AND ‘John’).

4 SELECT-OPTIONS TABLES customers. SELECT-OPTIONS sname FOR customers-name. START-OF-SELECTION. SELECT * FROM customers WHERE name IN sname.

5 Internal Structure of Select-options sname Internal Table Header Line

6 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

7 Internal Structure of SELECT-OPTIONS sname

8 SELECT-OPTIONS sname SELECT * FROM customers WHERE name IN sname. SELECT * FROM customers WHERE (name LIKE ‘M%’) OR (name = ‘Smith’) OR (name BETWEEN ‘A’ AND ‘John’). Transform

9 SELECT-OPTIONS Options SELECT-OPTIONS sname FOR customers-name OBLIGATORY.

10 INITIALIZATION Event PARAMETERS: nextday LIKE sy-datum. INITIALIZATION. nextday = sy-datum + 1. START-OF-SELECTION. WRITE nextday.

11 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. “ IF STRLEN( pcode ) <> 5. MESSAGE e000(38) WITH ‘Please enter postcode 5 characters’. ENDIF. START-OF-SELECTION. SELECT * FROM customers WHERE postcode = pcode. …

12 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… … 1 2 3 4 5

13 ABAP Exercise

14 Modularization

15  Subroutine  Function Module

16 Subroutine START-OF-SELECTION. PERFORM routine1. PERFORM routine2. FORM routine1. SELECT * FROM customers INTO TABLE tab. ENDFORM. FORM routine2. LOOP AT tab. WRITE: / tab-id,tab-name. ENDLOOP. ENDFORM. START-OF-SELECTION. SELECT * FROM customers INTO TABLE tab. LOOP AT tab. WRITE: / tab-id,tab-name. ENDLOOP. LOOP AT tab. WRITE: / tab-id,tab-name. ENDLOOP.

17 Modularization  Avoid redundancy  Make your program easy to read & improve their structure  Re-use Program components

18 Subrountine (Program Structure) REPORT ZSR1. *Data declaration TYPES: BEGIN OF strucbkpf, belnr TYPE bkpf-belnr, gjahr TYPE bkpf-gjahr, END OF strucbkpf. DATA tab TYPE TABLE OF strucbkpf with header line. *Processing block START-OF-SELECTION. SELECT belnr gjahr INTO TABLE tab FROM bkpf WHERE blart = 'SA'. LOOP AT tab. WRITE: / tab-belnr,tab-gjahr. ENDLOOP. LOOP AT tab. WRITE: / tab-belnr,tab-gjahr. ENDLOOP. REPORT ZSR2. *Data declaration TYPES: BEGIN OF strucbkpf, belnr TYPE bkpf-belnr, gjahr TYPE bkpf-gjahr, END OF strucbkpf. DATA tab TYPE TABLE OF strucbkpf with header line. *Processing block START-OF-SELECTION. PERFORM read_data. PERFORM display_data. *&---------------------------------------------------------------------* FORM read_data. SELECT belnr gjahr INTO TABLE tab FROM bkpf WHERE blart = 'SA'. ENDFORM. *&---------------------------------------------------------------------* FORM display_data. LOOP AT tab. WRITE: / tab-belnr,tab-gjahr. ENDLOOP. ENDFORM.

19 Calling and Defining Subroutines REPORT ztest. * Global Data TABLES customers. DATA tmp TYPE i. * Subroutine Calls PERFORM routine1. PERFORM routine2. * Subroutine FORM routine1. DATA tmp1 TYPE p. “Local data WRITE tmp. ENDFORM. FORM routine2. DATA tmp2(10). “Local data ….. ENDFORM.

20 Call by Value a1 Memory Space(Subroutine) f1 Copy

21 Call by Value DATA: a1,a2. a1 = ‘A’. a2 = ‘A’. PERFORM routine1 USING a1 a2..…... FORM routine1 USING VALUE(f1) VALUE(f2). f1 = ‘X’. f2 = ‘X’. ENDFORM.

22 Call by Reference a3 Memory Space(Subroutine) f3 Address Passing

23 Call by Reference DATA: a3. a3 = ‘A’. PERFORM routine2 USING a3..…... FORM routine2 USING f3. f3 = ‘X’. ENDFORM.

24 Call by Value and Result a4 Memory Space(Subroutine) f4 Copy

25 Call by Value and Result DATA: a4,a5. a4 = ‘A’. a5 = ‘A’. PERFORM routine3 USING a4 a5..…... FORM routine3 CHANGING VALUE(f4) VALUE(f5). f4 = ‘X’. f5 = ‘X’. ENDFORM.

26 Passing Structure as Parameters TABLES sflight. SELECT * FROM sflight. PERFORM subproc USING sflight. ENDSELECT. FORM subproc USING rec LIKE sflight. WRITE: / rec-carrid. ENDFORM.

27 Passing Internal Table as Parameters DATA: tab LIKE sflight OCCURS 0 WITH HEADER LINE. … PERFORM sub TABLES tab.

28 Passing Internal Table as Parameters FORM sub TABLES tab1 STRUCTURE tab. LOOP AT tab1. WRITE: / tab1-carrid. ENDLOOP. ENDFORM.

29 Function Module

30 Function Module : SE37  Function Group  Function Library - Admin - Import/Export Parameter - Source Code - Main Program - Documentation

31 Creating Function Module

32 Function Group When you create a function module, you must assign it to function group The function group is the main program in which a function module is embedded The function group is a program type F,and not executable The entire function group is loaded in a program the first time that you call a function module that belongs to it

33 Function Group is a container for function modules When a function module is called,the entire function group is loaded into the session of the program Function group is used to define global data for function modules A DATA statement in the global memory of a function group is shared by all the function modules that belong to that function group

34 Function Group : SE37

35 Function Group : SE80

36 Function Module is a code that can be called from any ABAP program,therefore making it a globally accessible object ABAP program pass data to function module from import parameters or internal tables Function module receives data from a program,process the information in its own code, and then sends back information in the export parameters or internal tables

37 Function Module : SE37

38 Function Module

39 Function Module : Import

40 Function Module : Export

41 Function Module : Source Code (Logic) FUNCTION z_fmtest. result = number1 ** number2. ENDFUNCTION.

42 Program Example I REPORT ztest. PARAMETERS: no1 TYPE i, no2 TYPE i. DATA result TYPE i. START-OF-SELECTION. CALL FUNCTION ‘Z_FMTEST’ EXPORTING number1 = no1 number2 = no2 IMPORTING result = result. WRITE: / result.

43 Exercise : Function Module ? ABAP Program Function Module

44 EXCEPTIONS

45 Function Module FUNCTION z_fmtest. IF number1 > 9 AND number2 > 9. RAISE invalidnumber. ELSE. result = number1 ** number2. ENDIF. ENDFUNCTION.

46 Example II : Exceptions Handler REPORT ztest. PARAMETERS: no1 TYPE i, no2 TYPE i. DATA result TYPE i. START-OF-SELECTION. CALL FUNCTION ‘Z_FMTEST’ EXPORTING number1 = no1 number2 = no2 IMPORTING result = result EXCEPTIONS invalidnumber = 1. IF sy-subrc = 1. write: / ‘Please enter number < 10’. ELSEIF sy-subrc = 0. write: / result. ENDIF.

47 Exercise : Exceptions ? ABAP Program Function Module

48 EXCEPTIONS VS AT SELECTION-SCREEN FUNCTION Z_FMTEST. IF number1 > 9 AND number2 > 9. RAISE invalidnumber. ELSE. result = number1 ** number2. ENDIF. ENDFUNCTION. REPORT ztest. PARAMETERS: no1 TYPE i, no2 TYPE i. AT SELECTION-SCREEN. IF no1 > 9 AND no2 > 9. MESSAGE e000(38) WITH ‘Please enter no < 10’. ENDIF. START-OF-SELECTION. CALL FUNCTION ‘Z_FMTEST’. ….. VS

49 Optional ABAP Program Function Module

50 Structure in Function Module

51 Example : Structure

52

53 Internal Table in Function Module

54 Example : Internal Table

55

56 CATCH Statement REPORT ztest. PARAMETERS: num1 TYPE i, num2 TYPE i. DATA result TYPE i. START-OF-SELECTION. CATCH SYSTEM-EXCEPTIONS others = 1. result = num1 / num2. ENDCATCH. IF sy-subrc = 1. WRITE: /'Divide by zero'. ELSE. WRITE: / result. ENDIF.

57 CATCH in Function Module FUNTION Z_CAL. IF number1 > 9 AND number2 > 9. RAISE invalidnumber. ELSE. result = number1 ** number2. ENDIF. ENDFUNCTION. FUNCTION Z_CAL. CATCH SYSTEM-EXCEPTIONS others = 1. result = number1 ** number2. ENDCATCH. IF sy-subrc = 1. RAISE invalidnumber. ENDIF. ENDFUNCTION.

58 Authorization in ABAP

59 Database Server Application Server Dispatcher Request Queue DDDB … SAP Buffer Program … User Context Area 1 3 4 6 79 10 11 Report zpsm1. Tables customers. Select single * from customers where id = 1. Write: / customers-name. 5 Execute ABAP stateme nt 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

60 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

61 SAP Authorization Principles  All data in the SAP system must be protected against access by unauthorized users  Since the SELECT statement does not perform any authorization checks,you must program these yourself with AUTHORITY-CHECK

62 No Authorization Check TABLES spfli. SELECT * FROM spfli. WRITE: / spfli-carrid, spfli-connid, spfli-cityfrom, spfli-cityto. ENDSELECT.

63 Authorization Check Syntax AUTHORITY-CHECK OBJECT ID FIELD ……. ID DUMMY. IF sy-subrc <> 0. …. ENDIF.

64 Authorization Check Selection SELECT AUTHORITY-CHECK Process Data Message sy-subrc = 0 ? No Yes Local Memory User Context Memory Space List Buffer

65 Authorization Check TABLES spfli. SELECT * FROM spfli. AUTHORITY-CHECK OBJECT ‘S_CARRID’ ID ‘CARRID’ FIELD spfli-carrid ID ‘ACTVT’ FIELD ‘03’. IF sy-subrc = 0. WRITE: / spfli-carrid, spfli-connid, spfli-cityfrom, spfli-cityto. ENDIF. ENDSELECT.

66 SAP Authorization Objects Transaction : SU03

67 Authorization Object Field u ABAP Editor : Pattern

68 Message in ABAP

69 Dynamic Message REPORT ztest1. PARAMETERS today LIKE sy-datum. AT SELECTION-SCREEN. IF today <> sy-datum. MESSAGE e000(38) WITH ‘Please enter today :’ sy-datum. ENDIF. START-OF-SELECTION. WRITE: / ‘Today is :’, today.

70 Message Type Message Type Syntax MESSAGE [ A ](message class) WITH. E, W, I, S

71 Messages Type - A(Abend) Message A000(38)... Program Start Selection Screen A Message Exit

72 Messages Type - E(Error) Message E 000(38)... Program Start Selection Screen Error Message New input Require

73 Messages Type - W(Warning) Message W 000(38)... Program Start Selection Screen Warning Message New input possible START-OF-SELECTION Enter

74 Messages Type - I(Information) Message i 000(38)... Program Start Selection Screen Information Message Enter START-OF-SELECTION

75 Messages Type - S(Success) Message S 000(38)... Program Start Selection Screen List (Next Screen)

76 Debugging

77 Debugging Mode

78 Debugging Mode : Internal Table

79 Debugging Mode : Watchpoint

80 Watchpoint : SAP ECC 6.0

81 GUI TITLE... SET TITLEBAR ‘ 0100 ’.

82 ABAP Exercise III

83 Sale Document : Data Model

84 Report Example VBAK-VBELNVBAK-ERDAT KNA1-NAME1 VBAP-MATNR VBAP-NETWR ZEX_T

85 Report Example : Group Header

86 ON CHANGE OF … … SORT tab BY vbeln. LOOP AT tab. ON CHANGE OF tab-vbeln. WRITE: / sy-vline,2(24) tab-vbeln COLOR 4 INTENSIFIED OFF, 25 sy-vline,26(20) tab-erdat COLOR 4 INTENSIFIED OFF, 45 sy-vline,46(30) tab-name1 COLOR 2 INTENSIFIED OFF. ENDON. WRITE: sy-vline, 25 sy-vline, 45 sy-vline, 75 sy-vline,76(25) tab-matnr COLOR 2 INTENSIFIED OFF, 100 sy-vline,101(18) tab-netwr COLOR 2 INTENSIFIED OFF, 120 sy-vline. NEW-LINE. ENDLOOP. …


Download ppt "SELECT-OPTIONS. SELECT-OPTIONS Syntax TABLES customers. SELECT-OPTIONS id FOR customers-id. START-OF-SELECTION."

Similar presentations


Ads by Google