研究、分享我学习零售业SAP的历程
------------打造中国第一个零售SAP博客
选择屏幕

下面是一个典型的选择屏幕的典型例子.
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
ID...
***要在选择屏幕上书写文本使用屏幕注释并在屏幕初始化时赋值.
 SELECTION-SCREEN COMMENT ...
***在屏幕上画线.
 SELECTION-SCREEN ULINE ...
***Begind(end)of line包含的屏幕参数将在同一条直线上.
 SELECTION-SCREEN BEGIN OF LINE...
 SELECTION-SCREEN END OF LINE...
***设置屏幕位置.
 SELECTION-SCREEN POSITION...
***在应用工具条上创建按钮响应事件
 SELECTION-SCREEN FUNCTION KEY...
***在屏幕上创建按钮.
 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.
下面一个简单的会计凭证显示的实例说明选择屏幕的使用.
***这程序只是做演示用,但是包含了常用的选择屏幕技术.
将下面的程序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
PARAMETERS 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 从0100000000到1000000000
 s_belnr-low = '0100000000'.
 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.
posted on 2007-08-10 13:34  会东  阅读(10667)  评论(0编辑  收藏  举报