abap-在table control中实现查找功能
生活随笔
收集整理的這篇文章主要介紹了
abap-在table control中实现查找功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
table?control?創建時可以實現添加,刪除,及翻頁的功能,但沒有查找的功能,故記錄多時查看不方便,所以要自己寫,DEBUG標準ALV的查找功能發現使用函數ALV_POPUP_TO_SEARCH2,該函數僅彈出查找框,其余查找代碼仍需要自己寫。
該函數查找提供的查找點過多,于是找了個簡單的ALV_POPUP_TO_SEARCH,實現一個簡單的查找功能,代碼如下:
??????WHEN?'%SC'."查找
??????CALL?FUNCTION?'ALV_POPUP_TO_SEARCH'
????????EXPORTING
??????????i_disable_search_sequence?=?'X'"不顯示下拉框
????????IMPORTING
??????????e_cancelled???????????????=?e_cancelled
??????????e_new_search??????????????=?e_new_search
????????CHANGING
??????????c_string??????????????????=?s_string.
??????IF?e_cancelled?NE?'X'."取消查找
????????IF?e_new_search?EQ?'X'."重新查找
??????????s_line?=?0.“從頭開始查找
????????ENDIF.
????????LOOP?AT?ztmsd1?FROM?s_line?TO?zmsdscp1-lines.
??????????IF?ztmsd1-matnr?CS?s_string.”包含字符串s_string
????????????ztmsd1-zflag?=?'X'."選中符合條件行記錄
????????????MODIFY?ztmsd1?TRANSPORTING?zflag.
????????????zmsdscp1-top_line?=?sy-tabix.“符合條件記錄置于首行
????????????s_line?=?sy-tabix.”記錄當前行,方便查找下一個時,從當前行的下一行開始查找
????????????search_deflag?=?'X'.“查找是否成功標志
????????????EXIT.
??????????ENDIF.
????????ENDLOOP.
????????IF?search_deflag?NE?'X'.
??????????MESSAGE?s007?WITH?'無匹配內容存在'.
????????ENDIF.
??????ENDIF.
??????CLEAR?search_deflag.
????WHEN?'%SC+'."查找下一個
??????IF?s_string?NE?''.
????????s_line?=?s_line?+?1.”查找下一個,則從上個符合條件記錄的下一行再始查找
????????LOOP?AT?ztmsd1?FROM?s_line?TO?zmsdscp1-lines.
??????????IF?ztmsd1-matnr?CS?s_string.
????????????ztmsd1-zflag?=?'X'.
????????????MODIFY?ztmsd1?TRANSPORTING?zflag.
????????????zmsdscp1-top_line?=?sy-tabix.
????????????s_line?=?sy-tabix.
????????????search_deflag?=?'X'.
????????????EXIT.
??????????ENDIF.
????????ENDLOOP.
????????IF?search_deflag?NE?'X'.
??????????MESSAGE?s007?WITH?'無匹配內容存在'.
????????ENDIF.
??????ENDIF.
??????CLEAR?search_deflag.
總結
以上是生活随笔為你收集整理的abap-在table control中实现查找功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Coding更改程序的变式(report
- 下一篇: ABAP TBL隐藏列