Reputation: 5554
I'm new to CDS and I'm trying to make my first view.
The thing is that when I try the following code I receive the error:
Association _Purchase_Order: BPOSB and EBELP do not have a compatible type.
Is it possible to make a cast on any field of the association to make it work?
Thanks in advance
@AbapCatalog.sqlViewName: 'YMM_VFRET'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Merchandise distribution view'
define view YMM_FRET
as select from fret as Collective_Purchase
association [1..*] to ekpo as _Stock_Transfer_Order
on $projection.blnra = _Stock_Transfer_Order.ebeln and $projection.bposa = _Stock_Transfer_Order.ebelp
association [1] to ekpo as _Purchase_Order
on $projection.blnrb = _Purchase_Order.ebeln and $projection.bposb = _Purchase_Order.ebelp
{
key Collective_Purchase.blnrb,
key Collective_Purchase.bposb,
key Collective_Purchase.blnra,
key Collective_Purchase.bposa,
_Stock_Transfer_Order,
_Purchase_Order
}
Upvotes: 0
Views: 1406
Reputation: 5554
I finally did it.
I made two CDS views.
The first one had all the FRET fields but used RIGHT and CAST to convert BPOSB and BPOSA to NUMC type.
DEFINE VIEW YMM_FRET_0 AS SELECT FROM FRET {
KEY MANDT,
KEY BTYPB,
KEY BLNRB,
KEY CAST( RIGHT( BPOSB, 5 ) AS ABAP.NUMC( 5 ) ) AS BPOSB, // <--
KEY BTYPA,
KEY BLNRA,
KEY CAST( RIGHT( BPOSA, 5 ) AS ABAP.NUMC( 5 ) ) AS BPOSA, // <--
...
The second used the first view and that resolved the issue.
Upvotes: 0
Reputation: 10621
The problem is:
BPOSB
in FRET
table has type NUMC(6)
EBELP
in EKPO
table has type NUMC(5)
According to the type comparison matrix you should have exact matching between RHS and LHS type length.
As per the rules for conditionals in ON
clause of the association:
No path expressions or other expressions or function calls can be specified.
So you can't do neither CAST( num1 AS NUMC( N ) )
, nor SUBSTRING
. Neither for RHS nor for LHS operand.
I see no solution here except rebuilding your view in another way.
Upvotes: 1