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 " 
           endif.
        else.
          CONTINUE.
        endif.
    lv_counter = lv_counter + 1.
   ENDDO.
 ENDLOOP.

 

Randa Khaled

Randa Khaled

Author Since: November 19, 2020

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x