-
Notifications
You must be signed in to change notification settings - Fork 3
Instantiating abaK
In order to get an abaK instance we need two things:
- A format
- A source
A format
is an interpreter which expects the content to provide its data in a specific format. A format
class is responsible for converting the data provided by source
into abaK's internal format. Learn more about formats in Format.
A source represents the actual constants data. It doesn't care how that data is formatted; It is solely concerned about where to get that data from. Learn more about sources in Source.
abaK
offers several ways to create a ZIF_ABAK
instance. They are all done through class ZCL_ABAK_FACTORY
.
Even though the diversity of examples found below may appear complex, the simple scenarios are actually very easy to use. This hidden, optional complexity is there to provide flexibility for the more complex scenarios which require the development of new custom format and/or content classes.
This is the easiest way to instantiate abaK. Just call ZABAK_FACTORY=>GET_ZABAK_INSTANCE()
providing an ID
which exists in table ZABAK
. Example:
o_abak = zcl_abak_factory=>get_zbak_instance( 'GLOBAL' ).
Where GLOBAL
is an existing ID in a record of table ZABAK.
This approach can be used only if using built-in format and content types. It doesn't require any record in table ZABAK
.
Example and example that gets its data from table ZABAK_DEFAULT
:
o_abak = zcl_abak_factory=>get_standard_instance(
i_format_type = 'DB'
i_source_type = 'INLINE' " Optional: 'INLINE' by default
i_content = 'ZABAK_DEFAULT' ).
Here's another example fetching XML data from an URL:
o_abak = zcl_abak_factory=>get_standard_instance(
i_format_type = 'XML'
i_source_type = 'URL'
i_content = 'https://somewhere.com/constants.xml' ).
This is the way to go whenever a custom format or content class need to be used. Because sometimes a format doesn't need a source instance, the IO_SOURCE
parameter is optional.
Example:
DATA: o_format TYPE REF TO zcl_proj1_abak_format_xpto,
o_source TYPE REF TO zcl_abak_source_url.
CREATE OBJECT o_format.
CREATE OBJECT o_source
EXPORTING
i_url = 'https://somewhere.com/legacy_constants.txt'.
o_abak = zcl_abak_factory=>get_custom_instance(
io_format = o_format
io_source = o_source ).
The above example fetches legacy data from an URL using the built-in URL source type and then uses a custom format class which understands the legacy data's format, converting it into abaK's internal format. Once we have both instances O_FORMAT
and O_SOURCE
we can use them to instantiate O_ABAK
.