SAP ABAP——学生信息系统demo

简介: 本文是一个ABAP学生信息系统的demo,废话不多说直接看demo场景

本文是一个ABAP学生信息系统的demo,废话不多说直接看demo场景


Demo场景

     通过自定义屏幕输入学生信息(其中自定义屏幕包含了复选框,能让用户自行选择学生是否参加暑期培训),可以对学生信息进行添加,修改和检查,并且将数据修改到数据库表中


自定义屏幕样式(屏幕号100)

  • 复选框收起

a47e69335bb025c4b3c4164b1c0f5d3.png

  • 复选框展开

bdd7e09c3c5926f16bb0be60469d4ad.png

  • 屏幕元素清单


412eca6f619228574a80342160cc71e.png

df663d3c99bb047d8ac0ffaa7733caa.png


数据库表ZSTUDENT_WYZ

  • 数据库表字段

0d68672f4d5f15dcd093133b9e38000.png


总程序代码

*&---------------------------------------------------------------------*
*& Modulpool ZWYZTEST_04
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
PROGRAM ZWYZTEST_04 MESSAGE-ID  FILAM.
TABLES:ZSTUDENT_WYZ.
INCLUDE ZWYZTEST_04_TOP.
INCLUDE ZWYZTEST_04_FROM.
INCLUDE ZWYZTEST_04_PBO.
INCLUDE ZWYZTEST_04_PAI.

子程序代码

ZWYZTEST_04_TOP

*&---------------------------------------------------------------------*
*& 包含               ZWYZTEST_04_TOP
*&---------------------------------------------------------------------*
DATA:CHECKBOX1 TYPE C LENGTH 1.
DATA:GS_ZSTUDENT TYPE ZSTUDENT_WYZ.
DATA:GT_ZSTUDENT TYPE TABLE OF ZSTUDENT_WYZ.
DATA:GV_BUTTON_F TYPE CHAR1.
DATA:GV_BUTTON_M TYPE CHAR1.

ZWYZTEST_04_FROM

*&---------------------------------------------------------------------*
*& 包含               ZWYZTEST_04_FROM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form SAVE_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM GET_DATA.
  DATA:LS_ZSTUDENT TYPE ZSTUDENT_WYZ.
  IF  ZSTUDENT_WYZ-ZSCHOOL IS INITIAL OR ZSTUDENT_WYZ-ZCODE IS INITIAL."第一次循环if
    MESSAGE S001 WITH '必须输入学校代码和学生代码' DISPLAY LIKE 'E'.
  ELSE.  "第一次循环else
     SELECT SINGLE *
       FROM ZSTUDENT_WYZ
       INTO CORRESPONDING FIELDS OF LS_ZSTUDENT
       WHERE ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL
         AND ZCODE = ZSTUDENT_WYZ-ZCODE.
    IF SY-SUBRC = 0.
      MESSAGE S001 WITH '禁止录入相同学生数据' DISPLAY LIKE 'E'.
     ELSE.
         IF GV_BUTTON_F = 'X'.
        GS_ZSTUDENT-ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL.
        GS_ZSTUDENT-ZCODE = ZSTUDENT_WYZ-ZCODE .
        GS_ZSTUDENT-ZNAME = ZSTUDENT_WYZ-ZNAME .
        GS_ZSTUDENT-ZSEX  = '女'.
        GS_ZSTUDENT-ZCLASS = ZSTUDENT_WYZ-ZCLASS .
        GS_ZSTUDENT-ZAGE = ZSTUDENT_WYZ-ZAGE .
        GS_ZSTUDENT-ZTRAIN = ZSTUDENT_WYZ-ZTRAIN .
        GS_ZSTUDENT-ZCRDT = ZSTUDENT_WYZ-ZCRDT.
        GS_ZSTUDENT-ZCRTM = ZSTUDENT_WYZ-ZCRTM .
       ELSEIF GV_BUTTON_M = 'X'.
        GS_ZSTUDENT-ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL.
        GS_ZSTUDENT-ZCODE = ZSTUDENT_WYZ-ZCODE .
        GS_ZSTUDENT-ZNAME = ZSTUDENT_WYZ-ZNAME .
        GS_ZSTUDENT-ZSEX = '男'.
        GS_ZSTUDENT-ZCLASS = ZSTUDENT_WYZ-ZCLASS .
        GS_ZSTUDENT-ZAGE = ZSTUDENT_WYZ-ZAGE .
        GS_ZSTUDENT-ZTRAIN = ZSTUDENT_WYZ-ZTRAIN .
        GS_ZSTUDENT-ZCRDT = ZSTUDENT_WYZ-ZCRDT.
        GS_ZSTUDENT-ZCRTM = ZSTUDENT_WYZ-ZCRTM .
      ENDIF.
       APPEND GS_ZSTUDENT TO GT_ZSTUDENT.
     MODIFY  ZSTUDENT_WYZ FROM TABLE GT_ZSTUDENT.
        IF SY-SUBRC = 0 .
          MESSAGE S001 WITH '录入学生数据成功'.
         ELSE.
           MESSAGE S001 WITH '录入学生数据失败' DISPLAY LIKE 'E'.
        ENDIF.   
       ENDIF.
   ENDIF."第一次循环endif
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DATA_UPDATE.
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM DATA_UPDATE .
  DATA:LS_ZSTUDENT TYPE ZSTUDENT_WYZ.
  DATA:LT_ZSTUDENT1 TYPE TABLE OF ZSTUDENT_WYZ.
  DATA:LT_ZSTUDENT2 TYPE TABLE OF ZSTUDENT_WYZ.
  IF  ZSTUDENT_WYZ-ZSCHOOL IS INITIAL OR ZSTUDENT_WYZ-ZCODE IS INITIAL."第一次循环if
  MESSAGE S001 WITH '必须输入学校代码和学生代码' DISPLAY LIKE 'E'.
  ELSE.  "第一次循环else
    SELECT * FROM ZSTUDENT_WYZ INTO TABLE LT_ZSTUDENT1 WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
   IF ZSTUDENT_WYZ-ZNAME IS NOT INITIAL.
     UPDATE ZSTUDENT_WYZ SET ZNAME = ZSTUDENT_WYZ-ZNAME WHERE
     ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
     ZCODE   = ZSTUDENT_WYZ-ZCODE.
     ENDIF.   
  IF ZSTUDENT_WYZ-ZCLASS IS NOT INITIAL.
    UPDATE ZSTUDENT_WYZ SET ZCLASS = ZSTUDENT_WYZ-ZCLASS WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.    
  IF ZSTUDENT_WYZ-ZAGE IS NOT INITIAL.
    UPDATE ZSTUDENT_WYZ SET ZAGE = ZSTUDENT_WYZ-ZAGE WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.    
  IF ZSTUDENT_WYZ-ZTRAIN IS NOT INITIAL.
    UPDATE ZSTUDENT_WYZ SET ZTRAIN = ZSTUDENT_WYZ-ZTRAIN WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.   
  IF ZSTUDENT_WYZ-ZCRDT IS NOT INITIAL.
    UPDATE ZSTUDENT_WYZ SET ZCRDT = ZSTUDENT_WYZ-ZCRDT WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.
  IF ZSTUDENT_WYZ-ZCRTM IS NOT INITIAL.
    UPDATE ZSTUDENT_WYZ SET ZCRTM = ZSTUDENT_WYZ-ZCRTM WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.   
  IF GV_BUTTON_F = 'X'.
   SELECT SINGLE * FROM ZSTUDENT_WYZ INTO CORRESPONDING FIELDS OF LS_ZSTUDENT WHERE
     ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
     ZCODE   = ZSTUDENT_WYZ-ZCODE.
    IF LS_ZSTUDENT-ZSEX = '男'.
  UPDATE ZSTUDENT_WYZ SET ZSEX = '女' WHERE
  ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
  ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.
  ELSEIF GV_BUTTON_M = 'X'.
    SELECT SINGLE * FROM ZSTUDENT_WYZ INTO CORRESPONDING FIELDS OF LS_ZSTUDENT WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
    ZCODE   = ZSTUDENT_WYZ-ZCODE.
    IF LS_ZSTUDENT-ZSEX = '女'.
  UPDATE ZSTUDENT_WYZ SET ZSEX = '男' WHERE
  ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
  ZCODE   = ZSTUDENT_WYZ-ZCODE.
  ENDIF.
  ENDIF.
  ENDIF.
  SELECT * FROM ZSTUDENT_WYZ INTO TABLE LT_ZSTUDENT2 WHERE
  ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL AND
  ZCODE   = ZSTUDENT_WYZ-ZCODE.
  IF LT_ZSTUDENT1[] = LT_ZSTUDENT2[].
    MESSAGE S001 WITH '修改数据失败' DISPLAY LIKE 'E'.
  ELSE.
    MESSAGE S001 WITH '修改数据成功' .
    ENDIF.
  ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELD_CHECK
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FIELD_CHECK .
  DATA:LS_ZSTUDENT TYPE ZSTUDENT_WYZ.
  IF  ZSTUDENT_WYZ-ZSCHOOL IS INITIAL OR ZSTUDENT_WYZ-ZCODE IS INITIAL."第一次循环if
  MESSAGE S001 WITH '必须输入学校代码和学生代码' DISPLAY LIKE 'E'.
  ELSE.  "第一次循环else
  SELECT SINGLE *
  FROM ZSTUDENT_WYZ
  INTO CORRESPONDING FIELDS OF LS_ZSTUDENT
  WHERE ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL
  AND ZCODE = ZSTUDENT_WYZ-ZCODE.
  IF SY-SUBRC = 0.
  MESSAGE S001 WITH '存在该学生数据'.
  ELSE.
    MESSAGE S001 WITH '不存在该学生数据' DISPLAY LIKE 'E'.
  ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DATA_DELETE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM DATA_DELETE .
  IF  ZSTUDENT_WYZ-ZSCHOOL IS INITIAL OR ZSTUDENT_WYZ-ZCODE IS INITIAL."第一次循环if
  MESSAGE S001 WITH '必须输入学校代码和学生代码' DISPLAY LIKE 'E'.
  ELSE.  "第一次循环else
   DELETE FROM ZSTUDENT_WYZ WHERE
    ZSCHOOL = ZSTUDENT_WYZ-ZSCHOOL
AND ZCODE   = ZSTUDENT_WYZ-ZCODE.
   IF SY-SUBRC = 0.
    MESSAGE S001 WITH '删除数据成功'.
   ELSE.
    MESSAGE S001 WITH '删除数据失败' DISPLAY LIKE 'E'.
    ENDIF.
   ENDIF.
ENDFORM.

ZWYZTEST_04_PBO

*&---------------------------------------------------------------------*
*& Module SET_VALUES OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE SET_VALUES OUTPUT.
    IF CHECKBOX1 =''.
     LOOP AT SCREEN.
    IF SCREEN-NAME = 'ZSTUDENT_WYZ-ZTRAIN'.
       SCREEN-INVISIBLE = '1'.
       SCREEN-INPUT     = '0'.
MODIFY SCREEN.
    ENDIF .
     ENDLOOP.
    ELSEIF CHECKBOX1 ='X'.
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'ZSTUDENT_WYZ-ZTRAIN'.
      SCREEN-INVISIBLE = '0'.
      SCREEN-INPUT     = '1'.
      MODIFY SCREEN.
    ENDIF .
  ENDLOOP.
  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& 包含               ZWYZTEST_04_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module HIDE OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE HIDE OUTPUT.
  IF CHECKBOX1 =''.
    LOOP AT SCREEN.
   IF SCREEN-GROUP1 = 'BOX'.
    SCREEN-INVISIBLE = '1'.
   SCREEN-INPUT     = '0'.
   MODIFY SCREEN.
   ENDIF.
   ENDLOOP.
  ELSEIF CHECKBOX1 ='X'.
LOOP AT SCREEN.
  IF SCREEN-GROUP1 = 'BOX'.
   SCREEN-INVISIBLE = '0'.
   SCREEN-INPUT     = '1'.
   MODIFY SCREEN.
 ENDIF.
  ENDLOOP.
  ENDIF.
  ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STANDARD' .
 SET TITLEBAR 'STATUS' .
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module CHECK_FIELD OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*

ZWYZTEST_04_PAI

*&---------------------------------------------------------------------*
*& 包含               ZWYZTEST_04_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
  WHEN 'ZBACK' OR 'BACK'.
    LEAVE TO SCREEN 0.
  WHEN 'ZEXIT' OR 'EXIT' OR 'CANCEL'.
    LEAVE PROGRAM.
  WHEN 'ZCHANGE'.
    PERFORM DATA_UPDATE.
  WHEN 'ZCHECK'.
    PERFORM FIELD_CHECK.
   WHEN'ZDELETE'.
   PERFORM DATA_DELETE.
   WHEN 'ZSAVE' OR 'SAVE'.
     PERFORM GET_DATA.
  WHEN OTHERS.
  ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
LEAVE PROGRAM.
ENDMODULE.

GUI状态栏

c2790cf1fae9877ac3771dff778dfa9.png

复制的是标准的GUI栏,写了几个按钮的功能


最后给源代码附上相应的事务代码T-CODE即可使用

目录
相关文章
|
7月前
|
数据库
SAP系统不能启动解决方案
SAP系统不能启动解决方案
273 1
|
7月前
|
Unix
SAP R/3系统的启动和关闭
SAP R/3系统的启动和关闭
91 1
|
7月前
|
Oracle 关系型数据库 Unix
SAP系统拷贝 UNIX + Oracle
SAP系统拷贝 UNIX + Oracle
61 1
SAP ABAP 程序调用设置成后台作业模式
ABAP 程序调用设置成后台作业模式
533 0
|
SQL
SAP ABAP-OPENSQL-数值函数简介
S4中针对OPENSQL新提供一些函数
145 0
|
SQL
SAP ABAP-OPENSQL-字符串函数介绍
S4中SQL新语法字符串函数
226 0
|
SQL
SAP ABAP-OPENSQL-日期/时间戳函数
S4提供针对OPENSQL一些新的SQL函数调用,本文展示相关函数的使用
704 0
SAP ABAP-删除工序示例代码
ABAP-删除工序示例代码
178 0
SAP ABAP 检查事务码权限
检查用户是否有自开发事务码的权限
164 0
|
7月前
|
程序员
开发语言漫谈-ABAP
ABAP是SAP公司专门用于SAP软件环境的专门语言