{"id":7409,"date":"2025-08-06T00:20:30","date_gmt":"2025-08-05T18:50:30","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=types-of-association-in-cds"},"modified":"2025-08-06T00:20:56","modified_gmt":"2025-08-05T18:50:56","slug":"types-of-association-in-cds","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=types-of-association-in-cds","title":{"rendered":"Types of Association in CDS ?"},"content":{"rendered":"<h5><strong>Exposed Associations<\/strong><\/h5>\n<p>An <strong>exposed association<\/strong> is one that is <strong>defined<\/strong> in a CDS view and is <strong>made available (exposed)<\/strong> to consumers of the view \u2014 such as other CDS views, analytical queries, or OData services. You define the association using the association [&#8230;] to clause and then expose it using an alias (typically starting with an underscore _) in the SELECT list.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code><!--StartFragment --><span><span>define\u00a0<\/span>view\u00a0ZI_SalesOrder\u00a0<span>as\u00a0<\/span><span>select\u00a0<\/span><span>from\u00a0<\/span>ZSalesOrderHeader\r\n{\r\n\u00a0\u00a0\u00a0\u00a0<span>key\u00a0<\/span>SalesOrderID<span>,<\/span>\r\n\u00a0\u00a0\u00a0\u00a0CustomerID<span>,<\/span>\r\n\r\n\u00a0\u00a0\u00a0\u00a0association\u00a0[0<span>.<\/span><span>.<\/span>1]\u00a0<span>to\u00a0<\/span>ZI_Customer\u00a0<span>as\u00a0<\/span>_Customer\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span>on\u00a0<\/span>_Customer<span>.<\/span>CustomerID\u00a0<span>=\u00a0<\/span>ZSalesOrderHeader<span>.<\/span>CustomerID\r\n\r\n\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Exposing\u00a0the\u00a0association\r\n\u00a0\u00a0\u00a0\u00a0_Customer\r\n}<\/span> <\/code><\/pre>\n<p><strong>Key Points:<\/strong><\/p>\n<ul>\n<li>You can reuse exposed associations in other views.<\/li>\n<li>Useful in modular CDS design.<\/li>\n<li>Can be traversed via path expressions (e.g., _Customer.Name).<\/li>\n<\/ul>\n<h5><strong>Ad-hoc Associations<\/strong><\/h5>\n<p>Ad-hoc associations are associations that are used inline (on-the-fly) via path expressions, without needing to expose the association explicitly in the SELECT list. If an association (like _Customer) is already defined in a view (exposed or implicit), you can use it ad-hoc in the SELECT or WHERE clause without re-exposing it.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code><!--StartFragment --><span><span>define\u00a0<\/span>view\u00a0ZI_SalesOrder\u00a0<span>as\u00a0<\/span><span>select\u00a0<\/span><span>from\u00a0<\/span>ZSalesOrderHeader\r\n{\r\n\u00a0\u00a0\u00a0\u00a0<span>key\u00a0<\/span>SalesOrderID<span>,<\/span>\r\n\u00a0\u00a0\u00a0\u00a0_Customer<span>.<\/span>Name\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Ad<span>-<\/span>hoc\u00a0usage\u00a0<span>of\u00a0<\/span>the\u00a0association\r\n}\r\n<\/span> <\/code><\/pre>\n<p>Key Points:<\/p>\n<ul>\n<li>No need to expose <code>_Customer<\/code> again in the select list.<\/li>\n<li>You&#8217;re just traversing the association to access fields of the target entity.<\/li>\n<li>Makes CDS views more compact and readable.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[173],"question_tags":[178,306,199,208,177],"class_list":["post-7409","question","type-question","status-publish","hentry","question-category-cdsviews","question_tags-abap","question_tags-association","question_tags-cds","question_tags-hana","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7409","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=7409"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7409"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7409"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}