ABAP项目砖家之旅-screen和表单项目实战( 二 )


然后鼠标遇到屏幕适当位置,点击一下即可定位所有字段控件
美化下,添加描述(sap标准数据元素-域组成的字段会自动带出,用char等定义的字段需要自己添加文本控件)
保存,然后修改屏幕的代码:
PROCESS BEFORE OUTPUT.MODULE STATUS_0100."写状态栏(工具栏)和加载数据的代码*PROCESS AFTER INPUT.MODULE USER_COMMAND_0100. "写按键保存、返回
再双击 的“”“”,提示不存在是否新建,则新建程序命名为“”,添加获取双击行和GUI状态(工具栏)按键的代码:
MODULE STATUS_0100 OUTPUT. "pbo 事件SET PF-STATUS 'ZTEST_DYNPROSTA0100'."双击,新建一个0100屏幕的GUI状态,才能使用保存按键SET TITLEBAR '二级用户编辑界面'.IF SY-LISEL IS NOT INITIAL.READ TABLE LT_ZTTEST INTO WA_ZTTEST INDEX SY-TABIX .IF sy-subrc = 0.ZTTEST_01 = WA_ZTTEST .ENDIF.ENDIF.ENDMODULE.*&---------------------------------------------------------------------**&ModuleUSER_COMMAND_0100INPUT*&---------------------------------------------------------------------**text*----------------------------------------------------------------------*MODULE USER_COMMAND_0100 INPUT. "pai事件CASE SY-UCOMM.WHEN 'BACK' OR '&BACK'.LEAVE TO SCREEN 0 .WHEN '%EX' OR '&UP' .leave PROGRAM .WHEN 'RW' OR '&EXIT'.leave PROGRAM .WHEN 'SAVE' OR '&SAVE'.MODIFY zttest_01 FROM zttest_01 .IF sy-subrc = 0.MESSAGE '保存成功' type 'S'.ELSE.MESSAGE '保存失败' type 'E'.ENDIF.WHEN OTHERS.ENDCASE.ENDMODULE.
当然添加个GUI状态这样保存按键才能使用:
最后测试一下:保存已经提示成功,但是数据貌似没刷新 。封装sql获取数据和write的方法,重新执行下即可,代码如下:
MODULE USER_COMMAND_0100 INPUT.CASE SY-UCOMM.WHEN 'BACK' OR '&BACK'.LEAVE TO SCREEN 0 .WHEN '%EX' OR '&UP' .leave PROGRAM .WHEN 'RW' OR '&EXIT'.leave PROGRAM .WHEN 'SAVE' OR '&SAVE'.MODIFY zttest_01 FROM zttest_01 .IF sy-subrc = 0.MESSAGE '保存成功' type 'S'.PERFORM GET_DATA."更新数据ELSE.MESSAGE '保存失败' type 'E'.ENDIF.WHEN OTHERS.ENDCASE.ENDMODULE.
*&---------------------------------------------------------------------**& Report ZTEST_DYNPRO*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT ZTEST_DYNPRO.TABLES:zttest_01 .DATA:LT_ZTTEST TYPE TABLE OF zttest_01 ,WA_ZTTEST LIKE LINE OF LT_ZTTEST .FIELD-SYMBOLS: LIKE LINE OF LT_ZTTEST.select-OPTIONS:s_zname for zttest_01-zname,s_zdesc for zttest_01-zdesc .INITIALIZATION.AT SELECTION-SCREEN .AT LINE-SELECTION.CALL SCREEN '0100' .START-OF-SELECTION .PERFORM GET_DATA.END-OF-SELECTION .PERFORM WRRTEOUT.TOP-OF-PAGE.END-OF-PAGE .INCLUDE ztest_dynpro_mod.*&---------------------------------------------------------------------**&FormWRRTEOUT*&---------------------------------------------------------------------**text*----------------------------------------------------------------------**-->p1text*<--p2text*----------------------------------------------------------------------*FORM WRRTEOUT .WRITE:'搜索条件——用户:',s_zname,';姓名:',s_zdesc .ULINE.WRITE:TEXT-000,TEXT-001,TEXT-002,TEXT-003,TEXT-004,TEXT-005.ULINE.IF LT_ZTTEST[] is not INITIAL.LOOP AT LT_ZTTEST ASSIGNING .IF -ZDATE ge sy-datum.WRITE icon_green_light AS ICON .ELSE.WRITE icon_red_light AS ICON .ENDIF.WRITE: -ZNAME,-zdesc ,-ZDATE,-ZAREA,-ZWERKS . ULINE.ENDLOOP.ENDIF.ENDFORM.*&---------------------------------------------------------------------**&FormGET_DATA*&---------------------------------------------------------------------**text*----------------------------------------------------------------------**-->p1text*