user command与 at user-command没有半点关系 除了长得有点像
If the user selects the pushbutton on the selection screen, the runtime environment triggers the event AT SELECTION-SCREEN and the function code fcode is transferred to the ucomm component in the interface work area sscrfields.
他触发的是 AT SELECTION-SCREEN这个事件
AT USER-COMMAND.
Effect
This statement defines an event block whose event is triggered by the ABAP runtime environment if, during the display of a screen list, a function with a self-defined function
code was chosen.
这个是需要一个自定义的function code来触发的
也就是 SET PF-STATUS 'MYLIST' guistatus里面的function code
把AT USER-COMMAND.换成AT SELECTION-SCREEN .
AT SELECTION-SCREEN .是选择屏幕的PAI事件。
把AT USER-COMMAND
修改为 AT SELECTION-SCREEN. 就可以了
AT SELECTION-SCREEN.(说明下面的代码是PAI,可以响应屏幕事件)
你还可以在最后添加初始化,让按钮显示提示文本
INITIALIZATION.
pubu1 = 'ABCD'.
pubu2 = 'ABCE'.
SELECTION-SCREEN PUSHBUTTON /1(20) PUBU1 USER-COMMAND ABCD.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN PUSHBUTTON /1(20) PUBU2 USER-COMMAND ABCE.
AT SELECTION-SCREEN. "选择屏幕的PAI事件。
CASE sy-ucomm.
WHEN 'ABCD'.
MESSAGE I005(MsgClass) WITH '111'.
WHEN 'ABCE'.
MESSAGE I005(MsgClass) WITH '222'.
WHEN OTHERS.
MESSAGE I005(MsgClass) WITH '333'.
ENDCASE.
我帮你改好了,别忘给分呀。
REPORT Z_STUDY_CASE_032 .
TABLES SSCRFIELDS.
SELECTION-SCREEN PUSHBUTTON /1(20) PUBU1 USER-COMMAND ABCD.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN PUSHBUTTON /1(20) PUBU2 USER-COMMAND ABCE.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'ABCD'.
WRITE '111'.
WHEN 'ABCE'.
MESSAGE I005(MsgClass) WITH '222'.
WHEN OTHERS.
MESSAGE I005(MsgClass) WITH '333'.
ENDCASE.
AT SELECTION-SCREEN.是处理选择屏幕PAI事件的。
而 AT USER-COMMAND是处理GUI的,即你手工创建一个按钮,当你点击那个按钮时就会触发AT USER-COMMAND事件。