Challenge:
Create a ABAP V4 – API with Parent and Child Relationship using existing Standard CDS Views Provided by SAP without Writing an ABAP Code
Note: Some of the code are not pasted so that readers try it with hands on.
Business Scenario: Get All Business Partner Details – Supplier – Customer – Expanding from Parent Child
Steps Followed :
Step 1:
We need to 2 Views , one acts as a parent ( Header ) and another as a child ( Item level)
In this case Business Partner is a header Info and Supplier is a Item detail ( Child ) . We will also see in the next steps that by using standard CDS Views the associations of the child view ( Supplier ) and associations of parent view ( Business Partner Header ) , parent child relationship will automatically pop up in the V4 API without any ABAP code involved.
Create two simple Custom CDS Views ZI_BP_PARENT and ZI_BP_SUPPLIER in your Package as shown below :
ZI_BP_PARENT
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'View for Consuming View as a oDATA V4'
define root view entity ZI_BP_PARENT as select from I_BusinessPartner as BPartner
composition [1..1] of ZI_BP_SUPPLIER as _Supplier
association [0..1] to bp001 as _BusinessPartner on $projection.BusinessPartner = _BusinessPartner.partner
association [0..1] to I_CustomerToBusinessPartner as _CustomerToBusinessPartner on BPartner.BusinessPartnerUUID = _CustomerToBusinessPartner.BusinessPartnerUUID
association [0..1] to I_SupplierToBusinessPartner as _SupplierToBusinessPartner on BPartner.BusinessPartnerUUID = _SupplierToBusinessPartner.BusinessPartnerUUID
association [0..1] to A_Customer as _Customer on $projection.customer = _Customer.Customer
//association [0..1] to A_Supplier as _Supplier on $projection.supplier = _Supplier.Supplier
association [0..*] to A_BusinessPartnerAddress as _BusinessPartnerAddress on $projection.BusinessPartner = _BusinessPartnerAddress.BusinessPartner
association [0..*] to A_BusinessPartnerRole as _BusinessPartnerRole on $projection.BusinessPartner = _BusinessPartnerRole.BusinessPartner
association [0..*] to A_BusinessPartnerTaxNumber as _BusinessPartnerTax on $projection.BusinessPartner = _BusinessPartnerTax.BusinessPartner
association [0..*] to A_BusinessPartnerBank as _BusinessPartnerBank on $projection.BusinessPartner = _BusinessPartnerBank.BusinessPartner
association [0..*] to A_BuPaIdentification as _BuPaIdentification on $projection.BusinessPartner = _BuPaIdentification.BusinessPartner
association [0..*] to A_BusinessPartnerContact as _BusinessPartnerContact on $projection.BusinessPartner = _BusinessPartnerContact.BusinessPartnerCompany
association [0..*] to A_BuPaIndustry as _BuPaIndustry on $projection.BusinessPartner = _BuPaIndustry.BusinessPartner
{
key BusinessPartner,
@ObjectModel.readOnly: true
_CustomerToBusinessPartner.Customer,
@ObjectModel.readOnly: true
_SupplierToBusinessPartner.Supplier,
AcademicTitle,
AuthorizationGroup,
BusinessPartnerCategory,
@ObjectModel.readOnly: true
BusinessPartnerFullName,
BusinessPartnerGrouping,
@ObjectModel.readOnly: true
BusinessPartnerName,
@ObjectModel.readOnly: true
BusinessPartnerUUID,
CorrespondenceLanguage,
@ObjectModel.readOnly: true
CreatedByUser,
@ObjectModel.readOnly: true
CreationDate,
@ObjectModel.readOnly: true
CreationTime,
FirstName,
FormOfAddress,
Industry,
InternationalLocationNumber1,
InternationalLocationNumber2,
// @API.element.releaseState:#DEPRECATED
IsFemale,
// @API.element.releaseState:#DEPRECATED
IsMale,
IsNaturalPerson,
// @API.element.releaseState:#DEPRECATED
IsSexUnknown,
// @API.element.successor
GenderCodeName,
Language,
@ObjectModel.readOnly: true
LastChangeDate,
@ObjectModel.readOnly: true
LastChangeTime,
@ObjectModel.readOnly: true
LastChangedByUser,
LastName,
LegalForm,
OrganizationBPName1,
OrganizationBPName2,
OrganizationBPName3,
OrganizationBPName4,
OrganizationFoundationDate,
OrganizationLiquidationDate,
SearchTerm1,
SearchTerm2,
AdditionalLastName,
BirthDate,
BusinessPartnerBirthDateStatus,
BusinessPartnerBirthplaceName,
BusinessPartnerIsBlocked,
BusinessPartnerType,
@ObjectModel.readOnly: true
ETag,
GroupBusinessPartnerName1,
GroupBusinessPartnerName2,
@ObjectModel.readOnly: true
IndependentAddressID,
InternationalLocationNumber3,
MiddleName,
NameCountry,
NameFormat,
PersonFullName,
@ObjectModel.readOnly: true
PersonNumber,
IsMarkedForArchiving,
@Consumption.hidden: true
IsBusinessPurposeCompleted,
BusinessPartnerIDByExtSystem,
_BusinessPartner.vbund as TradingPartner,
_Customer,
_Supplier,
_BusinessPartnerAddress,
_BusinessPartnerRole,
_BusinessPartnerTax,
_BusinessPartnerBank,
_BuPaIdentification,
_BusinessPartnerContact,
_BuPaIndustry
}
ZI_BP_SUPPLIER
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View for Supplier View'
define view entity ZI_BP_SUPPLIER as select from I_Supplier as BpSupplier
association to parent ZI_BP_PARENT as _BpParent on $projection.Supplier = _BpParent.BusinessPartner
association [0..*] to A_SupplierCompany as _SupplierCompany on $projection.Supplier = _SupplierCompany.Supplier
association [0..*] to A_SupplierPurchasingOrg as _SupplierPurchasingOrg on $projection.Supplier = _SupplierPurchasingOrg.Supplier
association [0..*] to A_SupplierText as _SupplierText on $projection.Supplier = _SupplierText.Supplier {
key Supplier,
AlternativePayeeAccountNumber,
AuthorizationGroup,
@ObjectModel.readOnly: true
CreatedByUser,
@ObjectModel.readOnly: true
CreationDate,
Customer,
PaymentIsBlockedForSupplier,
PostingIsBlocked,
PurchasingIsBlocked,
SupplierAccountGroup,
@ObjectModel.readOnly: true
SupplierFullName,
@ObjectModel.readOnly: true
SupplierName,
VATRegistration,
BirthDate,
@ObjectModel.readOnly: true
ConcatenatedInternationalLocNo,
DeletionIndicator,
FiscalAddress,
@ObjectModel.readOnly: true
Industry,
InternationalLocationNumber1,
InternationalLocationNumber2,
InternationalLocationNumber3,
IsNaturalPerson,
ResponsibleType,
SuplrQltyInProcmtCertfnValidTo,
SuplrQualityManagementSystem,
SupplierCorporateGroup,
SupplierProcurementBlock,
@ObjectModel.readOnly: true
TaxNumber1,
@ObjectModel.readOnly: true
TaxNumber2,
@ObjectModel.readOnly: true
TaxNumber3,
@ObjectModel.readOnly: true
TaxNumber4,
@ObjectModel.readOnly: true
TaxNumber5,
TaxNumberResponsible,
TaxNumberType,
SuplrProofOfDelivRlvtCode,
@Consumption.hidden: true
IsBusinessPurposeCompleted,
BR_TaxIsSplit,
/*associations*/
_SupplierCompany,
_SupplierPurchasingOrg,
_SupplierText,
_BpParent
}
Step 2 : Activate both the views together – Obligatory Step
Step 3 : Create two corresponding Projection Views for the CDS Views for previously created Views
Projection View : ZC_BP_SUPPLIER on ZI_BP_PARENT
and ZC_BP_SUPPLIER on ZI_BP_SUPPLIER
@EndUserText.label: 'Projection View for ZI_BP_PARENT'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Search.searchable: true
@Metadata.allowExtensions: true
define root view entity ZC_BP_PARENT
as projection on ZI_BP_PARENT as BPartner {
key BusinessPartner,
@Search.defaultSearchElement: true
Customer,
@Search.defaultSearchElement: true
Supplier,
@Search.defaultSearchElement: true
AcademicTitle,
AuthorizationGroup,
BusinessPartnerCategory,
BusinessPartnerFullName,
BusinessPartnerGrouping,
BusinessPartnerName,
BusinessPartnerUUID,
CorrespondenceLanguage,
CreatedByUser,
CreationDate,
CreationTime,
FirstName,
FormOfAddress,
Industry,
InternationalLocationNumber1,
InternationalLocationNumber2,
IsFemale,
IsMale,
IsNaturalPerson,
IsSexUnknown,
GenderCodeName,
Language,
LastChangeDate,
LastChangeTime,
LastChangedByUser,
LastName,
LegalForm,
OrganizationBPName1,
OrganizationBPName2,
OrganizationBPName3,
OrganizationBPName4,
OrganizationFoundationDate,
OrganizationLiquidationDate,
SearchTerm1,
SearchTerm2,
AdditionalLastName,
BirthDate,
BusinessPartnerBirthDateStatus,
BusinessPartnerBirthplaceName,
BusinessPartnerIsBlocked,
BusinessPartnerType,
ETag,
GroupBusinessPartnerName1,
GroupBusinessPartnerName2,
IndependentAddressID,
InternationalLocationNumber3,
MiddleName,
NameCountry,
NameFormat,
PersonFullName,
PersonNumber,
IsMarkedForArchiving,
IsBusinessPurposeCompleted,
BusinessPartnerIDByExtSystem,
TradingPartner,
/* Associations */
_BuPaIdentification,
_BuPaIndustry,
_BusinessPartnerAddress,
_BusinessPartnerBank,
_BusinessPartnerContact,
_BusinessPartnerRole,
_BusinessPartnerTax,
_Customer,
_Supplier : redirected to composition child ZC_BP_SUPPLIER
}
@EndUserText.label: 'Projection View for ZI_BP_SUPPLIER'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Search.searchable: true
@Metadata.allowExtensions: true
define view entity ZC_BP_SUPPLIER
as projection on ZI_BP_SUPPLIER {
key Supplier,
@Search.defaultSearchElement: true
AlternativePayeeAccountNumber,
@Search.defaultSearchElement: true
AuthorizationGroup,
CreatedByUser,
CreationDate,
Customer,
PaymentIsBlockedForSupplier,
PostingIsBlocked,
PurchasingIsBlocked,
@Search.defaultSearchElement: true
SupplierAccountGroup,
@Search.defaultSearchElement: true
SupplierFullName,
SupplierName,
VATRegistration,
BirthDate,
ConcatenatedInternationalLocNo,
DeletionIndicator,
FiscalAddress,
Industry,
InternationalLocationNumber1,
InternationalLocationNumber2,
InternationalLocationNumber3,
IsNaturalPerson,
ResponsibleType,
SuplrQltyInProcmtCertfnValidTo,
SuplrQualityManagementSystem,
SupplierCorporateGroup,
SupplierProcurementBlock,
TaxNumber1,
TaxNumber2,
TaxNumber3,
TaxNumber4,
TaxNumber5,
TaxNumberResponsible,
TaxNumberType,
SuplrProofOfDelivRlvtCode,
IsBusinessPurposeCompleted,
BR_TaxIsSplit,
/* Associations */
_BpParent : redirected to parent ZC_BP_PARENT,
_SupplierCompany,
_SupplierPurchasingOrg,
_SupplierText
}
Step 4 : Create a Business Services
No comments:
Post a Comment