1.写SQL
* -----增加业务员名字字段------SELECTA~VBELN,C~NAME1_TEXTFROM VBAK AS AINNER JOIN VBPA AS B ON A~VBELN = B~VBELNINNER JOIN BUT000 AS C ON B~KUNNR = C~PARTNERWHEREB~PARVW = 'Z1'AND B~POSNR = ''
* AND C~NAME1_TEXT IN @S_NAMEINTO TABLE @GT_NAME1 .SELECTA~VBELN,C~NAME1_TEXTFROM VBAK AS AINNER JOIN VBPA AS B ON A~VBELN = B~VBELNINNER JOIN BUT000 AS C ON B~KUNNR = C~PARTNERWHEREB~PARVW = 'Z1'AND B~POSNR <> ''
* AND C~NAME1_TEXT IN @S_NAMEINTO TABLE @GT_NAME2 .
2.按条件读取刚刚写的sql数据,if sy-subrc 中可以继续读
READ TABLE GT_NAME1 INTO DATA(LS_NAME1) WITH KEY VBELN = LS_GROUP1-VBELNBINARY SEARCH.IF SY-SUBRC = 0.CONDENSE LS_NAME1-NAME1_TEXT.GS_ALV-NAME1_TEXT = LS_NAME1-NAME1_TEXT. "高级业务员ELSE.READ TABLE GT_NAME2 INTO DATA(LS_NAME2) WITH KEY VBELN = LS_GROUP1-VBELNBINARY SEARCH.IF SY-SUBRC = 0.CONDENSE LS_NAME1-NAME1_TEXT.GS_ALV-NAME1_TEXT = LS_NAME2-NAME1_TEXT.ENDIF.ENDIF.
3.搜索帮助用函数和sql实现
"搜索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_NAME-LOW. "搜索帮助PERFORM FRM_SEARCH_HELP.FORM FRM_SEARCH_HELP.TYPES:BEGIN OF TY_TAB,NAME2_TEXT TYPE BUT000-NAME1_TEXT,END OF TY_TAB.DATA:GT_SEARCH TYPE TABLE OF TY_TAB WITH HEADER LINE,GS_SEARCH TYPE TY_TAB.SELECT DISTINCTNAME1_TEXTFROM BUT000WHERE NAME1_TEXT <> ''INTO TABLE @DATA(GT_SEARCH_NAME).LOOP AT GT_SEARCH_NAME INTO DATA(GS_SEARCH_NAME).CONDENSE GS_SEARCH_NAME-NAME1_TEXT.GS_SEARCH-NAME2_TEXT = GS_SEARCH_NAME-NAME1_TEXT.APPEND GS_SEARCH TO GT_SEARCH.CLEAR GS_SEARCH.ENDLOOP.CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGRETFIELD = 'NAME2_TEXT' "指定要返回屏幕参数的在内表中的fieldVALUE_ORG = 'S' "S代表structureDYNPPROG = SY-REPID "指定屏幕参数所在的程序名称DYNPNR = SY-DYNNR "指定参数所在的屏幕编号DYNPROFIELD = 'S_NAME' "指定屏幕参数的名称TABLESVALUE_TAB = GT_SEARCH "内表
* return_tab = lt_return1EXCEPTIONSPARAMETER_ERROR = 1NO_VALUES_FOUND = 2OTHERS = 3.ENDFORM.
4.根据屏幕输入数据筛选实现
*&-------START BY YAOBODONG AT 2024.7.3 增加高级业务作为搜索条件IF S_NAME-LOW = ''.APPEND GS_ALV TO GT_ALV.ELSE.IF GS_ALV-NAME1_TEXT = ''.CLEAR GS_ALV.CONTINUE.ELSE.IF GS_ALV-NAME1_TEXT = S_NAME-LOW.APPEND GS_ALV TO GT_ALV.ENDIF.ENDIF.ENDIF.
*&--------END BY YAOBODONG AT 2024.7.4
搜索条件可以这样加 用NOT IN 语法