8000 GitHub - sbcgua/text2tab: TAB-delimited text parser for ABAP
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sbcgua/text2tab

Repository files navigation

ABAP text2tab parser and serializer (ex. Abap data parser)

abaplint Version

TAB-delimited text parser and serializer for ABAP

Synopsis

Text2tab is an utility to parse TAB-delimited text into an internal table of an arbitrary flat structure.

  • supports "non-strict" mode which allows to skip fields in the source data (for the case when only certain fields are being loaded).
  • supports "header" specification as the first line in the text - in this case field order in the text may differ from the internal abap structure field order.
  • supports loading into a structure (the first data line of the text is parsed).
  • supports type-less parsing, when the data is not checked against existing structure but dynamically create as a table with string fields.
  • supports specifying date and amount formats
  • supports on-the-fly field name remapping (e.g. field FOO in the parsed text move to BAR component of the target internal table)
  • supports "deep" parsing - filling structure or table components in the target data container
  • supports "corresponding" parsing - filling only those fields which are in target structure. Kind of opposite to "non-strict" feature above.

And vice versa - serialize flat table or structure to text.

  • support specifying date and amount formats, and line-break symbol

The package also contains 2 examples (see examples sub-package):

  • ZTEXT2TAB_EXAMPLE - simple parsing code
  • ZTEXT2TAB_BACKUP_EXAMPLE - example of DB table backup with serializer

Documentation

Please find the complete documentation at our github pages site. The documentation includes infromation about installation, examples of usages and library API.

Example of usage

Source text file (CRLF as a line delimiter, TAB as a field delimiter)

NAME     BIRTHDATE
Alex     01.01.1990
John     02.02.1995
Lara     03.03.2000

Simple parsing code

types:
  begin of my_table_type,
    name      type char10,
    birthdate type datum,
  end of my_table_type.

data lt_container type my_table_type.

zcl_text2tab_parser=>create( lt_container )->parse(
  exporting
    i_data      = my_get_some_raw_text_data( )
  importing
    e_container = lt_container ).

... or a more complex one ...

types:
  begin of my_table_type,
    name      type char10,
    city      type char40, " <<< New field, but the text still contains just 2 !
    birthdate type datum,
  end of my_table_type.

...

zcl_text2tab_parser=>create(
    i_pattern       = lt_container   " table or structure
    i_amount_format = ' .'           " specify thousand and decimal delimiters
  )->parse( 
    exporting 
      i_data      = my_get_some_raw_text_data( )
      i_strict    = abap_false       " text may contain not all fields (city field will be skipped)
      i_has_head  = abap_true        " headers in the first line of the text
    importing 
      e_container = lt_container ).  " table or structure (first data line from text)

License

The code is licensed under MIT License. Please see the LICENSE for details.

About

TAB-delimited text parser for ABAP

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

0