{"id":7938,"date":"2025-10-30T23:37:31","date_gmt":"2025-10-30T18:07:31","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=add-buttons-in-sap-rap-application"},"modified":"2025-10-30T23:37:31","modified_gmt":"2025-10-30T18:07:31","slug":"add-buttons-in-sap-rap-application","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=add-buttons-in-sap-rap-application","title":{"rendered":"Add buttons in sap rap application"},"content":{"rendered":"<p><strong>Step 1: Create the RAP Project<\/strong><\/p>\n<ol>\n<li>\n<p>In <strong>ABAP Development Tools (ADT)<\/strong>:<\/p>\n<ul>\n<li>\n<p>Go to <strong>File \u2192 New \u2192 ABAP Project<\/strong>.<\/p>\n<\/li>\n<li>\n<p>Connect to your system.<\/p>\n<\/li>\n<li>\n<p>Create a new <strong>ABAP Package<\/strong> (e.g., <code>Z_RAP_BUTTONS<\/code>).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Create the RAP artifacts:<\/p>\n<ul>\n<li>\n<p><strong>Business Object (BO)<\/strong>:<\/p>\n<ul>\n<li>\n<p>Right-click the package \u2192 New \u2192 Other ABAP Repository Object \u2192 Business Object \u2192 RAP Business Object.<\/p>\n<\/li>\n<li>\n<p>Example: <code>ZBO_SALESORDER<\/code>.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>Step 2: Define the Behavior (Behavior Definition)<\/strong><\/p>\n<ol>\n<li>\n<p>In your <strong>Behavior Definition<\/strong> (<code>.behavior<\/code>):<\/p>\n<\/li>\n<\/ol>\n<p>define behavior for ZI_SALESORDER<br \/>\npersistent table ZI_SALESORDER<br \/>\nlock master<br \/>\n{<br \/>\ncreate;<br \/>\nupdate;<br \/>\ndelete;<\/p>\n<p>\/\/ Add custom action button<br \/>\naction confirm order result [0..1];<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 3: Implement the Behavior Logic<\/strong><\/p>\n<ol>\n<li>\n<p>In <strong>Behavior Implementation<\/strong> (<code>.behavior.abap<\/code>):<\/p>\n<\/li>\n<\/ol>\n<p>implementation in class zbp_i_salesorder unique;<\/p>\n<p>method confirm_order.<br \/>\n&#8221; Your business logic goes here<br \/>\nloop at it_entity into data(ls_entity).<br \/>\nls_entity-status = &#8216;CONFIRMED&#8217;.<br \/>\nmodify table et_entity from ls_entity.<br \/>\nendloop.<br \/>\nendmethod.<\/p>\n<p>endimplementation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 4: Expose Action in Service Definition<\/strong><\/p>\n<ol>\n<li>\n<p>Open <strong>Service Definition<\/strong> (<code>.service<\/code>):<\/p>\n<\/li>\n<\/ol>\n<p>define service ZC_SALESORDER_SRV {<br \/>\nexpose ZI_SALESORDER;<br \/>\n\/\/ Optionally expose action explicitly<br \/>\naction confirm order;<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 5: Register &amp; Test Service<\/strong><\/p>\n<ol>\n<li>\n<p>Go to <strong>\/IWFND\/MAINT_SERVICE<\/strong> \u2192 register your RAP service.<\/p>\n<\/li>\n<li>\n<p>Test via <strong>SAP Gateway Client<\/strong> (<code>\/IWFND\/GW_CLIENT<\/code>) to see the metadata:<\/p>\n<ul>\n<li>\n<p>You should see your <code>confirm order<\/code> action exposed.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>Step 6: Fiori\/UI Integration<\/strong><\/p>\n<ul>\n<li>\n<p>If you use <strong>Fiori Elements<\/strong> (List Report \/ Object Page):<\/p>\n<ol>\n<li>\n<p>The <code>action confirm order<\/code> will automatically appear as a button in the <strong>Object Page<\/strong> or <strong>List Report<\/strong>.<\/p>\n<\/li>\n<li>\n<p>No extra UI5 code is required if you use standard Fiori Elements.<\/p>\n<\/li>\n<li>\n<p>If you want <strong>custom UI5<\/strong>, you can bind a button like this:<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>&lt;Button<br \/>\ntext=&#8221;Confirm Order&#8221;<br \/>\npress=&#8221;.onConfirmOrder&#8221;<br \/>\n\/&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>And in your controller:<\/p>\n<p>onConfirmOrder: function(oEvent) {<br \/>\nvar oModel = this.getView().getModel();<br \/>\nvar sPath = oEvent.getSource().getBindingContext().getPath();<br \/>\noModel.callFunction(&#8220;\/ConfirmOrder&#8221;, {<br \/>\nmethod: &#8220;POST&#8221;,<br \/>\nurlParameters: {<br \/>\nSalesOrderID: oModel.getProperty(sPath + &#8220;\/SalesOrderID&#8221;)<br \/>\n},<br \/>\nsuccess: function() {<br \/>\nMessageToast.show(&#8220;Order Confirmed!&#8221;);<br \/>\n},<br \/>\nerror: function() {<br \/>\nMessageToast.show(&#8220;Error!&#8221;);<br \/>\n}<br \/>\n});<br \/>\n}<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[175],"question_tags":[201,449,280,200,177],"class_list":["post-7938","question","type-question","status-publish","hentry","question-category-rap","question_tags-btp","question_tags-button","question_tags-cloud","question_tags-rap","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7938","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=7938"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7938"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7938"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}