2

我有一个内部表,它被写入文件,然后作为数据源拉入 BW。有时,不可打印的字符会进入文件输出并将导入过程中断到 BW。下面是我的代码示例。由于 itab 不是类型 c 或字符串,我无法在其上使用查找/替换正则表达式。以前有没有其他人必须解决此类问题?

    FORM eliminate_non_print_char TABLES p_shiptab STRUCTURE shiptab.     

  LOOP AT p_shiptab INTO wa_shiptab.

    FIND REGEX '[^[:print:]]+(?!$)'
      IN wa_shiptab
    IGNORING CASE.
    "RESULTS result.
    IF  sy-subrc = 0.

     REPLACE REGEX '[^[:print:]]+(?!$)'
        IN wa_shiptab WITH ''
     IGNORING CASE.

    ENDIF.
  ENDLOOP.

DATA: BEGIN OF shiptab OCCURS 2000.
        INCLUDE STRUCTURE ship1.
        INCLUDE STRUCTURE ship2.
DATA: landtx            LIKE vbrk-landtx,
      bl_konwa          LIKE vbak-waerk.                    
        INCLUDE STRUCTURE ship3.
        INCLUDE STRUCTURE ship4.
DATA: frght_amnt_usd    LIKE konv-kwert,                    
      revenue_amnt_usd  LIKE vbap-netwr,                    
      unit_price_usd    LIKE vbap-netpr,                    
      pgi_posting_date  LIKE mkpf-budat,                    
      ord_line_item_qty LIKE lips-lfimg,                    
      asm_no            LIKE kna1-kunnr,
      asm_username      LIKE adrc-sort1,
      va_augru_t        LIKE tvaut-bezei,         
      ship_to_name      LIKE adrc-name1,
      bill_to_name      LIKE adrc-name1,
      forward_to_name   LIKE adrc-name1,
      fmv_amnt           LIKE konv-kbetr,    
      va_butxt           LIKE t001-butxt,    
      sold_to_search_term LIKE adrc-sort1,   
      bill_to_search_term LIKE adrc-sort1,  
      va_prctr           LIKE vbap-prctr,    
      va_bezei           LIKE tvrot-bezei.   
        INCLUDE STRUCTURE zorder_attr.         
DATA: extended_bits_count(20),              
      va_bstkd_hdr LIKE char32.            
DATA: gsm_bp_katr6      LIKE kna1-katr6,    
      gsm_bp_vtext6     LIKE tvk6t-vtext,   
      asm_ze_katr7      LIKE kna1-katr7,    
      asm_ze_vtext7     LIKE tvk7t-vtext,   
      gsm_ze_katr6      LIKE kna1-katr6,    
      gsm_ze_vtext6     LIKE tvk7t-vtext.
DATA:  END OF shiptab

.

我得到的错误是:“WA_SHIPTAB”必须是字符类型的数据对象(数据类型 C、N、D、T 或 STRING)。我在 itab shiptab 中有非字符类型。我知道我可以单独对每个字段进行此查找,但 itab 有 235 个字段,这似乎效率不高。

4

2 回答 2

2

该程序有另一个主 itab 副本,它是基于 char 的字段,我循环通过它并放置以下代码:

REPLACE ALL OCCURRENCES OF REGEX '[^[:print:]]+$'
  IN transtab WITH ''
  IGNORING CASE.

答案链接:

SCN 链接

帮助.SAP 链接

于 2013-06-10T17:01:09.780 回答
1

您可以使用运行时类型服务循环遍历表中每个字段的定义,以确定哪些与 REGEX 操作类型兼容。然后,您可以使用动态分配来仅处理那些兼容的字段,一次一个。例如:

" Initalize Range of typekinds that are compatable with REGEX. See constant 
" attributes of CL_ABAP_DATADESCR for typekind definitions. You'll have to
" define these explicitly
lr_typekind_regex = <...>. 

" Get components of table structure
lo_tabdescr = cl_abap_typedescr=>describe_by_data( p_shiptab ).
lo_strdescr = lo_tabdescr->get_table_ine_type( ).
li_comp = lo_structdescr->get_components( ).

" Loop through table, sanitizing regex-compatable fields in each row
LOOP AT p_shiptab ASSIGNING <la_shiptab>.
  LOOP AT li_comp INTO la_comp.
    CHECK la_comp-type->type_kind IN lr_typekind_regex.

    " Call subroutine containing Regex to remove non-printable chars from field        
    ASSIGN COMPONENT la_comp-name OF STRUCTURE <la_shiptab> TO <l_charvalue>.
    PERFORM sanitize_field CHANGING <l_charvalue>. 

  ENDLOOP.
ENDLOOP.
于 2013-05-22T15:23:49.527 回答