ABAP创建选择屏幕的详细介绍
选择屏幕
读者从ABAP开发帮助⽂档能了解选择屏幕的使⽤,有本英⽂教材是<<21天学会ABAP>>,同样本书的
⽬的是让有⼀定程序基础的读者在三个⽉内成为ABAP顾问,故本书重点将放在实际业务分析上,因
此在此只是汇总下选择屏幕的使⽤.
下⾯是⼀个典型的选择屏幕的典型例⼦.
1.设置选择屏幕参数.
***begin(end) of block使⽤屏幕元素逻辑块.
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TITLE1.
***定义选择标准,⽐如那些屏幕⼦段使⽤范围,设置为必选或使⽤内存ID等.
SELECT-OPTIONS <seltab> FOR <f> DEFAULT│NO INTERVALS│OBLIGATORY│NO-DISPLAY│MEMORY
<
***要在选择屏幕上书写⽂本使⽤屏幕注释并在屏幕初始化时赋值.
SELECTION-SCREEN COMMENT ...
***在屏幕上画线.
SELECTION-SCREEN ULINE ...
***Begind(end)of line包含的屏幕参数将在同⼀条直线上.
SELECTION-SCREEN BEGIN
SELECTION-SCREEN END
***设置屏幕位置.
***在应⽤⼯具条上创建按钮响应事件
SELECTION-SCREEN
***在屏幕上创建按钮.
SELECTION SCREEN PUSHBUTTON ...
SELECTION-SCREEN END OF BLOCK BK1.
INITIALIZATION.
***初始化屏幕参数,类似VB的Form_load事件***
AT SELECTION-SCREEN <on help(value)-request for field│>.
***系统选择屏幕时的过程处理,⽐如需要判断⼀些屏幕字段的条件限制如为某些值则***显⽰
error message,程序没有必要浪费时间继续执⾏下去.
***on help-request 可为屏幕字段显⽰⾃定义帮助
***on value-request可显⽰建议列表值
***可这样理解AT selection-screen相当于 PBO.
***PERFORM sub_validate_FieldXXX .
***选屏后按Enter或F8运⾏时都会执⾏.
START-OF-SELECTION .
***设置内表值,处理没有附加关键字的所有语句.
***通常包含在此的Form是在按F8后才开始执⾏.
END-OF_SELECTION .
AT USER-COMMAND.
***处理⽤户请求事件,如报表使⽤ALV格式,通常在call function exporting
*** I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
***再建⽴⼀个⼦程序form USER_COMMAND USING UCOMM LIKE SY-UCOMM
AT LINE-SELECTION.
***通常此事件在报表显⽰后⽤户在列表中在选择⾏时触发.如报表使⽤的是write
***就可使⽤此事件.
*** SET PARAMETER ID 'XXX' FIELD XXX.
*** call transACtion 'XXX' AND SKIP FIRST SCREEN.
TOP-OF-PAGE.
*** 显⽰数据,使⽤TOP-OF-PAGE是在分页时可将定义的页头页尾在每页显⽰.
*** PERFORM write_page_header(page header在每页都显⽰).
*** PERFORM DISPLAY_ALV_DATA.
END-OF-PAGE.
abap开发顾问是程序员吗下⾯⼀个简单的会计凭证显⽰的实例说明选择屏幕的使⽤.
***这程序只是做演⽰⽤,但是包含了常⽤的选择屏幕技术.
将下⾯的程序copy就可跑.
REPORT ZSELECTION NO STANDARD PAGE HEADING
MESSAGE-ID zFIMSG "MEssage Class
LINE-SIZE 255
LINE-COUNT 32(3).
tables :BKPF,BSEG,S070.
DATA:ZBKPF like bkpf occurs 0 ,
zwa_bkpf like bkpf.
CONSTANTS:P_variant(2) TYPE c VALUE 'WL'.
***下⾯这些屏幕参数和事件没有关系,只是参数集⽽已.
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE Cond1.
SELECT-OPTIONS S_bukrs FOR bkpf-bukrs MEMORY ID BUK.
SELECT-OPTIONS S_blart FOR bkpf-blart NO INTERVALS .
SELECT-OPTIONS S_belnr FOR bkpf-belnr .
SELECT-OPTIONS S_budat FOR bkpf-budat DEFAULT sy-datum.
SELECT-OPTIONS S_bldat FOR bkpf-bldat NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_gjahr FOR bkpf-gjahr MEMORY ID GJR DEFAULT sy-datum(4).
SELECT-OPTIONS weekran for s070-SPBUP NO-EXTENSION .
SELECTION-SCREEN END OF BLOCK bk1.
SELECTION-SCREEN BEGIN OF BLOCK bk2 WITH FRAME TITLE Cond2. SELECTION-SCREEN COMMENT /1(30) COMM1 . "使⽤屏幕注释SELECTION-SCREEN BEGIN OF LINE ."两单选框将在同⼀条线上. PARAMETERS pnor RADIOBUTTON GROUP grp1 DEFAULT 'X'."Print normal doc PAR
AMETERS ppark RADIOBUTTON GROUP grp1. "Print parked doc SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN END OF BLOCK bk2.
***1 初始化参数.
INITIALIZATION.
Cond1 = '【Condition】'.
Cond2 = '【Normal Doc│Parked Doc】'.
COMM1 = 'Choose Doc. Type:'. "注释赋初值.
***初始公司值,这在有些需要后台跑的程序⾮常有⽤,除了使⽤variant外,在此也可赋初***下⾯的例⼦在初始化后公司代码选择了1000和3000排除了2000
S_bukrs-low = '1000'.
S_bukrs-sign = 'I'. "I->包含,E->排除
S_bukrs-option = 'EQ'. "NE
APPEND S_bukrs.
S_bukrs-low = '2000'.
S_bukrs-sign = 'E'.
S_bukrs-option = 'EQ'.
APPEND S_bukrs.
S_bukrs-low = '3000'.
S_bukrs-sign = 'E'.
S_bukrs-option = 'EQ'.
APPEND S_bukrs.
***初始化doc range 从010*******到1000000000
s_belnr-low = '010*******'.
s_belnr-high = '1000000000'.
s_belnr-sign = 'I' .
s_belnr-option = 'BT'.
append s_belnr.
***2 使⽤sug_get_week后得到所选⽇期的当前周数,在选择weekrag字段时才触发. ***当你选择weekran字段时.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR weekran-low. PERFORM sub_get_week CHANGING weekran-low.
AT SELECTION-SCREEN.
***判断所选择的公司代码是否有效,通常并不是必须的.
***当然你也可将此步省略,直接在START-OF-SELECTION判断.
***根据需要可做很多vaid字段的判断.
PERFORM SUB_VALIDATE_COMP.
***3开始选屏
START-OF-SELECTION.
Perform SUB_GET_DOC.
PERFORM SUB_WRT_DOC.
END-OF-SELECTION.
***4.分页时显⽰page header或page footer.
TOP-OF-PAGE.
perform sub_WRT_HEADER.
end-of-page.
***5.当点击⾏并且是点到Document NO.CAll FB03.
AT line-selection.
Perform sub_line_response.
form sub_line_response.
Data: ZFLDNAME like DD01L-DOMNAME,
ZFLDVALUE like TTREET-TEXT,
zwa_bkpf like bkpf.
GET CURSOR FIELD ZFLDNAME VALUE ZFLDVALUE .
if ZFLDNAME = 'ZWA_BKPF-BELNR' .
* READ TABLE Zbkpf into zwa_bkpf WITH KEY BELNR = ZFLDVALUE.
* SET PARAMETER ID 'BUK' FIELD zwa_bkpf-BUKRS.
* SET PARAMETER ID 'GJR' FIELD zwa_bkpf-GJAHR.
* SET PARAMETER ID 'BLN' FIELD zwa_bkpf-BELNR.
SET PARAMETER ID 'BLN' FIELD ZFLDVALUE .
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
endif.
endform .
FORM SUB_GET_DOC.
refresh zbkpf .
SELECT * FROM bkpf into table Zbkpf
WHERE bukrs IN s_bukrs
AND belnr IN s_belnr
AND gjahr IN s_gjahr
AND budat IN s_budat.
endform.
form sub_wrt_header.
FORMAT INTENSIFIED COLOR = 6.
WRITE AT: /01 'Finaincial Document List:'(h07).
FORMAT COLOR COL_NORMAL ON.
FORMAT COLOR COL_HEADING ON.
WRITE AT:/01(48) sy-uline.
FORMAT COLOR COL_HEADING OFF.
FORMAT COLOR OFF.
endform.
form sub_wrt_doc.
uline /1(41).
loop at zbkpf into zwa_bkpf.
write:/ '│',zwa_bkpf-bukrs,'│',zwa_bkpf-belnr,'│',zwa_bkpf-gjahr,'│',zwa_bkpf- budat,'│'.
uline /1(41).
endloop.
endform.
FORM SUB_VALIDATE_COMP.
data itab_bukrs like bkpf-bukrs occurs 0 .
select bukrs into table itab_bukrs
from T001
where BUKRS in S_bukrs .
if itab_bukrs IS INITIAL.
Message e002(00) .
endif.
endform.
FORM sub_get_week CHANGING wkran LIKE s070-SPBUP.
DATA: l_date LIKE workflds-gkday,
l_period LIKE t009b-poper,
l_year LIKE t009b-bdatj.
***根据选择⽇期得到当前周数
CALL FUNCTION 'F4_DATE'
EXPORTING
date_for_first_month = sy-datum
display = ''
IMPORTING
select_date = l_date
EXCEPTIONS
calendar_buffer_not_loadable = 1
date_after_range = 2
date_before_range = 3
date_invalid = 4
factory_calendar_not_found = 5
holiday_calendar_not_found = 6
parameter_conflict = 7
OTHERS = 8.
CALL FUNCTION 'G_PERIOD_GET'
EXPORTING
date = l_date
***使⽤WL variant得到的period是周/年,空则是期间/年.
***在CO-PA或做计划时,通常是以周做period的.
variant = P_variant "'WL'
IMPORTING
period = l_period
year = l_year
EXCEPTIONS
ledger_not_assigned_to_company = 1
period_not_defined = 2
variant_not_defined = 3
OTHERS = 4.
weekran-sign = 'I'.
weekran-option = 'EQ'.
CONCATENATE l_year l_period+1(2) INTO wkran.
endform.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论