You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you call the `read` method of a *reader* instance,
34
+
`csv_data` can be:
35
+
- a string
36
+
- a table of strings
37
+
- a table with one-component table line
38
+
39
+
`tab_data` must be a *flat* table: a table whose table line is a structure, whose components are simple elements.
40
+
41
+
Sometimes you need to read a CSV but you don't know a priori how many and which columns it contains. In these cases you still have two ways to read it:
42
+
43
+
- you can get a reference variable to a table whose fields (of type string) are named F1, F2, ..., FN and so on;
- or you can get a transposed version of the CSV, that is, a table with two fields: the row index and a table containing the list of its values, for each column.
:office_worker:**Can I decide which character to use as delimiter, quotechar, and line terminator? And what about escaping special characters?**
23
84
24
85
:mage: Once instantiated you can configure the csv management object:
25
-
-``csv_man->delimiter( `;` ).``*fields delimiter, default is comma:*`,`*. Here "delimiter" is a synonym of "separator".*
26
-
-``csv_man->quotechar( `"` ).``*to quote fields, default is none.*
86
+
-``csv_man->delimiter( `;` ).``*fields delimiter, default is semicolon:*`;`*. Here "delimiter" is a synonym of "separator".*
87
+
-``csv_man->quotechar( `"` ).``*to quote fields, default is none.
27
88
-``csv_man->end_of_line( `|` ).``*line-terminator char, default is Carriage Return and Line Feed*`%_CR_LF`*.*
28
89
-``csv_man->escapechar( `/` ).``*to escape special characters, both in read and write mode.*
29
90
-``csv_man->doublequote( abap_true ).``*to escape a quotechar character with a quotechar character.*
30
91
-`csv_man->quoting( ztbox_cl_csvman=>c_quote_minimal ).`*to restrict quoting application, with these options:*
31
-
-`ztbox_cl_csvman=>c_quote_all`*to apply quotechar character to all fields (this is default behaviour if a quotechar is set);*
32
-
-`ztbox_cl_csvman=>c_quote_minimal`*to apply quotechar character only to fields containing special characters;*
33
-
-`ztbox_cl_csvman=>c_quote_nonnumeric`*to apply quotechar character only to non-numeric fields;*
34
-
-`ztbox_cl_csvman=>c_quote_none`*to never quote fields (this is the default behaviour if no quotechar is set).*
35
-
-`csv_man->header( abap_true ).`*to write/expect an header line in write/read mode.*
36
-
-`csv_man->header_desc( abap_true ).`*to use long label description (from data element, in the log-on language) as header text field. If the field is not typed with a dictionary data element its name is still used as description.*
37
-
-`csv_man->ingore_rows( int_range ).`*in read mode, ignore rows whose index is into parameter (it's a range of int)*
92
+
-`zcl_tbox_csv_writer=>c_quote_all`*to apply quotechar character to all fields (this is default behaviour if a quotechar is set);*
93
+
-`zcl_tbox_csv_writer=>c_quote_minimal`*to apply quotechar character only to fields containing special characters;*
94
+
-`zcl_tbox_csv_writer=>c_quote_nonnumeric`*to apply quotechar character only to non-numeric fields;*
95
+
-`zcl_tbox_csv_writer=>c_quote_none`*to never quote fields (this is the default behaviour if no quotechar is set).*
96
+
-`csv_man->header( abap_true ).`*to write/expect an header line in write/read mode. Default is*`abap_true`*.*
97
+
-`csv_man->header_desc( abap_true ).`*to use field name as header text field. You can column text by calling*`->label( )`*method on fields level, see below for details.*
38
98
39
99
## Output Format
40
100
:office_worker:**Nice, but I want also control fields output format, especially for date/time/numeric fields.**
-``csv_man->country( `US` ).``*to output date, time and numbers according to a country rules (less specific than previous methods).*
50
110
-`csv_man->decimals( 3 ).`*to write numerical fields with the specified decimals precision.*
51
-
-`csv_man->convexit( abap_true ).`*to apply domain conversion exit, internal-to-external in write mode, external-to-internal in read mode. Default is*`abap_true`.
52
-
-`csv_man->condense( abap_true ).`*to remove leading and trailing spaces. Default is*`abap_false`.
53
-
-`csv_man->keep_init( abap_true ).`*to maintain initial values: if set to*`abap_false`*a numerical field containing only 0, as well as an initial date or initial time, became blank in write mode. Default is*`abap_true`.
111
+
-`csv_man->condense_values( ).`*to remove leading and trailing spaces. Default is*`abap_false`.
112
+
-`csv_man->keep_init( ).`*to maintain initial values: if set to*`abap_false`*a numerical field containing only 0, as well as an initial date or initial time, became blank in write mode. Default is*`abap_true`.
54
113
-`csv_man->alignment( cl_abap_format=>a_right ).`*to align fields content according to the following options:*
55
114
-`cl_abap_format=>a_left`*to justify text on the left (default option);*
56
115
-`cl_abap_format=>a_right`*to justify text on the right.*
You can also exclude some fields from the CSV generation/reading process using `exclude( abap_true )` method:
126
+
You can also exclude some fields from the CSV generation/reading process using `exclude( )` method:
68
127
69
128
```abap
70
-
csv_man->field( `MANDT` )->exclude( abap_true ).
129
+
csv_man->field( `MANDT` )->exclude( ).
71
130
```
72
131
73
-
Viceversa, if you work with a table having too many fields, you can generate or reading a CSV considering only a small subset of fields using `include( abap_true )` method. Once you have called `include` for a field, only fields for which `include` has been called will be considered.
132
+
Viceversa, if you work with a table having too many fields, you can generate or reading a CSV considering only a small subset of fields using `include( )` method. Once you have called `include` for a field, only fields for which `include` has been called will be considered.
74
133
75
134
```abap
76
-
csv_man->field( `MATNR` )->include( abap_true ).
77
-
csv_man->field( `WERKS` )->include( abap_true ).
135
+
csv_man->field( `MATNR` )->include( ).
136
+
csv_man->field( `WERKS` )->include( ).
78
137
```
79
138
80
139
If the order of the fields in the table does not match the columns in the CSV to generate or read, you can map each field with the corresponding csv-column position:
@@ -129,7 +188,7 @@ And the `get_validation_fails( )` output is this table:
129
188
You can add also custom validation checks: it must be an instance method with the following signature
130
189
131
190
```abap
132
-
METHODS sample_check IMPORTING value TYPE string RETURNING VALUE(fail) TYPE flag.
191
+
METHODS sample_check IMPORTING i_value TYPE string RETURNING VALUE(r_fail) TYPE flag.
133
192
```
134
193
If, e.g., an object `sample_object` implements method `sample_check`, you can add this check to a field:
135
194
@@ -145,7 +204,5 @@ in two ways: as a *pre validation* by calling method `add_pre_validation( )`, an
145
204
146
205
`fail = abap_true` means the check has not been passed.
147
206
148
-
There are also two global defualt validations: a check verifying that CSV has the same number of fields for each row and a check for empty rows. These checks are applied only calling `check_csv( csv_tab )` method, where `csv_tab` is the CSV file as a table of strings.
149
-
150
207
## Installation
151
208
Install this project using [abapGit](https://abapgit.org/)
0 commit comments