• 2022.8.18-8.19 代码记录


    &---------------------------------------------------------------------
    *& Report ZALVTEST031
    &---------------------------------------------------------------------
    *&
    &---------------------------------------------------------------------
    report zalvtest031
    no standard page heading
    line-count 90(03)
    line-size 120
    message-id ztestmsg.

    ---------

    • INCLUDE
      ---------
      include: ztest0n, "常量定义
      ztest0f. "Form定义

    ------------------

    • TABLES:
      ------------------
      tables: zttest_t.

    --------------
    *DATA
    --------------
    data: begin of flg,
    cls_frst type c value cns-off, "班级起始
    end of flg.

    --------------

    • CLASS-DATA
      --------------
    • 接口定义
      --------------
      interfaces test.
      methods: get_name,get_detail,get_all.
      events not_found exporting value(id) type any.
      endinterface.

    --------------

    • CLASS CLS_TEACHER DEFINTION
      --------------
    • 教师信息表
      --------------
      CLASS CLS_TEACHER DEFINITION.
      PUBLIC SECTION.
      DATA ZTNUMBER TYPE ZMTNUMBER_T-ZTNUMBER. "教师番号
      *接口使用
      INTERFACE: TEST.
      ALIASES : GET_TEACHER_NAME FOR TEST~GET_NAME,
      GET_TEACHER_DETAIL FOR TEST~GET_DETAIL,
      GET_TEACHER_ALL FOR TEST~GET_ALL,
      NO_TEACHER_FOUND FOR TEST~NOT_FOUND.

    *事件触发方法
    METHODS: ERROR_HANDLE FOR EVENT NO_TEACHER_FOUND
    OF CLS_TEACHER IMPORTING ID.

    PROTECTED SECTION.
    DATA: ZTNAME TYPE ZMTNUMBER_T-ZTNAME, "姓名
    ZTSEX TYPE ZMTNUMBER_T-ZTSEX, "性别
    ZZMOBILE TYPE ZMTNUMBER_T-ZZMOBILE. "联系电话
    PRIVATE SECTION.
    DATA: TEACHER TYPE ZMTNUMBER_T.
    ENDCLASS.

    --------------

    • CLASS CLS_TEACHER IMOLEMENTATION
      --------------

    • 教师信息表
      --------------
      CLASS CLS_TEACHER IMPLEMENTATION.

    • 取得教师姓名
      METHOD GET_TEACHER_NAME.
      SELECT SINGLE ZTNAME "姓名
      FROM ZMTUNMBER_T "教师信息表
      INTO ME->ZTNAME "姓名
      WHERE ZTNUMBER = ME->ZTNMBER.
      IF SY-SUBRC <> 0.
      RAISE EVENT NO_TEACHER_FOUND EXPORTING ID = ME->ZTNUMBER.
      ENDIF.
      ENDMETHOD.

    • 取得教师详细
      METHOD GET_TEACHER_DETAIL.
      SELECT SINGLE ZTNAME ZTSEX ZZMOBILE
      FROM ZMTUNMBER_T
      INTO (ME->ZTNAME, ME->ZTSEX, ME->ZZMOBILE)
      WHERE ZTNUMBER = ME->ZTNMBER.
      IF SY-SUBRC <> 0.
      RAISE EVENT NO_TEACHER_FOUND EXPORTING ID = ME->ZTNUMBER.
      ENDIF.
      ENDMETHOD.

    *取得教师信息
    METHOD GET_TEACHER_ALL.
    SELECT SINGLE *
    FROM ZMTUNMBER_T
    INTO ME->TEACHER
    WHERE ZTNUMBER = ME->ZTNMBER.
    IF SY-SUBRC <> 0.
    RAISE EVENT NO_TEACHER_FOUND EXPORTING ID = ME->ZTNUMBER.
    ENDIF.
    ENDMETHOD.

    *输出错误信息
    METHOD ERROR_HANDLE.
    MESSAGE E001 WITH ID.
    ENDMETHOD.

    ENDCLASS.
    ----------------------------

    • CLASS CLS_TEST DEFINITION
      ----------------------------
    • 学生信息表
      ----------------------------
      CLASS CLS_STUDENT DEFINITION CREATE PROTECTED FRIENDS TEST.
      PUBLIC SECTION.
      DATA ZZNUMBER TYPE ZMNUMBER_T-ZZNUMBER. "学生编号
    • 构造函数,初始化该类的实例
      METHODS: CONSTRUCTOR IMPORTING SID TYPE ZMNUMBER_T-ZZNUMBER.

    *接口使用
    INTERFACES: TEST.
    ALIASES : GET_STUDENT_NAME FOR TEST~GET_NAME,
    GET_STUDENT_DETAIL FOR TEST~GET_DETAIL,
    GET_STUDENT_ALL FOR TEST~GET_ALL,
    METHODS: ERROR_HANDLE FOR EVENT NO_STUDENT_FOUND OF CLS_STUDENT IMPORTING ID.

    PROTECTED SECTION.
    DATA: ZZNAME TYPE ZMUNMBER_T-ZZNAME, "姓名
    ZZSEX TYPE ZMNUMBER_T-ZZSEX, "性别
    ZZFNAME TYPE ZMNUMBER_T-ZZFNAME, "父亲
    ZZMNAME TYPE ZMNUMBER_T-ZZMNAME, "母亲
    ZZMOBILE TYPE ZMNUMBER_T-ZZMOBILE, "联系电话
    ZZADDR TYPE ZMNUMBER_T-ZZADDR. "家庭地址
    PRIVATE SECTION.

    DATA: STUDENT TYPE  ZMNUMBER_T.
    
    • 1

    ENDCLASS.

    ----------------------------

    • CLASS CLS_TEST IMPLEMENTATION
      ----------------------------

    • 学生信息表
      ----------------------------
      class cls_student implementation.
      *构造函数声明
      method constructor.
      me-> zznumber = sid.
      set handler error_handle for all instances.
      endmethod.
      *取得学生姓名
      method get_student_name.
      select single zzname
      from zmnumber_t
      into me->zzname
      where zznumber = me->zznumber.
      if sy-subrc <> 0.
      raise event no_student_found exporting id = me->zznumber.
      endif.

      endmethod.

    • 取得学生详细
      method get_student_detail.
      select single zzname zzsex zzfname zzmname zzmobile zzaddr
      from zmnumber_t
      into (me->zzname,me->zzsex,me->zzfname,me->zzmname,me->zzmobile,me->zzaddr)
      where zznumber = me->zznumber.
      if sy-subrc <> 0.
      raise event no_student_found exporting id = me->zznumber.
      endif.
      endmethod.

    • 取得学生信息
      method get_student_all.
      select single *
      from zmnumber_t
      into me->student
      where zznumber = me->zznumber.
      if sy-subrc <> 0.
      raise event no_student_found exporting id = me->zznumber.
      endif.
      endmethod.

        method error_handle.
          message e001 with id.
        endmethod.
      
      • 1
      • 2
      • 3

    ----------------------------

    • CLASS CLS_CLASS DEFINITION
      ----------------------------

    • 班主任表
      ----------------------------
      class cls_class definition inheriting from cls_teacher.
      public section.
      data: zzclass type zcclass_t-zzclass, "班级
      zzclsname type string, "班级名称
      zzteanom type zcclass_t-zzteanom, "班主任
      zzteanos type zcclass_tzzteanos, "副班主任
      ztnamem type zmtnumber_t-ztname, "班主任名
      ztnames type zmtnumber_t-ztname. "副班主任名

    • 取得班级名称
      methods: get_class_domain.
      events: no_class_found
      exporting value(clsid) type zcclass_t-zzclass.

    *声明友类
    data teacher type ref to cls_teacher.

    *取得班级详细信息
    methods: get_class.

    *取得班级错误处理
    methods: nodata_handle for event no_class_found of cls_class importing clsid.

    endclass.

    class cls_class implementation.

    • 班级信息取得
      method get_class.

      select single zzteanom zzteanos
      from zcclass_t
      into (me->zzteanom, me->zzteanos)
      where zzclass = me->zzclass. "班级
      if sy-subrc <> 0.
      raise event no_class_found exporting clisd = me->zzlcass.
      else.
      set handler error_handle for all instances.
      me->ztnumber = zzteanom.
      call method me->get_teacher_name.
      me->ztnamem = me->ztname.
      call method me->get_teacher_name.
      me->ztnames = me->ztname.
      endif.
      endmethod.

    • 取得班级名称
      method get_class_domain.

      select single dd07t~ddtext   " 域固定值文本
        from dd07t  inner join  dd07l  "内结合
        on dd07t~domname = dd07l~domname    "结合条件
        and dd07t~valpos = dd07l~valpos
        where dd07l~domname = 'ZZCLASS_D'   "域名相等
        and dd07l~domvalue_l = me->zzlcass.   "域固定值相等
      
        if sy-subrc <> 0.
          raise event no_class_found exporting clsid = me->zzclass.
        endif.
      endmethod.
      
      
      method nodata_handle.
        message e001 with clsid.
      endmethod.
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16

    endclass.

    ----------------------------

    • CLASS CLS_TEST DEFINITION
      ----------------------------

    • 成绩表
      ----------------------------
      CLASS CLS_TEST DEFINITION INHERITING FROM CLS_CLASS.
      PUBLIC SECTION.

      DATA: ZZYEAR TYPE ZZTEST_S-ZZYEAR, "学年
      ZZSTDNOF TYPE ZZTEST_S-ZZSTDNO, "学号From
      ZZSTDNOT TYPE ZZTEST_S-ZZSTDNO, "学号To
      TEST TYPE TABLE OF ZZTEST_S, "成绩表
      H_TEST TYPE ZZTEST_S. "成绩表

    EVENTS: NO_TEST_DATA
    EXPORTING VALUE(CLASS) TYPE ZCCLASS_T-ZZCLASS
    VALUE(YEAR) TYPE ZTTEST_T-ZZYEAR.
    METHODS: GET_TEST IMPORTING CLASS TYPE ZCCLASS_T-ZZCLASS
    YEAR TYPE ZTTEST_T-ZZYEAR.
    METHODS: NOTEST_HANDLE FOR EVENT NO_TEST_DATA OF CLS_TEST IMPORTING CLASS YEAR.

    ENDCLASS.

    ----------------------------

    • CLASS CLS_TEST IMPLEMENTATION
      ----------------------------
    • 成绩表
      ----------------------------

    class cls_test implementation.

    • 成绩表数据抽取
      method get_test.
      select zzclass "班级
      zzyear "学年
      zzstdno "学号
      zztenkok "语文
      zztensan "数学
      zztenrik "自然
      zztensha "思品
      from zttest_t "成绩表
      into corresponding fields of table test "成绩内部表
      where zzclass = class "班级
      and zzyear = year. "学年

      if sy-subrc <> 0.
        raise event no_test_data
          exporting class = class year = year.
      else.
        data student type ref to cls_student.
        loop at test into h_test.
          create object student
            exporting
              sid = h_test-zzstdno.
      
          call method student->get_student_name.
          h_test-zzname = student->zzname.
          modify test from h_test.
        endloop.
      endif.
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15

      endmethod.

    endclass.

    *成绩表对象声明
    data test type ref to cls_test.

    parameters: p_class type zttest_t-zzclass obligatory. "班级

    parameters p_year type zttest_t-zzyear obligatory. "学年

    *-----------------

    • SELECT-OPTIONS
      *-----------------

    select-options s_stdno for zttest_t-zzstdno "学号
    matchcode object zzmcsbid.

    *-----------------

    • INITIALIZATION
      *-----------------
      initialization.

    *数据初始化
    perform data_init
    using
    p_class "班级
    p_year. "学年
    create object test.
    set handler test->notest_handle for all instances.
    set handler test->nodata_handle for all instances.

    *-----------------

    • AT SELECTION SCREEN
      *-----------------
      at selection-screen.

    *选择画面项目-班级
    perform classoo_input_check.

    *选择画面项目检查-学年
    perform year_input_check using p_year text-001.

    ---------------------

    • START-OF-SELECTION
      ---------------------

    • 报表数据初始化
      perform report_data_init.

    • 报表数据选择
      perform report_data_select.
      *报表数据打印
      perform report_data_exe.

    *-----------------------

    • END-OF-SELECTION
      *-----------------------
      end-of-selection.

      perform report_edit_end.

    *--------------
    *TOP-OF-PAGE
    *--------------
    top-of-page.

    *报表页眉编辑
    perform report_header_edit.
    skip 1.
    write: /030 text-002. "成绩表
    write: /016 text-001, "学年
    020 cns-colon,
    022 test->h_test-zzyear.
    write: 030 text-003, "班主任
    036 cns-colon,
    038 test->ztnamem(6),
    038 test->ztnames(6).

    write: /015 sy-uline(052).
    write: /015 sy-vline,
    017 text-004, "班级
    021 sy-vline,
    025 text-005, "学生
    038 sy-vline,
    040 text-006, "语文
    045 sy-vline,
    047 text-007, "数学
    052 sy-vline,
    054 text-008, "自然
    059 sy-vline,
    061 text-009, "思品
    066 sy-vline.

    write: /015 sy-vline,
    015 sy-vline,
    021 sy-vline,
    038 sy-vline,
    045 sy-vline,
    052 sy-vline,
    059 sy-vline,
    066 sy-vline,
    015 sy-uline(052).
    endform.

    &------------------
    *& form EDIT_REPORT_DTL
    &------------------

    • 报表明细编辑
      
      • 1

    -------------------
    form edit_report_dtl.

    write: /015 sy-vline,
    021 sy-vline,
    023 test->h_test-zzname(14), "数学
    038 sy_vline,
    041(4) test->h_test-zztenkok, "语文
    045 sy-vline,
    048(4) test->h_test-zztensan, "数学
    052 sy-vline,
    055(4) test->h_test-zztenrik, "自然
    059 sy-vline,
    062(4) test->h_test-zztensha, "思品
    066 sy-vline.
    if flg-cls_frst = cns-on. "班级开始
    write: 017 test->h_test-zzclass+0(1),
    018 cns-plus,
    019 test->h_test-zzclass+1(1).
    endform.

    &------------------------
    *& FORM EDIT_REPORT_CLS
    &------------------------

    • 报表挂线
      
      • 1

    -------------------------
    form edit_report_cls.

    *成绩表挂线
    write: /015 sy-vline,
    021 sy-vline,
    038 sy-vline,
    045 sy-vline,
    052 sy-vline,
    059 sy-vline,
    066 sy-vline,
    015 sy-uline(052).

    endform.

    *成绩表对象声明
    DATA TEST TYPE REF TO CLS_TEST.
    &-----------------------
    *& PARAMETERS
    &-----------------------
    PARAMETERS: P_CLASS TYPE ZTTEST_T-ZZCLASS OBLIGATORY. "班级

    PARAMETERS P_YEAR TYPE ZTTEST_T-ZZYEAR OBLIGATORY. "学年

    &-----------------------
    *& SELECT-OPTIONS
    &-----------------------
    SELECT-OPTIONS S_STDNO FOR ZTTEST_T-ZZSTDNO "学号
    MATCHCODE OBJECT ZZMCSBID.

    &-----------------------
    *& AT SELECTION SCREEN
    &-----------------------

    INITIALIZATION.

    &-----------------------
    *& AT SELECTION SCREEN
    &-----------------------
    AT SELECTION-SCREEN.

    • 选择画面项目检查-班级
      PERFORM CLASSOO_INPUT_CHECK.

    • 选择画面项目检查-学年
      PERFORM YEAR_INPUT_CHECK USING P_YEAR TEXT-001.

    &-----------------------
    *& START-OF-SELECTION
    &-----------------------
    START-OF-SELECTION.

    &-----------------------
    *& END-OF-SELECTION
    &-----------------------
    END-OF-SELECTION.

    *报表程序终了处理
    PERFORM REPORT_EDIT_END.
    &-----------------------
    *& TOP-OF-PAGE
    &-----------------------
    TOP-OF-PAGE.

    • 报表页眉编辑
      PERFORM REPORT_HEADER_EDIT.
      &-----------------------
      *& END-OF-PAGE
      &-----------------------
      END-OF-PAGE.

    • 报表页脚编辑
      perform report_footer_edit.

      WIRITE 030 SY-PAGNO. "页数

    ENDFORM.

    &-----------------------
    *& FORM CLASS_INPUT_CHECK
    &-----------------------

    •     选择画面项目检查-班级
      
      • 1

    -------------------------
    form classoo_input_check.
    test->zzclass = p_class.
    call method test->get_class_domain.
    call method test->get_class.

    endform.

    &------------------------

    •   报表数据初始化
      
      • 1

    -------------------------
    form report_data_init.

    • 内部表初始化
      clear: test->h_test. "成绩表头
      refresh: test->test. "成绩表

    endform.

    &------------------------

    •   报表数据选择
      
      • 1

    -------------------------
    form report_data_select.

    test->zzstdnof = s_stdno-low.
    test->zzstdnof = s_stdno-high.
    call method test->get_test
    exporting
    class = p_class
    year = p_year.

    endform.

    &---------------------------
    *& Form REPORT_DATA_EXE
    &---------------------------

    •   报表数据打印
      
      • 1

    ----------------------------
    form report_data_exe.

    check test->test[] is not initial.

    loop at test->test into test->h_test. "成绩内部表
    clear flg-gls_frst. "班级表示清空
    at new zzclass. "新班级
    move cns-on to flg-cls_frst. "班级标示设ON
    endat.
    reserve 3 lines.

    • 报表明细编辑
      perform edit_report_dtl.

      at end of zzclass. "班级最后

    • 报表挂线
      perform edit_report_cls.
      endat.

    at end of zzyear.
      new-page.
    endat.
    
    • 1
    • 2
    • 3

    endloop.
    endform.

    &----------------------
    *& Form REPORT_EDIT_END
    &----------------------

    • 报表程序终了处理
      
      • 1

    -----------------------
    form report_edit_end.

    check test->test[] is not initial.

    • 当前行号小于88时
      if sy-linno < line88.
      skip to line line88.
      perform report_footer_edit.
      endif.

    endform.

    &----------------------
    *& Form REPORT_HEADER_EDIT
    &----------------------

    • 报表页眉编辑
      
      • 1

    -----------------------
    FORM REPORT_HEADER_EDIT.
    SKIP 1.
    WRITE: /030 TEXT-002. "成绩表
    WRITE: /016 TEXT-001, "学年
    020 CNS-COLON,
    022 TEST->H_TEST-ZZYEAR.
    WRITE: 030 TEXT-003,
    036 CNS-COLON,
    038 TEST->ZTNAMEM(6),
    035 TEST->ZTNAMES(6).

    WRITE: /015 SY-ULINE(052).
    WRITE: /015 SY-VLINE,
    017 TEXT-004, "班级
    021 SY-VLINE,
    025 TEXT-005, "学生
    038 SY-VLINE,
    040 TEXT-006, "语文
    045 SY-VLINE,
    047 TEXT-007, "数学
    052 SY-VLINE,
    054 TEXT-008, "自然
    059 SY-VLINE,
    061 TEXT-009, "思品
    066 SY-VLINE.

    WRITE: /015 SY-VLINE,
    021 SY-VLINE,
    038 SY-VLINE,
    045 SY-VLINE,
    052 SY-VLINE,
    059 SY-VLINE,
    066 SY-VLINE,
    015 SY-ULINE(052).

    ENDFORM.

    &----------------------
    *& Form REPORT_EDIT_DTL
    &----------------------

    • 报表明细编辑
      
      • 1

    -----------------------

    form edit_report_dtl.

    write: /015 sy-vline,
    021 sy-vline,
    023(4) test->h_test-zztensha, "学生
    038 sy-vline,
    041(4) test->h_test-zztensha, "语文
    045 sy-vline,
    048(4) test->h_test-zztensha, "数学
    052 sy-vline,
    055(4) test->h_test-zztensha, "自然
    059 sy-vline,
    062(4) test->h_test-zztensha, "思品
    066 sy-vline.
    if flg-cls_frst = cns-on. "班级开始
    write: 017 test->h_test-zzclass+0(1),
    018 cns-plus,
    019 test->h_test-zzclass+1(1).

    endform.

    &----------------------
    *& Form EDIT_REPORT_CLS
    &----------------------

    • 报表挂线
      
      • 1

    -----------------------
    form edit_report_cls.

    • 成绩表挂线
      write: /015 sy-vline,
      021 sy-vline,
      038 sy-vline,
      045 sy-vline,
      052 sy-vline,
      059 sy-vline,
      066 sy-vline,
      015 sy-vline,
      021 sy-uline(052).

    endform.

    &----------------------
    *& Form REPORT_FOOTER_EDIT
    &----------------------

    • 报表页脚编辑
      
      • 1

    -----------------------
    form report_footer_edit.

    write 030 sy-pagno. "页数

    endform.

  • 相关阅读:
    国际播客日 · 森海塞尔精选播客设备满足各类音频需求
    收银系统商品定价设计思考
    RT-Thread提供的网络世界入口 -net组件
    iTOP3A5000_7A2000开发板龙芯全国产处理器LoongArch架构核心主板
    java计算机毕业设计VUE技术小区车辆档案车位管理系统设计与实现源码+数据库+系统+lw文档
    【毕业设计】机器学习的员工离职模型研究-python
    21天学习挑战赛--第一天打卡(屏幕密度)
    HTTP/2和HTTP/3特性介绍
    RK3399 Android7.1修改安兔兔等第三方软件读到的内核版本信息
    js字符串处理
  • 原文地址:https://blog.csdn.net/weixin_43847969/article/details/126420533