{"id":13698801,"url":"https://github.com/bunysae/abap_db_preparator","last_synced_at":"2025-05-04T04:30:39.348Z","repository":{"id":38348585,"uuid":"236528855","full_name":"bunysae/abap_db_preparator","owner":"bunysae","description":"Avoid breaking tests with database preparation","archived":false,"fork":false,"pushed_at":"2024-06-17T08:33:13.000Z","size":450,"stargazers_count":17,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-13T03:34:50.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"ABAP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bunysae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://paypal.me/bunysae"]}},"created_at":"2020-01-27T15:56:16.000Z","updated_at":"2024-06-17T08:33:16.000Z","dependencies_parsed_at":"2024-08-02T19:12:02.513Z","dependency_job_id":null,"html_url":"https://github.com/bunysae/abap_db_preparator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bunysae%2Fabap_db_preparator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bunysae%2Fabap_db_preparator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bunysae%2Fabap_db_preparator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bunysae%2Fabap_db_preparator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bunysae","download_url":"https://codeload.github.com/bunysae/abap_db_preparator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252288912,"owners_count":21724323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T19:00:53.150Z","updated_at":"2025-05-04T04:30:38.691Z","avatar_url":"https://github.com/bunysae.png","language":"ABAP","funding_links":["https://paypal.me/bunysae"],"categories":["Categories"],"sub_categories":["🧪 Testing"],"readme":"# ABAP Database preparator #\nDatabase preparation for unit testing made simple. Store snapshots \n(bundles) of your database records for later use in unit tests.\n\n## No more breaking unit tests ##\nThe snapshots should avoid breaking unit tests after system copies and \nother database manipulations. This is achieved by providing a wrapper\nfor the OpenSQL replacement service in class `cl_osql_replace`, that \nmakes huge setups unnecessary.\n\n### Good bye huge setups ###\nReplace this huge setup method\n```ABAP\nMETHOD setup.\n  DATA: airlines TYPE STANDARD TABLE OF zcarr_fake,\n        replaced_tables TYPE cl_osql_replace=\u003ett_replacement.\n\n  DELETE FROM airlines.\n  airlines = VALUE #(\n    ( carrid = 'TG' carrname = 'Thai Airways' )\n  ).\n  INSERT zcarr_fake FROM airlines.\n\n  replaced_tables = VALUE #(\n    ( source = 'SCARR' target = 'ZCARR_FAKE' )\n  ).\n  cl_osql_replace=\u003eactivate_replacement( EXPORTING\n    replacement_table = replaced_tables ).\n\nENDMETHOD.\n```\nby just two method calls:\n```ABAP\nMETHOD setup.\n\n  DATA(db_preparator) = NEW zimport_bundle_from_tdc( tdc = 'ZAIRLINES'\n    tdc_version = 1 variant = 'ECATTDEFAULT' ).\n  db_preparator-\u003ereplace_content_completly( ).\n  db_preparator-\u003eactivate_osql_replacement( ).\n\nENDMETHOD.\n```\n\n## How it works ##\nBundles are stored either in an ECATT test data container\nor in a cluster (binary MIME-object in transaction smw0).\n\n### Export step ###\nIn the first step we can choose the database records,\nwhich should be exported into the bundle.\nThe OpenSQL replacement service needs a so called fake table with the same\nstructure as the original table. From this fake table the database records are\nread or they are written back in this fake table. In the export step we link\noriginal and fake table as shown in the picture below.\n![program zexport_gui](img/export_scarr.png)\n*Figure 1 Export step for table scarr in program `zexport_gui`*\nIn figure 1 the original table is named `scarr`, the fake table `zcarr_fake`.\n\nFake tables can be left empty, if the OpenSQL replacement service isn't\ninstalled.\n\n#### FOR ALL ENTRIES IN ####\nThe SQL where restriction can be prefixed a `FOR ALL ENTRIES IN`, which acts\nlike the corresponding ABAP-statement. As internal table any original table from the bundle can be given. Internal table name should be `'X' \u0026\u0026 table_name`. E.g.\nDatabase table | Fake database table | SQL where restriction\n-------------- | ------------------- | ---------------------\nSCARR | ZCARR_FAKE | carrid in ('TG', 'AA')\nSPFLI | ZSPFLI_FAKE | FOR ALL ENTRIES IN xzcarr_fake WHERE carrid = xzcarr_fake-carrid\n\n#### JOINS ####\nJoins can be expressed with subqueries. Let's consider the following join:\n```\nSELECT * FROM sflight AS f INNER JOIN spfli AS p\n  ON p~carrid = f~carrid AND p~connid = f~connid\n  WHERE p~airpto = 'BKK' AND f~fldate = '20210420'.\n```\nThe database records can be picked up in programm ```zexport_gui``` with subqueries:\nDatabase table | Fake database table | SQL where restriction\n-------------- | ------------------- | ---------------------\nSFLIGHT | ZCARR_SFLIGHT | fldate = '20210420' AND EXISTS ( SELECT * FROM spfli WHERE carrid = sflight~carrid AND connid = sflight~connid AND airpto = 'BKK' )\nSPFLI | ZCARR_SPFLI | FOR ALL ENTRIES IN xsflight WHERE carrid = xsflight-carrid AND connid = xsflight-connid\n\n### Import step ###\nIn the ABAP unit-testclass the database records exported in previous step\ncan be imported in the fake tables or in the original tables,\nif the corresponding fake table was left empty.\nThe API for the import step is located in class `zimport_bundle_from_cluster`\nfor clusters or in class `zimport_bundle_from_tdc` for\nECATT test data container.\n\nFor testing Rfc-Client- or Rfc-Serverprograms or programs,\nwhich interact through the [JSON Adapter for ABAP Function Modules](https://github.com/cesar-sap/abap_fm_json/)\na API is located in function-group `zimport_bundle`.\n\nA example can be found in the listing below.\n```ABAP\nCLASS test_airlines DEFINITION FOR TESTING DURATION SHORT\n  RISK LEVEL HARMLESS.\n  \n  PRIVATE SECTION.\n\n    \" activate replacement service\t  \n    METHODS setup.\n\n    METHODS thai_should_be_found FOR TESTING.\n\nENDCLASS.\n\nCLASS test_airlines IMPLEMENTATION.\n\n  METHOD setup.\n\n    DATA(db_preparator) = NEW zimport_bundle_from_tdc( tdc = 'ZAIRLINES'\n      tdc_version = 1 variant = 'ECATTDEFAULT' ).\n    db_preparator-\u003ereplace_content_completly( ).\n    db_preparator-\u003eactivate_osql_replacement( ).\n\n  ENDMETHOD.\n\n  METHOD thai_should_be_found.\n    DATA: exp_airlines TYPE STANDARD TABLE OF scarr.\n\n    exp_airlines = VALUE #( ( carrid = 'TG' carrname = 'Thai airways'\n                              currcode = 'THB' url = 'https://thaiairways.com' ) ).\n\n    SELECT * FROM scarr INTO TABLE @DATA(act_airlines).\n\n    cl_abap_unit_assert=\u003eassert_equals( exp = exp_airlines\n      act = act_airlines ).\n\n  ENDMETHOD.\n\nENDCLASS.\n```\n\n### Authorization ###\nThe APIs in class `zimport_bundle_from_cluster` or \nin class `zimport_bundle_from_tdc` can only be used in \ndevelopment systems, where \ndangerous ABAP unit-testclasses are enabled.\n\n### Whitelist-check ###\nContent of fake tables listed in the whitelist can be completely\noverriden. The whitelist is maintained in parameter\n`ZIMPORT_REPLACE_WHITELIST` (transaction `stvarv`, table `tvarvc`).\n\n## Terms ##\n\n* Bundle: a collection of database records, which are stored outside\n  of the database tables.\n* Cluster: a MIME-object in transaction `smw0`, which contains the bundle\n* TDC: abbreviation for ECATT test data container\n\n## Cloning this repository ##\nCloning can be done with [abapGit](https://github.com/larshp/abapgit).\nThe code is backwards compatible until release 7.40. The replacement services\nneed higher releases (SAP NetWeaver 7.51 or 7.52).\n\n## Further links ##\n[Blog entry on SAP community network](https://blogs.sap.com/?p=1049057)\n[Repository mirror](https://github.com/ABAP-prep/abap_db_preparator)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunysae%2Fabap_db_preparator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbunysae%2Fabap_db_preparator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunysae%2Fabap_db_preparator/lists"}