{"id":7505,"date":"2025-08-19T16:26:45","date_gmt":"2025-08-19T10:56:45","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=managed-and-unmanaged-scenario-in-sap-rap"},"modified":"2025-08-19T16:26:45","modified_gmt":"2025-08-19T10:56:45","slug":"managed-and-unmanaged-scenario-in-sap-rap","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=managed-and-unmanaged-scenario-in-sap-rap","title":{"rendered":"Managed and unmanaged Scenario in SAP RAP"},"content":{"rendered":"<p><strong>RAP<\/strong> = Framework for building <strong>OData services<\/strong> on SAP BTP ABAP Environment (a.k.a. Steampunk) or on S\/4HANA.<\/p>\n<ul>\n<li>It allows you to expose business objects via REST APIs.<\/li>\n<li>A Business Object (BO) in RAP is defined via CDS Views + Behavior Definition + Behavior Implementation.<\/li>\n<\/ul>\n<p><strong>Managed vs. Unmanaged Scenarios<\/strong><\/p>\n<p>Managed Scenario<\/p>\n<p>In this case, <strong>RAP framework manages the persistence (DB operations)<\/strong> automatically.<\/p>\n<ul>\n<li>\n<p>You define your CDS entity and annotate it.<\/p>\n<\/li>\n<li>\n<p>RAP auto-generates all CRUD (Create, Read, Update, Delete) operations.<\/p>\n<\/li>\n<li>\n<p>Developer effort = <strong>Minimal<\/strong>, only add custom logic if needed.<\/p>\n<\/li>\n<li>\n<p>RAP uses the <strong>ETag handling, draft handling, transactional behavior<\/strong> automatically.<\/p>\n<\/li>\n<\/ul>\n<p><strong>When to use:<\/strong><\/p>\n<ul>\n<li>When your DB tables are new or not yet used elsewhere.<\/li>\n<li>For greenfield developments (new business objects).<\/li>\n<\/ul>\n<p><strong>Example (Managed Scenario)<\/strong><\/p>\n<p>CDS Entity:<\/p>\n<p>define root view entity Z_I_SalesOrder<br \/>as select from zsalesorder<br \/>{<br \/>key salesorder_id,<br \/>customer,<br \/>order_date,<br \/>status<br \/>}<\/p>\n<p><strong>Behavior Definition (Z_I_SalesOrder.behavior):<\/strong><\/p>\n<p>managed implementation in class zbp_salesorder unique;<\/p>\n<p>define behavior for Z_I_SalesOrder alias SalesOrder<br \/>persistent table zsalesorder<br \/>lock master<br \/>draft;<\/p>\n<p>create;<br \/>update;<br \/>delete;<br \/>endbehavior;<\/p>\n<p>RAP automatically knows how to insert\/update\/delete records in zsalesorder.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Unmanaged Scenario<\/strong><\/p>\n<p>In this case, developer controls persistence logic (you implement CRUD manually).<\/p>\n<ul>\n<li>RAP only provides the framework &amp; metadata.<\/li>\n<li>You must implement the behavior in an ABAP class (behavior handler).<\/li>\n<li>Useful when business logic is complex or DB table is legacy (used by other apps, needs validations, custom logic, or external system integration).<\/li>\n<\/ul>\n<p><strong>When to use:<\/strong><\/p>\n<ul>\n<li>When you already have existing tables and need custom save logic.<\/li>\n<li>For brownfield scenarios (extending existing business processes).<\/li>\n<\/ul>\n<p>Example (Unmanaged Scenario)<\/p>\n<p>CDS Entity<\/p>\n<p>define root view entity Z_I_SalesOrder<br \/>as select from zsalesorder_legacy<br \/>{<br \/>key salesorder_id,<br \/>customer,<br \/>order_date,<br \/>status<br \/>}<\/p>\n<p>&nbsp;<\/p>\n<p>Behavior Definition (Z_I_SalesOrder.behavior):<\/p>\n<p>unmanaged implementation in class zbp_salesorder unique;<\/p>\n<p>define behavior for Z_I_SalesOrder alias SalesOrder<br \/>lock master;<\/p>\n<p>create;<br \/>update;<br \/>delete;<br \/>endbehavior;<\/p>\n<p>&nbsp;<\/p>\n<p>Behavior Implementation (ABAP Class):<\/p>\n<p>&nbsp;<\/p>\n<p>CLASS zbp_salesorder DEFINITION PUBLIC FINAL CREATE PUBLIC.<br \/>PUBLIC SECTION.<br \/>INTERFACES if_abap_behavior_handler.<br \/>ENDCLASS.<\/p>\n<p>CLASS zbp_salesorder IMPLEMENTATION.<br \/>METHOD if_abap_behavior_handler~create.<br \/>&#8221; Custom logic for inserting into zsalesorder_legacy<br \/>ENDMETHOD.<\/p>\n<p>METHOD if_abap_behavior_handler~update.<br \/>&#8221; Custom logic for updating existing orders<br \/>ENDMETHOD.<\/p>\n<p>METHOD if_abap_behavior_handler~delete.<br \/>&#8221; Custom logic for deletion<br \/>ENDMETHOD.<br \/>ENDCLASS.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[175],"question_tags":[201,280,200,177],"class_list":["post-7505","question","type-question","status-publish","hentry","question-category-rap","question_tags-btp","question_tags-cloud","question_tags-rap","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7505"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7505"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7505"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}