├── .abapgit.xml ├── .github └── FUNDING.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── abaplint.json ├── img └── export_scarr.png └── src ├── package.devc.xml ├── zcx_export_cluster_table.clas.abap ├── zcx_export_cluster_table.clas.xml ├── zcx_export_empty.clas.abap ├── zcx_export_empty.clas.xml ├── zcx_export_error.clas.abap ├── zcx_export_error.clas.xml ├── zcx_export_invalid_name.clas.abap ├── zcx_export_invalid_name.clas.xml ├── zcx_export_object_exists.clas.abap ├── zcx_export_object_exists.clas.xml ├── zcx_export_table_duplicate.clas.abap ├── zcx_export_table_duplicate.clas.xml ├── zcx_export_to_file.clas.abap ├── zcx_export_to_file.clas.xml ├── zcx_export_tr_order.clas.abap ├── zcx_export_tr_order.clas.xml ├── zcx_export_where_clause_invali.clas.abap ├── zcx_export_where_clause_invali.clas.xml ├── zcx_import_error.clas.abap ├── zcx_import_error.clas.xml ├── zcx_import_merge_conflict.clas.abap ├── zcx_import_merge_conflict.clas.xml ├── zcx_import_not_allowed.clas.abap ├── zcx_import_not_allowed.clas.xml ├── zcx_import_object_not_exists.clas.abap ├── zcx_import_object_not_exists.clas.xml ├── zexport.msag.xml ├── zexport_batch_input.prog.abap ├── zexport_batch_input.prog.xml ├── zexport_bundle.clas.abap ├── zexport_bundle.clas.xml ├── zexport_bundle_in_cluster.clas.abap ├── zexport_bundle_in_cluster.clas.xml ├── zexport_bundle_in_tdc.clas.abap ├── zexport_bundle_in_tdc.clas.testclasses.abap ├── zexport_bundle_in_tdc.clas.xml ├── zexport_changed_sign.dtel.xml ├── zexport_fake_table.dtel.xml ├── zexport_file_mime_to_frontend.clas.abap ├── zexport_file_mime_to_frontend.clas.xml ├── zexport_gui.prog.abap ├── zexport_gui.prog.xml ├── zexport_is_initial.dtel.xml ├── zexport_overwrite.doma.xml ├── zexport_overwrite.dtel.xml ├── zexport_source_table.dtel.xml ├── zexport_table_list.tabl.xml ├── zexport_table_mod.tabl.xml ├── zexport_ut1.tabl.xml ├── zexport_ut2.tabl.xml ├── zexport_ut3.tabl.xml ├── zexport_utils.clas.abap ├── zexport_utils.clas.testclasses.abap ├── zexport_utils.clas.xml ├── zimport_bundle.clas.abap ├── zimport_bundle.clas.xml ├── zimport_bundle.fugr.lzimport_bundletop.abap ├── zimport_bundle.fugr.lzimport_bundletop.xml ├── zimport_bundle.fugr.saplzimport_bundle.abap ├── zimport_bundle.fugr.saplzimport_bundle.xml ├── zimport_bundle.fugr.xml ├── zimport_bundle.fugr.zimport_bundle_from_cluster.abap ├── zimport_bundle.fugr.zimport_bundle_from_tdc.abap ├── zimport_bundle.fugr.zimport_prevent_commit_work.abap ├── zimport_bundle.fugr.zrfc_import_bundle_from_tdc.abap ├── zimport_bundle.fugr.zrfcimport_bundle_from_cluster.abap ├── zimport_bundle_from_cluster.clas.abap ├── zimport_bundle_from_cluster.clas.testclasses.abap ├── zimport_bundle_from_cluster.clas.xml ├── zimport_bundle_from_tdc.clas.abap ├── zimport_bundle_from_tdc.clas.testclasses.abap ├── zimport_bundle_from_tdc.clas.xml ├── zimport_tvarvc.tabl.xml ├── zimport_ut1.tabl.xml ├── zimport_ut2.tabl.xml ├── ztest_export_gui.prog.abap └── ztest_export_gui.prog.xml /.abapgit.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | E 6 | /src/ 7 | PREFIX 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ["https://paypal.me/bunysae"] 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing # 2 | Contributions are welcome. Please open a issue before submitting a bigger pull-request. 3 | 4 | ## Styleguide ## 5 | Development should be sustainable (clean-code). 6 | Please stick to [clean-code styleguides](https://github.com/sap/styleguides). 7 | Refactorings are always welcome! 8 | 9 | * Please use the Pretty Printer with keywords in upper-case. 10 | * Code should be compatible with release 7.40. The sytnax check 11 | shouldn't find any errors, if features from higher releases are used. 12 | * Development objects should begin with `zexport` or with `zimport`. 13 | 14 | ## Testing ## 15 | The classes `zimport_bundle_from_cluster` and `zimport_bundle_from_tdc` 16 | contains automated tests. The automated tests overwrite the MIME-object `ZBUNDLE_UNIT_TEST` and the ECATT test data container `ZBUNDLE_UNIT_TEST`. Please make sure, 17 | these objects are not used otherwise. 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Bunyanuch Saengnet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ABAP Database preparator # 2 | Database preparation for unit testing made simple. Store snapshots 3 | (bundles) of your database records for later use in unit tests. 4 | 5 | ## No more breaking unit tests ## 6 | The snapshots should avoid breaking unit tests after system copies and 7 | other database manipulations. This is achieved by providing a wrapper 8 | for the OpenSQL replacement service in class `cl_osql_replace`, that 9 | makes huge setups unnecessary. 10 | 11 | ### Good bye huge setups ### 12 | Replace this huge setup method 13 | ```ABAP 14 | METHOD setup. 15 | DATA: airlines TYPE STANDARD TABLE OF zcarr_fake, 16 | replaced_tables TYPE cl_osql_replace=>tt_replacement. 17 | 18 | DELETE FROM airlines. 19 | airlines = VALUE #( 20 | ( carrid = 'TG' carrname = 'Thai Airways' ) 21 | ). 22 | INSERT zcarr_fake FROM airlines. 23 | 24 | replaced_tables = VALUE #( 25 | ( source = 'SCARR' target = 'ZCARR_FAKE' ) 26 | ). 27 | cl_osql_replace=>activate_replacement( EXPORTING 28 | replacement_table = replaced_tables ). 29 | 30 | ENDMETHOD. 31 | ``` 32 | by just two method calls: 33 | ```ABAP 34 | METHOD setup. 35 | 36 | DATA(db_preparator) = NEW zimport_bundle_from_tdc( tdc = 'ZAIRLINES' 37 | tdc_version = 1 variant = 'ECATTDEFAULT' ). 38 | db_preparator->replace_content_completly( ). 39 | db_preparator->activate_osql_replacement( ). 40 | 41 | ENDMETHOD. 42 | ``` 43 | 44 | ## How it works ## 45 | Bundles are stored either in an ECATT test data container 46 | or in a cluster (binary MIME-object in transaction smw0). 47 | 48 | ### Export step ### 49 | In the first step we can choose the database records, 50 | which should be exported into the bundle. 51 | The OpenSQL replacement service needs a so called fake table with the same 52 | structure as the original table. From this fake table the database records are 53 | read or they are written back in this fake table. In the export step we link 54 | original and fake table as shown in the picture below. 55 | ![program zexport_gui](img/export_scarr.png) 56 | *Figure 1 Export step for table scarr in program `zexport_gui`* 57 | In figure 1 the original table is named `scarr`, the fake table `zcarr_fake`. 58 | 59 | Fake tables can be left empty, if the OpenSQL replacement service isn't 60 | installed. 61 | 62 | #### FOR ALL ENTRIES IN #### 63 | The SQL where restriction can be prefixed a `FOR ALL ENTRIES IN`, which acts 64 | like the corresponding ABAP-statement. As internal table any original table from the bundle can be given. Internal table name should be `'X' && table_name`. E.g. 65 | Database table | Fake database table | SQL where restriction 66 | -------------- | ------------------- | --------------------- 67 | SCARR | ZCARR_FAKE | carrid in ('TG', 'AA') 68 | SPFLI | ZSPFLI_FAKE | FOR ALL ENTRIES IN xzcarr_fake WHERE carrid = xzcarr_fake-carrid 69 | 70 | #### JOINS #### 71 | Joins can be expressed with subqueries. Let's consider the following join: 72 | ``` 73 | SELECT * FROM sflight AS f INNER JOIN spfli AS p 74 | ON p~carrid = f~carrid AND p~connid = f~connid 75 | WHERE p~airpto = 'BKK' AND f~fldate = '20210420'. 76 | ``` 77 | The database records can be picked up in programm ```zexport_gui``` with subqueries: 78 | Database table | Fake database table | SQL where restriction 79 | -------------- | ------------------- | --------------------- 80 | SFLIGHT | ZCARR_SFLIGHT | fldate = '20210420' AND EXISTS ( SELECT * FROM spfli WHERE carrid = sflight~carrid AND connid = sflight~connid AND airpto = 'BKK' ) 81 | SPFLI | ZCARR_SPFLI | FOR ALL ENTRIES IN xsflight WHERE carrid = xsflight-carrid AND connid = xsflight-connid 82 | 83 | ### Import step ### 84 | In the ABAP unit-testclass the database records exported in previous step 85 | can be imported in the fake tables or in the original tables, 86 | if the corresponding fake table was left empty. 87 | The API for the import step is located in class `zimport_bundle_from_cluster` 88 | for clusters or in class `zimport_bundle_from_tdc` for 89 | ECATT test data container. 90 | 91 | For testing Rfc-Client- or Rfc-Serverprograms or programs, 92 | which interact through the [JSON Adapter for ABAP Function Modules](https://github.com/cesar-sap/abap_fm_json/) 93 | a API is located in function-group `zimport_bundle`. 94 | 95 | A example can be found in the listing below. 96 | ```ABAP 97 | CLASS test_airlines DEFINITION FOR TESTING DURATION SHORT 98 | RISK LEVEL HARMLESS. 99 | 100 | PRIVATE SECTION. 101 | 102 | " activate replacement service 103 | METHODS setup. 104 | 105 | METHODS thai_should_be_found FOR TESTING. 106 | 107 | ENDCLASS. 108 | 109 | CLASS test_airlines IMPLEMENTATION. 110 | 111 | METHOD setup. 112 | 113 | DATA(db_preparator) = NEW zimport_bundle_from_tdc( tdc = 'ZAIRLINES' 114 | tdc_version = 1 variant = 'ECATTDEFAULT' ). 115 | db_preparator->replace_content_completly( ). 116 | db_preparator->activate_osql_replacement( ). 117 | 118 | ENDMETHOD. 119 | 120 | METHOD thai_should_be_found. 121 | DATA: exp_airlines TYPE STANDARD TABLE OF scarr. 122 | 123 | exp_airlines = VALUE #( ( carrid = 'TG' carrname = 'Thai airways' 124 | currcode = 'THB' url = 'https://thaiairways.com' ) ). 125 | 126 | SELECT * FROM scarr INTO TABLE @DATA(act_airlines). 127 | 128 | cl_abap_unit_assert=>assert_equals( exp = exp_airlines 129 | act = act_airlines ). 130 | 131 | ENDMETHOD. 132 | 133 | ENDCLASS. 134 | ``` 135 | 136 | ### Authorization ### 137 | The APIs in class `zimport_bundle_from_cluster` or 138 | in class `zimport_bundle_from_tdc` can only be used in 139 | development systems, where 140 | dangerous ABAP unit-testclasses are enabled. 141 | 142 | ### Whitelist-check ### 143 | Content of fake tables listed in the whitelist can be completely 144 | overriden. The whitelist is maintained in parameter 145 | `ZIMPORT_REPLACE_WHITELIST` (transaction `stvarv`, table `tvarvc`). 146 | 147 | ## Terms ## 148 | 149 | * Bundle: a collection of database records, which are stored outside 150 | of the database tables. 151 | * Cluster: a MIME-object in transaction `smw0`, which contains the bundle 152 | * TDC: abbreviation for ECATT test data container 153 | 154 | ## Cloning this repository ## 155 | Cloning can be done with [abapGit](https://github.com/larshp/abapgit). 156 | The code is backwards compatible until release 7.40. The replacement services 157 | need higher releases (SAP NetWeaver 7.51 or 7.52). 158 | 159 | ## Further links ## 160 | [Blog entry on SAP community network](https://blogs.sap.com/?p=1049057) 161 | [Repository mirror](https://github.com/ABAP-prep/abap_db_preparator) 162 | -------------------------------------------------------------------------------- /abaplint.json: -------------------------------------------------------------------------------- 1 | { 2 | "global": { 3 | "files": "/src/**/*.*", 4 | "skipGeneratedGatewayClasses": true, 5 | "skipGeneratedPersistentClasses": true, 6 | "skipGeneratedFunctionGroups": true 7 | }, 8 | "dependencies": [ 9 | { 10 | "url": "https://github.com/abaplint/deps", 11 | "folder": "/deps", 12 | "files": "/src/**/*.*" 13 | } 14 | ], 15 | "syntax": { 16 | "version": "v745", 17 | "errorNamespace": "^(Z|Y|LT?CL_|TY_|LIF_)", 18 | "globalConstants": [], 19 | "globalMacros": [] 20 | }, 21 | "rules": { 22 | "downport": false, 23 | "line_break_multiple_parameters": false, 24 | "unknown_types": true, 25 | "forbidden_void_type": { 26 | "check": [] 27 | }, 28 | "forbidden_identifier": true, 29 | "try_without_catch": false, 30 | "unused_variables": false, 31 | "prefix_is_current_class": { 32 | "omitMeInstanceCalls": false 33 | }, 34 | "allowed_object_naming": true, 35 | "check_comments": false, 36 | "fully_type_constants": true, 37 | "keep_single_parameter_on_one_line": false, 38 | "prefer_returning_to_exporting": false, 39 | "selection_screen_naming": true, 40 | "sicf_consistency": true, 41 | "sql_escape_host_variables": false, 42 | "xml_consistency": true, 43 | "check_no_handler_pragma": true, 44 | "newline_between_methods": false, 45 | "chain_mainly_declarations": false, 46 | "check_abstract": true, 47 | "check_text_elements": true, 48 | "type_begin_single_include": true, 49 | "types_naming": false, 50 | "7bit_ascii": true, 51 | "abapdoc": false, 52 | "check_ddic": true, 53 | "check_include": true, 54 | "form_no_dash": true, 55 | "allowed_object_types": false, 56 | "ambiguous_statement": false, 57 | "avoid_use": { 58 | "define": false, 59 | "endselect": false, 60 | "execSQL": true, 61 | "kernelCall": true, 62 | "communication": true, 63 | "systemCall": true, 64 | "defaultKey": false, 65 | "break": false, 66 | "statics": false 67 | }, 68 | "begin_end_names": true, 69 | "check_transformation_exists": true, 70 | "check_syntax": true, 71 | "class_attribute_names": { 72 | }, 73 | "cloud_types": true, 74 | "colon_missing_space": true, 75 | "commented_code": true, 76 | "constructor_visibility_public": true, 77 | "contains_tab": true, 78 | "definitions_top": true, 79 | "description_empty": true, 80 | "double_space": false, 81 | "empty_line_in_statement": { 82 | "allowChained": true 83 | }, 84 | "empty_statement": true, 85 | "empty_structure": { 86 | "loop": true, 87 | "if": false, 88 | "while": true, 89 | "case": true, 90 | "select": true, 91 | "do": true, 92 | "at": true 93 | }, 94 | "exit_or_check": true, 95 | "exporting": true, 96 | "form_tables_obsolete": false, 97 | "functional_writing": { 98 | "ignoreExceptions": true 99 | }, 100 | "global_class": true, 101 | "identical_form_names": true, 102 | "if_in_if": true, 103 | "implement_methods": true, 104 | "in_statement_indentation": false, 105 | "indentation": { 106 | "ignoreExceptions": true, 107 | "alignTryCatch": false, 108 | "globalClassSkipFirst": false, 109 | "ignoreGlobalClassDefinition": false, 110 | "ignoreGlobalInterface": false 111 | }, 112 | "inline_data_old_versions": true, 113 | "keyword_case": { 114 | "style": "upper", 115 | "ignoreExceptions": true, 116 | "ignoreLowerClassImplmentationStatement": true, 117 | "ignoreGlobalClassDefinition": false, 118 | "ignoreGlobalInterface": false, 119 | "ignoreKeywords": [], 120 | "ignoreFunctionModuleName": false 121 | }, 122 | "line_length": { 123 | "length": 120 124 | }, 125 | "line_only_punc": { 126 | "ignoreExceptions": true 127 | }, 128 | "local_class_naming": { 129 | }, 130 | "local_testclass_location": true, 131 | "local_variable_names": { 132 | }, 133 | "main_file_contents": true, 134 | "max_one_statement": true, 135 | "message_exists": false, 136 | "method_length": { 137 | "statements": 100, 138 | "ignoreTestClasses": false, 139 | "errorWhenEmpty": false 140 | }, 141 | "method_parameter_names": false, 142 | "mix_returning": true, 143 | "msag_consistency": true, 144 | "nesting": { 145 | "depth": 5 146 | }, 147 | "no_public_attributes": false, 148 | "object_naming": { 149 | "clas": "^Z", 150 | "intf": "^Z", 151 | "prog": "^Z", 152 | "fugr": "^Z", 153 | "tabl": "^Z", 154 | "ttyp": "^Z", 155 | "dtel": "^Z", 156 | "doma": "^Z", 157 | "msag": "^Z", 158 | "tran": "^Z", 159 | "enqu": "^EZ", 160 | "auth": "^Z", 161 | "pinf": "^Z", 162 | "idoc": "^Z", 163 | "ssfo": "^Z", 164 | "ssst": "^Z", 165 | "xslt": "^Z" 166 | }, 167 | "obsolete_statement": { 168 | "refresh": true, 169 | "compute": true, 170 | "add": true, 171 | "subtract": true, 172 | "multiply": true, 173 | "move": true, 174 | "divide": true, 175 | "requested": true, 176 | "setExtended": true, 177 | "occurs": true 178 | }, 179 | "parser_error": {}, 180 | "preferred_compare_operator": { 181 | "badOperators": [ 182 | "EQ", 183 | "><", 184 | "NE", 185 | "GE", 186 | "GT", 187 | "LT", 188 | "LE" 189 | ] 190 | }, 191 | "release_idoc": true, 192 | "remove_descriptions": { 193 | }, 194 | "rfc_error_handling": false, 195 | "sequential_blank": { 196 | "lines": 4 197 | }, 198 | "short_case": { 199 | "length": 1, 200 | "allow": [ 201 | "iv_action", 202 | "sy" 203 | ] 204 | }, 205 | "space_before_colon": true, 206 | "space_before_dot": { 207 | "ignoreGlobalDefinition": true, 208 | "ignoreExceptions": true 209 | }, 210 | "start_at_tab": true, 211 | "superclass_final": true, 212 | "tabl_enhancement_category": true, 213 | "type_form_parameters": true, 214 | "unreachable_code": true, 215 | "use_new": true, 216 | "when_others_last": true, 217 | "whitespace_end": true 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /img/export_scarr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bunysae/abap_db_preparator/5d4681bd4a572b69d489aa9b5d049310a450680f/img/export_scarr.png -------------------------------------------------------------------------------- /src/package.devc.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | DB preparator 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/zcx_export_cluster_table.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zcx_export_cluster_table DEFINITION 2 | PUBLIC 3 | INHERITING FROM zcx_export_error 4 | FINAL 5 | CREATE PUBLIC . 6 | 7 | PUBLIC SECTION. 8 | 9 | CONSTANTS: 10 | BEGIN OF zcx_export_cluster_table, 11 | msgid TYPE symsgid VALUE 'ZEXPORT', 12 | msgno TYPE symsgno VALUE '015', 13 | attr1 TYPE scx_attrname VALUE '', 14 | attr2 TYPE scx_attrname VALUE '', 15 | attr3 TYPE scx_attrname VALUE '', 16 | attr4 TYPE scx_attrname VALUE '', 17 | END OF zcx_export_cluster_table . 18 | DATA: 19 | table_name TYPE tabname. 20 | 21 | METHODS constructor 22 | IMPORTING 23 | !textid LIKE if_t100_message=>t100key OPTIONAL 24 | !previous LIKE previous OPTIONAL 25 | !msgv1 TYPE symsgv OPTIONAL 26 | !msgv2 TYPE symsgv OPTIONAL 27 | !msgv3 TYPE symsgv OPTIONAL 28 | !msgv4 TYPE symsgv OPTIONAL 29 | !table_name TYPE tabname OPTIONAL. 30 | protected section. 31 | private section. 32 | ENDCLASS. 33 | 34 | 35 | 36 | CLASS ZCX_EXPORT_CLUSTER_TABLE IMPLEMENTATION. 37 | 38 | 39 | method CONSTRUCTOR. 40 | CALL METHOD SUPER->CONSTRUCTOR 41 | EXPORTING 42 | PREVIOUS = PREVIOUS 43 | MSGV1 = MSGV1 44 | MSGV2 = MSGV2 45 | MSGV3 = MSGV3 46 | MSGV4 = MSGV4 47 | . 48 | me->TABLE_NAME = TABLE_NAME . 49 | clear me->textid. 50 | if textid is initial. 51 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_CLUSTER_TABLE . 52 | else. 53 | IF_T100_MESSAGE~T100KEY = TEXTID. 54 | endif. 55 | endmethod. 56 | ENDCLASS. 57 | -------------------------------------------------------------------------------- /src/zcx_export_cluster_table.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_CLUSTER_TABLE 7 | E 8 | Exporting cluster tables 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | CONSTRUCTOR 18 | E 19 | CONSTRUCTOR 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/zcx_export_empty.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zcx_export_empty DEFINITION 2 | PUBLIC 3 | INHERITING FROM zcx_export_error 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | CONSTANTS: BEGIN OF zcx_export_empty, 9 | msgid TYPE symsgid VALUE 'ZEXPORT', 10 | msgno TYPE symsgno VALUE '013', 11 | attr1 TYPE scx_attrname VALUE 'TABLE_NAME', 12 | attr2 TYPE scx_attrname VALUE '', 13 | attr3 TYPE scx_attrname VALUE '', 14 | attr4 TYPE scx_attrname VALUE '', 15 | END OF zcx_export_empty. 16 | DATA table_name TYPE tabname. 17 | 18 | METHODS constructor 19 | IMPORTING 20 | !textid LIKE if_t100_message=>t100key OPTIONAL 21 | !previous LIKE previous OPTIONAL 22 | !msgv1 TYPE symsgv OPTIONAL 23 | !msgv2 TYPE symsgv OPTIONAL 24 | !msgv3 TYPE symsgv OPTIONAL 25 | !msgv4 TYPE symsgv OPTIONAL 26 | table_name TYPE tabname. 27 | protected section. 28 | private section. 29 | ENDCLASS. 30 | 31 | 32 | 33 | CLASS ZCX_EXPORT_EMPTY IMPLEMENTATION. 34 | 35 | 36 | method CONSTRUCTOR. 37 | CALL METHOD SUPER->CONSTRUCTOR 38 | EXPORTING 39 | PREVIOUS = PREVIOUS 40 | MSGV1 = MSGV1 41 | MSGV2 = MSGV2 42 | MSGV3 = MSGV3 43 | MSGV4 = MSGV4 44 | . 45 | me->TABLE_NAME = TABLE_NAME . 46 | clear me->textid. 47 | if textid is initial. 48 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_EMPTY . 49 | else. 50 | IF_T100_MESSAGE~T100KEY = TEXTID. 51 | endif. 52 | endmethod. 53 | ENDCLASS. 54 | -------------------------------------------------------------------------------- /src/zcx_export_empty.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_EMPTY 7 | E 8 | Given table is empty (FOR ALL ENTRIES IN) 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_export_error.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_EXPORT_ERROR definition 2 | public 3 | inheriting from CX_STATIC_CHECK 4 | create public . 5 | 6 | public section. 7 | 8 | interfaces IF_T100_MESSAGE . 9 | 10 | data MSGV1 type SYMSGV . 11 | data MSGV2 type SYMSGV . 12 | data MSGV3 type SYMSGV . 13 | data MSGV4 type SYMSGV . 14 | 15 | methods CONSTRUCTOR 16 | importing 17 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 18 | !PREVIOUS like PREVIOUS optional 19 | !MSGV1 type SYMSGV optional 20 | !MSGV2 type SYMSGV optional 21 | !MSGV3 type SYMSGV optional 22 | !MSGV4 type SYMSGV optional . 23 | class-methods WRAP_ECATT_FAILURE 24 | importing 25 | !ECATT_FAILURE type ref to CX_ECATT_TDC_ACCESS 26 | raising 27 | ZCX_EXPORT_ERROR . 28 | class-methods WRAP_T100_MESSAGE 29 | RAISING 30 | zcx_export_error. 31 | 32 | methods IF_MESSAGE~GET_LONGTEXT 33 | redefinition . 34 | methods IF_MESSAGE~GET_TEXT 35 | redefinition . 36 | protected section. 37 | private section. 38 | ENDCLASS. 39 | 40 | 41 | 42 | CLASS ZCX_EXPORT_ERROR IMPLEMENTATION. 43 | 44 | 45 | method CONSTRUCTOR. 46 | CALL METHOD SUPER->CONSTRUCTOR 47 | EXPORTING 48 | PREVIOUS = PREVIOUS 49 | . 50 | me->MSGV1 = MSGV1 . 51 | me->MSGV2 = MSGV2 . 52 | me->MSGV3 = MSGV3 . 53 | me->MSGV4 = MSGV4 . 54 | clear me->textid. 55 | if textid is initial. 56 | IF_T100_MESSAGE~T100KEY = IF_T100_MESSAGE=>DEFAULT_TEXTID. 57 | else. 58 | IF_T100_MESSAGE~T100KEY = TEXTID. 59 | endif. 60 | endmethod. 61 | 62 | 63 | method IF_MESSAGE~GET_LONGTEXT. 64 | 65 | IF previous IS BOUND. 66 | result = previous->if_message~get_longtext( preserve_newlines ). 67 | ELSE. 68 | result = super->if_message~get_longtext( preserve_newlines ). 69 | ENDIF. 70 | 71 | endmethod. 72 | 73 | 74 | method IF_MESSAGE~GET_TEXT. 75 | 76 | IF previous IS BOUND. 77 | result = previous->if_message~get_text( ). 78 | ELSE. 79 | result = super->if_message~get_text( ). 80 | ENDIF. 81 | 82 | endmethod. 83 | 84 | 85 | method WRAP_ECATT_FAILURE. 86 | 87 | RAISE EXCEPTION TYPE zcx_export_error 88 | EXPORTING 89 | previous = ecatt_failure. 90 | 91 | endmethod. 92 | 93 | 94 | method WRAP_T100_MESSAGE. 95 | DATA: textid TYPE scx_t100key. 96 | 97 | textid = VALUE #( msgid = sy-msgid msgno = sy-msgno 98 | attr1 = 'MSGV1' attr2 = 'MSGV2' attr3 = 'MSGV3' 99 | attr4 = 'MSGV4' ). 100 | 101 | RAISE EXCEPTION TYPE zcx_export_error 102 | EXPORTING 103 | textid = textid 104 | msgv1 = sy-msgv1 105 | msgv2 = sy-msgv2 106 | msgv3 = sy-msgv3 107 | msgv4 = sy-msgv4. 108 | 109 | endmethod. 110 | ENDCLASS. 111 | -------------------------------------------------------------------------------- /src/zcx_export_error.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_ERROR 7 | E 8 | Export error 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_export_invalid_name.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zcx_export_invalid_name DEFINITION 2 | PUBLIC 3 | INHERITING FROM zcx_export_error 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | CONSTANTS: 9 | BEGIN OF zcx_export_invalid_name, 10 | msgid TYPE symsgid VALUE 'ZEXPORT', 11 | msgno TYPE symsgno VALUE '014', 12 | attr1 TYPE scx_attrname VALUE 'NAME', 13 | attr2 TYPE scx_attrname VALUE '', 14 | attr3 TYPE scx_attrname VALUE '', 15 | attr4 TYPE scx_attrname VALUE '', 16 | END OF zcx_export_invalid_name . 17 | DATA name TYPE tabname. 18 | 19 | METHODS constructor 20 | IMPORTING 21 | !textid LIKE if_t100_message=>t100key OPTIONAL 22 | !previous LIKE previous OPTIONAL 23 | !msgv1 TYPE symsgv OPTIONAL 24 | !msgv2 TYPE symsgv OPTIONAL 25 | !msgv3 TYPE symsgv OPTIONAL 26 | !msgv4 TYPE symsgv OPTIONAL 27 | !name TYPE tabname. 28 | protected section. 29 | private section. 30 | ENDCLASS. 31 | 32 | 33 | 34 | CLASS ZCX_EXPORT_INVALID_NAME IMPLEMENTATION. 35 | 36 | 37 | method CONSTRUCTOR. 38 | CALL METHOD SUPER->CONSTRUCTOR 39 | EXPORTING 40 | PREVIOUS = PREVIOUS 41 | MSGV1 = MSGV1 42 | MSGV2 = MSGV2 43 | MSGV3 = MSGV3 44 | MSGV4 = MSGV4 45 | . 46 | me->NAME = NAME . 47 | clear me->textid. 48 | if textid is initial. 49 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_INVALID_NAME . 50 | else. 51 | IF_T100_MESSAGE~T100KEY = TEXTID. 52 | endif. 53 | endmethod. 54 | ENDCLASS. 55 | -------------------------------------------------------------------------------- /src/zcx_export_invalid_name.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_INVALID_NAME 7 | E 8 | Invalid name 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_export_object_exists.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_EXPORT_OBJECT_EXISTS definition 2 | public 3 | inheriting from ZCX_EXPORT_ERROR 4 | final 5 | create public . 6 | 7 | public section. 8 | 9 | constants: 10 | BEGIN OF zcx_export_object_exists, 11 | msgid TYPE symsgid VALUE 'ZEXPORT', 12 | msgno TYPE symsgno VALUE '000', 13 | attr1 TYPE scx_attrname VALUE 'TESTCASE_ID', 14 | attr2 TYPE scx_attrname VALUE '', 15 | attr3 TYPE scx_attrname VALUE '', 16 | attr4 TYPE scx_attrname VALUE '', 17 | END OF zcx_export_object_exists . 18 | constants: 19 | BEGIN OF tdc_exists, 20 | msgid TYPE symsgid VALUE 'ZEXPORT', 21 | msgno TYPE symsgno VALUE '007', 22 | attr1 TYPE scx_attrname VALUE 'TDC_NAME', 23 | attr2 TYPE scx_attrname VALUE '', 24 | attr3 TYPE scx_attrname VALUE '', 25 | attr4 TYPE scx_attrname VALUE '', 26 | END OF tdc_exists . 27 | data TESTCASE_ID type W3OBJID . 28 | data TDC_NAME type ETOBJ_NAME . 29 | 30 | methods CONSTRUCTOR 31 | importing 32 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 33 | !PREVIOUS like PREVIOUS optional 34 | !MSGV1 type SYMSGV optional 35 | !MSGV2 type SYMSGV optional 36 | !MSGV3 type SYMSGV optional 37 | !MSGV4 type SYMSGV optional 38 | !TESTCASE_ID type W3OBJID optional 39 | !TDC_NAME type ETOBJ_NAME optional . 40 | protected section. 41 | private section. 42 | ENDCLASS. 43 | 44 | 45 | 46 | CLASS ZCX_EXPORT_OBJECT_EXISTS IMPLEMENTATION. 47 | 48 | 49 | method CONSTRUCTOR. 50 | CALL METHOD SUPER->CONSTRUCTOR 51 | EXPORTING 52 | PREVIOUS = PREVIOUS 53 | MSGV1 = MSGV1 54 | MSGV2 = MSGV2 55 | MSGV3 = MSGV3 56 | MSGV4 = MSGV4 57 | . 58 | me->TESTCASE_ID = TESTCASE_ID . 59 | me->TDC_NAME = TDC_NAME . 60 | clear me->textid. 61 | if textid is initial. 62 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_OBJECT_EXISTS . 63 | else. 64 | IF_T100_MESSAGE~T100KEY = TEXTID. 65 | endif. 66 | endmethod. 67 | ENDCLASS. 68 | -------------------------------------------------------------------------------- /src/zcx_export_object_exists.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_OBJECT_EXISTS 7 | E 8 | Object already exists 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_export_table_duplicate.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_EXPORT_TABLE_DUPLICATE definition 2 | public 3 | inheriting from ZCX_EXPORT_ERROR 4 | final 5 | create public . 6 | 7 | public section. 8 | 9 | constants: 10 | BEGIN OF zcx_export_table_duplicate, 11 | msgid TYPE symsgid VALUE 'ZEXPORT', 12 | msgno TYPE symsgno VALUE '003', 13 | attr1 TYPE scx_attrname VALUE 'TABLE', 14 | attr2 TYPE scx_attrname VALUE '', 15 | attr3 TYPE scx_attrname VALUE '', 16 | attr4 TYPE scx_attrname VALUE '', 17 | END OF zcx_export_table_duplicate . 18 | data TABLE type TABNAME . 19 | 20 | methods CONSTRUCTOR 21 | importing 22 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 23 | !PREVIOUS like PREVIOUS optional 24 | !MSGV1 type SYMSGV optional 25 | !MSGV2 type SYMSGV optional 26 | !MSGV3 type SYMSGV optional 27 | !MSGV4 type SYMSGV optional 28 | !TABLE type TABNAME . 29 | protected section. 30 | private section. 31 | ENDCLASS. 32 | 33 | 34 | 35 | CLASS ZCX_EXPORT_TABLE_DUPLICATE IMPLEMENTATION. 36 | 37 | 38 | method CONSTRUCTOR. 39 | CALL METHOD SUPER->CONSTRUCTOR 40 | EXPORTING 41 | PREVIOUS = PREVIOUS 42 | MSGV1 = MSGV1 43 | MSGV2 = MSGV2 44 | MSGV3 = MSGV3 45 | MSGV4 = MSGV4 46 | . 47 | me->TABLE = TABLE . 48 | clear me->textid. 49 | if textid is initial. 50 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_TABLE_DUPLICATE . 51 | else. 52 | IF_T100_MESSAGE~T100KEY = TEXTID. 53 | endif. 54 | endmethod. 55 | ENDCLASS. 56 | -------------------------------------------------------------------------------- /src/zcx_export_table_duplicate.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_TABLE_DUPLICATE 7 | E 8 | Table used more than one time 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_export_to_file.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_EXPORT_TO_FILE definition 2 | public 3 | inheriting from CX_STATIC_CHECK 4 | final 5 | create private . 6 | 7 | public section. 8 | 9 | CONSTANTS: BEGIN OF zcx_export_to_file, 10 | msgid TYPE symsgid VALUE 'ZEXPORT', 11 | msgno TYPE symsgno VALUE '006', 12 | attr1 TYPE scx_attrname VALUE 'FILENAME', 13 | attr2 TYPE scx_attrname VALUE 'REASON', 14 | attr3 TYPE scx_attrname VALUE '', 15 | attr4 TYPE scx_attrname VALUE '', 16 | END OF zcx_export_to_file. 17 | 18 | INTERFACES if_t100_message. 19 | DATA: filename TYPE string, 20 | reason TYPE string. 21 | 22 | methods CONSTRUCTOR 23 | importing 24 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 25 | !PREVIOUS like PREVIOUS optional 26 | filename TYPE string 27 | reason TYPE string. 28 | class-methods DOWNLOAD_FAILED 29 | importing 30 | !FILENAME type STRING 31 | VALUE(SUBRC) type SYST-SUBRC 32 | RAISING 33 | zcx_export_to_file. 34 | protected section. 35 | private section. 36 | 37 | TYPES: BEGIN OF _return_code_map, 38 | subrc TYPE i, 39 | reason TYPE string, 40 | END OF _return_code_map. 41 | CLASS-DATA: return_code_map TYPE STANDARD TABLE OF _return_code_map. 42 | 43 | CLASS-METHODS initialize. 44 | ENDCLASS. 45 | 46 | 47 | 48 | CLASS ZCX_EXPORT_TO_FILE IMPLEMENTATION. 49 | 50 | 51 | method CONSTRUCTOR. 52 | CALL METHOD SUPER->CONSTRUCTOR 53 | EXPORTING 54 | PREVIOUS = PREVIOUS 55 | . 56 | me->FILENAME = FILENAME . 57 | me->REASON = REASON . 58 | clear me->textid. 59 | if textid is initial. 60 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_TO_FILE . 61 | else. 62 | IF_T100_MESSAGE~T100KEY = TEXTID. 63 | endif. 64 | endmethod. 65 | 66 | 67 | method DOWNLOAD_FAILED. 68 | DATA: reason TYPE string. 69 | 70 | initialize( ). 71 | 72 | READ TABLE return_code_map REFERENCE INTO DATA(ret) 73 | WITH KEY subrc = subrc. 74 | IF sy-subrc = 0. 75 | reason = ret->*-reason. 76 | ELSE. 77 | reason = subrc. 78 | ENDIF. 79 | 80 | RAISE EXCEPTION TYPE zcx_export_to_file 81 | EXPORTING 82 | filename = filename 83 | reason = reason. 84 | 85 | endmethod. 86 | 87 | 88 | method INITIALIZE. 89 | 90 | return_code_map = VALUE #( 91 | ( subrc = 2 reason = text-002 ) 92 | ( subrc = 4 reason = text-004 ) 93 | ( subrc = 6 reason = text-006 ) 94 | ( subrc = 8 reason = text-008 ) 95 | ( subrc = 10 reason = text-010 ) 96 | ). 97 | 98 | endmethod. 99 | ENDCLASS. 100 | -------------------------------------------------------------------------------- /src/zcx_export_to_file.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_TO_FILE 7 | E 8 | Export to file failed 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | I 18 | 002 19 | Error writing file 20 | 28 21 | 22 | 23 | I 24 | 004 25 | GUI refuses filetransfer 26 | 48 27 | 28 | 29 | I 30 | 006 31 | no authority 32 | 22 33 | 34 | 35 | I 36 | 008 37 | access denied 38 | 23 39 | 40 | 41 | I 42 | 010 43 | unexpected error 44 | 26 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/zcx_export_tr_order.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_EXPORT_TR_ORDER definition 2 | public 3 | inheriting from ZCX_EXPORT_ERROR 4 | final 5 | create public . 6 | 7 | public section. 8 | 9 | CONSTANTS: BEGIN OF zcx_export_tr_order, 10 | msgid TYPE symsgid VALUE 'ZEXPORT', 11 | msgno TYPE symsgno VALUE '009', 12 | attr1 TYPE scx_attrname VALUE 'TR_ORDER', 13 | attr2 TYPE scx_attrname VALUE '', 14 | attr3 TYPE scx_attrname VALUE '', 15 | attr4 TYPE scx_attrname VALUE '', 16 | END OF zcx_export_tr_order. 17 | DATA tr_order TYPE e070-trkorr. 18 | 19 | methods CONSTRUCTOR 20 | importing 21 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 22 | !PREVIOUS like PREVIOUS optional 23 | !MSGV1 type SYMSGV optional 24 | !MSGV2 type SYMSGV optional 25 | !MSGV3 type SYMSGV optional 26 | !MSGV4 type SYMSGV optional 27 | tr_order TYPE e070-trkorr. 28 | protected section. 29 | private section. 30 | ENDCLASS. 31 | 32 | 33 | 34 | CLASS ZCX_EXPORT_TR_ORDER IMPLEMENTATION. 35 | 36 | 37 | method CONSTRUCTOR. 38 | CALL METHOD SUPER->CONSTRUCTOR 39 | EXPORTING 40 | PREVIOUS = PREVIOUS 41 | MSGV1 = MSGV1 42 | MSGV2 = MSGV2 43 | MSGV3 = MSGV3 44 | MSGV4 = MSGV4 45 | . 46 | me->TR_ORDER = TR_ORDER . 47 | clear me->textid. 48 | if textid is initial. 49 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_TR_ORDER . 50 | else. 51 | IF_T100_MESSAGE~T100KEY = TEXTID. 52 | endif. 53 | endmethod. 54 | ENDCLASS. 55 | -------------------------------------------------------------------------------- /src/zcx_export_tr_order.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_TR_ORDER 7 | E 8 | Transport order is invalid 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_export_where_clause_invali.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_EXPORT_WHERE_CLAUSE_INVALI definition 2 | public 3 | inheriting from ZCX_EXPORT_ERROR 4 | final 5 | create public . 6 | 7 | public section. 8 | 9 | constants: 10 | BEGIN OF ZCX_EXPORT_WHERE_CLAUSE_INVALI, 11 | msgid TYPE symsgid VALUE 'ZEXPORT', 12 | msgno TYPE symsgno VALUE '008', 13 | attr1 TYPE scx_attrname VALUE 'TABLE', 14 | attr2 TYPE scx_attrname VALUE 'WHERE_CLAUSE', 15 | attr3 TYPE scx_attrname VALUE 'FAILURE_DESCRIPTION', 16 | attr4 TYPE scx_attrname VALUE '', 17 | END OF ZCX_EXPORT_WHERE_CLAUSE_INVALI . 18 | data TABLE type TABNAME . 19 | data WHERE_CLAUSE type STRING . 20 | data failure_description type STRING. 21 | 22 | methods CONSTRUCTOR 23 | importing 24 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 25 | !PREVIOUS like PREVIOUS optional 26 | !MSGV1 type SYMSGV optional 27 | !MSGV2 type SYMSGV optional 28 | !MSGV3 type SYMSGV optional 29 | !MSGV4 type SYMSGV optional 30 | !TABLE type TABNAME 31 | !WHERE_CLAUSE type STRING 32 | failure_description type STRING. 33 | protected section. 34 | private section. 35 | ENDCLASS. 36 | 37 | 38 | 39 | CLASS ZCX_EXPORT_WHERE_CLAUSE_INVALI IMPLEMENTATION. 40 | 41 | 42 | method CONSTRUCTOR. 43 | CALL METHOD SUPER->CONSTRUCTOR 44 | EXPORTING 45 | PREVIOUS = PREVIOUS 46 | MSGV1 = MSGV1 47 | MSGV2 = MSGV2 48 | MSGV3 = MSGV3 49 | MSGV4 = MSGV4 50 | . 51 | me->TABLE = TABLE . 52 | me->WHERE_CLAUSE = WHERE_CLAUSE . 53 | me->FAILURE_DESCRIPTION = FAILURE_DESCRIPTION . 54 | clear me->textid. 55 | if textid is initial. 56 | IF_T100_MESSAGE~T100KEY = ZCX_EXPORT_WHERE_CLAUSE_INVALI . 57 | else. 58 | IF_T100_MESSAGE~T100KEY = TEXTID. 59 | endif. 60 | endmethod. 61 | ENDCLASS. 62 | -------------------------------------------------------------------------------- /src/zcx_export_where_clause_invali.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_EXPORT_WHERE_CLAUSE_INVALI 7 | E 8 | Where-Clause is invalid 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_import_error.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zcx_import_error DEFINITION 2 | PUBLIC 3 | INHERITING FROM cx_static_check 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | METHODS constructor 9 | IMPORTING 10 | !textid LIKE textid OPTIONAL 11 | !previous LIKE previous OPTIONAL . 12 | CLASS-METHODS wrap_ecatt_failure 13 | IMPORTING 14 | ecatt_failure TYPE REF TO cx_ecatt_tdc_access 15 | RAISING 16 | zcx_import_error. 17 | 18 | METHODS if_message~get_text REDEFINITION. 19 | 20 | METHODS if_message~get_longtext REDEFINITION. 21 | protected section. 22 | private section. 23 | ENDCLASS. 24 | 25 | 26 | 27 | CLASS ZCX_IMPORT_ERROR IMPLEMENTATION. 28 | 29 | 30 | method CONSTRUCTOR. 31 | CALL METHOD SUPER->CONSTRUCTOR 32 | EXPORTING 33 | TEXTID = TEXTID 34 | PREVIOUS = PREVIOUS 35 | . 36 | endmethod. 37 | 38 | 39 | METHOD if_message~get_longtext. 40 | 41 | IF previous IS BOUND. 42 | result = previous->if_message~get_longtext( preserve_newlines ). 43 | ELSE. 44 | result = super->if_message~get_longtext( preserve_newlines ). 45 | ENDIF. 46 | 47 | ENDMETHOD. 48 | 49 | 50 | method IF_MESSAGE~GET_TEXT. 51 | 52 | IF previous IS BOUND. 53 | result = previous->if_message~get_text( ). 54 | ELSE. 55 | result = super->if_message~get_text( ). 56 | ENDIF. 57 | 58 | endmethod. 59 | 60 | 61 | method WRAP_ECATT_FAILURE. 62 | 63 | RAISE EXCEPTION TYPE zcx_import_error 64 | EXPORTING 65 | previous = ecatt_failure. 66 | 67 | endmethod. 68 | ENDCLASS. 69 | -------------------------------------------------------------------------------- /src/zcx_import_error.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_IMPORT_ERROR 7 | E 8 | Import-Errors 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_import_merge_conflict.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zcx_import_merge_conflict DEFINITION 2 | PUBLIC 3 | INHERITING FROM zcx_import_error 4 | FINAL 5 | CREATE PUBLIC . 6 | 7 | PUBLIC SECTION. 8 | 9 | INTERFACES if_t100_message . 10 | 11 | CONSTANTS: BEGIN OF zcx_import_merge_conflict, 12 | msgid TYPE symsgid VALUE 'ZEXPORT', 13 | msgno TYPE symsgno VALUE '003', 14 | attr1 TYPE scx_attrname VALUE 'TABLE', 15 | attr2 TYPE scx_attrname VALUE '', 16 | attr3 TYPE scx_attrname VALUE '', 17 | attr4 TYPE scx_attrname VALUE '', 18 | END OF zcx_import_merge_conflict. 19 | DATA: table TYPE tabname. 20 | 21 | METHODS constructor 22 | IMPORTING 23 | !textid LIKE if_t100_message=>t100key OPTIONAL 24 | !previous LIKE previous OPTIONAL 25 | table TYPE tabname. 26 | protected section. 27 | private section. 28 | ENDCLASS. 29 | 30 | 31 | 32 | CLASS ZCX_IMPORT_MERGE_CONFLICT IMPLEMENTATION. 33 | 34 | 35 | method CONSTRUCTOR. 36 | CALL METHOD SUPER->CONSTRUCTOR 37 | EXPORTING 38 | PREVIOUS = PREVIOUS 39 | . 40 | me->TABLE = TABLE . 41 | clear me->textid. 42 | if textid is initial. 43 | IF_T100_MESSAGE~T100KEY = ZCX_IMPORT_MERGE_CONFLICT . 44 | else. 45 | IF_T100_MESSAGE~T100KEY = TEXTID. 46 | endif. 47 | endmethod. 48 | ENDCLASS. 49 | -------------------------------------------------------------------------------- /src/zcx_import_merge_conflict.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_IMPORT_MERGE_CONFLICT 7 | E 8 | Merge conflict 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_import_not_allowed.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_IMPORT_NOT_ALLOWED definition 2 | public 3 | inheriting from ZCX_IMPORT_ERROR 4 | final 5 | create public . 6 | 7 | public section. 8 | 9 | interfaces IF_T100_MESSAGE . 10 | 11 | constants: 12 | begin of ZCX_IMPORT_NOT_ALLOWED, 13 | msgid type symsgid value 'ZEXPORT', 14 | msgno type symsgno value '001', 15 | attr1 type scx_attrname value '', 16 | attr2 type scx_attrname value '', 17 | attr3 type scx_attrname value '', 18 | attr4 type scx_attrname value '', 19 | end of ZCX_IMPORT_NOT_ALLOWED . 20 | 21 | methods CONSTRUCTOR 22 | importing 23 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 24 | !PREVIOUS like PREVIOUS optional . 25 | protected section. 26 | private section. 27 | ENDCLASS. 28 | 29 | 30 | 31 | CLASS ZCX_IMPORT_NOT_ALLOWED IMPLEMENTATION. 32 | 33 | 34 | method CONSTRUCTOR. 35 | CALL METHOD SUPER->CONSTRUCTOR 36 | EXPORTING 37 | PREVIOUS = PREVIOUS 38 | . 39 | clear me->textid. 40 | if textid is initial. 41 | IF_T100_MESSAGE~T100KEY = ZCX_IMPORT_NOT_ALLOWED . 42 | else. 43 | IF_T100_MESSAGE~T100KEY = TEXTID. 44 | endif. 45 | endmethod. 46 | ENDCLASS. 47 | -------------------------------------------------------------------------------- /src/zcx_import_not_allowed.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_IMPORT_NOT_ALLOWED 7 | E 8 | Import not allowed outside unit-test 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zcx_import_object_not_exists.clas.abap: -------------------------------------------------------------------------------- 1 | class ZCX_IMPORT_OBJECT_NOT_EXISTS definition 2 | public 3 | inheriting from ZCX_IMPORT_ERROR 4 | final 5 | create public . 6 | 7 | public section. 8 | 9 | interfaces IF_T100_MESSAGE . 10 | 11 | constants: 12 | begin of ZCX_IMPORT_OBJECT_NOT_EXISTS, 13 | msgid type symsgid value 'ZEXPORT', 14 | msgno type symsgno value '012', 15 | attr1 type scx_attrname value 'TESTCASE_ID', 16 | attr2 type scx_attrname value '', 17 | attr3 type scx_attrname value '', 18 | attr4 type scx_attrname value '', 19 | end of ZCX_IMPORT_OBJECT_NOT_EXISTS . 20 | data TESTCASE_ID type W3OBJID . 21 | 22 | methods CONSTRUCTOR 23 | importing 24 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 25 | !PREVIOUS like PREVIOUS optional 26 | !TESTCASE_ID type W3OBJID . 27 | protected section. 28 | private section. 29 | ENDCLASS. 30 | 31 | 32 | 33 | CLASS ZCX_IMPORT_OBJECT_NOT_EXISTS IMPLEMENTATION. 34 | 35 | 36 | method CONSTRUCTOR. 37 | CALL METHOD SUPER->CONSTRUCTOR 38 | EXPORTING 39 | PREVIOUS = PREVIOUS 40 | . 41 | me->TESTCASE_ID = TESTCASE_ID . 42 | clear me->textid. 43 | if textid is initial. 44 | IF_T100_MESSAGE~T100KEY = ZCX_IMPORT_OBJECT_NOT_EXISTS . 45 | else. 46 | IF_T100_MESSAGE~T100KEY = TEXTID. 47 | endif. 48 | endmethod. 49 | ENDCLASS. 50 | -------------------------------------------------------------------------------- /src/zcx_import_object_not_exists.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZCX_IMPORT_OBJECT_NOT_EXISTS 7 | E 8 | Imported MIM-Object doesn't exist 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zexport.msag.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT 7 | E 8 | Export in Cluster 9 | 10 | 11 | 12 | E 13 | ZEXPORT 14 | 000 15 | Testcase &1 already exists. Overwritting is not active. 16 | 17 | 18 | E 19 | ZEXPORT 20 | 001 21 | Import is just allowed when dangerous testclasses can be executed. 22 | 23 | 24 | E 25 | ZEXPORT 26 | 002 27 | Please add some tables to the bundle 28 | 29 | 30 | E 31 | ZEXPORT 32 | 003 33 | Table &1 is used more than one time 34 | 35 | 36 | E 37 | ZEXPORT 38 | 004 39 | &1 doesn't exists 40 | 41 | 42 | E 43 | ZEXPORT 44 | 005 45 | &1 isn't a database table 46 | 47 | 48 | E 49 | ZEXPORT 50 | 006 51 | Download of file &1 failed (reason: &2) 52 | 53 | 54 | E 55 | ZEXPORT 56 | 007 57 | Testdatacontainer &1 already exists. Overwritting is not active. 58 | 59 | 60 | E 61 | ZEXPORT 62 | 008 63 | The where-clause for table &1 is invalid. 64 | 65 | 66 | E 67 | ZEXPORT 68 | 009 69 | The transport request &1 must exists and must be open. 70 | 71 | 72 | E 73 | ZEXPORT 74 | 010 75 | The content-handler &1 is invalid. 76 | 77 | 78 | E 79 | ZEXPORT 80 | 011 81 | The name can't be changed, if the table isn't reexported (table &1) 82 | 83 | 84 | E 85 | ZEXPORT 86 | 012 87 | Can't find bundle with id &1 88 | 89 | 90 | E 91 | ZEXPORT 92 | 013 93 | FOR ALL ENTRIES IN is only possible when table &1 is not empty. 94 | 95 | 96 | E 97 | ZEXPORT 98 | 014 99 | &1 is a invalid name. 100 | 101 | 102 | E 103 | ZEXPORT 104 | 015 105 | Cluster-Tables can only be added, when a table type is defined. 106 | 107 | 108 | 109 | 110 | 111 | NA 112 | ZEXPORT001 113 | E 114 | E 115 | 0001 116 | X 117 | 00004 118 | 119 | 120 | DOKU 121 | ZEXPORT001 122 | NA 123 | E 124 | S_DOCU_SHOW 125 | S_DOCUS1 126 | 00001 127 | 072 128 | 129 | 130 | 131 | U1 132 | &CAUSE& 133 | 134 | 135 | AS 136 | Testclasses (ABAP Unit) have different risk levels. The import is not 137 | 138 | 139 | allowed, when just the execution of harmless testclasses is permitted. 140 | 141 | 142 | U1 143 | &WHAT_TO_DO& 144 | 145 | 146 | AS 147 | Set the risk level limit to dangerous or critical in report 148 | 149 | 150 | SAUNIT_CLIENT_SETUP. 151 | 152 | 153 | AS 154 | 155 | 156 | 157 | 158 | 159 | NA 160 | ZEXPORT008 161 | E 162 | E 163 | 0001 164 | X 165 | 00002 166 | 167 | 168 | DOKU 169 | ZEXPORT008 170 | NA 171 | E 172 | S_DOCU_SHOW 173 | S_DOCUS1 174 | 00001 175 | 072 176 | 177 | 178 | 179 | U1 180 | &CAUSE& 181 | 182 | 183 | AS 184 | &V3& 185 | 186 | 187 | U1 188 | &WHAT_TO_DO& 189 | 190 | 191 | AS 192 | Please correct the where-clause. 193 | 194 | 195 | 196 | 197 | 198 | NA 199 | ZEXPORT010 200 | E 201 | E 202 | 0001 203 | X 204 | 00006 205 | 206 | 207 | DOKU 208 | ZEXPORT010 209 | NA 210 | E 211 | S_DOCU_SHOW 212 | S_DOCUS1 213 | 00001 214 | 072 215 | 216 | 217 | 218 | U1 219 | &CAUSE& 220 | 221 | 222 | AS 223 | The content-handler must be a public method of the class "ZIMPORT_BUNDLE 224 | 225 | 226 | = 227 | ". 228 | 229 | 230 | U1 231 | &WHAT_TO_DO& 232 | 233 | 234 | AS 235 | Valid content-handlers are: 236 | 237 | 238 | B1 239 | REPLACE_CONTENT_ALL_TABLES 240 | 241 | 242 | B1 243 | REPLACE_CONTENT_COMPLETLY 244 | 245 | 246 | B1 247 | ADD_CONTENT_ALL_TABLES 248 | 249 | 250 | 251 | 252 | 253 | NA 254 | ZEXPORT015 255 | E 256 | E 257 | 0001 258 | X 259 | 00004 260 | 261 | 262 | DOKU 263 | ZEXPORT015 264 | NA 265 | E 266 | S_DOCU_SHOW 267 | S_DOCUS1 268 | 00001 269 | 072 270 | 271 | 272 | 273 | U1 274 | &CAUSE& 275 | 276 | 277 | AS 278 | Cluster-Tables need a table type defined in ABAP-dictionary in order 279 | 280 | 281 | = 282 | to be added to the test data container. 283 | 284 | 285 | U1 286 | &WHAT_TO_DO& 287 | 288 | 289 | AS 290 | Please create a table type for dictionary structure &V1& of kind 291 | 292 | 293 | = 294 | standard table. 295 | 296 | 297 | 298 | 299 | 300 | C 301 | 302 | 303 | 304 | C 305 | ZEXPORT 306 | Export in Cluster 307 | 308 | 309 | 310 | 311 | C 312 | 000 313 | Testcase &1 already exists. Overwritting is not active. 314 | 315 | 316 | C 317 | 001 318 | Import is just allowed when dangerous testclasses can be executed. 319 | 320 | 321 | C 322 | 002 323 | Please add some tables to the bundle 324 | 325 | 326 | C 327 | 003 328 | Table &1 is used more than one time 329 | 330 | 331 | C 332 | 004 333 | &1 doesn't exists 334 | 335 | 336 | C 337 | 005 338 | &1 isn't a database table 339 | 340 | 341 | C 342 | 006 343 | Download of file &1 failed (reason: &2) 344 | 345 | 346 | C 347 | 007 348 | Testdatacontainer &1 already exists. Overwritting is not active. 349 | 350 | 351 | C 352 | 008 353 | The where-clause for table &1 is invalid. 354 | 355 | 356 | C 357 | 009 358 | The transport request &1 must exists and must be open. 359 | 360 | 361 | C 362 | 010 363 | The content-handler &1 is invalid. 364 | 365 | 366 | C 367 | 011 368 | The name can't be changed, if the table isn't reexported (table &1) 369 | 370 | 371 | C 372 | 012 373 | Can't find bundle with id &1 374 | 375 | 376 | C 377 | 013 378 | FOR ALL ENTRIES IN is only possible when table &1 is not empty. 379 | 380 | 381 | C 382 | 014 383 | &1 is a invalid name. 384 | 385 | 386 | 387 | 388 | 389 | -------------------------------------------------------------------------------- /src/zexport_batch_input.prog.abap: -------------------------------------------------------------------------------- 1 | CLASS batch_input DEFINITION. 2 | 3 | PUBLIC SECTION. 4 | 5 | METHODS dynpro_field 6 | IMPORTING 7 | name TYPE clike 8 | fvalue TYPE any. 9 | 10 | METHODS dynpro_head 11 | IMPORTING 12 | report TYPE syst-repid 13 | dynpro TYPE syst-dynnr. 14 | 15 | METHODS call_transaction 16 | IMPORTING code TYPE tcode 17 | VALUE(options) TYPE ctu_params OPTIONAL. 18 | 19 | METHODS command 20 | IMPORTING command TYPE syst-ucomm. 21 | 22 | METHODS subscreen 23 | IMPORTING subscreen TYPE bdc_fval. 24 | 25 | PROTECTED SECTION. 26 | DATA: input_map TYPE STANDARD TABLE OF bdcdata. 27 | 28 | ENDCLASS. 29 | 30 | CLASS batch_input IMPLEMENTATION. 31 | 32 | METHOD dynpro_field. 33 | DATA: conv_exit TYPE tfdir-funcname. 34 | 35 | APPEND INITIAL LINE TO input_map ASSIGNING FIELD-SYMBOL(). 36 | -fnam = name. 37 | 38 | DESCRIBE FIELD fvalue EDIT MASK conv_exit. 39 | 40 | IF conv_exit <> space. 41 | WRITE fvalue TO -fval USING EDIT MASK conv_exit. 42 | ELSE. 43 | ##WRITE_MOVE 44 | WRITE fvalue TO -fval. 45 | ENDIF. 46 | 47 | ENDMETHOD. 48 | 49 | METHOD dynpro_head. 50 | 51 | APPEND INITIAL LINE TO input_map ASSIGNING FIELD-SYMBOL(). 52 | 53 | -program = report. 54 | -dynpro = dynpro. 55 | -dynbegin = abap_true. 56 | 57 | ENDMETHOD. 58 | 59 | METHOD command. 60 | 61 | APPEND INITIAL LINE TO input_map ASSIGNING FIELD-SYMBOL(). 62 | -fnam = 'BDC_OKCODE'. 63 | -fval = command. 64 | 65 | ENDMETHOD. 66 | 67 | METHOD subscreen. 68 | 69 | APPEND INITIAL LINE TO input_map ASSIGNING FIELD-SYMBOL(). 70 | -fnam = 'BDC_SUBSCR'. 71 | -fval = subscreen. 72 | 73 | ENDMETHOD. 74 | 75 | METHOD call_transaction. 76 | 77 | CALL TRANSACTION code WITH AUTHORITY-CHECK USING input_map 78 | OPTIONS FROM options. 79 | 80 | ENDMETHOD. 81 | 82 | ENDCLASS. 83 | -------------------------------------------------------------------------------- /src/zexport_batch_input.prog.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_BATCH_INPUT 7 | I 8 | S 9 | E 10 | X 11 | 12 | 13 | 14 | R 15 | API for batch-input 16 | 27 17 | 18 | 19 | 20 | 21 | D 22 | 23 | 24 | R 25 | Include ZMAKROS_BATCH_INPUT 26 | 27 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/zexport_bundle.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zexport_bundle DEFINITION 2 | PUBLIC 3 | CREATE PUBLIC 4 | ABSTRACT. 5 | 6 | PUBLIC SECTION. 7 | PROTECTED SECTION. 8 | DATA table_list TYPE STANDARD TABLE OF zexport_table_list . 9 | 10 | METHODS select 11 | IMPORTING 12 | table_conjunction TYPE zexport_table_list 13 | EXPORTING 14 | content TYPE STANDARD TABLE 15 | RAISING 16 | zcx_export_error. 17 | 18 | METHODS get_exported_content ABSTRACT 19 | IMPORTING 20 | table_conjunction TYPE zexport_table_list 21 | CHANGING 22 | table_for_all_entries TYPE REF TO data 23 | RAISING 24 | zcx_export_error. 25 | 26 | PRIVATE SECTION. 27 | ENDCLASS. 28 | 29 | 30 | 31 | CLASS ZEXPORT_BUNDLE IMPLEMENTATION. 32 | 33 | 34 | METHOD select. 35 | DATA: table_for_all_entries TYPE REF TO data. 36 | 37 | zexport_utils=>get_table_for_all_entries( EXPORTING 38 | table_conjunction = table_conjunction 39 | RECEIVING table_name = DATA(table_name) 40 | EXCEPTIONS not_for_all_entries_cond = 4 ). 41 | IF sy-subrc = 0. 42 | 43 | READ TABLE table_list REFERENCE INTO DATA(foe_conjunction) 44 | WITH KEY fake_table = table_name+1. 45 | IF sy-subrc <> 0. 46 | RAISE EXCEPTION TYPE zcx_export_invalid_name 47 | EXPORTING 48 | name = table_name. 49 | ENDIF. 50 | 51 | CREATE DATA table_for_all_entries TYPE STANDARD TABLE OF (table_name+1). 52 | get_exported_content( EXPORTING table_conjunction = foe_conjunction->* 53 | CHANGING table_for_all_entries = table_for_all_entries ). 54 | ASSIGN table_for_all_entries->* TO FIELD-SYMBOL(). 55 | zexport_utils=>select( EXPORTING table_for_all_entries = 56 | table_conjunction = table_conjunction table_name = table_name 57 | IMPORTING result = content ). 58 | 59 | ELSE. 60 | 61 | TRY. 62 | SELECT * FROM (table_conjunction-source_table) 63 | INTO CORRESPONDING FIELDS OF TABLE @content 64 | WHERE (table_conjunction-where_restriction). 65 | CATCH cx_sy_dynamic_osql_error INTO DATA(osql_syntax_error). 66 | RAISE EXCEPTION TYPE zcx_export_where_clause_invali 67 | EXPORTING 68 | table = table_conjunction-source_table 69 | where_clause = table_conjunction-where_restriction 70 | failure_description = osql_syntax_error->msgtext. 71 | ENDTRY. 72 | 73 | ENDIF. 74 | 75 | ENDMETHOD. 76 | ENDCLASS. 77 | -------------------------------------------------------------------------------- /src/zexport_bundle.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_BUNDLE 7 | E 8 | Export Bundle baseclass 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/zexport_bundle_in_cluster.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zexport_bundle_in_cluster DEFINITION 2 | PUBLIC 3 | FINAL 4 | CREATE PUBLIC 5 | INHERITING FROM zexport_bundle. 6 | 7 | PUBLIC SECTION. 8 | 9 | METHODS constructor 10 | IMPORTING 11 | !testcase_id TYPE w3objid 12 | !force_overwrite TYPE abap_bool DEFAULT abap_false 13 | !dev_package TYPE devclass 14 | !title TYPE w3_text 15 | RAISING 16 | zcx_export_object_exists . 17 | "! Add the content of the table to the bundle (uses the builder-pattern). 18 | "! @parameter _table | 19 | "!
    20 | "!
  • Component "source_table": 21 | "! Database table (transparent table), where the content lies. 22 | "!
  • 23 | "!
  • Component "fake_table": 24 | "! The fake table, which is used in the unit-test. 25 | "! The import-class zimport_bundle_from_cluster 26 | "! overwrites the content of the fake-table. 27 | "! This parameter can be used, if working with class cl_osq_replace 28 | "! to replace table contents. 29 | "! If this parameter is omitted, parameter table is used. 30 | "!
  • 31 | "!
  • Component "where_restriction": 32 | "! An valid sql-where-clause for an restriction of the exported rows. 33 | "!
  • 34 | "!
35 | "! @raising zcx_export_error | If a table name is 36 | "! used more than one time, 37 | "! or the "where_restriction" is invalid. 38 | METHODS add_table_to_bundle 39 | IMPORTING 40 | VALUE(_table) TYPE zexport_table_list 41 | RETURNING 42 | VALUE(instance) TYPE REF TO zexport_bundle_in_cluster 43 | RAISING 44 | zcx_export_error . 45 | METHODS export . 46 | "! Attach the MIME-Object to an workbench order for transportation pruposes 47 | METHODS attach_to_wb_order 48 | RAISING 49 | zcx_export_error . 50 | METHODS add_prior_content 51 | IMPORTING 52 | VALUE(_table) TYPE zexport_table_list 53 | content TYPE REF TO data 54 | RETURNING VALUE(instance) TYPE REF TO zexport_bundle_in_cluster 55 | RAISING 56 | zcx_export_error. 57 | PROTECTED SECTION. 58 | METHODS get_exported_content REDEFINITION. 59 | PRIVATE SECTION. 60 | 61 | DATA cluster_objects TYPE abap_trans_srcbind_tab . 62 | DATA mime_key TYPE wwwdatatab . 63 | 64 | METHODS serialize 65 | RETURNING 66 | VALUE(result) TYPE REF TO cl_sxml_string_writer . 67 | METHODS create_mime_object 68 | IMPORTING 69 | !content TYPE REF TO cl_sxml_string_writer . 70 | METHODS set_filesize 71 | IMPORTING 72 | !size TYPE i . 73 | ENDCLASS. 74 | 75 | 76 | 77 | CLASS ZEXPORT_BUNDLE_IN_CLUSTER IMPLEMENTATION. 78 | 79 | 80 | METHOD add_prior_content. 81 | 82 | IF _table-fake_table IS INITIAL. 83 | _table-fake_table = _table-source_table. 84 | ENDIF. 85 | IF line_exists( cluster_objects[ name = _table-fake_table ] ). 86 | RAISE EXCEPTION TYPE zcx_export_table_duplicate 87 | EXPORTING 88 | table = _table-fake_table. 89 | ENDIF. 90 | 91 | INSERT _table INTO TABLE table_list. 92 | 93 | APPEND INITIAL LINE TO cluster_objects 94 | ASSIGNING FIELD-SYMBOL(). 95 | -name = _table-fake_table. 96 | -value = content. 97 | 98 | instance = me. 99 | 100 | ENDMETHOD. 101 | 102 | 103 | METHOD add_table_to_bundle. 104 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 105 | 106 | IF _table-fake_table IS INITIAL. 107 | _table-fake_table = _table-source_table. 108 | ENDIF. 109 | IF line_exists( cluster_objects[ name = _table-fake_table ] ). 110 | RAISE EXCEPTION TYPE zcx_export_table_duplicate 111 | EXPORTING 112 | table = _table-fake_table. 113 | ENDIF. 114 | 115 | INSERT _table INTO TABLE table_list. 116 | 117 | APPEND INITIAL LINE TO cluster_objects 118 | ASSIGNING FIELD-SYMBOL(). 119 | -name = _table-fake_table. 120 | 121 | CREATE DATA -value TYPE STANDARD TABLE OF 122 | (_table-source_table). 123 | ASSIGN -value->* TO . 124 | 125 | select( EXPORTING table_conjunction = _table 126 | IMPORTING content = ). 127 | 128 | instance = me. 129 | 130 | ENDMETHOD. 131 | 132 | 133 | METHOD attach_to_wb_order. 134 | DATA: header TYPE STANDARD TABLE OF ko200, 135 | items TYPE STANDARD TABLE OF e071k. 136 | 137 | header = VALUE #( 138 | ( pgmid = 'R3TR' object = 'W3' && mime_key-relid obj_name = mime_key-objid 139 | masterlang = sy-langu devclass = mime_key-devclass ) ). 140 | 141 | CALL FUNCTION 'TR_OBJECTS_CHECK' 142 | TABLES 143 | wt_ko200 = header 144 | wt_e071k = items 145 | EXCEPTIONS 146 | cancel_edit_other_error = 2 147 | show_only_other_error = 4. 148 | IF sy-subrc <> 0. 149 | zcx_export_error=>wrap_t100_message( ). 150 | ENDIF. 151 | 152 | CALL FUNCTION 'TR_OBJECTS_INSERT' 153 | TABLES 154 | wt_ko200 = header 155 | wt_e071k = items 156 | EXCEPTIONS 157 | cancel_edit_other_error = 2 158 | show_only_other_error = 4. 159 | IF sy-subrc <> 0. 160 | zcx_export_error=>wrap_t100_message( ). 161 | ENDIF. 162 | 163 | ENDMETHOD. 164 | 165 | 166 | METHOD constructor. 167 | 168 | super->constructor( ). 169 | mime_key-relid = 'MI'. 170 | mime_key-objid = testcase_id. 171 | mime_key-devclass = dev_package. 172 | mime_key-text = title. 173 | 174 | IF force_overwrite = abap_false. 175 | SELECT COUNT(*) FROM wwwdata WHERE relid = @mime_key-relid 176 | AND objid = @mime_key-objid. 177 | IF sy-subrc = 0. 178 | RAISE EXCEPTION TYPE zcx_export_object_exists 179 | EXPORTING 180 | testcase_id = testcase_id. 181 | ENDIF. 182 | ENDIF. 183 | 184 | ENDMETHOD. 185 | 186 | 187 | METHOD create_mime_object. 188 | DATA: mime_content TYPE STANDARD TABLE OF w3mime, 189 | binary_content TYPE xstring, 190 | length TYPE i. 191 | 192 | DATA(binary_table_content) = content->get_output( ). 193 | 194 | " exporting the table list is necessary for deserialization 195 | EXPORT content = binary_table_content table_list = table_list 196 | TO DATA BUFFER binary_content. 197 | 198 | CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 199 | EXPORTING 200 | buffer = binary_content 201 | IMPORTING 202 | output_length = length 203 | TABLES 204 | binary_tab = mime_content. 205 | 206 | CALL FUNCTION 'WWWDATA_EXPORT' 207 | EXPORTING 208 | key = mime_key 209 | TABLES 210 | mime = mime_content. 211 | 212 | set_filesize( length ). 213 | 214 | ENDMETHOD. 215 | 216 | 217 | METHOD export. 218 | 219 | create_mime_object( serialize( ) ). 220 | 221 | ENDMETHOD. 222 | 223 | 224 | METHOD get_exported_content. 225 | 226 | READ TABLE cluster_objects ASSIGNING FIELD-SYMBOL() 227 | WITH KEY name = table_conjunction-fake_table. 228 | IF sy-subrc <> 0. 229 | RAISE EXCEPTION TYPE zcx_export_invalid_name 230 | EXPORTING 231 | name = table_conjunction-fake_table. 232 | ENDIF. 233 | table_for_all_entries = -value. 234 | 235 | ENDMETHOD. 236 | 237 | 238 | METHOD serialize. 239 | 240 | result = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ). 241 | 242 | CALL TRANSFORMATION id 243 | SOURCE (cluster_objects) 244 | RESULT XML result. 245 | 246 | ENDMETHOD. 247 | 248 | 249 | METHOD set_filesize. 250 | DATA: filesize_param TYPE wwwparams. 251 | 252 | filesize_param-relid = mime_key-relid. 253 | filesize_param-objid = mime_key-objid. 254 | filesize_param-name = 'filesize'. 255 | filesize_param-value = size. 256 | MODIFY wwwparams FROM filesize_param. 257 | 258 | ENDMETHOD. 259 | ENDCLASS. 260 | -------------------------------------------------------------------------------- /src/zexport_bundle_in_cluster.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_BUNDLE_IN_CLUSTER 7 | E 8 | Export Tablebundel into cluster 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/zexport_bundle_in_tdc.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zexport_bundle_in_tdc DEFINITION 2 | PUBLIC 3 | FINAL 4 | CREATE PUBLIC 5 | INHERITING FROM zexport_bundle. 6 | 7 | PUBLIC SECTION. 8 | 9 | METHODS constructor 10 | IMPORTING 11 | !tdc TYPE REF TO cl_apl_ecatt_tdc_api 12 | !variant TYPE etvar_id 13 | RAISING 14 | cx_ecatt_tdc_access . 15 | "! Add the content of the table to the bundle (uses the builder-pattern). 16 | "! @parameter _table | 17 | "!
    18 | "!
  • Component "source_table": 19 | "! Database table (transparent table), where the content lies. 20 | "!
  • 21 | "!
  • Component "fake_table": 22 | "! The fake table, which is used in the unit-test. 23 | "! The import-class zimport_bundle_from_cluster 24 | "! overwrites the content of the fake-table. 25 | "! This parameter can be used, if working with class cl_osq_replace 26 | "! to replace table contents. 27 | "! If this parameter is omitted, parameter table is used. 28 | "!
  • 29 | "!
  • Component "where_restriction": 30 | "! An valid sql-where-clause for an restriction of the exported rows. 31 | "!
  • 32 | "!
33 | "! @raising zcx_export_error | If a table name is 34 | "! used more than one time or, 35 | "! if the "where_restriction" is invalid. 36 | METHODS add_table_to_bundle 37 | IMPORTING 38 | VALUE(_table) TYPE zexport_table_list 39 | RETURNING 40 | VALUE(instance) TYPE REF TO zexport_bundle_in_tdc 41 | RAISING 42 | zcx_export_error . 43 | METHODS export 44 | IMPORTING 45 | !transport_request TYPE e070-trkorr 46 | RAISING 47 | zcx_export_error . 48 | METHODS add_prior_content 49 | IMPORTING 50 | table_conjunction TYPE zexport_table_list 51 | RAISING 52 | zcx_export_error . 53 | PROTECTED SECTION. 54 | METHODS get_exported_content REDEFINITION. 55 | PRIVATE SECTION. 56 | 57 | DATA tdc TYPE REF TO cl_apl_ecatt_tdc_api . 58 | DATA variant TYPE etvar_id . 59 | 60 | METHODS create_parameter 61 | IMPORTING 62 | !table TYPE tabname 63 | RETURNING 64 | VALUE(name) TYPE etp_name 65 | RAISING 66 | zcx_export_error 67 | cx_ecatt_tdc_access . 68 | METHODS set_parameter_value 69 | IMPORTING 70 | !content TYPE STANDARD TABLE 71 | !name TYPE etp_name 72 | RAISING 73 | cx_ecatt_tdc_access . 74 | "! Invalid characters for ecatt parameters are replaced by '_'. 75 | METHODS get_parameter_name 76 | IMPORTING 77 | !table_name TYPE tabname 78 | RETURNING 79 | VALUE(result) TYPE etp_name . 80 | METHODS get_parameter_definition 81 | IMPORTING 82 | !table_name TYPE tabname 83 | RETURNING 84 | VALUE(result) TYPE string 85 | RAISING 86 | zcx_export_error. 87 | METHODS search_for_table_types 88 | IMPORTING 89 | !table_name TYPE tabname 90 | RETURNING 91 | VALUE(result) TYPE ttypename 92 | RAISING 93 | zcx_export_error. 94 | METHODS is_cluster_table 95 | IMPORTING 96 | !table_name TYPE tabname 97 | RETURNING 98 | VALUE(result) TYPE sap_bool . 99 | ENDCLASS. 100 | 101 | 102 | 103 | CLASS ZEXPORT_BUNDLE_IN_TDC IMPLEMENTATION. 104 | 105 | 106 | METHOD add_prior_content. 107 | 108 | IF line_exists( table_list[ fake_table = table_conjunction-fake_table ] ). 109 | RAISE EXCEPTION TYPE zcx_export_table_duplicate 110 | EXPORTING 111 | table = table_conjunction-fake_table. 112 | ENDIF. 113 | 114 | INSERT table_conjunction INTO TABLE table_list. 115 | 116 | ENDMETHOD. 117 | 118 | 119 | METHOD add_table_to_bundle. 120 | DATA: content TYPE REF TO data, 121 | param_name TYPE etp_name. 122 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 123 | 124 | " Parameters in test data containers can only refer to the 125 | " CDS-Database-view. So write CDS-Database-view-name to fake table name. 126 | IF zexport_utils=>is_cds_view_entity( _table-source_table ) = abap_true. 127 | _table-fake_table = zexport_utils=>get_cds_view_name( _table-source_table ). 128 | ELSEIF _table-fake_table IS INITIAL. 129 | _table-fake_table = _table-source_table. 130 | ENDIF. 131 | IF line_exists( table_list[ fake_table = _table-fake_table ] ). 132 | RAISE EXCEPTION TYPE zcx_export_table_duplicate 133 | EXPORTING 134 | table = _table-fake_table. 135 | ENDIF. 136 | 137 | TRY. 138 | _table-tdc_parameter_name = create_parameter( _table-fake_table ). 139 | 140 | CREATE DATA content TYPE STANDARD TABLE OF (_table-fake_table). 141 | ASSIGN content->* TO . 142 | 143 | select( EXPORTING table_conjunction = _table 144 | IMPORTING content = ). 145 | _table-is_initial = xsdbool( IS INITIAL ). 146 | 147 | set_parameter_value( content = name = _table-tdc_parameter_name ). 148 | 149 | INSERT _table INTO TABLE table_list. 150 | 151 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 152 | zcx_export_error=>wrap_ecatt_failure( ecatt_failure ). 153 | ENDTRY. 154 | 155 | ENDMETHOD. 156 | 157 | 158 | METHOD constructor. 159 | 160 | super->constructor( ). 161 | me->tdc = tdc. 162 | me->variant = variant. 163 | 164 | " create variant, if not exists 165 | TRY. 166 | tdc->create_variant( i_variant_name = variant ). 167 | CATCH cx_ecatt_tdc_access INTO DATA(failure). 168 | IF failure->textid <> cx_ecatt_tdc_access=>variant_exists. 169 | RAISE EXCEPTION failure. 170 | ENDIF. 171 | ENDTRY. 172 | 173 | ENDMETHOD. 174 | 175 | 176 | METHOD create_parameter. 177 | DATA: type_definition TYPE string. 178 | 179 | type_definition = get_parameter_definition( table ). 180 | name = get_parameter_name( table ). 181 | 182 | TRY. 183 | tdc->create_parameter( i_param_name = name 184 | i_param_def = type_definition ). 185 | CATCH cx_ecatt_tdc_access INTO DATA(failure). 186 | IF failure->textid = cx_ecatt_tdc_access=>parameter_exists. 187 | IF tdc->get_param_definition( name ) <> type_definition. 188 | tdc->change_parameter( i_param_name = name 189 | i_param_def = type_definition ). 190 | ENDIF. 191 | ELSE. 192 | RAISE EXCEPTION failure. 193 | ENDIF. 194 | ENDTRY. 195 | 196 | ENDMETHOD. 197 | 198 | 199 | METHOD export. 200 | 201 | TRY. 202 | DATA(param_for_list) = create_parameter( table = 'ZEXPORT_TABLE_LIST' ). 203 | set_parameter_value( content = table_list name = param_for_list ). 204 | 205 | tdc->commit_changes( i_commit_mode = abap_false 206 | i_tr_order = transport_request i_release_lock = abap_true ). 207 | 208 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 209 | zcx_export_error=>wrap_ecatt_failure( ecatt_failure ). 210 | ENDTRY. 211 | 212 | ENDMETHOD. 213 | 214 | 215 | METHOD get_exported_content. 216 | 217 | ASSIGN table_for_all_entries->* TO FIELD-SYMBOL(). 218 | select( EXPORTING table_conjunction = table_conjunction 219 | IMPORTING content = ). 220 | 221 | ENDMETHOD. 222 | 223 | 224 | METHOD get_parameter_definition. 225 | 226 | " search for table types first as type "standard table of" for cluster tables 227 | " is changed to character like type in TDC, which causes a dump 228 | result = search_for_table_types( table_name ). 229 | IF result IS NOT INITIAL. 230 | RETURN. 231 | ENDIF. 232 | 233 | CONCATENATE 'STANDARD TABLE OF' table_name INTO result 234 | SEPARATED BY space. 235 | 236 | ENDMETHOD. 237 | 238 | 239 | METHOD get_parameter_name. 240 | 241 | result = table_name. 242 | REPLACE ALL OCCURRENCES OF REGEX '[^A-Za-z0-9_\s]' 243 | IN result WITH '_'. 244 | 245 | ENDMETHOD. 246 | 247 | 248 | METHOD is_cluster_table. 249 | 250 | SELECT COUNT(*) FROM dd02l 251 | WHERE tabname = @table_name AND as4local = 'A' AND tabclass = 'CLUSTER'. 252 | result = xsdbool( sy-subrc = 0 ). 253 | 254 | ENDMETHOD. 255 | 256 | 257 | METHOD search_for_table_types. 258 | DATA: 259 | objects_to_search TYPE STANDARD TABLE OF rsfind, 260 | scope_object_classes TYPE STANDARD TABLE OF seu_obj, 261 | found_table_types TYPE STANDARD TABLE OF rsfindlst, 262 | table_type_range TYPE RANGE OF ttypename. 263 | 264 | objects_to_search = VALUE #( ( object = table_name ) ). 265 | scope_object_classes = VALUE #( ( 'DA' ) ). 266 | CALL FUNCTION 'RS_EU_CROSSREF' 267 | EXPORTING 268 | i_find_obj_cls = 'DS' 269 | i_answer = 'N' 270 | no_dialog = abap_true 271 | expand_source_in_online_mode = abap_true 272 | rekursiv = abap_true 273 | TABLES 274 | i_findstrings = objects_to_search 275 | i_scope_object_cls = scope_object_classes 276 | o_founds = found_table_types 277 | EXCEPTIONS 278 | OTHERS = 4. 279 | IF ( sy-subrc <> 0 OR found_table_types IS INITIAL ) 280 | AND is_cluster_table( table_name ) = abap_true. 281 | RAISE EXCEPTION TYPE zcx_export_cluster_table 282 | EXPORTING 283 | table_name = table_name. 284 | ELSEIF found_table_types IS INITIAL. 285 | RETURN. 286 | ENDIF. 287 | 288 | table_type_range = VALUE #( 289 | FOR IN found_table_types 290 | ( sign = 'I' option = 'EQ' low = -object ) ). 291 | SELECT typename FROM dd40l 292 | WHERE typename IN @table_type_range AND as4local = 'A' AND accessmode = 'T' 293 | INTO @result. 294 | ENDSELECT. 295 | IF sy-subrc <> 0 AND is_cluster_table( table_name ) = abap_true. 296 | RAISE EXCEPTION TYPE zcx_export_cluster_table 297 | EXPORTING 298 | table_name = table_name. 299 | ENDIF. 300 | 301 | ENDMETHOD. 302 | 303 | 304 | METHOD set_parameter_value. 305 | 306 | tdc->set_value( i_param_name = name i_param_value = content 307 | i_variant_name = variant ). 308 | 309 | ENDMETHOD. 310 | ENDCLASS. 311 | -------------------------------------------------------------------------------- /src/zexport_bundle_in_tdc.clas.testclasses.abap: -------------------------------------------------------------------------------- 1 | CLASS test_export_bundle DEFINITION FOR TESTING 2 | DURATION SHORT RISK LEVEL HARMLESS. 3 | 4 | PRIVATE SECTION. 5 | " TDC is temporary created 6 | CONSTANTS: tdc_name TYPE etobj_name VALUE 'ZEXPORT_UNIT_TEST'. 7 | CLASS-DATA: cut TYPE REF TO zexport_bundle_in_tdc. 8 | 9 | CLASS-METHODS class_setup 10 | RAISING cx_static_check. 11 | 12 | " Testcases for method get_parameter_name: 13 | "
    14 | "
  1. should replace invalid characters
  2. 15 | "
  3. should not replace valid characters
  4. 16 | METHODS verify_parameter_name FOR TESTING. 17 | 18 | CLASS-METHODS class_teardown. 19 | 20 | ENDCLASS. 21 | 22 | CLASS zexport_bundle_in_tdc DEFINITION LOCAL FRIENDS test_export_bundle. 23 | 24 | CLASS test_export_bundle IMPLEMENTATION. 25 | 26 | METHOD class_setup. 27 | 28 | TRY. 29 | cl_apl_ecatt_tdc_api=>delete_tdc( i_name = tdc_name ). 30 | ##NO_HANDLER 31 | CATCH cx_ecatt_tdc_access. 32 | ENDTRY. 33 | 34 | cl_apl_ecatt_tdc_api=>create_tdc( EXPORTING 35 | i_name = 'ZEXPORT_UNIT_TEST' i_tadir_devclass = '$TMP' i_write_access = abap_true 36 | IMPORTING e_tdc_ref = DATA(tdc) ). 37 | 38 | cut = NEW zexport_bundle_in_tdc( tdc = tdc variant = 'ECATTDEFAULT' ). 39 | 40 | ENDMETHOD. 41 | 42 | METHOD verify_parameter_name. 43 | 44 | cl_abap_unit_assert=>assert_equals( exp = '_namespace_table1' 45 | act = cut->get_parameter_name( '/namespace/table1' ) 46 | msg = `invalid character '\' should be replaced` ). 47 | 48 | cl_abap_unit_assert=>assert_equals( exp = 'some_table1' 49 | act = cut->get_parameter_name( 'some_table1' ) 50 | msg = `no characters should be changed. All are valid` ). 51 | 52 | ENDMETHOD. 53 | 54 | METHOD class_teardown. 55 | 56 | TRY. 57 | cl_apl_ecatt_tdc_api=>delete_tdc( i_name = tdc_name ). 58 | ##NO_HANDLER 59 | CATCH cx_ecatt_tdc_access. 60 | ENDTRY. 61 | 62 | ENDMETHOD. 63 | 64 | ENDCLASS. 65 | -------------------------------------------------------------------------------- /src/zexport_bundle_in_tdc.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_BUNDLE_IN_TDC 7 | E 8 | Exports bundle as Test Data Container (ecatt) 9 | 1 10 | X 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zexport_changed_sign.dtel.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_CHANGED_SIGN 7 | E 8 | SAP_BOOL 9 | 55 10 | 10 11 | 20 12 | 40 13 | Export function: changed sign 14 | Changed since last export 15 | Changed 16 | Changed since last e 17 | Changed since last export 18 | E 19 | D 20 | 21 | 22 | 23 | 24 | DE 25 | ZEXPORT_CHANGED_SIGN 26 | E 27 | E 28 | 0001 29 | X 30 | 00001 31 | A 32 | 33 | 34 | DOKU 35 | ZEXPORT_CHANGED_SIGN 36 | DE 37 | E 38 | S_DOCU_SHOW 39 | S_DOCUS1 40 | 00001 41 | 072 42 | 43 | 44 | 45 | U1 46 | &DEFINITION& 47 | 48 | 49 | AS 50 | Table content of source table has changed since last export. 51 | 52 | 53 | U1 54 | &USE& 55 | 56 | 57 | AS 58 | 59 | 60 | U1 61 | &DEPENDENCIES& 62 | 63 | 64 | AS 65 | 66 | 67 | U1 68 | &EXAMPLE& 69 | 70 | 71 | AS 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/zexport_fake_table.dtel.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_FAKE_TABLE 7 | E 8 | TABNAME 9 | 30 10 | 10 11 | 20 12 | 40 13 | Fake table 14 | Fake table 15 | Fake table 16 | Fake table 17 | Fake table 18 | E 19 | D 20 | 21 | 22 | 23 | 24 | DE 25 | ZEXPORT_FAKE_TABLE 26 | E 27 | E 28 | 0001 29 | X 30 | 00003 31 | A 32 | 33 | 34 | DOKU 35 | ZEXPORT_FAKE_TABLE 36 | DE 37 | E 38 | S_DOCU_SHOW 39 | S_DOCUS1 40 | 00001 41 | 072 42 | 43 | 44 | 45 | U1 46 | &DEFINITION& 47 | 48 | 49 | AS 50 | The fake table has the same structure as the source table. The fake 51 | 52 | 53 | table is just used in the unit tests as a test-double. The class 54 | 55 | 56 | cl_osql_replace replaces the source table with the fake table. 57 | 58 | 59 | U1 60 | &USE& 61 | 62 | 63 | AS 64 | 65 | 66 | U1 67 | &DEPENDENCIES& 68 | 69 | 70 | AS 71 | 72 | 73 | U1 74 | &EXAMPLE& 75 | 76 | 77 | AS 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/zexport_file_mime_to_frontend.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zexport_file_mime_to_frontend DEFINITION 2 | PUBLIC 3 | FINAL 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | CLASS-METHODS export_to_sapgui_work_dir 9 | IMPORTING 10 | !mime_key TYPE wwwdatatab 11 | RAISING 12 | zcx_export_to_file 13 | zcx_import_object_not_exists . 14 | CLASS-METHODS get_filename 15 | IMPORTING 16 | !key TYPE wwwdatatab 17 | RETURNING 18 | VALUE(filename) TYPE string . 19 | CLASS-METHODS delete_from_sapgui_work 20 | IMPORTING 21 | !key TYPE wwwdatatab. 22 | PROTECTED SECTION. 23 | PRIVATE SECTION. 24 | 25 | TYPES: 26 | _mime_content TYPE STANDARD TABLE OF w3mime . 27 | 28 | CLASS-METHODS get_mime_object 29 | IMPORTING 30 | !key TYPE wwwdatatab 31 | EXPORTING 32 | !content TYPE _mime_content 33 | size TYPE i 34 | RAISING 35 | zcx_import_object_not_exists . 36 | ENDCLASS. 37 | 38 | 39 | 40 | CLASS ZEXPORT_FILE_MIME_TO_FRONTEND IMPLEMENTATION. 41 | 42 | 43 | METHOD delete_from_sapgui_work. 44 | DATA: 45 | ##NEEDED 46 | return_code TYPE i. 47 | 48 | cl_gui_frontend_services=>file_delete( EXPORTING 49 | filename = get_filename( key ) 50 | CHANGING rc = return_code EXCEPTIONS OTHERS = 0 ). 51 | 52 | ENDMETHOD. 53 | 54 | 55 | METHOD export_to_sapgui_work_dir. 56 | DATA subrc TYPE sy-subrc. 57 | 58 | get_mime_object( EXPORTING key = mime_key 59 | IMPORTING content = DATA(content) 60 | size = DATA(binary_filesize) ). 61 | 62 | cl_gui_frontend_services=>gui_download( 63 | EXPORTING bin_filesize = binary_filesize 64 | filename = get_filename( mime_key ) filetype = 'BIN' 65 | CHANGING data_tab = content 66 | EXCEPTIONS 67 | file_write_error = 2 gui_refuse_filetransfer = 4 68 | no_authority = 6 access_denied = 8 OTHERS = 10 ). 69 | subrc = sy-subrc. 70 | IF sy-subrc <> 0. 71 | zcx_export_to_file=>download_failed( 72 | subrc = subrc filename = get_filename( mime_key ) ). 73 | ENDIF. 74 | 75 | ENDMETHOD. 76 | 77 | 78 | METHOD get_filename. 79 | DATA: file_separator(1) TYPE c, 80 | file_extension TYPE wwwparams-value. 81 | 82 | cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = filename ). 83 | cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = file_separator ). 84 | 85 | SELECT SINGLE value FROM wwwparams INTO @file_extension 86 | WHERE relid = @key-relid AND objid = @key-objid 87 | AND name = 'fileextension'. 88 | 89 | filename = filename && file_separator && key-objid && file_extension. 90 | 91 | ENDMETHOD. 92 | 93 | 94 | METHOD get_mime_object. 95 | DATA: c_size TYPE wwwparams-value. 96 | 97 | CALL FUNCTION 'WWWDATA_IMPORT' 98 | EXPORTING 99 | key = key 100 | TABLES 101 | mime = content 102 | EXCEPTIONS 103 | import_error = 4. 104 | IF sy-subrc <> 0. 105 | RAISE EXCEPTION TYPE zcx_import_object_not_exists 106 | EXPORTING 107 | testcase_id = key-objid. 108 | ENDIF. 109 | 110 | SELECT SINGLE value FROM wwwparams INTO @c_size 111 | WHERE relid = @key-relid AND objid = @key-objid 112 | AND name = 'filesize'. 113 | 114 | size = c_size. 115 | 116 | ENDMETHOD. 117 | ENDCLASS. 118 | -------------------------------------------------------------------------------- /src/zexport_file_mime_to_frontend.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_FILE_MIME_TO_FRONTEND 7 | E 8 | Export file from MIME-Object to frontend 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/zexport_is_initial.dtel.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_IS_INITIAL 7 | E 8 | SAP_BOOL 9 | 55 10 | 10 11 | 20 12 | 40 13 | Table content is initial 14 | exported content is initial 15 | is initial 16 | is initial 17 | exported content is initial 18 | E 19 | D 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/zexport_overwrite.doma.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_OVERWRITE 7 | E 8 | CHAR 9 | 000001 10 | 000001 11 | X 12 | Export table content: overwrite allowed 13 | 14 | 15 | 16 | ZEXPORT_OVERWRITE 17 | 0001 18 | E 19 | 1 20 | don't change 21 | 22 | 23 | ZEXPORT_OVERWRITE 24 | 0002 25 | E 26 | 2 27 | overwrite 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/zexport_overwrite.dtel.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_OVERWRITE 7 | E 8 | ZEXPORT_OVERWRITE 9 | 55 10 | 10 11 | 20 12 | 40 13 | Export function: overwrite allowed 14 | Overwrite content in bundle on reexport 15 | Overwrite 16 | Overwrite content 17 | Overwrite content in bundle on reexport 18 | E 19 | D 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/zexport_source_table.dtel.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_SOURCE_TABLE 7 | E 8 | TABNAME 9 | 30 10 | 10 11 | 20 12 | 40 13 | Source table 14 | Source table 15 | Source tab 16 | Source table 17 | Source table 18 | E 19 | D 20 | 21 | 22 | 23 | 24 | DE 25 | ZEXPORT_SOURCE_TABLE 26 | E 27 | E 28 | 0001 29 | X 30 | 00001 31 | A 32 | 33 | 34 | DOKU 35 | ZEXPORT_SOURCE_TABLE 36 | DE 37 | E 38 | S_DOCU_SHOW 39 | S_DOCUS1 40 | 00001 41 | 072 42 | 43 | 44 | 45 | U1 46 | &DEFINITION& 47 | 48 | 49 | AS 50 | The source table, the data originate from. 51 | 52 | 53 | U1 54 | &USE& 55 | 56 | 57 | AS 58 | 59 | 60 | U1 61 | &DEPENDENCIES& 62 | 63 | 64 | AS 65 | 66 | 67 | U1 68 | &EXAMPLE& 69 | 70 | 71 | AS 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/zexport_table_list.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_TABLE_LIST 7 | E 8 | INTTAB 9 | Export bundle table details 10 | 4 11 | 12 | 13 | 14 | SOURCE_TABLE 15 | ZEXPORT_SOURCE_TABLE 16 | 0 17 | E 18 | 19 | 20 | FAKE_TABLE 21 | ZEXPORT_FAKE_TABLE 22 | 0 23 | E 24 | 25 | 26 | WHERE_RESTRICTION 27 | 0 28 | g 29 | 000008 30 | STRG 31 | STRG 32 | SQL Where restriction 33 | 34 | 35 | TDC_PARAMETER_NAME 36 | ETP_NAME 37 | 0 38 | E 39 | 40 | 41 | IS_INITIAL 42 | ZEXPORT_IS_INITIAL 43 | 0 44 | X 45 | F 46 | E 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/zexport_table_mod.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_TABLE_MOD 7 | E 8 | INTTAB 9 | Export fuction: table modifications 10 | 1 11 | 12 | 13 | 14 | CHANGED 15 | ZEXPORT_CHANGED_SIGN 16 | 0 17 | X 18 | F 19 | E 20 | 21 | 22 | OVERWRITE 23 | ZEXPORT_OVERWRITE 24 | 0 25 | X 26 | F 27 | E 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/zexport_ut1.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_UT1 7 | E 8 | TRANSP 9 | X 10 | Table with content to export 11 | X 12 | A 13 | 3 14 | 15 | 16 | ZEXPORT_UT1 17 | A 18 | 0 19 | APPL0 20 | X 21 | X 22 | 23 | 24 | 25 | CLIENT 26 | X 27 | MANDT 28 | 0 29 | X 30 | E 31 | 32 | 33 | PRIMARY_KEY 34 | X 35 | 0 36 | C 37 | 000006 38 | X 39 | CHAR 40 | 000003 41 | CHAR 42 | primary key 43 | 44 | 45 | CONTENT 46 | 0 47 | C 48 | 000020 49 | CHAR 50 | 000010 51 | CHAR 52 | content 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/zexport_ut2.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_UT2 7 | E 8 | TRANSP 9 | X 10 | Table with content to export 11 | X 12 | A 13 | 3 14 | 15 | 16 | ZEXPORT_UT2 17 | A 18 | 0 19 | APPL0 20 | X 21 | X 22 | 23 | 24 | 25 | CLIENT 26 | X 27 | MANDT 28 | 0 29 | X 30 | E 31 | 32 | 33 | PRIMARY_KEY 34 | X 35 | 0 36 | C 37 | 000006 38 | X 39 | CHAR 40 | 000003 41 | CHAR 42 | primary_key 43 | 44 | 45 | CONTENT 46 | 0 47 | P 48 | 000003 49 | DEC 50 | 000004 51 | DEC 52 | a number 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/zexport_ut3.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_UT3 7 | E 8 | TRANSP 9 | X 10 | Table with content to export 11 | X 12 | A 13 | 3 14 | 15 | 16 | ZEXPORT_UT3 17 | A 18 | 0 19 | APPL0 20 | X 21 | X 22 | 23 | 24 | 25 | CLIENT 26 | X 27 | MANDT 28 | 0 29 | X 30 | E 31 | 32 | 33 | PRIMARY_KEY 34 | 0 35 | C 36 | 000006 37 | CHAR 38 | 000003 39 | CHAR 40 | primary_key 41 | 42 | 43 | CONTENT 44 | 0 45 | N 46 | 000008 47 | NUMC 48 | 000004 49 | NUMC 50 | content 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/zexport_utils.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zexport_utils DEFINITION 2 | PUBLIC 3 | FINAL 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | TYPES: 9 | _conditions TYPE STANDARD TABLE OF string . 10 | 11 | CLASS-METHODS get_table_for_all_entries 12 | IMPORTING 13 | !table_conjunction TYPE zexport_table_list 14 | RETURNING 15 | VALUE(table_name) TYPE tabname 16 | EXCEPTIONS 17 | not_for_all_entries_cond . 18 | "! Perform select-statement 19 | "! @parameter table_name | Dictionary-Name of table_for_all_entries 20 | CLASS-METHODS select 21 | IMPORTING 22 | !table_for_all_entries TYPE STANDARD TABLE 23 | !table_conjunction TYPE zexport_table_list 24 | !table_name TYPE tabname 25 | select_from_fake TYPE abap_bool DEFAULT abap_false 26 | EXPORTING 27 | result TYPE STANDARD TABLE 28 | RAISING 29 | zcx_export_error. 30 | CLASS-METHODS is_cds_view_entity 31 | IMPORTING 32 | table_name TYPE tabname 33 | RETURNING 34 | VALUE(result) TYPE sap_bool. 35 | CLASS-METHODS is_view 36 | IMPORTING 37 | table_name TYPE tabname 38 | RETURNING 39 | VALUE(result) TYPE sap_bool. 40 | CLASS-METHODS get_cds_view_name 41 | IMPORTING 42 | entity_name TYPE tabname 43 | RETURNING 44 | VALUE(result) TYPE ddstrucobjname. 45 | PROTECTED SECTION. 46 | PRIVATE SECTION. 47 | ENDCLASS. 48 | 49 | 50 | 51 | CLASS ZEXPORT_UTILS IMPLEMENTATION. 52 | 53 | 54 | METHOD get_cds_view_name. 55 | 56 | cl_dd_ddl_handler_factory=>create( )->get_viewname_from_entityname( 57 | EXPORTING 58 | ddnames = VALUE #( ( name = entity_name ) ) 59 | IMPORTING 60 | view_of_entity = DATA(entities) ). 61 | result = entities[ 1 ]-viewname. 62 | 63 | ENDMETHOD. 64 | 65 | 66 | METHOD get_table_for_all_entries. 67 | CONSTANTS: expression TYPE string VALUE 'FOR ALL ENTRIES IN'. 68 | 69 | DATA(where_restriction) = table_conjunction-where_restriction. 70 | TRANSLATE where_restriction TO UPPER CASE. 71 | DATA(length) = strlen( expression ). 72 | IF strlen( where_restriction ) < length 73 | OR where_restriction+0(length) <> expression. 74 | RAISE not_for_all_entries_cond. 75 | ENDIF. 76 | 77 | SHIFT where_restriction BY length PLACES LEFT. 78 | FIND FIRST OCCURRENCE OF 'WHERE' IN where_restriction 79 | MATCH OFFSET length 80 | IGNORING CASE. 81 | table_name = where_restriction+0(length). 82 | CONDENSE table_name NO-GAPS. 83 | 84 | ENDMETHOD. 85 | 86 | 87 | METHOD is_cds_view_entity. 88 | DATA: object_type TYPE dd02v-tabclass. 89 | 90 | CALL FUNCTION 'DDIF_NAMETAB_GET' 91 | EXPORTING 92 | tabname = table_name 93 | IMPORTING 94 | ddobjtype = object_type 95 | EXCEPTIONS 96 | not_found = 4. 97 | ASSERT sy-subrc = 0. 98 | result = xsdbool( object_type = 'STOB' ). 99 | 100 | ENDMETHOD. 101 | 102 | 103 | METHOD is_view. 104 | 105 | DATA: object_type TYPE dd02v-tabclass. 106 | 107 | CALL FUNCTION 'DDIF_NAMETAB_GET' 108 | EXPORTING 109 | tabname = table_name 110 | IMPORTING 111 | ddobjtype = object_type 112 | EXCEPTIONS 113 | not_found = 4. 114 | ASSERT sy-subrc = 0. 115 | result = xsdbool( object_type = 'STOB' OR object_type = 'STTF' OR object_type = 'VIEW' ). 116 | 117 | ENDMETHOD. 118 | 119 | 120 | METHOD select. 121 | DATA: offset TYPE i, 122 | length TYPE i. 123 | 124 | IF table_for_all_entries IS INITIAL. 125 | RAISE EXCEPTION TYPE zcx_export_empty 126 | EXPORTING 127 | table_name = table_name. 128 | ENDIF. 129 | 130 | CLEAR result. 131 | 132 | FIND FIRST OCCURRENCE OF 'WHERE' IN table_conjunction-where_restriction 133 | MATCH OFFSET offset 134 | MATCH LENGTH length 135 | IGNORING CASE. 136 | IF sy-subrc <> 0. 137 | RAISE EXCEPTION TYPE zcx_export_where_clause_invali 138 | EXPORTING 139 | table = table_conjunction-source_table 140 | where_clause = table_conjunction-where_restriction 141 | failure_description = CONV string( TEXT-001 ). 142 | ENDIF. 143 | offset = offset + length. 144 | DATA(where_restriction) = table_conjunction-where_restriction+offset. 145 | REPLACE ALL OCCURRENCES OF table_name IN where_restriction 146 | WITH 'table_for_all_entries' 147 | IGNORING CASE. 148 | 149 | DATA(select_table) = COND tabname( WHEN select_from_fake = abap_true 150 | THEN table_conjunction-fake_table 151 | ELSE table_conjunction-source_table ). 152 | TRY. 153 | SELECT * FROM (select_table) 154 | INTO CORRESPONDING FIELDS OF TABLE result 155 | FOR ALL ENTRIES IN table_for_all_entries 156 | WHERE (where_restriction). 157 | CATCH cx_sy_dynamic_osql_error INTO DATA(osql_syntax_error). 158 | RAISE EXCEPTION TYPE zcx_export_where_clause_invali 159 | EXPORTING 160 | table = table_conjunction-source_table 161 | where_clause = table_conjunction-where_restriction 162 | failure_description = osql_syntax_error->msgtext. 163 | ENDTRY. 164 | 165 | ENDMETHOD. 166 | ENDCLASS. 167 | -------------------------------------------------------------------------------- /src/zexport_utils.clas.testclasses.abap: -------------------------------------------------------------------------------- 1 | CLASS test_utils DEFINITION FOR TESTING 2 | DURATION SHORT RISK LEVEL HARMLESS FINAL. 3 | 4 | PRIVATE SECTION. 5 | 6 | METHODS get_table_for_all_entries FOR TESTING. 7 | 8 | METHODS select_lower_case FOR TESTING 9 | RAISING 10 | cx_static_check. 11 | 12 | METHODS select_upper_case FOR TESTING 13 | RAISING 14 | cx_static_check. 15 | 16 | METHODS is_cds_view_entity FOR TESTING 17 | RAISING 18 | cx_static_check. 19 | 20 | METHODS get_cds_view_name FOR TESTING 21 | RAISING 22 | cx_static_check. 23 | 24 | ENDCLASS. 25 | 26 | CLASS test_utils IMPLEMENTATION. 27 | 28 | METHOD get_table_for_all_entries. 29 | 30 | zexport_utils=>get_table_for_all_entries( EXPORTING 31 | table_conjunction = VALUE #( where_restriction = `A = 'A'` ) 32 | EXCEPTIONS not_for_all_entries_cond = 4 ). 33 | cl_abap_unit_assert=>assert_subrc( exp = 4 34 | msg = 'not for all entries condition' ). 35 | 36 | " lower case 37 | zexport_utils=>get_table_for_all_entries( EXPORTING 38 | table_conjunction = VALUE #( where_restriction = `for all entries in mseg where a = 'A'` ) 39 | RECEIVING table_name = DATA(act_table_name) 40 | EXCEPTIONS not_for_all_entries_cond = 4 ). 41 | cl_abap_unit_assert=>assert_equals( exp = 'MSEG' 42 | act = act_table_name ). 43 | 44 | " upper case 45 | zexport_utils=>get_table_for_all_entries( EXPORTING 46 | table_conjunction = VALUE #( where_restriction = `FOR ALL ENTRIES IN mseg WHERE A = 'A'` ) 47 | RECEIVING table_name = act_table_name 48 | EXCEPTIONS not_for_all_entries_cond = 4 ). 49 | cl_abap_unit_assert=>assert_equals( exp = 'MSEG' 50 | act = act_table_name ). 51 | 52 | ENDMETHOD. 53 | 54 | METHOD select_lower_case. 55 | DATA: keys TYPE STANDARD TABLE OF zexport_ut3, 56 | mockup TYPE STANDARD TABLE OF zexport_ut1, 57 | act_result TYPE STANDARD TABLE OF zexport_ut1. 58 | 59 | DELETE FROM: zimport_ut1, zexport_ut1. 60 | keys = VALUE #( 61 | ( primary_key = 'AA' ) 62 | ( primary_key = 'BB' ) ). 63 | mockup = VALUE #( 64 | ( client = sy-mandt primary_key = 'AA' content = 'A' ) 65 | ( client = sy-mandt primary_key = 'AB' content = 'AB' ) 66 | ( client = sy-mandt primary_key = 'BB' content = 'B' ) ). 67 | INSERT zexport_ut1 FROM TABLE mockup. 68 | 69 | DATA(table_conjunction) = VALUE zexport_table_list( 70 | source_table = 'ZEXPORT_UT1' fake_table = 'ZIMPORT_UT1' 71 | where_restriction = 'for all entries in keys where primary_key = keys-primary_key' ). 72 | 73 | zexport_utils=>select( EXPORTING 74 | table_for_all_entries = keys 75 | table_conjunction = table_conjunction 76 | table_name = 'KEYS' 77 | IMPORTING 78 | result = act_result ). 79 | 80 | DELETE mockup WHERE primary_key = 'AB'. 81 | cl_abap_unit_assert=>assert_equals( exp = mockup 82 | act = act_result ). 83 | 84 | ENDMETHOD. 85 | 86 | METHOD select_upper_case. 87 | DATA: keys TYPE STANDARD TABLE OF zexport_ut3, 88 | mockup TYPE STANDARD TABLE OF zexport_ut1, 89 | act_result TYPE STANDARD TABLE OF zexport_ut1. 90 | 91 | DELETE FROM: zimport_ut1, zexport_ut1. 92 | keys = VALUE #( 93 | ( primary_key = 'AA' ) 94 | ( primary_key = 'BB' ) ). 95 | mockup = VALUE #( 96 | ( client = sy-mandt primary_key = 'AA' content = 'A' ) 97 | ( client = sy-mandt primary_key = 'AB' content = 'AB' ) 98 | ( client = sy-mandt primary_key = 'BB' content = 'B' ) ). 99 | INSERT zexport_ut1 FROM TABLE mockup. 100 | 101 | DATA(table_conjunction) = VALUE zexport_table_list( 102 | source_table = 'ZEXPORT_UT1' fake_table = 'ZIMPORT_UT1' 103 | where_restriction = 'FOR ALL ENTRIES IN keys WHERE primary_key = keys-primary_key' ). 104 | 105 | zexport_utils=>select( EXPORTING 106 | table_for_all_entries = keys 107 | table_conjunction = table_conjunction 108 | table_name = 'KEYS' 109 | IMPORTING 110 | result = act_result ). 111 | 112 | DELETE mockup WHERE primary_key = 'AB'. 113 | cl_abap_unit_assert=>assert_equals( exp = mockup 114 | act = act_result ). 115 | 116 | ENDMETHOD. 117 | 118 | METHOD is_cds_view_entity. 119 | 120 | cl_abap_unit_assert=>assert_true( act = zexport_utils=>is_cds_view_entity( 'DEMO_CDS_AGGREGATE' ) ). 121 | cl_abap_unit_assert=>assert_false( act = zexport_utils=>is_cds_view_entity( 'SCARR' ) ). 122 | 123 | ENDMETHOD. 124 | 125 | METHOD get_cds_view_name. 126 | 127 | cl_abap_unit_assert=>assert_equals( exp = 'DEMO_CDS_AGG' 128 | act = zexport_utils=>get_cds_view_name( 'DEMO_CDS_AGGREGATE' ) ). 129 | 130 | ENDMETHOD. 131 | 132 | ENDCLASS. 133 | -------------------------------------------------------------------------------- /src/zexport_utils.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZEXPORT_UTILS 7 | E 8 | Utils 9 | 1 10 | X 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | I 18 | 001 19 | Keyword 'WHERE' missing 20 | 46 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/zimport_bundle.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zimport_bundle DEFINITION 2 | PUBLIC 3 | ABSTRACT 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | TYPES: 9 | index_table TYPE STANDARD TABLE OF i . 10 | 11 | DATA: 12 | table_list TYPE STANDARD TABLE OF zexport_table_list READ-ONLY . 13 | 14 | METHODS replace_content_all_tables 15 | ABSTRACT 16 | RAISING 17 | zcx_import_error . 18 | METHODS replace_content_completly 19 | ABSTRACT 20 | RAISING 21 | zcx_import_error . 22 | METHODS add_content_all_tables 23 | ABSTRACT 24 | RAISING 25 | zcx_import_error . 26 | "! 7.51 feature, for backwards-compatibility uses dynamic method calls 27 | METHODS activate_osql_replacement 28 | RAISING 29 | zcx_import_error . 30 | "! Indicies relate to the attribute "table_list" 31 | METHODS get_changed_source_tables 32 | EXPORTING 33 | !indicies TYPE index_table 34 | RAISING 35 | zcx_import_error . 36 | METHODS source_table_has_changed 37 | IMPORTING 38 | !table_conjunction TYPE zexport_table_list 39 | RETURNING 40 | VALUE(has_changed) TYPE abap_bool 41 | RAISING 42 | zcx_import_error . 43 | METHODS prevent_commit_work . 44 | PROTECTED SECTION. 45 | 46 | TYPES: 47 | whitelist TYPE RANGE OF tabname . 48 | 49 | METHODS get_exported_content 50 | ABSTRACT 51 | IMPORTING 52 | !table_conjunction TYPE zexport_table_list 53 | EXPORTING 54 | !content TYPE REF TO data 55 | RAISING 56 | zcx_import_error . 57 | METHODS permission_is_granted 58 | RAISING 59 | zcx_import_not_allowed . 60 | METHODS get_whitelist 61 | RETURNING 62 | VALUE(result) TYPE whitelist . 63 | METHODS delete 64 | IMPORTING 65 | table_conjunction TYPE zexport_table_list 66 | RAISING 67 | zcx_import_error. 68 | PRIVATE SECTION. 69 | 70 | TYPES: 71 | BEGIN OF replaced_table, 72 | source TYPE tabname, 73 | target TYPE string, 74 | END OF replaced_table . 75 | TYPES: 76 | replaced_tables TYPE SORTED TABLE OF replaced_table WITH UNIQUE KEY source . 77 | 78 | METHODS compare 79 | IMPORTING 80 | lhs TYPE STANDARD TABLE 81 | rhs TYPE STANDARD TABLE 82 | RETURNING VALUE(differs) TYPE abap_bool. 83 | METHODS select 84 | IMPORTING 85 | table_conjunction TYPE zexport_table_list 86 | from_fake TYPE sap_bool OPTIONAL 87 | EXPORTING 88 | content TYPE STANDARD TABLE 89 | RAISING 90 | zcx_import_error. 91 | METHODS select_from_fake 92 | IMPORTING 93 | table_conjunction TYPE zexport_table_list 94 | EXPORTING 95 | content TYPE STANDARD TABLE 96 | RAISING 97 | zcx_import_error. 98 | ENDCLASS. 99 | 100 | 101 | 102 | CLASS ZIMPORT_BUNDLE IMPLEMENTATION. 103 | 104 | 105 | METHOD activate_osql_replacement. 106 | DATA: replaced_tables TYPE replaced_tables, 107 | _replaced_tables TYPE REF TO data. 108 | FIELD-SYMBOLS: TYPE ANY TABLE. 109 | 110 | CREATE DATA _replaced_tables TYPE ('CL_OSQL_REPLACE=>TT_REPLACEMENT'). 111 | ASSIGN _replaced_tables->* TO . 112 | 113 | LOOP AT table_list REFERENCE INTO DATA(pair). 114 | IF pair->*-source_table <> pair->*-fake_table. 115 | INSERT VALUE #( source = pair->*-source_table target = pair->*-fake_table ) 116 | INTO TABLE replaced_tables. 117 | ENDIF. 118 | ENDLOOP. 119 | 120 | MOVE-CORRESPONDING replaced_tables TO . 121 | CALL METHOD ('CL_OSQL_REPLACE')=>activate_replacement 122 | EXPORTING 123 | replacement_table = . 124 | 125 | ENDMETHOD. 126 | 127 | 128 | METHOD compare. 129 | FIELD-SYMBOLS: TYPE any, 130 | TYPE any. 131 | 132 | IF lines( lhs ) <> lines( rhs ). 133 | differs = abap_true. 134 | RETURN. 135 | ENDIF. 136 | 137 | " "lhs" and "rhs" may have different sort order 138 | LOOP AT lhs ASSIGNING . 139 | READ TABLE rhs ASSIGNING FROM . 140 | IF sy-subrc = 0. 141 | IF <> . 142 | differs = abap_true. 143 | RETURN. 144 | ENDIF. 145 | ELSE. 146 | differs = abap_true. 147 | RETURN. 148 | ENDIF. 149 | ENDLOOP. 150 | 151 | ENDMETHOD. 152 | 153 | 154 | METHOD delete. 155 | DATA: content TYPE REF TO data. 156 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 157 | 158 | CREATE DATA content TYPE STANDARD TABLE OF (table_conjunction-fake_table). 159 | ASSIGN content->* TO . 160 | 161 | select_from_fake( EXPORTING table_conjunction = table_conjunction 162 | IMPORTING content = ). 163 | DELETE (table_conjunction-fake_table) FROM TABLE . 164 | 165 | ENDMETHOD. 166 | 167 | 168 | METHOD get_changed_source_tables. 169 | DATA: actual_content TYPE REF TO data, 170 | exported_content TYPE REF TO data. 171 | FIELD-SYMBOLS: TYPE STANDARD TABLE, 172 | TYPE STANDARD TABLE. 173 | 174 | CLEAR indicies. 175 | LOOP AT table_list REFERENCE INTO DATA(table_conjunction). 176 | 177 | DATA(idx) = sy-tabix. 178 | 179 | CREATE DATA: 180 | actual_content TYPE STANDARD TABLE OF (table_conjunction->*-source_table), 181 | exported_content TYPE STANDARD TABLE OF (table_conjunction->*-source_table). 182 | ASSIGN actual_content->* TO . 183 | 184 | get_exported_content( EXPORTING table_conjunction = table_conjunction->* 185 | IMPORTING content = exported_content ). 186 | ASSIGN exported_content->* TO . 187 | select( EXPORTING table_conjunction = table_conjunction->* 188 | IMPORTING content = ). 189 | 190 | IF compare( lhs = rhs = ) = abap_true. 191 | APPEND idx TO indicies. 192 | ENDIF. 193 | 194 | ENDLOOP. 195 | 196 | ENDMETHOD. 197 | 198 | 199 | METHOD get_whitelist. 200 | 201 | SELECT sign, opti AS option, low, high FROM tvarvc 202 | INTO CORRESPONDING FIELDS OF TABLE @result 203 | WHERE name = 'ZIMPORT_REPLACE_WHITELIST' AND type = 'S'. 204 | 205 | ENDMETHOD. 206 | 207 | 208 | METHOD permission_is_granted. 209 | 210 | DATA(aunit_setup) = cl_aunit_customizing=>get_setup( ). 211 | IF aunit_setup-client-max_risk_level >= if_aunit_attribute_enums=>c_risk_level-dangerous 212 | AND aunit_setup-client-deny_execution = abap_false. 213 | 214 | RETURN. 215 | 216 | ENDIF. 217 | 218 | RAISE EXCEPTION TYPE zcx_import_not_allowed. 219 | 220 | ENDMETHOD. 221 | 222 | 223 | METHOD prevent_commit_work. 224 | 225 | SET UPDATE TASK LOCAL. 226 | CALL FUNCTION 'ZIMPORT_PREVENT_COMMIT_WORK' 227 | IN UPDATE TASK. 228 | 229 | ENDMETHOD. 230 | 231 | 232 | METHOD select. 233 | DATA: table_for_all_entries TYPE REF TO data. 234 | 235 | TRY. 236 | zexport_utils=>get_table_for_all_entries( EXPORTING 237 | table_conjunction = table_conjunction 238 | RECEIVING table_name = DATA(table_name) 239 | EXCEPTIONS not_for_all_entries_cond = 4 ). 240 | IF sy-subrc = 0. 241 | 242 | READ TABLE table_list REFERENCE INTO DATA(foe_conjunction) 243 | WITH KEY fake_table = table_name+1. 244 | IF sy-subrc <> 0. 245 | RAISE EXCEPTION TYPE zcx_export_invalid_name 246 | EXPORTING 247 | name = table_name. 248 | ENDIF. 249 | 250 | CREATE DATA table_for_all_entries TYPE STANDARD TABLE OF (table_name+1). 251 | get_exported_content( EXPORTING table_conjunction = foe_conjunction->* 252 | IMPORTING content = table_for_all_entries ). 253 | ASSIGN table_for_all_entries->* TO FIELD-SYMBOL(). 254 | zexport_utils=>select( EXPORTING table_for_all_entries = 255 | table_conjunction = table_conjunction table_name = table_name 256 | select_from_fake = from_fake 257 | IMPORTING result = content ). 258 | 259 | ELSE. 260 | 261 | DATA(data_source) = COND tabname( WHEN from_fake = abap_true 262 | THEN table_conjunction-fake_table ELSE table_conjunction-source_table ). 263 | SELECT * FROM (data_source) INTO TABLE @content 264 | WHERE (table_conjunction-where_restriction). 265 | 266 | ENDIF. 267 | CATCH zcx_export_error INTO DATA(exc). 268 | RAISE EXCEPTION TYPE zcx_import_error 269 | EXPORTING 270 | previous = exc. 271 | ENDTRY. 272 | 273 | ENDMETHOD. 274 | 275 | 276 | METHOD select_from_fake. 277 | 278 | select( EXPORTING table_conjunction = table_conjunction 279 | from_fake = abap_true 280 | IMPORTING content = content ). 281 | 282 | ENDMETHOD. 283 | 284 | 285 | METHOD source_table_has_changed. 286 | DATA: actual_content TYPE REF TO data, 287 | exported_content TYPE REF TO data. 288 | FIELD-SYMBOLS: TYPE STANDARD TABLE, 289 | TYPE STANDARD TABLE. 290 | 291 | CREATE DATA: 292 | actual_content TYPE STANDARD TABLE OF (table_conjunction-source_table), 293 | exported_content TYPE STANDARD TABLE OF (table_conjunction-source_table). 294 | ASSIGN actual_content->* TO . 295 | 296 | get_exported_content( EXPORTING table_conjunction = table_conjunction 297 | IMPORTING content = exported_content ). 298 | ASSIGN exported_content->* TO . 299 | select( EXPORTING table_conjunction = table_conjunction 300 | IMPORTING content = ). 301 | 302 | has_changed = compare( lhs = rhs = ). 303 | 304 | ENDMETHOD. 305 | ENDCLASS. 306 | -------------------------------------------------------------------------------- /src/zimport_bundle.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZIMPORT_BUNDLE 7 | E 8 | Import Bundle from abstract source 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.lzimport_bundletop.abap: -------------------------------------------------------------------------------- 1 | FUNCTION-POOL zimport_bundle. "MESSAGE-ID .. 2 | 3 | * INCLUDE LZIMPORT_BUNDLED... " Local class definition 4 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.lzimport_bundletop.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | LZIMPORT_BUNDLETOP 7 | S 8 | D$ 9 | I 10 | S 11 | X 12 | D$S 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.saplzimport_bundle.abap: -------------------------------------------------------------------------------- 1 | ******************************************************************* 2 | * System-defined Include-files. * 3 | ******************************************************************* 4 | INCLUDE lzimport_bundletop. " Global Data 5 | INCLUDE lzimport_bundleuxx. " Function Modules 6 | 7 | ******************************************************************* 8 | * User-defined Include-files (if necessary). * 9 | ******************************************************************* 10 | * INCLUDE LZIMPORT_BUNDLEF... " Subroutines 11 | * INCLUDE LZIMPORT_BUNDLEO... " PBO-Modules 12 | * INCLUDE LZIMPORT_BUNDLEI... " PAI-Modules 13 | * INCLUDE LZIMPORT_BUNDLEE... " Events 14 | * INCLUDE LZIMPORT_BUNDLEP... " Local class implement. 15 | * INCLUDE LZIMPORT_BUNDLET99. " ABAP Unit tests 16 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.saplzimport_bundle.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | SAPLZIMPORT_BUNDLE 7 | S 8 | D$ 9 | F 10 | S 11 | E 12 | X 13 | D$S 14 | X 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Import bundle RFC-API 6 | 7 | LZIMPORT_BUNDLETOP 8 | SAPLZIMPORT_BUNDLE 9 | 10 | 11 | 12 | ZIMPORT_BUNDLE_FROM_CLUSTER 13 | Imprt Bundle from cluster 14 | 15 | 16 | TESTCASE_ID 17 | X 18 | W3OBJID 19 | 20 | 21 | CONTENT_HANDLER 22 | X 23 | SEOCMPNAME 24 | 25 | 26 | DO_COMMIT 27 | X 28 | ABAP_BOOL 29 | 30 | 31 | 32 | 33 | ZCX_IMPORT_ERROR 34 | 35 | 36 | CX_SY_DYN_CALL_ILLEGAL_METHOD 37 | 38 | 39 | 40 | 41 | TESTCASE_ID 42 | P 43 | Id of cluster 44 | 45 | 46 | CONTENT_HANDLER 47 | P 48 | Handler (method) 49 | 50 | 51 | DO_COMMIT 52 | P 53 | execute "COMMIT WORK" 54 | 55 | 56 | ZCX_IMPORT_ERROR 57 | X 58 | Import-Errors 59 | 60 | 61 | CX_SY_DYN_CALL_ILLEGAL_METHOD 62 | X 63 | Content-Handler is not a valid method 64 | 65 | 66 | X 67 | 68 | 69 | ZIMPORT_BUNDLE_FROM_TDC 70 | Import bundle from Test-Data-Container 71 | 72 | 73 | TDC 74 | X 75 | ETOBJ_NAME 76 | 77 | 78 | TDC_VERSION 79 | X 80 | ETOBJ_VER 81 | 82 | 83 | VARIANT 84 | X 85 | ETVAR_ID 86 | 87 | 88 | CONTENT_HANDLER 89 | X 90 | SEOCMPNAME 91 | 92 | 93 | DO_COMMIT 94 | ABAP_TRUE 95 | X 96 | SAP_BOOL 97 | 98 | 99 | 100 | 101 | ZCX_IMPORT_ERROR 102 | 103 | 104 | CX_SY_DYN_CALL_ILLEGAL_METHOD 105 | 106 | 107 | 108 | 109 | TDC 110 | P 111 | Testdatacontainer 112 | 113 | 114 | TDC_VERSION 115 | P 116 | Version TDC 117 | 118 | 119 | VARIANT 120 | P 121 | Variant name 122 | 123 | 124 | CONTENT_HANDLER 125 | P 126 | Handler (method) 127 | 128 | 129 | DO_COMMIT 130 | P 131 | execute "COMMIT WORK AND WAIT" 132 | 133 | 134 | ZCX_IMPORT_ERROR 135 | X 136 | Import-Errors 137 | 138 | 139 | CX_SY_DYN_CALL_ILLEGAL_METHOD 140 | X 141 | content-handler is invalid 142 | 143 | 144 | X 145 | 146 | 147 | ZIMPORT_PREVENT_COMMIT_WORK 148 | 1 149 | Prevent COMMIT WORK 150 | 151 | 152 | ZRFCIMPORT_BUNDLE_FROM_CLUSTER 153 | R 154 | Imprt Bundle from cluster 155 | 156 | 157 | TESTCASE_ID 158 | W3OBJID 159 | 160 | 161 | CONTENT_HANDLER 162 | SEOCMPNAME 163 | 164 | 165 | DO_COMMIT 166 | ABAP_TRUE 167 | X 168 | SAP_BOOL 169 | 170 | 171 | 172 | 173 | IMPORT_ERROR 174 | 175 | 176 | INVALID_CONTENT_HANDLER 177 | 178 | 179 | 180 | 181 | TESTCASE_ID 182 | P 183 | Id of cluster 184 | 185 | 186 | CONTENT_HANDLER 187 | P 188 | Handler (method) 189 | 190 | 191 | DO_COMMIT 192 | P 193 | execute "COMMIT WORK" 194 | 195 | 196 | IMPORT_ERROR 197 | X 198 | Import-errors 199 | 200 | 201 | INVALID_CONTENT_HANDLER 202 | X 203 | Content-Handler is invalid 204 | 205 | 206 | 207 | 208 | ZRFC_IMPORT_BUNDLE_FROM_TDC 209 | R 210 | Import bundle from Test-Data-Container 211 | 212 | 213 | TDC 214 | ETOBJ_NAME 215 | 216 | 217 | TDC_VERSION 218 | ETOBJ_VER 219 | 220 | 221 | VARIANT 222 | ETVAR_ID 223 | 224 | 225 | CONTENT_HANDLER 226 | SEOCMPNAME 227 | 228 | 229 | DO_COMMIT 230 | ABAP_TRUE 231 | SAP_BOOL 232 | 233 | 234 | 235 | 236 | IMPORT_ERROR 237 | 238 | 239 | INVALID_CONTENT_HANDLER 240 | 241 | 242 | 243 | 244 | TDC 245 | P 246 | Testdatacontainer 247 | 248 | 249 | TDC_VERSION 250 | P 251 | Version TDC 252 | 253 | 254 | VARIANT 255 | P 256 | Variant name 257 | 258 | 259 | CONTENT_HANDLER 260 | P 261 | Handler (method) 262 | 263 | 264 | DO_COMMIT 265 | P 266 | execute "COMMIT WORK AND WAIT" 267 | 268 | 269 | IMPORT_ERROR 270 | X 271 | Import-Error 272 | 273 | 274 | INVALID_CONTENT_HANDLER 275 | X 276 | Content-Handler is invalid 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.zimport_bundle_from_cluster.abap: -------------------------------------------------------------------------------- 1 | FUNCTION zimport_bundle_from_cluster. 2 | *"---------------------------------------------------------------------- 3 | *"*"Local Interface: 4 | *" IMPORTING 5 | *" REFERENCE(TESTCASE_ID) TYPE W3OBJID 6 | *" REFERENCE(CONTENT_HANDLER) TYPE SEOCMPNAME 7 | *" REFERENCE(DO_COMMIT) TYPE ABAP_BOOL 8 | *" RAISING 9 | *" ZCX_IMPORT_ERROR 10 | *" CX_SY_DYN_CALL_ILLEGAL_METHOD 11 | *"---------------------------------------------------------------------- 12 | 13 | DATA(importer) = NEW zimport_bundle_from_cluster( testcase_id ). 14 | 15 | CALL METHOD importer->(content_handler). 16 | 17 | IF do_commit = abap_true. 18 | COMMIT WORK AND WAIT. 19 | ENDIF. 20 | 21 | ENDFUNCTION. 22 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.zimport_bundle_from_tdc.abap: -------------------------------------------------------------------------------- 1 | FUNCTION zimport_bundle_from_tdc. 2 | *"---------------------------------------------------------------------- 3 | *"*"Local Interface: 4 | *" IMPORTING 5 | *" REFERENCE(TDC) TYPE ETOBJ_NAME 6 | *" REFERENCE(TDC_VERSION) TYPE ETOBJ_VER 7 | *" REFERENCE(VARIANT) TYPE ETVAR_ID 8 | *" REFERENCE(CONTENT_HANDLER) TYPE SEOCMPNAME 9 | *" REFERENCE(DO_COMMIT) TYPE SAP_BOOL DEFAULT ABAP_TRUE 10 | *" RAISING 11 | *" ZCX_IMPORT_ERROR 12 | *" CX_SY_DYN_CALL_ILLEGAL_METHOD 13 | *"---------------------------------------------------------------------- 14 | 15 | DATA(importer) = NEW zimport_bundle_from_tdc( 16 | tdc = tdc tdc_version = tdc_version variant = variant ). 17 | 18 | CALL METHOD importer->(content_handler). 19 | 20 | IF do_commit = abap_true. 21 | COMMIT WORK AND WAIT. 22 | ENDIF. 23 | 24 | ENDFUNCTION. 25 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.zimport_prevent_commit_work.abap: -------------------------------------------------------------------------------- 1 | FUNCTION zimport_prevent_commit_work. 2 | *"---------------------------------------------------------------------- 3 | *"*"Update Function Module: 4 | *" 5 | *"*"Local Interface: 6 | *"---------------------------------------------------------------------- 7 | 8 | ASSERT 1 = 0. 9 | 10 | ENDFUNCTION. 11 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.zrfc_import_bundle_from_tdc.abap: -------------------------------------------------------------------------------- 1 | FUNCTION zrfc_import_bundle_from_tdc. 2 | *"---------------------------------------------------------------------- 3 | *"*"Local Interface: 4 | *" IMPORTING 5 | *" VALUE(TDC) TYPE ETOBJ_NAME 6 | *" VALUE(TDC_VERSION) TYPE ETOBJ_VER 7 | *" VALUE(VARIANT) TYPE ETVAR_ID 8 | *" VALUE(CONTENT_HANDLER) TYPE SEOCMPNAME 9 | *" VALUE(DO_COMMIT) TYPE SAP_BOOL DEFAULT ABAP_TRUE 10 | *" EXCEPTIONS 11 | *" IMPORT_ERROR 12 | *" INVALID_CONTENT_HANDLER 13 | *"---------------------------------------------------------------------- 14 | 15 | TRY. 16 | 17 | CALL FUNCTION 'ZIMPORT_BUNDLE_FROM_TDC' 18 | EXPORTING 19 | tdc = tdc 20 | tdc_version = tdc_version 21 | variant = variant 22 | content_handler = content_handler 23 | do_commit = do_commit. 24 | 25 | CATCH zcx_import_error INTO DATA(error). 26 | MESSAGE error TYPE 'E' RAISING import_error. 27 | CATCH cx_sy_dyn_call_illegal_method. 28 | MESSAGE e010(zexport) WITH content_handler RAISING invalid_content_handler. 29 | ENDTRY. 30 | 31 | ENDFUNCTION. 32 | -------------------------------------------------------------------------------- /src/zimport_bundle.fugr.zrfcimport_bundle_from_cluster.abap: -------------------------------------------------------------------------------- 1 | FUNCTION zrfcimport_bundle_from_cluster. 2 | *"---------------------------------------------------------------------- 3 | *"*"Local Interface: 4 | *" IMPORTING 5 | *" VALUE(TESTCASE_ID) TYPE W3OBJID 6 | *" VALUE(CONTENT_HANDLER) TYPE SEOCMPNAME 7 | *" VALUE(DO_COMMIT) TYPE SAP_BOOL DEFAULT ABAP_TRUE 8 | *" EXCEPTIONS 9 | *" IMPORT_ERROR 10 | *" INVALID_CONTENT_HANDLER 11 | *"---------------------------------------------------------------------- 12 | 13 | TRY. 14 | 15 | CALL FUNCTION 'ZIMPORT_BUNDLE_FROM_CLUSTER' 16 | EXPORTING 17 | testcase_id = testcase_id 18 | content_handler = content_handler 19 | do_commit = do_commit. 20 | 21 | CATCH zcx_import_error INTO DATA(error). 22 | MESSAGE error TYPE 'E' RAISING import_error. 23 | CATCH cx_sy_dyn_call_illegal_method. 24 | MESSAGE e010(zexport) WITH content_handler RAISING invalid_content_handler. 25 | ENDTRY. 26 | 27 | ENDFUNCTION. 28 | -------------------------------------------------------------------------------- /src/zimport_bundle_from_cluster.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zimport_bundle_from_cluster DEFINITION 2 | PUBLIC 3 | INHERITING FROM zimport_bundle 4 | FINAL 5 | CREATE PUBLIC . 6 | 7 | PUBLIC SECTION. 8 | 9 | METHODS constructor 10 | IMPORTING 11 | !testcase_id TYPE w3objid 12 | RAISING 13 | zcx_import_error . 14 | METHODS get_exported_content_for_table 15 | IMPORTING 16 | source_table TYPE tabname 17 | EXPORTING 18 | content TYPE REF TO data 19 | table_conjunction TYPE zexport_table_list 20 | RAISING 21 | zcx_import_error. 22 | 23 | METHODS add_content_all_tables 24 | REDEFINITION . 25 | METHODS replace_content_all_tables 26 | REDEFINITION . 27 | METHODS replace_content_completly 28 | REDEFINITION . 29 | PROTECTED SECTION. 30 | 31 | METHODS get_exported_content REDEFINITION. 32 | PRIVATE SECTION. 33 | 34 | DATA cluster_objects TYPE abap_trans_srcbind_tab . 35 | DATA mime_key TYPE wwwdatatab . 36 | 37 | METHODS import_mime_object 38 | RAISING 39 | zcx_import_object_not_exists . 40 | METHODS get_filesize 41 | RETURNING 42 | VALUE(size) TYPE i . 43 | METHODS deserialize 44 | IMPORTING 45 | !binary_content TYPE xstring . 46 | ENDCLASS. 47 | 48 | 49 | 50 | CLASS ZIMPORT_BUNDLE_FROM_CLUSTER IMPLEMENTATION. 51 | 52 | 53 | METHOD add_content_all_tables. 54 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 55 | 56 | permission_is_granted( ). 57 | LOOP AT cluster_objects REFERENCE INTO DATA(object). 58 | 59 | IF zexport_utils=>is_view( CONV tabname( object->*-name ) ) = abap_true. 60 | CONTINUE. 61 | ENDIF. 62 | ASSIGN object->*-value->* TO . 63 | 64 | MODIFY (object->*-name) FROM TABLE . 65 | 66 | ENDLOOP. 67 | 68 | ENDMETHOD. 69 | 70 | 71 | METHOD constructor. 72 | 73 | super->constructor( ). 74 | 75 | mime_key-relid = 'MI'. 76 | mime_key-objid = testcase_id. 77 | 78 | import_mime_object( ). 79 | 80 | ENDMETHOD. 81 | 82 | 83 | METHOD deserialize. 84 | DATA: binary_table_content TYPE xstring. 85 | 86 | IMPORT content = binary_table_content table_list = table_list 87 | FROM DATA BUFFER binary_content. 88 | 89 | LOOP AT table_list REFERENCE INTO DATA(_table). 90 | APPEND INITIAL LINE TO cluster_objects ASSIGNING FIELD-SYMBOL(). 91 | -name = _table->*-fake_table. 92 | CREATE DATA -value TYPE STANDARD TABLE OF (_table->*-fake_table). 93 | ENDLOOP. 94 | 95 | CALL TRANSFORMATION id 96 | SOURCE XML binary_table_content 97 | RESULT (cluster_objects). 98 | 99 | ENDMETHOD. 100 | 101 | 102 | METHOD get_exported_content. 103 | 104 | READ TABLE cluster_objects REFERENCE INTO DATA(object) 105 | WITH KEY name = table_conjunction-fake_table. 106 | content = object->*-value. 107 | 108 | ENDMETHOD. 109 | 110 | 111 | METHOD get_exported_content_for_table. 112 | 113 | READ TABLE table_list INTO table_conjunction 114 | WITH KEY source_table = source_table. 115 | 116 | get_exported_content( EXPORTING table_conjunction = table_conjunction 117 | IMPORTING content = content ). 118 | 119 | ENDMETHOD. 120 | 121 | 122 | METHOD get_filesize. 123 | DATA: c_size TYPE wwwparams-value. 124 | 125 | SELECT SINGLE value FROM wwwparams INTO c_size 126 | WHERE relid = mime_key-relid AND objid = mime_key-objid 127 | AND name = 'filesize'. 128 | 129 | size = c_size. 130 | 131 | ENDMETHOD. 132 | 133 | 134 | METHOD import_mime_object. 135 | DATA: mime_content TYPE STANDARD TABLE OF w3mime, 136 | binary_content TYPE xstring. 137 | 138 | CALL FUNCTION 'WWWDATA_IMPORT' 139 | EXPORTING 140 | key = mime_key 141 | TABLES 142 | mime = mime_content 143 | EXCEPTIONS 144 | import_error = 4. 145 | IF sy-subrc <> 0. 146 | RAISE EXCEPTION TYPE zcx_import_object_not_exists 147 | EXPORTING 148 | testcase_id = mime_key-objid. 149 | ENDIF. 150 | 151 | DATA(length) = get_filesize( ). 152 | 153 | CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' 154 | EXPORTING 155 | input_length = length 156 | IMPORTING 157 | buffer = binary_content 158 | TABLES 159 | binary_tab = mime_content. 160 | 161 | deserialize( binary_content ). 162 | 163 | ENDMETHOD. 164 | 165 | 166 | METHOD replace_content_all_tables. 167 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 168 | 169 | permission_is_granted( ). 170 | LOOP AT cluster_objects REFERENCE INTO DATA(object). 171 | 172 | IF zexport_utils=>is_view( CONV tabname( object->*-name ) ) = abap_true. 173 | CONTINUE. 174 | ENDIF. 175 | 176 | ASSIGN object->*-value->* TO . 177 | 178 | READ TABLE table_list REFERENCE INTO DATA(_table) 179 | WITH KEY fake_table = CONV tabname( object->*-name ). 180 | ASSERT FIELDS object->*-name CONDITION sy-subrc = 0. 181 | 182 | delete( _table->* ). 183 | INSERT (object->*-name) FROM TABLE . 184 | 185 | ENDLOOP. 186 | 187 | ENDMETHOD. 188 | 189 | 190 | METHOD replace_content_completly. 191 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 192 | 193 | permission_is_granted( ). 194 | LOOP AT cluster_objects REFERENCE INTO DATA(object). 195 | 196 | IF zexport_utils=>is_view( CONV tabname( object->*-name ) ) = abap_true. 197 | CONTINUE. 198 | ENDIF. 199 | 200 | ASSIGN object->*-value->* TO . 201 | 202 | DELETE FROM (object->*-name). 203 | INSERT (object->*-name) FROM TABLE . 204 | 205 | ENDLOOP. 206 | 207 | ENDMETHOD. 208 | ENDCLASS. 209 | -------------------------------------------------------------------------------- /src/zimport_bundle_from_cluster.clas.testclasses.abap: -------------------------------------------------------------------------------- 1 | CONSTANTS: testcase_id TYPE w3objid VALUE 'ZBUNDLE_UNIT_TEST'. 2 | 3 | CLASS test_export_import DEFINITION FOR TESTING DURATION SHORT 4 | RISK LEVEL DANGEROUS. 5 | 6 | PRIVATE SECTION. 7 | 8 | METHODS setup 9 | RAISING 10 | zcx_export_error. 11 | 12 | METHODS setup_mime. 13 | 14 | METHODS setup_tables. 15 | 16 | METHODS export 17 | RAISING 18 | zcx_export_error. 19 | 20 | METHODS import_and_replace FOR TESTING 21 | RAISING 22 | zcx_import_error. 23 | 24 | METHODS import_and_add FOR TESTING 25 | RAISING 26 | zcx_import_error. 27 | 28 | METHODS activate_osql_replacement FOR TESTING 29 | RAISING 30 | zcx_import_error. 31 | 32 | METHODS get_changed_source_tables FOR TESTING 33 | RAISING 34 | cx_static_check. 35 | 36 | METHODS get_exported_content FOR TESTING 37 | RAISING 38 | cx_static_check. 39 | 40 | METHODS reexport 41 | RAISING 42 | cx_static_check. 43 | 44 | METHODS reexport_subset FOR TESTING 45 | RAISING 46 | cx_static_check. 47 | 48 | ENDCLASS. 49 | 50 | CLASS test_export_import IMPLEMENTATION. 51 | 52 | METHOD setup. 53 | 54 | setup_mime( ). 55 | setup_tables( ). 56 | COMMIT WORK AND WAIT. 57 | export( ). 58 | COMMIT WORK AND WAIT. 59 | 60 | DELETE FROM zexport_ut3. 61 | COMMIT WORK AND WAIT. 62 | 63 | ENDMETHOD. 64 | 65 | METHOD setup_mime. 66 | DATA: mime_key TYPE wwwdatatab. 67 | 68 | mime_key-relid = 'MI'. 69 | mime_key-objid = testcase_id. 70 | 71 | CALL FUNCTION 'WWWDATA_DELETE' 72 | EXPORTING 73 | key = mime_key 74 | EXCEPTIONS 75 | OTHERS = 0. 76 | 77 | " commit work and wait necessary, because uncommitted read 78 | " on oracle and hana databases not possible. 79 | " If the MIME-Object exists, export will throw exception. 80 | COMMIT WORK AND WAIT. 81 | 82 | ENDMETHOD. 83 | 84 | METHOD setup_tables. 85 | DATA: export_ut1 TYPE zexport_ut1, 86 | export_ut2 TYPE zexport_ut2, 87 | export_ut3 TYPE zexport_ut3, 88 | import_ut1 TYPE zimport_ut1, 89 | import_ut2 TYPE zimport_ut2. 90 | 91 | " setup the tables in this package 92 | DELETE FROM: zexport_ut1, zimport_ut1, 93 | zexport_ut2, zexport_ut3, zimport_ut2. 94 | 95 | export_ut1 = VALUE #( primary_key = 'AAA' content = 'char' ). 96 | ##LITERAL 97 | export_ut2 = VALUE #( primary_key = 'AAA' content = '130' ). 98 | export_ut3 = VALUE #( primary_key = 'ADA' content = '9999' ). 99 | import_ut1 = VALUE #( primary_key = 'CCC' content = 'imp' ). 100 | ##LITERAL 101 | import_ut2 = VALUE #( primary_key = 'CCC' content = '30' ). 102 | 103 | INSERT zexport_ut1 FROM @export_ut1. 104 | INSERT zexport_ut2 FROM @export_ut2. 105 | 106 | INSERT zimport_ut1 FROM @import_ut1. 107 | INSERT zimport_ut2 FROM @import_ut2. 108 | 109 | INSERT zexport_ut3 FROM @export_ut3. 110 | 111 | ENDMETHOD. 112 | 113 | METHOD export. 114 | DATA: dev_package TYPE devclass. 115 | 116 | SELECT SINGLE devclass FROM tadir INTO @dev_package 117 | WHERE pgmid = 'R3TR' AND object = 'CLAS' AND obj_name = 'ZIMPORT_BUNDLE_FROM_CLUSTER'. 118 | 119 | DATA(exporter) = NEW zexport_bundle_in_cluster( testcase_id = testcase_id 120 | dev_package = dev_package title = 'Unit-Test ABAP DB preparator' ). 121 | 122 | exporter->add_table_to_bundle( _table = VALUE #( 123 | source_table = 'ZEXPORT_UT1' fake_table = 'ZIMPORT_UT1' ) ). 124 | exporter->add_table_to_bundle( _table = VALUE #( 125 | source_table = 'ZEXPORT_UT2' fake_table = 'ZIMPORT_UT2' ) ). 126 | exporter->add_table_to_bundle( _table = VALUE #( 127 | source_table = 'ZEXPORT_UT3' ) ). 128 | 129 | exporter->export( ). 130 | 131 | ENDMETHOD. 132 | 133 | METHOD import_and_replace. 134 | DATA: act_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 135 | act_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 136 | act_cont_export_ut3 TYPE STANDARD TABLE OF zexport_ut3, 137 | exp_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 138 | exp_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 139 | exp_cont_export_ut3 TYPE STANDARD TABLE OF zexport_ut3. 140 | 141 | exp_cont_import_ut1 = VALUE #( 142 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) ). 143 | exp_cont_import_ut2 = VALUE #( 144 | ( client = sy-mandt primary_key = 'AAA' content = '130' ) ). 145 | exp_cont_export_ut3 = VALUE #( 146 | ( client = sy-mandt primary_key = 'ADA' content = '9999' ) ). 147 | 148 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 149 | 150 | cut->replace_content_all_tables( ). 151 | COMMIT WORK AND WAIT. 152 | 153 | SELECT * FROM zimport_ut1 INTO TABLE @act_cont_import_ut1. 154 | SELECT * FROM zimport_ut2 INTO TABLE @act_cont_import_ut2. 155 | SELECT * FROM zexport_ut3 INTO TABLE @act_cont_export_ut3. 156 | 157 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut1 158 | act = act_cont_import_ut1 159 | msg = 'content imported from table zimport_ut1' ). 160 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut2 161 | act = act_cont_import_ut2 162 | msg = 'content imported from table zimport_ut2' ). 163 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_export_ut3 164 | act = act_cont_export_ut3 165 | msg = 'content imported from table zexport_ut3 (no fake-table)' ). 166 | 167 | ENDMETHOD. 168 | 169 | METHOD import_and_add. 170 | DATA: act_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 171 | act_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 172 | act_cont_export_ut3 TYPE STANDARD TABLE OF zexport_ut3, 173 | exp_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 174 | exp_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 175 | exp_cont_export_ut3 TYPE STANDARD TABLE OF zexport_ut3. 176 | 177 | exp_cont_import_ut1 = VALUE #( 178 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) 179 | ( client = sy-mandt primary_key = 'CCC' content = 'imp' ) ). 180 | exp_cont_import_ut2 = VALUE #( 181 | ( client = sy-mandt primary_key = 'AAA' content = '130' ) 182 | ( client = sy-mandt primary_key = 'CCC' content = '30' ) ). 183 | exp_cont_export_ut3 = VALUE #( 184 | ( client = sy-mandt primary_key = 'ADA' content = '9999' ) ). 185 | 186 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 187 | 188 | cut->add_content_all_tables( ). 189 | COMMIT WORK AND WAIT. 190 | 191 | SELECT * FROM zimport_ut1 INTO TABLE @act_cont_import_ut1 192 | ORDER BY PRIMARY KEY. 193 | SELECT * FROM zimport_ut2 INTO TABLE @act_cont_import_ut2 194 | ORDER BY PRIMARY KEY. 195 | SELECT * FROM zexport_ut3 INTO TABLE @act_cont_export_ut3. 196 | 197 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut1 198 | act = act_cont_import_ut1 199 | msg = 'content imported from table zimport_ut1' ). 200 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut2 201 | act = act_cont_import_ut2 202 | msg = 'content imported from table zimport_ut2' ). 203 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_export_ut3 204 | act = act_cont_export_ut3 205 | msg = 'content imported from table zexport_ut3 (no fake-table)' ). 206 | 207 | ENDMETHOD. 208 | 209 | METHOD activate_osql_replacement. 210 | DATA: act_cont_export_ut1 TYPE STANDARD TABLE OF zexport_ut1, 211 | exp_cont_export_ut1 TYPE STANDARD TABLE OF zexport_ut1. 212 | 213 | exp_cont_export_ut1 = VALUE #( 214 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) ). 215 | 216 | " when 217 | DELETE FROM zexport_ut1. 218 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 219 | cut->replace_content_completly( ). 220 | cut->activate_osql_replacement( ). 221 | COMMIT WORK AND WAIT. 222 | 223 | " then 224 | SELECT * FROM zexport_ut1 INTO TABLE @act_cont_export_ut1. 225 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_export_ut1 226 | act = act_cont_export_ut1 ). 227 | 228 | " teardown 229 | CALL METHOD ('CL_OSQL_REPLACE')=>activate_replacement. 230 | 231 | ENDMETHOD. 232 | 233 | METHOD get_changed_source_tables. 234 | DATA: exp_indicies TYPE zimport_bundle=>index_table, 235 | export_ut2 TYPE zexport_ut2. 236 | 237 | " given 238 | ##LITERAL 239 | export_ut2 = VALUE #( primary_key = 'BBB' content = '130' ). 240 | INSERT zexport_ut2 FROM @export_ut2. 241 | COMMIT WORK AND WAIT. 242 | 243 | " when 244 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 245 | cut->get_changed_source_tables( 246 | IMPORTING indicies = DATA(act_indicies) ). 247 | 248 | " then 249 | APPEND: 2 TO exp_indicies, 3 TO exp_indicies. 250 | cl_abap_unit_assert=>assert_equals( exp = exp_indicies 251 | act = act_indicies ). 252 | 253 | ENDMETHOD. 254 | 255 | METHOD get_exported_content. 256 | DATA: act_content TYPE REF TO data, 257 | exp_content TYPE STANDARD TABLE OF zexport_ut1. 258 | FIELD-SYMBOLS: LIKE exp_content. 259 | 260 | exp_content = VALUE #( 261 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) ). 262 | 263 | " when 264 | CREATE DATA act_content LIKE exp_content. 265 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 266 | cut->get_exported_content_for_table( EXPORTING source_table = 'ZEXPORT_UT1' 267 | IMPORTING content = act_content ). 268 | 269 | " then 270 | ASSIGN act_content->* TO . 271 | cl_abap_unit_assert=>assert_equals( exp = exp_content 272 | act = ). 273 | 274 | ENDMETHOD. 275 | 276 | METHOD reexport. 277 | DATA: prior_content_ut1 TYPE REF TO data, 278 | dev_package TYPE devclass. 279 | 280 | SELECT SINGLE devclass FROM tadir INTO @dev_package 281 | WHERE pgmid = 'R3TR' AND object = 'CLAS' AND obj_name = 'ZIMPORT_BUNDLE_FROM_CLUSTER'. 282 | 283 | DATA(exporter) = NEW zexport_bundle_in_cluster( testcase_id = testcase_id 284 | dev_package = dev_package title = 'Unit-Test ABAP DB preparator' 285 | force_overwrite = abap_true ). 286 | DATA(importer) = NEW zimport_bundle_from_cluster( testcase_id = testcase_id ). 287 | 288 | importer->get_exported_content_for_table( EXPORTING source_table = 'ZEXPORT_UT1' 289 | IMPORTING content = prior_content_ut1 ). 290 | exporter->add_prior_content( _table = VALUE #( 291 | source_table = 'ZEXPORT_UT1' fake_table = 'ZIMPORT_UT1' ) 292 | content = prior_content_ut1 ). 293 | exporter->add_table_to_bundle( _table = VALUE #( 294 | source_table = 'ZEXPORT_UT2' fake_table = 'ZIMPORT_UT2' ) ). 295 | exporter->add_table_to_bundle( _table = VALUE #( 296 | source_table = 'ZEXPORT_UT3' ) ). 297 | 298 | exporter->export( ). 299 | 300 | ENDMETHOD. 301 | 302 | METHOD reexport_subset. 303 | DATA: act_content_ut1 TYPE REF TO data, 304 | exp_content_ut1 TYPE STANDARD TABLE OF zexport_ut1. 305 | FIELD-SYMBOLS: LIKE exp_content_ut1. 306 | 307 | exp_content_ut1 = VALUE #( 308 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) ). 309 | 310 | " when 311 | reexport( ). 312 | COMMIT WORK AND WAIT. 313 | 314 | " then 315 | DATA(importer) = NEW zimport_bundle_from_cluster( testcase_id = testcase_id ). 316 | importer->get_exported_content_for_table( EXPORTING source_table = 'ZEXPORT_UT1' 317 | IMPORTING content = act_content_ut1 ). 318 | ASSIGN act_content_ut1->* TO . 319 | 320 | cl_abap_unit_assert=>assert_equals( exp = exp_content_ut1 321 | act = ). 322 | 323 | ENDMETHOD. 324 | 325 | ENDCLASS. 326 | 327 | CLASS test_for_all_entries DEFINITION FOR TESTING 328 | DURATION SHORT RISK LEVEL HARMLESS. 329 | 330 | PRIVATE SECTION. 331 | 332 | METHODS setup 333 | RAISING 334 | cx_static_check. 335 | 336 | METHODS setup_mime 337 | RAISING 338 | cx_static_check. 339 | 340 | METHODS setup_tables. 341 | 342 | METHODS export 343 | RAISING 344 | cx_static_check. 345 | 346 | METHODS setup_import_tables. 347 | 348 | METHODS import_and_replace FOR TESTING 349 | RAISING 350 | cx_static_check. 351 | 352 | METHODS import_and_add FOR TESTING 353 | RAISING 354 | cx_static_check. 355 | 356 | METHODS import_and_replace_all FOR TESTING 357 | RAISING 358 | cx_static_check. 359 | 360 | ENDCLASS. 361 | 362 | CLASS test_for_all_entries IMPLEMENTATION. 363 | 364 | METHOD setup. 365 | 366 | setup_mime( ). 367 | setup_tables( ). 368 | export( ). 369 | setup_import_tables( ). 370 | COMMIT WORK AND WAIT. 371 | 372 | ENDMETHOD. 373 | 374 | METHOD setup_mime. 375 | DATA: mime_key TYPE wwwdatatab. 376 | 377 | mime_key-relid = 'MI'. 378 | mime_key-objid = testcase_id. 379 | 380 | CALL FUNCTION 'WWWDATA_DELETE' 381 | EXPORTING 382 | key = mime_key 383 | EXCEPTIONS 384 | OTHERS = 0. 385 | 386 | ENDMETHOD. 387 | 388 | METHOD setup_tables. 389 | DATA: export_ut1 TYPE STANDARD TABLE OF zexport_ut1, 390 | export_ut2 TYPE STANDARD TABLE OF zexport_ut2, 391 | export_ut3 TYPE zexport_ut3. 392 | 393 | " setup the tables in this package 394 | DELETE FROM: zexport_ut1, zexport_ut2, zexport_ut3. 395 | 396 | export_ut1 = VALUE #( 397 | ( primary_key = 'AAA' content = 'char' ) 398 | ( primary_key = 'AAB' content = 'num' ) 399 | ( primary_key = 'AAC' content = 'int' ) ). 400 | ##LITERAL 401 | export_ut2 = VALUE #( 402 | ( primary_key = 'AAA' content = '130' ) 403 | ( primary_key = 'AAB' content = '140' ) 404 | ( primary_key = 'DDD' content = '150' ) ). 405 | export_ut3 = VALUE #( primary_key = 'ADA' content = '9999' ). 406 | 407 | INSERT zexport_ut1 FROM TABLE @export_ut1. 408 | INSERT zexport_ut2 FROM TABLE @export_ut2. 409 | INSERT zexport_ut3 FROM @export_ut3. 410 | 411 | ENDMETHOD. 412 | 413 | METHOD export. 414 | DATA: dev_package TYPE devclass. 415 | 416 | SELECT SINGLE devclass FROM tadir INTO dev_package 417 | WHERE pgmid = 'R3TR' AND object = 'CLAS' AND obj_name = 'ZIMPORT_BUNDLE_FROM_CLUSTER'. 418 | 419 | DATA(exporter) = NEW zexport_bundle_in_cluster( testcase_id = testcase_id 420 | dev_package = dev_package title = 'Unit-Test ABAP DB preparator' ). 421 | 422 | exporter->add_table_to_bundle( _table = VALUE #( 423 | source_table = 'ZEXPORT_UT1' fake_table = 'ZIMPORT_UT1' ) ). 424 | exporter->add_table_to_bundle( _table = VALUE #( 425 | source_table = 'ZEXPORT_UT2' fake_table = 'ZIMPORT_UT2' 426 | where_restriction = 'FOR ALL ENTRIES IN xzimport_ut1 WHERE primary_key = xzimport_ut1-primary_key' ) ). 427 | exporter->add_table_to_bundle( _table = VALUE #( 428 | source_table = 'ZEXPORT_UT3' ) ). 429 | 430 | exporter->export( ). 431 | 432 | ENDMETHOD. 433 | 434 | METHOD setup_import_tables. 435 | DATA: import_ut2 TYPE zimport_ut2. 436 | 437 | DELETE FROM: zimport_ut1, zimport_ut2, zexport_ut3. 438 | ##LITERAL 439 | import_ut2 = VALUE #( primary_key = 'CCC' content = '400' ). 440 | INSERT zimport_ut2 FROM @import_ut2. 441 | 442 | ENDMETHOD. 443 | 444 | METHOD import_and_replace. 445 | DATA: act_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 446 | exp_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 447 | act_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 448 | exp_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2. 449 | 450 | exp_cont_import_ut1 = VALUE #( 451 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) 452 | ( client = sy-mandt primary_key = 'AAB' content = 'num' ) 453 | ( client = sy-mandt primary_key = 'AAC' content = 'int' ) ). 454 | exp_cont_import_ut2 = VALUE #( 455 | ( client = sy-mandt primary_key = 'AAA' content = '130' ) 456 | ( client = sy-mandt primary_key = 'AAB' content = '140' ) 457 | ( client = sy-mandt primary_key = 'CCC' content = '400' ) ). 458 | 459 | " when 460 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 461 | cut->replace_content_all_tables( ). 462 | SELECT * FROM zimport_ut1 INTO TABLE @act_cont_import_ut1 463 | ORDER BY PRIMARY KEY. 464 | SELECT * FROM zimport_ut2 INTO TABLE @act_cont_import_ut2 465 | ORDER BY PRIMARY KEY. 466 | 467 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut1 468 | act = act_cont_import_ut1 ). 469 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut2 470 | act = act_cont_import_ut2 ). 471 | 472 | ENDMETHOD. 473 | 474 | METHOD import_and_add. 475 | DATA: act_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 476 | exp_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 477 | act_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 478 | exp_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2. 479 | 480 | exp_cont_import_ut1 = VALUE #( 481 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) 482 | ( client = sy-mandt primary_key = 'AAB' content = 'num' ) 483 | ( client = sy-mandt primary_key = 'AAC' content = 'int' ) ). 484 | exp_cont_import_ut2 = VALUE #( 485 | ( client = sy-mandt primary_key = 'AAA' content = '130' ) 486 | ( client = sy-mandt primary_key = 'AAB' content = '140' ) 487 | ( client = sy-mandt primary_key = 'CCC' content = '400' ) ). 488 | 489 | " when 490 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 491 | cut->add_content_all_tables( ). 492 | SELECT * FROM zimport_ut1 INTO TABLE @act_cont_import_ut1 493 | ORDER BY PRIMARY KEY. 494 | SELECT * FROM zimport_ut2 INTO TABLE @act_cont_import_ut2 495 | ORDER BY PRIMARY KEY. 496 | 497 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut1 498 | act = act_cont_import_ut1 ). 499 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut2 500 | act = act_cont_import_ut2 ). 501 | 502 | ENDMETHOD. 503 | 504 | METHOD import_and_replace_all. 505 | DATA: act_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 506 | exp_cont_import_ut1 TYPE STANDARD TABLE OF zimport_ut1, 507 | act_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2, 508 | exp_cont_import_ut2 TYPE STANDARD TABLE OF zimport_ut2. 509 | 510 | exp_cont_import_ut1 = VALUE #( 511 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) 512 | ( client = sy-mandt primary_key = 'AAB' content = 'num' ) 513 | ( client = sy-mandt primary_key = 'AAC' content = 'int' ) ). 514 | exp_cont_import_ut2 = VALUE #( 515 | ( client = sy-mandt primary_key = 'AAA' content = '130' ) 516 | ( client = sy-mandt primary_key = 'AAB' content = '140' ) ). 517 | 518 | " when 519 | DATA(cut) = NEW zimport_bundle_from_cluster( testcase_id ). 520 | cut->replace_content_completly( ). 521 | SELECT * FROM zimport_ut1 INTO TABLE @act_cont_import_ut1 522 | ORDER BY PRIMARY KEY. 523 | SELECT * FROM zimport_ut2 INTO TABLE @act_cont_import_ut2 524 | ORDER BY PRIMARY KEY. 525 | 526 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut1 527 | act = act_cont_import_ut1 ). 528 | cl_abap_unit_assert=>assert_equals( exp = exp_cont_import_ut2 529 | act = act_cont_import_ut2 ). 530 | 531 | ENDMETHOD. 532 | 533 | ENDCLASS. 534 | -------------------------------------------------------------------------------- /src/zimport_bundle_from_cluster.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZIMPORT_BUNDLE_FROM_CLUSTER 7 | E 8 | Import Bundle from a MIME-Object-Cluster 9 | 1 10 | X 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zimport_bundle_from_tdc.clas.abap: -------------------------------------------------------------------------------- 1 | CLASS zimport_bundle_from_tdc DEFINITION 2 | PUBLIC 3 | INHERITING FROM zimport_bundle 4 | FINAL 5 | CREATE PUBLIC . 6 | 7 | PUBLIC SECTION. 8 | 9 | METHODS constructor 10 | IMPORTING 11 | !tdc TYPE etobj_name 12 | !tdc_version TYPE etobj_ver OPTIONAL 13 | !variant TYPE etvar_id 14 | RAISING 15 | zcx_import_error . 16 | 17 | METHODS add_content_all_tables 18 | REDEFINITION . 19 | METHODS replace_content_all_tables 20 | REDEFINITION . 21 | METHODS replace_content_completly 22 | REDEFINITION . 23 | PROTECTED SECTION. 24 | 25 | METHODS get_exported_content 26 | REDEFINITION . 27 | PRIVATE SECTION. 28 | 29 | DATA tdc TYPE REF TO cl_apl_ecatt_tdc_api . 30 | DATA variant TYPE etvar_id . 31 | 32 | METHODS get_tdc_parameter_name 33 | IMPORTING 34 | table TYPE zexport_table_list 35 | RETURNING VALUE(result) TYPE etp_name. 36 | ENDCLASS. 37 | 38 | 39 | 40 | CLASS ZIMPORT_BUNDLE_FROM_TDC IMPLEMENTATION. 41 | 42 | 43 | METHOD add_content_all_tables. 44 | DATA: content TYPE REF TO data. 45 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 46 | 47 | permission_is_granted( ). 48 | TRY. 49 | 50 | LOOP AT table_list REFERENCE INTO DATA(table). 51 | 52 | IF zexport_utils=>is_view( table->*-source_table ) = abap_true. 53 | CONTINUE. 54 | ENDIF. 55 | 56 | CREATE DATA content TYPE STANDARD TABLE OF (table->*-fake_table). 57 | ASSIGN content->* TO . 58 | tdc->get_value( EXPORTING i_param_name = get_tdc_parameter_name( table->* ) 59 | i_variant_name = variant 60 | CHANGING e_param_value = ). 61 | 62 | " If no content is exported in other than the "ECATTDEFAULT"-variant, 63 | " contains the parameter value of the "ECATTDEFAULT"-variant. 64 | " Therefore INSERT-Statement is only executed, when the exported content is not initial. 65 | IF table->*-is_initial = abap_false. 66 | MODIFY (table->*-fake_table) FROM TABLE . 67 | ENDIF. 68 | 69 | ENDLOOP. 70 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 71 | zcx_import_error=>wrap_ecatt_failure( ecatt_failure ). 72 | ENDTRY. 73 | 74 | ENDMETHOD. 75 | 76 | 77 | METHOD constructor. 78 | 79 | super->constructor( ). 80 | 81 | TRY. 82 | me->tdc = cl_apl_ecatt_tdc_api=>get_instance( i_testdatacontainer = tdc 83 | i_testdatacontainer_version = tdc_version ). 84 | me->variant = variant. 85 | 86 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 87 | zcx_import_error=>wrap_ecatt_failure( ecatt_failure ). 88 | ENDTRY. 89 | 90 | TRY. 91 | " The tables are read from the parameter "ZEXPORT_TABLE_LIST". 92 | " The parameter-list is not used, because different variants can use 93 | " different parameters and some parameters may be not database-tables. 94 | me->tdc->get_value( EXPORTING i_param_name = 'ZEXPORT_TABLE_LIST' i_variant_name = variant 95 | CHANGING e_param_value = table_list ). 96 | ##NO_HANDLER 97 | CATCH cx_ecatt_tdc_access. 98 | ENDTRY. 99 | 100 | 101 | ENDMETHOD. 102 | 103 | 104 | METHOD get_exported_content. 105 | 106 | TRY. 107 | tdc->get_value_ref( EXPORTING i_param_name = get_tdc_parameter_name( table_conjunction ) 108 | i_variant_name = variant 109 | CHANGING e_param_ref = content ). 110 | 111 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 112 | zcx_import_error=>wrap_ecatt_failure( ecatt_failure ). 113 | ENDTRY. 114 | 115 | ENDMETHOD. 116 | 117 | 118 | METHOD get_tdc_parameter_name. 119 | 120 | " backwards-compatibility: until commit 121 | " 550688c21ca119ffaecd4e1c11a68ab504fc53ee 122 | " tdc-parameter-name was the fake-table name. 123 | " So 'table-tdc_parameter_name' can be empty. 124 | IF table-tdc_parameter_name IS INITIAL. 125 | result = table-fake_table. 126 | ELSE. 127 | result = table-tdc_parameter_name. 128 | ENDIF. 129 | 130 | ENDMETHOD. 131 | 132 | 133 | METHOD replace_content_all_tables. 134 | DATA: content TYPE REF TO data. 135 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 136 | 137 | permission_is_granted( ). 138 | TRY. 139 | 140 | LOOP AT table_list REFERENCE INTO DATA(table). 141 | 142 | IF zexport_utils=>is_view( table->*-source_table ) = abap_true. 143 | CONTINUE. 144 | ENDIF. 145 | 146 | CREATE DATA content TYPE STANDARD TABLE OF (table->*-fake_table). 147 | ASSIGN content->* TO . 148 | tdc->get_value( EXPORTING i_param_name = get_tdc_parameter_name( table->* ) 149 | i_variant_name = variant 150 | CHANGING e_param_value = ). 151 | 152 | delete( table->* ). 153 | " If no content is exported in other than the "ECATTDEFAULT"-variant, 154 | " contains the parameter value of the "ECATTDEFAULT"-variant. 155 | " Therefore INSERT-Statement is only executed, when the exported content is not initial. 156 | IF table->*-is_initial = abap_false. 157 | MODIFY (table->*-fake_table) FROM TABLE . 158 | ENDIF. 159 | 160 | ENDLOOP. 161 | 162 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 163 | zcx_import_error=>wrap_ecatt_failure( ecatt_failure ). 164 | ENDTRY. 165 | 166 | ENDMETHOD. 167 | 168 | 169 | METHOD replace_content_completly. 170 | DATA: content TYPE REF TO data. 171 | FIELD-SYMBOLS: TYPE STANDARD TABLE. 172 | 173 | permission_is_granted( ). 174 | TRY. 175 | 176 | LOOP AT table_list REFERENCE INTO DATA(table). 177 | 178 | IF zexport_utils=>is_view( table->*-source_table ) = abap_true 179 | OR table->*-fake_table NOT IN get_whitelist( ). 180 | CONTINUE. 181 | ENDIF. 182 | 183 | CREATE DATA content TYPE STANDARD TABLE OF (table->*-fake_table). 184 | ASSIGN content->* TO . 185 | tdc->get_value( EXPORTING i_param_name = get_tdc_parameter_name( table->* ) 186 | i_variant_name = variant 187 | CHANGING e_param_value = ). 188 | 189 | DELETE FROM (table->*-fake_table). 190 | " If no content is exported in other than the "ECATTDEFAULT"-variant, 191 | " contains the parameter value of the "ECATTDEFAULT"-variant. 192 | " Therefore INSERT-Statement is only executed, when the exported content is not initial. 193 | IF table->*-is_initial = abap_false. 194 | INSERT (table->*-fake_table) FROM TABLE . 195 | ENDIF. 196 | 197 | ENDLOOP. 198 | 199 | CATCH cx_ecatt_tdc_access INTO DATA(ecatt_failure). 200 | zcx_import_error=>wrap_ecatt_failure( ecatt_failure ). 201 | ENDTRY. 202 | 203 | ENDMETHOD. 204 | ENDCLASS. 205 | -------------------------------------------------------------------------------- /src/zimport_bundle_from_tdc.clas.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZIMPORT_BUNDLE_FROM_TDC 7 | E 8 | Import the bundle from Test Data Container 9 | 1 10 | X 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/zimport_tvarvc.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZIMPORT_TVARVC 7 | E 8 | TRANSP 9 | X 10 | Table of Variant Variables (Client-Specific) 11 | X 12 | G 13 | 3 14 | 15 | 16 | ZIMPORT_TVARVC 17 | A 18 | 0 19 | APPL0 20 | X 21 | X 22 | 23 | 24 | 25 | MANDT 26 | X 27 | SYMANDT 28 | 0 29 | X 30 | E 31 | 32 | 33 | NAME 34 | X 35 | RVARI_VNAM 36 | 0 37 | X 38 | E 39 | 40 | 41 | TYPE 42 | X 43 | RSSCR_KIND 44 | 0 45 | X 46 | E 47 | 48 | 49 | NUMB 50 | X 51 | TVARV_NUMB 52 | 0 53 | X 54 | E 55 | 56 | 57 | SIGN 58 | TVARV_SIGN 59 | 0 60 | E 61 | 62 | 63 | OPTI 64 | TVARV_OPTI 65 | 0 66 | E 67 | 68 | 69 | LOW 70 | RVARI_VAL_255 71 | 0 72 | E 73 | 74 | 75 | HIGH 76 | RVARI_VAL_255 77 | 0 78 | E 79 | 80 | 81 | CLIE_INDEP 82 | SYCHAR01 83 | 0 84 | E 85 | 86 | 87 | 88 | D 89 | F 90 | 91 | 92 | 93 | D 94 | Tabelle der Variantenvariablen (mandantenabhängig) 95 | 96 | 97 | F 98 | Table des variables variantes (dépendant du mandant) 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/zimport_ut1.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZIMPORT_UT1 7 | E 8 | TRANSP 9 | X 10 | Table with content to export 11 | X 12 | A 13 | 3 14 | 15 | 16 | ZIMPORT_UT1 17 | A 18 | 0 19 | APPL0 20 | X 21 | X 22 | 23 | 24 | 25 | CLIENT 26 | X 27 | MANDT 28 | 0 29 | X 30 | E 31 | 32 | 33 | PRIMARY_KEY 34 | X 35 | 0 36 | C 37 | 000006 38 | X 39 | CHAR 40 | 000003 41 | CHAR 42 | primary key 43 | 44 | 45 | CONTENT 46 | 0 47 | C 48 | 000020 49 | CHAR 50 | 000010 51 | CHAR 52 | content 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/zimport_ut2.tabl.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZIMPORT_UT2 7 | E 8 | TRANSP 9 | X 10 | Table with content to export 11 | X 12 | A 13 | 3 14 | 15 | 16 | ZIMPORT_UT2 17 | A 18 | 0 19 | APPL0 20 | X 21 | X 22 | 23 | 24 | 25 | CLIENT 26 | X 27 | MANDT 28 | 0 29 | X 30 | E 31 | 32 | 33 | PRIMARY_KEY 34 | X 35 | 0 36 | C 37 | 000006 38 | X 39 | CHAR 40 | 000003 41 | CHAR 42 | primary_key 43 | 44 | 45 | CONTENT 46 | 0 47 | P 48 | 000003 49 | DEC 50 | 000004 51 | DEC 52 | a number 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/ztest_export_gui.prog.abap: -------------------------------------------------------------------------------- 1 | *&---------------------------------------------------------------------* 2 | *& Include ZTEST_EXPORT_GUI 3 | *&---------------------------------------------------------------------* 4 | CLASS test_export_tdc DEFINITION FOR TESTING DURATION SHORT 5 | RISK LEVEL DANGEROUS. 6 | 7 | PRIVATE SECTION. 8 | CONSTANTS: tdc_name TYPE etobj_name VALUE 'ZEXPORT_UNIT_TEST'. 9 | TYPES: _export_ut1 TYPE STANDARD TABLE OF zexport_ut1, 10 | _export_ut2 TYPE STANDARD TABLE OF zexport_ut2. 11 | 12 | METHODS setup 13 | RAISING cx_static_check. 14 | 15 | METHODS setup_tables. 16 | 17 | METHODS change_tables. 18 | 19 | METHODS export_in_new_tdc FOR TESTING 20 | RAISING cx_static_check. 21 | 22 | METHODS reexport_in_existing_tdc FOR TESTING 23 | RAISING cx_static_check. 24 | 25 | METHODS tdc_params_equals 26 | IMPORTING 27 | exp_table_list TYPE _table_list 28 | exp_export_ut1 TYPE _export_ut1 29 | exp_export_ut2 TYPE _export_ut2 30 | RAISING 31 | cx_static_check. 32 | 33 | ENDCLASS. 34 | 35 | CLASS test_export_tdc IMPLEMENTATION. 36 | 37 | METHOD setup. 38 | 39 | TRY. 40 | cl_apl_ecatt_tdc_api=>delete_tdc( i_name = tdc_name ). 41 | ##NO_HANDLER 42 | CATCH cx_ecatt_tdc_access. 43 | ENDTRY. 44 | header_tdc = VALUE #( name = tdc_name version = 1 variant = 'ECATTDEFAULT' 45 | package = '$TMP' overwrite = abap_true ). 46 | bundle = VALUE #( 47 | ( name = 'ZEXPORT_UT1' overwrite = overwrite_option-yes ) 48 | ( name = 'ZEXPORT_UT2' overwrite = overwrite_option-yes ) ). 49 | setup_tables( ). 50 | PERFORM export_screen_0002. 51 | 52 | ENDMETHOD. 53 | 54 | METHOD setup_tables. 55 | DATA: export_ut1 TYPE zexport_ut1, 56 | export_ut2 TYPE zexport_ut2. 57 | 58 | DELETE FROM: zexport_ut1, zexport_ut2. 59 | 60 | export_ut1 = VALUE #( primary_key = 'AAA' content = 'char' ). 61 | ##LITERAL 62 | export_ut2 = VALUE #( primary_key = 'AAA' content = '130' ). 63 | 64 | INSERT zexport_ut1 FROM export_ut1. 65 | INSERT zexport_ut2 FROM export_ut2. 66 | 67 | ENDMETHOD. 68 | 69 | METHOD change_tables. 70 | DATA: export_ut1 TYPE zexport_ut1, 71 | export_ut2 TYPE zexport_ut2. 72 | 73 | DELETE FROM: zexport_ut1, zexport_ut2. 74 | 75 | export_ut1 = VALUE #( primary_key = 'TTT' content = 'char' ). 76 | ##LITERAL 77 | export_ut2 = VALUE #( primary_key = 'TTT' content = '130' ). 78 | 79 | INSERT zexport_ut1 FROM export_ut1. 80 | INSERT zexport_ut2 FROM export_ut2. 81 | 82 | ENDMETHOD. 83 | 84 | METHOD export_in_new_tdc. 85 | DATA: exp_table_list TYPE _table_list, 86 | exp_export_ut1 TYPE _export_ut1, 87 | exp_export_ut2 TYPE _export_ut2. 88 | 89 | exp_table_list = VALUE #( 90 | ( source_table = 'ZEXPORT_UT1' fake_table = 'ZEXPORT_UT1' 91 | tdc_parameter_name = 'ZEXPORT_UT1' ) 92 | ( source_table = 'ZEXPORT_UT2' fake_table = 'ZEXPORT_UT2' 93 | tdc_parameter_name = 'ZEXPORT_UT2' ) ). 94 | exp_export_ut1 = VALUE #( 95 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) ). 96 | exp_export_ut2 = VALUE #( 97 | ( client = sy-mandt primary_key = 'AAA' content = 130 ) ). 98 | 99 | " when: is done in setup 100 | " then 101 | tdc_params_equals( exp_table_list = exp_table_list 102 | exp_export_ut1 = exp_export_ut1 exp_export_ut2 = exp_export_ut2 ). 103 | 104 | ENDMETHOD. 105 | 106 | METHOD reexport_in_existing_tdc. 107 | DATA: exp_table_list TYPE _table_list, 108 | exp_export_ut1 TYPE _export_ut1, 109 | exp_export_ut2 TYPE _export_ut2. 110 | 111 | exp_table_list = VALUE #( 112 | ( source_table = 'ZEXPORT_UT1' fake_table = 'ZEXPORT_UT1' 113 | tdc_parameter_name = 'ZEXPORT_UT1' ) 114 | ( source_table = 'ZEXPORT_UT2' fake_table = 'ZEXPORT_UT2' 115 | tdc_parameter_name = 'ZEXPORT_UT2' ) ). 116 | exp_export_ut1 = VALUE #( 117 | ( client = sy-mandt primary_key = 'TTT' content = 'char' ) ). 118 | exp_export_ut2 = VALUE #( 119 | ( client = sy-mandt primary_key = 'AAA' content = 130 ) ). 120 | 121 | " given 122 | change_tables( ). 123 | bundle = VALUE #( 124 | ( name = 'ZEXPORT_UT1' overwrite = overwrite_option-yes ) 125 | ( name = 'ZEXPORT_UT2' overwrite = overwrite_option-no ) ). 126 | 127 | " when 128 | PERFORM export_screen_0002. 129 | 130 | " then 131 | tdc_params_equals( exp_table_list = exp_table_list 132 | exp_export_ut1 = exp_export_ut1 exp_export_ut2 = exp_export_ut2 ). 133 | 134 | ENDMETHOD. 135 | 136 | METHOD tdc_params_equals. 137 | DATA: act_table_list TYPE _table_list, 138 | act_export_ut1 TYPE _export_ut1, 139 | act_export_ut2 TYPE _export_ut2. 140 | 141 | DATA(tdc) = cl_apl_ecatt_tdc_api=>get_instance( 142 | i_testdatacontainer = tdc_name 143 | i_testdatacontainer_version = 1 ). 144 | 145 | tdc->get_value( EXPORTING i_param_name = 'ZEXPORT_TABLE_LIST' 146 | i_variant_name = 'ECATTDEFAULT' 147 | CHANGING e_param_value = act_table_list ). 148 | cl_abap_unit_assert=>assert_equals( exp = exp_table_list 149 | act = act_table_list ). 150 | 151 | tdc->get_value( EXPORTING i_param_name = 'ZEXPORT_UT1' 152 | i_variant_name = 'ECATTDEFAULT' 153 | CHANGING e_param_value = act_export_ut1 ). 154 | cl_abap_unit_assert=>assert_equals( exp = exp_export_ut1 155 | act = act_export_ut1 ). 156 | 157 | tdc->get_value( EXPORTING i_param_name = 'ZEXPORT_UT2' 158 | i_variant_name = 'ECATTDEFAULT' 159 | CHANGING e_param_value = act_export_ut2 ). 160 | cl_abap_unit_assert=>assert_equals( exp = exp_export_ut2 161 | act = act_export_ut2 ). 162 | 163 | ENDMETHOD. 164 | 165 | ENDCLASS. 166 | 167 | CLASS test_export_cluster DEFINITION FOR TESTING DURATION SHORT 168 | RISK LEVEL HARMLESS. 169 | 170 | PRIVATE SECTION. 171 | CONSTANTS: testcase_id TYPE w3objid VALUE 'ZBUNDLE_UNIT_TEST'. 172 | TYPES: _export_ut1 TYPE STANDARD TABLE OF zexport_ut1, 173 | _export_ut2 TYPE STANDARD TABLE OF zexport_ut2. 174 | 175 | METHODS setup 176 | RAISING cx_static_check. 177 | 178 | METHODS setup_mime. 179 | 180 | METHODS setup_tables. 181 | 182 | METHODS change_tables. 183 | 184 | METHODS export_in_new_cluster FOR TESTING 185 | RAISING cx_static_check. 186 | 187 | METHODS reexport_in_cluster FOR TESTING 188 | RAISING cx_static_check. 189 | 190 | METHODS cluster_equals 191 | IMPORTING 192 | exp_table_list TYPE _table_list 193 | exp_export_ut1 TYPE _export_ut1 194 | exp_export_ut2 TYPE _export_ut2 195 | RAISING 196 | cx_static_check. 197 | 198 | ENDCLASS. 199 | 200 | CLASS test_export_cluster IMPLEMENTATION. 201 | 202 | METHOD setup. 203 | 204 | setup_mime( ). 205 | header_cluster = VALUE #( testcase_id = testcase_id package = '$TMP' 206 | overwrite = abap_true ). 207 | bundle = VALUE #( 208 | ( name = 'ZEXPORT_UT1' overwrite = overwrite_option-yes ) 209 | ( name = 'ZEXPORT_UT2' overwrite = overwrite_option-yes ) ). 210 | setup_tables( ). 211 | PERFORM export_screen_0001. 212 | 213 | ENDMETHOD. 214 | 215 | METHOD setup_mime. 216 | DATA: mime_key TYPE wwwdatatab. 217 | 218 | mime_key-relid = 'MI'. 219 | mime_key-objid = testcase_id. 220 | 221 | CALL FUNCTION 'WWWDATA_DELETE' 222 | EXPORTING 223 | key = mime_key 224 | EXCEPTIONS 225 | OTHERS = 0. 226 | 227 | ENDMETHOD. 228 | 229 | METHOD setup_tables. 230 | DATA: export_ut1 TYPE zexport_ut1, 231 | export_ut2 TYPE zexport_ut2. 232 | 233 | DELETE FROM: zexport_ut1, zexport_ut2. 234 | 235 | export_ut1 = VALUE #( primary_key = 'AAA' content = 'char' ). 236 | ##LITERAL 237 | export_ut2 = VALUE #( primary_key = 'AAA' content = '130' ). 238 | 239 | INSERT zexport_ut1 FROM export_ut1. 240 | INSERT zexport_ut2 FROM export_ut2. 241 | 242 | ENDMETHOD. 243 | 244 | METHOD change_tables. 245 | DATA: export_ut1 TYPE zexport_ut1, 246 | export_ut2 TYPE zexport_ut2. 247 | 248 | DELETE FROM: zexport_ut1, zexport_ut2. 249 | 250 | export_ut1 = VALUE #( primary_key = 'TTT' content = 'char' ). 251 | ##LITERAL 252 | export_ut2 = VALUE #( primary_key = 'TTT' content = '130' ). 253 | 254 | INSERT zexport_ut1 FROM export_ut1. 255 | INSERT zexport_ut2 FROM export_ut2. 256 | 257 | ENDMETHOD. 258 | 259 | METHOD export_in_new_cluster. 260 | DATA: exp_table_list TYPE _table_list, 261 | exp_export_ut1 TYPE _export_ut1, 262 | exp_export_ut2 TYPE _export_ut2. 263 | 264 | exp_table_list = VALUE #( 265 | ( source_table = 'ZEXPORT_UT1' fake_table = 'ZEXPORT_UT1' ) 266 | ( source_table = 'ZEXPORT_UT2' fake_table = 'ZEXPORT_UT2' ) ). 267 | exp_export_ut1 = VALUE #( 268 | ( client = sy-mandt primary_key = 'AAA' content = 'char' ) ). 269 | exp_export_ut2 = VALUE #( 270 | ( client = sy-mandt primary_key = 'AAA' content = 130 ) ). 271 | 272 | " when: is done in setup 273 | " then 274 | cluster_equals( exp_table_list = exp_table_list exp_export_ut1 = exp_export_ut1 275 | exp_export_ut2 = exp_export_ut2 ). 276 | 277 | ENDMETHOD. 278 | 279 | METHOD reexport_in_cluster. 280 | DATA: exp_table_list TYPE _table_list, 281 | exp_export_ut1 TYPE _export_ut1, 282 | exp_export_ut2 TYPE _export_ut2. 283 | 284 | exp_table_list = VALUE #( 285 | ( source_table = 'ZEXPORT_UT1' fake_table = 'ZEXPORT_UT1' ) 286 | ( source_table = 'ZEXPORT_UT2' fake_table = 'ZEXPORT_UT2' ) ). 287 | exp_export_ut1 = VALUE #( 288 | ( client = sy-mandt primary_key = 'TTT' content = 'char' ) ). 289 | exp_export_ut2 = VALUE #( 290 | ( client = sy-mandt primary_key = 'AAA' content = 130 ) ). 291 | 292 | " given 293 | change_tables( ). 294 | bundle = VALUE #( 295 | ( name = 'ZEXPORT_UT1' overwrite = overwrite_option-yes ) 296 | ( name = 'ZEXPORT_UT2' overwrite = overwrite_option-no ) ). 297 | 298 | " when 299 | PERFORM export_screen_0001. 300 | 301 | " then 302 | cluster_equals( exp_table_list = exp_table_list exp_export_ut1 = exp_export_ut1 303 | exp_export_ut2 = exp_export_ut2 ). 304 | 305 | ENDMETHOD. 306 | 307 | METHOD cluster_equals. 308 | DATA: act_export_ut1 TYPE REF TO data, 309 | act_export_ut2 TYPE REF TO data. 310 | FIELD-SYMBOLS: TYPE _export_ut1, 311 | TYPE _export_ut2. 312 | 313 | DATA(importer) = NEW zimport_bundle_from_cluster( testcase_id = testcase_id ). 314 | 315 | CREATE DATA: act_export_ut1 TYPE _export_ut1, 316 | act_export_ut2 TYPE _export_ut2. 317 | 318 | cl_abap_unit_assert=>assert_equals( exp = exp_table_list 319 | act = importer->table_list ). 320 | 321 | importer->get_exported_content_for_table( EXPORTING source_table = 'ZEXPORT_UT1' 322 | IMPORTING content = act_export_ut1 ). 323 | ASSIGN act_export_ut1->* TO . 324 | cl_abap_unit_assert=>assert_equals( exp = exp_export_ut1 325 | act = ). 326 | 327 | importer->get_exported_content_for_table( EXPORTING source_table = 'ZEXPORT_UT2' 328 | IMPORTING content = act_export_ut2 ). 329 | ASSIGN act_export_ut2->* TO . 330 | cl_abap_unit_assert=>assert_equals( exp = exp_export_ut2 331 | act = ). 332 | 333 | ENDMETHOD. 334 | 335 | ENDCLASS. 336 | 337 | CLASS test_tdc_bundle_reader DEFINITION FOR TESTING 338 | DURATION SHORT RISK LEVEL HARMLESS. 339 | 340 | PRIVATE SECTION. 341 | 342 | METHODS setup 343 | RAISING 344 | cx_static_check. 345 | 346 | METHODS setup_tables 347 | RAISING 348 | cx_static_check. 349 | 350 | METHODS change_tables 351 | RAISING 352 | cx_static_check. 353 | 354 | METHODS merge_bundle_tdc_success FOR TESTING 355 | RAISING 356 | cx_static_check. 357 | 358 | METHODS merge_bundle_tdc_conflict FOR TESTING 359 | RAISING 360 | cx_static_check. 361 | 362 | ENDCLASS. 363 | 364 | CLASS test_tdc_bundle_reader IMPLEMENTATION. 365 | 366 | METHOD setup. 367 | 368 | setup_tables( ). 369 | 370 | bundle = VALUE #( 371 | ( name = 'ZEXPORT_UT1' fake = 'ZIMPORT_UT1' overwrite = overwrite_option-yes ) 372 | ( name = 'ZEXPORT_UT2' fake = 'ZIMPORT_UT2' overwrite = overwrite_option-yes ) ). 373 | header_tdc = VALUE #( name = 'ZEXPORT_UNIT_TEST' version = 1 variant = 'TDC_MERGE' 374 | package = '$TMP' overwrite = abap_true ). 375 | PERFORM export_screen_0002. 376 | change_tables( ). 377 | 378 | ENDMETHOD. 379 | 380 | METHOD setup_tables. 381 | DATA: export_ut1 TYPE zexport_ut1, 382 | export_ut2 TYPE zexport_ut2. 383 | 384 | DELETE FROM: zexport_ut1, zexport_ut2. 385 | 386 | export_ut1 = VALUE #( primary_key = 'AAA' content = 'char' ). 387 | ##LITERAL 388 | export_ut2 = VALUE #( primary_key = 'AAA' content = '130' ). 389 | 390 | INSERT zexport_ut1 FROM export_ut1. 391 | INSERT zexport_ut2 FROM export_ut2. 392 | 393 | ENDMETHOD. 394 | 395 | METHOD change_tables. 396 | 397 | DATA(export_ut1) = VALUE zexport_ut1( primary_key = 'BBB' content = 'char' ). 398 | INSERT zexport_ut1 FROM export_ut1. 399 | 400 | ENDMETHOD. 401 | 402 | METHOD merge_bundle_tdc_success. 403 | DATA: exp_bundle LIKE bundle. 404 | 405 | bundle = VALUE #( 406 | ( name = 'ZEXPORT_UT3' ) 407 | ( name = 'ZEXPORT_UT2' fake = 'ZIMPORT_UT2' ) ). 408 | PERFORM merge_bundle_tdc. 409 | 410 | exp_bundle = VALUE #( 411 | ( name = 'ZEXPORT_UT3' overwrite = overwrite_option-yes ) 412 | ( name = 'ZEXPORT_UT2' fake = 'ZIMPORT_UT2' overwrite = overwrite_option-no ) 413 | ( name = 'ZEXPORT_UT1' fake = 'ZIMPORT_UT1' overwrite = overwrite_option-no 414 | changed = abap_true ) ). 415 | cl_abap_unit_assert=>assert_equals( act = bundle 416 | exp = exp_bundle ). 417 | 418 | ENDMETHOD. 419 | 420 | METHOD merge_bundle_tdc_conflict. 421 | 422 | bundle = VALUE #( 423 | ( name = 'ZEXPORT_UT3' ) 424 | ( name = 'ZEXPORT_UT2' fake = 'ZIMPORT_UT2' where_restriction = '1' ) ). 425 | TRY. 426 | PERFORM merge_bundle_tdc. 427 | cl_abap_unit_assert=>fail( ). 428 | ##NO_HANDLER 429 | CATCH zcx_import_merge_conflict. 430 | ENDTRY. 431 | 432 | ENDMETHOD. 433 | 434 | ENDCLASS. 435 | -------------------------------------------------------------------------------- /src/ztest_export_gui.prog.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ZTEST_EXPORT_GUI 7 | I 8 | E 9 | X 10 | 11 | 12 | 13 | R 14 | Unit-Test Export function 15 | 25 16 | 17 | 18 | 19 | 20 | 21 | --------------------------------------------------------------------------------