itab to file with separated by coma, semicolon, etc

data: struct type ref to cl_abap_structdescr,
ls_component type abap_compdescr.
lt_tab  type truxs_t_text_data with header line,
ls_tab(4096),
lv_tab       type string.
lv_text      type c length 255.
field-symbols: <lfs_file>  type any.
loop at lt_itab.
clear: lt_tab,
lv_tab.
loop at struct->components into ls_component.
read table gt_fieldcat into gs_fcat with key fieldname = ls_component-name.
check sy-subrc eq 0.
ASSIGN COMPONENT ls_component-name OF STRUCTURE lt_itab TO <lfs_file>.
check sy-subrc eq 0.
case gs_fcat-datatype.
when 'DATS'.
write <lfs_file> to lv_text MM/DD/YYYY.
when 'QUAN' or 'CURR'.
write <lfs_file> to lv_text.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = lv_text.
when 'INT4'.
write <lfs_file> to lv_text DECIMALS 0.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = lv_text.
when others.
write <lfs_file> to lv_text.
endcase.
condense lv_text.
concatenate lt_tab lv_text into lt_tab
separated by lv_tab.
lv_tab = ';'.    "separator
endloop.
append lt_tab.
endloop.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.