1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
FUNCTION ZTEST_XIAOY_CHECKTF. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" REFERENCE(IV_TABNAME) TYPE TABNAME *" TABLES *" IT_DATA *" ET_MESSAGE STRUCTURE ZSHR_MESSAGE *"---------------------------------------------------------------------- DATA: dyn_table TYPE REF TO data, ”gs_display type ref to data, lo_descr type ref to cl_abap_structdescr, lt_fields type ddfields, lv_zz type string, ls_fields like line of lt_fields, ls_message type zshr_message, lv_text type string, lv_line type char20, dyn_wa TYPE REF TO data. FIELD-SYMBOLS: <dyn_table> TYPE table, <dyn_wa> TYPE ANY. *IV_TABNAME 是我们excel se11定义的结构或者表 CREATE DATA dyn_table TYPE TABLE OF (IV_TABNAME). ASSIGN dyn_table->* TO <dyn_table>. CREATE DATA dyn_wa LIKE LINE OF <dyn_table>. ASSIGN dyn_wa->* TO <dyn_wa>. *<dyn_table> = IT_DATA[]. ASSIGN IT_DATA[] to <dyn_table>. *下面是获取结构字段属性 当然有个简单的办法,直接从dd03l读取就行 lo_descr ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ). lt_fields = lo_descr->get_ddic_field_list( p_langu = 'E' p_including_substructres = abap_true ). *sort lt_fields by tabname fieldname. loop at <dyn_table> ASSIGNING <dyn_wa>. lv_line = sy-tabix. CONDENSE lv_line. loop at lt_fields into ls_fields. ASSIGN COMPONENT ls_fields-fieldname of STRUCTURE <dyn_wa> to FIELD-SYMBOL(<field>). if <field> is ASSIGNED. case ls_fields-inttype. when 'D'. if <field> is not initial. replace all occurrences of '' in lv_text with space. replace all occurrences of '-' in lv_text with space. replace all occurrences of '/' in lv_text with space. condense: lv_text no-gaps. lv_text = <field> . lv_zz = '^(?:(?:(?:(?:(?:1[6-9]|[2-9]d)(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:0229))|' && '(?:(?:(?:1[6-9]|[2-9]d)d{2})(?:(?:(?:0[13578]|1[02])31)|(?:(?:0[13-9]|1[0-2])(?:29|30))|(?:(?:0[1-9])|(?:1[0-2]))(' && '?:0[1-9]|1d|2[0-8]))))$'. if cl_abap_matcher=>matches( pattern = lv_zz text = lv_text ) ne abap_true. ls_message-msgty = 'E'. concatenate 'Excel第' lv_line '字段' ls_fields-fieldname '数据不是日期格式YYYYMMDD' into ls_message-msgtx SEPARATED BY space. append ls_message to ET_MESSAGE. “exit . clear:ls_message. endif. <field> = lv_text. endif. when 'N' or 'I' . if <field> is not initial. lv_text = <field> . replace all occurrences of ',' in lv_text with space. condense: lv_text no-gaps. if cl_abap_matcher=>matches( pattern = '-?[0-9]d*' text = lv_text ) ne abap_true. ls_MESSAGE-msgty = 'E'. * concatenate ls_fields-fieldname '数据不是整数类型的' into ls_MESSAGE-msgtx. concatenate 'Excel第' lv_line '字段' ls_fields-fieldname '数据不是整数类型的' into ls_message-msgtx SEPARATED BY space. append ls_MESSAGE to ET_MESSAGE. ”exit . clear:ls_MESSAGE. endif. <field> = lv_text. endif. when 'P'. if <field> is not initial. lv_text = <field> . replace all occurrences of ',' in lv_text with space. condense: lv_text no-gaps. if cl_abap_matcher=>matches( * pattern = '^(([1-9]d*)(.d{1,2})?)$|^(0.0?([1-9]d?))$' pattern = '^[0-9]+.?[0-9]*$'"肖勇更改正则表达式 20190422 text = lv_text ) ne abap_true. ls_message-msgty = 'E'. * concatenate ls_ztehrdt02-fielc '数据不是数字类型的' into ls_message-msgtx. concatenate 'Excel第' lv_line '字段' ls_fields-fieldname '数据不是数字类型的' into ls_message-msgtx SEPARATED BY space. append ls_message to et_message. “ exit . clear:ls_message. endif. <field> = lv_text. endif. when 'C'. * clear:len. data(len) = strlen( <field> )."先判断长度 if len > ls_fields-leng. ls_message-msgty = 'E'. * concatenate ls_ztehrdt02-fielc '数据长度过长' into ls_message-msgtx. concatenate 'Excel第' lv_line '字段' ls_fields-fieldname '数据长度过长' into ls_message-msgtx SEPARATED BY space. append ls_message to ET_MESSAGE.clear:ls_message. endif. clear:len. endcase. endif. endloop. ENDLOOP. ENDFUNCTION. 测试用的小段代码 select * into CORRESPONDING FIELDS OF TABLE lt_mara from mara UP TO 10 ROWS. CALL FUNCTION 'ZTEST_XIAOY_CHECKTF' EXPORTING IV_TABNAME = 'MARA' TABLES IT_DATA = lt_mara[] ET_MESSAGE = ET_MESSAGE. |
我们在debug的时候可以改变 lt_mara里面的值来验证代码。
Just want to ssay your article iss as amazing. The clarity in your submit iis just cool and that i
can assume you are an expert on this subject. Fine along with your permission allow me to take hold of your RSS feed
to keep upated with coming nearr near post. Thank you one million aand please carry on the
enjoyable work.
Levitra Levitra