MM03查看某料号,有特殊字符,看上去是#
SE16N中并没有显示出来这个特殊字符
DeBug时可以看到#,复制出来也是#,但其实不是
ALV中也看不到这个特殊字符
需要写代码,获取这个编码Unicode
参考:【ABAP系列】SAP ABAP 字符编码与解码、Unicode - SAPmatinal - 博客园
DATA:xstr TYPE xstring,l_codepage(4) TYPE n,l_encoding(20),convout TYPE REF TO cl_abap_conv_out_ce, "编码convin TYPE REF TO cl_abap_conv_in_ce,str TYPE string.LOOP AT gt_marc ASSIGNING <fs_marc>.lv_maktx = <fs_marc>-maktx.lv_length = strlen( lv_maktx ).lv_i = 0.DO lv_length TIMES.lv_char = lv_maktx+lv_i(1).lv_i = lv_i + 1.IF lv_i = 20.lv_i = lv_i.ENDIF.convout->write( data = lv_char ). " 编码xstr = convout->get_buffer( ). " 获取码流ENDDO.ENDLOOP.
获取到编码后,又要把这个解析出来,再用正则判断,物料描述中是不是含有这个特殊字符
xstr = '02'.convin = cl_abap_conv_in_ce=>create( encoding = l_encoding input = xstr )."创建解码对象CALL METHOD convin->read IMPORTING data = str."解码lv_char = str .LOOP AT gt_marc ASSIGNING <fs_marc>.PERFORM get_data_matcher USING <fs_marc>-maktx lv_char <fs_marc>-status.ENDLOOP.*&---------------------------------------------------------------------*
*& Form GET_DATA_MATCHER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LV_CHAR1
*&---------------------------------------------------------------------*
FORM get_data_matcher USING p_ls_maktx p_ls_char p_ls_status.DATA:lv_maktx TYPE maktx,lv_char TYPE c,lv_status(4) TYPE c.lv_maktx = p_ls_maktx.lv_char = p_ls_char.lv_status = p_ls_status.IF cl_abap_matcher=>contains(pattern = lv_chartext = lv_maktxignore_case = 'X' ) = abap_true.lv_status = icon_led_red.ENDIF.IF lv_status NE icon_led_red.lv_status = icon_led_green.ENDIF.p_ls_status = lv_status.ENDFORM.
这个特殊字符的错误会导致EXCEL导不出来
另外一个料号也有特殊字符,看上去似乎是#,ALV同样显示不出来,但是却不影响导出EXCEL
该特殊字符可以用这个获取:cl_abap_char_utilities=>newline.