Need to create CDS view for a domain with fixed values, try this code generator.
Introduction
Fixed values and respective language-dependent text for the domain are generically stored in tables DD07L and DD07T. These values for a given domain needs to put together into CDS views before it can be reused. Let’s first see how SAP does this and then later in this blog there is a code generator tool which will let you generate CDS code automatically for any domain.
This Incomplete Sales Document app displays a dropdown list for Sales Document Category.
These values and respective texts are coming from CDS views I_SDDocumentCategory and I_SDDocumentCategoryText . CDS View I_SDDocumentCategory get values from table DD07L for domain VBTYPL. Language dependent texts are retrieved in the CDS view I_SDDocumentCategoryText. Both these CDS are related to each other using associations.
Code generator below let you specify required inputs, for example, domain name, length, CDS View name etc and generate code for two CDS Views. One for value and other for text CDS view which you can copy-paste in Eclipse.
CDS Code Generator
I have prefilled the inputs for domain KOART – Account type, test the tool by pressing the button “Generate CDS View Code”.
To use for you own domain, I recommend you input values only in inputs highlighted in yellow.
Domain Name | |
Domain Length |
Value CDS View | Text CDS View | ||
---|---|---|---|
View name | View Name | ||
ABAP View Name | ABAP View Name | ||
End User Text | End User Text | ||
Field Name | Projection Name | ||
Text Field Name |
CDS View with Values and Association to Text View
press Generate CDS View Code button
CDS View with Text and Association to Value View
press Generate CDS View Code button
Example
I have this CDS view and Fiori Elements List Report where Account type values are being displayed and I like to bring in texts for these values.
@AbapCatalog.sqlViewName: 'ZITAXCODE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Tax code grouping'
@ObjectModel.usageType: {
serviceQuality: #A,
sizeCategory: #S,
dataClass: #ORGANIZATIONAL }
@OData.publish: true
define view ZI_BPTaxCode
as select from t007c
association [1..*] to C_BPTaxCodeTextValueHelp as _Text
on $projection.TaxGroupingCode = _Text.TaxGroupingCode and
$projection.AccountType = _Text.AccountType
{
@UI.facet: [ { id:'idGeneralInformation' ,
type: #COLLECTION ,
label: 'General Information' ,
position: 10 } ,
{ type: #IDENTIFICATION_REFERENCE ,
label : 'General Information',
parentId: 'idGeneralInformation' ,
id: 'idIdentification' } ]
@UI.selectionField: [{ position: 10 }]
@UI.lineItem: [{ position: 10 }]
@ObjectModel.text.association: '_Text'
key taxgr as TaxGroupingCode,
@UI.selectionField: [{ position: 20 }]
@UI.lineItem: [{ position: 10 }]
key koart as AccountType,
@UI.selectionField: [{ position: 30 }]
@UI.lineItem: [{ position: 30 }]
wrnex as ExceptionPossible,
_Text
}
After using the CDS Code Generator tool in this blog I have created two CDS views ZI_AccounType and ZI_AccountTypeText (copy-paste the generated code). Do not activate them individually as they have a cyclic dependency.
Click on activate all button, select both CDS view to be activated at once.
Using view ZI_AccountType
@AbapCatalog.sqlViewName: 'ZITAXCODE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Tax code grouping'
@ObjectModel.usageType: {serviceQuality: #A, sizeCategory: #S, dataClass: #ORGANIZATIONAL}
@OData.publish: true
define view ZI_BPTaxCode
as select from t007c
association [1..*] to C_BPTaxCodeTextValueHelp as _Text
on $projection.TaxGroupingCode = _Text.TaxGroupingCode and
$projection.AccountType = _Text.AccountType
association [1..1] to ZI_AccountType as _AccountType
on $projection.AccountType = _AccountType.AccountType
{
@UI.facet: [ { id:'idGeneralInformation' ,
type: #COLLECTION ,
label: 'General Information' ,
position: 10 } ,
{ type: #IDENTIFICATION_REFERENCE ,
label : 'General Information',
parentId: 'idGeneralInformation' ,
id: 'idIdentification' } ]
@UI.selectionField: [{ position: 10 }]
@UI.lineItem: [{ position: 10 }]
@ObjectModel.text.association: '_Text'
key taxgr as TaxGroupingCode,
@UI.selectionField: [{ position: 20 }]
@UI.lineItem: [{ position: 10 }]
@ObjectModel.foreignKey.association: '_AccountType'
key koart as AccountType,
@UI.selectionField: [{ position: 30 }]
@UI.lineItem: [{ position: 30 }]
wrnex as ExceptionPossible,
_Text,
_AccountType
}
This brings in text for account type and also value help on filter.
I’m kind of surprised there isn’t an automated way to do this in CDS since you’d think it was so routinely need. Since there isn’t, this page is a great tool. Thanks so much for providing it.
Cool feature!
Note: The generator produces two errors in the generated files:
1. In the first file it uses “AS AccountType” for the domain field.
2. In the second file it refers to a path “_AccountType”.
After correcting these two it worked for me.
Regards
Michaela
thank you , will fix that soon
Can you also so your VH file? Thanks in advance