本文是一个ABAP学生信息系统的demo,废话不多说直接看demo场景
Demo场景
通过自定义屏幕输入学生信息(其中自定义屏幕包含了复选框,能让用户自行选择学生是否参加暑期培训),可以对学生信息进行添加,修改和检查,并且将数据修改到数据库表中
自定义屏幕样式(屏幕号100)
- 复选框收起
- 复选框展开
- 屏幕元素清单
数据库表ZSTUDENT_WYZ
- 数据库表字段
总程序代码
*&---------------------------------------------------------------------* *& 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状态栏
复制的是标准的GUI栏,写了几个按钮的功能
最后给源代码附上相应的事务代码T-CODE即可使用