Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CDS association: fields do not have compatible types

nmirandaghn
Participant
2,269

Hi guys, 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
}
5 REPLIES 5

luis_sismeiro
Participant
1,259

Hello Nelson,

You can create a new CDS view in order to make a cast for the field. As you can see in the code below:

@AbapCatalog.sqlViewName: 'ZLLS_TEST_CDSV'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
define view ZLLS_TEST_CDS1
  as select from ekpo
{
 key ebeln,
 key ebelp,
     cast( LPAD( ebelp, 6, '0' ) as posnr ) as conv_ebelp " Cast the field to the right type and size.
}

And then use the newly created view to create the desired view.

@AbapCatalog.sqlViewName: 'ZLLS_TEST_CDS1V'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
define view ZLLS_TEST_CDS
  as select from fret as Collective_Purchase
  association [1..*] to ZLLS_TEST_CDS1 as _Stock_Transfer_Order on  $projection.blnra = _Stock_Transfer_Order.ebeln
                                                      and $projection.bposa = _Stock_Transfer_Order.conv_ebelp
  association [1]    to ZLLS_TEST_CDS1 as _Purchase_Order       on  $projection.blnrb = _Purchase_Order.ebeln
                                                                and $projection.bposb = _Purchase_Order.conv_ebelp
{
  key Collective_Purchase.blnrb,
  key Collective_Purchase.bposb,
  key Collective_Purchase.blnra,
  key Collective_Purchase.bposa,
      _Stock_Transfer_Order,
      _Purchase_Order
}

Note: Example only. I don't have access to working environment with data to test this solution.


0 Kudos
1,259

Thanks for your answer however, on the view ZLLS_TEST_CDS1, Eclipse shows me the error :

CAST on Data Element POSNR, type NUMC: type, length of source, target must be the same

0 Kudos
1,259

Well, that was not exactly the answer but it led me to the right path.

Made 2 CDS views as suggested and for the first one, I used RIGHT and CAST for the incompatible fields.

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, // <--

0 Kudos
1,259

I’m glad that I could help. Sorry for the delay, with Xmas and weekend.. it took me a while to get back online.

1,259

Hi,

yes you can do casting.

bposa and bposb both are of type numc(6) cast to char(10) which is same as ekpo table ebeln data type char(10).do as shown below

first create one view then do casting.

after that create another view as shown below and execute.

hope this will be helpful