Title: SAP BC400
1SAP BC400
2? ?
- 1. System Architecture, Syntax 3
- 2. ?? ?? 10
- 3. ?? ?? 14
- 4. Full Source Code 48
- 5. Subroutine 51
- 6. TABLE JOIN 57
31. System Architecture, Syntax
4System Architecture
- 3 Tier ??
- Presentation Layer
- Application Layer
- DB Layer
- MS
- Dispatcher ?? ??
- Dispatcher
- ??? WP? ??
- Work Process
- ?? ??
5ABAP Program
1.????
2.F8(??)
6.Write?
5.Itab? ??
3.WP?? ???? ??
4. DB ?? ???
6Interaction Between Server Layers
Load-of-program. Initialization.
START-OF-SELECTION. END-OF-SELECTION.
Select, Insert ? SQL?
Write? ? ???
7Activate
- Saved Program
- Saved ? Activate?? ??? ????? Save ? ?? ???
????? Activate ? ?? Execute??. - ?? ? Activate ??
- Activate
- Save
- Check
- Activate
- Activate? ????.
8General ABAP Syntax I
- Data??
- SELECT ENDSELECT
- DB?? ??? ?? DATA? WA_SCARR? ???.
- NEW-LINE. (???)
- wa_scarr-carrid ? 2? ?? ??.
- . (???)
9General ABAP Syntax II
Line ?? line ??? ?? ???? ??? ???
, , ?? ??? ??? ??? ?? ??? ?? ?? ??.(??
WRITE)
102. ?? ??
11?? ??
12?? ??
13Double Click
14- 3. ?? ??
- Data ??, 15
- Local Global Data Type 16
- Dictionary 17
- Structure, Work area Internal Table 19
- Assignments 24
- Event ?? 26
- gt ?? ?? gt LOAD-OF-PROGRAM. 28
- gt INITIALIZATION. 28
- gt AT SELECTION-SCREEN. 29
- gt ?? ?? gt START-OF-SELECTION. 30
- gt DB ACCESS 31
- gt SYSTEM ?? 38
- gt ?? ?? gt END-OF-SELECTION. 39
- gt ?? ?? gt AT SELECTION-SCREEN. 41
- gt ???, ??? 42
- gt DETAIL LIST 44
- gt HIDE AREA 46
- Source ?? ??
15Data ??
DATA gv_char(10) TYPE c, Character length 10
gv_numc(4) TYPE n, Numerical Char length 4
gv_pack(5) TYPE p DECIMALS 2, Length
? 5??? ??? 2??(length 5 ??) gv_date TYPE d,
Date (ex)2006.08.27 gv_time TYPE t, Time
(ex)123026 gv_int TYPE i.
??? ?? ??.
16Local Global Data Type
- wa_scarr2 Local Data Type
- ???? ??? ???? Local Data Type
- DATA BEGIN OF wa_scarr2, carrid TYPE
scarr-carrid, carrname TYPE
scarr-carrname, END OF wa_scarr2. - scarr Global Data Type
- ABAP Dictionary? ???? ??? Global Data type
- DATA wa_scarr TYPE scarr.DATA it_scarr LIKE
TABLE OF wa_scarr.
17Using Dictionary Elements to Define Data Objects
Within the Program
- Data type ??
- Dictionary ??
- DATA name TYPE dictionary.
- field ??? ?
- Work area ?? ?? ?? Set?? ??.
- Internal Table Work area? set
DATA it_spfli TYPE spfli_tab
Table Type
18Access to Structure Components
Work Area Fieldname ??? Data?? ?? ??
19Work Area, Internal Table ??
TYPE ABAP Dictionary? ?? ? ??. Like
Program??? ?? ? ?? ???. Dictionary? TYPE??
????? ?? ??. DATA wa_scarr TYPE scarr.
Work areaDATA it_scarr LIKE TABLE OF
wa_scarr. Itab DATA it_scarr TYPE TABLE OF
scarr. Itab DATA wa_scarr LIKE LINE OF
it_scarr. Work area
DATA wa_scarr TYPE s_carr_id. Data
Element,W.A. DATA it_scarr TYPE TABLE OF scarr.
Itab DATA it_scarr TYPE scarr_tab.
Table Type,Itab DATA wa_scarr LIKE LINE OF
it_scarr. Work area
20Internal Table with Header line
- DATA BEGIN OF it_scarr OCCURS 0, carrid
TYPE scarr-carrid, carrname TYPE
scarr-carrname, currcode TYPE
scarr-currcode, url TYPE scarr-url,
END OF it_scarr.DATA it_scarr2 TYPE TABLE OF
scarr WITH HEADER LINE.
21Internal Table with Header line
- ??
- ????? 1? ??
- SAP?? 3? ??.
- 1? 2? 3?
- 1?? LOOP At itab ??? INTO itab. ??
1. LOOP AT itab. itab-carrid
itab-carrname. MODIFY itab. CLEAR itab.
ENDLOOP. 2. LOOP AT itab INTO itab.
itab-carrid itab-carrname. MODIFY itab.
CLEAR itab. ENDLOOP.3. LOOP AT itab INTO
wa. wa-carrid wa-carrname. MODIFY wa.
CLEAR wa. ENDLOOP.
22Internal Tables with and Without Header Lines
- ???? ?? Internal Table ?? ??
- Why?
- Class?? ???? ?? Internal Table? ??? ? ??.
- ??? ???? ?? Internal Table Work Area? ?? ??
23Internal Table with Header line
1. 1? ??? ????? ?? ???? ?? 2. MODIFY ?? ???
????. 3. 2? ???? ??? ???? ????? ????? ?? ?? ?
MODIFY ?? ?? ??
2
1
24Value Assignments
carrid1 c_qf
Counter 1??
Field? Initial Value? Clear
25Copying Structure Components with the Same Name
Corresponding? ?? Field name? ?? ???? Data? ??
?? ?.
26Event ??
- LOAD-OF-PROGRAM.
- INITIALIZATION.
- Selection Screen ? PARAMETERS SELECT-OPTIONS?
?? ?? ?? ??. - AT SELECTION-SCREEN
- Selection Screen ? ?? ?? ??
- START-OF-SELECTION.
- Select ?? ??
- END-OF-SELECTION.
- ????? ???.
- AT SELECTION-SCREEN
- ?? ?? ???
- ?? ?? ???? ?? ???? ??? ??? ???
27?? ??
PARAMETERS pa_scarr TYPE s_carr_id. SELECT-OPTI
ONS so_scarr FOR wa_scarr-carrid. Select-op
tions?? ?? ? so_scarr? sign, option, low, high ??
??? ????? ???Internal table.
28???? ?? ?
- LOAD-OF-PROGRAM. so_scarr-sign 'I'.
so_scarr-option 'BT'. so_scarr-low
'AA'. so_scarr-high 'AZ'. APPEND
so_scarr. - INITIALIZATION. pa_scarr 'AB'.
- ???? Execute ??? ???? ??? ? ??.
29?? ?? ??
- AT SELECTION-SCREEN. IF pa_scarr 'AA'.
MESSAGE 'Another value input' TYPE 'E'. ENDIF. - ?? ?? AA??? ERROR Message
30Dialog Messages
- (?)MESSAGE i001(zm19) WITH es_row e_column.
- ZM19??? ?? ???? message_class? ?????.
- ??? ?? ???? ??? es_row, e_column? ???? ?????.
?? 4??? ?????. - ? ???? ??? ?? ?????.
31???? ?? ??
- START-OF-SELECTION. SELECT FROM scarr
INTO CORRESPONDING FIELDS OF TABLE it_scarr
WHERE carrid IN so_scarr. IF sy-subrc ltgt '0'.
STOP. ENDIF. - Scarr table?? where ??? ???? ???? select??
it_scarr? ???. - ??? ???? Data? ??? sy-subrc 0
- ??? sy-subrc 4
32Database Access (Architecture)
- Open SQL
- DB interface? ?? Native SQL? ??
- ?? ?? Table buffer? ??
- SELECT
- Native SQL
- DB? ?? Access DBMS? Dependent
- EXEC. ENDEXEC.
33Database Read Access
34Reading Single Records
- SELECT SINGLE
- WHERE ??? KEY?? ? ???? DATA ??? ??? ?? ? ??? ??
?. - DATA ??? ?? ??? ?? ?? ?? ??? ?? ???
35Suitable Target Structure for the Field List
- SELECT SINGLE
- SELECT SINGLE ??1, ??2, ??3, ??4, ??5
- ??1, ??2, ??3, ??4, ??5 ??? Work Area? ????.
36Fields in the Target Structure that have the Same
Names as those in the Field List
- SELECT SINGLE INTO CORRESPONDING FIELDS OF
- ?? name? ?? ?? ???? ?? Work area? ????.
37Reading several rows using a loop
- SELECT ENDSELECT
- DB Interface?? ????? Data? ???? ??? ??? ???.
- ??? ???, ???? ???? ??.
38Reading Several Rows Using an Array Fetch
- SELECT INTO TABLE ITAB
- DB Interface?? Table ??? ???? ??? ??? ???.
- Into corresponding fields of table itab ? ??
fields name? ???? ??? ??? ?? ??? ?? ??? ??.
39System ??
- sy-subrc
- Select? Data ??? 0, ??? 4
- ? ? true 0, false ltgt 0
- sy-index
- loop counter
- DO. ENDDO. DO n TIMES. ENDDO. WHILE.
ENDWHILE. - sy-tabix
- loop counter, LOOP AT itab. ENDLOOP.
- sy-lsind
- ??? ??. BACK ??? ??.
- sy-ucomm
- SCREEN ???? ??? ??? ??? ???
- sy-langu
- ?? ??
- sy-datum
- ?? ??
40?? ??
- END-OF-SELECTION. LOOP AT it_scarr INTO
wa_scarr. WRITE / wa_scarr-carrid,
wa_scarr-carrname, wa_scarr-currcode. HIDE
wa_scarr-carrid, wa_scarr-carrname. CLEAR
wa_scarr. ENDLOOP. - START-OF-SELECTION?? ??? ?? ??? ??.
- it_scarr? internal table??? data? ??? ??.
- it_scarr ????? wa_scarr? ??? ??? ????.
- HIDE? ?? ???? AT LINE-SELECTION.?? ?? ???
- ?? ????.
41CLEAR, REFRESH, FREE
- CLEAR ITAB. ??? ???.
- CLEAR ITAB. REFRESH ITAB. ??? ???.
- FREE ITAB. ?? ? ???? ???.
- ??? ??? ???? ITAB? ???? ???.
- CLEAR ??1, ??2, ??3.
- Sort it_sflight by carrid. carrid? it_sflight??
42?? ?? Event
- AT LINE-SELECTION. IF sy-lsind '1'.
SELECT FROM sflight INTO
CORRESPONDING FIELDS OF TABLE it_sflight
WHERE carrid wa_scarr-carrid. IF sy-subrc
'0'. WRITE/ 'New Page Start'. ELSE.
WRITE/ 'No Data in Database'. ENDIF.
LOOP AT it_sflight INTO wa_sflight. WRITE
/ wa_sflight-carrid, wa_sflight-connid,
wa_sflight-fldate, wa_sflight-price.
CLEAR wa_sflight. ENDLOOP. ENDIF.
43Conditional Branches(???)
44Loops(???)
- Loop Counter
- sy-index
- DO. ENDDO.
- DO n TIMS.
- ENDDO.
- WHILE.
- ENDWHILE.
- sy-tabix
- LOOP AT ltITABgt.
- ENDLOOP.
45Generating a Details List
- AT LINE-SELECTION.
- Double click Event
46Generating Several Details Lists
- sy-lsind
- 1?? ?? ?? 1? ? ??
- 2?? ??? ?? ?? 1?? ???? ?? ????
1 write
2 ????
7 BACK
4 ????
3 write
6 BACK
5 write
47Buffering Row-Specific Data in the Hide Area
- Hide Area
- Hide ? ?? Data Area? Line? Field name? Value?
???? ??.
48Data Flow for the Row Selection
- Hide Area
- Double Click??
- At line-selection.?? ???? Hide ?? ??? ?? ??? ? ??.
494. Full Source Code
50Full Source 1/2
- REPORT zabap19_11. Data typeDATA
gv_char(10) TYPE c, "Character Length
10 gv_numc(4) TYPE n,
"Numerical character Length 4 gv_pack(5)
TYPE p DECIMALS 2, "Packed Number XXX.XX
gv_date TYPE d, "Date 2006.08.27
gv_time TYPE t, "Time
121630 gv_int TYPE i.
"Integer Local Data TypeDATA BEGIN OF
wa_scarr2, carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname, END OF
wa_scarr2. scarr, sflight Global Data
TypeDATA wa_scarr TYPE scarr.DATA it_scarr LIKE
TABLE OF wa_scarr.DATA wa_sflight TYPE
sflight.DATA it_sflight LIKE TABLE OF
wa_sflight.PARAMETERS pa_scarr TYPE
s_carr_id.SELECT-OPTIONS so_scarr FOR
wa_scarr-carrid.LOAD-OF-PROGRAM.
so_scarr-sign 'I'. so_scarr-option 'BT'.
so_scarr-low 'AA'. so_scarr-high
'AZ'. APPEND so_scarr.
51Full Source 2/2
- INITIALIZATION. pa_scarr 'AB'.AT
SELECTION-SCREEN. IF pa_scarr 'AA'.
MESSAGE 'Another value input' TYPE 'E'.
ENDIF.START-OF-SELECTION. SELECT FROM
scarr INTO CORRESPONDING FIELDS OF TABLE
it_scarr WHERE carrid IN so_scarr. IF
sy-subrc ltgt '0'. STOP. ENDIF.END-OF-SELECT
ION. LOOP AT it_scarr INTO wa_scarr. WRITE
/ wa_scarr-carrid, wa_scarr-carrname,
wa_scarr-currcode. HIDE wa_scarr-carrid,
wa_scarr-carrname. CLEAR wa_scarr.
ENDLOOP.AT LINE-SELECTION. IF sy-lsind
'1'. SELECT FROM sflight INTO
CORRESPONDING FIELDS OF TABLE it_sflight
WHERE carrid wa_scarr-carrid. IF sy-subrc
'0'. WRITE/ 'New Page Start'. ELSE.
WRITE/ 'No Data in Database'. ENDIF.
LOOP AT it_sflight INTO wa_sflight. WRITE
/ wa_sflight-carrid, wa_sflight-connid,
wa_sflight-fldate, wa_sflight-price.
CLEAR wa_sflight. ENDLOOP. ENDIF.
525. Subroutine
53Actual Formal parameters
54Call by value, Call by value result, Call by
reference
- Call by value
- ?? ???? ???? ???.
- Call by value and result
- ?? ???? ???? Subroutine? ??? ?? ????.
- Call by reference
- Actual parameter? ??? ????.
55Call by value, Call by value result, Call by
reference
- Call by value
- ?? ???? ???? Subroutine? ??? ???.
- Call by value and result
- ?? ???? ???? Subroutine? ??? ?? ????.
- Call by reference
- Actual parameter? ??? ????.
56Call by value ? 2? ?? 1/2
REPORT zabap19_13.DATA pv_a(3) TYPE n,
pv_b(3) TYPE n, pv_sum(3) TYPE n.WRITE
/'Initial value ', 50 'a ', pv_a, 'b ',
pv_b, 'sum ', pv_sum.pv_a 1.pv_b
2.PERFORM call_by_value USING pv_a pv_b
pv_sum.WRITE /'Main ', 50 ' a ', pv_a, '
b ', pv_b, ' sum ', pv_sum COLOR 3.WRITE /
'Change call by value but main is not
change.'.PERFORM call_by_value_result CHANGING
pv_a pv_b pv_sum.WRITE /'Main ', 50 ' a ',
pv_a, ' b ', pv_b, ' sum ', pv_sum COLOR
1.WRITE / 'Change after function' COLOR
5.PERFORM call_by_reference USING pv_a pv_b
pv_sum.WRITE /'Main ', 50 ' a ', pv_a, '
b ', pv_b, ' sum ', pv_sum COLOR 4.WRITE /
'Actual parameter Formal parameter' COLOR
5. FORM call_by_value USING value(p_pv_a)
value(p_pv_b)
value(p_pv_sum). WRITE/. WRITE/
' start function '.
WRITE/ 'Call by value Start'. p_pv_sum
p_pv_a p_pv_b. WRITE /'Call by value ', 50
'p_a ', p_pv_a, 'p_b ', p_pv_b,
'p_sum ', p_pv_sum COLOR 3. WRITE /'Call by
value ', 50 ' a ', pv_a, ' b ', pv_b,
' sum ', pv_sum COLOR 3. WRITE/
' end function '.ENDFOR
M. " call_by_value
57Call by value ? 2? ?? 2/2
FORM call_by_value_result CHANGING value(p_pv_a)
value(p_pv_b)
value(p_pv_sum). p_pv_a 10. p_pv_b 20.
WRITE/. WRITE/ ' start function
'. WRITE/ 'Call by value and
result Start'. p_pv_sum p_pv_a p_pv_b.
WRITE /'Call by value result pv_a pv_b pv_sum
', 50 'p_a ', p_pv_a, 'p_b ', p_pv_b,
'p_sum ', p_pv_sum. WRITE /'Call by value
result ', 50 ' a ', pv_a, ' b ', pv_b,
' sum ', pv_sum COLOR 1. WRITE/
' end function '.ENDFOR
M. " call_by_value_result FORM
call_by_reference USING p_pv_a
p_pv_b
p_pv_sum. p_pv_a 100. p_pv_b
200. WRITE/. WRITE/ ' start
function '. WRITE/ 'Call by
reference Start'. p_pv_sum p_pv_a p_pv_b.
WRITE /'Call by reference pv_a pv_b pv_sum
', 50 'p_a ', p_pv_a, 'p_b ', p_pv_b,
'p_sum ', p_pv_sum COLOR 4. WRITE /'Call
by reference ', 50 ' a ', pv_a, ' b ',
pv_b, ' sum ', pv_sum COLOR 4. WRITE/
' end function '.ENDFOR
M. " call_by_reference
585. TABLE JOIN
59Example of a Table Join
- inner join
- 2?? Table?? ??? ??? ???? ??? ???? ???. 2?? ?????
??? ??? ??? ??? ??. - ???? Mandt, Carrid? ?? ??
60Implementation Options for Table Joins
?? ? SELECT asabun aname
aparts bparts_area FROM emp AS a
INNER JOIN dep AS b ON aparts bparts
INTO CORRESPONDING FIELDS OF TABLE
it_people. emp INNER JOIN dep emp ? dep table?
inner join ON aparts bparts ??? ??? ?? ?