Skip to content

Commit 513c0f8

Browse files
authored
Merge pull request #34 from sbcgua/improvements-2025-07
Improvements 2025 07
2 parents cc261a3 + 1dde635 commit 513c0f8

6 files changed

Lines changed: 117 additions & 3 deletions

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Legend
88
+ : added
99
- : removed
1010

11+
v2.5.1, 2025-?
12+
------------------
13+
+ new parameter skip_lines_starting_with to allow skipping "commented" lines
14+
+ string i_renames now also support `,` delimiter
15+
1116
v2.5.0, 2025-06-10
1217
------------------
1318
! BREAKING: move types to zif_text2tab interface #27

docsite/docs/03-parsing-options.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ zcl_text2tab_parser=>create( lt_container )->parse(
3535
* JOHN 02.02.1995
3636
```
3737

38-
Renames can be also passed as a string in this format: `'field_to_rename:new_name;another_field:another_new_name'`. Coding convenience is important ;)
38+
Renames can be also passed as a string in this format: `'field_to_rename:new_name, another_field:another_new_name'`. `;` and `,` are supported as separators. Coding convenience is important ;)
3939

4040
```abap
4141
zcl_text2tab_parser=>create( lt_container )->parse(
@@ -134,7 +134,9 @@ JOHN 01.01.1990
134134
Now we should call the factory method like this and the first line is interpreted as a comment:
135135

136136
```abap
137-
zcl_text2tab_parser=>create( i_pattern = ls_birthday i_begin_comment = '*' ).
137+
zcl_text2tab_parser=>create(
138+
i_pattern = ls_birthday
139+
i_begin_comment = '*' ).
138140
```
139141

140142
The char '*' must have the first position in the text line. Otherwise it isn't interpreted as a comment.
@@ -146,3 +148,22 @@ Name Date of birth <<< containes spaces
146148
NAME BIRTHDAY
147149
JOHN 01.01.1990
148150
```
151+
152+
### Within-data comments
153+
154+
Also the data can contain commented lines. They can be skipped if started with a char passed with `i_skip_lines_starting_with` param. This can be useful for human-friendly data grouping.
155+
156+
```abap
157+
zcl_text2tab_parser=>create(
158+
i_pattern = ls_birthday
159+
i_skip_lines_starting_with = '#' ).
160+
```
161+
162+
```text
163+
NAME BIRTHDAY
164+
# Managers <<< will be ignored
165+
John 01.01.1990
166+
# Employees <<< will be ignored
167+
Anna 01.01.1990
168+
```
169+

src/core/zcl_text2tab_parser.clas.abap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class zcl_text2tab_parser definition
2020
!i_amount_format type zif_text2tab=>ty_amount_format optional
2121
!i_date_format type zif_text2tab=>ty_date_format optional
2222
!i_begin_comment type zif_text2tab=>ty_begin_comment optional
23+
!i_skip_lines_starting_with type zif_text2tab=>ty_begin_comment optional
2324
!i_deep_provider type ref to zif_text2tab_deep_provider optional
2425
returning
2526
value(ro_parser) type ref to zcl_text2tab_parser
@@ -60,6 +61,7 @@ class zcl_text2tab_parser definition
6061
data mv_line_index type i.
6162
data mv_is_typeless type abap_bool.
6263
data mv_begin_comment type zif_text2tab=>ty_begin_comment.
64+
data mv_skip_lines_starting_with type zif_text2tab=>ty_begin_comment.
6365
data mt_ignore_exits type sorted table of abap_editmask with unique key table_line.
6466

6567
data mt_components type zif_text2tab=>tt_comp_descr.
@@ -244,6 +246,7 @@ CLASS ZCL_TEXT2TAB_PARSER IMPLEMENTATION.
244246
endif.
245247

246248
ro_parser->mv_begin_comment = i_begin_comment.
249+
ro_parser->mv_skip_lines_starting_with = i_skip_lines_starting_with.
247250

248251
endmethod.
249252

@@ -418,6 +421,10 @@ CLASS ZCL_TEXT2TAB_PARSER IMPLEMENTATION.
418421
raise_error( i_msg = 'Empty line cannot be parsed' i_code = 'LE' ). "#EC NOTEXT
419422
endif.
420423

424+
if mv_skip_lines_starting_with is not initial and <dataline>+0(1) = mv_skip_lines_starting_with.
425+
continue. " Skip comment lines
426+
endif.
427+
421428
parse_line(
422429
exporting
423430
i_dataline = <dataline>

src/core/zcl_text2tab_parser.clas.testclasses.abap

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class ltcl_text2tab_parser_test definition for testing
101101
methods deep_structures for testing.
102102
methods parse_corresponding for testing raising zcx_text2tab_error.
103103

104+
methods begin_comments for testing raising zcx_text2tab_error.
105+
methods line_comments for testing raising zcx_text2tab_error.
104106

105107
* ==== HELPERS ===
106108

@@ -1655,4 +1657,69 @@ class ltcl_text2tab_parser_test implementation.
16551657

16561658
endmethod.
16571659

1660+
method begin_comments.
1661+
1662+
data lv_text_orig type string.
1663+
data lt_exp type tt_dummy.
1664+
data lt_act like lt_exp.
1665+
1666+
get_dummy_data(
1667+
importing
1668+
e_dummy_tab = lt_exp
1669+
e_dummy_string = lv_text_orig ).
1670+
1671+
zcl_text2tab_parser=>create(
1672+
i_pattern = lt_act
1673+
i_begin_comment = '#'
1674+
)->parse(
1675+
exporting
1676+
i_data = |#comment{ c_crlf }{ lv_text_orig }|
1677+
importing
1678+
e_container = lt_act ).
1679+
1680+
cl_abap_unit_assert=>assert_equals(
1681+
act = lt_act
1682+
exp = lt_exp ).
1683+
1684+
zcl_text2tab_parser=>create(
1685+
i_pattern = lt_act
1686+
i_begin_comment = zif_text2tab=>c_auto_detect_by_space
1687+
)->parse(
1688+
exporting
1689+
i_data = |field descr with space\tanother one...{ c_crlf }{ lv_text_orig }|
1690+
importing
1691+
e_container = lt_act ).
1692+
1693+
cl_abap_unit_assert=>assert_equals(
1694+
act = lt_act
1695+
exp = lt_exp ).
1696+
1697+
endmethod.
1698+
1699+
method line_comments.
1700+
1701+
data lv_text_orig type string.
1702+
data lt_exp type tt_dummy.
1703+
data lt_act like lt_exp.
1704+
1705+
get_dummy_data(
1706+
importing
1707+
e_dummy_tab = lt_exp
1708+
e_dummy_string = lv_text_orig ).
1709+
1710+
zcl_text2tab_parser=>create(
1711+
i_pattern = lt_act
1712+
i_skip_lines_starting_with = '#'
1713+
)->parse(
1714+
exporting
1715+
i_data = |{ lv_text_orig }#comment| " CRLF is already at the end, no need to add
1716+
importing
1717+
e_container = lt_act ).
1718+
1719+
cl_abap_unit_assert=>assert_equals(
1720+
act = lt_act
1721+
exp = lt_exp ).
1722+
1723+
endmethod.
1724+
16581725
endclass.

src/core/zcl_text2tab_utils.clas.abap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ CLASS ZCL_TEXT2TAB_UTILS IMPLEMENTATION.
171171
elseif lo_type->type_kind = cl_abap_typedescr=>typekind_char or lo_type->type_kind = cl_abap_typedescr=>typekind_string.
172172
data lt_renames type string_table.
173173
field-symbols <str> type string.
174-
split i_rename_fields at ';' into table lt_renames.
174+
if find( val = i_rename_fields sub = ',' ) >= 0.
175+
split i_rename_fields at ',' into table lt_renames. " TODO maybe make comma the only separator
176+
else.
177+
split i_rename_fields at ';' into table lt_renames.
178+
endif.
175179
delete lt_renames where table_line is initial.
176180
loop at lt_renames assigning <str>.
177181
clear ls_rename.

src/core/zcl_text2tab_utils.clas.testclasses.abap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ class ltcl_text2tab_utils_test implementation.
9393
endtry.
9494
cl_abap_unit_assert=>assert_equals( act = lt_map_act exp = lt_map_exp ).
9595

96+
" with comma
97+
lv_fields = 'some_field:tstring,some_field2:tstring2,,'.
98+
99+
try.
100+
lt_map_act = zcl_text2tab_utils=>build_rename_map( lv_fields ).
101+
catch zcx_text2tab_error into lx.
102+
cl_abap_unit_assert=>fail( lx->get_text( ) ).
103+
endtry.
104+
cl_abap_unit_assert=>assert_equals( act = lt_map_act exp = lt_map_exp ).
105+
96106
endmethod.
97107

98108
method break_to_lines.

0 commit comments

Comments
 (0)