├── .gitignore
├── LICENSE.md
├── README.md
├── collections
├── zcl_abstractcollection.abap
├── zcl_abstractlist.abap
├── zcl_abstractlist.local.imp.abap
├── zcl_arraylist.abap
├── zcl_collections.abap
├── zcl_collections.local.imp.abap
├── zcx_concurrmodification.abap
├── zcx_nosuchelement.abap
├── zif_collection.abap
├── zif_iterator.abap
├── zif_list.abap
└── zif_listiterator.abap
├── csv
├── csv.messageclass.txt
├── zcl_csv_parser.abap
├── zcx_csv_parse_error.abap
└── zif_csv_parser_delegate.abap
├── json
├── json.messageclass.txt
├── zcl_json_array.abap
├── zcl_json_boolean.abap
├── zcl_json_null.abap
├── zcl_json_number.abap
├── zcl_json_object.abap
├── zcl_json_pair.abap
├── zcl_json_parser.abap
├── zcl_json_string.abap
├── zcl_json_types.abap
├── zcl_json_util.abap
├── zcx_json_parse_error.abap
└── zif_json_value.abap
├── lang
├── zcl_bitwise.abap
├── zcl_object.abap
├── zcl_string_distance.abap
├── zcx_clonenotsupported.abap
├── zcx_illegalargument.abap
├── zcx_illegalstate.abap
├── zcx_indexoutofbounds.abap
├── zcx_runtimeexception.abap
├── zcx_staticexception.abap
└── zcx_unsupportedoperation.abap
├── local
└── Z_LOCAL_JSON_UTIL.txt
├── logging
├── log.messageclass.txt
├── zcl_log_viewer.abap
├── zcl_logger.abap
├── zcl_logger_factory.abap
├── zcl_logging_repo_http.abap
├── zcl_logging_repository.abap
├── zcl_logging_resource.abap
├── zcx_logging_error.abap
└── zif_logging_repository.abap
├── rest
├── rest.messageclass.txt
├── zcl_dispatcher.abap
├── zcl_http_header_fields.abap
├── zcl_http_methods.abap
├── zcl_http_mime_types.abap
├── zcl_http_status_codes.abap
├── zcl_request.abap
├── zcl_resource.abap
├── zcl_response.abap
├── zcx_resource_exception.abap
├── zcx_text_conversion_error.abap
├── zcx_uri_too_long.abap
└── zrestlog.abap
├── unittest
├── zcl_ut_arraylist.abap
└── zcl_ut_json_util.abap
└── xml
├── zcl_xmlparser.abap
├── zcx_invalid_xml.abap
└── zif_xmlparser_delegate.abap
/.gitignore:
--------------------------------------------------------------------------------
1 | # osx noise
2 | .DS_Store
3 | profile
4 |
5 | # xcode noise
6 | build/*
7 | *.mode1
8 | *.mode1v3
9 | *.mode2v3
10 | *.perspective
11 | *.perspectivev3
12 | *.pbxuser
13 | *.xcworkspace
14 | xcuserdata
15 |
16 | # svn & cvs
17 | .svn
18 | CVS
19 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2013 René van Mil
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining
5 | a copy of this software and associated documentation files (the
6 | "Software"), to deal in the Software without restriction, including
7 | without limitation the rights to use, copy, modify, merge, publish,
8 | distribute, sublicense, and/or sell copies of the Software, and to
9 | permit persons to whom the Software is furnished to do so, subject to
10 | the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ABAP Object-oriented programming Library
2 |
3 | ## Installation
4 |
5 | - Manually create the dictionary types listed below
6 | - Use the source based class editor and regular editor to import all classes, interfaces and programs.
7 | - Some packages use a message class. The messages are saved in the .messageclass.txt files. Create the message class manually and copy/paste the messages inside it.
8 |
9 | ## Dictionary Types
10 |
11 | ### Table type 'zarray'
12 |
13 | Standard table with no keys.
14 | Line type: reference to zcl_object
15 |
16 | ### Data type 'zresourceclass'
17 |
18 | Domain: SEOCLSNAME
19 |
20 | ### Data type 'zresourcename'
21 |
22 | Built-in type: CHAR 30
23 |
24 | ### Data type 'zresourcepath'
25 |
26 | Built-in type: CHAR 255
27 |
28 | ### Domain 'zlog_requests'
29 |
30 | Built-in type: CHAR 1
31 |
32 | Values: ' ' No
33 | 'X' Yes
34 |
35 | ### Data type 'zlog_requests'
36 |
37 | Domain: zlog_requests
38 |
39 | ### Database table 'zresources'
40 |
41 | Type: customizing
42 | Buffer: full
43 |
44 | Field Key Type
45 | MANDT X MANDT
46 | NAME X ZRESOURCENAME
47 | CLASS ZRESOURCECLASS
48 | PATH ZRESOURCEPATH
49 | LOG_REQUESTS ZLOG_REQUESTS
50 |
51 | ### Database table 'zrestlog'
52 |
53 | Type: application
54 | Buffer: none
55 |
56 | Field Key Type
57 | MANDT X MANDT
58 | UUID X SYSUUID_C32
59 | REQUESTDATE X DATUM
60 | REQUESTTIME X UZEIT
61 | REQUESTUSER X UNAME
62 | RESOURCEPATH ZRESOURCEPATH
63 | RESOURCENAME ZRESOURCENAME
64 | RESOURCEID STRING
65 | REQUEST STRING
66 |
67 |
--------------------------------------------------------------------------------
/collections/zcl_abstractcollection.abap:
--------------------------------------------------------------------------------
1 | class ZCL_ABSTRACTCOLLECTION definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | abstract
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_ABSTRACTCOLLECTION
10 | *"* do not include other source files here!!!
11 | interfaces ZIF_COLLECTION
12 | abstract methods ITERATOR
13 | SIZE .
14 |
15 | aliases ADD
16 | for ZIF_COLLECTION~ADD .
17 | aliases ADDALL
18 | for ZIF_COLLECTION~ADDALL .
19 | aliases CLEAR
20 | for ZIF_COLLECTION~CLEAR .
21 | aliases CONTAINS
22 | for ZIF_COLLECTION~CONTAINS .
23 | aliases CONTAINSALL
24 | for ZIF_COLLECTION~CONTAINSALL .
25 | aliases ISEMPTY
26 | for ZIF_COLLECTION~ISEMPTY .
27 | aliases ITERATOR
28 | for ZIF_COLLECTION~ITERATOR .
29 | aliases REMOVE
30 | for ZIF_COLLECTION~REMOVE .
31 | aliases REMOVEALL
32 | for ZIF_COLLECTION~REMOVEALL .
33 | aliases RETAINALL
34 | for ZIF_COLLECTION~RETAINALL .
35 | aliases SIZE
36 | for ZIF_COLLECTION~SIZE .
37 | aliases TOARRAY
38 | for ZIF_COLLECTION~TOARRAY .
39 | protected section.
40 | *"* protected components of class zCL_ABSTRACTCOLLECTION
41 | *"* do not include other source files here!!!
42 | private section.
43 | *"* private components of class zCL_ABSTRACTCOLLECTION
44 | *"* do not include other source files here!!!
45 | ENDCLASS.
46 |
47 |
48 |
49 | CLASS ZCL_ABSTRACTCOLLECTION IMPLEMENTATION.
50 |
51 |
52 | * ---------------------------------------------------------------------------------------+
53 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~ADD
54 | * +-------------------------------------------------------------------------------------------------+
55 | * | [--->] ELEMENT TYPE REF TO ZCL_OBJECT
56 | * | [<-()] RETURNING TYPE ABAP_BOOL
57 | * +--------------------------------------------------------------------------------------
58 | method zif_collection~add.
59 | raise exception type zcx_unsupportedoperation.
60 | endmethod.
61 |
62 |
63 | * ---------------------------------------------------------------------------------------+
64 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~ADDALL
65 | * +-------------------------------------------------------------------------------------------------+
66 | * | [--->] COLLECTION TYPE REF TO ZIF_COLLECTION
67 | * | [<-()] RETURNING TYPE ABAP_BOOL
68 | * +--------------------------------------------------------------------------------------
69 | method zif_collection~addall.
70 | data modified type abap_bool.
71 | modified = abap_false.
72 | data iterator type ref to zif_iterator.
73 | iterator = collection->iterator( ).
74 | while iterator->hasnext( ) = abap_true.
75 | data next type ref to zcl_object.
76 | next = iterator->next( ).
77 | if me->add( next ) = abap_true.
78 | modified = abap_true.
79 | endif.
80 | endwhile.
81 | returning = modified.
82 | endmethod.
83 |
84 |
85 | * ---------------------------------------------------------------------------------------+
86 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~CLEAR
87 | * +-------------------------------------------------------------------------------------------------+
88 | * +--------------------------------------------------------------------------------------
89 | method zif_collection~clear.
90 | data iterator type ref to zif_iterator.
91 | iterator = me->iterator( ).
92 | while iterator->hasnext( ) = abap_true.
93 | iterator->next( ).
94 | iterator->remove( ).
95 | endwhile.
96 | endmethod.
97 |
98 |
99 | * ---------------------------------------------------------------------------------------+
100 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~CONTAINS
101 | * +-------------------------------------------------------------------------------------------------+
102 | * | [--->] OBJECT TYPE REF TO ZCL_OBJECT
103 | * | [<-()] RETURNING TYPE ABAP_BOOL
104 | * +--------------------------------------------------------------------------------------
105 | method zif_collection~contains.
106 | data iterator type ref to zif_iterator.
107 | iterator = me->iterator( ).
108 | if object is not bound.
109 | while iterator->hasnext( ) = abap_true.
110 | if object = iterator->next( ).
111 | returning = abap_true.
112 | return.
113 | endif.
114 | endwhile.
115 | else.
116 | while iterator->hasnext( ) = abap_true.
117 | data obj type ref to zcl_object.
118 | obj = iterator->next( ).
119 | if obj->equals( object ) = abap_true.
120 | returning = abap_true.
121 | return.
122 | endif.
123 | endwhile.
124 | endif.
125 | " Return false if the object is not found
126 | returning = abap_false.
127 | return.
128 | endmethod.
129 |
130 |
131 | * ---------------------------------------------------------------------------------------+
132 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~CONTAINSALL
133 | * +-------------------------------------------------------------------------------------------------+
134 | * | [--->] COLLECTION TYPE REF TO ZIF_COLLECTION
135 | * | [<-()] RETURNING TYPE ABAP_BOOL
136 | * +--------------------------------------------------------------------------------------
137 | method zif_collection~containsall.
138 | data iterator type ref to zif_iterator.
139 | iterator = collection->iterator( ).
140 | while iterator->hasnext( ) = abap_true.
141 | data next type ref to zcl_object.
142 | next = iterator->next( ).
143 | if me->contains( next ) = abap_false.
144 | returning = abap_false.
145 | return.
146 | endif.
147 | endwhile.
148 | returning = abap_true.
149 | endmethod.
150 |
151 |
152 | * ---------------------------------------------------------------------------------------+
153 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~ISEMPTY
154 | * +-------------------------------------------------------------------------------------------------+
155 | * | [<-()] RETURNING TYPE ABAP_BOOL
156 | * +--------------------------------------------------------------------------------------
157 | method zif_collection~isempty.
158 | if me->size( ) = 0.
159 | returning = abap_true.
160 | return.
161 | endif.
162 | returning = abap_false.
163 | endmethod.
164 |
165 |
166 | * ---------------------------------------------------------------------------------------+
167 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~REMOVE
168 | * +-------------------------------------------------------------------------------------------------+
169 | * | [--->] OBJECT TYPE REF TO ZCL_OBJECT
170 | * | [<-()] RETURNING TYPE ABAP_BOOL
171 | * +--------------------------------------------------------------------------------------
172 | method zif_collection~remove.
173 | data iterator type ref to zif_iterator.
174 | iterator = me->iterator( ).
175 | if object is not bound.
176 | while iterator->hasnext( ) = abap_true.
177 | if object = iterator->next( ).
178 | iterator->remove( ).
179 | returning = abap_true.
180 | return.
181 | endif.
182 | endwhile.
183 | else.
184 | while iterator->hasnext( ) = abap_true.
185 | data obj type ref to zcl_object.
186 | obj = iterator->next( ).
187 | if obj->equals( object ) = abap_true.
188 | iterator->remove( ).
189 | returning = abap_true.
190 | return.
191 | endif.
192 | endwhile.
193 | endif.
194 | " Return false if the object is not found
195 | returning = abap_false.
196 | return.
197 | endmethod.
198 |
199 |
200 | * ---------------------------------------------------------------------------------------+
201 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~REMOVEALL
202 | * +-------------------------------------------------------------------------------------------------+
203 | * | [--->] COLLECTION TYPE REF TO ZIF_COLLECTION
204 | * | [<-()] RETURNING TYPE ABAP_BOOL
205 | * +--------------------------------------------------------------------------------------
206 | method zif_collection~removeall.
207 | data modified type abap_bool.
208 | modified = abap_false.
209 | data iterator type ref to zif_iterator.
210 | iterator = me->iterator( ).
211 | while iterator->hasnext( ) = abap_true.
212 | data next type ref to zcl_object.
213 | next = iterator->next( ).
214 | if collection->contains( next ) = abap_true.
215 | iterator->remove( ).
216 | modified = abap_true.
217 | endif.
218 | endwhile.
219 | returning = modified.
220 | endmethod.
221 |
222 |
223 | * ---------------------------------------------------------------------------------------+
224 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~RETAINALL
225 | * +-------------------------------------------------------------------------------------------------+
226 | * | [--->] COLLECTION TYPE REF TO ZIF_COLLECTION
227 | * | [<-()] RETURNING TYPE ABAP_BOOL
228 | * +--------------------------------------------------------------------------------------
229 | method zif_collection~retainall.
230 | data modified type abap_bool.
231 | modified = abap_false.
232 | data iterator type ref to zif_iterator.
233 | iterator = me->iterator( ).
234 | while iterator->hasnext( ) = abap_true.
235 | data next type ref to zcl_object.
236 | next = iterator->next( ).
237 | if collection->contains( next ) = abap_false.
238 | iterator->remove( ).
239 | modified = abap_true.
240 | endif.
241 | endwhile.
242 | returning = modified.
243 | endmethod.
244 |
245 |
246 | * ---------------------------------------------------------------------------------------+
247 | * | Instance Public Method ZCL_ABSTRACTCOLLECTION->ZIF_COLLECTION~TOARRAY
248 | * +-------------------------------------------------------------------------------------------------+
249 | * | [<-()] RETURNING TYPE ZARRAY
250 | * +--------------------------------------------------------------------------------------
251 | method zif_collection~toarray.
252 | data array type zarray.
253 | data iterator type ref to zif_iterator.
254 | iterator = me->iterator( ).
255 | while iterator->hasnext( ) = abap_true.
256 | data next type ref to zcl_object.
257 | next = iterator->next( ).
258 | append next to array.
259 | endwhile.
260 | returning = array.
261 | endmethod.
262 | ENDCLASS.
263 |
--------------------------------------------------------------------------------
/collections/zcl_abstractlist.abap:
--------------------------------------------------------------------------------
1 | class ZCL_ABSTRACTLIST definition
2 | public
3 | inheriting from ZCL_ABSTRACTCOLLECTION
4 | abstract
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_ABSTRACTLIST
10 | *"* do not include other source files here!!!
11 | interfaces ZIF_LIST
12 | abstract methods GET .
13 |
14 | aliases ADDALLAT
15 | for ZIF_LIST~ADDALLAT .
16 | aliases ADDAT
17 | for ZIF_LIST~ADDAT .
18 | aliases GET
19 | for ZIF_LIST~GET .
20 | aliases INDEXOF
21 | for ZIF_LIST~INDEXOF .
22 | aliases LASTINDEXOF
23 | for ZIF_LIST~LASTINDEXOF .
24 | aliases LISTITERATOR
25 | for ZIF_LIST~LISTITERATOR .
26 | aliases LISTITERATORAT
27 | for ZIF_LIST~LISTITERATORAT .
28 | aliases REMOVEAT
29 | for ZIF_LIST~REMOVEAT .
30 | aliases SET
31 | for ZIF_LIST~SET .
32 |
33 | methods ZIF_COLLECTION~ADD
34 | redefinition .
35 | methods ZIF_COLLECTION~CLEAR
36 | redefinition .
37 | methods ZIF_COLLECTION~ITERATOR
38 | redefinition .
39 | methods EQUALS
40 | redefinition .
41 | protected section.
42 |
43 | *"* protected components of class zCL_ABSTRACTLIST
44 | *"* do not include other source files here!!!
45 | data MODCOUNT type I value 0. "#EC NOTEXT . " .
46 |
47 | methods REMOVERANGE
48 | importing
49 | !FROMINDEX type I
50 | !TOINDEX type I .
51 | private section.
52 | *"* private components of class zCL_ABSTRACTLIST
53 | *"* do not include other source files here!!!
54 | ENDCLASS.
55 |
56 |
57 |
58 | CLASS ZCL_ABSTRACTLIST IMPLEMENTATION.
59 |
60 |
61 | * ---------------------------------------------------------------------------------------+
62 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_COLLECTION~ADD
63 | * +-------------------------------------------------------------------------------------------------+
64 | * | [--->] ELEMENT TYPE REF TO ZCL_OBJECT
65 | * | [<-()] RETURNING TYPE ABAP_BOOL
66 | * +--------------------------------------------------------------------------------------
67 | method zif_collection~add.
68 | data index type i.
69 | index = me->size( ).
70 | me->addat( index = index element = element ).
71 | endmethod.
72 |
73 |
74 | * ---------------------------------------------------------------------------------------+
75 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_COLLECTION~CLEAR
76 | * +-------------------------------------------------------------------------------------------------+
77 | * +--------------------------------------------------------------------------------------
78 | method zif_collection~clear.
79 | data size type i.
80 | size = me->size( ).
81 | me->removerange( fromindex = 0 toindex = size ).
82 | endmethod.
83 |
84 |
85 | * ---------------------------------------------------------------------------------------+
86 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_COLLECTION~ITERATOR
87 | * +-------------------------------------------------------------------------------------------------+
88 | * | [<-()] RETURNING TYPE REF TO ZIF_ITERATOR
89 | * +--------------------------------------------------------------------------------------
90 | method zif_collection~iterator.
91 | data iterator type ref to lcl_iterator.
92 | create object iterator
93 | exporting
94 | enclosinglist = me.
95 | returning = iterator.
96 | endmethod.
97 |
98 |
99 | * ---------------------------------------------------------------------------------------+
100 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~ADDALLAT
101 | * +-------------------------------------------------------------------------------------------------+
102 | * | [--->] INDEX TYPE I
103 | * | [--->] COLLECTION TYPE REF TO ZIF_COLLECTION
104 | * | [<-()] RETURNING TYPE ABAP_BOOL
105 | * +--------------------------------------------------------------------------------------
106 | method zif_list~addallat.
107 | data newindex type i.
108 | newindex = index.
109 | data modified type abap_bool.
110 | modified = abap_false.
111 | data iterator type ref to zif_iterator.
112 | iterator = collection->iterator( ).
113 | while iterator->hasnext( ) = abap_true.
114 | data next type ref to zcl_object.
115 | next = iterator->next( ).
116 | me->addat( index = newindex element = next ).
117 | newindex = newindex + 1.
118 | modified = abap_true.
119 | endwhile.
120 | returning = modified.
121 | endmethod.
122 |
123 |
124 | * ---------------------------------------------------------------------------------------+
125 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~ADDAT
126 | * +-------------------------------------------------------------------------------------------------+
127 | * | [--->] INDEX TYPE I
128 | * | [--->] ELEMENT TYPE REF TO ZCL_OBJECT
129 | * +--------------------------------------------------------------------------------------
130 | method zif_list~addat.
131 | raise exception type zcx_unsupportedoperation.
132 | endmethod.
133 |
134 |
135 | * ---------------------------------------------------------------------------------------+
136 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~INDEXOF
137 | * +-------------------------------------------------------------------------------------------------+
138 | * | [--->] OBJECT TYPE REF TO ZCL_OBJECT
139 | * | [<-()] RETURNING TYPE I
140 | * +--------------------------------------------------------------------------------------
141 | method zif_list~indexof.
142 | " Returns the index of the first match
143 | data listiterator type ref to zif_listiterator.
144 | listiterator = me->listiterator( ).
145 | if object is not bound.
146 | while listiterator->hasnext( ) = abap_true.
147 | if object = listiterator->next( ).
148 | returning = listiterator->previousindex( ).
149 | return.
150 | endif.
151 | endwhile.
152 | else.
153 | while listiterator->hasnext( ) = abap_true.
154 | data obj type ref to zcl_object.
155 | obj = listiterator->next( ).
156 | if obj->equals( object ) = abap_true.
157 | returning = listiterator->previousindex( ).
158 | return.
159 | endif.
160 | endwhile.
161 | endif.
162 | " Return -1 if the object is not found
163 | returning = -1.
164 | return.
165 | endmethod.
166 |
167 |
168 | * ---------------------------------------------------------------------------------------+
169 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~LASTINDEXOF
170 | * +-------------------------------------------------------------------------------------------------+
171 | * | [--->] OBJECT TYPE REF TO ZCL_OBJECT
172 | * | [<-()] RETURNING TYPE I
173 | * +--------------------------------------------------------------------------------------
174 | method zif_list~lastindexof.
175 | " Returns the index of the first match
176 | data index type i.
177 | index = me->size( ).
178 | data listiterator type ref to zif_listiterator.
179 | listiterator = me->listiteratorat( index ).
180 | if object is not bound.
181 | while listiterator->hasprevious( ) = abap_true.
182 | if object = listiterator->previous( ).
183 | returning = listiterator->nextindex( ).
184 | return.
185 | endif.
186 | endwhile.
187 | else.
188 | while listiterator->hasprevious( ) = abap_true.
189 | data obj type ref to zcl_object.
190 | obj = listiterator->previous( ).
191 | if obj->equals( object ) = abap_true.
192 | returning = listiterator->nextindex( ).
193 | return.
194 | endif.
195 | endwhile.
196 | endif.
197 | " Return -1 if the object is not found
198 | returning = -1.
199 | return.
200 | endmethod.
201 |
202 |
203 | * ---------------------------------------------------------------------------------------+
204 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~LISTITERATOR
205 | * +-------------------------------------------------------------------------------------------------+
206 | * | [<-()] RETURNING TYPE REF TO ZIF_LISTITERATOR
207 | * +--------------------------------------------------------------------------------------
208 | method zif_list~listiterator.
209 | returning = me->listiteratorat( 0 ).
210 | endmethod.
211 |
212 |
213 | * ---------------------------------------------------------------------------------------+
214 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~LISTITERATORAT
215 | * +-------------------------------------------------------------------------------------------------+
216 | * | [--->] INDEX TYPE I
217 | * | [<-()] RETURNING TYPE REF TO ZIF_LISTITERATOR
218 | * +--------------------------------------------------------------------------------------
219 | method zif_list~listiteratorat.
220 | if index < 0 or index > me->size( ).
221 | raise exception type zcx_indexoutofbounds.
222 | endif.
223 | data listiterator type ref to lcl_listiterator.
224 | create object listiterator
225 | exporting
226 | enclosinglist = me
227 | index = index.
228 | returning = listiterator.
229 | endmethod.
230 |
231 |
232 | * ---------------------------------------------------------------------------------------+
233 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~REMOVEAT
234 | * +-------------------------------------------------------------------------------------------------+
235 | * | [--->] INDEX TYPE I
236 | * | [<-()] RETURNING TYPE REF TO ZCL_OBJECT
237 | * +--------------------------------------------------------------------------------------
238 | method zif_list~removeat.
239 | raise exception type zcx_unsupportedoperation.
240 | endmethod.
241 |
242 |
243 | * ---------------------------------------------------------------------------------------+
244 | * | Instance Public Method ZCL_ABSTRACTLIST->ZIF_LIST~SET
245 | * +-------------------------------------------------------------------------------------------------+
246 | * | [--->] INDEX TYPE I
247 | * | [--->] ELEMENT TYPE REF TO ZCL_OBJECT
248 | * | [<-()] RETURNING TYPE REF TO ZCL_OBJECT
249 | * +--------------------------------------------------------------------------------------
250 | method zif_list~set.
251 | raise exception type zcx_unsupportedoperation.
252 | endmethod.
253 |
254 |
255 | * ---------------------------------------------------------------------------------------+
256 | * | Instance Public Method ZCL_ABSTRACTLIST->EQUALS
257 | * +-------------------------------------------------------------------------------------------------+
258 | * | [--->] OBJ TYPE REF TO ZCL_OBJECT
259 | * | [<-()] RETURNING TYPE ABAP_BOOL
260 | * +--------------------------------------------------------------------------------------
261 | method equals.
262 | if me = obj.
263 | returning = abap_true.
264 | return.
265 | endif.
266 | data otherlist type ref to zif_list.
267 | try.
268 | otherlist ?= obj.
269 | catch cx_sy_move_cast_error.
270 | returning = abap_false.
271 | return.
272 | endtry.
273 | " Compare each element in both lists until one of the lists (or both) have no more elements
274 | data it_thislist type ref to zif_listiterator.
275 | data it_otherlist type ref to zif_listiterator.
276 | it_thislist = me->listiterator( ).
277 | it_otherlist = otherlist->listiterator( ).
278 | while ( it_thislist->hasnext( ) = abap_true ) and ( it_otherlist->hasnext( ) = abap_true ).
279 | data obj_thislist type ref to zcl_object.
280 | data obj_otherlist type ref to zcl_object.
281 | obj_thislist = it_thislist->next( ).
282 | obj_otherlist = it_otherlist->next( ).
283 | if obj_thislist is not bound.
284 | if obj_otherlist is bound.
285 | " obj_thislist is null, but obj_otherlist is not null
286 | returning = abap_false.
287 | return.
288 | endif.
289 | else.
290 | if obj_otherlist is not bound.
291 | " obj_thislist is not null, but obj_otherlist is null
292 | returning = abap_false.
293 | return.
294 | endif.
295 | " both are not null, compare using equals method
296 | if obj_thislist->equals( obj_otherlist ) = abap_false.
297 | returning = abap_false.
298 | return.
299 | endif.
300 | endif.
301 | endwhile.
302 | " If one of the lists still has remaining elements at this point, then they are not equal
303 | if ( it_thislist->hasnext( ) = abap_true ) or ( it_otherlist->hasnext( ) = abap_true ).
304 | returning = abap_false.
305 | return.
306 | endif.
307 | " Lists are equal
308 | returning = abap_true.
309 | endmethod.
310 |
311 |
312 | * ---------------------------------------------------------------------------------------+
313 | * | Instance Protected Method ZCL_ABSTRACTLIST->REMOVERANGE
314 | * +-------------------------------------------------------------------------------------------------+
315 | * | [--->] FROMINDEX TYPE I
316 | * | [--->] TOINDEX TYPE I
317 | * +--------------------------------------------------------------------------------------
318 | method removerange.
319 | data listiterator type ref to zif_listiterator.
320 | listiterator = me->listiteratorat( fromindex ).
321 | data count type i.
322 | count = toindex - fromindex.
323 | if count > 0.
324 | do count times.
325 | listiterator->next( ).
326 | listiterator->remove( ).
327 | enddo.
328 | endif.
329 | endmethod.
330 | ENDCLASS.
331 |
--------------------------------------------------------------------------------
/collections/zcl_abstractlist.local.imp.abap:
--------------------------------------------------------------------------------
1 | *"* use this source file for the definition and implementation of
2 | *"* local helper classes, interface definitions and type
3 | *"* declarations
4 |
5 | *----------------------------------------------------------------------*
6 | * CLASS lcl_iterator DEFINITION
7 | *----------------------------------------------------------------------*
8 | *
9 | *----------------------------------------------------------------------*
10 | class lcl_iterator definition inheriting from zcl_object.
11 | public section.
12 | interfaces zif_iterator.
13 | methods constructor importing enclosinglist type ref to zcl_abstractlist.
14 | protected section.
15 | data enclosinglist type ref to zcl_abstractlist.
16 | data cursor type i value 0.
17 | data lastret type i value -1.
18 | data expectedmodcount type i.
19 | methods checkforcomodification final.
20 | endclass. "lcl_iterator DEFINITION
21 |
22 | *----------------------------------------------------------------------*
23 | * CLASS lcl_listiterator DEFINITION
24 | *----------------------------------------------------------------------*
25 | *
26 | *----------------------------------------------------------------------*
27 | class lcl_listiterator definition inheriting from lcl_iterator final.
28 | public section.
29 | interfaces zif_listiterator.
30 | methods constructor importing enclosinglist type ref to zcl_abstractlist
31 | index type i.
32 | endclass. "lcl_listiterator DEFINITION
33 |
34 | class zcl_abstractlist definition local friends lcl_iterator lcl_listiterator.
35 |
36 | *----------------------------------------------------------------------*
37 | * CLASS lcl_iterator IMPLEMENTATION
38 | *----------------------------------------------------------------------*
39 | *
40 | *----------------------------------------------------------------------*
41 | class lcl_iterator implementation.
42 | method constructor.
43 | super->constructor( ).
44 | me->enclosinglist = enclosinglist.
45 | me->expectedmodcount = enclosinglist->modcount.
46 | endmethod. "constructor
47 | method zif_iterator~hasnext.
48 | if me->cursor <> enclosinglist->size( ).
49 | returning = abap_true.
50 | return.
51 | else.
52 | returning = abap_false.
53 | return.
54 | endif.
55 | endmethod. "zif_iterator~HASNEXT
56 | method zif_iterator~next.
57 | me->checkforcomodification( ).
58 | try.
59 | data next type ref to zcl_object.
60 | next = enclosinglist->get( me->cursor ).
61 | me->lastret = me->cursor.
62 | me->cursor = me->cursor + 1.
63 | returning = next.
64 | return.
65 | catch zcx_indexoutofbounds.
66 | me->checkforcomodification( ). " Check if this exception is caused by a concurrent modification
67 | raise exception type zcx_nosuchelement. " Not a concurrent modification, element simply not found
68 | endtry.
69 | endmethod. "zif_iterator~NEXT
70 | method zif_iterator~remove.
71 | if lastret = -1.
72 | raise exception type zcx_illegalstate.
73 | endif.
74 | me->checkforcomodification( ).
75 | try.
76 | enclosinglist->removeat( index = me->lastret ).
77 | if me->lastret < me->cursor.
78 | me->cursor = me->cursor - 1.
79 | endif.
80 | me->lastret = -1.
81 | me->expectedmodcount = enclosinglist->modcount.
82 | catch zcx_indexoutofbounds.
83 | raise exception type zcx_concurrmodification.
84 | endtry.
85 | endmethod. "zif_iterator~REMOVE
86 | method checkforcomodification.
87 | if enclosinglist->modcount <> me->expectedmodcount.
88 | raise exception type zcx_concurrmodification.
89 | endif.
90 | endmethod. "checkforcomodification
91 | endclass. "lcl_iterator IMPLEMENTATION
92 |
93 | *----------------------------------------------------------------------*
94 | * CLASS lcl_listiterator IMPLEMENTATION
95 | *----------------------------------------------------------------------*
96 | *
97 | *----------------------------------------------------------------------*
98 | class lcl_listiterator implementation.
99 | method constructor.
100 | super->constructor( enclosinglist ).
101 | me->cursor = index.
102 | endmethod. "constructor
103 | method zif_listiterator~add.
104 | me->checkforcomodification( ).
105 | try.
106 | enclosinglist->addat( index = me->cursor element = element ).
107 | me->cursor = me->cursor + 1.
108 | me->lastret = -1.
109 | me->expectedmodcount = enclosinglist->modcount.
110 | catch zcx_indexoutofbounds.
111 | raise exception type zcx_concurrmodification.
112 | endtry.
113 | endmethod. "zif_listiterator~ADD
114 | method zif_listiterator~hasprevious.
115 | if me->cursor <> 0.
116 | returning = abap_true.
117 | return.
118 | else.
119 | returning = abap_false.
120 | return.
121 | endif.
122 | endmethod. "zif_listiterator~HASPREVIOUS
123 | method zif_listiterator~nextindex.
124 | returning = me->cursor.
125 | return.
126 | endmethod. "zif_listiterator~NEXTINDEX
127 | method zif_listiterator~previous.
128 | me->checkforcomodification( ).
129 | try.
130 | data previousindex type i.
131 | previousindex = me->cursor - 1.
132 | data previous type ref to zcl_object.
133 | previous = enclosinglist->get( previousindex ).
134 | me->lastret = previousindex.
135 | me->cursor = previousindex.
136 | returning = previous.
137 | return.
138 | catch zcx_indexoutofbounds.
139 | me->checkforcomodification( ). " Check if this exception is caused by a concurrent modification
140 | raise exception type zcx_nosuchelement. " Not a concurrent modification, element simply not found
141 | endtry.
142 | endmethod. "zif_listiterator~PREVIOUS
143 | method zif_listiterator~previousindex.
144 | returning = me->cursor - 1.
145 | return.
146 | endmethod. "zif_listiterator~PREVIOUSINDEX
147 | method zif_listiterator~set.
148 | if lastret = -1.
149 | raise exception type zcx_illegalstate.
150 | endif.
151 | me->checkforcomodification( ).
152 | try.
153 | enclosinglist->set( index = me->lastret element = element ).
154 | me->expectedmodcount = enclosinglist->modcount.
155 | catch zcx_indexoutofbounds.
156 | raise exception type zcx_concurrmodification.
157 | endtry.
158 | endmethod. "zif_listiterator~SET
159 | endclass. "lcl_listiterator IMPLEMENTATION
160 |
--------------------------------------------------------------------------------
/collections/zcl_collections.abap:
--------------------------------------------------------------------------------
1 | class ZCL_COLLECTIONS definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create private .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_COLLECTIONS
10 | *"* do not include other source files here!!!
11 | class-methods UNMODIFIABLELIST
12 | importing
13 | !LIST type ref to ZIF_LIST
14 | returning
15 | value(RETURNING) type ref to ZIF_LIST .
16 | protected section.
17 | *"* protected components of class zCL_COLLECTIONS
18 | *"* do not include other source files here!!!
19 | private section.
20 | *"* private components of class zCL_COLLECTIONS
21 | *"* do not include other source files here!!!
22 | ENDCLASS.
23 |
24 |
25 |
26 | CLASS ZCL_COLLECTIONS IMPLEMENTATION.
27 |
28 |
29 | * ---------------------------------------------------------------------------------------+
30 | * | Static Public Method ZCL_COLLECTIONS=>UNMODIFIABLELIST
31 | * +-------------------------------------------------------------------------------------------------+
32 | * | [--->] LIST TYPE REF TO ZIF_LIST
33 | * | [<-()] RETURNING TYPE REF TO ZIF_LIST
34 | * +--------------------------------------------------------------------------------------
35 | method unmodifiablelist.
36 | data unmodifiablelist type ref to lcl_unmodifiablelist.
37 | create object unmodifiablelist
38 | exporting
39 | list = list.
40 | returning = unmodifiablelist.
41 | endmethod.
42 | ENDCLASS.
43 |
--------------------------------------------------------------------------------
/collections/zcl_collections.local.imp.abap:
--------------------------------------------------------------------------------
1 | *"* use this source file for the definition and implementation of
2 | *"* local helper classes, interface definitions and type
3 | *"* declarations
4 |
5 | *----------------------------------------------------------------------*
6 | * CLASS lcl_unmodifiablecollection DEFINITION
7 | *----------------------------------------------------------------------*
8 | *
9 | *----------------------------------------------------------------------*
10 | class lcl_unmodifiablecollection definition.
11 | public section.
12 | interfaces zif_collection.
13 | interfaces if_serializable_object.
14 | aliases add for zif_collection~add .
15 | aliases addall for zif_collection~addall .
16 | aliases clear for zif_collection~clear .
17 | aliases contains for zif_collection~contains .
18 | aliases containsall for zif_collection~containsall .
19 | aliases isempty for zif_collection~isempty .
20 | aliases iterator for zif_collection~iterator .
21 | aliases remove for zif_collection~remove .
22 | aliases removeall for zif_collection~removeall .
23 | aliases retainall for zif_collection~retainall .
24 | aliases size for zif_collection~size .
25 | aliases toarray for zif_collection~toarray .
26 | methods constructor importing collection type ref to zif_collection.
27 | private section.
28 | data collection type ref to zif_collection.
29 | endclass. "lcl_UnmodifiableCollection DEFINITION
30 |
31 | *----------------------------------------------------------------------*
32 | * CLASS lcl_unmodifiablelist DEFINITION
33 | *----------------------------------------------------------------------*
34 | *
35 | *----------------------------------------------------------------------*
36 | class lcl_unmodifiablelist definition inheriting from lcl_unmodifiablecollection final.
37 | public section.
38 | interfaces zif_list.
39 | aliases addallat for zif_list~addallat.
40 | aliases addat for zif_list~addat.
41 | aliases get for zif_list~get.
42 | aliases indexof for zif_list~indexof.
43 | aliases lastindexof for zif_list~lastindexof.
44 | aliases listiterator for zif_list~listiterator.
45 | aliases listiteratorat for zif_list~listiteratorat.
46 | aliases removeat for zif_list~removeat.
47 | aliases set for zif_list~set.
48 | methods constructor importing list type ref to zif_list.
49 | private section.
50 | data list type ref to zif_list.
51 | endclass. "lcl_unmodifiablelist DEFINITION
52 |
53 | *----------------------------------------------------------------------*
54 | * CLASS lcl_unmod_collection_iterator DEFINITION
55 | *----------------------------------------------------------------------*
56 | *
57 | *----------------------------------------------------------------------*
58 | class lcl_unmod_coll_iterator definition final.
59 | public section.
60 | interfaces zif_iterator.
61 | methods constructor importing iterator type ref to zif_iterator.
62 | private section.
63 | data iterator type ref to zif_iterator.
64 | endclass. "lcl_unmod_collection_iterator DEFINITION
65 |
66 | *----------------------------------------------------------------------*
67 | * CLASS lcl_unmod_coll_listiterator DEFINITION
68 | *----------------------------------------------------------------------*
69 | *
70 | *----------------------------------------------------------------------*
71 | class lcl_unmod_coll_listiterator definition final.
72 | public section.
73 | interfaces zif_listiterator.
74 | methods constructor importing listiterator type ref to zif_listiterator.
75 | private section.
76 | data listiterator type ref to zif_listiterator.
77 | endclass. "lcl_unmod_coll_listiterator DEFINITION
78 |
79 | *----------------------------------------------------------------------*
80 | * CLASS lcl_unmodifiablecollection IMPLEMENTATION
81 | *----------------------------------------------------------------------*
82 | *
83 | *----------------------------------------------------------------------*
84 | class lcl_unmodifiablecollection implementation.
85 | method constructor.
86 | if collection is not bound.
87 | raise exception type cx_sy_ref_is_initial.
88 | endif.
89 | me->collection = collection.
90 | endmethod. "constructor
91 | method zif_collection~add.
92 | raise exception type zcx_unsupportedoperation.
93 | endmethod. "zif_collection~add
94 | method zif_collection~addall.
95 | raise exception type zcx_unsupportedoperation.
96 | endmethod. "zif_collection~addall
97 | method zif_collection~clear.
98 | raise exception type zcx_unsupportedoperation.
99 | endmethod. "zif_collection~clear
100 | method zif_collection~contains.
101 | returning = me->collection->contains( object ).
102 | endmethod. "zif_collection~contains
103 | method zif_collection~containsall.
104 | returning = me->collection->containsall( collection ).
105 | endmethod. "zif_collection~containsall
106 | method zif_collection~isempty.
107 | returning = me->collection->isempty( ).
108 | endmethod. "zif_collection~isempty
109 | method zif_collection~iterator.
110 | data iterator type ref to zif_iterator.
111 | iterator ?= me->collection->iterator( ).
112 | data unmod_coll_iterator type ref to lcl_unmod_coll_iterator.
113 | create object unmod_coll_iterator
114 | exporting
115 | iterator = iterator.
116 | returning = unmod_coll_iterator.
117 | endmethod. "zif_collection~iterator
118 | method zif_collection~remove.
119 | raise exception type zcx_unsupportedoperation.
120 | endmethod. "zif_collection~remove
121 | method zif_collection~removeall.
122 | raise exception type zcx_unsupportedoperation.
123 | endmethod. "zif_collection~removeall
124 | method zif_collection~retainall.
125 | raise exception type zcx_unsupportedoperation.
126 | endmethod. "zif_collection~retainall
127 | method zif_collection~size.
128 | returning = me->collection->size( ).
129 | endmethod. "zif_collection~size
130 | method zif_collection~toarray.
131 | returning = me->collection->toarray( ).
132 | endmethod. "zif_collection~toarray
133 | endclass. "lcl_unmodifiablecollection IMPLEMENTATION
134 |
135 | *----------------------------------------------------------------------*
136 | * CLASS lcl_unmodifiablelist IMPLEMENTATION
137 | *----------------------------------------------------------------------*
138 | *
139 | *----------------------------------------------------------------------*
140 | class lcl_unmodifiablelist implementation.
141 | method constructor.
142 | super->constructor( list ).
143 | me->list = list.
144 | endmethod. "constructor
145 | method zif_list~addallat.
146 | raise exception type zcx_unsupportedoperation.
147 | endmethod. "zif_list~addallat
148 | method zif_list~addat.
149 | raise exception type zcx_unsupportedoperation.
150 | endmethod. "zif_list~addat
151 | method zif_list~get.
152 | returning = me->list->get( index ).
153 | endmethod. "zif_list~get
154 | method zif_list~indexof.
155 | returning = me->list->indexof( object ).
156 | endmethod. "zif_list~indexof
157 | method zif_list~lastindexof.
158 | returning = me->list->lastindexof( object ).
159 | endmethod. "zif_list~lastindexof
160 | method zif_list~listiterator.
161 | returning = me->listiteratorat( 0 ).
162 | endmethod. "zif_list~listiterator
163 | method zif_list~listiteratorat.
164 | data listiterator type ref to zif_listiterator.
165 | listiterator ?= me->list->listiteratorat( index ).
166 | data unmod_coll_listiterator type ref to lcl_unmod_coll_listiterator.
167 | create object unmod_coll_listiterator
168 | exporting
169 | listiterator = listiterator.
170 | returning = unmod_coll_listiterator.
171 | endmethod. "zif_list~listiteratorat
172 | method zif_list~removeat.
173 | raise exception type zcx_unsupportedoperation.
174 | endmethod. "zif_list~removeat
175 | method zif_list~set.
176 | raise exception type zcx_unsupportedoperation.
177 | endmethod. "zif_list~set
178 | endclass. "lcl_unmodifiablelist IMPLEMENTATION
179 |
180 | *----------------------------------------------------------------------*
181 | * CLASS lcl_unmod_collection_iterator IMPLEMENTATION
182 | *----------------------------------------------------------------------*
183 | *
184 | *----------------------------------------------------------------------*
185 | class lcl_unmod_coll_iterator implementation.
186 | method constructor.
187 | me->iterator = iterator.
188 | endmethod. "constructor
189 | method zif_iterator~hasnext.
190 | returning = me->iterator->hasnext( ).
191 | endmethod. "zif_iterator~HASNEXT
192 | method zif_iterator~next.
193 | returning = me->iterator->next( ).
194 | endmethod. "zif_iterator~NEXT
195 | method zif_iterator~remove.
196 | raise exception type zcx_unsupportedoperation.
197 | endmethod. "zif_iterator~REMOVE
198 | endclass. "lcl_unmod_collection_iterator IMPLEMENTATION
199 |
200 | *----------------------------------------------------------------------*
201 | * CLASS lcl_unmod_coll_listiterator IMPLEMENTATION
202 | *----------------------------------------------------------------------*
203 | *
204 | *----------------------------------------------------------------------*
205 | class lcl_unmod_coll_listiterator implementation.
206 | method constructor.
207 | me->listiterator = listiterator.
208 | endmethod. "constructor
209 | method zif_iterator~hasnext.
210 | returning = me->listiterator->hasnext( ).
211 | endmethod. "zif_iterator~HASNEXT
212 | method zif_iterator~next.
213 | returning = me->listiterator->next( ).
214 | endmethod. "zif_iterator~NEXT
215 | method zif_iterator~remove.
216 | raise exception type zcx_unsupportedoperation.
217 | endmethod. "zif_iterator~REMOVE
218 | method zif_listiterator~add.
219 | raise exception type zcx_unsupportedoperation.
220 | endmethod. "zif_listiterator~ADD
221 | method zif_listiterator~hasprevious.
222 | returning = me->listiterator->hasprevious( ).
223 | endmethod. "zif_listiterator~HASPREVIOUS
224 | method zif_listiterator~nextindex.
225 | returning = me->listiterator->nextindex( ).
226 | endmethod. "zif_listiterator~NEXTINDEX
227 | method zif_listiterator~previous.
228 | returning = me->listiterator->previous( ).
229 | endmethod. "zif_listiterator~PREVIOUS
230 | method zif_listiterator~previousindex.
231 | returning = me->listiterator->previousindex( ).
232 | endmethod. "zif_listiterator~PREVIOUSINDEX
233 | method zif_listiterator~set.
234 | raise exception type zcx_unsupportedoperation.
235 | endmethod. "zif_listiterator~SET
236 | endclass. "lcl_unmod_coll_listiterator IMPLEMENTATION
237 |
--------------------------------------------------------------------------------
/collections/zcx_concurrmodification.abap:
--------------------------------------------------------------------------------
1 | class ZCX_CONCURRMODIFICATION definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_CONCURRMODIFICATION type SOTR_CONC value '00155D334B0D1EE2B8FDDB2837A32991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_CONCURRMODIFICATION IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_CONCURRMODIFICATION->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_CONCURRMODIFICATION .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/collections/zcx_nosuchelement.abap:
--------------------------------------------------------------------------------
1 | class ZCX_NOSUCHELEMENT definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_NOSUCHELEMENT type SOTR_CONC value '00155D334B0D1EE2B8FDDBEADE068991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_NOSUCHELEMENT IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_NOSUCHELEMENT->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_NOSUCHELEMENT .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/collections/zif_collection.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_COLLECTION
2 | public .
3 |
4 |
5 | type-pools ABAP .
6 | methods ADD
7 | importing
8 | !ELEMENT type ref to ZCL_OBJECT
9 | returning
10 | value(RETURNING) type ABAP_BOOL .
11 | methods ADDALL
12 | importing
13 | !COLLECTION type ref to ZIF_COLLECTION
14 | returning
15 | value(RETURNING) type ABAP_BOOL .
16 | methods CLEAR .
17 | methods CONTAINS
18 | importing
19 | !OBJECT type ref to ZCL_OBJECT
20 | returning
21 | value(RETURNING) type ABAP_BOOL .
22 | methods CONTAINSALL
23 | importing
24 | !COLLECTION type ref to ZIF_COLLECTION
25 | returning
26 | value(RETURNING) type ABAP_BOOL .
27 | methods ISEMPTY
28 | returning
29 | value(RETURNING) type ABAP_BOOL .
30 | methods ITERATOR
31 | returning
32 | value(RETURNING) type ref to ZIF_ITERATOR .
33 | methods REMOVE
34 | importing
35 | !OBJECT type ref to ZCL_OBJECT
36 | returning
37 | value(RETURNING) type ABAP_BOOL .
38 | methods REMOVEALL
39 | importing
40 | !COLLECTION type ref to ZIF_COLLECTION
41 | returning
42 | value(RETURNING) type ABAP_BOOL .
43 | methods RETAINALL
44 | importing
45 | !COLLECTION type ref to ZIF_COLLECTION
46 | returning
47 | value(RETURNING) type ABAP_BOOL .
48 | methods SIZE
49 | returning
50 | value(RETURNING) type I .
51 | methods TOARRAY
52 | returning
53 | value(RETURNING) type ZARRAY .
54 | endinterface.
55 |
--------------------------------------------------------------------------------
/collections/zif_iterator.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_ITERATOR
2 | public .
3 |
4 |
5 | type-pools ABAP .
6 | methods HASNEXT
7 | returning
8 | value(RETURNING) type ABAP_BOOL .
9 | methods NEXT
10 | returning
11 | value(RETURNING) type ref to ZCL_OBJECT .
12 | methods REMOVE .
13 | endinterface.
14 |
--------------------------------------------------------------------------------
/collections/zif_list.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_LIST
2 | public .
3 |
4 |
5 | interfaces ZIF_COLLECTION .
6 |
7 | aliases ADD
8 | for ZIF_COLLECTION~ADD .
9 | aliases ADDALL
10 | for ZIF_COLLECTION~ADDALL .
11 | aliases CLEAR
12 | for ZIF_COLLECTION~CLEAR .
13 | aliases CONTAINS
14 | for ZIF_COLLECTION~CONTAINS .
15 | aliases CONTAINSALL
16 | for ZIF_COLLECTION~CONTAINSALL .
17 | aliases ISEMPTY
18 | for ZIF_COLLECTION~ISEMPTY .
19 | aliases ITERATOR
20 | for ZIF_COLLECTION~ITERATOR .
21 | aliases REMOVE
22 | for ZIF_COLLECTION~REMOVE .
23 | aliases REMOVEALL
24 | for ZIF_COLLECTION~REMOVEALL .
25 | aliases RETAINALL
26 | for ZIF_COLLECTION~RETAINALL .
27 | aliases SIZE
28 | for ZIF_COLLECTION~SIZE .
29 | aliases TOARRAY
30 | for ZIF_COLLECTION~TOARRAY .
31 |
32 | methods ADDAT
33 | importing
34 | !INDEX type I
35 | !ELEMENT type ref to ZCL_OBJECT .
36 | type-pools ABAP .
37 | methods ADDALLAT
38 | importing
39 | !INDEX type I
40 | !COLLECTION type ref to ZIF_COLLECTION
41 | returning
42 | value(RETURNING) type ABAP_BOOL .
43 | methods GET
44 | importing
45 | !INDEX type I
46 | returning
47 | value(RETURNING) type ref to ZCL_OBJECT .
48 | methods INDEXOF
49 | importing
50 | !OBJECT type ref to ZCL_OBJECT
51 | returning
52 | value(RETURNING) type I .
53 | methods LASTINDEXOF
54 | importing
55 | !OBJECT type ref to ZCL_OBJECT
56 | returning
57 | value(RETURNING) type I .
58 | methods LISTITERATOR
59 | returning
60 | value(RETURNING) type ref to ZIF_LISTITERATOR .
61 | methods LISTITERATORAT
62 | importing
63 | !INDEX type I
64 | returning
65 | value(RETURNING) type ref to ZIF_LISTITERATOR .
66 | methods REMOVEAT
67 | importing
68 | !INDEX type I
69 | returning
70 | value(RETURNING) type ref to ZCL_OBJECT .
71 | methods SET
72 | importing
73 | !INDEX type I
74 | !ELEMENT type ref to ZCL_OBJECT
75 | returning
76 | value(RETURNING) type ref to ZCL_OBJECT .
77 | endinterface.
78 |
--------------------------------------------------------------------------------
/collections/zif_listiterator.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_LISTITERATOR
2 | public .
3 |
4 |
5 | interfaces ZIF_ITERATOR .
6 |
7 | aliases HASNEXT
8 | for ZIF_ITERATOR~HASNEXT .
9 | aliases NEXT
10 | for ZIF_ITERATOR~NEXT .
11 | aliases REMOVE
12 | for ZIF_ITERATOR~REMOVE .
13 |
14 | methods ADD
15 | importing
16 | !ELEMENT type ref to ZCL_OBJECT .
17 | type-pools ABAP .
18 | methods HASPREVIOUS
19 | returning
20 | value(RETURNING) type ABAP_BOOL .
21 | methods NEXTINDEX
22 | returning
23 | value(RETURNING) type I .
24 | methods PREVIOUS
25 | returning
26 | value(RETURNING) type ref to ZCL_OBJECT .
27 | methods PREVIOUSINDEX
28 | returning
29 | value(RETURNING) type I .
30 | methods SET
31 | importing
32 | !ELEMENT type ref to ZCL_OBJECT .
33 | endinterface.
34 |
--------------------------------------------------------------------------------
/csv/csv.messageclass.txt:
--------------------------------------------------------------------------------
1 | 000 & & & &
2 | 001 & & & &
3 | 002 Empty CSV string
4 | 003 Error in CSV format
--------------------------------------------------------------------------------
/csv/zcl_csv_parser.abap:
--------------------------------------------------------------------------------
1 | class ZCL_CSV_PARSER definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 | *"* public components of class zCL_CSV_PARSER
9 | *"* do not include other source files here!!!
10 | type-pools ABAP .
11 |
12 | methods CONSTRUCTOR
13 | importing
14 | !DELEGATE type ref to ZIF_CSV_PARSER_DELEGATE
15 | !CSVSTRING type STRING
16 | !SEPARATOR type C
17 | !SKIP_FIRST_LINE type ABAP_BOOL .
18 | methods PARSE
19 | raising
20 | ZCX_CSV_PARSE_ERROR .
21 | protected section.
22 | *"* protected components of class zCL_CSV_PARSER
23 | *"* do not include other source files here!!!
24 | private section.
25 |
26 | *"* private components of class zCL_CSV_PARSER
27 | *"* do not include other source files here!!!
28 | constants _TEXTINDICATOR type C value '"'. "#EC NOTEXT
29 | data _DELEGATE type ref to ZIF_CSV_PARSER_DELEGATE .
30 | data _CSVSTRING type STRING .
31 | data _SEPARATOR type C .
32 | data _SKIP_FIRST_LINE type ABAP_BOOL .
33 |
34 | methods _LINES
35 | returning
36 | value(RETURNING) type STRINGTAB .
37 | methods _PARSE_LINE
38 | importing
39 | !LINE type STRING
40 | returning
41 | value(RETURNING) type STRINGTAB
42 | raising
43 | ZCX_CSV_PARSE_ERROR .
44 | ENDCLASS.
45 |
46 |
47 |
48 | CLASS ZCL_CSV_PARSER IMPLEMENTATION.
49 |
50 |
51 | * ---------------------------------------------------------------------------------------+
52 | * | Instance Public Method ZCL_CSV_PARSER->CONSTRUCTOR
53 | * +-------------------------------------------------------------------------------------------------+
54 | * | [--->] DELEGATE TYPE REF TO ZIF_CSV_PARSER_DELEGATE
55 | * | [--->] CSVSTRING TYPE STRING
56 | * | [--->] SEPARATOR TYPE C
57 | * | [--->] SKIP_FIRST_LINE TYPE ABAP_BOOL
58 | * +--------------------------------------------------------------------------------------
59 | method constructor.
60 | super->constructor( ).
61 | _delegate = delegate.
62 | _csvstring = csvstring.
63 | _separator = separator.
64 | _skip_first_line = skip_first_line.
65 | endmethod.
66 |
67 |
68 | * ---------------------------------------------------------------------------------------+
69 | * | Instance Public Method ZCL_CSV_PARSER->PARSE
70 | * +-------------------------------------------------------------------------------------------------+
71 | * | [!CX!] ZCX_CSV_PARSE_ERROR
72 | * +--------------------------------------------------------------------------------------
73 | method parse.
74 | data msg type string.
75 | if _csvstring is initial.
76 | message e002(zcsv) into msg.
77 | raise exception type zcx_csv_parse_error
78 | exporting
79 | message = msg.
80 | endif.
81 |
82 | " Get the lines
83 | data is_first_line type abap_bool value abap_true.
84 | data lines type standard table of string.
85 | lines = _lines( ).
86 | field-symbols type string.
87 | loop at lines assigning .
88 | " Should we skip the first line?
89 | if _skip_first_line = abap_true and is_first_line = abap_true.
90 | is_first_line = abap_false.
91 | continue.
92 | endif.
93 | " Parse the line
94 | data values type standard table of string.
95 | values = _parse_line( ).
96 | " Send values to delegate
97 | _delegate->values_found( values ).
98 | endloop.
99 | endmethod.
100 |
101 |
102 | * ---------------------------------------------------------------------------------------+
103 | * | Instance Private Method ZCL_CSV_PARSER->_LINES
104 | * +-------------------------------------------------------------------------------------------------+
105 | * | [<-()] RETURNING TYPE STRINGTAB
106 | * +--------------------------------------------------------------------------------------
107 | method _lines.
108 | split _csvstring at cl_abap_char_utilities=>cr_lf into table returning.
109 | endmethod.
110 |
111 |
112 | * ---------------------------------------------------------------------------------------+
113 | * | Instance Private Method ZCL_CSV_PARSER->_PARSE_LINE
114 | * +-------------------------------------------------------------------------------------------------+
115 | * | [--->] LINE TYPE STRING
116 | * | [<-()] RETURNING TYPE STRINGTAB
117 | * | [!CX!] ZCX_CSV_PARSE_ERROR
118 | * +--------------------------------------------------------------------------------------
119 | method _parse_line.
120 | data msg type string.
121 |
122 | data csvvalue type string.
123 | data csvvalues type standard table of string.
124 |
125 | data char type c.
126 | data pos type i value 0.
127 | data len type i.
128 | len = strlen( line ).
129 | while pos < len.
130 | char = line+pos(1).
131 | if char <> _separator.
132 | if char = _textindicator.
133 | data text_ended type abap_bool.
134 | text_ended = abap_false.
135 | while text_ended = abap_false.
136 | pos = pos + 1.
137 | if pos < len.
138 | char = line+pos(1).
139 | if char = _textindicator.
140 | text_ended = abap_true.
141 | else.
142 | if char is initial. " Space
143 | concatenate csvvalue ` ` into csvvalue.
144 | else.
145 | concatenate csvvalue char into csvvalue.
146 | endif.
147 | endif.
148 | else.
149 | " Reached the end of the line while inside a text value
150 | " This indicates an error in the CSV formatting
151 | text_ended = abap_true.
152 | message e003(zcsv) into msg.
153 | raise exception type zcx_csv_parse_error
154 | exporting
155 | message = msg.
156 | endif.
157 | endwhile.
158 | " Check if next character is a separator, otherwise the CSV formatting is incorrect
159 | data nextpos type i.
160 | nextpos = pos + 1.
161 | if nextpos < len and line+nextpos(1) <> _separator.
162 | message e003(zcsv) into msg.
163 | raise exception type zcx_csv_parse_error
164 | exporting
165 | message = msg.
166 | endif.
167 | else.
168 | if char is initial. " Space
169 | concatenate csvvalue ` ` into csvvalue.
170 | else.
171 | concatenate csvvalue char into csvvalue.
172 | endif.
173 | endif.
174 | else.
175 | append csvvalue to csvvalues.
176 | clear csvvalue.
177 | endif.
178 | pos = pos + 1.
179 | endwhile.
180 | append csvvalue to csvvalues. " Don't forget the last value
181 |
182 | returning = csvvalues.
183 | endmethod.
184 | ENDCLASS.
185 |
--------------------------------------------------------------------------------
/csv/zcx_csv_parse_error.abap:
--------------------------------------------------------------------------------
1 | class ZCX_CSV_PARSE_ERROR definition
2 | public
3 | inheriting from ZCX_STATICEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_CSV_PARSE_ERROR type SOTR_CONC value '00155D334B0D1EE2B8FDAF6749B78991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_CSV_PARSE_ERROR IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_CSV_PARSE_ERROR->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_CSV_PARSE_ERROR .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/csv/zif_csv_parser_delegate.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_CSV_PARSER_DELEGATE
2 | public .
3 |
4 |
5 | methods VALUES_FOUND
6 | importing
7 | !VALUES type STRINGTAB .
8 | endinterface.
9 |
--------------------------------------------------------------------------------
/json/json.messageclass.txt:
--------------------------------------------------------------------------------
1 | 000 & & & &
2 | 001 & & & &
3 | 002 Parse error, position & has unexpected character '&'
--------------------------------------------------------------------------------
/json/zcl_json_array.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_ARRAY definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 | *"* public components of class zCL_JSON_ARRAY
9 | *"* do not include other source files here!!!
10 | type-pools ABAP .
11 |
12 | interfaces ZIF_JSON_VALUE .
13 |
14 | aliases GET_TYPE
15 | for ZIF_JSON_VALUE~GET_TYPE .
16 |
17 | methods CONSTRUCTOR .
18 | methods ADD
19 | importing
20 | !VALUE type ref to ZIF_JSON_VALUE
21 | returning
22 | value(RETURNING) type ABAP_BOOL .
23 | methods CLEAR .
24 | methods GET
25 | importing
26 | !INDEX type I
27 | returning
28 | value(RETURNING) type ref to ZIF_JSON_VALUE .
29 | methods ITERATOR
30 | returning
31 | value(RETURNING) type ref to ZIF_ITERATOR .
32 | methods REMOVE
33 | importing
34 | !VALUE type ref to ZIF_JSON_VALUE
35 | returning
36 | value(RETURNING) type ABAP_BOOL .
37 | methods SET
38 | importing
39 | !INDEX type I
40 | !VALUE type ref to ZIF_JSON_VALUE
41 | returning
42 | value(RETURNING) type ref to ZIF_JSON_VALUE .
43 | methods SIZE
44 | returning
45 | value(RETURNING) type I .
46 | protected section.
47 | *"* protected components of class zCL_JSON_ARRAY
48 | *"* do not include other source files here!!!
49 | private section.
50 |
51 | *"* private components of class zCL_JSON_ARRAY
52 | *"* do not include other source files here!!!
53 | data VALUES type ref to ZCL_ARRAYLIST .
54 | ENDCLASS.
55 |
56 |
57 |
58 | CLASS ZCL_JSON_ARRAY IMPLEMENTATION.
59 |
60 |
61 | * ---------------------------------------------------------------------------------------+
62 | * | Instance Public Method ZCL_JSON_ARRAY->ZIF_JSON_VALUE~GET_TYPE
63 | * +-------------------------------------------------------------------------------------------------+
64 | * | [<-()] RETURNING TYPE I
65 | * +--------------------------------------------------------------------------------------
66 | method zif_json_value~get_type.
67 | returning = zcl_json_types=>type_array.
68 | endmethod.
69 |
70 |
71 | * ---------------------------------------------------------------------------------------+
72 | * | Instance Public Method ZCL_JSON_ARRAY->ADD
73 | * +-------------------------------------------------------------------------------------------------+
74 | * | [--->] VALUE TYPE REF TO ZIF_JSON_VALUE
75 | * | [<-()] RETURNING TYPE ABAP_BOOL
76 | * +--------------------------------------------------------------------------------------
77 | method add.
78 | data object type ref to zcl_object.
79 | object ?= value.
80 | returning = me->values->add( object ).
81 | endmethod.
82 |
83 |
84 | * ---------------------------------------------------------------------------------------+
85 | * | Instance Public Method ZCL_JSON_ARRAY->CLEAR
86 | * +-------------------------------------------------------------------------------------------------+
87 | * +--------------------------------------------------------------------------------------
88 | method clear.
89 | me->values->clear( ).
90 | endmethod.
91 |
92 |
93 | * ---------------------------------------------------------------------------------------+
94 | * | Instance Public Method ZCL_JSON_ARRAY->CONSTRUCTOR
95 | * +-------------------------------------------------------------------------------------------------+
96 | * +--------------------------------------------------------------------------------------
97 | method constructor.
98 | super->constructor( ).
99 | " Init values list
100 | create object me->values.
101 | endmethod.
102 |
103 |
104 | * ---------------------------------------------------------------------------------------+
105 | * | Instance Public Method ZCL_JSON_ARRAY->GET
106 | * +-------------------------------------------------------------------------------------------------+
107 | * | [--->] INDEX TYPE I
108 | * | [<-()] RETURNING TYPE REF TO ZIF_JSON_VALUE
109 | * +--------------------------------------------------------------------------------------
110 | method get.
111 | returning ?= me->values->get( index ).
112 | endmethod.
113 |
114 |
115 | * ---------------------------------------------------------------------------------------+
116 | * | Instance Public Method ZCL_JSON_ARRAY->ITERATOR
117 | * +-------------------------------------------------------------------------------------------------+
118 | * | [<-()] RETURNING TYPE REF TO ZIF_ITERATOR
119 | * +--------------------------------------------------------------------------------------
120 | method iterator.
121 | returning = me->values->iterator( ).
122 | endmethod.
123 |
124 |
125 | * ---------------------------------------------------------------------------------------+
126 | * | Instance Public Method ZCL_JSON_ARRAY->REMOVE
127 | * +-------------------------------------------------------------------------------------------------+
128 | * | [--->] VALUE TYPE REF TO ZIF_JSON_VALUE
129 | * | [<-()] RETURNING TYPE ABAP_BOOL
130 | * +--------------------------------------------------------------------------------------
131 | method remove.
132 | data object type ref to zcl_object.
133 | object ?= value.
134 | returning = me->values->remove( object ).
135 | endmethod.
136 |
137 |
138 | * ---------------------------------------------------------------------------------------+
139 | * | Instance Public Method ZCL_JSON_ARRAY->SET
140 | * +-------------------------------------------------------------------------------------------------+
141 | * | [--->] INDEX TYPE I
142 | * | [--->] VALUE TYPE REF TO ZIF_JSON_VALUE
143 | * | [<-()] RETURNING TYPE REF TO ZIF_JSON_VALUE
144 | * +--------------------------------------------------------------------------------------
145 | method set.
146 | data object type ref to zcl_object.
147 | object ?= value.
148 | returning ?= me->values->set( index = index element = object ).
149 | endmethod.
150 |
151 |
152 | * ---------------------------------------------------------------------------------------+
153 | * | Instance Public Method ZCL_JSON_ARRAY->SIZE
154 | * +-------------------------------------------------------------------------------------------------+
155 | * | [<-()] RETURNING TYPE I
156 | * +--------------------------------------------------------------------------------------
157 | method size.
158 | returning = me->values->size( ).
159 | endmethod.
160 | ENDCLASS.
161 |
--------------------------------------------------------------------------------
/json/zcl_json_boolean.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_BOOLEAN definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 | *"* public components of class zCL_JSON_BOOLEAN
9 | *"* do not include other source files here!!!
10 | type-pools ABAP .
11 |
12 | interfaces ZIF_JSON_VALUE .
13 |
14 | aliases GET_TYPE
15 | for ZIF_JSON_VALUE~GET_TYPE .
16 |
17 | data VALUE type ABAP_BOOL read-only .
18 |
19 | methods CONSTRUCTOR
20 | importing
21 | !VALUE type ABAP_BOOL .
22 | protected section.
23 | *"* protected components of class zCL_JSON_BOOLEAN
24 | *"* do not include other source files here!!!
25 | private section.
26 | *"* private components of class zCL_JSON_BOOLEAN
27 | *"* do not include other source files here!!!
28 | ENDCLASS.
29 |
30 |
31 |
32 | CLASS ZCL_JSON_BOOLEAN IMPLEMENTATION.
33 |
34 |
35 | * ---------------------------------------------------------------------------------------+
36 | * | Instance Public Method ZCL_JSON_BOOLEAN->ZIF_JSON_VALUE~GET_TYPE
37 | * +-------------------------------------------------------------------------------------------------+
38 | * | [<-()] RETURNING TYPE I
39 | * +--------------------------------------------------------------------------------------
40 | method zif_json_value~get_type.
41 | returning = zcl_json_types=>type_boolean.
42 | endmethod.
43 |
44 |
45 | * ---------------------------------------------------------------------------------------+
46 | * | Instance Public Method ZCL_JSON_BOOLEAN->CONSTRUCTOR
47 | * +-------------------------------------------------------------------------------------------------+
48 | * | [--->] VALUE TYPE ABAP_BOOL
49 | * +--------------------------------------------------------------------------------------
50 | method constructor.
51 | super->constructor( ).
52 | me->value = value.
53 | endmethod.
54 | ENDCLASS.
55 |
--------------------------------------------------------------------------------
/json/zcl_json_null.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_NULL definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_JSON_NULL
10 | *"* do not include other source files here!!!
11 | interfaces ZIF_JSON_VALUE .
12 | protected section.
13 | *"* protected components of class zCL_JSON_NULL
14 | *"* do not include other source files here!!!
15 | private section.
16 | *"* private components of class zCL_JSON_NULL
17 | *"* do not include other source files here!!!
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCL_JSON_NULL IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCL_JSON_NULL->ZIF_JSON_VALUE~GET_TYPE
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [<-()] RETURNING TYPE I
29 | * +--------------------------------------------------------------------------------------
30 | method zif_json_value~get_type.
31 | returning = zcl_json_types=>type_null.
32 | endmethod.
33 | ENDCLASS.
34 |
--------------------------------------------------------------------------------
/json/zcl_json_number.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_NUMBER definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_JSON_NUMBER
10 | *"* do not include other source files here!!!
11 | interfaces ZIF_JSON_VALUE .
12 |
13 | aliases GET_TYPE
14 | for ZIF_JSON_VALUE~GET_TYPE .
15 |
16 | data VALUE type F read-only .
17 |
18 | methods CONSTRUCTOR
19 | importing
20 | !VALUE type F .
21 | protected section.
22 | *"* protected components of class zCL_JSON_NUMBER
23 | *"* do not include other source files here!!!
24 | private section.
25 | *"* private components of class zCL_JSON_NUMBER
26 | *"* do not include other source files here!!!
27 | ENDCLASS.
28 |
29 |
30 |
31 | CLASS ZCL_JSON_NUMBER IMPLEMENTATION.
32 |
33 |
34 | * ---------------------------------------------------------------------------------------+
35 | * | Instance Public Method ZCL_JSON_NUMBER->ZIF_JSON_VALUE~GET_TYPE
36 | * +-------------------------------------------------------------------------------------------------+
37 | * | [<-()] RETURNING TYPE I
38 | * +--------------------------------------------------------------------------------------
39 | method zif_json_value~get_type.
40 | returning = zcl_json_types=>type_number.
41 | endmethod.
42 |
43 |
44 | * ---------------------------------------------------------------------------------------+
45 | * | Instance Public Method ZCL_JSON_NUMBER->CONSTRUCTOR
46 | * +-------------------------------------------------------------------------------------------------+
47 | * | [--->] VALUE TYPE F
48 | * +--------------------------------------------------------------------------------------
49 | method constructor.
50 | super->constructor( ).
51 | me->value = value.
52 | endmethod.
53 | ENDCLASS.
54 |
--------------------------------------------------------------------------------
/json/zcl_json_object.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_OBJECT definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_JSON_OBJECT
10 | *"* do not include other source files here!!!
11 | interfaces ZIF_JSON_VALUE .
12 |
13 | aliases GET_TYPE
14 | for ZIF_JSON_VALUE~GET_TYPE .
15 |
16 | methods CONSTRUCTOR .
17 | methods ADD
18 | importing
19 | !PAIR type ref to ZCL_JSON_PAIR
20 | returning
21 | value(RETURNING) type ABAP_BOOL .
22 | methods CLEAR .
23 | methods GET
24 | importing
25 | !INDEX type I
26 | returning
27 | value(RETURNING) type ref to ZCL_JSON_PAIR .
28 | methods ITERATOR
29 | returning
30 | value(RETURNING) type ref to ZIF_ITERATOR .
31 | methods REMOVE
32 | importing
33 | !PAIR type ref to ZCL_JSON_PAIR
34 | returning
35 | value(RETURNING) type ABAP_BOOL .
36 | methods SET
37 | importing
38 | !INDEX type I
39 | !PAIR type ref to ZCL_JSON_PAIR
40 | returning
41 | value(RETURNING) type ref to ZCL_JSON_PAIR .
42 | methods SIZE
43 | returning
44 | value(RETURNING) type I .
45 | protected section.
46 | *"* protected components of class zCL_JSON_OBJECT
47 | *"* do not include other source files here!!!
48 | private section.
49 |
50 | *"* private components of class zCL_JSON_OBJECT
51 | *"* do not include other source files here!!!
52 | data PAIRS type ref to ZCL_ARRAYLIST .
53 | ENDCLASS.
54 |
55 |
56 |
57 | CLASS ZCL_JSON_OBJECT IMPLEMENTATION.
58 |
59 |
60 | * ---------------------------------------------------------------------------------------+
61 | * | Instance Public Method ZCL_JSON_OBJECT->ZIF_JSON_VALUE~GET_TYPE
62 | * +-------------------------------------------------------------------------------------------------+
63 | * | [<-()] RETURNING TYPE I
64 | * +--------------------------------------------------------------------------------------
65 | method zif_json_value~get_type.
66 | returning = zcl_json_types=>type_object.
67 | endmethod.
68 |
69 |
70 | * ---------------------------------------------------------------------------------------+
71 | * | Instance Public Method ZCL_JSON_OBJECT->ADD
72 | * +-------------------------------------------------------------------------------------------------+
73 | * | [--->] PAIR TYPE REF TO ZCL_JSON_PAIR
74 | * | [<-()] RETURNING TYPE ABAP_BOOL
75 | * +--------------------------------------------------------------------------------------
76 | method add.
77 | data object type ref to zcl_object.
78 | object = pair.
79 | returning = me->pairs->add( object ).
80 | endmethod.
81 |
82 |
83 | * ---------------------------------------------------------------------------------------+
84 | * | Instance Public Method ZCL_JSON_OBJECT->CLEAR
85 | * +-------------------------------------------------------------------------------------------------+
86 | * +--------------------------------------------------------------------------------------
87 | method clear.
88 | me->pairs->clear( ).
89 | endmethod.
90 |
91 |
92 | * ---------------------------------------------------------------------------------------+
93 | * | Instance Public Method ZCL_JSON_OBJECT->CONSTRUCTOR
94 | * +-------------------------------------------------------------------------------------------------+
95 | * +--------------------------------------------------------------------------------------
96 | method constructor.
97 | super->constructor( ).
98 | " Init pairs list
99 | create object me->pairs.
100 | endmethod.
101 |
102 |
103 | * ---------------------------------------------------------------------------------------+
104 | * | Instance Public Method ZCL_JSON_OBJECT->GET
105 | * +-------------------------------------------------------------------------------------------------+
106 | * | [--->] INDEX TYPE I
107 | * | [<-()] RETURNING TYPE REF TO ZCL_JSON_PAIR
108 | * +--------------------------------------------------------------------------------------
109 | method get.
110 | returning ?= me->pairs->get( index ).
111 | endmethod.
112 |
113 |
114 | * ---------------------------------------------------------------------------------------+
115 | * | Instance Public Method ZCL_JSON_OBJECT->ITERATOR
116 | * +-------------------------------------------------------------------------------------------------+
117 | * | [<-()] RETURNING TYPE REF TO ZIF_ITERATOR
118 | * +--------------------------------------------------------------------------------------
119 | method iterator.
120 | returning = me->pairs->iterator( ).
121 | endmethod.
122 |
123 |
124 | * ---------------------------------------------------------------------------------------+
125 | * | Instance Public Method ZCL_JSON_OBJECT->REMOVE
126 | * +-------------------------------------------------------------------------------------------------+
127 | * | [--->] PAIR TYPE REF TO ZCL_JSON_PAIR
128 | * | [<-()] RETURNING TYPE ABAP_BOOL
129 | * +--------------------------------------------------------------------------------------
130 | method remove.
131 | data object type ref to zcl_object.
132 | object = pair.
133 | returning = me->pairs->remove( object ).
134 | endmethod.
135 |
136 |
137 | * ---------------------------------------------------------------------------------------+
138 | * | Instance Public Method ZCL_JSON_OBJECT->SET
139 | * +-------------------------------------------------------------------------------------------------+
140 | * | [--->] INDEX TYPE I
141 | * | [--->] PAIR TYPE REF TO ZCL_JSON_PAIR
142 | * | [<-()] RETURNING TYPE REF TO ZCL_JSON_PAIR
143 | * +--------------------------------------------------------------------------------------
144 | method set.
145 | data object type ref to zcl_object.
146 | object = pair.
147 | returning ?= me->pairs->set( index = index element = object ).
148 | endmethod.
149 |
150 |
151 | * ---------------------------------------------------------------------------------------+
152 | * | Instance Public Method ZCL_JSON_OBJECT->SIZE
153 | * +-------------------------------------------------------------------------------------------------+
154 | * | [<-()] RETURNING TYPE I
155 | * +--------------------------------------------------------------------------------------
156 | method size.
157 | returning = me->pairs->size( ).
158 | endmethod.
159 | ENDCLASS.
160 |
--------------------------------------------------------------------------------
/json/zcl_json_pair.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_PAIR definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_JSON_PAIR
10 | *"* do not include other source files here!!!
11 | data NAME type ref to ZCL_JSON_STRING read-only .
12 | data VALUE type ref to ZIF_JSON_VALUE read-only .
13 |
14 | methods CONSTRUCTOR
15 | importing
16 | !NAME type ref to ZCL_JSON_STRING
17 | !VALUE type ref to ZIF_JSON_VALUE .
18 | protected section.
19 | *"* protected components of class zCL_JSON_PAIR
20 | *"* do not include other source files here!!!
21 | private section.
22 | *"* private components of class zCL_JSON_PAIR
23 | *"* do not include other source files here!!!
24 | ENDCLASS.
25 |
26 |
27 |
28 | CLASS ZCL_JSON_PAIR IMPLEMENTATION.
29 |
30 |
31 | * ---------------------------------------------------------------------------------------+
32 | * | Instance Public Method ZCL_JSON_PAIR->CONSTRUCTOR
33 | * +-------------------------------------------------------------------------------------------------+
34 | * | [--->] NAME TYPE REF TO ZCL_JSON_STRING
35 | * | [--->] VALUE TYPE REF TO ZIF_JSON_VALUE
36 | * +--------------------------------------------------------------------------------------
37 | method constructor.
38 | super->constructor( ).
39 | me->name = name.
40 | me->value = value.
41 | endmethod.
42 | ENDCLASS.
43 |
--------------------------------------------------------------------------------
/json/zcl_json_string.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_STRING definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_JSON_STRING
10 | *"* do not include other source files here!!!
11 | interfaces ZIF_JSON_VALUE .
12 |
13 | aliases GET_TYPE
14 | for ZIF_JSON_VALUE~GET_TYPE .
15 |
16 | data VALUE type STRING read-only .
17 |
18 | methods CONSTRUCTOR
19 | importing
20 | !VALUE type STRING .
21 | protected section.
22 | *"* protected components of class zCL_JSON_STRING
23 | *"* do not include other source files here!!!
24 | private section.
25 | *"* private components of class zCL_JSON_STRING
26 | *"* do not include other source files here!!!
27 | ENDCLASS.
28 |
29 |
30 |
31 | CLASS ZCL_JSON_STRING IMPLEMENTATION.
32 |
33 |
34 | * ---------------------------------------------------------------------------------------+
35 | * | Instance Public Method ZCL_JSON_STRING->ZIF_JSON_VALUE~GET_TYPE
36 | * +-------------------------------------------------------------------------------------------------+
37 | * | [<-()] RETURNING TYPE I
38 | * +--------------------------------------------------------------------------------------
39 | method zif_json_value~get_type.
40 | returning = zcl_json_types=>type_string.
41 | endmethod.
42 |
43 |
44 | * ---------------------------------------------------------------------------------------+
45 | * | Instance Public Method ZCL_JSON_STRING->CONSTRUCTOR
46 | * +-------------------------------------------------------------------------------------------------+
47 | * | [--->] VALUE TYPE STRING
48 | * +--------------------------------------------------------------------------------------
49 | method constructor.
50 | super->constructor( ).
51 | me->value = value.
52 | endmethod.
53 | ENDCLASS.
54 |
--------------------------------------------------------------------------------
/json/zcl_json_types.abap:
--------------------------------------------------------------------------------
1 | class ZCL_JSON_TYPES definition
2 | public
3 | final
4 | create public .
5 |
6 | public section.
7 |
8 | *"* public components of class zCL_JSON_TYPES
9 | *"* do not include other source files here!!!
10 | constants TYPE_STRING type I value 1. "#EC NOTEXT
11 | constants TYPE_NUMBER type I value 2. "#EC NOTEXT
12 | constants TYPE_BOOLEAN type I value 3. "#EC NOTEXT
13 | constants TYPE_NULL type I value 4. "#EC NOTEXT
14 | constants TYPE_OBJECT type I value 5. "#EC NOTEXT
15 | constants TYPE_ARRAY type I value 6. "#EC NOTEXT
16 | protected section.
17 | *"* protected components of class zCL_JSON_TYPES
18 | *"* do not include other source files here!!!
19 | private section.
20 | *"* private components of class zCL_JSON_TYPES
21 | *"* do not include other source files here!!!
22 | ENDCLASS.
23 |
24 |
25 |
26 | CLASS ZCL_JSON_TYPES IMPLEMENTATION.
27 | ENDCLASS.
28 |
--------------------------------------------------------------------------------
/json/zcx_json_parse_error.abap:
--------------------------------------------------------------------------------
1 | class ZCX_JSON_PARSE_ERROR definition
2 | public
3 | inheriting from ZCX_STATICEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_JSON_PARSE_ERROR type SOTR_CONC value '00155D334B0D1EE2B8FE494E09B42991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_JSON_PARSE_ERROR IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_JSON_PARSE_ERROR->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_JSON_PARSE_ERROR .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/json/zif_json_value.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_JSON_VALUE
2 | public .
3 |
4 |
5 | methods GET_TYPE
6 | returning
7 | value(RETURNING) type I .
8 | endinterface.
9 |
--------------------------------------------------------------------------------
/lang/zcl_object.abap:
--------------------------------------------------------------------------------
1 | class ZCL_OBJECT definition
2 | public
3 | create public .
4 |
5 | public section.
6 | *"* public components of class zCL_OBJECT
7 | *"* do not include other source files here!!!
8 | type-pools ABAP .
9 |
10 | methods CLONE
11 | returning
12 | value(RETURNING) type ref to ZCL_OBJECT .
13 | methods EQUALS
14 | importing
15 | !OBJ type ref to ZCL_OBJECT
16 | returning
17 | value(RETURNING) type ABAP_BOOL .
18 | methods GETCLASS
19 | final
20 | returning
21 | value(RETURNING) type ref to CL_ABAP_OBJECTDESCR .
22 | protected section.
23 | *"* protected components of class zCL_OBJECT
24 | *"* do not include other source files here!!!
25 | private section.
26 | *"* private components of class zCL_OBJECT
27 | *"* do not include other source files here!!!
28 | ENDCLASS.
29 |
30 |
31 |
32 | CLASS ZCL_OBJECT IMPLEMENTATION.
33 |
34 |
35 | * ---------------------------------------------------------------------------------------+
36 | * | Instance Public Method ZCL_OBJECT->CLONE
37 | * +-------------------------------------------------------------------------------------------------+
38 | * | [<-()] RETURNING TYPE REF TO ZCL_OBJECT
39 | * +--------------------------------------------------------------------------------------
40 | method clone.
41 | raise exception type zcx_clonenotsupported.
42 |
43 | " Any implementation of this method MUST follow these rules:
44 | " - TRUE: x->clone( ) <> x
45 | " - TRUE: x->clone( )->getclass( ) = x->getclass( )
46 | " - TRUE: x->clone( )->equals( x )
47 | " - The clone object should be independent of the original object, which means
48 | " you must also clone all mutable objects which comprise the internal "deep structure"
49 | " of the object being cloned.
50 | " - In case of arrays only the array object must be cloned and not the objects inside
51 | " the array, resulting in a "shallow copy"
52 | "
53 | " IMPORTANT
54 | " This method does NOT behave like it does in Java.
55 | " The difference is, it will NEVER return an instance of an object (in Java, when a class
56 | " implements the Cloneable interface, this method will return an instance of that class).
57 | " This means you CANNOT rely on calling super->clone( ) to get an instance,
58 | " if none of the superclasses implement the clone( ) method.
59 | " In practice, this means you will have to create the instance yourself if you want to
60 | " make your objects cloneable. In the case of abstract classes this won't be possible,
61 | " which means you cannot use super->clone( ) and you have to write an implementation in
62 | " each concrete subclass.
63 |
64 | endmethod.
65 |
66 |
67 | * ---------------------------------------------------------------------------------------+
68 | * | Instance Public Method ZCL_OBJECT->EQUALS
69 | * +-------------------------------------------------------------------------------------------------+
70 | * | [--->] OBJ TYPE REF TO ZCL_OBJECT
71 | * | [<-()] RETURNING TYPE ABAP_BOOL
72 | * +--------------------------------------------------------------------------------------
73 | method equals.
74 | " Only compare reference by default
75 | if me = obj.
76 | returning = abap_true.
77 | return.
78 | else.
79 | returning = abap_false.
80 | return.
81 | endif.
82 |
83 | " Override this method to implement a more specific comparison.
84 |
85 | endmethod.
86 |
87 |
88 | * ---------------------------------------------------------------------------------------+
89 | * | Instance Public Method ZCL_OBJECT->GETCLASS
90 | * +-------------------------------------------------------------------------------------------------+
91 | * | [<-()] RETURNING TYPE REF TO CL_ABAP_OBJECTDESCR
92 | * +--------------------------------------------------------------------------------------
93 | method getclass.
94 | returning ?= cl_abap_typedescr=>describe_by_object_ref( me ).
95 | endmethod.
96 | ENDCLASS.
97 |
--------------------------------------------------------------------------------
/lang/zcl_string_distance.abap:
--------------------------------------------------------------------------------
1 | class ZCL_STRING_DISTANCE definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_STRING_DISTANCE
10 | *"* do not include other source files here!!!
11 | class-methods DISTANCE
12 | importing
13 | !STRING1 type STRING
14 | !STRING2 type STRING
15 | returning
16 | value(RETURNING) type I .
17 | protected section.
18 | *"* protected components of class zCL_STRING_DISTANCE
19 | *"* do not include other source files here!!!
20 | private section.
21 |
22 | *"* private components of class zCL_STRING_DISTANCE
23 | *"* do not include other source files here!!!
24 | class-methods _MIN
25 | importing
26 | !INT1 type I
27 | !INT2 type I
28 | !INT3 type I
29 | returning
30 | value(RETURNING) type I .
31 | ENDCLASS.
32 |
33 |
34 |
35 | CLASS ZCL_STRING_DISTANCE IMPLEMENTATION.
36 |
37 |
38 | * ---------------------------------------------------------------------------------------+
39 | * | Static Public Method ZCL_STRING_DISTANCE=>DISTANCE
40 | * +-------------------------------------------------------------------------------------------------+
41 | * | [--->] STRING1 TYPE STRING
42 | * | [--->] STRING2 TYPE STRING
43 | * | [<-()] RETURNING TYPE I
44 | * +--------------------------------------------------------------------------------------
45 | method distance.
46 | types: begin of ty_row,
47 | value type standard table of i with default key,
48 | end of ty_row.
49 | data distance_table_row type ty_row.
50 | data distance_table type standard table of ty_row.
51 |
52 | data col_count type i.
53 | col_count = strlen( string2 ) + 1.
54 | data row_count type i.
55 | row_count = strlen( string1 ).
56 |
57 | " Create first row
58 | data value type i.
59 | value = 0.
60 | do col_count times.
61 | append value to distance_table_row-value.
62 | value = value + 1.
63 | enddo.
64 | append distance_table_row to distance_table.
65 | clear distance_table_row.
66 |
67 | " Create next rows
68 | value = 0.
69 | do row_count times.
70 | value = value + 1.
71 | data is_first type abap_bool.
72 | is_first = abap_true.
73 | do col_count times.
74 | if is_first = abap_true.
75 | append value to distance_table_row-value.
76 | is_first = abap_false.
77 | else.
78 | append 0 to distance_table_row-value.
79 | endif.
80 | enddo.
81 | append distance_table_row to distance_table.
82 | clear distance_table_row.
83 | enddo.
84 |
85 | " Calculate distances
86 | data counter_rows type i.
87 | data counter_cols type i.
88 | field-symbols type i.
89 | field-symbols type ty_row.
90 | counter_rows = 1.
91 | loop at distance_table assigning .
92 | if counter_rows = 1.
93 | counter_rows = counter_rows + 1.
94 | continue.
95 | endif.
96 | counter_cols = 0.
97 | do col_count times.
98 | counter_cols = counter_cols + 1.
99 | if counter_cols = 1. " Skip first column
100 | continue.
101 | endif.
102 | read table -value assigning index counter_cols.
103 |
104 | data previous_row type i.
105 | previous_row = counter_rows - 1.
106 | data previous_col type i.
107 | previous_col = counter_cols - 1.
108 |
109 | " Distance previous row
110 | data dist1 type i.
111 | field-symbols type ty_row.
112 | field-symbols type i.
113 | read table distance_table assigning index previous_row.
114 | read table -value assigning index counter_cols.
115 | dist1 = + 1.
116 |
117 | " Distance previous column
118 | data dist2 type i.
119 | field-symbols type i.
120 | read table -value assigning index previous_col.
121 | dist2 = + 1.
122 |
123 | " Distance previous row and column
124 | data dist3 type i.
125 | field-symbols type i.
126 | read table -value assigning index previous_col.
127 | data char_pos1 type i.
128 | char_pos1 = previous_row - 1.
129 | data char_pos2 type i.
130 | char_pos2 = previous_col - 1.
131 | if string1+char_pos1(1) = string2+char_pos2(1).
132 | dist3 = .
133 | else.
134 | dist3 = + 1.
135 | endif.
136 |
137 | " Use minimum distance
138 | = _min( int1 = dist1 int2 = dist2 int3 = dist3 ).
139 |
140 | enddo.
141 | counter_rows = counter_rows + 1.
142 | endloop.
143 |
144 | field-symbols type i.
145 | data row type i.
146 | row = row_count.
147 | data col type i.
148 | col = strlen( string2 ).
149 | read table distance_table assigning index row.
150 | read table -value assigning index col.
151 | if is not assigned.
152 | returning = 0.
153 | else.
154 | returning = .
155 | endif.
156 |
157 | endmethod.
158 |
159 |
160 | * ---------------------------------------------------------------------------------------+
161 | * | Static Private Method ZCL_STRING_DISTANCE=>_MIN
162 | * +-------------------------------------------------------------------------------------------------+
163 | * | [--->] INT1 TYPE I
164 | * | [--->] INT2 TYPE I
165 | * | [--->] INT3 TYPE I
166 | * | [<-()] RETURNING TYPE I
167 | * +--------------------------------------------------------------------------------------
168 | method _min.
169 | data result type i.
170 | if int1 < int2.
171 | result = int1.
172 | else.
173 | result = int2.
174 | endif.
175 | if int3 < result.
176 | result = int3.
177 | endif.
178 | returning = result.
179 | endmethod.
180 | ENDCLASS.
181 |
--------------------------------------------------------------------------------
/lang/zcx_clonenotsupported.abap:
--------------------------------------------------------------------------------
1 | class ZCX_CLONENOTSUPPORTED definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_CLONENOTSUPPORTED type SOTR_CONC value '00155D334B0D1EE2B8FD3A94F7EE2991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_CLONENOTSUPPORTED IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_CLONENOTSUPPORTED->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_CLONENOTSUPPORTED .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/lang/zcx_illegalargument.abap:
--------------------------------------------------------------------------------
1 | class ZCX_ILLEGALARGUMENT definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_ILLEGALARGUMENT type SOTR_CONC value '00155D334B0D1EE2B8FD402EC389C991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_ILLEGALARGUMENT IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_ILLEGALARGUMENT->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_ILLEGALARGUMENT .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/lang/zcx_illegalstate.abap:
--------------------------------------------------------------------------------
1 | class ZCX_ILLEGALSTATE definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_ILLEGALSTATE type SOTR_CONC value '00155D334B0D1EE2B8FD3D2374DAA991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_ILLEGALSTATE IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_ILLEGALSTATE->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_ILLEGALSTATE .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/lang/zcx_indexoutofbounds.abap:
--------------------------------------------------------------------------------
1 | class ZCX_INDEXOUTOFBOUNDS definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_INDEXOUTOFBOUNDS type SOTR_CONC value '00155D334B0D1EE2B8FD3C3528670991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_INDEXOUTOFBOUNDS IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_INDEXOUTOFBOUNDS->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_INDEXOUTOFBOUNDS .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/lang/zcx_runtimeexception.abap:
--------------------------------------------------------------------------------
1 | class ZCX_RUNTIMEEXCEPTION definition
2 | public
3 | inheriting from CX_NO_CHECK
4 | create public .
5 |
6 | public section.
7 |
8 | constants ZCX_RUNTIMEEXCEPTION type SOTR_CONC value '00155D334B0D1EE2B8FD2B3F667A8991'. "#EC NOTEXT
9 | data MESSAGE type STRING read-only .
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_RUNTIMEEXCEPTION IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_RUNTIMEEXCEPTION->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | .
38 | IF textid IS INITIAL.
39 | me->textid = ZCX_RUNTIMEEXCEPTION .
40 | ENDIF.
41 | me->MESSAGE = MESSAGE .
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/lang/zcx_staticexception.abap:
--------------------------------------------------------------------------------
1 | class ZCX_STATICEXCEPTION definition
2 | public
3 | inheriting from CX_STATIC_CHECK
4 | create public .
5 |
6 | public section.
7 |
8 | constants ZCX_STATICEXCEPTION type SOTR_CONC value '00155D334B0D1EE2B8FD2F95F2326991'. "#EC NOTEXT
9 | data MESSAGE type STRING read-only .
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_STATICEXCEPTION IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_STATICEXCEPTION->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | .
38 | IF textid IS INITIAL.
39 | me->textid = ZCX_STATICEXCEPTION .
40 | ENDIF.
41 | me->MESSAGE = MESSAGE .
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/lang/zcx_unsupportedoperation.abap:
--------------------------------------------------------------------------------
1 | class ZCX_UNSUPPORTEDOPERATION definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_UNSUPPORTEDOPERATION type SOTR_CONC value '00155D334B0D1EE2B8FD3C3528612991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_UNSUPPORTEDOPERATION IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_UNSUPPORTEDOPERATION->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_UNSUPPORTEDOPERATION .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/logging/log.messageclass.txt:
--------------------------------------------------------------------------------
1 | 000 & & & &
2 | 001 & & & &
3 | 002 Log entry not found
4 | 004 No log object specified
5 | 005 No log subobject specified
6 | 007 No log number specified
7 | 008 Error creating log
8 | 010 No message specified
9 | 011 No message type specified
10 | 012 Error updating log
--------------------------------------------------------------------------------
/logging/zcl_log_viewer.abap:
--------------------------------------------------------------------------------
1 | class /OOD/CL_LOG_VIEWER definition
2 | public
3 | inheriting from /OOD/CL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 | *"* public components of class /OOD/CL_LOG_VIEWER
9 | *"* do not include other source files here!!!
10 |
11 | data DISPLAY_PROFILE type BAL_S_PROF .
12 |
13 | methods CONSTRUCTOR .
14 | methods DISPLAY
15 | importing
16 | !LOGGER type ref to /OOD/CL_LOGGER .
17 | methods DISPLAY_LIST
18 | importing
19 | !LOGGER_LIST type ref to /OOD/IF_LIST .
20 | methods SET_DISPLAY_PROFILE
21 | importing
22 | !DISPLAY_PROFILE type BAL_S_PROF .
23 | methods SET_DISPLAY_DEFAULT .
24 | methods SET_DISPLAY_POPUP .
25 | methods SET_DISPLAY_NO_TREE .
26 | protected section.
27 | *"* protected components of class /OOD/CL_LOG_VIEWER
28 | *"* do not include other source files here!!!
29 | private section.
30 | *"* private components of class /OOD/CL_LOG_VIEWER
31 | *"* do not include other source files here!!!
32 |
33 | methods _GET_HANDLES
34 | importing
35 | !LOGGER type ref to /OOD/CL_LOGGER
36 | returning
37 | value(RETURNING) type BAL_T_LOGH .
38 | methods _DISPLAY_WITH_HANDLES
39 | importing
40 | !HANDLES type BAL_T_LOGH .
41 | ENDCLASS.
42 |
43 |
44 |
45 | CLASS /OOD/CL_LOG_VIEWER IMPLEMENTATION.
46 |
47 |
48 | * ---------------------------------------------------------------------------------------+
49 | * | Instance Public Method /OOD/CL_LOG_VIEWER->CONSTRUCTOR
50 | * +-------------------------------------------------------------------------------------------------+
51 | * +--------------------------------------------------------------------------------------
52 | method constructor.
53 | super->constructor( ).
54 |
55 | " Init display profile
56 | set_display_default( ).
57 |
58 | endmethod.
59 |
60 |
61 | * ---------------------------------------------------------------------------------------+
62 | * | Instance Public Method /OOD/CL_LOG_VIEWER->DISPLAY
63 | * +-------------------------------------------------------------------------------------------------+
64 | * | [--->] LOGGER TYPE REF TO /OOD/CL_LOGGER
65 | * +--------------------------------------------------------------------------------------
66 | method display.
67 | data: handles type bal_t_logh.
68 |
69 | handles = _get_handles( logger ).
70 |
71 | if handles is not initial.
72 | _display_with_handles( handles ).
73 | endif.
74 |
75 | endmethod.
76 |
77 |
78 | * ---------------------------------------------------------------------------------------+
79 | * | Instance Public Method /OOD/CL_LOG_VIEWER->DISPLAY_LIST
80 | * +-------------------------------------------------------------------------------------------------+
81 | * | [--->] LOGGER_LIST TYPE REF TO /OOD/IF_LIST
82 | * +--------------------------------------------------------------------------------------
83 | method display_list.
84 | data: logger_list_iterator type ref to /ood/if_iterator,
85 | logger type ref to /ood/cl_logger,
86 | handles type bal_t_logh,
87 | handles_list type bal_t_logh.
88 |
89 | logger_list_iterator = logger_list->iterator( ).
90 | while logger_list_iterator->hasnext( ) = abap_true.
91 | logger ?= logger_list_iterator->next( ).
92 | handles = _get_handles( logger ).
93 | insert lines of handles into table handles_list.
94 | endwhile.
95 |
96 | if handles_list is not initial.
97 | _display_with_handles( handles_list ).
98 | endif.
99 |
100 | endmethod.
101 |
102 |
103 | * ---------------------------------------------------------------------------------------+
104 | * | Instance Public Method /OOD/CL_LOG_VIEWER->SET_DISPLAY_DEFAULT
105 | * +-------------------------------------------------------------------------------------------------+
106 | * +--------------------------------------------------------------------------------------
107 | method set_display_default.
108 | call function 'BAL_DSP_PROFILE_STANDARD_GET'
109 | importing
110 | e_s_display_profile = me->display_profile.
111 | me->display_profile-exp_level = '2'.
112 | me->display_profile-show_all = 'X'.
113 | endmethod.
114 |
115 |
116 | * ---------------------------------------------------------------------------------------+
117 | * | Instance Public Method /OOD/CL_LOG_VIEWER->SET_DISPLAY_NO_TREE
118 | * +-------------------------------------------------------------------------------------------------+
119 | * +--------------------------------------------------------------------------------------
120 | method set_display_no_tree.
121 | call function 'BAL_DSP_PROFILE_NO_TREE_GET'
122 | importing
123 | e_s_display_profile = me->display_profile.
124 | endmethod.
125 |
126 |
127 | * ---------------------------------------------------------------------------------------+
128 | * | Instance Public Method /OOD/CL_LOG_VIEWER->SET_DISPLAY_POPUP
129 | * +-------------------------------------------------------------------------------------------------+
130 | * +--------------------------------------------------------------------------------------
131 | method set_display_popup.
132 | call function 'BAL_DSP_PROFILE_POPUP_GET'
133 | importing
134 | e_s_display_profile = me->display_profile.
135 | endmethod.
136 |
137 |
138 | * ---------------------------------------------------------------------------------------+
139 | * | Instance Public Method /OOD/CL_LOG_VIEWER->SET_DISPLAY_PROFILE
140 | * +-------------------------------------------------------------------------------------------------+
141 | * | [--->] DISPLAY_PROFILE TYPE BAL_S_PROF
142 | * +--------------------------------------------------------------------------------------
143 | method set_display_profile.
144 | if display_profile is not initial.
145 | me->display_profile = display_profile.
146 | endif.
147 | endmethod.
148 |
149 |
150 | * ---------------------------------------------------------------------------------------+
151 | * | Instance Private Method /OOD/CL_LOG_VIEWER->_DISPLAY_WITH_HANDLES
152 | * +-------------------------------------------------------------------------------------------------+
153 | * | [--->] HANDLES TYPE BAL_T_LOGH
154 | * +--------------------------------------------------------------------------------------
155 | method _display_with_handles.
156 | data: handle type balloghndl.
157 |
158 | " Display log
159 | call function 'BAL_DSP_LOG_DISPLAY'
160 | exporting
161 | i_s_display_profile = display_profile
162 | i_t_log_handle = handles
163 | exceptions
164 | profile_inconsistent = 1
165 | internal_error = 2
166 | no_data_available = 3
167 | no_authority = 4
168 | others = 5.
169 | if sy-subrc <> 0.
170 | return.
171 | endif.
172 |
173 | " Clear memory after displaying
174 | loop at handles into handle.
175 | call function 'BAL_LOG_REFRESH'
176 | exporting
177 | i_log_handle = handle
178 | exceptions
179 | log_not_found = 1
180 | others = 2.
181 | if sy-subrc <> 0.
182 | continue.
183 | endif.
184 | endloop.
185 |
186 | endmethod.
187 |
188 |
189 | * ---------------------------------------------------------------------------------------+
190 | * | Instance Private Method /OOD/CL_LOG_VIEWER->_GET_HANDLES
191 | * +-------------------------------------------------------------------------------------------------+
192 | * | [--->] LOGGER TYPE REF TO /OOD/CL_LOGGER
193 | * | [<-()] RETURNING TYPE BAL_T_LOGH
194 | * +--------------------------------------------------------------------------------------
195 | method _GET_HANDLES.
196 | data: log_number type balognr,
197 | i_t_lognumber type bal_t_logn,
198 | e_t_log_handle type bal_t_logh.
199 |
200 | log_number = logger->get_log_number( ).
201 | if log_number is not initial.
202 | insert log_number into table i_t_lognumber.
203 | call function 'BAL_DB_LOAD'
204 | exporting
205 | i_t_lognumber = i_t_lognumber
206 | importing
207 | e_t_log_handle = e_t_log_handle
208 | exceptions
209 | no_logs_specified = 1
210 | log_not_found = 2
211 | log_already_loaded = 3
212 | others = 4.
213 | if sy-subrc <> 0.
214 | return.
215 | endif.
216 | returning = e_t_log_handle.
217 | endif.
218 | endmethod.
219 | ENDCLASS.
--------------------------------------------------------------------------------
/logging/zcl_logger.abap:
--------------------------------------------------------------------------------
1 | class ZCL_LOGGER definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create private
6 |
7 | global friends ZCL_LOGGER_FACTORY
8 | ZIF_LOGGING_REPOSITORY .
9 |
10 | public section.
11 |
12 | methods INFO
13 | importing
14 | !MESSAGE type STRING .
15 | methods WARNING
16 | importing
17 | !MESSAGE type STRING .
18 | methods ERROR
19 | importing
20 | !MESSAGE type STRING .
21 | methods SUCCESS
22 | importing
23 | !MESSAGE type STRING .
24 | methods FROM_BAPI_MESSAGE
25 | importing
26 | !BAPIRET type BAPIRET2 .
27 | methods FROM_BAPI_MESSAGE_TABLE
28 | importing
29 | !BAPIRETTAB type BAPIRET2_T .
30 | methods GET_OBJECT
31 | returning
32 | value(RETURNING) type BALOBJ_D .
33 | methods GET_SUBOBJECT
34 | returning
35 | value(RETURNING) type BALSUBOBJ .
36 | methods GET_LOG_NUMBER
37 | returning
38 | value(RETURNING) type BALOGNR .
39 | protected section.
40 | *"* protected components of class zCL_LOGGER
41 | *"* do not include other source files here!!!
42 | private section.
43 |
44 | *"* private components of class zCL_LOGGER
45 | *"* do not include other source files here!!!
46 | data LOG_OBJECT type BALOBJ_D .
47 | data LOG_SUBOBJECT type BALSUBOBJ .
48 | data LOG_NUMBER type BALOGNR .
49 | data LOGGING_REPOSITORY type ref to ZCL_LOGGING_REPO_HTTP .
50 |
51 | methods CONSTRUCTOR
52 | importing
53 | !LOG_OBJECT type BALOBJ_D
54 | !LOG_SUBOBJECT type BALSUBOBJ
55 | !LOG_NUMBER type BALOGNR optional .
56 | methods ADD_MESSAGE
57 | importing
58 | !LOG_MESSAGE type STRING
59 | !LOG_MESSAGE_TYPE type SYMSGTY .
60 | ENDCLASS.
61 |
62 |
63 |
64 | CLASS ZCL_LOGGER IMPLEMENTATION.
65 |
66 |
67 | * ---------------------------------------------------------------------------------------+
68 | * | Instance Private Method ZCL_LOGGER->ADD_MESSAGE
69 | * +-------------------------------------------------------------------------------------------------+
70 | * | [--->] LOG_MESSAGE TYPE STRING
71 | * | [--->] LOG_MESSAGE_TYPE TYPE SYMSGTY
72 | * +--------------------------------------------------------------------------------------
73 | method add_message.
74 | if me->log_number is initial.
75 | me->log_number = me->logging_repository->create( log_object = me->log_object log_subobject = me->log_subobject ).
76 | endif.
77 | me->logging_repository->update( log_number = me->log_number log_message = log_message log_message_type = log_message_type ).
78 | endmethod.
79 |
80 |
81 | * ---------------------------------------------------------------------------------------+
82 | * | Instance Private Method ZCL_LOGGER->CONSTRUCTOR
83 | * +-------------------------------------------------------------------------------------------------+
84 | * | [--->] LOG_OBJECT TYPE BALOBJ_D
85 | * | [--->] LOG_SUBOBJECT TYPE BALSUBOBJ
86 | * | [--->] LOG_NUMBER TYPE BALOGNR(optional)
87 | * +--------------------------------------------------------------------------------------
88 | method constructor.
89 | super->constructor( ).
90 | if log_object is initial or log_subobject is initial.
91 | raise exception type zcx_logging_error.
92 | endif.
93 | " Set log objects
94 | me->log_object = log_object.
95 | me->log_subobject = log_subobject.
96 | me->log_number = log_number.
97 | " Init client
98 | create object me->logging_repository.
99 | endmethod.
100 |
101 |
102 | * ---------------------------------------------------------------------------------------+
103 | * | Instance Public Method ZCL_LOGGER->ERROR
104 | * +-------------------------------------------------------------------------------------------------+
105 | * | [--->] MESSAGE TYPE STRING
106 | * +--------------------------------------------------------------------------------------
107 | method error.
108 | me->add_message( log_message = message log_message_type = 'E' ).
109 | endmethod.
110 |
111 |
112 | * ---------------------------------------------------------------------------------------+
113 | * | Instance Public Method ZCL_LOGGER->FROM_BAPI_MESSAGE
114 | * +-------------------------------------------------------------------------------------------------+
115 | * | [--->] BAPIRET TYPE BAPIRET2
116 | * +--------------------------------------------------------------------------------------
117 | method from_bapi_message.
118 | data message type string.
119 | message = bapiret-message.
120 | me->add_message( log_message = message log_message_type = bapiret-type ).
121 | endmethod.
122 |
123 |
124 | * ---------------------------------------------------------------------------------------+
125 | * | Instance Public Method ZCL_LOGGER->FROM_BAPI_MESSAGE_TABLE
126 | * +-------------------------------------------------------------------------------------------------+
127 | * | [--->] BAPIRETTAB TYPE BAPIRET2_T
128 | * +--------------------------------------------------------------------------------------
129 | method from_bapi_message_table.
130 | data bapiret type bapiret2.
131 | loop at bapirettab into bapiret.
132 | me->from_bapi_message( bapiret ).
133 | endloop.
134 | endmethod.
135 |
136 |
137 | * ---------------------------------------------------------------------------------------+
138 | * | Instance Public Method ZCL_LOGGER->GET_LOG_NUMBER
139 | * +-------------------------------------------------------------------------------------------------+
140 | * | [<-()] RETURNING TYPE BALOGNR
141 | * +--------------------------------------------------------------------------------------
142 | method get_log_number.
143 | returning = me->log_number.
144 | endmethod.
145 |
146 |
147 | * ---------------------------------------------------------------------------------------+
148 | * | Instance Public Method ZCL_LOGGER->GET_OBJECT
149 | * +-------------------------------------------------------------------------------------------------+
150 | * | [<-()] RETURNING TYPE BALOBJ_D
151 | * +--------------------------------------------------------------------------------------
152 | method get_object.
153 | returning = me->log_object.
154 | endmethod.
155 |
156 |
157 | * ---------------------------------------------------------------------------------------+
158 | * | Instance Public Method ZCL_LOGGER->GET_SUBOBJECT
159 | * +-------------------------------------------------------------------------------------------------+
160 | * | [<-()] RETURNING TYPE BALSUBOBJ
161 | * +--------------------------------------------------------------------------------------
162 | method get_subobject.
163 | returning = me->log_subobject.
164 | endmethod.
165 |
166 |
167 | * ---------------------------------------------------------------------------------------+
168 | * | Instance Public Method ZCL_LOGGER->INFO
169 | * +-------------------------------------------------------------------------------------------------+
170 | * | [--->] MESSAGE TYPE STRING
171 | * +--------------------------------------------------------------------------------------
172 | method info.
173 | me->add_message( log_message = message log_message_type = 'I' ).
174 | endmethod.
175 |
176 |
177 | * ---------------------------------------------------------------------------------------+
178 | * | Instance Public Method ZCL_LOGGER->SUCCESS
179 | * +-------------------------------------------------------------------------------------------------+
180 | * | [--->] MESSAGE TYPE STRING
181 | * +--------------------------------------------------------------------------------------
182 | method success.
183 | me->add_message( log_message = message log_message_type = 'S' ).
184 | endmethod.
185 |
186 |
187 | * ---------------------------------------------------------------------------------------+
188 | * | Instance Public Method ZCL_LOGGER->WARNING
189 | * +-------------------------------------------------------------------------------------------------+
190 | * | [--->] MESSAGE TYPE STRING
191 | * +--------------------------------------------------------------------------------------
192 | method warning.
193 | me->add_message( log_message = message log_message_type = 'W' ).
194 | endmethod.
195 | ENDCLASS.
196 |
--------------------------------------------------------------------------------
/logging/zcl_logger_factory.abap:
--------------------------------------------------------------------------------
1 | class ZCL_LOGGER_FACTORY definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create private .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_LOGGER_FACTORY
10 | *"* do not include other source files here!!!
11 | class-methods CREATE_CUSTOM_LOG
12 | importing
13 | !OBJECT type BALOBJ_D
14 | !SUBOBJECT type BALSUBOBJ
15 | returning
16 | value(RETURNING) type ref to ZCL_LOGGER .
17 | class-methods GET_EXISTING_LOG
18 | importing
19 | !LOG_NUMBER type BALOGNR
20 | returning
21 | value(RETURNING) type ref to ZCL_LOGGER .
22 | class-methods GET_SESSION_LOG
23 | importing
24 | !OBJECT type BALOBJ_D optional
25 | !SUBOBJECT type BALSUBOBJ optional
26 | returning
27 | value(RETURNING) type ref to ZCL_LOGGER .
28 | protected section.
29 | *"* protected components of class zCL_LOGGER_FACTORY
30 | *"* do not include other source files here!!!
31 | private section.
32 |
33 | *"* private components of class zCL_LOGGER_FACTORY
34 | *"* do not include other source files here!!!
35 | class-data LOGGER type ref to ZCL_LOGGER .
36 | ENDCLASS.
37 |
38 |
39 |
40 | CLASS ZCL_LOGGER_FACTORY IMPLEMENTATION.
41 |
42 |
43 | * ---------------------------------------------------------------------------------------+
44 | * | Static Public Method ZCL_LOGGER_FACTORY=>CREATE_CUSTOM_LOG
45 | * +-------------------------------------------------------------------------------------------------+
46 | * | [--->] OBJECT TYPE BALOBJ_D
47 | * | [--->] SUBOBJECT TYPE BALSUBOBJ
48 | * | [<-()] RETURNING TYPE REF TO ZCL_LOGGER
49 | * +--------------------------------------------------------------------------------------
50 | method create_custom_log.
51 | data custom_logger type ref to zcl_logger.
52 | create object custom_logger
53 | exporting
54 | log_object = object
55 | log_subobject = subobject.
56 | returning = custom_logger.
57 | endmethod.
58 |
59 |
60 | * ---------------------------------------------------------------------------------------+
61 | * | Static Public Method ZCL_LOGGER_FACTORY=>GET_EXISTING_LOG
62 | * +-------------------------------------------------------------------------------------------------+
63 | * | [--->] LOG_NUMBER TYPE BALOGNR
64 | * | [<-()] RETURNING TYPE REF TO ZCL_LOGGER
65 | * +--------------------------------------------------------------------------------------
66 | method get_existing_log.
67 | data logging_repository type ref to zcl_logging_repo_http.
68 | create object logging_repository.
69 | returning = logging_repository->find_by_id( log_number ).
70 | endmethod.
71 |
72 |
73 | * ---------------------------------------------------------------------------------------+
74 | * | Static Public Method ZCL_LOGGER_FACTORY=>GET_SESSION_LOG
75 | * +-------------------------------------------------------------------------------------------------+
76 | * | [--->] OBJECT TYPE BALOBJ_D(optional)
77 | * | [--->] SUBOBJECT TYPE BALSUBOBJ(optional)
78 | * | [<-()] RETURNING TYPE REF TO ZCL_LOGGER
79 | * +--------------------------------------------------------------------------------------
80 | method get_session_log.
81 | if zcl_logger_factory=>logger is not bound.
82 | zcl_logger_factory=>logger = zcl_logger_factory=>create_custom_log( object = object subobject = subobject ).
83 | endif.
84 | returning = zcl_logger_factory=>logger.
85 | endmethod.
86 | ENDCLASS.
87 |
--------------------------------------------------------------------------------
/logging/zcl_logging_repo_http.abap:
--------------------------------------------------------------------------------
1 | class ZCL_LOGGING_REPO_HTTP definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create private
6 |
7 | global friends ZCL_LOGGER
8 | ZCL_LOGGER_FACTORY .
9 |
10 | public section.
11 |
12 | *"* public components of class zCL_LOGGING_REPO_HTTP
13 | *"* do not include other source files here!!!
14 | interfaces ZIF_LOGGING_REPOSITORY .
15 |
16 | aliases CREATE
17 | for ZIF_LOGGING_REPOSITORY~CREATE .
18 | aliases FIND_BY_ID
19 | for ZIF_LOGGING_REPOSITORY~FIND_BY_ID .
20 | aliases UPDATE
21 | for ZIF_LOGGING_REPOSITORY~UPDATE .
22 | protected section.
23 | *"* protected components of class zCL_LOGGING_REPO_HTTP
24 | *"* do not include other source files here!!!
25 | private section.
26 |
27 | *"* private components of class zCL_LOGGING_REPO_HTTP
28 | *"* do not include other source files here!!!
29 | methods GET_CLIENT
30 | returning
31 | value(RETURNING) type ref to IF_HTTP_CLIENT .
32 | methods SEND_REQUEST
33 | importing
34 | !CLIENT type ref to IF_HTTP_CLIENT .
35 | methods CLOSE_REQUEST
36 | importing
37 | !CLIENT type ref to IF_HTTP_CLIENT .
38 | ENDCLASS.
39 |
40 |
41 |
42 | CLASS ZCL_LOGGING_REPO_HTTP IMPLEMENTATION.
43 |
44 |
45 | * ---------------------------------------------------------------------------------------+
46 | * | Instance Public Method ZCL_LOGGING_REPO_HTTP->ZIF_LOGGING_REPOSITORY~CREATE
47 | * +-------------------------------------------------------------------------------------------------+
48 | * | [--->] LOG_OBJECT TYPE BALOBJ_D
49 | * | [--->] LOG_SUBOBJECT TYPE BALSUBOBJ
50 | * | [<-()] RETURNING TYPE BALOGNR
51 | * +--------------------------------------------------------------------------------------
52 | method zif_logging_repository~create.
53 | " Create client
54 | data client type ref to if_http_client.
55 | client = me->get_client( ).
56 | " Construct request
57 | " - URI
58 | data uri type string.
59 | uri = '/log/'.
60 | client->request->set_header_field( name = '~request_uri' value = uri ).
61 | client->request->set_header_field( name = '~request_method' value = zcl_http_methods=>post ).
62 | " - Body
63 | data tp_log_object type string.
64 | data tp_log_subobject type string.
65 | tp_log_object = log_object.
66 | tp_log_subobject = log_subobject.
67 | client->request->set_form_field( name = 'logobject' value = tp_log_object ). "#EC NOTEXT
68 | client->request->set_form_field( name = 'logsubobject' value = tp_log_subobject ). "#EC NOTEXT
69 | client->request->set_formfield_encoding( if_http_entity=>co_formfield_encoding_encoded ).
70 | " Send request
71 | me->send_request( client ).
72 | " Keep log number returned by response
73 | data tp_location type string.
74 | tp_location = client->response->if_http_entity~get_header_field( zcl_http_header_fields=>location ).
75 | if tp_location is initial.
76 | raise exception type zcx_logging_error.
77 | endif.
78 | " Close request
79 | me->close_request( client ).
80 | " Return location (log number)
81 | returning = tp_location.
82 | endmethod.
83 |
84 |
85 | * ---------------------------------------------------------------------------------------+
86 | * | Instance Public Method ZCL_LOGGING_REPO_HTTP->ZIF_LOGGING_REPOSITORY~FIND_BY_ID
87 | * +-------------------------------------------------------------------------------------------------+
88 | * | [--->] LOG_NUMBER TYPE BALOGNR
89 | * | [<-()] RETURNING TYPE REF TO ZCL_LOGGER
90 | * +--------------------------------------------------------------------------------------
91 | method zif_logging_repository~find_by_id.
92 | " Create client
93 | data client type ref to if_http_client.
94 | client = me->get_client( ).
95 | " Construct request
96 | " - URI
97 | data uri type string.
98 | concatenate '/log/' log_number into uri.
99 | client->request->set_header_field( name = '~request_uri' value = uri ).
100 | client->request->set_header_field( name = '~request_method' value = zcl_http_methods=>get ).
101 | " Send request
102 | me->send_request( client ).
103 | " Retrieve log details returned by response
104 | data log_as_string type string.
105 | log_as_string = client->response->get_cdata( ).
106 | if log_as_string is initial.
107 | raise exception type zcx_logging_error.
108 | endif.
109 | data log_as_json type ref to zcl_json_object.
110 | data json_parser type ref to zcl_json_parser.
111 | create object json_parser.
112 | try.
113 | log_as_json ?= json_parser->deserialize( log_as_string ).
114 | catch zcx_json_parse_error.
115 | raise exception type zcx_logging_error.
116 | endtry.
117 | data log_object_json type ref to zcl_json_pair.
118 | data log_subobject_json type ref to zcl_json_pair.
119 | log_object_json = log_as_json->get( 0 ).
120 | log_subobject_json = log_as_json->get( 1 ).
121 | data log_object_json_string type ref to zcl_json_string.
122 | data log_subobject_json_string type ref to zcl_json_string.
123 | log_object_json_string ?= log_object_json->value.
124 | log_subobject_json_string ?= log_subobject_json->value.
125 | data log_object type balobj_d.
126 | data log_subobject type balsubobj.
127 | log_object = log_object_json_string->value.
128 | log_subobject = log_subobject_json_string->value.
129 | data logger type ref to zcl_logger.
130 | create object logger
131 | exporting
132 | log_object = log_object
133 | log_subobject = log_subobject
134 | log_number = log_number.
135 | " Close request
136 | me->close_request( client ).
137 | " Return logger
138 | returning = logger.
139 | endmethod.
140 |
141 |
142 | * ---------------------------------------------------------------------------------------+
143 | * | Instance Public Method ZCL_LOGGING_REPO_HTTP->ZIF_LOGGING_REPOSITORY~UPDATE
144 | * +-------------------------------------------------------------------------------------------------+
145 | * | [--->] LOG_NUMBER TYPE BALOGNR
146 | * | [--->] LOG_MESSAGE TYPE STRING
147 | * | [--->] LOG_MESSAGE_TYPE TYPE SYMSGTY
148 | * | [<-()] RETURNING TYPE ABAP_BOOL
149 | * +--------------------------------------------------------------------------------------
150 | method zif_logging_repository~update.
151 | " Create client
152 | data client type ref to if_http_client.
153 | client = me->get_client( ).
154 | " Construct request
155 | " - URI
156 | data uri type string.
157 | concatenate '/log/' log_number into uri.
158 | client->request->set_header_field( name = '~request_uri' value = uri ).
159 | client->request->set_header_field( name = '~request_method' value = zcl_http_methods=>put ).
160 | " - Body
161 | data tp_message type string.
162 | data tp_message_type type string.
163 | tp_message = log_message.
164 | tp_message_type = log_message_type.
165 | client->request->set_form_field( name = 'message' value = tp_message ). "#EC NOTEXT
166 | client->request->set_form_field( name = 'messagetype' value = tp_message_type ). "#EC NOTEXT
167 | client->request->set_formfield_encoding( if_http_entity=>co_formfield_encoding_encoded ).
168 | " Send request
169 | me->send_request( client ).
170 | " Close request
171 | me->close_request( client ).
172 | endmethod.
173 |
174 |
175 | * ---------------------------------------------------------------------------------------+
176 | * | Instance Private Method ZCL_LOGGING_REPO_HTTP->CLOSE_REQUEST
177 | * +-------------------------------------------------------------------------------------------------+
178 | * | [--->] CLIENT TYPE REF TO IF_HTTP_CLIENT
179 | * +--------------------------------------------------------------------------------------
180 | method close_request.
181 | " Close connection
182 | call method client->close
183 | exceptions
184 | http_invalid_state = 1
185 | others = 2.
186 | if sy-subrc <> 0.
187 | raise exception type zcx_logging_error.
188 | endif.
189 | endmethod.
190 |
191 |
192 | * ---------------------------------------------------------------------------------------+
193 | * | Instance Private Method ZCL_LOGGING_REPO_HTTP->GET_CLIENT
194 | * +-------------------------------------------------------------------------------------------------+
195 | * | [<-()] RETURNING TYPE REF TO IF_HTTP_CLIENT
196 | * +--------------------------------------------------------------------------------------
197 | method get_client.
198 | " Create client
199 | data client type ref to if_http_client.
200 | call method cl_http_client=>create_by_destination
201 | exporting
202 | destination = 'LOG_LOCALHOST'
203 | importing
204 | client = client
205 | exceptions
206 | argument_not_found = 1
207 | destination_not_found = 2
208 | destination_no_authority = 3
209 | plugin_not_active = 4
210 | internal_error = 5
211 | others = 6.
212 | if sy-subrc <> 0.
213 | raise exception type zcx_logging_error.
214 | endif.
215 | returning = client.
216 | endmethod.
217 |
218 |
219 | * ---------------------------------------------------------------------------------------+
220 | * | Instance Private Method ZCL_LOGGING_REPO_HTTP->SEND_REQUEST
221 | * +-------------------------------------------------------------------------------------------------+
222 | * | [--->] CLIENT TYPE REF TO IF_HTTP_CLIENT
223 | * +--------------------------------------------------------------------------------------
224 | method send_request.
225 | " Send request
226 | call method client->send
227 | exceptions
228 | http_communication_failure = 1
229 | http_invalid_state = 2
230 | http_processing_failed = 3
231 | http_invalid_timeout = 4
232 | others = 5.
233 | if sy-subrc <> 0.
234 | me->close_request( client ).
235 | raise exception type zcx_logging_error.
236 | endif.
237 | " Receive response
238 | call method client->receive
239 | exceptions
240 | http_communication_failure = 1
241 | http_invalid_state = 2
242 | http_processing_failed = 3
243 | others = 4.
244 | if sy-subrc <> 0.
245 | me->close_request( client ).
246 | raise exception type zcx_logging_error.
247 | endif.
248 | " Read response
249 | data tp_status_code type i.
250 | client->response->get_status( importing code = tp_status_code ).
251 | if tp_status_code <> zcl_http_status_codes=>ok and tp_status_code <> zcl_http_status_codes=>created.
252 | me->close_request( client ).
253 | raise exception type zcx_logging_error.
254 | endif.
255 | endmethod.
256 | ENDCLASS.
257 |
--------------------------------------------------------------------------------
/logging/zcl_logging_repository.abap:
--------------------------------------------------------------------------------
1 | class ZCL_LOGGING_REPOSITORY definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create private
6 |
7 | global friends ZCL_LOGGING_RESOURCE .
8 |
9 | public section.
10 |
11 | *"* public components of class zCL_LOGGING_REPOSITORY
12 | *"* do not include other source files here!!!
13 | interfaces ZIF_LOGGING_REPOSITORY .
14 |
15 | aliases CREATE
16 | for ZIF_LOGGING_REPOSITORY~CREATE .
17 | aliases FIND_BY_ID
18 | for ZIF_LOGGING_REPOSITORY~FIND_BY_ID .
19 | aliases UPDATE
20 | for ZIF_LOGGING_REPOSITORY~UPDATE .
21 | protected section.
22 | *"* protected components of class zCL_LOGGING_REPOSITORY
23 | *"* do not include other source files here!!!
24 | private section.
25 | *"* private components of class zCL_LOGGING_REPOSITORY
26 | *"* do not include other source files here!!!
27 | ENDCLASS.
28 |
29 |
30 |
31 | CLASS ZCL_LOGGING_REPOSITORY IMPLEMENTATION.
32 |
33 |
34 | * ---------------------------------------------------------------------------------------+
35 | * | Instance Public Method ZCL_LOGGING_REPOSITORY->ZIF_LOGGING_REPOSITORY~CREATE
36 | * +-------------------------------------------------------------------------------------------------+
37 | * | [--->] LOG_OBJECT TYPE BALOBJ_D
38 | * | [--->] LOG_SUBOBJECT TYPE BALSUBOBJ
39 | * | [<-()] RETURNING TYPE BALOGNR
40 | * +--------------------------------------------------------------------------------------
41 | method zif_logging_repository~create.
42 |
43 | " Create new application log entry
44 | data wa_log_header type bal_s_log.
45 | data tp_log_handle type balloghndl.
46 | wa_log_header-object = log_object.
47 | wa_log_header-subobject = log_subobject.
48 | wa_log_header-aldate_del = sy-datum + 60. " Expire after 2 months
49 | wa_log_header-del_before = abap_true.
50 |
51 | concatenate sy-uname '_' sy-datum '_' sy-uzeit into wa_log_header-extnumber.
52 | call function 'BAL_LOG_CREATE'
53 | exporting
54 | i_s_log = wa_log_header
55 | importing
56 | e_log_handle = tp_log_handle
57 | exceptions
58 | log_header_inconsistent = 1
59 | others = 2.
60 | if sy-subrc <> 0.
61 | " Error creating new application log entry
62 | return.
63 | endif.
64 |
65 | " Save the application log entry
66 | data ta_log_numbers type bal_t_lgnm.
67 | data ta_log_handles type bal_t_logh.
68 | insert tp_log_handle into table ta_log_handles.
69 | call function 'BAL_DB_SAVE'
70 | exporting
71 | i_t_log_handle = ta_log_handles
72 | importing
73 | e_new_lognumbers = ta_log_numbers
74 | exceptions
75 | log_not_found = 1
76 | save_not_allowed = 2
77 | numbering_error = 3
78 | others = 4.
79 | if sy-subrc <> 0.
80 | " Error saving new application log entry
81 | return.
82 | endif.
83 |
84 | " Get the log number (always one handle, always one number)
85 | data wa_log_number type bal_s_lgnm.
86 | data tp_log_number type balognr.
87 | read table ta_log_numbers into wa_log_number index 1.
88 | tp_log_number = wa_log_number-lognumber.
89 | if tp_log_number is initial.
90 | " No log number was created
91 | return.
92 | endif.
93 | returning = tp_log_number.
94 |
95 | endmethod.
96 |
97 |
98 | * ---------------------------------------------------------------------------------------+
99 | * | Instance Public Method ZCL_LOGGING_REPOSITORY->ZIF_LOGGING_REPOSITORY~FIND_BY_ID
100 | * +-------------------------------------------------------------------------------------------------+
101 | * | [--->] LOG_NUMBER TYPE BALOGNR
102 | * | [<-()] RETURNING TYPE REF TO ZCL_LOGGER
103 | * +--------------------------------------------------------------------------------------
104 | method zif_logging_repository~find_by_id.
105 | data log_object type balobj_d.
106 | data log_subobject type balsubobj.
107 | select single object subobject from balhdr into (log_object, log_subobject) where lognumber = log_number.
108 | if sy-subrc = 0.
109 | data logger type ref to zcl_logger.
110 | create object logger
111 | exporting
112 | log_object = log_object
113 | log_subobject = log_subobject
114 | log_number = log_number.
115 | returning = logger.
116 | return.
117 | endif.
118 | endmethod.
119 |
120 |
121 | * ---------------------------------------------------------------------------------------+
122 | * | Instance Public Method ZCL_LOGGING_REPOSITORY->ZIF_LOGGING_REPOSITORY~UPDATE
123 | * +-------------------------------------------------------------------------------------------------+
124 | * | [--->] LOG_NUMBER TYPE BALOGNR
125 | * | [--->] LOG_MESSAGE TYPE STRING
126 | * | [--->] LOG_MESSAGE_TYPE TYPE SYMSGTY
127 | * | [<-()] RETURNING TYPE ABAP_BOOL
128 | * +--------------------------------------------------------------------------------------
129 | method zif_logging_repository~update.
130 |
131 | " Read the application log entry from the database
132 | data ta_e_t_log_handle type bal_t_logh.
133 | data ta_bal_t_logn type bal_t_logn.
134 | insert log_number into table ta_bal_t_logn.
135 | call function 'BAL_DB_LOAD'
136 | exporting
137 | i_t_lognumber = ta_bal_t_logn
138 | importing
139 | e_t_log_handle = ta_e_t_log_handle
140 | exceptions
141 | no_logs_specified = 1
142 | log_not_found = 2
143 | log_already_loaded = 3
144 | others = 4.
145 | if sy-subrc <> 0.
146 | " Unknown log requested
147 | return.
148 | endif.
149 |
150 | " Get the log handle (always one number, always one handle)
151 | data tp_handle type balloghndl.
152 | read table ta_e_t_log_handle into tp_handle index 1.
153 | if tp_handle is initial.
154 | " No handle available
155 | return.
156 | endif.
157 |
158 | " Add the message to the application log entry
159 | data tp_log_text(200) type c.
160 | tp_log_text = log_message.
161 | call function 'BAL_LOG_MSG_ADD_FREE_TEXT'
162 | exporting
163 | i_log_handle = tp_handle
164 | i_msgty = log_message_type
165 | i_text = tp_log_text
166 | exceptions
167 | log_not_found = 1
168 | msg_inconsistent = 2
169 | log_is_full = 3
170 | others = 4.
171 | if sy-subrc <> 0.
172 | " Could not add message to application log entry
173 | return.
174 | endif.
175 |
176 | " Save the application log entry
177 | data log_handles type bal_t_logh.
178 | insert tp_handle into table log_handles.
179 | call function 'BAL_DB_SAVE'
180 | exporting
181 | i_t_log_handle = log_handles
182 | exceptions
183 | log_not_found = 1
184 | save_not_allowed = 2
185 | numbering_error = 3
186 | others = 4.
187 | if sy-subrc <> 0.
188 | " Error saving new application log entry
189 | return.
190 | endif.
191 |
192 | returning = abap_true.
193 |
194 | endmethod.
195 | ENDCLASS.
196 |
--------------------------------------------------------------------------------
/logging/zcl_logging_resource.abap:
--------------------------------------------------------------------------------
1 | class ZCL_LOGGING_RESOURCE definition
2 | public
3 | inheriting from ZCL_RESOURCE
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_LOGGING_RESOURCE
10 | *"* do not include other source files here!!!
11 | methods CONSTRUCTOR .
12 |
13 | methods CREATE
14 | redefinition .
15 | methods READ
16 | redefinition .
17 | methods UPDATE
18 | redefinition .
19 | protected section.
20 | *"* protected components of class zCL_LOGGING_RESOURCE
21 | *"* do not include other source files here!!!
22 | private section.
23 |
24 | *"* private components of class zCL_LOGGING_RESOURCE
25 | *"* do not include other source files here!!!
26 | data LOGGING_REPOSITORY type ref to ZCL_LOGGING_REPOSITORY .
27 |
28 | methods PARSE_URI
29 | importing
30 | !URI type STRING
31 | returning
32 | value(RETURNING) type BALOGNR .
33 | ENDCLASS.
34 |
35 |
36 |
37 | CLASS ZCL_LOGGING_RESOURCE IMPLEMENTATION.
38 |
39 |
40 | * ---------------------------------------------------------------------------------------+
41 | * | Instance Public Method ZCL_LOGGING_RESOURCE->CONSTRUCTOR
42 | * +-------------------------------------------------------------------------------------------------+
43 | * +--------------------------------------------------------------------------------------
44 | method constructor.
45 | super->constructor( ).
46 | create object me->logging_repository.
47 | endmethod.
48 |
49 |
50 | * ---------------------------------------------------------------------------------------+
51 | * | Instance Public Method ZCL_LOGGING_RESOURCE->CREATE
52 | * +-------------------------------------------------------------------------------------------------+
53 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
54 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
55 | * +--------------------------------------------------------------------------------------
56 | method create.
57 | */**
58 | *
59 | * Creates a new application log entry and returns the log number
60 | *
61 | */
62 |
63 | data msg type string.
64 |
65 | " Read application log object and subobject strings from HTTP request
66 | data tp_log_object type balobj_d.
67 | data tp_log_subobject type balsubobj.
68 | tp_log_object = request->get_parameter( 'logobject' ). "#EC NOTEXT
69 | if tp_log_object is initial.
70 | " No log object specified
71 | message e004(zlog) into msg.
72 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
73 | return.
74 | endif.
75 | tp_log_subobject = request->get_parameter( 'logsubobject' ). "#EC NOTEXT
76 | if tp_log_subobject is initial.
77 | " No log subobject specified
78 | message e005(zlog) into msg.
79 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
80 | return.
81 | endif.
82 | " Create new application log entry
83 | data tp_log_number type balognr.
84 | tp_log_number = me->logging_repository->create( log_object = tp_log_object log_subobject = tp_log_subobject ).
85 | if tp_log_number is initial.
86 | " No log number was created
87 | message e008(zlog) into msg.
88 | response->send_error( code = zcl_http_status_codes=>internal_server_error message = msg ).
89 | return.
90 | endif.
91 | " Return the created log number
92 | data tp_location type string.
93 | tp_location = tp_log_number.
94 | response->send_created( tp_location ).
95 | return.
96 |
97 | endmethod.
98 |
99 |
100 | * ---------------------------------------------------------------------------------------+
101 | * | Instance Private Method ZCL_LOGGING_RESOURCE->PARSE_URI
102 | * +-------------------------------------------------------------------------------------------------+
103 | * | [--->] URI TYPE STRING
104 | * | [<-()] RETURNING TYPE BALOGNR
105 | * +--------------------------------------------------------------------------------------
106 | method parse_uri.
107 | */**
108 | * Parses the URI using a regular expression
109 | * The URI is expected to have the following possible formats:
110 | *
111 | * /log
112 | * /log/number
113 | *
114 | */
115 |
116 | " In order to keep this compatible with older systems, the CL_ABAP_MATCHER class is no longer used here.
117 | * DATA matcher TYPE REF TO cl_abap_matcher.
118 | * matcher = cl_abap_matcher=>create( pattern = '^/log/(.{1,20})' text = uri ).
119 | * IF matcher IS BOUND.
120 | * IF matcher->match( ) = abap_true.
121 | * tp_balognr = matcher->get_submatch( 1 ).
122 | * ENDIF.
123 | * ENDIF.
124 | data ta_values type standard table of string.
125 | split uri at '/' into table ta_values.
126 | data tp_balognr type balognr.
127 | " In case the log number was specified, it will be at index position 3 (since the '/' will occur twice in this case)
128 | read table ta_values into tp_balognr index 3.
129 | returning = tp_balognr.
130 | endmethod.
131 |
132 |
133 | * ---------------------------------------------------------------------------------------+
134 | * | Instance Public Method ZCL_LOGGING_RESOURCE->READ
135 | * +-------------------------------------------------------------------------------------------------+
136 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
137 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
138 | * +--------------------------------------------------------------------------------------
139 | method read.
140 | */**
141 | *
142 | * Return the details of an existing application log entry
143 | * Does not return any messages contained in the entry
144 | *
145 | */
146 |
147 | data msg type string.
148 |
149 | " Retrieve log number from the URI
150 | data uri type string.
151 | data balognr type balognr.
152 | uri = request->get_requesturi( ).
153 | balognr = me->parse_uri( uri ).
154 | if balognr is initial.
155 | " No log number specified
156 | message e007(zlog) into msg.
157 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
158 | return.
159 | endif.
160 |
161 | " Get the log entry
162 | data logger type ref to zcl_logger.
163 | logger = me->logging_repository->find_by_id( balognr ).
164 | if logger is not bound.
165 | " Log entry not found
166 | message e002(zlog) into msg.
167 | response->send_error( code = zcl_http_status_codes=>not_found message = msg ).
168 | return.
169 | endif.
170 |
171 | " Return log entry details in JSON format
172 | data log_object_str type string.
173 | data log_subobject_str type string.
174 | log_object_str = logger->get_object( ).
175 | log_subobject_str = logger->get_subobject( ).
176 | data log_object_json type ref to zcl_json_pair.
177 | data log_subobject_json type ref to zcl_json_pair.
178 | data log_as_json type ref to zcl_json_object.
179 | log_object_json = zcl_json_util=>new_pair_with_string( name = 'object' value = log_object_str ).
180 | log_subobject_json = zcl_json_util=>new_pair_with_string( name = 'subobject' value = log_subobject_str ).
181 | create object log_as_json.
182 | log_as_json->add( log_object_json ).
183 | log_as_json->add( log_subobject_json ).
184 | data log_as_string type string.
185 | data json_parser type ref to zcl_json_parser.
186 | create object json_parser.
187 | log_as_string = json_parser->serialize( log_as_json ).
188 | response->send_text( data = log_as_string mime_type = zcl_http_mime_types=>text_plain code = zcl_http_status_codes=>ok ).
189 | return.
190 |
191 | endmethod.
192 |
193 |
194 | * ---------------------------------------------------------------------------------------+
195 | * | Instance Public Method ZCL_LOGGING_RESOURCE->UPDATE
196 | * +-------------------------------------------------------------------------------------------------+
197 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
198 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
199 | * +--------------------------------------------------------------------------------------
200 | method update.
201 | */**
202 | *
203 | * Adds a message to an existing application log entry
204 | *
205 | */
206 |
207 | data msg type string.
208 |
209 | " Retrieve log number from the URI
210 | data uri type string.
211 | data tp_balognr type balognr.
212 | uri = request->get_requesturi( ).
213 | tp_balognr = me->parse_uri( uri ).
214 | if tp_balognr is initial.
215 | " No log number specified
216 | message e007(zlog) into msg.
217 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
218 | return.
219 | endif.
220 |
221 | " Read application log type and message from HTTP request
222 | data tp_message type string.
223 | data tp_message_type type symsgty.
224 | tp_message = request->get_parameter( 'message' ). "#EC NOTEXT
225 | if tp_message is initial.
226 | " No message specified
227 | message e010(zlog) into msg.
228 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
229 | return.
230 | endif.
231 | tp_message_type = request->get_parameter( 'messagetype' ). "#EC NOTEXT
232 | if tp_message_type is initial.
233 | " No message type specified
234 | message e011(zlog) into msg.
235 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
236 | return.
237 | endif.
238 | " Add message
239 | data tp_ok type abap_bool.
240 | tp_ok = me->logging_repository->update( log_number = tp_balognr log_message = tp_message log_message_type = tp_message_type ).
241 | if tp_ok = abap_true.
242 | " Return OK
243 | response->send_ok( ).
244 | return.
245 | else.
246 | message e012(zlog) into msg.
247 | response->send_error( code = zcl_http_status_codes=>bad_request message = msg ).
248 | return.
249 | endif.
250 |
251 | endmethod.
252 | ENDCLASS.
253 |
--------------------------------------------------------------------------------
/logging/zcx_logging_error.abap:
--------------------------------------------------------------------------------
1 | class ZCX_LOGGING_ERROR definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_LOGGING_ERROR type SOTR_CONC value '00155D334B0D1EE2B9823B5A2B998991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_LOGGING_ERROR IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_LOGGING_ERROR->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_LOGGING_ERROR .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/logging/zif_logging_repository.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_LOGGING_REPOSITORY
2 | public .
3 |
4 |
5 | methods CREATE
6 | importing
7 | !LOG_OBJECT type BALOBJ_D
8 | !LOG_SUBOBJECT type BALSUBOBJ
9 | returning
10 | value(RETURNING) type BALOGNR .
11 | methods FIND_BY_ID
12 | importing
13 | !LOG_NUMBER type BALOGNR
14 | returning
15 | value(RETURNING) type ref to ZCL_LOGGER .
16 | type-pools ABAP .
17 | methods UPDATE
18 | importing
19 | !LOG_NUMBER type BALOGNR
20 | !LOG_MESSAGE type STRING
21 | !LOG_MESSAGE_TYPE type SYMSGTY
22 | returning
23 | value(RETURNING) type ABAP_BOOL .
24 | endinterface.
25 |
--------------------------------------------------------------------------------
/rest/rest.messageclass.txt:
--------------------------------------------------------------------------------
1 | 000 & & & &
2 | 001 & & & &
3 | 002 HTTP method not supported
4 | 003 Resource not found
5 | 004 URI too long
6 | 005 Method not allowed
--------------------------------------------------------------------------------
/rest/zcl_dispatcher.abap:
--------------------------------------------------------------------------------
1 | class ZCL_DISPATCHER definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | interfaces IF_HTTP_EXTENSION .
10 | protected section.
11 | *"* protected components of class zCL_DISPATCHER
12 | *"* do not include other source files here!!!
13 | private section.
14 |
15 | *"* private components of class zCL_DISPATCHER
16 | *"* do not include other source files here!!!
17 | constants MAX_URI_LENGTH type I value 1000. "#EC NOTEXT
18 |
19 | methods _SERVICE
20 | importing
21 | !REQUEST type ref to ZCL_REQUEST
22 | !RESPONSE type ref to ZCL_RESPONSE
23 | raising
24 | ZCX_RESOURCE_EXCEPTION .
25 | methods _GET_MAPPED_RESOURCE
26 | importing
27 | !REQUEST type ref to ZCL_REQUEST
28 | returning
29 | value(RETURNING) type ref to ZCL_RESOURCE
30 | raising
31 | ZCX_URI_TOO_LONG .
32 | methods _LOG_REQUEST
33 | importing
34 | !RESOURCE type ref to ZCL_RESOURCE
35 | !REQUEST type ref to ZCL_REQUEST .
36 | ENDCLASS.
37 |
38 |
39 |
40 | CLASS ZCL_DISPATCHER IMPLEMENTATION.
41 |
42 |
43 | * ---------------------------------------------------------------------------------------+
44 | * | Instance Public Method ZCL_DISPATCHER->IF_HTTP_EXTENSION~HANDLE_REQUEST
45 | * +-------------------------------------------------------------------------------------------------+
46 | * | [--->] SERVER TYPE REF TO IF_HTTP_SERVER
47 | * +--------------------------------------------------------------------------------------
48 | method if_http_extension~handle_request.
49 | */**
50 | * This method is called by the SAP ICF system on handler classes
51 | * Wraps the SAP request and response objects and let's the SERVICE method handle them
52 | */
53 |
54 | " Wrap request and response
55 | data request type ref to zcl_request.
56 | data response type ref to zcl_response.
57 | create object request
58 | type
59 | zcl_request
60 | exporting
61 | request = server->request.
62 | create object response
63 | type
64 | zcl_response
65 | exporting
66 | response = server->response.
67 |
68 | " Handle request
69 | data e type ref to zcx_resource_exception.
70 | try.
71 | _service( request = request response = response ).
72 | return.
73 | catch zcx_resource_exception into e.
74 | response->send_internal_server_error( message = e->message ).
75 | return.
76 | endtry.
77 |
78 | endmethod.
79 |
80 |
81 | * ---------------------------------------------------------------------------------------+
82 | * | Instance Private Method ZCL_DISPATCHER->_GET_MAPPED_RESOURCE
83 | * +-------------------------------------------------------------------------------------------------+
84 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
85 | * | [<-()] RETURNING TYPE REF TO ZCL_RESOURCE
86 | * | [!CX!] ZCX_URI_TOO_LONG
87 | * +--------------------------------------------------------------------------------------
88 | method _get_mapped_resource.
89 | */**
90 | * Finds the resource mapped to the request URI.
91 | * A resource is linked to a resource path. This path is always the root path of the received request URI.
92 | *
93 | * Examples:
94 | * - request URI: /partners
95 | * - resource path: /partners
96 | *
97 | * - request URI: /partners/12
98 | * - resource path: /partners
99 | *
100 | * - request URI: /partners/12/address
101 | * - resource path: /partners
102 | *
103 | * - request URI: /partners/12/contactpersons?hasemailaddress=true
104 | * - resource path: /partners
105 | *
106 | */
107 | data uri type string.
108 | data uri_parts type standard table of string.
109 | data resource_path type string.
110 | data resource_id type string.
111 | data resource_record type zresources.
112 | data resource type ref to zcl_resource.
113 |
114 | " Get request URI
115 | uri = request->get_requesturi( ).
116 | if strlen( uri ) > max_uri_length. " Maximum supported URI length
117 | raise exception type zcx_uri_too_long.
118 | endif.
119 | " Get the path and resource id from the URI
120 | split uri at '/' into table uri_parts.
121 | read table uri_parts into resource_path index 2.
122 | read table uri_parts into resource_id index 3.
123 | " Resource paths are case insensitive, so they are stored in UPPER CASE
124 | translate resource_path to upper case.
125 | " Find the mapped resource
126 | select single * into resource_record from zresources where path = resource_path.
127 | if sy-subrc <> 0.
128 | return.
129 | endif.
130 | " Create the resource
131 | try.
132 | create object resource type (resource_record-class).
133 | resource->_name = resource_record-name.
134 | resource->_path = resource_record-path.
135 | resource->_id = resource_id.
136 | catch cx_sy_create_object_error.
137 | " Do nothing; this method returns null if no resource was found
138 | return.
139 | endtry.
140 | " Log the request, if required
141 | if resource_record-log_requests = abap_true.
142 | _log_request( resource = resource request = request ).
143 | endif.
144 |
145 | returning = resource.
146 | endmethod.
147 |
148 |
149 | * ---------------------------------------------------------------------------------------+
150 | * | Instance Private Method ZCL_DISPATCHER->_LOG_REQUEST
151 | * +-------------------------------------------------------------------------------------------------+
152 | * | [--->] RESOURCE TYPE REF TO ZCL_RESOURCE
153 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
154 | * +--------------------------------------------------------------------------------------
155 | method _log_request.
156 | data: raw type xstring,
157 | rawstr type string,
158 | utf8_converter type ref to cl_abap_conv_in_ce,
159 | restlog type zrestlog.
160 |
161 | raw = request->get_raw_message( ).
162 | utf8_converter = cl_abap_conv_in_ce=>create( encoding = 'UTF-8' ).
163 | call method utf8_converter->convert
164 | exporting
165 | input = raw
166 | importing
167 | data = rawstr.
168 |
169 | get time.
170 | try.
171 | restlog-uuid = cl_system_uuid=>create_uuid_c32_static( ).
172 | catch cx_uuid_error.
173 | " Try to write without guid anyway
174 | endtry.
175 | restlog-requestdate = sy-datum.
176 | restlog-requesttime = sy-uzeit.
177 | restlog-requestuser = sy-uname.
178 | restlog-resourcepath = resource->path( ).
179 | restlog-resourcename = resource->name( ).
180 | restlog-resourceid = resource->id( ).
181 | restlog-request = rawstr.
182 | insert zrestlog from restlog.
183 | commit work.
184 |
185 | endmethod.
186 |
187 |
188 | * ---------------------------------------------------------------------------------------+
189 | * | Instance Private Method ZCL_DISPATCHER->_SERVICE
190 | * +-------------------------------------------------------------------------------------------------+
191 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
192 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
193 | * | [!CX!] ZCX_RESOURCE_EXCEPTION
194 | * +--------------------------------------------------------------------------------------
195 | method _service.
196 | */**
197 | * Dispatches the HTTP request to the corresponding resource.
198 | * Returns the NOT_FOUND status code for unknown resources.
199 | * Returns the NOT_IMPLEMENTED status code for methods which are not supported.
200 | * Supported methods:
201 | * - DELETE
202 | * - GET
203 | * - POST
204 | * - PUT
205 | * - HEAD
206 | */
207 | data message type string.
208 | data resource type ref to zcl_resource.
209 | data method type string.
210 |
211 | " Find the resource mapped to the request URI
212 | try.
213 | resource = _get_mapped_resource( request ).
214 | catch zcx_uri_too_long.
215 | " Too long URI
216 | message e004(zrest) into message.
217 | response->send_error( code = zcl_http_status_codes=>requesturi_too_large message = message ).
218 | return.
219 | endtry.
220 | if resource is not bound.
221 | " Unknown resource
222 | message e003(zrest) into message.
223 | response->send_not_found( message = message ).
224 | return.
225 | endif.
226 | " Dispatch request to the requested resource
227 | method = request->get_method( ).
228 | case method.
229 | when zcl_http_methods=>delete.
230 | resource->delete( request = request response = response ).
231 | when zcl_http_methods=>get.
232 | resource->read( request = request response = response ).
233 | when zcl_http_methods=>post.
234 | resource->create( request = request response = response ).
235 | when zcl_http_methods=>put.
236 | resource->update( request = request response = response ).
237 | when zcl_http_methods=>head.
238 | resource->head( request = request response = response ).
239 | when others.
240 | " Unsupported HTTP method
241 | message e002(zrest) into message.
242 | response->send_error( code = zcl_http_status_codes=>not_implemented message = message ).
243 | return.
244 | endcase.
245 | endmethod.
246 | ENDCLASS.
247 |
--------------------------------------------------------------------------------
/rest/zcl_http_header_fields.abap:
--------------------------------------------------------------------------------
1 | class ZCL_HTTP_HEADER_FIELDS definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_HTTP_HEADER_FIELDS
10 | *"* do not include other source files here!!!
11 | constants ACCEPT type STRING value 'Accept'. "#EC NOTEXT
12 | constants ACCEPTCHARSET type STRING value 'Accept-Charset'. "#EC NOTEXT
13 | constants ETAG type STRING value 'ETag'. "#EC NOTEXT
14 | constants LOCATION type STRING value 'Location'. "#EC NOTEXT
15 | constants REFERER type STRING value 'Referer'. "#EC NOTEXT
16 | protected section.
17 | *"* protected components of class zCL_HTTP_HEADER_FIELDS
18 | *"* do not include other source files here!!!
19 | private section.
20 | *"* private components of class zCL_HTTP_HEADER_FIELDS
21 | *"* do not include other source files here!!!
22 | ENDCLASS.
23 |
24 |
25 |
26 | CLASS ZCL_HTTP_HEADER_FIELDS IMPLEMENTATION.
27 | ENDCLASS.
28 |
--------------------------------------------------------------------------------
/rest/zcl_http_methods.abap:
--------------------------------------------------------------------------------
1 | class ZCL_HTTP_METHODS definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_HTTP_METHODS
10 | *"* do not include other source files here!!!
11 | constants DELETE type STRING value 'DELETE'. "#EC NOTEXT
12 | constants HEAD type STRING value 'HEAD'. "#EC NOTEXT
13 | constants GET type STRING value 'GET'. "#EC NOTEXT
14 | constants OPTIONS type STRING value 'OPTIONS'. "#EC NOTEXT
15 | constants POST type STRING value 'POST'. "#EC NOTEXT
16 | constants PUT type STRING value 'PUT'. "#EC NOTEXT
17 | constants TRACE type STRING value 'TRACE'. "#EC NOTEXT
18 | protected section.
19 | *"* protected components of class zCL_HTTP_METHODS
20 | *"* do not include other source files here!!!
21 | private section.
22 | *"* private components of class zCL_HTTP_METHODS
23 | *"* do not include other source files here!!!
24 | ENDCLASS.
25 |
26 |
27 |
28 | CLASS ZCL_HTTP_METHODS IMPLEMENTATION.
29 | ENDCLASS.
30 |
--------------------------------------------------------------------------------
/rest/zcl_http_mime_types.abap:
--------------------------------------------------------------------------------
1 | class ZCL_HTTP_MIME_TYPES definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_HTTP_MIME_TYPES
10 | *"* do not include other source files here!!!
11 | constants APPLICATION_JSON type STRING value 'application/json'. "#EC NOTEXT
12 | constants APPLICATION_OCTETSTREAM type STRING value 'application/octet-stream'. "#EC NOTEXT
13 | constants APPLICATION_PDF type STRING value 'application/pdf'. "#EC NOTEXT
14 | constants APPLICATION_RSS type STRING value 'application/rss+xml'. "#EC NOTEXT
15 | constants APPLICATION_XML type STRING value 'application/xml'. "#EC NOTEXT
16 | constants APPLICATION_X_WWW_FORM_URLENC type STRING value 'application/x-www-form-urlencoded'. "#EC NOTEXT
17 | constants IMAGE_GIF type STRING value 'image/gif'. "#EC NOTEXT
18 | constants IMAGE_JPEG type STRING value 'image/jpeg'. "#EC NOTEXT
19 | constants IMAGE_PNG type STRING value 'image/png'. "#EC NOTEXT
20 | constants TEXT_CSS type STRING value 'text/css'. "#EC NOTEXT
21 | constants TEXT_CSV type STRING value 'text/csv'. "#EC NOTEXT
22 | constants TEXT_HTML type STRING value 'text/html'. "#EC NOTEXT
23 | constants TEXT_PLAIN type STRING value 'text/plain'. "#EC NOTEXT
24 | constants TEXT_XML type STRING value 'text/xml'. "#EC NOTEXT
25 | protected section.
26 | *"* protected components of class zCL_HTTP_MIME_TYPES
27 | *"* do not include other source files here!!!
28 | private section.
29 | *"* private components of class zCL_HTTP_MIME_TYPES
30 | *"* do not include other source files here!!!
31 | ENDCLASS.
32 |
33 |
34 |
35 | CLASS ZCL_HTTP_MIME_TYPES IMPLEMENTATION.
36 | ENDCLASS.
37 |
--------------------------------------------------------------------------------
/rest/zcl_http_status_codes.abap:
--------------------------------------------------------------------------------
1 | class ZCL_HTTP_STATUS_CODES definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | *"* public components of class zCL_HTTP_STATUS_CODES
10 | *"* do not include other source files here!!!
11 | constants ACCEPTED type I value 202. "#EC NOTEXT
12 | constants BAD_GATEWAY type I value 502. "#EC NOTEXT
13 | constants BAD_REQUEST type I value 400. "#EC NOTEXT
14 | constants CONFLICT type I value 409. "#EC NOTEXT
15 | constants CONTINUE type I value 100. "#EC NOTEXT
16 | constants CREATED type I value 201. "#EC NOTEXT
17 | constants EXPECTATION_FAILED type I value 417. "#EC NOTEXT
18 | constants FORBIDDEN type I value 403. "#EC NOTEXT
19 | constants FOUND type I value 302. "#EC NOTEXT
20 | constants GATEWAY_TIMEOUT type I value 504. "#EC NOTEXT
21 | constants GONE type I value 410. "#EC NOTEXT
22 | constants HTTP_VERSION_NOT_SUPPORTED type I value 505. "#EC NOTEXT
23 | constants INTERNAL_SERVER_ERROR type I value 500. "#EC NOTEXT
24 | constants LENGTH_REQUIRED type I value 411. "#EC NOTEXT
25 | constants METHOD_NOT_ALLOWED type I value 405. "#EC NOTEXT
26 | constants MOVED_PERMANENTLY type I value 301. "#EC NOTEXT
27 | constants MULTIPLE_CHOICES type I value 300. "#EC NOTEXT
28 | constants NONAUTHORITATIVE_INFORMATIO type I value 203. "#EC NOTEXT
29 | constants NOT_ACCEPTABLE type I value 406. "#EC NOTEXT
30 | constants NOT_FOUND type I value 404. "#EC NOTEXT
31 | constants NOT_IMPLEMENTED type I value 501. "#EC NOTEXT
32 | constants NOT_MODIFIED type I value 304. "#EC NOTEXT
33 | constants NO_CONTENT type I value 204. "#EC NOTEXT
34 | constants OK type I value 200. "#EC NOTEXT
35 | constants PARTIAL_CONTENT type I value 206. "#EC NOTEXT
36 | constants PAYMENT_REQUIRED type I value 402. "#EC NOTEXT
37 | constants PRECONDITION_FAILED type I value 412. "#EC NOTEXT
38 | constants PROXY_AUTHENTICATION_REQUIR type I value 407. "#EC NOTEXT
39 | constants REQUESTED_RANGE_NOT_SATISFI type I value 416. "#EC NOTEXT
40 | constants REQUESTURI_TOO_LARGE type I value 414. "#EC NOTEXT
41 | constants REQUEST_ENTITY_TOO_LARGE type I value 413. "#EC NOTEXT
42 | constants REQUEST_TIMEOUT type I value 408. "#EC NOTEXT
43 | constants RESET_CONTENT type I value 205. "#EC NOTEXT
44 | constants SEE_OTHER type I value 303. "#EC NOTEXT
45 | constants SERVICE_UNAVAILABLE type I value 503. "#EC NOTEXT
46 | constants SWITCHING_PROTOCOLS type I value 101. "#EC NOTEXT
47 | constants TEMPORARY_REDIRECT type I value 307. "#EC NOTEXT
48 | constants UNAUTHORIZED type I value 401. "#EC NOTEXT
49 | constants UNSUPPORTED_MEDIA_TYPE type I value 415. "#EC NOTEXT
50 | constants USE_PROXY type I value 305. "#EC NOTEXT
51 | protected section.
52 | *"* protected components of class zCL_HTTP_STATUS_CODES
53 | *"* do not include other source files here!!!
54 | private section.
55 | *"* private components of class zCL_HTTP_STATUS_CODES
56 | *"* do not include other source files here!!!
57 | ENDCLASS.
58 |
59 |
60 |
61 | CLASS ZCL_HTTP_STATUS_CODES IMPLEMENTATION.
62 | ENDCLASS.
63 |
--------------------------------------------------------------------------------
/rest/zcl_request.abap:
--------------------------------------------------------------------------------
1 | class ZCL_REQUEST definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | data REQUEST type ref to IF_HTTP_REQUEST .
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !REQUEST type ref to IF_HTTP_REQUEST .
14 | methods GET_BODY_BINARY
15 | returning
16 | value(RETURNING) type XSTRING .
17 | methods GET_BODY_TEXT
18 | returning
19 | value(RETURNING) type STRING .
20 | methods GET_BODY_JSON
21 | returning
22 | value(RETURNING) type ref to ZIF_JSON_VALUE
23 | raising
24 | ZCX_JSON_PARSE_ERROR .
25 | methods GET_CONTENT_TYPE
26 | returning
27 | value(RETURNING) type STRING .
28 | methods GET_HEADER
29 | importing
30 | !NAME type STRING
31 | returning
32 | value(RETURNING) type STRING .
33 | methods GET_METHOD
34 | returning
35 | value(RETURNING) type STRING .
36 | methods GET_PARAMETER
37 | importing
38 | !NAME type STRING
39 | returning
40 | value(RETURNING) type STRING .
41 | methods GET_RAW_MESSAGE
42 | returning
43 | value(RETURNING) type XSTRING .
44 | methods GET_REQUESTURI
45 | returning
46 | value(RETURNING) type STRING .
47 | methods LIST_HEADERS
48 | returning
49 | value(RETURNING) type TIHTTPNVP .
50 | methods LIST_PARAMETERS
51 | returning
52 | value(RETURNING) type TIHTTPNVP .
53 | protected section.
54 | *"* protected components of class zCL_REQUEST
55 | *"* do not include other source files here!!!
56 | private section.
57 | ENDCLASS.
58 |
59 |
60 |
61 | CLASS ZCL_REQUEST IMPLEMENTATION.
62 |
63 |
64 | * ---------------------------------------------------------------------------------------+
65 | * | Instance Public Method ZCL_REQUEST->CONSTRUCTOR
66 | * +-------------------------------------------------------------------------------------------------+
67 | * | [--->] REQUEST TYPE REF TO IF_HTTP_REQUEST
68 | * +--------------------------------------------------------------------------------------
69 | method constructor.
70 | super->constructor( ).
71 | me->request = request.
72 | endmethod.
73 |
74 |
75 | * ---------------------------------------------------------------------------------------+
76 | * | Instance Public Method ZCL_REQUEST->GET_BODY_BINARY
77 | * +-------------------------------------------------------------------------------------------------+
78 | * | [<-()] RETURNING TYPE XSTRING
79 | * +--------------------------------------------------------------------------------------
80 | method get_body_binary.
81 | */**
82 | * Retrieves the body of the request as binary data.
83 | */
84 | returning = me->request->get_data( ).
85 | endmethod.
86 |
87 |
88 | * ---------------------------------------------------------------------------------------+
89 | * | Instance Public Method ZCL_REQUEST->GET_BODY_JSON
90 | * +-------------------------------------------------------------------------------------------------+
91 | * | [<-()] RETURNING TYPE REF TO ZIF_JSON_VALUE
92 | * | [!CX!] ZCX_JSON_PARSE_ERROR
93 | * +--------------------------------------------------------------------------------------
94 | method get_body_json.
95 | */**
96 | * Retrieves the body of the request as a JSON value object.
97 | */
98 | data: json_parser type ref to zcl_json_parser,
99 | json_string type string.
100 | create object json_parser.
101 | json_string = me->request->get_cdata( ).
102 | returning = json_parser->deserialize( json_string ).
103 | endmethod.
104 |
105 |
106 | * ---------------------------------------------------------------------------------------+
107 | * | Instance Public Method ZCL_REQUEST->GET_BODY_TEXT
108 | * +-------------------------------------------------------------------------------------------------+
109 | * | [<-()] RETURNING TYPE STRING
110 | * +--------------------------------------------------------------------------------------
111 | method get_body_text.
112 | */**
113 | * Retrieves the body of the request as a string.
114 | */
115 | returning = me->request->get_cdata( ).
116 | endmethod.
117 |
118 |
119 | * ---------------------------------------------------------------------------------------+
120 | * | Instance Public Method ZCL_REQUEST->GET_CONTENT_TYPE
121 | * +-------------------------------------------------------------------------------------------------+
122 | * | [<-()] RETURNING TYPE STRING
123 | * +--------------------------------------------------------------------------------------
124 | method get_content_type.
125 | */**
126 | * Returns the MIME type of the body of the request, or null if the type is not known.
127 | */
128 | returning = me->request->get_content_type( ).
129 | endmethod.
130 |
131 |
132 | * ---------------------------------------------------------------------------------------+
133 | * | Instance Public Method ZCL_REQUEST->GET_HEADER
134 | * +-------------------------------------------------------------------------------------------------+
135 | * | [--->] NAME TYPE STRING
136 | * | [<-()] RETURNING TYPE STRING
137 | * +--------------------------------------------------------------------------------------
138 | method get_header.
139 | */**
140 | * Returns the value of the specified request header
141 | * as a string. If the request did not include a header
142 | * of the specified name, this method returns null.
143 | */
144 | returning = me->request->get_header_field( name ).
145 | endmethod.
146 |
147 |
148 | * ---------------------------------------------------------------------------------------+
149 | * | Instance Public Method ZCL_REQUEST->GET_METHOD
150 | * +-------------------------------------------------------------------------------------------------+
151 | * | [<-()] RETURNING TYPE STRING
152 | * +--------------------------------------------------------------------------------------
153 | method get_method.
154 | */**
155 | * Returns the name of the HTTP method with which this request was made,
156 | * for example, GET, POST, or PUT.
157 | */
158 | returning = me->request->if_http_entity~get_header_field( '~request_method' ).
159 | " returning = me->request->get_method( ).
160 | endmethod.
161 |
162 |
163 | * ---------------------------------------------------------------------------------------+
164 | * | Instance Public Method ZCL_REQUEST->GET_PARAMETER
165 | * +-------------------------------------------------------------------------------------------------+
166 | * | [--->] NAME TYPE STRING
167 | * | [<-()] RETURNING TYPE STRING
168 | * +--------------------------------------------------------------------------------------
169 | method get_parameter.
170 | */**
171 | * Returns the value of a request parameter as a String,
172 | * or null if the parameter does not exist.
173 | * Request parameters are extra information sent with the request.
174 | */
175 | returning = me->request->get_form_field_cs( name ).
176 | endmethod.
177 |
178 |
179 | * ---------------------------------------------------------------------------------------+
180 | * | Instance Public Method ZCL_REQUEST->GET_RAW_MESSAGE
181 | * +-------------------------------------------------------------------------------------------------+
182 | * | [<-()] RETURNING TYPE XSTRING
183 | * +--------------------------------------------------------------------------------------
184 | method get_raw_message.
185 | returning = me->request->get_raw_message( ).
186 | endmethod.
187 |
188 |
189 | * ---------------------------------------------------------------------------------------+
190 | * | Instance Public Method ZCL_REQUEST->GET_REQUESTURI
191 | * +-------------------------------------------------------------------------------------------------+
192 | * | [<-()] RETURNING TYPE STRING
193 | * +--------------------------------------------------------------------------------------
194 | method get_requesturi.
195 | */**
196 | * Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
197 | * Examples:
198 | * First line of HTTP request Returned Value
199 | * POST /some/path.html HTTP/1.1 /some/path.html
200 | * GET http://foo.bar/a.html HTTP/1.0 /a.html
201 | * HEAD /xyz?a=b HTTP/1.1 /xyz
202 | */
203 | returning = me->request->get_header_field( '~path_info' ).
204 | endmethod.
205 |
206 |
207 | * ---------------------------------------------------------------------------------------+
208 | * | Instance Public Method ZCL_REQUEST->LIST_HEADERS
209 | * +-------------------------------------------------------------------------------------------------+
210 | * | [<-()] RETURNING TYPE TIHTTPNVP
211 | * +--------------------------------------------------------------------------------------
212 | method list_headers.
213 | */**
214 | * Returns all request headers
215 | */
216 | me->request->get_header_fields( changing fields = returning ).
217 | endmethod.
218 |
219 |
220 | * ---------------------------------------------------------------------------------------+
221 | * | Instance Public Method ZCL_REQUEST->LIST_PARAMETERS
222 | * +-------------------------------------------------------------------------------------------------+
223 | * | [<-()] RETURNING TYPE TIHTTPNVP
224 | * +--------------------------------------------------------------------------------------
225 | method list_parameters.
226 | */**
227 | * Returns all request parameters
228 | */
229 | me->request->get_form_fields_cs( changing fields = returning ).
230 | endmethod.
231 | ENDCLASS.
232 |
--------------------------------------------------------------------------------
/rest/zcl_resource.abap:
--------------------------------------------------------------------------------
1 | class ZCL_RESOURCE definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | abstract
5 | create public
6 |
7 | global friends ZCL_DISPATCHER .
8 |
9 | public section.
10 |
11 | *"* public components of class zCL_RESOURCE
12 | *"* do not include other source files here!!!
13 | methods CREATE
14 | importing
15 | !REQUEST type ref to ZCL_REQUEST
16 | !RESPONSE type ref to ZCL_RESPONSE .
17 | methods READ
18 | importing
19 | !REQUEST type ref to ZCL_REQUEST
20 | !RESPONSE type ref to ZCL_RESPONSE .
21 | methods UPDATE
22 | importing
23 | !REQUEST type ref to ZCL_REQUEST
24 | !RESPONSE type ref to ZCL_RESPONSE .
25 | methods DELETE
26 | importing
27 | !REQUEST type ref to ZCL_REQUEST
28 | !RESPONSE type ref to ZCL_RESPONSE .
29 | methods HEAD
30 | importing
31 | !REQUEST type ref to ZCL_REQUEST
32 | !RESPONSE type ref to ZCL_RESPONSE .
33 | methods NAME
34 | final
35 | returning
36 | value(RETURNING) type ZRESOURCENAME .
37 | methods PATH
38 | final
39 | returning
40 | value(RETURNING) type ZRESOURCEPATH .
41 | methods ID
42 | final
43 | returning
44 | value(RETURNING) type STRING .
45 | protected section.
46 | *"* protected components of class zCL_RESOURCE
47 | *"* do not include other source files here!!!
48 | private section.
49 |
50 | data _NAME type ZRESOURCENAME .
51 | data _PATH type ZRESOURCEPATH .
52 | data _ID type STRING .
53 | ENDCLASS.
54 |
55 |
56 |
57 | CLASS ZCL_RESOURCE IMPLEMENTATION.
58 |
59 |
60 | * ---------------------------------------------------------------------------------------+
61 | * | Instance Public Method ZCL_RESOURCE->CREATE
62 | * +-------------------------------------------------------------------------------------------------+
63 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
64 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
65 | * +--------------------------------------------------------------------------------------
66 | method create.
67 | */**
68 | * Handle the POST method:
69 | * - parses the HTTP body and instantiates a new resource
70 | * - creates the new resource using the repository
71 | *
72 | * Method specification:
73 | * - SAFE: no
74 | * - IDEMPOTENT: no
75 | *
76 | * Common responses:
77 | * - 200 with the created resource as HTTP body
78 | * - 201 without HTTP body, with Location header referring to the created resource
79 | * - 204 without HTTP body, same as 200 but the created resource is not returned
80 | */
81 | " Method not allowed unless overridden by subclass
82 | data message type string.
83 | message e005(rest) into message.
84 | response->send_error( code = zcl_http_status_codes=>method_not_allowed message = message ).
85 | endmethod.
86 |
87 |
88 | * ---------------------------------------------------------------------------------------+
89 | * | Instance Public Method ZCL_RESOURCE->DELETE
90 | * +-------------------------------------------------------------------------------------------------+
91 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
92 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
93 | * +--------------------------------------------------------------------------------------
94 | method delete.
95 | */**
96 | * Handle the DELETE method:
97 | * - deletes the referred resource
98 | *
99 | * Method specification:
100 | * - SAFE: no
101 | * - IDEMPOTENT: yes
102 | *
103 | * Common responses:
104 | * - 200 with the deleted resource as HTTP body
105 | * - 202 without HTTP body, used for asynchronous processing
106 | * - 204 without HTTP body, same as 200 but the deleted resource is not returned
107 | */
108 | " Method not allowed unless overridden by subclass
109 | data message type string.
110 | message e005(rest) into message.
111 | response->send_error( code = zcl_http_status_codes=>method_not_allowed message = message ).
112 | endmethod.
113 |
114 |
115 | * ---------------------------------------------------------------------------------------+
116 | * | Instance Public Method ZCL_RESOURCE->HEAD
117 | * +-------------------------------------------------------------------------------------------------+
118 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
119 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
120 | * +--------------------------------------------------------------------------------------
121 | method head.
122 | */**
123 | * Handle the HEAD method:
124 | * - exactly the same as the GET method, but ONLY returns the headers
125 | *
126 | * Method specification:
127 | * - SAFE: yes
128 | * - IDEMPOTENT: yes
129 | *
130 | * Common responses:
131 | * - 200 without HTTP body
132 | * - 404 without HTTP body, if the requested resource was not found
133 | */
134 | " Method not allowed unless overridden by subclass
135 | data message type string.
136 | message e005(rest) into message.
137 | response->send_error( code = zcl_http_status_codes=>method_not_allowed message = message ).
138 | endmethod.
139 |
140 |
141 | * ---------------------------------------------------------------------------------------+
142 | * | Instance Public Method ZCL_RESOURCE->ID
143 | * +-------------------------------------------------------------------------------------------------+
144 | * | [<-()] RETURNING TYPE STRING
145 | * +--------------------------------------------------------------------------------------
146 | method id.
147 | returning = _id.
148 | endmethod.
149 |
150 |
151 | * ---------------------------------------------------------------------------------------+
152 | * | Instance Public Method ZCL_RESOURCE->NAME
153 | * +-------------------------------------------------------------------------------------------------+
154 | * | [<-()] RETURNING TYPE ZRESOURCENAME
155 | * +--------------------------------------------------------------------------------------
156 | method name.
157 | returning = _name.
158 | endmethod.
159 |
160 |
161 | * ---------------------------------------------------------------------------------------+
162 | * | Instance Public Method ZCL_RESOURCE->PATH
163 | * +-------------------------------------------------------------------------------------------------+
164 | * | [<-()] RETURNING TYPE ZRESOURCEPATH
165 | * +--------------------------------------------------------------------------------------
166 | method path.
167 | returning = _path.
168 | endmethod.
169 |
170 |
171 | * ---------------------------------------------------------------------------------------+
172 | * | Instance Public Method ZCL_RESOURCE->READ
173 | * +-------------------------------------------------------------------------------------------------+
174 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
175 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
176 | * +--------------------------------------------------------------------------------------
177 | method read.
178 | */**
179 | * Handle the GET method:
180 | * - retrieves the referred resource from the repository
181 | * - formats the resource into the requested representation and
182 | * - returns the representation as the HTTP body using either the SEND_BINARY or SEND_TEXT methods of the response
183 | *
184 | * Method specification:
185 | * - SAFE: yes
186 | * - IDEMPOTENT: yes
187 | *
188 | * Common responses:
189 | * - 200 with the requested resource as HTTP body
190 | * - 404 without HTTP body, if the requested resource was not found
191 | */
192 | " Method not allowed unless overridden by subclass
193 | data message type string.
194 | message e005(rest) into message.
195 | response->send_error( code = zcl_http_status_codes=>method_not_allowed message = message ).
196 | endmethod.
197 |
198 |
199 | * ---------------------------------------------------------------------------------------+
200 | * | Instance Public Method ZCL_RESOURCE->UPDATE
201 | * +-------------------------------------------------------------------------------------------------+
202 | * | [--->] REQUEST TYPE REF TO ZCL_REQUEST
203 | * | [--->] RESPONSE TYPE REF TO ZCL_RESPONSE
204 | * +--------------------------------------------------------------------------------------
205 | method update.
206 | */**
207 | * Handle the PUT method:
208 | * - this method updates an existing resource, or creates a new resource if the referred resource does not exist yet
209 | * - retrieves the referred resource from the repository
210 | * - parses the HTTP body and instantiates a new resource
211 | * - creates a new, or replaces the existing resource with the new resource
212 | *
213 | * Method specification:
214 | * - SAFE: no
215 | * - IDEMPOTENT: yes
216 | *
217 | * Common responses:
218 | * - 200 with the updated resource as HTTP body
219 | * - 201 without HTTP body, with Location header referring to the updated resource
220 | * - 204 without HTTP body, same as 200 but the updated resource is not returned
221 | */
222 | " Method not allowed unless overridden by subclass
223 | data message type string.
224 | message e005(rest) into message.
225 | response->send_error( code = zcl_http_status_codes=>method_not_allowed message = message ).
226 | endmethod.
227 | ENDCLASS.
228 |
--------------------------------------------------------------------------------
/rest/zcx_resource_exception.abap:
--------------------------------------------------------------------------------
1 | class ZCX_RESOURCE_EXCEPTION definition
2 | public
3 | inheriting from ZCX_STATICEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_RESOURCE_EXCEPTION type SOTR_CONC value '00155D334B0D1EE2B982605B111AA991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_RESOURCE_EXCEPTION IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_RESOURCE_EXCEPTION->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_RESOURCE_EXCEPTION .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/rest/zcx_text_conversion_error.abap:
--------------------------------------------------------------------------------
1 | class ZCX_TEXT_CONVERSION_ERROR definition
2 | public
3 | inheriting from ZCX_RUNTIMEEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_TEXT_CONVERSION_ERROR type SOTR_CONC value '00155D334B0D1EE2B9826501204AA991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_TEXT_CONVERSION_ERROR IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_TEXT_CONVERSION_ERROR->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_TEXT_CONVERSION_ERROR .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/rest/zcx_uri_too_long.abap:
--------------------------------------------------------------------------------
1 | class ZCX_URI_TOO_LONG definition
2 | public
3 | inheriting from ZCX_STATICEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_URI_TOO_LONG type SOTR_CONC value '00155D334B0D1EE2B9826796ABECE991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_URI_TOO_LONG IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_URI_TOO_LONG->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_URI_TOO_LONG .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/rest/zrestlog.abap:
--------------------------------------------------------------------------------
1 | report zrestlog no standard page heading line-size 1023.
2 |
3 | data: restlog_record type zrestlog,
4 | restlog_records type standard table of zrestlog,
5 | alv type ref to cl_salv_table,
6 | request_lines type standard table of string,
7 | request_line type string.
8 |
9 | select-options s_date for restlog_record-requestdate.
10 | select-options s_time for restlog_record-requesttime.
11 | select-options s_user for restlog_record-requestuser.
12 | select-options s_path for restlog_record-resourcepath.
13 | select-options s_name for restlog_record-resourcename.
14 |
15 | start-of-selection.
16 |
17 | select * into table restlog_records from zrestlog
18 | where requestdate in s_date and
19 | requesttime in s_time and
20 | requestuser in s_user and
21 | resourcepath in s_path and
22 | resourcename in s_name
23 | order by requestdate descending requesttime descending.
24 |
25 | end-of-selection.
26 |
27 | loop at restlog_records into restlog_record.
28 | condense: restlog_record-requestdate, restlog_record-requesttime, restlog_record-requestuser,
29 | restlog_record-resourcepath, restlog_record-resourcename, restlog_record-resourceid.
30 | write: / `Date: ` color col_key, restlog_record-requestdate.
31 | write: / `Time: ` color col_key, restlog_record-requesttime.
32 | write: / `User: ` color col_key, restlog_record-requestuser.
33 | write: / `Path: ` color col_key, restlog_record-resourcepath.
34 | write: / `Name: ` color col_key, restlog_record-resourcename.
35 | write: / `Id: ` color col_key, restlog_record-resourceid.
36 | write: / `Request:` color col_key.
37 | split restlog_record-request at cl_abap_char_utilities=>cr_lf into table request_lines.
38 | loop at request_lines into request_line.
39 | write: / request_line.
40 | endloop.
41 | uline.
42 | endloop.
--------------------------------------------------------------------------------
/unittest/zcl_ut_json_util.abap:
--------------------------------------------------------------------------------
1 | class ZCL_UT_JSON_UTIL definition
2 | public
3 | abstract
4 | create public
5 | for testing
6 | duration short
7 | risk level harmless .
8 |
9 | public section.
10 | *"* public components of class zCL_UT_JSON_UTIL
11 | *"* do not include other source files here!!!
12 | protected section.
13 |
14 | *"* protected components of class zCL_UT_JSON_UTIL
15 | *"* do not include other source files here!!!
16 | methods TEST
17 | for testing .
18 | private section.
19 |
20 | *"* private components of class zCL_UT_JSON_UTIL
21 | *"* do not include other source files here!!!
22 | methods SETUP .
23 | ENDCLASS.
24 |
25 |
26 |
27 | CLASS ZCL_UT_JSON_UTIL IMPLEMENTATION.
28 |
29 |
30 | * ---------------------------------------------------------------------------------------+
31 | * | Instance Private Method ZCL_UT_JSON_UTIL->SETUP
32 | * +-------------------------------------------------------------------------------------------------+
33 | * +--------------------------------------------------------------------------------------
34 | method setup.
35 | endmethod. "setup
36 |
37 |
38 | * ---------------------------------------------------------------------------------------+
39 | * | Instance Protected Method ZCL_UT_JSON_UTIL->TEST
40 | * +-------------------------------------------------------------------------------------------------+
41 | * +--------------------------------------------------------------------------------------
42 | method test.
43 | data array type ref to zcl_json_array.
44 | create object array.
45 | data object type ref to zcl_json_object.
46 | create object object.
47 |
48 | data pair_with_array type ref to zcl_json_pair.
49 | data pair_with_bool type ref to zcl_json_pair.
50 | data pair_with_null type ref to zcl_json_pair.
51 | data pair_with_number type ref to zcl_json_pair.
52 | data pair_with_object type ref to zcl_json_pair.
53 | data pair_with_string type ref to zcl_json_pair.
54 |
55 | pair_with_array = zcl_json_util=>new_pair_with_array( name = `array` value = array ).
56 | pair_with_bool = zcl_json_util=>new_pair_with_bool( name = `bool` value = abap_true ).
57 | pair_with_null = zcl_json_util=>new_pair_with_null( name = `null`).
58 | pair_with_number = zcl_json_util=>new_pair_with_number( name = `number` value = `10.45` ).
59 | pair_with_object = zcl_json_util=>new_pair_with_object( name = `object` value = object ).
60 | pair_with_string = zcl_json_util=>new_pair_with_string( name = `string` value = `Hello, World!` ).
61 |
62 | data object_with_array_pair type ref to zcl_json_object.
63 | data object_with_bool_pair type ref to zcl_json_object.
64 | data object_with_null_pair type ref to zcl_json_object.
65 | data object_with_number_pair type ref to zcl_json_object.
66 | data object_with_object_pair type ref to zcl_json_object.
67 | data object_with_string_pair type ref to zcl_json_object.
68 |
69 | object_with_array_pair = zcl_json_util=>new_object_with_array_pair( name = `obj_array` value = array ).
70 | object_with_bool_pair = zcl_json_util=>new_object_with_bool_pair( name = `obj_bool` value = abap_true ).
71 | object_with_null_pair = zcl_json_util=>new_object_with_null_pair( name = `obj_null` ).
72 | object_with_number_pair = zcl_json_util=>new_object_with_number_pair( name = `obj_number` value = `10.45` ).
73 | object_with_object_pair = zcl_json_util=>new_object_with_object_pair( name = `obj_object` value = object ).
74 | object_with_string_pair = zcl_json_util=>new_object_with_string_pair( name = `obj_string` value = `Hello, World!` ).
75 |
76 | data root_object type ref to zcl_json_object.
77 | data root_array type ref to zcl_json_array.
78 | data root_pair type ref to zcl_json_pair.
79 | create object root_object.
80 | create object root_array.
81 | root_object->add( pair_with_array ).
82 | root_object->add( pair_with_bool ).
83 | root_object->add( pair_with_null ).
84 | root_object->add( pair_with_number ).
85 | root_object->add( pair_with_object ).
86 | root_object->add( pair_with_string ).
87 | root_array->add( object_with_array_pair ).
88 | root_array->add( object_with_bool_pair ).
89 | root_array->add( object_with_null_pair ).
90 | root_array->add( object_with_number_pair ).
91 | root_array->add( object_with_object_pair ).
92 | root_array->add( object_with_string_pair ).
93 | root_pair = zcl_json_util=>new_pair_with_array( name = `root_array` value = root_array ).
94 | root_object->add( root_pair ).
95 |
96 | data parser type ref to zcl_json_parser.
97 | create object parser.
98 | data json_string type string.
99 | json_string = parser->serialize( root_object ).
100 | data json_string_valid type string.
101 | json_string_valid = `{ "array" : [ ], "bool" : true, "null" : null, "number" : 1.0449999999999999E+01, "object" : { }, "string" : "Hello, World!", `.
102 | concatenate json_string_valid `"root_array" : [ { "obj_array" : [ ] }, { "obj_bool" : true }, { "obj_null" : null }, ` into json_string_valid.
103 | concatenate json_string_valid `{ "obj_number" : 1.0449999999999999E+01 }, { "obj_object" : { } }, { "obj_string" : "Hello, World!" } ] }` into json_string_valid.
104 |
105 | cl_aunit_assert=>assert_equals( act = json_string exp = json_string_valid ).
106 | endmethod.
107 | ENDCLASS.
108 |
--------------------------------------------------------------------------------
/xml/zcl_xmlparser.abap:
--------------------------------------------------------------------------------
1 | class ZCL_XMLPARSER definition
2 | public
3 | inheriting from ZCL_OBJECT
4 | final
5 | create public .
6 |
7 | public section.
8 | *"* public components of class zCL_XMLPARSER
9 | *"* do not include other source files here!!!
10 | type-pools ABAP .
11 |
12 | constants ERROR_DELEGATEABORTEDPARSE type I value 1. "#EC NOTEXT
13 | constants ERROR_UNSUPPORTEDNODETYPE type I value 2. "#EC NOTEXT
14 | constants ERROR_EMPTYDOCUMENT type I value 3. "#EC NOTEXT
15 |
16 | methods INIT_WITH_STRING
17 | importing
18 | !XMLSTRING type STRING
19 | raising
20 | ZCX_INVALID_XML .
21 | methods SET_DELEGATE
22 | importing
23 | !DELEGATE type ref to ZIF_XMLPARSER_DELEGATE .
24 | methods PARSE
25 | returning
26 | value(RETURNING) type ABAP_BOOL .
27 | methods ABORT_PARSING .
28 | protected section.
29 | *"* protected components of class zCL_XMLPARSER
30 | *"* do not include other source files here!!!
31 | private section.
32 |
33 | *"* private components of class zCL_XMLPARSER
34 | *"* do not include other source files here!!!
35 | data DELEGATE type ref to ZIF_XMLPARSER_DELEGATE .
36 | data IXML_DOCUMENT type ref to IF_IXML_DOCUMENT .
37 | data ABORTED_BY_DELEGATE type ABAP_BOOL value ABAP_FALSE. "#EC NOTEXT . . " .
38 |
39 | methods PROCESS_NODE
40 | importing
41 | !NODE type ref to IF_IXML_NODE
42 | returning
43 | value(RETURNING) type ABAP_BOOL .
44 | methods DID_START_DOCUMENT .
45 | methods DID_END_DOCUMENT .
46 | methods DID_START_ELEMENT
47 | importing
48 | !ELEMENT type ref to IF_IXML_NODE .
49 | methods DID_END_ELEMENT
50 | importing
51 | !ELEMENT type ref to IF_IXML_NODE .
52 | methods FOUND_CHARACTERS
53 | importing
54 | !ELEMENT type ref to IF_IXML_NODE .
55 | methods FOUND_COMMENT
56 | importing
57 | !ELEMENT type ref to IF_IXML_NODE .
58 | methods ERROR_OCCURRED
59 | importing
60 | !ERROR type I .
61 | ENDCLASS.
62 |
63 |
64 |
65 | CLASS ZCL_XMLPARSER IMPLEMENTATION.
66 |
67 |
68 | * ---------------------------------------------------------------------------------------+
69 | * | Instance Public Method ZCL_XMLPARSER->ABORT_PARSING
70 | * +-------------------------------------------------------------------------------------------------+
71 | * +--------------------------------------------------------------------------------------
72 | method abort_parsing.
73 | me->aborted_by_delegate = abap_true.
74 | endmethod. "abort_parsing
75 |
76 |
77 | * ---------------------------------------------------------------------------------------+
78 | * | Instance Private Method ZCL_XMLPARSER->DID_END_DOCUMENT
79 | * +-------------------------------------------------------------------------------------------------+
80 | * +--------------------------------------------------------------------------------------
81 | method did_end_document.
82 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
83 | me->delegate->parser_did_end_document( parser = me ).
84 | endif.
85 | endmethod. "did_end_document
86 |
87 |
88 | * ---------------------------------------------------------------------------------------+
89 | * | Instance Private Method ZCL_XMLPARSER->DID_END_ELEMENT
90 | * +-------------------------------------------------------------------------------------------------+
91 | * | [--->] ELEMENT TYPE REF TO IF_IXML_NODE
92 | * +--------------------------------------------------------------------------------------
93 | method did_end_element.
94 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
95 | data elementname type string.
96 | elementname = element->get_name( ).
97 | me->delegate->parser_did_end_element( parser = me elementname = elementname ).
98 | endif.
99 | endmethod. "did_end_element
100 |
101 |
102 | * ---------------------------------------------------------------------------------------+
103 | * | Instance Private Method ZCL_XMLPARSER->DID_START_DOCUMENT
104 | * +-------------------------------------------------------------------------------------------------+
105 | * +--------------------------------------------------------------------------------------
106 | method did_start_document.
107 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
108 | me->delegate->parser_did_start_document( parser = me ).
109 | endif.
110 | endmethod. "did_start_document
111 |
112 |
113 | * ---------------------------------------------------------------------------------------+
114 | * | Instance Private Method ZCL_XMLPARSER->DID_START_ELEMENT
115 | * +-------------------------------------------------------------------------------------------------+
116 | * | [--->] ELEMENT TYPE REF TO IF_IXML_NODE
117 | * +--------------------------------------------------------------------------------------
118 | method did_start_element.
119 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
120 | data elementname type string.
121 | elementname = element->get_name( ).
122 | me->delegate->parser_did_start_element( parser = me elementname = elementname ).
123 | endif.
124 | endmethod. "did_start_element
125 |
126 |
127 | * ---------------------------------------------------------------------------------------+
128 | * | Instance Private Method ZCL_XMLPARSER->ERROR_OCCURRED
129 | * +-------------------------------------------------------------------------------------------------+
130 | * | [--->] ERROR TYPE I
131 | * +--------------------------------------------------------------------------------------
132 | method error_occurred.
133 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
134 | me->delegate->parser_error_occurred( parser = me error = error ).
135 | endif.
136 | endmethod. "error_occurred
137 |
138 |
139 | * ---------------------------------------------------------------------------------------+
140 | * | Instance Private Method ZCL_XMLPARSER->FOUND_CHARACTERS
141 | * +-------------------------------------------------------------------------------------------------+
142 | * | [--->] ELEMENT TYPE REF TO IF_IXML_NODE
143 | * +--------------------------------------------------------------------------------------
144 | method found_characters.
145 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
146 | data characters type string.
147 | characters = element->get_value( ).
148 | me->delegate->parser_found_characters( parser = me characters = characters ).
149 | endif.
150 | endmethod. "found_characters
151 |
152 |
153 | * ---------------------------------------------------------------------------------------+
154 | * | Instance Private Method ZCL_XMLPARSER->FOUND_COMMENT
155 | * +-------------------------------------------------------------------------------------------------+
156 | * | [--->] ELEMENT TYPE REF TO IF_IXML_NODE
157 | * +--------------------------------------------------------------------------------------
158 | method found_comment.
159 | if me->delegate is bound and me->aborted_by_delegate = abap_false.
160 | data comment type string.
161 | comment = element->get_value( ).
162 | me->delegate->parser_found_comment( parser = me comment = comment ).
163 | endif.
164 | endmethod. "found_comment
165 |
166 |
167 | * ---------------------------------------------------------------------------------------+
168 | * | Instance Public Method ZCL_XMLPARSER->INIT_WITH_STRING
169 | * +-------------------------------------------------------------------------------------------------+
170 | * | [--->] XMLSTRING TYPE STRING
171 | * | [!CX!] ZCX_INVALID_XML
172 | * +--------------------------------------------------------------------------------------
173 | method init_with_string.
174 | data ixml type ref to if_ixml.
175 | ixml = cl_ixml=>create( ).
176 | data streamfactory type ref to if_ixml_stream_factory.
177 | streamfactory = ixml->create_stream_factory( ).
178 | data istream type ref to if_ixml_istream.
179 | istream = streamfactory->create_istream_string( xmlstring ).
180 | data parser type ref to if_ixml_parser.
181 | me->ixml_document = ixml->create_document( ).
182 | parser = ixml->create_parser( stream_factory = streamfactory istream = istream document = me->ixml_document ).
183 | if parser->parse( ) <> 0.
184 | istream->close( ).
185 | raise exception type zcx_invalid_xml.
186 | endif.
187 | istream->close( ).
188 | endmethod. "init_with_string
189 |
190 |
191 | * ---------------------------------------------------------------------------------------+
192 | * | Instance Public Method ZCL_XMLPARSER->PARSE
193 | * +-------------------------------------------------------------------------------------------------+
194 | * | [<-()] RETURNING TYPE ABAP_BOOL
195 | * +--------------------------------------------------------------------------------------
196 | method parse.
197 | if me->ixml_document is bound.
198 | me->process_node( node = me->ixml_document ).
199 | else.
200 | " Nothing to parse
201 | me->error_occurred( error = error_emptydocument ).
202 | returning = abap_false.
203 | return.
204 | endif.
205 | endmethod. "parse
206 |
207 |
208 | * ---------------------------------------------------------------------------------------+
209 | * | Instance Private Method ZCL_XMLPARSER->PROCESS_NODE
210 | * +-------------------------------------------------------------------------------------------------+
211 | * | [--->] NODE TYPE REF TO IF_IXML_NODE
212 | * | [<-()] RETURNING TYPE ABAP_BOOL
213 | * +--------------------------------------------------------------------------------------
214 | method process_node.
215 | if me->aborted_by_delegate = abap_false.
216 | " The node type tells us if we're at a new element, or inside an element
217 | data node_type type i.
218 | node_type = node->get_type( ).
219 | case node_type.
220 | when if_ixml_node=>co_node_document or if_ixml_node=>co_node_element. " New document or element
221 | " Start of document/element
222 | if node_type = if_ixml_node=>co_node_document.
223 | me->did_start_document( ).
224 | else.
225 | me->did_start_element( element = node ).
226 | endif.
227 | " Recursively process all child nodes
228 | data children type ref to if_ixml_node_list.
229 | children = node->get_children( ).
230 | data it_children type ref to if_ixml_node_iterator.
231 | it_children = children->create_iterator( ).
232 | do.
233 | data childnode type ref to if_ixml_node.
234 | childnode = it_children->get_next( ).
235 | if childnode is not bound.
236 | exit. " All child nodes processed
237 | endif.
238 | me->process_node( node = childnode ).
239 | enddo.
240 | " End of document/element
241 | if node_type = if_ixml_node=>co_node_document.
242 | me->did_end_document( ).
243 | else.
244 | me->did_end_element( element = node ).
245 | endif.
246 | " Parse finished successfully
247 | returning = abap_true.
248 | return.
249 | when if_ixml_node=>co_node_text. " Characters inside an element
250 | me->found_characters( element = node ).
251 | " Parse finished successfully
252 | returning = abap_true.
253 | return.
254 | when if_ixml_node=>co_node_comment. " Comment
255 | me->found_comment( element = node ).
256 | " Parse finished successfully
257 | returning = abap_true.
258 | return.
259 | when others. " Unsupported node type
260 | me->error_occurred( error = error_unsupportednodetype ).
261 | " Parse finished with errors
262 | returning = abap_false.
263 | return.
264 | endcase.
265 | else.
266 | " Parse aborted
267 | returning = abap_false.
268 | endif.
269 | endmethod. "process_node
270 |
271 |
272 | * ---------------------------------------------------------------------------------------+
273 | * | Instance Public Method ZCL_XMLPARSER->SET_DELEGATE
274 | * +-------------------------------------------------------------------------------------------------+
275 | * | [--->] DELEGATE TYPE REF TO ZIF_XMLPARSER_DELEGATE
276 | * +--------------------------------------------------------------------------------------
277 | method set_delegate.
278 | me->delegate = delegate.
279 | endmethod. "set_delegate
280 | ENDCLASS.
281 |
--------------------------------------------------------------------------------
/xml/zcx_invalid_xml.abap:
--------------------------------------------------------------------------------
1 | class ZCX_INVALID_XML definition
2 | public
3 | inheriting from ZCX_STATICEXCEPTION
4 | final
5 | create public .
6 |
7 | public section.
8 |
9 | constants ZCX_INVALID_XML type SOTR_CONC value '00155D334B0D1EE2B8FDBDAF0809A991'. "#EC NOTEXT
10 |
11 | methods CONSTRUCTOR
12 | importing
13 | !TEXTID like TEXTID optional
14 | !PREVIOUS like PREVIOUS optional
15 | !MESSAGE type STRING optional .
16 | protected section.
17 | private section.
18 | ENDCLASS.
19 |
20 |
21 |
22 | CLASS ZCX_INVALID_XML IMPLEMENTATION.
23 |
24 |
25 | * ---------------------------------------------------------------------------------------+
26 | * | Instance Public Method ZCX_INVALID_XML->CONSTRUCTOR
27 | * +-------------------------------------------------------------------------------------------------+
28 | * | [--->] TEXTID LIKE TEXTID(optional)
29 | * | [--->] PREVIOUS LIKE PREVIOUS(optional)
30 | * | [--->] MESSAGE TYPE STRING(optional)
31 | * +--------------------------------------------------------------------------------------
32 | method CONSTRUCTOR.
33 | CALL METHOD SUPER->CONSTRUCTOR
34 | EXPORTING
35 | TEXTID = TEXTID
36 | PREVIOUS = PREVIOUS
37 | MESSAGE = MESSAGE
38 | .
39 | IF textid IS INITIAL.
40 | me->textid = ZCX_INVALID_XML .
41 | ENDIF.
42 | endmethod.
43 | ENDCLASS.
44 |
--------------------------------------------------------------------------------
/xml/zif_xmlparser_delegate.abap:
--------------------------------------------------------------------------------
1 | interface ZIF_XMLPARSER_DELEGATE
2 | public .
3 |
4 |
5 | methods PARSER_DID_START_DOCUMENT
6 | importing
7 | !PARSER type ref to ZCL_XMLPARSER .
8 | methods PARSER_DID_END_DOCUMENT
9 | importing
10 | !PARSER type ref to ZCL_XMLPARSER .
11 | methods PARSER_DID_START_ELEMENT
12 | importing
13 | !PARSER type ref to ZCL_XMLPARSER
14 | !ELEMENTNAME type STRING .
15 | methods PARSER_DID_END_ELEMENT
16 | importing
17 | !PARSER type ref to ZCL_XMLPARSER
18 | !ELEMENTNAME type STRING .
19 | methods PARSER_FOUND_CHARACTERS
20 | importing
21 | !PARSER type ref to ZCL_XMLPARSER
22 | !CHARACTERS type STRING .
23 | methods PARSER_FOUND_COMMENT
24 | importing
25 | !PARSER type ref to ZCL_XMLPARSER
26 | !COMMENT type STRING .
27 | methods PARSER_ERROR_OCCURRED
28 | importing
29 | !PARSER type ref to ZCL_XMLPARSER
30 | !ERROR type I .
31 | endinterface.
32 |
--------------------------------------------------------------------------------