ABAP步循环

一、在界面中循环输出行数据,屏幕直接画出行数,需要计算翻页,一旦界面行数变动,则需要更改代码,所以引入步循环

二、步循环

首先在界面上画出要展示的内容

注意,在步循环中,文本的名称和输入框的名称不能相同,否则报错

选中显示的框,定义步循环,发现一行框变成了两行

 通过下拉框,可以随意展示多行数据

 定义翻页按钮

 在屏幕输入输出流中加入步循环代码

 参考代码如下

"-----------------------------@斌将军-----------------------------
TYPES: BEGIN OF ty_makt, matnr TYPE makt-matnr, maktx TYPE makt-maktx, END OF ty_makt. DATA:gt_makt TYPE TABLE OF ty_makt, gs_makt TYPE ty_makt. DATA:gv_line TYPE i, "当前行 gv_lines TYPE i, " gv_row TYPE i, "总行数 gv_page_lines TYPE i. * gv_limit TYPE i. DATA:ok_code TYPE sy-ucomm, save_ok TYPE sy-ucomm. START-OF-SELECTION. SELECT matnr"物料号 spras"语言 maktx"物料描述 FROM makt INTO CORRESPONDING FIELDS OF TABLE gt_makt WHERE matnr >= '000000000000000001' AND matnr <= '000000000000004422'. DESCRIBE TABLE gt_makt LINES gv_row. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Module READ_DATA OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE read_data OUTPUT. gv_page_lines = sy-loopc. gv_lines = sy-stepl + gv_line. READ TABLE gt_makt INTO gs_makt INDEX gv_lines. ENDMODULE. " READ_DATA OUTPUT *&---------------------------------------------------------------------* *& Module MODIFY_DATA INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE modify_data INPUT. gv_lines = sy-stepl + gv_line. MODIFY gt_makt FROM gs_makt INDEX gv_lines. ENDMODULE. " MODIFY_DATA INPUT *&---------------------------------------------------------------------* *& Module USER_COMM INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_comm INPUT. DATA:lv_count TYPE i. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'PREV_LINE'. gv_line = gv_line - 1. IF gv_line < 0. gv_line = 0. ENDIF. WHEN 'PREV_PAGE'. gv_line = gv_line - gv_page_lines. IF gv_line < 0. gv_line = 0. ENDIF. WHEN 'FIRST_PAGE'. gv_line = 0. WHEN 'NEXT_LINE'. * CLEAR gv_limit. * gv_limit = gv_row - gv_line. * IF gv_limit > gv_page_lines. IF gv_line + 1 < gv_row."如果后边已经没有了,就不能再翻页 gv_line = gv_line + 1. ENDIF. * ENDIF. WHEN 'NEXT_PAGE'. * CLEAR gv_limit. * gv_limit = gv_row - gv_line - gv_page_lines. * IF gv_limit > gv_page_lines. IF gv_line + gv_page_lines < gv_row."如果后边已经没有了,就不能再翻页 gv_line = gv_line + gv_page_lines. ENDIF. * ELSE. * gv_line = gv_row - gv_page_lines. * ENDIF. WHEN 'LAST_PAGE'. * gv_line = gv_row - gv_page_lines. IF gv_page_lines <> 0. gv_line = ( gv_row / gv_page_lines ) * 10. ENDIF. WHEN 'CANCEL'. LEAVE PROGRAM. WHEN OTHERS. ENDCASE. ENDMODULE. " USER_COMM INPUT "-----------------------------@斌将军-----------------------------

 

定期更文,欢迎关注

 
 
posted @ 2022-03-14 10:44  斌将军  阅读(326)  评论(0编辑  收藏  举报