Skip to Content
Technical Articles
Author's profile photo Jigang Zhang 张吉刚

dynamic remove all special characters at internal table

Many description fields maintain by the user could contain special characters like double quotes and a vertical line, which will lead to mismatched columns like at generated Excel file or spool result list. Here create a small routine to replace all those kinds of characters for all fields at one internal table.


  FIELD-SYMBOLS: <wa_table> TYPE any,
                 <field> TYPE any.
  DATA:lv_counter TYPE I,   "countner
       ld_fieldtype   TYPE CHAR01, "field type
       lv_field_num type I. "num of fields

check gt_output[] is not INITIAL.

*Get number of fields for Input table
read TABLE gt_output ASSIGNING <wa_table> INDEX 1.
DATA(lo_descr) = CAST cl_abap_structdescr(
     cl_abap_datadescr=>describe_by_data( <wa_table> ) ).

  lv_field_num = LINES( lo_descr->components ).

 loop at gt_output ASSIGNING <wa_table>.
   lv_counter = 1.
   DO lv_field_num TIMES.
*   loop every fields of internal table
         ASSIGN COMPONENT lv_counter
          OF STRUCTURE <wa_table> TO <field>.
        if sy-subrc eq 0.
           DESCRIBE field <field> TYPE ld_fieldtype.
           "only replace Character type, could dump like for P type field with replace
           IF  ld_fieldtype = 'C'.
            REPLACE ALL OCCURRENCES OF '"' in <field> with space.
           "here only replace the double quotes " 
    lv_counter = lv_counter + 1.


Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.