{"id":7399,"date":"2025-08-05T14:59:20","date_gmt":"2025-08-05T09:29:20","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?post_type=question&#038;p=7399"},"modified":"2025-08-05T16:17:48","modified_gmt":"2025-08-05T10:47:48","slug":"how-to-use-case-statement-in-cds-view","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=how-to-use-case-statement-in-cds-view","title":{"rendered":"How to use Case Statement in CDS View"},"content":{"rendered":"\r\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\r\n<p>Here in this example, We are going to create CDS view with Case statement, here new field &#8220;DocText&#8221; will be added and value will be calculated based on below. <\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>    case vbtyp\r\n        when 'A' then 'Inquiry'\r\n        when 'B' then 'Quotation'\r\n        when 'C' then  \r\n            case netwr\r\n                 when 0 then 'Not Paid Order'\r\n                else 'Paid Order'\r\n            end    \r\n        else 'Unknown'\r\n    end as DocText, <\/code><\/pre>\r\n<\/div><\/div>\r\n\r\n\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-plain\"><code>@AbapCatalog.viewEnhancementCategory: [#NONE]\r\n@AccessControl.authorizationCheck: #NOT_REQUIRED\r\n@EndUserText.label: 'CDS - Session Variables'\r\n@Metadata.ignorePropagatedAnnotations: true\r\n@ObjectModel.usageType:{\r\n    serviceQuality: #X,\r\n    sizeCategory: #S,\r\n    dataClass: #MIXED\r\n}\r\ndefine view entity ZCDS_CASE \r\nas select from vbak\r\n{\r\n    key vbeln as SaleDoc,\r\n    vbtyp as DocCatCode,\r\n    vkorg as SalesOrg,\r\n    vtweg as DistChannel,\r\n    spart as Div,\r\n    kunnr as CustNo,\r\n    \r\n    case vbtyp\r\n        when 'A' then 'Inquiry'\r\n        when 'B' then 'Quotation'\r\n        when 'C' then  \r\n            case netwr\r\n                 when 0 then 'Not Paid Order'\r\n                else 'Paid Order'\r\n            end    \r\n        else 'Unknown'\r\n    end as DocText,     \r\n}\r\n<\/code><\/pre>\r\n<\/div>\r\n\r\n\r\n\r\n<p>&nbsp;<\/p>\r\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[173],"question_tags":[294,295,209,299,296,297],"class_list":["post-7399","question","type-question","status-publish","hentry","question-category-cdsviews","question_tags-abap-cds-view","question_tags-case-statement-in-cds-view","question_tags-cds-view","question_tags-nested-case-statement-in-cds-view","question_tags-using-case-in-cds","question_tags-when-and-then-in-cds"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7399","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7399"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7399"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7399"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}