其他分享
首页 > 其他分享> > SAP选择屏幕

SAP选择屏幕

作者:互联网

注意:PBO->PAI->PBO 
PBO对控件进行设置,PAI对数据进行校验
FUNC CODE会触发PAI 就不需要在屏幕上回车触发了
1.单选
PARAMETERS P_ZCODE TYPE ZWXSTUDENT_01-ZCODE.
 
2.复选
SELECT-OPTIONS S_SEX FOR GS_STUDENT-SEX NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_ZNAME FOR GS_STUDENT-ZNAME.
 
3.常用语法
    默认值 DEFAULT aaa
    必输   OBLIGATORY
    隐藏   NO-DISPLAY
    显示长度 VISIBLE LENGTH aaa
    编辑组控制 MODIF ID modId
    按钮功能   USER-COMMAND fcode
    允许小写字母    LOWER CASE
    搜索棒读    MATCHCODE OBJECT search_help
    定义内存参数    MEMORY ID pid
SELECT-OPTIONS后缀
    默认值 DEFAULT aaa to bbb OPTION opt SIGN sgn
    多行输入控制 NO-EXTENSION
    输入范围控制 NO-INTERVALS
 
4.动态SQL语句
先新建一个内表和字符串
DATA WHERE_CONDS(100) OCCURS 0 WITH HEADER LINE.
DATA WHERE_COND(100) TYPE C.
动态拼接在WHERE_COND上在APPEND在WHERE_CONDS上
最后在SQL语句上where (WHERE_CONDS) 注意()是必需的
 
如果动态拼接SELECT-OPTIONS建议使用IN
注意BETWEEN A AND B  A和B需要用单引号引起来
 
NUMC前导零太多先转成字符串
使用SHIFT STR LEFT DELETING LEADING '0'. 即可去掉前导零
 
5.判断在表头的内表是否为空
  IF GT_TABLE[] IS NOT INITIAL 注意[]
 
6.多表查询
使用LEFT JOIN 连接表的时候条件写法是
表名1~字段1 = 表名2~字段2
 
还有就是查询出来的数据名字必须和内表完全统一
使用AS关键字给查出的字段重命名
 
7.PERFORM
PERFORM XXX USING a b c 进行传值
注意这里不加value就穿的是a的地址,加value是传值
FORM XXX USING aa bb value(cc).
ENDFORM.
 
CHANGING会返回值
 
 
 
 
2.T2
*&---------------------------------------------------------------------*
*& Report ZWXT_04
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZWXT_04.
 
TABLES ZWXSTUDENT_01.
 
DATA GENDER TYPE C.
 
TYPES: BEGIN OF GTY_TOTAL,
        ZCODE   TYPE ZWXSTUDENT_01-ZCODE,
        ZNAME   TYPE ZWXSTUDENT_01-ZNAME,
        ZSEX    TYPE ZWXSTUDENT_01-SEX,
        ZSCHOOL TYPE ZWXSCHOOL_01-ZSCHOOL,
        ZSNAME  TYPE ZWXSCHOOL_01-ZSNAME,
       END OF GTY_TOTAL.
 
DATA GT_TOTAL TYPE STANDARD TABLE OF GTY_TOTAL.
DATA GS_TOTAL TYPE GTY_TOTAL.
 
* 学校表
DATA GT_SCHOOL TYPE STANDARD TABLE OF ZSCHOOL_WX_STR_01.
DATA GS_SCHOOL TYPE ZSCHOOL_WX_STR_01.
 
* 学生表
DATA GT_STUDENT TYPE STANDARD TABLE OF ZWXSTUDENT_01.
DATA GS_STUDENT TYPE ZWXSTUDENT_01.
 
*&---------------------------------------------------------------------*
*&  选择屏幕 OBLIGATORY 必输项
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-T01.
PARAMETERS P_ZCODE TYPE ZWXSTUDENT_01-ZCODE OBLIGATORY VISIBLE LENGTH 10 DEFAULT '1001'.
SELECT-OPTIONS S_SCHOOL FOR GS_STUDENT-ZSCHOOL NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_ZNAME FOR GS_STUDENT-ZNAME ."DEFAULT '张三' TO '李四' SIGN I OPTION NB.
SELECTION-SCREEN END OF BLOCK BK1.
 
 
SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME TITLE TEXT-T02.
*&---------------------------------------------------------------------*
*&  RadioButton SELECTION-SCREEN BEGIN OF LINE指明放在一行
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF LINE.
   "放在一行的无法显示文本,需要使用SELECTION-SCREEN COMMENT (10) TEXT-T03来显示文本
   PARAMETERS R_MALE   RADIOBUTTON GROUP GP_1.
   SELECTION-SCREEN COMMENT (10) TEXT-T03 FOR FIELD R_MALE.
   "两边间隔
   SELECTION-SCREEN POSITION 30.
   PARAMETERS R_FEMALE RADIOBUTTON GROUP GP_1 DEFAULT 'X'.
   SELECTION-SCREEN COMMENT (10) TEXT-T04 FOR FIELD R_FEMALE.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BK2.
*&---------------------------------------------------------------------*
*&  CheckBox
*&---------------------------------------------------------------------*
 
SELECTION-SCREEN BEGIN OF BLOCK BK3 WITH FRAME TITLE TEXT-T09.
  SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS C_FOOD01  AS CHECKBOX.
    SELECTION-SCREEN COMMENT (10) TEXT-T05 FOR FIELD C_FOOD01.
    PARAMETERS C_FOOD02  AS CHECKBOX.
    SELECTION-SCREEN COMMENT (10) TEXT-T06 FOR FIELD C_FOOD02.
    PARAMETERS C_FOOD03  AS CHECKBOX.
    SELECTION-SCREEN COMMENT (10) TEXT-T07 FOR FIELD C_FOOD03.
    PARAMETERS C_FOOD04  AS CHECKBOX.
    SELECTION-SCREEN COMMENT (10) TEXT-T08 FOR FIELD C_FOOD04.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BK3.
 
*&---------------------------------------------------------------------*
*&  取数及输出
*&---------------------------------------------------------------------*
* SELECT语句 多条取数 -> INTO TABLE
* SIGN OPTION LOW HIGH
* 如果INTO TABLE则SELECT查出的字段需要和INTO的内表结构一致
* 如果只需要个别字段使用INTO CORRESPONDING FIELDS OF TABLE即可
* 判断选的男还是女
IF R_MALE = 'X'.
  GENDER = 'F'.
ELSE.
  GENDER = 'M'.
ENDIF.
SELECT ZCODE ZNAME SEX ZSCHOOL FROM ZWXSTUDENT_01
         INTO CORRESPONDING FIELDS OF TABLE GT_STUDENT
         WHERE ZCODE EQ P_ZCODE
         AND  SEX EQ GENDER
         AND  ZSCHOOL IN S_SCHOOL
         AND  ZNAME IN S_ZNAME.
 
LOOP AT GT_STUDENT INTO GS_STUDENT.
  WRITE: / GS_STUDENT-ZCODE NO-ZERO,GS_STUDENT-ZNAME,GS_STUDENT-SEX,GS_STUDENT-ZSCHOOL.
ENDLOOP.
WRITE: / '输出成功'.
3.T3
*&---------------------------------------------------------------------*
*& Report ZWXT_05
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZWXT_05 MESSAGE-ID WX NO STANDARD PAGE HEADING.
 
*&---------------------------------------------------------------------*
*&  TOP
*&---------------------------------------------------------------------*
INCLUDE ZWXT_05_TOP.
INCLUDE ZWXT_05_FORM.
 
* 初始化
INITIALIZATION.
  PERFORM INIT_SCREEN.
 
* PAI
AT SELECTION-SCREEN.
  PERFORM PAI_SCREEN.
 
* PBO
AT SELECTION-SCREEN OUTPUT.
  PERFORM PBO_SCREEN.
 
* START-OF-SELECTION
START-OF-SELECTION.
  PERFORM START_SCREEN.
 
* END-OF-SELECTION
END-OF-SELECTION.
  PERFORM END_SCREEN.
 
****************TOP**********************
****************TOP**********************
****************TOP**********************
****************TOP**********************
****************TOP**********************
*&---------------------------------------------------------------------*
*& 包含               ZWXT_05_TOP
*&---------------------------------------------------------------------*
 
*&---------------------------------------------------------------------*
*& 数据定义
*&---------------------------------------------------------------------*
TABLES: ZWXSTUDENT_01,
        ZWXSCHOOL_01,
        ZWX_COURSE,
        ZWX_SCORE.
* 动态拼接SQL
DATA WHERE_CONDS(100) OCCURS 0 WITH HEADER LINE.
DATA WHERE_COND(100) TYPE C.
* 定义数据转换中间变量
DATA DEC_TO_C_LOW(6) TYPE C.
DATA DEC_TO_C_HIGH(6) TYPE C.
DATA NUMC_TO_C(15) TYPE C.
* 学生内表和结构
DATA GT_STUDENT TYPE STANDARD TABLE OF ZWXSTUDENT_01.
DATA GS_STUDENT TYPE ZWXSTUDENT_01.
* 学校内表和结构
DATA GT_SCHOOL TYPE STANDARD TABLE OF ZWXSCHOOL_01.
DATA GS_SCHOOL TYPE ZWXSCHOOL_01.
* 课程内表和结构
DATA GT_COURSE TYPE STANDARD TABLE OF ZWX_COURSE.
DATA GS_COURSE TYPE ZWX_COURSE.
* 分数内表和结构
DATA GT_SCORE TYPE STANDARD TABLE OF ZWX_SCORE.
DATA GS_SCORE TYPE ZWX_SCORE.
 
* 显示页面的总和
TYPES: BEGIN OF GTY_TOTAL,
        ZCODE   TYPE ZWXSTUDENT_01-ZCODE, "学生编号
        ZNAME   TYPE ZWXSTUDENT_01-ZNAME, "学生姓名
        ZSEX    TYPE ZWXSTUDENT_01-SEX,   "学生性别
        ZSNAME  TYPE ZWXSCHOOL_01-ZSNAME, "学校名称
        ZCNAME  TYPE ZWX_COURSE-ZCNAME,   "课程名字
        ZSCORE  TYPE ZWX_SCORE-ZSCORE,    "课程分数
       END OF GTY_TOTAL.
* 显示数据内表和结构
DATA GT_TOTAL TYPE STANDARD TABLE OF GTY_TOTAL.
DATA GS_TOTAL TYPE GTY_TOTAL.
 
*&---------------------------------------------------------------------*
*& SELECTION-SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-T03.
  SELECTION-SCREEN BEGIN OF LINE.
      SELECTION-SCREEN COMMENT (10) TEXT-T06 FOR FIELD P_ZCODE.
      SELECTION-SCREEN POSITION 33.
      PARAMETERS P_ZCODE(10) TYPE C.  " 学生编号选择
      SELECTION-SCREEN POSITION 45.
      SELECTION-SCREEN COMMENT (10) GV_MSG.
  SELECTION-SCREEN END OF LINE.
  SELECT-OPTIONS S_ZNAME FOR GS_TOTAL-ZNAME. "学生姓名选择
 
SELECTION-SCREEN END OF BLOCK BK1.
 
* 课程名
SELECTION-SCREEN BEGIN OF BLOCK BK3 WITH FRAME TITLE TEXT-T05.
  SELECT-OPTIONS S_ZCNAME FOR GS_COURSE-ZCNAME NO INTERVALS NO-EXTENSION.
  SELECT-OPTIONS S_ZSCORE FOR GS_SCORE-ZSCORE.
SELECTION-SCREEN END OF BLOCK BK3.
 
* 是否根据性别选择
PARAMETERS P_ISSEX AS CHECKBOX USER-COMMAND HIDE.
SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME TITLE TEXT-T04.
  SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS P_MALE   RADIOBUTTON GROUP GP1 MODIF ID MD1.
    SELECTION-SCREEN COMMENT (2) TEXT-T01 FOR FIELD P_MALE.
    SELECTION-SCREEN POSITION 10.
    PARAMETERS P_FEMALE RADIOBUTTON GROUP GP1 MODIF ID MD1.
    SELECTION-SCREEN COMMENT (2) TEXT-T02 FOR FIELD P_FEMALE.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BK2.
 
 
************FORM*****************
************FORM*****************
************FORM*****************
************FORM*****************
************FORM*****************
*&---------------------------------------------------------------------*
*& 包含               ZWXT_05_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& FORM INIT-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM INIT_SCREEN .
  GV_MSG = '学号待验证'.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM PAI-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM PAI_SCREEN .
  IF P_ZCODE IS NOT INITIAL.
    SELECT SINGLE ZCODE
           FROM   ZWXSTUDENT_01
           INTO   GS_STUDENT
           WHERE  ZCODE = P_ZCODE.
    IF SY-SUBRC = 0.
      GV_MSG = '学生存在!'.
    ELSE.
      GV_MSG = '学生不存在'.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM PBO-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM PBO_SCREEN .
  IF P_ISSEX <> 'X'.
    LOOP AT SCREEN.
      IF SCREEN-GROUP1 = 'MD1'.
        SCREEN-INVISIBLE = 1.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM START-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM START_SCREEN .
" 判断是否选择了男或女
IF P_ISSEX = 'X'.
  IF P_MALE = 'X'.
    CONCATENATE WHERE_COND ' ZWXSTUDENT_01~SEX = ''M'' ' INTO WHERE_COND .
  ELSE.
    CONCATENATE WHERE_COND ' ZWXSTUDENT_01~SEX = ''F'' ' INTO WHERE_COND.
  ENDIF.
  APPEND WHERE_COND TO WHERE_CONDS.
  CLEAR WHERE_COND.
ENDIF.
 
" 判断是否输入学生编号
IF P_ZCODE IS NOT INITIAL.
  IF WHERE_CONDS[] IS NOT INITIAL.
    CONCATENATE WHERE_COND ' AND ZWXSTUDENT_01~ZCODE = ''' P_ZCODE '''' INTO WHERE_COND.
  ELSE.
    CONCATENATE WHERE_COND ' ZWXSTUDENT_01~ZCODE = '' ' P_ZCODE ' '' ' INTO WHERE_COND.
  ENDIF.
  APPEND WHERE_COND TO WHERE_CONDS.
  CLEAR WHERE_COND.
ENDIF.
 
" 判断是否输入学生姓名 取low 和 high 其余不暂时不加
" LOW
IF S_ZNAME-LOW IS NOT INITIAL.
  IF WHERE_CONDS[] IS NOT INITIAL.
    CONCATENATE WHERE_COND ' AND ZWXSTUDENT_01~ZNAME IN (''' S_ZNAME-LOW INTO WHERE_COND.
  ELSE.
    CONCATENATE WHERE_COND ' ZWXSTUDENT_01~ZNAME IN (''' S_ZNAME-LOW INTO WHERE_COND.
  ENDIF.
  " 判断HIGH是不是也输入了
  IF S_ZNAME-HIGH IS NOT INITIAL.
    CONCATENATE WHERE_COND ''',''' S_ZNAME-HIGH ''')' INTO WHERE_COND.
  ELSE.
    CONCATENATE WHERE_COND ''')' INTO WHERE_COND.
  ENDIF.
  " 追加
  APPEND WHERE_COND TO WHERE_CONDS.
  CLEAR WHERE_CONDS.
" 如果low没输 输了high
ELSEIF S_ZNAME-HIGH IS NOT INITIAL.
  IF WHERE_CONDS[] IS NOT INITIAL.
    CONCATENATE WHERE_COND ' AND ZWXSTUDENT_01~ZNAME = ''' S_ZNAME-HIGH '''' INTO WHERE_COND.
  ELSE.
    CONCATENATE WHERE_COND ' ZWXSTUDENT_01~ZNAME = ''' S_ZNAME-HIGH '''' INTO WHERE_COND.
  ENDIF.
  " 追加
  APPEND WHERE_COND TO WHERE_CONDS.
  CLEAR WHERE_CONDS.
ENDIF.
 
 
" 判断是否输入了课程编号
IF S_ZCNAME-LOW IS NOT INITIAL.
  IF WHERE_CONDS[] IS NOT INITIAL.
    CONCATENATE WHERE_COND 'AND ZWX_COURSE~ZCNAME = ''' S_ZCNAME-LOW '''' INTO WHERE_COND.
  ELSE.
    CONCATENATE WHERE_COND 'ZWX_COURSE~ZCNAME = ''' S_ZCNAME-LOW '''' INTO WHERE_COND.
  ENDIF.
  APPEND WHERE_COND TO WHERE_CONDS.
  CLEAR WHERE_COND.
ENDIF.
 
" 判断在某个成绩范围内
IF S_ZSCORE-LOW IS NOT INITIAL.
  DEC_TO_C_LOW = S_ZSCORE-LOW.
  " 成绩顶峰不为空
  IF S_ZSCORE-HIGH IS NOT INITIAL.
    DEC_TO_C_HIGH = S_ZSCORE-HIGH.
    " 条件内表是否为空
    IF WHERE_CONDS[] IS NOT INITIAL.
      CONCATENATE WHERE_COND 'AND ZWX_SCORE~ZSCORE BETWEEN  '''  DEC_TO_C_LOW ''' AND  '''  DEC_TO_C_HIGH '''' INTO WHERE_COND.
    " 为空
    ELSE.
      CONCATENATE WHERE_COND 'ZWX_SCORE~ZSCORE BETWEEN  ''' DEC_TO_C_LOW ''' AND  ''' DEC_TO_C_HIGH '''' INTO WHERE_COND.
    ENDIF.
  " 否则只有最低值
  ELSE.
    IF WHERE_CONDS[] IS NOT INITIAL.
      CONCATENATE WHERE_COND 'AND ZWX_SCORE~ZSCORE GE  ''' DEC_TO_C_LOW '''' INTO WHERE_COND.
    " 为空
    ELSE.
      CONCATENATE WHERE_COND 'ZWX_SCORE~ZSCORE GE  ''' DEC_TO_C_LOW '''' INTO WHERE_COND.
    ENDIF.
  ENDIF.
  APPEND WHERE_COND TO WHERE_CONDS.
  CLEAR WHERE_COND.
" 没有最低值,判断是否要小于峰值
ELSE.
  IF S_ZSCORE-HIGH IS NOT INITIAL.
    DEC_TO_C_HIGH = S_ZSCORE-HIGH.
    IF WHERE_CONDS[] IS NOT INITIAL.
      CONCATENATE WHERE_COND 'AND ZWX_SCORE~ZSCORE LE ''' DEC_TO_C_HIGH '''' INTO WHERE_COND.
    " 为空
    ELSE.
      CONCATENATE WHERE_COND 'ZWX_SCORE~ZSCORE LE ''' DEC_TO_C_HIGH '''' INTO WHERE_COND.
    ENDIF.
    APPEND WHERE_COND TO WHERE_CONDS.
    CLEAR WHERE_COND.
  ENDIF.
ENDIF.
 
SELECT  Z1~ZCODE AS ZCODE,
        Z1~ZNAME AS ZNAME,
        Z1~SEX   AS ZSEX,
        Z2~ZSNAME AS ZSNAME,
        Z4~ZCNAME   AS ZCNAME,
        Z3~ZSCORE   AS ZSCORE
        INTO TABLE @GT_TOTAL
        FROM ZWXSTUDENT_01     AS Z1
        LEFT JOIN ZWXSCHOOL_01 AS Z2  ON Z1~ZSCHOOL = Z2~ZSCHOOL
        LEFT JOIN ZWX_SCORE    AS Z3  ON Z1~ZCODE   = Z3~ZCODE
        LEFT JOIN ZWX_COURSE   AS Z4  ON Z3~ZCID    = Z4~ZCID
        WHERE (WHERE_CONDS).
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM END_SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM END_SCREEN .
  IF GT_TOTAL[] IS INITIAL.
    MESSAGE S890 WITH '没有查到符合的数据' DISPLAY LIKE 'E'.
  ELSE.
    WRITE:/ SY-ULINE(81) .
    WRITE:/   SY-VLINE NO-GAP,(15) '学号' CENTERED NO-GAP,
              SY-VLINE NO-GAP,(12) '姓名' CENTERED NO-GAP,
              SY-VLINE NO-GAP,(5)  '性别' CENTERED NO-GAP,
              SY-VLINE NO-GAP,(12) '学校' CENTERED NO-GAP,
              SY-VLINE NO-GAP,(20) '课程' CENTERED NO-GAP,
              SY-VLINE NO-GAP,(10) '成绩' CENTERED NO-GAP,
              SY-VLINE.
    WRITE:/ SY-ULINE(81) .
    LOOP AT GT_TOTAL INTO GS_TOTAL.
      NUMC_TO_C = GS_TOTAL-ZCODE.
      SHIFT NUMC_TO_C LEFT DELETING LEADING '0'.
      IF GS_TOTAL-ZSEX = 'M'.
        GS_TOTAL-ZSEX = '男'.
      ELSE.
        GS_TOTAL-ZSEX = '女'.
      ENDIF.
      WRITE:/ SY-VLINE NO-GAP,(15) NUMC_TO_C       CENTERED NO-GAP,
              SY-VLINE NO-GAP,(12) GS_TOTAL-ZNAME  CENTERED NO-GAP,
              SY-VLINE NO-GAP,(5)  GS_TOTAL-ZSEX   CENTERED NO-GAP,
              SY-VLINE NO-GAP,(12) GS_TOTAL-ZSNAME CENTERED NO-GAP,
              SY-VLINE NO-GAP,(20) GS_TOTAL-ZCNAME CENTERED NO-GAP,
              SY-VLINE NO-GAP,(10) GS_TOTAL-ZSCORE CENTERED NO-GAP,
              SY-VLINE.
      WRITE:/ SY-ULINE(81) .
    ENDLOOP.
  ENDIF.
ENDFORM.
4.T4(操作内表来连接四个表)
*&---------------------------------------------------------------------*
*& Report ZWXT_06
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZWXT_06
              MESSAGE-ID WX
              "隐藏默认表头
              NO STANDARD PAGE HEADING
              LINE-COUNT 10.
 
*&---------------------------------------------------------------------*
*&  TOP
*&---------------------------------------------------------------------*
INCLUDE ZWXT_06_TOP.
INCLUDE ZWXT_06_FORM.
 
* 初始化
INITIALIZATION.
  PERFORM INIT_SCREEN.
 
* PAI
AT SELECTION-SCREEN.
  PERFORM PAI_SCREEN.
 
* PBO
AT SELECTION-SCREEN OUTPUT.
  PERFORM PBO_SCREEN.
 
* START-OF-SELECTION
START-OF-SELECTION.
  PERFORM START_SCREEN.
 
* END-OF-SELECTION
END-OF-SELECTION.
  PERFORM END_SCREEN.
 
* TOP-OF-PAGE
TOP-OF-PAGE.
  PERFORM TOP_PAGE.
 
TOP-OF-PAGE DURING LINE-SELECTION.
  CASE SY-UCOMM.
    WHEN 'SORTUP' OR 'SORTDOWN'.
      PERFORM TOP_PAGE.
    WHEN OTHERS.
      WRITE:/ '学校信息'.
  ENDCASE.
 
* LINE-SELECTION
AT LINE-SELECTION.
  PERFORM LINE_SELECTION.
 
* USER-COMMAND
AT USER-COMMAND.
  PERFORM USER_COMMAND.
 
* LOAD PROGRAM
*&---------------------------------------------------------------------*
*& 包含               ZWXT_06_TOP
*&---------------------------------------------------------------------*
 
*&---------------------------------------------------------------------*
*& 数据定义
*&---------------------------------------------------------------------*
TABLES: ZWXSTUDENT_01,
        ZWXSCHOOL_01,
        ZWX_COURSE,
        ZWX_SCORE.
* 定义学生ID内表
DATA: LT_ZCODE TYPE RANGE OF ZWXSTUDENT_01-ZCODE,
      LS_ZCODE LIKE LINE OF LT_ZCODE,
      LT_ZSEX  TYPE RANGE OF ZWXSTUDENT_01-SEX,
      LS_ZSEX  LIKE LINE OF LT_ZSEX.
* 定义数据转换中间变量
DATA DEC_TO_C_LOW(6) TYPE C.
DATA DEC_TO_C_HIGH(6) TYPE C.
DATA NUMC_TO_C(15) TYPE C.
* 学生内表和结构
DATA GT_STUDENT TYPE STANDARD TABLE OF ZWXSTUDENT_01.
DATA GS_STUDENT TYPE ZWXSTUDENT_01.
* 学校内表和结构
DATA GT_SCHOOL TYPE STANDARD TABLE OF ZWXSCHOOL_01.
DATA GS_SCHOOL TYPE ZWXSCHOOL_01.
* 课程内表和结构
DATA GT_COURSE TYPE STANDARD TABLE OF ZWX_COURSE.
DATA GS_COURSE TYPE ZWX_COURSE.
* 分数内表和结构
DATA GT_SCORE TYPE STANDARD TABLE OF ZWX_SCORE.
DATA GS_SCORE TYPE ZWX_SCORE.
 
* 显示页面的总和
TYPES: BEGIN OF GTY_TOTAL,
        ZCODE   TYPE ZWXSTUDENT_01-ZCODE, "学生编号
        ZNAME   TYPE ZWXSTUDENT_01-ZNAME, "学生姓名
        SEX    TYPE ZWXSTUDENT_01-SEX,   "学生性别
        ZSNAME  TYPE ZWXSCHOOL_01-ZSNAME, "学校名称
        ZCNAME  TYPE ZWX_COURSE-ZCNAME,   "课程名字
        ZSCORE  TYPE ZWX_SCORE-ZSCORE,    "课程分数
       END OF GTY_TOTAL.
* 显示数据内表和结构
DATA GT_TOTAL TYPE STANDARD TABLE OF GTY_TOTAL.
DATA GS_TOTAL TYPE GTY_TOTAL.
 
*&---------------------------------------------------------------------*
*& SELECTION-SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-T03.
 
  SELECTION-SCREEN BEGIN OF LINE.
      SELECTION-SCREEN COMMENT (10) TEXT-T06 FOR FIELD P_ZCODE.
      SELECTION-SCREEN POSITION 33.
      PARAMETERS P_ZCODE TYPE ZWXSTUDENT_01-ZCODE.
      "SELECT-OPTIONS S_ZCODE FOR ZWXSTUDENT_01-ZCODE NO INTERVALS NO-EXTENSION.
      SELECTION-SCREEN COMMENT (10) GV_MSG.
  SELECTION-SCREEN END OF LINE.
  SELECT-OPTIONS S_ZNAME FOR GS_TOTAL-ZNAME. "学生姓名选择
SELECTION-SCREEN END OF BLOCK BK1.
 
* 课程名
SELECTION-SCREEN BEGIN OF BLOCK BK3 WITH FRAME TITLE TEXT-T05.
  SELECT-OPTIONS S_ZCNAME FOR GS_COURSE-ZCNAME NO INTERVALS NO-EXTENSION.
  SELECT-OPTIONS S_ZSCORE FOR GS_SCORE-ZSCORE.
SELECTION-SCREEN END OF BLOCK BK3.
 
* 是否根据性别选择
PARAMETERS P_ISSEX AS CHECKBOX USER-COMMAND HIDE.
SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME TITLE TEXT-T04.
  SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS P_MALE   RADIOBUTTON GROUP GP1 MODIF ID MD1.
    SELECTION-SCREEN COMMENT (2) TEXT-T01 FOR FIELD P_MALE.
    SELECTION-SCREEN POSITION 10.
    PARAMETERS P_FEMALE RADIOBUTTON GROUP GP1 MODIF ID MD1.
    SELECTION-SCREEN COMMENT (2) TEXT-T02 FOR FIELD P_FEMALE.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BK2.
*&---------------------------------------------------------------------*
*& 包含               ZWXT_06_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& FORM INIT-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM init_screen .
  gv_msg = '学号待验证'.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM PAI-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM pai_screen .
  IF p_zcode IS NOT INITIAL.
    SELECT SINGLE zcode
           FROM   zwxstudent_01
           INTO   gs_student
           WHERE  zcode = p_zcode.
    IF sy-subrc = 0.
      gv_msg = '学生存在!'.
    ELSE.
      gv_msg = '学生不存在'.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM PBO-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM pbo_screen .
  IF p_issex <> 'X'.
    LOOP AT SCREEN.
      IF screen-group1 = 'MD1'.
        screen-invisible = 1.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM START-SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM start_screen .
  IF p_zcode IS NOT INITIAL.
    ls_zcode-sign = 'I'.
    ls_zcode-low  = p_zcode.
    ls_zcode-option = 'EQ'.
    ls_zcode-high = ''.
    APPEND ls_zcode TO lt_zcode.
  ENDIF.
 
  IF p_issex IS NOT INITIAL.
    IF p_male = 'X'.
      ls_zsex-sign = 'I'.
      ls_zsex-option = 'EQ'.
      ls_zsex-low  = 'M'.
      ls_zsex-high = ''.
    ELSE.
      ls_zsex-sign = 'I'.
      ls_zsex-option = 'EQ'.
      ls_zsex-low  = 'F'.
      ls_zsex-high = ''.
    ENDIF.
    APPEND ls_zsex TO lt_zsex.
  ENDIF.
 
  "查询符合的学生
  SELECT
    zcode
    zname
    sex
    zschool
    FROM zwxstudent_01
    INTO CORRESPONDING FIELDS OF TABLE gt_student
    WHERE zcode IN lt_zcode
    AND   zname IN s_zname
    AND   sex   IN lt_zsex.
 
  "查询对应的学校
  IF gt_student IS NOT INITIAL.
    SELECT
    zschool
    zsname
    FROM  zwxschool_01
    INTO CORRESPONDING FIELDS OF TABLE gt_school
    FOR ALL ENTRIES IN gt_student
    WHERE zschool = gt_student-zschool.
  ENDIF.
 
  "查询对应的成绩
  IF gt_student IS NOT INITIAL.
    SELECT
      zcode
      zcid
      zscore
      FROM zwx_score
      INTO CORRESPONDING FIELDS OF TABLE gt_score
      FOR ALL ENTRIES IN gt_student
      WHERE zcode = gt_student-zcode
      AND   zscore IN s_zscore.
  ENDIF.
 
  "查询对应课程名
  IF gt_score IS NOT INITIAL.
    SELECT
      zcid
      zcname
      FROM zwx_course
      INTO CORRESPONDING FIELDS OF TABLE gt_course
      FOR ALL ENTRIES IN gt_score
      WHERE zcid = gt_score-zcid
      AND   zcname IN s_zcname.
      ENDIF.
 
  "将四个内表整合内容到主表里
  LOOP AT gt_student INTO gs_student.
    MOVE-CORRESPONDING gs_student TO gs_total.
    READ TABLE gt_school INTO gs_school WITH KEY zschool = gs_student-zschool.
    IF sy-subrc = 0.
      MOVE gs_school-zsname TO gs_total-zsname.
    ENDIF.
    LOOP AT gt_score INTO gs_score.
      IF gs_student-zcode = gs_score-zcode.
        READ TABLE gt_score INTO gs_score INDEX sy-tabix.
        IF sy-subrc = 0.
          MOVE gs_score-zscore TO gs_total-zscore.
          READ TABLE gt_course INTO gs_course WITH KEY zcid = gs_score-zcid.
          IF sy-subrc = 0.
            MOVE gs_course-zcname TO gs_total-zcname.
            APPEND gs_total TO gt_total.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM END_SCREEN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM end_screen .
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'TITLE'.
  IF gt_total[] IS INITIAL.
    MESSAGE s890 WITH '没有查到符合的数据' DISPLAY LIKE 'E'.
  ELSE.
*    WRITE:/ SY-ULINE(81) .
*    WRITE:/   SY-VLINE NO-GAP,(15) '学号' CENTERED NO-GAP,
*              SY-VLINE NO-GAP,(12) '姓名' CENTERED NO-GAP,
*              SY-VLINE NO-GAP,(5)  '性别' CENTERED NO-GAP,
*              SY-VLINE NO-GAP,(12) '学校' CENTERED NO-GAP,
*              SY-VLINE NO-GAP,(20) '课程' CENTERED NO-GAP,
*              SY-VLINE NO-GAP,(10) '成绩' CENTERED NO-GAP,
*              SY-VLINE.
*    WRITE:/ SY-ULINE(81) .
    LOOP AT gt_total INTO gs_total.
      numc_to_c = gs_total-zcode.
      SHIFT numc_to_c LEFT DELETING LEADING '0'.
      IF gs_total-sex = 'M'.
        gs_total-sex = '男'.
      ELSE.
        gs_total-sex = '女'.
      ENDIF.
      WRITE:/ sy-vline NO-GAP,(15) numc_to_c       CENTERED NO-GAP,
              sy-vline NO-GAP,(12) gs_total-zname  CENTERED NO-GAP,
              sy-vline NO-GAP,(5)  gs_total-sex   CENTERED NO-GAP,
              sy-vline NO-GAP,(12) gs_total-zsname CENTERED NO-GAP,
              sy-vline NO-GAP,(20) gs_total-zcname CENTERED NO-GAP,
              sy-vline NO-GAP,(10) gs_total-zscore CENTERED NO-GAP,
              sy-vline.
      WRITE:/ sy-uline(81) .
    ENDLOOP.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form TOP_PAGE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM top_page .
    FORMAT COLOR 3 ON.
    WRITE:/(81) '学生信息表' CENTERED.
    FORMAT COLOR 3 OFF.
    WRITE:/ sy-uline(81).
    FORMAT COLOR 6 INVERSE ON.
    WRITE:/   sy-vline NO-GAP,(15) '学号' CENTERED NO-GAP,
              sy-vline NO-GAP,(12) '姓名' CENTERED NO-GAP,
              sy-vline NO-GAP,(5)  '性别' CENTERED NO-GAP,
              sy-vline NO-GAP,(12) '学校' CENTERED NO-GAP,
              sy-vline NO-GAP,(20) '课程' CENTERED NO-GAP,
              sy-vline NO-GAP,(10) '成绩' CENTERED NO-GAP,
              sy-vline.
    FORMAT COLOR 6 INVERSE OFF.
    WRITE:/ sy-uline(81) .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form LINE_SELECTION
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM line_selection .
* 定义选择行数据FIELD和VALUE
  DATA: lv_field TYPE c LENGTH 30,
        lv_value TYPE c LENGTH 30.
  GET CURSOR FIELD lv_field VALUE lv_value.
  CHECK lv_field = 'GS_TOTAL-ZSNAME'.
  CONDENSE lv_value NO-GAPS.
  CLEAR gs_school.
  SELECT
      SINGLE
      zschool
      zsname
      zadd
      FROM zwxschool_01
      INTO CORRESPONDING FIELDS OF gs_school
      WHERE zsname = lv_value.
  IF sy-subrc = 0.
    WRITE:/ '学校编号:',gs_school-zschool,
          / '学校名称:',gs_school-zsname,
          / '学校地址:',gs_school-zadd.
  ELSE.
    MESSAGE i890 WITH '没有该学校的详细信息'.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM user_command .
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'SORTUP'.
      sy-lsind = sy-lsind - 1.
      PERFORM sort_up.
    WHEN 'SORTDOWN'.
      sy-lsind = sy-lsind - 1.
      PERFORM sort_down.
    WHEN OTHERS.
      MESSAGE s890 WITH '未知的指令'.
  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SORT_UP
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM sort_up .
  PERFORM sort_list USING 'UP'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SORT_DOWN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM sort_down .
  PERFORM sort_list USING 'DOWN'.
ENDFORM.
 
FORM sort_list USING p_flag.
  " 定义选择行数据field和value
  DATA: lv_field TYPE c LENGTH 30,
        lv_value TYPE c LENGTH 30.
  GET CURSOR FIELD lv_field. "GS_TOTAL-ZCNAME
  IF lv_field = 'NUMC_TO_C'.
    lv_field = 'ZCODE'.
  ELSE.
    lv_field = lv_field+9(*).
  ENDIF.
  IF p_flag = 'UP'.
    SORT gt_total BY (lv_field). "()代表取值
  ELSEIF p_flag = 'DOWN'.
    SORT gt_total BY (lv_field) DESCENDING. "()代表取值
  ENDIF.
  PERFORM end_screen.
ENDFORM
 

标签:SELECTION,&-----------------------------------------------------------------
来源: https://blog.csdn.net/weixin_42921800/article/details/120473052