Code: Alles auswählen.
*----------------------------------------------------------------------*
* CREATE CSV FILE
*----------------------------------------------------------------------*
gv_filename = 'data_payroll.csv'.
gv_line = 'employee_no;last_name;first_name;labor_prod_time;payed_overtime;time_unit;average_wage;additional_wage;wage_amount;currency'.
CONCATENATE gv_line cl_abap_char_utilities=>cr_lf INTO gv_line.
gs_csv = gv_line.
APPEND gs_csv TO gt_csv.
LOOP AT gt_out INTO gs_out.
...
CONCATENATE gs_out-employee_no_clean gs_out-last_name gs_out-first_name gv_labor_prod_time gv_payed_overtime gs_out-unit gv_wage_rate gv_additional_wage gv_wage_amount gs_wage-currency
INTO gv_line SEPARATED BY ';'.
CONCATENATE gv_line cl_abap_char_utilities=>cr_lf INTO gv_line.
gs_csv = gv_line.
APPEND gs_csv TO gt_csv.
ENDLOOP.
OPEN DATASET gv_filename FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
IF sy-subrc = 0.
LOOP AT gt_csv INTO gs_csv.
TRANSFER gs_csv TO gv_filename.
ENDLOOP.
CLOSE DATASET gv_filename.
ENDIF.
OPEN DATASET gv_filename FOR INPUT IN TEXT MODE ENCODING UTF-8.
IF sy-subrc = 0.
DO.
READ DATASET gv_filename INTO gs_csv.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND gs_csv TO gt_attachment.
ENDDO.
CLOSE DATASET gv_filename.
ENDIF.
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZFPF_TEST041
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zfpf_test041.
types:
wage type c length 5,
id type c length 4,
begin of t_empl_data,
id type id,
last_name type string,
first_name type string,
prod_time type time,
payed_overtime type time,
unit type string,
wage_rate type wage,
additional_wage type wage,
wage_amount type wage,
currency type curcy,
end of t_empl_data.
data:
file_name type string,
csv_line type string,
empl_data type table of t_empl_data,
empl_data_line like line of empl_data,
csv_out type table of string,
csv_out_line like line of csv_out.
empl_data = value #(
( id = '4711' last_name = 'A' first_name = '1' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4712' last_name = 'B' first_name = '2' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4713' last_name = 'C' first_name = '3' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4714' last_name = 'D' first_name = '4' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4715' last_name = 'E' first_name = '5' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4716' last_name = 'F' first_name = '6' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4717' last_name = 'G' first_name = '7' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4718' last_name = 'H' first_name = '8' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4719' last_name = 'I' first_name = '9' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
( id = '4720' last_name = 'J' first_name = '0' prod_time = '080000' payed_overtime = '000300' unit = 'CO' wage_rate = 13 additional_wage = 37 wage_amount = 42 currency = 'EUR' )
).
data:
dummy type string.
dummy = sy-host.
file_name = '\\XXX\sap\ED0\LO\data_payroll.csv'. " XXX ist in dem Fall der Root-Pfad des SAP Systems
csv_line = 'id;last_name;first_name;prod_time;payed_overtime;unit;wage_rate;additional_wage;wage_amount;currency'.
concatenate csv_line cl_abap_char_utilities=>cr_lf into csv_line.
csv_out_line = csv_line.
append csv_out_line to csv_out.
loop at empl_data into empl_data_line.
" ...
concatenate
empl_data_line-id
empl_data_line-last_name
empl_data_line-first_name
empl_data_line-prod_time
empl_data_line-payed_overtime
empl_data_line-unit
empl_data_line-wage_rate
empl_data_line-wage_amount
empl_data_line-currency
into
csv_line
separated by
';'.
concatenate
csv_line
cl_abap_char_utilities=>cr_lf
into
csv_out_line.
append csv_out_line to csv_out.
endloop.
open dataset file_name for output in text mode encoding utf-8.
if ( sy-subrc = 0 ).
loop at csv_out into csv_out_line.
transfer csv_out_line to file_name.
endloop.
close dataset file_name.
endif.
Folgende Benutzer bedankten sich beim Autor Radinator für den Beitrag:
Julia.hrtm
Danke für die Antwort. :)
Code: Alles auswählen.
OPEN DATASET gv_filename FOR INPUT IN TEXT MODE ENCODING UTF-8.
IF sy-subrc = 0.
DO.
READ DATASET gv_filename INTO gs_csv.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF gs_csv IS NOT INITIAL.
APPEND gs_csv TO gt_attachment.
ENDIF.
ENDDO.
CLOSE DATASET gv_filename.
ENDIF.