对EXEC导入的日期,时间,金额,数值,通常需要转换为SAP通用的格式,基于不同的EXEC格式,可能会有不同的处理,以下是一引起常见的处理逻辑。
- 时间HH:MM:SS>时间HHMMSS
- 时间HH:MM>时间HHMMSS
- 时间HMMSS>时间HHMMSS
- 日期YYYY/MM/DD>日期YYYYMMDD
- 日期YYYY-MM-DD>日期YYYYMMDD
- 日期YYYY.MM.DD>日期YYYYMMDD
- 时间戳YYYYMMDD…… >日期YYYYMMDD
- 日期M/D/YYYY>日期YYYYMMDD
- 日期YYYY/M/D>日期YYYYMMDD
- 日期DD/MM/YYYY>日期YYYYMMDD
- 日期DD-MM-YYYY>日期YYYYMMDD
- 日期D/M/YYYY>日期YYYYMMDD
- 时间戳M/D/YY……>日期YYYYMMDD
- 日期DD-Jun-YY>日期YYYYMMDD
- 时间戳YYYY/M/D……>日期YYYYMMDD
- 金额 1,234.00->1234.00
- 金额 (1,234.00)->-1234.00
- 有小数点的数字
以下是日期YYYY-MM-DD>日期YYYYMMDD的一人例子代码
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 |
method CVT_DATE2. DATA lv_date TYPE char10. DATA: lcx_error TYPE REF TO cx_root. DATA yyyy TYPE numc4. DATA mm TYPE numc2. DATA dd TYPE numc2. lv_date = iv_in . FIND '-' IN lv_date. IF sy-subrc = 0. SPLIT lv_date AT '-' INTO DATA(y) DATA(M) DATA(d) . yyyy = y. mm = M. dd = d. lv_date = yyyy && mm && dd. ENDIF. CONDENSE lv_date NO-GAPS . TRY . ev_out = lv_date. CATCH cx_sy_conversion_error INTO lcx_error. RAISE err. ENDTRY. CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY' EXPORTING DATE = ev_out EXCEPTIONS plausibility_check_failed = 1 OTHERS = 2. IF sy-subrc <> 0. RAISE err. ENDIF. endmethod. |
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 |
METHOD get_data. FIELD-SYMBOLS <fs_table> TYPE ANY TABLE. FIELD-SYMBOLS <fs_line> TYPE any . ASSIGN excel_tab->* TO <fs_table>. IF <fs_table> IS NOT ASSIGNED. RETURN. ENDIF. *指定内表与工作区到字段符号 FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, <dyn_wa> TYPE any. ASSIGN dyn_wa->* TO <dyn_wa>. ASSIGN dyn_table->* TO <dyn_table>. DATA inta TYPE int4. DATA intb TYPE int4. SELECT SINGLE dcpfm INTO @DATA(dcpfm) FROM usr01 WHERE bname = @sy-uname. LOOP AT <fs_table> ASSIGNING <fs_line> . IF <fs_line> IS INITIAL OR sy-tabix NOT BETWEEN begin_row AND end_row. CONTINUE. ENDIF. inta = begin_col. intb = 1. WHILE inta <= end_col. ASSIGN COMPONENT inta OF STRUCTURE <fs_line> TO FIELD-SYMBOL(<fs_upfield>). IF sy-subrc = 0. ASSIGN COMPONENT intb OF STRUCTURE <dyn_wa> TO FIELD-SYMBOL(<fs_mapfield>). IF sy-subrc = 0. CASE cl_abap_datadescr=>get_data_type_kind( <fs_mapfield> ). WHEN 'D'."date IF strlen( <fs_upfield> ) = 5."日期转换成了数值 DATA bdate TYPE dats VALUE '19000101'. <fs_mapfield> = bdate + <fs_upfield> . ELSE. zcl_tr_3022_gui=>cvt_date4( EXPORTING iv_in = <fs_upfield> IMPORTING ev_out = <fs_mapfield> EXCEPTIONS err = 1 OTHERS = 2 ). ENDIF. WHEN 'T'."time zcl_tr_3022_gui=>cvt_time1( EXPORTING iv_in = <fs_upfield> IMPORTING ev_out = <fs_mapfield> EXCEPTIONS err = 1 OTHERS = 2 ). WHEN 'P'."number CALL FUNCTION 'UNITS_STRING_CONVERT' EXPORTING units_string = <fs_upfield> dcpfm = dcpfm * MLLN = 'M' * TSND = 'T' IMPORTING units = <fs_mapfield> EXCEPTIONS invalid_type = 1 OTHERS = 2. IF sy-subrc <> 0. zcl_tr_3022_gui=>cvt_amt1( EXPORTING iv_in = <fs_upfield> IMPORTING ev_out = <fs_mapfield> EXCEPTIONS err = 1 OTHERS = 2 ). IF sy-subrc <> 0. <fs_mapfield> = <fs_upfield>."日元港元可能需要计算 ENDIF. ENDIF. WHEN OTHERS. <fs_mapfield> = <fs_upfield>. ENDCASE. ENDIF. ENDIF. ADD 1 TO inta. ADD 1 TO intb. ENDWHILE. IF NOT <dyn_wa> IS INITIAL. APPEND <dyn_wa> TO <dyn_table>. CLEAR <dyn_wa>. ENDIF. ENDLOOP. IF e_table[] IS INITIAL. MOVE-CORRESPONDING <dyn_table>[] TO e_table. ELSE. LOOP AT e_table ASSIGNING FIELD-SYMBOL(<fs_map>) . READ TABLE <dyn_table> INTO <dyn_wa> INDEX sy-tabix. IF sy-subrc = 0. MOVE-CORRESPONDING <dyn_wa> TO <fs_map>. ENDIF. ENDLOOP. ENDIF. ENDMETHOD. |