在展示ABAP代码之前,先建立自建表ZCHENH006,表中包含两个关键字段 BELNR(地区编码),SDESC(地区描述)。

编码规则参考:身份证前六位地区编码规则,可参考我另外一篇Blog导入系统:ABAP自动生成身份证及校验

 在导入配置之后,可以参考以下ABAP代码。

  1 *&---------------------------------------------------------------------*
  2 *& REPORT  ZCHENH014
  3 *&
  4 *&---------------------------------------------------------------------*
  5 *&
  6 *&
  7 *&---------------------------------------------------------------------*
  8 
  9 REPORT zchenh014.
 10 TABLES:zchenh006.
 11 SELECTION-SCREEN BEGIN OF LINE.
 12 PARAMETERS:p_sdesc TYPE zchenh006-sdesc DEFAULT '请选择省份信息'.
 13 PARAMETERS:p_belnr TYPE zchenh006-belnr.
 14 
 15 SELECTION-SCREEN END OF LINE.
 16 
 17 SELECTION-SCREEN BEGIN OF LINE.
 18 PARAMETERS:p_sdesc1 TYPE zchenh006-sdesc DEFAULT '请选择市信息'.
 19 PARAMETERS:p_belnr1 TYPE zchenh006-belnr.
 20 
 21 SELECTION-SCREEN END OF LINE.
 22 
 23 SELECTION-SCREEN BEGIN OF LINE.
 24 PARAMETERS:p_sdesc2 TYPE zchenh006-sdesc DEFAULT '请选择县/区信息'.
 25 PARAMETERS:p_belnr2 TYPE zchenh006-belnr.
 26 SELECTION-SCREEN END OF LINE.
 27 
 28 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_belnr.
 29   PERFORM frm_f4_get_belnr USING '' CHANGING p_belnr p_sdesc.
 30 
 31 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_belnr1.
 32   PERFORM frm_f4_get_belnr USING '' CHANGING p_belnr1 p_sdesc1.
 33 
 34 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_belnr2.
 35   PERFORM frm_f4_get_belnr USING '' CHANGING p_belnr2 p_sdesc2.
 36 
 37 AT SELECTION-SCREEN OUTPUT.
 38   PERFORM frm_modify_screen.
 39 
 40 INITIALIZATION.
 41 *&---------------------------------------------------------------------*
 42 *&      Form  frm_f4_get_belnr
 43 *&---------------------------------------------------------------------*
 44 *       text
 45 *----------------------------------------------------------------------*
 46 *  -->  p1        text
 47 *  <--  p2        text
 48 *----------------------------------------------------------------------*
 49 FORM frm_f4_get_belnr USING p_in CHANGING p_out1 p_out2.
 50   DATA:lt_field TYPE dfies      OCCURS 0 WITH HEADER LINE,
 51        lt_ret   TYPE ddshretval OCCURS 0 WITH HEADER LINE,
 52        lt_dyn   TYPE dselc      OCCURS 0 WITH HEADER LINE.
 53   DATA:BEGIN OF lt_zchenh006 OCCURS 0 ,
 54         sdesc TYPE zchenh006-sdesc, " 省市县代码
 55         belnr TYPE zchenh006-belnr, " 省市县描述
 56        END OF lt_zchenh006.
 57   DATA:lv_belnr(6).
 58   IF p_in = ''.
 59     SELECT sdesc belnr
 60       INTO TABLE lt_zchenh006
 61       FROM zchenh006
 62       WHERE belnr LIKE '%0000'.
 63   ENDIF.
 64 
 65   IF p_in = ''.
 66     lv_belnr = p_belnr+0(2) && '%'.
 67     SELECT  sdesc  belnr
 68       INTO TABLE lt_zchenh006
 69       FROM zchenh006
 70     WHERE belnr LIKE lv_belnr
 71     AND belnr LIKE '%00'
 72     AND belnr NE  p_in
 73     AND sdesc NE ''.
 74   ENDIF.
 75 
 76   IF p_in = ''.
 77     lv_belnr = p_belnr1+0(4) && '%'.
 78     SELECT sdesc belnr
 79       INTO TABLE lt_zchenh006
 80       FROM zchenh006
 81      WHERE belnr NOT LIKE '%00'
 82 *       AND belnr NOT LIKE '%01'
 83        AND belnr  LIKE lv_belnr
 84        AND belnr  NE  p_belnr1.
 85   ENDIF.
 86 
 87   CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
 88     EXPORTING
 89       retfield         = 'ZCHENH006-BELNR'
 90       dynpprog         = sy-repid
 91       dynpnr           = sy-dynnr
 92       dynprofield      = 'P_BELNR'
 93       window_title     = '自定义搜索帮助'
 94       value_org        = 'S'
 95       callback_program = sy-repid
 96     TABLES
 97       value_tab        = lt_zchenh006
 98       field_tab        = lt_field
 99       return_tab       = lt_ret
100       dynpfld_mapping  = lt_dyn
101     EXCEPTIONS
102       parameter_error  = 1
103       no_values_found  = 2
104       OTHERS           = 3.
105   LOOP AT lt_ret.
106     p_out1 = lt_ret-fieldval.
107     SELECT SINGLE sdesc INTO p_out2 FROM zchenh006 WHERE belnr = p_out1.
108     IF sy-subrc NE 0.
109       p_out2 = '无效编号'.
110     ENDIF.
111   ENDLOOP.
112 ENDFORM.                    " frm_f4_get_belnr
113 *&---------------------------------------------------------------------*
114 *&      Form  FRM_MODIFY_SCREEN
115 *&---------------------------------------------------------------------*
116 *       text
117 *----------------------------------------------------------------------*
118 *  -->  p1        text
119 *  <--  p2        text
120 *----------------------------------------------------------------------*
121 FORM frm_modify_screen .
122   LOOP AT SCREEN.
123     CASE screen-name.
124       WHEN 'P_SDESC'.
125         screen-input = 0.
126         IF  p_sdesc IS INITIAL.
127           screen-active = 0.
128         ENDIF.
129       WHEN 'P_SDESC1'.
130         screen-input = 0.
131         IF  p_sdesc1 IS INITIAL.
132           screen-active = 0.
133         ENDIF.
134       WHEN 'P_SDESC2'.
135         screen-input = 0.
136         IF  p_sdesc2 IS INITIAL.
137           screen-active = 0.
138         ENDIF.
139     ENDCASE.
140     MODIFY SCREEN.
141   ENDLOOP.
142 
143 ENDFORM.                    " FRM_MODIFY_SCREEN


但是该代码有个瑕疵,每次选择完毕后,需要按下"回车",才能显示完整的地区描述信息。