sap-abap-學(xué)習(xí)筆記總結(jié)_第1頁
sap-abap-學(xué)習(xí)筆記總結(jié)_第2頁
sap-abap-學(xué)習(xí)筆記總結(jié)_第3頁
sap-abap-學(xué)習(xí)筆記總結(jié)_第4頁
sap-abap-學(xué)習(xí)筆記總結(jié)_第5頁
已閱讀5頁,還剩74頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

目錄TOC\o"1-5"\h\z\u基本語法 4定義數(shù)據(jù)和類型 4運(yùn)算符控制流語句 5字符串操作 7字符串連接 7字符串拆分 7字符串查找 7字符串替換 8字符串長度 8定位操作字符串 9子程序 9無參數(shù) 9帶參數(shù) 9參數(shù)傳值和傳地址對(duì)比 10創(chuàng)建功能模塊function 10包含程序 11靜態(tài)變量 11內(nèi)表操作 111. 定義基本內(nèi)表 112復(fù)雜內(nèi)表. 12示例一 12示例二 15示例三 16示例四 17數(shù)據(jù)庫建表 21數(shù)據(jù)庫查詢 21(一) 單表查詢 21(二)多表聯(lián)合查詢 251.嵌套查詢 252.FOR

ALL

ENTRIES 263多表結(jié)合查詢 27結(jié)果放入變量 27查詢單行,結(jié)果放入結(jié)構(gòu)體對(duì)象(工作區(qū))中 27查詢多行,結(jié)果放入內(nèi)表中 27數(shù)據(jù)庫操作查詢學(xué)生班級(jí)表。 29單表查詢 29單行

部分字段 30多表聯(lián)合查詢 30多行查詢

部分字段 31單行

所有字段 31單行部分字段 32添加數(shù)據(jù) 33添加一條 33插入多行數(shù)據(jù) 33修改記錄 34使用變量修改 34使用工作區(qū)修改 34使用內(nèi)表修改多條數(shù)據(jù) 34修改或保存 35使用工作區(qū)修改或保存 35使用內(nèi)表

修改或保存 35刪除 36使用工作區(qū)刪除 36使用內(nèi)表刪除 36案例:查詢數(shù)據(jù)庫數(shù)據(jù)至內(nèi)表修改內(nèi)容并且更新到數(shù)據(jù)庫 36報(bào)表設(shè)計(jì) 37選擇屏幕 37選擇屏幕參數(shù) 37格式化屏幕參數(shù) 38復(fù)雜選擇標(biāo)準(zhǔn) 38ALV報(bào)表 40示例一 40參數(shù)說明 43w_fcat

TYPE

slis_fieldcat_alv, 43用到屬性: 44其他屬性: 44w_layo

TYPE

slis_layout_alv, 46使用屬性: 46其他屬性 46i_fcat

TYPE

slis_t_fieldcat_alv. 49示例二: 52屏幕編程 55重要概念: 55創(chuàng)建: 55舉例:用戶輸入學(xué)號(hào)返回姓名等信息 57由數(shù)據(jù)字典生成屏幕 58根據(jù)定義的結(jié)構(gòu)生成屏幕 58單選、復(fù)選鈕用法 58Pov(F4幫助)添加 59屏幕間跳轉(zhuǎn) 59Tablecontrolwithwizard 60添加tablecontrol字段 63設(shè)置某列為不可編輯 64設(shè)置下拉列表框 64從數(shù)據(jù)庫取值加入列表 65下拉列表取值 66Screen上后添加數(shù)據(jù)庫字段 67Tablecontrol 67Screenlayout 67Screen100中代碼 68Programe中代碼 69Sartform 70簡單示例 70程序部分 70Smartform配置 70Template 70Table做法: 74樣式設(shè)置 76基本語法定義數(shù)據(jù)和類型REPORT

ZWANGZHENG2.

*定義數(shù)據(jù)txt1類型C長度15初始值HELLO

WORLDDATA

txt1(15)

TYPE

c

VALUE

'HELLO

WORLD'.

*定義類型t_txtTYPES

t_txt(15)

TYPE

c

.*定義數(shù)據(jù)txt2

類型為:t_txt

DATA

txt2

TYPE

t_txt

VALUE

'first'.

*定義類型為N的數(shù)據(jù)及類型。

DATA

i1(2)

TYPE

n

VALUE

118.

TYPES

my_number_type(5)

TYPE

n.

DATA

i2

TYPE

my_number_type.

*定義時(shí)間類型數(shù)據(jù)

Data

time1

TYPE

t

VALUE

'100701'.

WRITE

time1.

*定義日期類型數(shù)據(jù)

DATA

day1

TYPE

d.

day1

='20110628'.

DATA

i1

TYPE

I.

i1

=

15.

WRITE

i1.

*定義結(jié)構(gòu)體

TYPES:

BEGIN

OF

student,

studentid

type

I,

sname(20)

type

c,

sex(10)

type

c,

age

type

I,

END

OF

student.

DATA

stu1

TYPE

student.

stu1-studentid

=

1001

.

stu1-sname

=

'tom'.

stu1-sex

=

'man'.

stu1-age

=

18.

WRITE

stu1-studentid

.

WRITE

stu1-sname

.

WRITE

stu1-sex

.

WRITE

stu1-age

.運(yùn)算符控制流語句REPORT

ZWANGZHENG6.

DATA

a

TYPE

i

VALUE

1.

DATA

b

TYPE

i

VALUE

20.

DATA

c

TYPE

i

.

*a的b次方.c

=

a

**

b

.*b=a+b.

ADD

a

TO

b.

if

a

>

10.

WRITE

/

'>10'

.

elseif

a

>

5

.

WRITE

/

'>5'

.

else

.

WRITE

/

'<5'

.

ENDIF

.

*case語句

CASE

a.

when

12

OR

1

OR

2

.

WRITE

/

'winner'

.

when

3

OR

4

OR

5

.

WRITE

/

'spring'

.

when

6

OR

7

OR

8

.

WRITE

/

'summer'

.

when

9

OR

10

OR

11

.

WRITE

/

'winner'

.

when

others.

WRITE

/

'NO'.

ENDCASE

.

*固定次數(shù)循環(huán)*輸出1-30之間偶數(shù)*sy-index循環(huán)次數(shù)從1開始

DATA

a

TYPE

i

.

DO

30

TIMES.

a

=

sy-index.

DATA

s

TYPE

i

.

s

=

a

MOD

2

.

IF

s

=

0

.

WRITE

/

sy-index

.

ENDIF

.

ENDDO.

DATA

sum1

TYPE

i

value

0

.

DATA

sum2

TYPE

i

value

0

.*循環(huán)計(jì)算1~100之間的奇數(shù)和偶數(shù)和。

WHILE

sy-index

<=

100

.

a

=

sy-index

.

b

=

a

mod

2

.

if

b

=

0

.

sum1

=

sum1

+

a

.

else

.

sum2

=

sum2

+

a

.

ENDIF

.

ENDWHILE.

WRITE

/

sum1

.

WRITE

/

sum2

.循環(huán)控制CONTINUE:結(jié)束本次循環(huán)EXIT跳出整個(gè)循環(huán)相當(dāng)于BREAK字符串操作字符串連接REPORT

ZWANGZHENG7.

DATA:

s1(20)

TYPE

c

value

'aaa',

s2(20)

TYPE

c

value

'bbb'

,

s3(20)

TYPE

c

,

sep(1)

TYPE

c

value

'.'

.

*s3=s1+s2.中間無空格

CONCATENATE

s1

s2

INTO

s3

.

WRITE

/

s3

.

*s3=s1+s2連接處使用數(shù)據(jù)sep中的值填充

CONCATENATE

s1

s2

INTO

s3

SEPARATED

BY

sep

.

WRITE

/

s3

.字符串拆分REPORT

ZWANGZHENG8.

DATA:

t

Type

string,

i

TYPE

TABLE

OF

string,

sep

TYPE

c

value

'*'.

t

=

'ABAP*is*a*programming*language'

.

*拆分字符串,把

t

按照

sep

分隔符

拆分

拆分結(jié)果放入到

i

表中。

SPLIT

t

At

sep

INTO

TABLE

i

.

*迭代

內(nèi)表

i

每個(gè)元素,將元素

一個(gè)個(gè)付給

t

LOOP

AT

i

INTO

t.

WRITE

/

t

.

END字符串查找REPORT

ZWANGZHENG9.

DATA

s(30)

TYPE

c

VALUE

'This

is

a

testing

sentence.'

.

WRITE:

/

'Searched'

,

'SY-SUBRC'

,

'SY-FDPOS'.

SEARCH

s

for

'x'

.

WRITE

:/

'x'

,

sy-subrc

UNDER

'SY-SUBRC'

,

SY-fdpos

UNDER

'SY-FDPOS'

.

SEARCH

s

for

'ing

'

.

WRITE

:/

'ing

'

,

sy-subrc

UNDER

'SY-SUBRC'

,

sy-fdpos

UNDER

'SY-FDPOS'

.

SEARCH

s

for

'.ing

'

.

WRITE

:/

'.ing

'

,

sy-subrc

UNDER

'SY-SUBRC'

,

sy-fdpos

UNDER

'SY-FDPOS'

.

SEARCH

s

for

's*'

.

WRITE

:/

's*'

,

sy-subrc

UNDER

'SY-SUBRC'

,

sy-fdpos

UNDER

'SY-FDPOS'

.

SEARCH

s

for

'*s'

.

WRITE

:/

'*s'

,

sy-subrc

UNDER

'SY-SUBRC'

,

sy-fdpos

UNDER

'SY-FDPOS'

.字符串替換REPORT

zwangzheng10.

DATA

s

TYPE

string.

s

=

'aaa-ss-dd-fff-ggg-sss'.

WRITE

sy-subrc

."sy-subrc初始值為0

WHILE

sy-subrc

=

0

.

REPLACE

'-'

WITH

'

'

INTO

s

.

ENDWHILE

.

WRITE

s

.字符串長度REPORT

zwangzheng11.

DATA:

s

TYPE

string

VALUE

'123456789'

,

len

TYPE

i

.

len

=

STRLEN(

s

).

WRITE

len

.定位操作字符串REPORT

ZWANGZHENG12.

DATA:

s1(8)

TYPE

c

VALUE

'abcdefgh'

,

s2(20)

TYPE

c

value

'1234567890'

.*將s2從下標(biāo)為2的位子開始往后3個(gè)字符串,*替換成s1從下標(biāo)為2的位子開始往后3個(gè)字符串

s2+2(3)

=

s1+2(3)

.

WRITE

s1

.

WRITE

s2

.子程序無參數(shù)data:

a

type

i

value

1

,

b

type

i

value

2,

sum

type

i.

perform

add.

write

sum.

form

add.

sum

=

a

+

b.

endform.帶參數(shù)

DATA:

a

TYPE

i

,

b

TYPE

i

,

c

TYPE

i

,

d

TYPE

i

,

sum

TYPE

i.

START-OF-SELECTION.

a

=

1.

b

=

2.

PERFORM

add

USING

a

b.

WRITE

sum.

FORM

add

USING

c

d.

sum

=

c

+

d.

WRITE

sum.

ENDFORM.

參數(shù)傳值和傳地址對(duì)比

DATA:

a

TYPE

i

,

b

TYPE

i

.

START-OF-SELECTION.

a

=

1.

b

=

1.

"a傳地址

b傳值

PERFORM

add

USING

a

b.

write

:

/

a

,

b.

*輸出結(jié)果21

FORM

add

USING

c

type

i

value(d)

type

i.

c

=

c

+

1.

d

=

d

+

1.

ENDFORM.創(chuàng)建功能模塊function1)t-code:SE37進(jìn)入2)gotofuctiongroupcreategroup輸入組名。操作按書p154-p158操作。包含程序被包含程序不需要programreport進(jìn)行引導(dǎo),不能獨(dú)立運(yùn)行,不能與包含程序之間傳數(shù)據(jù)。創(chuàng)建方法:創(chuàng)建programtype:includeprogram.*&

*&

Include

ZTEST7_15_HEAD

*&*

WRITE:

/

'系統(tǒng)用戶:'

,sy-uname

,

',所在服務(wù)器:',

sy-host,

',日期:',sy-datum

,',時(shí)間',sy-uzeit.

ULINE.調(diào)用包含程序程序中調(diào)用:include

ZTEST7_15_HEAD.靜態(tài)變量聲明:STATICS

a

TYPE

i.內(nèi)表操作定義基本內(nèi)表實(shí)例1:*定義結(jié)構(gòu)體

line

DATA:

BEGIN

OF

line

,

num

TYPE

i,

sqr

TYPE

i,

END

OF

line

.

*定義內(nèi)表itab

按照數(shù)據(jù)line存儲(chǔ)。并且制定整行為關(guān)鍵字

DATA

itab

LIKE

STANDARD

TABLE

OF

line

WITH

KEY

table_line.

DO

5

TIMES

.

line-num

=

sy-index

.

line-sqr

=

sy-index

**

2

.

APPEND

line

TO

itab.

ENDDO

.

LOOP

AT

itab

INTO

line

.

WRITE:

/

line-num

,line-sqr.

ENDLOOP.

CLEAR

itab."清空內(nèi)表實(shí)例2:REPORT

zwangzheng14.

TYPES:BEGIN

OF

address,

street(20)

TYPE

c,

city(20)

TYPE

c,

END

OF

address

.

DATA:

BEGIN

OF

company,

name(20)

TYPE

c,

address

TYPE

address,

END

OF

company.

DATA

itab_company

LIKE

HASHED

TABLE

OF

company

WITH

UNIQUE

KEY

name.

DATA

itab_company_sorted

LIKE

SORTED

TABLE

OF

company

WITH

UNIQUE

KEY

name.2復(fù)雜內(nèi)表.示例一*定義結(jié)構(gòu)

address

DATA:

BEGIN

OF

address,

street(20)

type

c,

city(20)

type

c,

END

OF

address.

*定義標(biāo)準(zhǔn)內(nèi)表address_tab

,結(jié)構(gòu)為:address

TYPES

address_tab

LIKE

STANDARD

TABLE

OF

address

WITH

NON-UNIQUE

KEY

city.

*定義結(jié)構(gòu)

company

包含

address_tab屬性

DATA:

BEGIN

OF

company,

name(20)

TYPE

c,

addresses

TYPE

address_tab,

END

OF

company.

*定義哈希內(nèi)表company_tab,結(jié)構(gòu):company

DATA

company_tab

LIKE

HASHED

TABLE

OF

company

WITH

UNIQUE

KEY

name.

*定義變量idx

:內(nèi)表下標(biāo)

DATA

idx

TYPE

sy-tabix.

*創(chuàng)建一個(gè)

company

結(jié)構(gòu)體數(shù)據(jù):麥當(dāng)勞。

company-name

=

'麥當(dāng)勞'.

address-street

=

'太原街'.

address-city

=

'沈陽'.

APPEND

address

to

company-addresses.

address-street

=

'中街'.

address-city

=

'沈陽'.

APPEND

address

to

company-addresses.

INSERT

company

INTO

TABLE

company_tab.

CLEAR

company.

*創(chuàng)建一個(gè)

company

結(jié)構(gòu)體數(shù)據(jù):肯德基。

company-name

=

'肯德基'.

address-street

=

'王府井'.

address-city

=

'北京'.

APPEND

address

to

company-addresses.

address-street

=

'南京路'.

address-city

=

'上海'.

APPEND

address

to

company-addresses.

INSERT

company

INTO

TABLE

company_tab.

CLEAR

company.

*

*通過

KEY

name

讀取表

裝入company結(jié)構(gòu)

READ

TABLE

company_tab

WITH

KEY

name

=

'肯德基'

INTO

company.

WRITE

/

company-name.

LOOP

AT

company-addresses

INTO

address.

WRITE:

/

sy-tabix

,

address-street

,

address-city

.

ENDLOOP.

*

*

修改內(nèi)表

address-street

=

'五愛街'.

address-city

=

'沈陽'.

READ

TABLE

company_tab

WITH

TABLE

KEY

name

=

'麥當(dāng)勞'

INTO

company.

*讀取

company-addresses

對(duì)應(yīng)內(nèi)表--address_tab

READ

TABLE

company-addresses

TRANSPORTING

NO

FIELDS

WITH

TABLE

KEY

city

=

address-city

.

idx

=

sy-tabix.

"操作內(nèi)表

操作完

返回行記錄索引,未操作

返回0.

*修改company-addresses對(duì)應(yīng)內(nèi)表

將索引為idx的記錄

用address對(duì)象替代

MODIFY

company-addresses

FROM

address

INDEX

idx

.

*?????????????未指定條件

MODIFY

TABLE

company_tab

from

company

.

*

*讀取表信息

*key

字段可以使任何字段,不一定是關(guān)鍵字段

READ

TABLE

company_tab

WITH

KEY

name

=

'麥當(dāng)勞'

INTO

company.

WRITE

/

company-name.

LOOP

AT

company-addresses

INTO

address.

WRITE:

/

sy-tabix

,

address-street

,

address-city

.

ENDLOOP.

*示例二REPORT

ZWANGZHENG17.

DATA:

BEGIN

OF

student,

sid

TYPE

n,

name(20)

TYPE

c,

END

OF

student.

TYPES:

stu_tab

LIKE

STANDARD

TABLE

OF

student

WITH

KEY

sid.

DATA:

BEGIN

OF

class

,

cid

TYPE

n,

name(20)

TYPE

c,

students

TYPE

stu_tab,

END

OF

class.

DATA:

class_tab

LIKE

STANDARD

TABLE

OF

class

WITH

KEY

cid.

class-cid

=

1.

class-name

=

'軟件一班'.

student-sid

=

1.

student-name

=

'Tom'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'Lucy'.

APPEND

student

to

class-students.

student-sid

=

3.

student-name

=

'Lily'.

APPEND

student

to

class-students.

INSERT

class

INTO

TABLE

class_tab.

CLEAR

class.

class-cid

=

2.

class-name

=

'軟件二班'.

student-sid

=

1.

student-name

=

'李雷'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'韓梅梅'.

APPEND

student

to

class-students.

INSERT

class

INTO

TABLE

class_tab.

CLEAR

class.

*讀取數(shù)據(jù)

READ

TABLE

class_tab

WITH

TABLE

KEY

cid

=

1

INTO

class.

WRITE:

/

class-cid,

class-name.

LOOP

AT

class-students

INTO

student.

WRITE:

/

student-sid

,

student-name

.

ENDLOOP.示例三REPORT

ZWANGZHENG18.

DATA:

BEGIN

OF

student,

sid

TYPE

n,

name(20)

TYPE

c,

END

OF

student.

TYPES:

stu_tab

LIKE

STANDARD

TABLE

OF

student

WITH

KEY

sid.

DATA:

BEGIN

OF

class

,

cid

TYPE

n,

name(20)

TYPE

c,

students

TYPE

stu_tab,

END

OF

class.

DATA:

class_tab

LIKE

STANDARD

TABLE

OF

class

WITH

KEY

cid.

class-cid

=

1.

class-name

=

'軟件一班'.

student-sid

=

1.

student-name

=

'Tom'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'Lucy'.

APPEND

student

to

class-students.

student-sid

=

3.

student-name

=

'Lily'.

APPEND

student

to

class-students.

INSERT

class

INTO

TABLE

class_tab.

CLEAR

class.

class-cid

=

2.

class-name

=

'軟件二班'.

student-sid

=

1.

student-name

=

'李雷'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'韓梅梅'.

APPEND

student

to

class-students.

INSERT

class

INTO

TABLE

class_tab.

CLEAR

class.

*讀取數(shù)據(jù)

"READ

TABLE

class_tab

WITH

TABLE

KEY

cid

=

1

INTO

class.

"WRITE:

/

class-cid,

class-name.

LOOP

AT

class_tab

INTO

class.

WRITE:

/

class-cid,

class-name.

LOOP

AT

class-students

INTO

student.

WRITE:

/

student-sid

,

student-name

.

ENDLOOP.

WRITE

/.

ENDLOOP.示例四

REPORT

ZWANGZHENG19.

DATA:

BEGIN

OF

student,

sid

TYPE

n,

name(20)

TYPE

c,

END

OF

student.

TYPES:

stu_tab

LIKE

STANDARD

TABLE

OF

student

WITH

KEY

sid.

DATA:

BEGIN

OF

class

,

cid

TYPE

n,

name(20)

TYPE

c,

students

TYPE

stu_tab,

END

OF

class.

TYPES:

class_tab

LIKE

STANDARD

TABLE

OF

class

WITH

KEY

cid.

DATA:

BEGIN

OF

dept

,

did

TYPE

n,

name(20)

TYPE

c,

classes

TYPE

class_tab,

END

OF

dept.

DATA:

dept_tab

LIKE

STANDARD

TABLE

OF

dept

WITH

KEY

did.

dept-did

=

1.

dept-name

=

'信息學(xué)院'.

class-cid

=

1.

class-name

=

'軟件一班'.

student-sid

=

1.

student-name

=

'Tom'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'Lucy'.

APPEND

student

to

class-students.

student-sid

=

3.

student-name

=

'Lily'.

APPEND

student

to

class-students.

APPEND

class

TO

dept-classes.

CLEAR

class.

class-cid

=

2.

class-name

=

'軟件二班'.

student-sid

=

1.

student-name

=

'李雷'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'韓梅梅'.

APPEND

student

to

class-students.

"INSERT

class

INTO

TABLE

class_tab.

APPEND

class

TO

dept-classes.

CLEAR

class.

INSERT

dept

INTO

TABLE

dept_tab.

CLEAR

DEPT.

dept-did

=

2.

dept-name

=

'法學(xué)院'.

class-cid

=

1.

class-name

=

'民法一班'.

student-sid

=

1.

student-name

=

'張三'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'李四'.

APPEND

student

to

class-students.

student-sid

=

3.

student-name

=

'王五'.

APPEND

student

to

class-students.

APPEND

class

TO

dept-classes.

CLEAR

class.

class-cid

=

2.

class-name

=

'憲法一班'.

student-sid

=

1.

student-name

=

'劉德華'.

APPEND

student

to

class-students.

student-sid

=

2.

student-name

=

'張惠妹'.

APPEND

student

to

class-students.

"INSERT

class

INTO

TABLE

class_tab.

APPEND

class

TO

dept-classes.

CLEAR

class.

INSERT

dept

INTO

TABLE

dept_tab.

CLEAR

DEPT.

*讀取數(shù)據(jù)

LOOP

AT

dept_tab

INTO

dept.

WRITE:

/

dept-did,

dept-name

.

WRITE:

/.

LOOP

AT

dept-classes

INTO

class.

WRITE:

/

'

',

class-cid,

class-name.

LOOP

AT

class-students

INTO

student.

WRITE:

/

'

',

student-sid

,

student-name

.

ENDLOOP.

WRITE

/.

ENDLOOP.

WRITE

/.

ENDLOOP.數(shù)據(jù)庫建表先建表輸入dataelement名(不存在),雙擊名字,去創(chuàng)建,創(chuàng)建過程中輸入DOMAIN名(不存在),雙擊創(chuàng)建,選擇數(shù)據(jù)類型和長度nocharactor數(shù)據(jù)庫查詢示例表spfliscar單表查詢

1)單行查詢

1.1所有字段,將結(jié)果裝入結(jié)構(gòu)體中。

DATA

wa_spfli

TYPE

spfli.

SELECT

SINGLE

*

FROM

spfli

INTO

wa_spfli

WHERE

cityfrom

=

'SINGAPORE'

.

WRITE:

/

wa_spfli-mandt

,

wa_spfli-carrid

,

wa_spfli-connid

,

wa_spfli-countryfr

,

wa_spfli-countryfr

,

wa_spfli-cityfrom

,

wa_spfli-cityto

.

"

運(yùn)行結(jié)果:

800

QF

0005

SG

SG

SINGAPORE

FRANKFURT

"

結(jié)果為第一個(gè)符合條件的數(shù)據(jù)行。

1.2部分字段

1.2.1結(jié)果裝入多個(gè)基本數(shù)據(jù)類型

DATA:

wa_mandt

TYPE

spfli-mandt,

wa_carrid

TYPE

spfli-carrid,

wa_connid

TYPE

spfli-connid.

SELECT

SINGLE

mandt

carrid

connid

FROM

spfli

INTO

(wa_mandt,wa_carrid,wa_connid)

WHERE

cityfrom

=

'SINGAPORE'

.

WRITE:

/

wa_mandt,

wa_carrid,

wa_connid

.

"運(yùn)行結(jié)果:800

QF

0005

1.2.2結(jié)果裝入結(jié)構(gòu)體中

*效率不如裝入多個(gè)基本數(shù)據(jù)類型高。

data

wa_spfli

type

spfli.

SELECT

SINGLE

mandt

carrid

connid

from

spfli

into

corresponding

fields

of

wa_spfli

where

cityfrom

=

'SINGAPORE'

.

WRITE:

/

wa_spfli-mandt,

wa_spfli-carrid,

wa_spfli-connid

.

"運(yùn)行結(jié)果相同,效率較低

2)多行查詢

2.1所有字段

2.1.1循環(huán)查詢

裝入結(jié)構(gòu)

并且輸出。

data

wa_spfli

type

spfli.

SELECT

*

FROM

spfli

INTO

wa_spfli

WHERE

cityfrom

=

'SINGAPORE'

.

write:

/

wa_spfli-mandt,

wa_spfli-carrid,

wa_spfli-connid

,

wa_spfli-countryfr

,

wa_spfli-cityfrom

,

wa_spfli-cityto.

endselect.

*輸出結(jié)果:

*800

QF

0005

SG

SINGAPORE

FRANKFUR

*800

SQ

0002

SG

SINGAPORE

SAN

FRAN

*800

SQ

0158

SG

SINGAPORE

JAKARTA

*800

SQ

0988

SG

SINGAPORE

TOKYO

"將都裝入一個(gè)結(jié)構(gòu)體中,每次循環(huán)會(huì)被替換。

2.1.2

查詢

裝入內(nèi)表。

DATA

spfli_tab

TYPE

TABLE

OF

spfli.

"按照spfli結(jié)構(gòu)定義內(nèi)表

SELECT

*

FROM

spfli

INTO

TABLE

spfli_tab.

"迭代內(nèi)表。

DATA

wa_spfli

TYPE

spfli.

"負(fù)責(zé)存貯每次迭代出的數(shù)據(jù)

LOOP

AT

spfli_tab

INTO

wa_spfli.

write:

/

wa_spfli-mandt,

wa_spfli-carrid,

wa_spfli-connid

,

wa_spfli-countryfr

,

wa_spfli-cityfrom

,

wa_spfli-cityto.

ENDLOOP.

*運(yùn)行結(jié)果:

*800

AA

0017

US

NEW

YORK

SAN

FRANCISCO

*800

AA

0064

US

SAN

FRANCISCO

NEW

YORK

*800

AZ

0555

IT

ROME

FRANKFURT

*800

AZ

0788

IT

ROME

TOKYO

*800

AZ

0789

JP

TOKYO

ROME

*800

AZ

0790

IT

ROME

OSAKA

*800

DL

0106

US

NEW

YORK

FRANKFURT

*800

DL

1699

US

NEW

YORK

SAN

FRANCISCO

*800

DL

1984

US

SAN

FRANCISCO

NEW

YORK

*800

JL

0407

JP

TOKYO

FRANKFURT

*800

JL

0408

DE

FRANKFURT

TOKYO

*800

LH

0400

DE

FRANKFURT

NEW

YORK

*800

LH

0401

US

NEW

YORK

FRANKFURT

*800

LH

0402

DE

FRANKFURT

NEW

YORK

*800

LH

2402

DE

FRANKFURT

BERLIN

*800

LH

2407

DE

BERLIN

FRANKFURT

*800

QF

0005

SG

SINGAPORE

FRANKFURT

*800

QF

0006

DE

FRANKFURT

SINGAPORE

*800

SQ

0002

SG

SINGAPORE

SAN

FRANCISCO

*800

SQ

0015

US

SAN

FRANCISCO

SINGAPORE

*800

SQ

0158

SG

SINGAPORE

JAKARTA

*800

SQ

0988

SG

SINGAPORE

TOKYO

*800

UA

0941

DE

FRANKFURT

SAN

FRANCISCO

*800

UA

3504

US

SAN

FRANCISCO

FRANKFURT

*800

UA

3516

US

NEW

YORK

FRANKFURT

*800

UA

3517

DE

FRANKFURT

NEW

YORK

2.2部分字段

2.2.1

查詢

裝入內(nèi)表。

"定義結(jié)構(gòu)

與查詢字段列表結(jié)構(gòu)相同

TYPES:

BEGIN

OF

tab_type,

mandt

TYPE

spfli-mandt

,

carrid

TYPE

spfli-carrid

,

connid

TYPE

spfli-connid

,

END

OF

tab_type.

data

spfli_tab2

type

table

of

tab_type.

"定義內(nèi)表類型

SELECT

mandt

carrid

connid

FROM

spfli

into

corresponding

fields

of

table

spfli_tab2

where

carrid

=

'AA'.

"迭代內(nèi)表

data

t_t

type

tab_type.

loop

at

spfli_tab2

into

t_t.

write:

/

t_t-mandt,

t_t-carrid

,

t_t-connid.

endloop.

*運(yùn)行結(jié)果:

*800

AA

0017

*800

AA

0064(二)多表聯(lián)合查詢1.嵌套查詢data:

wa_carrid

type

spfli-carrid,

wa_connid

type

spfli-connid,

wa_carrname

type

scarr-carrname.

select

carrid

connid

from

spfli

into

(wa_carrid

,

wa_connid)

where

cityfrom

=

'SAN

FRANCISCO'

.

write:

/

wa_carrid

,

wa_connid.

select

carrname

from

scarr

into

wa_carrname

where

carrid

=

wa_carrid."查詢結(jié)果與表數(shù)據(jù)比較

write

wa_carrname.

endselect.

endselect.2.FOR

ALL

ENTRIESDATA:

BEGIN

OF

wa_spfli,

"!!!!!!

"types:

BEGIN

OF

wa_spfli,

"

carrid

TYPE

spfli-carrid,

connid

TYPE

spfli-connid,

END

OF

wa_spfli.

DATA

spfli_tab

LIKE

TABLE

OF

wa_spfli.

"!!!!!!

"data

spfli_table

type

table

of

wa_spfli.

"

*與,!!!!!!與!!!!!!

組合使用

data:

begin

of

wa_scarr,

carrid

type

scarr-carrid

,

carrname

type

scarr-carrname

,

end

of

wa_scarr.

SELECT

carrid

connid

FROM

spfli

INTO

TABLE

spfli_tab

WHERE

cityfrom

=

'SAN

FRANCISCO'

.

select

carrid

carrname

from

scarr

into

wa_scarr

for

all

entries

in

spfli_tab“對(duì)應(yīng)字段插入值

where

carrid

=

spfli_tab-carrid.

write:

/

wa_scarr-carrid

,

wa_scarr-carrname.

endselect.

"輸出結(jié)果

*AA

American

Airlines

*DL

Delta

Airlines

*SQ

Singapore

Airlines

*UA

United

Airlines3多表結(jié)合查詢結(jié)果放入變量DATA:

wa_carrid

TYPE

spfli-carrid,

wa_connid

TYPE

spfli-connid,

wa_carrname

TYPE

scarr-carrname.

SELECT

spfli~carrid

scarr~carrname

spfli~connid

FROM

spfli

INNER

JOIN

scarr

ON

scarr~carrid

=

spfli~carrid

INTO

(wa_carrid

,

wa_carrname,wa_connid)

WHERE

spfli~cityfrom

=

'SINGAPORE'.

write:

/

wa_carrid

,

wa_connid,

wa_carrname.

ENDSELECT.查詢單行,結(jié)果放入結(jié)構(gòu)體對(duì)象(工作區(qū))中

TYPES:BEGIN

OF

wa_spfli_type,

carrid

TYPE

spfli-carrid,

connid

TYPE

spfli-connid,

carrname

TYPE

scarr-carrname,

END

OF

wa_spfli_type.

DATA

wa_spfli

TYPE

wa_spfli_type.

SELECT

SINGLE

spfli~carrid

spfli~connid

scarr~carrname

FROM

spfli

INNER

JOIN

scarr

ON

scarr~carrid

=

spfli~carrid

INTO

wa_spfli

WHERE

spfli~cityfrom

=

'SINGAPORE'.

write:

/

wa_spfli-carrid

,

wa_spfli-connid

,

wa_spfli-carrname

.查詢多行,結(jié)果放入內(nèi)表中

TYPES:BEGIN

OF

wa_spfli_type,

carrid

TYPE

spfli-carrid,

connid

TYPE

spfli-connid,

carrname

TYPE

scarr-carrname,

END

OF

wa_spfli_type.

data

spfil_tab

type

table

of

wa_spfli_type.

select

spfli~carrid

spfli~connid

scarr~carrname

from

spfli

inner

join

scarr

on

scarr~carrid

=

spfli~carrid

into

corresponding

fields

of

table

spfil_tab

.

data

wa_spfli

type

wa_spfli_type.

loop

at

spfil_tab

into

wa_spfli.

write:

/

wa_spfli-carrid

,wa_spfli-connid

,

wa_spfli-carrname.

endloop.

*輸出結(jié)果

*AA

0017

American

Airlines

*AA

0064

American

Airlines

*AZ

0555

Alitalia

*AZ

0788

Alitalia

*AZ

0789

Alitalia

*AZ

0790

Alitalia

*DL

0106

Delta

Airlines

*DL

1699

Delta

Airlines

*DL

1984

Delta

Airlines

*JL

0407

Japan

Airlines

*JL

0408

Japan

Airlines

*LH

0400

Lufthansa

*LH

0401

Lufthansa

*LH

0402

Lufthansa

*LH

2402

Lufthansa

*LH

2407

Lufthansa

*QF

0005

Qantas

Airways

*QF

0006

Qantas

Airways

*SQ

0002

Singapore

Airline

*SQ

0015

Singapore

Airline

*SQ

0158

Singapore

Airline

*SQ

0988

Singapore

Airline

*UA

0941

United

Airlines

*UA

3504

United

Airlines

*UA

3516

United

Airlines

*UA

3517

United

Airlines數(shù)據(jù)庫操作查詢學(xué)生班級(jí)表。使用表zstudentzclass單表查詢

多行

所有字段。

*Data

stu_tab

type

table

of

zstudent.

*data

wa_stu

type

zstudent.

*select

*

*

from

zstudent

*

*

into

table

stu_tab

*

order

by

zstudent~sid.

*

*

loop

at

stu_tab

into

wa_stu.

*

write:

/

wa_stu-sid

,

wa_stu-sname

,

wa_stu-sex

,

wa_stu-age

.

*

endloop.

多行部分字段

*TYPES:

BEGIN

OF

stu_type,

*

sid

TYPE

zstudent-sid,

*

sname

TYPE

zstudent-sname,

*

END

OF

stu_type.

*

*DATA

stu_tab

TYPE

TABLE

OF

stu_type.

*DATA

wa_stu

TYPE

stu_type.

*

*SELECT

sid

sname

*

FROM

zstudent

*

INTO

TABLE

stu_tab

*

WHERE

cid

=

1.

*

*LOOP

AT

stu_tab

INTO

wa_stu.

*

write:

/

wa_stu-sid

,

wa_stu-sname.

*ENDLOOP.

單行

所有字段

*data

wa_stu

type

zstudent.

*

*select

single

*

*

from

zstudent

*

into

wa_stu

*

where

sid

=

1

.

*

*

write:

wa_stu-sid

,

wa_stu-sname

,

wa_stu-cid

.

單行

部分字段

*TYPES:

BEGIN

OF

stu_type,

*

sid

TYPE

zstudent-sid,

*

sname

TYPE

zstudent-sname,

*

cid

TYPE

zstudent-cid,

*

END

OF

stu_type.

*

*DATA

wa_stu

TYPE

stu_type.

*

*SELECT

SINGLE

sid

sname

cid

*

FROM

zstudent

*

INTO

wa_stu

*

WHERE

sid

=

11.

*

*

write:

/

wa_stu-sid

,

wa_stu-sname

,

wa_stu-cid.多表聯(lián)合查詢

多行查詢

所有字段

TYPES:

BEGIN

OF

stu_class_type,

sid

TYPE

zstudent-sid

,

sname

TYPE

zstudent-sname,

sex

TYPE

zstudent-sex,

age

TYPE

zstudent-age,

cid

TYPE

zclass-cid

,

cname

TYPE

zclass-cname

,

address

TYPE

zclass-address

,

END

OF

stu_class_type.

DATA

stu_class_tab

TYPE

TABLE

OF

stu_class_type.

SELECT

*

FROM

zstudent

JOIN

zclass

ON

zstudent~cid

=

zclass~cid

INTO

CORRESPONDING

FIELDS

OF

TABLE

stu_class_tab

WHERE

zstudent~cid

=

1.

DATA

wa_stu_class

TYPE

stu_class_type.

LOOP

AT

stu_class_tab

into

wa_stu_class.

write:

/

wa_stu_class-sid

,

wa_stu_class-sname

,

wa_stu_class-cid

,

wa_stu_class-cname

,wa_stu_class-address.

endloop

.多行查詢

部分字段

types:

begin

of

stu_class_type,

sid

type

zstudent-sid,

sname

type

zstudent-sname,

cid

type

zclass-cid,

cname

type

zclass-cname,

end

of

stu_class_type.

data

stu_class_tab

type

table

of

stu_class_type.

data

wa_stu_class

type

stu_class_type.

select

zstudent~sid

zstudent~sname

zclass~cid

zclass~cname

from

zstudent

join

zclass

on

zstudent~cid

=

zclass~cid

into

table

stu_class_tab

where

zclass~cid

=

2

.

loop

at

stu_class_tab

into

wa_stu_class.

write:

/

wa_stu_class-sid,

wa_stu_class-sname

,

wa_stu_class-cid

,

wa_stu_class-cname.

endloop.單行

所有字段

TYPES:

BEGIN

OF

stu_class_type,

sid

TYPE

zstudent-sid

,

sname

TYPE

zstudent-sname,

sex

TYPE

zstudent-sex,

age

TYPE

zstudent-age,

cid

TYPE

zclass-cid

,

cname

TYPE

zclass-cname

,

address

TYPE

zclass-address

,

END

OF

stu_class_type.

data

wa_stu_class

type

stu_class_type.

select

single

*

from

zstudent

join

zclass

on

zstudent~cid

=

zclass~cid

"對(duì)應(yīng)同名字段。

into

corresponding

fields

of

wa_stu_class

where

zstudent~sid

=

12.

write:

/

wa_stu_class-sid

,

wa_stu_class-sname

,

wa_stu_class-sex

,

wa_stu_class-cid

,

wa_stu_class-cname

,

wa_stu_class-address.單行部分字段

types:

begin

of

stu_class_type,

sid

type

zstudent-sid,

sname

type

zstudent-sname,

cid

type

zclass-cid,

cname

type

zclass-cname,

end

of

stu_class_type.

data

wa_stu_class

type

stu_class_type.

select

single

zstudent~sid

zstudent~sname

zclass~cid

zclass~cname

from

zstudent

join

zclass

on

zstudent~cid

=

zclass~cid

into

wa_stu_class

where

zstudent~sid

=

13.

write:

/

wa_stu_class-sid

,

wa_stu_class-sname

,

wa_stu_class-cid

,

wa_stu_class-cname

.添加數(shù)據(jù)添加一條DATA

wa_stu

TYPE

zstudent.

wa_stu-sid

=

102.

wa_stu-sname

=

'hanmeimei'.

wa_stu-sex

=

'女'.

wa_stu-age

=

19.

wa_stu-cid

=

1.

INSERT

into

zstudent

values

wa_stu.插入多行數(shù)據(jù)DATA

stu_tab

TYPE

TABLE

OF

zstudent.

DATA

wa_stu

TYPE

zstudent.

wa_stu-sid

=

103.

wa_stu-sname

=

'劉德華'.

wa_stu-sex

=

'男'.

wa_stu-age

=

50.

wa_stu-cid

=

1.

APPEND

wa_stu

TO

stu_tab.

wa_stu-sid

=

104.

wa_stu-sname

=

'

張學(xué)友'.

wa_stu-sex

=

'男'.

wa_stu-age

=

49.

wa_stu-cid

=

1.

APPEND

wa_stu

TO

stu_tab.

INSERT

zstudent

FROM

TABLE

stu_tab.修改記錄使用變量修改

update

zstudent

set

sname

=

'韓梅梅'

age

=

20

where

sid

=

102.

使用工作區(qū)修改

DATA

wa_stu

TYPE

zstudent.

*數(shù)據(jù)必須填寫全,不填項(xiàng)將被設(shè)置為空。

wa_stu-sid

=

101.

wa_stu-sname

=

'李磊'.

wa_stu-sex

=

'男'.

wa_stu-age

=

20.

wa_stu-cid

=

1.

update

zstudent

from

wa_stu.使用內(nèi)表修改多條數(shù)據(jù)

data

stu_tab

type

table

of

zstudent.

data

wa_stu

type

zstudent.

wa_stu-sid

=

10.

wa_stu-sname

=

'lily'.

wa_stu-sex

=

'女'.

wa_stu-age

=

16.

wa_stu-cid

=

1.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

11.

wa_stu-sname

=

'lucy'.

wa_stu-sex

=

'女'.

wa_stu-age

=

16.

wa_stu-cid

=

1.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

12.

wa_stu-sname

=

'tom'.

wa_stu-sex

=

'男'.

wa_stu-age

=

18.

wa_stu-cid

=

1.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

13.

wa_stu-sname

=

'jim'.

wa_stu-sex

=

'男'.

wa_stu-age

=

19.

wa_stu-cid

=

1.

append

wa_stu

to

stu_tab.

update

zstudent

from

table

stu_tab.修改或保存使用工作區(qū)修改或保存

data

wa_stu

type

zstudent.

wa_stu-sid

=

2.

wa_stu-sname

=

'周杰倫'.

wa_stu-sex

=

'男'.

wa_stu-age

=

32.

wa_stu-cid

=

1.

*當(dāng)主鍵存在時(shí)修改否則添加。

modify

zstudent

from

wa_stu.使用內(nèi)表

修改或保存

data

stu_tab

type

table

of

zstudent.

data

wa_stu

type

zstudent.

wa_stu-sid

=

13.

wa_stu-sname

=

'Jim

Green'.

wa_stu-sex

=

'男'.

wa_stu-age

=

18.

wa_stu-cid

=

1.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

14.

wa_stu-sname

=

'王叔叔'.

wa_stu-sex

=

'男'.

wa_stu-age

=

60.

wa_stu-cid

=

1.

append

wa_stu

to

stu_tab.

modify

zstudent

from

table

stu_tab.刪除

使用條件

必須列出所有關(guān)鍵字

delete

from

zstudent

where

sid

=

1.使用工作區(qū)刪除

*僅需要為工作區(qū)賦值所有關(guān)鍵字

data

wa_stu

type

zstudent.

wa_stu-sid

=

100.

delete

zstudent

from

wa_stu.使用內(nèi)表刪除

data

stu_tab

type

table

of

zstudent.

data

wa_stu

type

zstudent.

wa_stu-sid

=

11.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

12.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

13.

append

wa_stu

to

stu_tab.

wa_stu-sid

=

14.

append

wa_stu

to

stu_tab.

delete

zstudent

from

table

stu_tab.案例:查詢數(shù)據(jù)庫數(shù)據(jù)至內(nèi)表修改內(nèi)容并且更新到數(shù)據(jù)庫*練習(xí)將zstudent表中數(shù)據(jù)

查詢

裝入內(nèi)表,循環(huán)內(nèi)表

將所有人age+1

sname后

+先生、女士

DATA

stu_tab

TYPE

TABLE

OF

zstudent.

DATA

wa_stu

TYPE

zstudent.

SELECT

*

FROM

zstudent

INTO

CORRESPONDING

FIELDS

OF

TABLE

stu_tab.

LOOP

AT

stu_tab

INTO

wa_stu.

WRITE:

/

wa_stu-sid

,wa_stu-sname

,

wa_stu-sex

,wa_stu-age

,wa_stu-cid.

wa_stu-age

=

wa_stu-age

+

10.

IF

wa_stu-sex

=

'男'

.

concatenate

wa_stu-sname

'先生'

into

wa_stu-sname.

ELSEIF

wa_stu-sex

=

'女'.

concatenate

wa_stu-sname

'女士'

into

wa_stu-sname.

ELSE

.

concatenate

wa_stu-sname

'同志'

into

wa_stu-sname.

ENDIF.

"WRITE:

/

'--'

,wa_stu-sid

,wa_stu-sname

,

wa_stu-sex

,wa_stu-age

,wa_stu-cid.

modify

zstudent

from

wa_stu."更新回?cái)?shù)據(jù)庫

"MODIFY

stu_tab

FROM

wa_stu

."或者先將工作區(qū)內(nèi)容更新回內(nèi)表

ENDLOOP.

"modify

zstudent

from

table

stu_tab."將內(nèi)表整體更新回?cái)?shù)據(jù)庫報(bào)表設(shè)計(jì)選擇屏幕選擇屏幕參數(shù)DATA

stu_tab

TYPE

TABLE

OF

zstudent.

DATA

wa_stu

TYPE

zstudent.

PARAMETERS

p_sex(4)

TYPE

c.

SELECT

*

FROM

zstudent

INTO

CORRESPONDING

FIELDS

OF

TABLE

stu_tab

WHERE

sex

=

p_sex.

LOOP

AT

stu_tab

INTO

wa_stu.

write:

/

wa_stu-sid

,

wa_stu-sname

,

wa_stu-sex

,

wa_stu-age

,

wa_stu-cid.

ENDLOOP.格式化屏幕參數(shù)

parameters

sname(20)

type

c

default

'姓名'.

"默認(rèn)值

parameters

age

type

i

obligatory

."必填******單選框使用*******PARAMETERS:

r1

RADIOBUTTON

GROUP

rad1

,

r2

RADIOBUTTON

GROUP

rad1

,

r3

RADIOBUTTON

GROUP

rad1

DEFAULT

'X'

.

IF

r1

=

'X'.

WRITE:

/

'r1'.

ELSEIF

r2

=

'X'.

WRITE:

/

'r2'.

ELSE.

WRITE:

/

'r3'.

ENDIF.復(fù)雜選擇標(biāo)準(zhǔn)data

wa_zstudent

type

zstudent.

*設(shè)置選擇條件

select-options

so_stu

for

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論