<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: CDS association: fields do not have compatible types in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319026#M1991073</link>
    <description>&lt;P&gt;Well, that was not exactly the answer but it led me to the right path.&lt;/P&gt;&lt;P&gt;Made 2 CDS views as suggested and for the first one, I used RIGHT and CAST for the incompatible fields.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;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, // &amp;lt;--
  KEY BTYPA,
  KEY BLNRA,
  KEY CAST( RIGHT( BPOSA, 5 ) AS ABAP.NUMC( 5 ) ) AS BPOSA, // &amp;lt;--
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Dec 2020 15:33:56 GMT</pubDate>
    <dc:creator>nmirandaghn</dc:creator>
    <dc:date>2020-12-28T15:33:56Z</dc:date>
    <item>
      <title>CDS association: fields do not have compatible types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319022#M1991069</link>
      <description>&lt;P&gt;Hi guys, I'm new to CDS and I'm trying to make my first view. &lt;/P&gt;
  &lt;P&gt;The thing is that when I try the following code I receive the error:&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Association _Purchase_Order: BPOSB and EBELP do not have a compatible type.&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;Is it possible to make a cast on any field of the association to make it work?&lt;/P&gt;
  &lt;P&gt;Thanks in advance&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;@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
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:51:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319022#M1991069</guid>
      <dc:creator>nmirandaghn</dc:creator>
      <dc:date>2020-12-22T15:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: CDS association: fields do not have compatible types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319023#M1991070</link>
      <description>&lt;P&gt;Hello Nelson,&lt;/P&gt;&lt;P&gt;You can create a new CDS view in order to make a cast for the field. As you can see in the code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@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.
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And then use the newly created view to create the desired view.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@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
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note: Example only. I don't have access to working environment with data to test this solution.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Dec 2020 23:54:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319023#M1991070</guid>
      <dc:creator>luis_sismeiro</dc:creator>
      <dc:date>2020-12-22T23:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: CDS association: fields do not have compatible types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319024#M1991071</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;yes you can do casting.&lt;/P&gt;&lt;P&gt; 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 &lt;/P&gt;&lt;P&gt;first create one view then do casting.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1873659-img1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" /&gt;&lt;/P&gt;&lt;P&gt;after that create another view as shown below and execute.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1873660-img.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" /&gt;hope this will be helpful &lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 09:44:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319024#M1991071</guid>
      <dc:creator>former_member697514</dc:creator>
      <dc:date>2020-12-23T09:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: CDS association: fields do not have compatible types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319025#M1991072</link>
      <description>&lt;P&gt;Thanks for your answer however, on the view ZLLS_TEST_CDS1, Eclipse shows me the error :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CAST on Data Element POSNR, type NUMC: type, length of source, target must be the same&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Dec 2020 15:19:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319025#M1991072</guid>
      <dc:creator>nmirandaghn</dc:creator>
      <dc:date>2020-12-23T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: CDS association: fields do not have compatible types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319026#M1991073</link>
      <description>&lt;P&gt;Well, that was not exactly the answer but it led me to the right path.&lt;/P&gt;&lt;P&gt;Made 2 CDS views as suggested and for the first one, I used RIGHT and CAST for the incompatible fields.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;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, // &amp;lt;--
  KEY BTYPA,
  KEY BLNRA,
  KEY CAST( RIGHT( BPOSA, 5 ) AS ABAP.NUMC( 5 ) ) AS BPOSA, // &amp;lt;--
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Dec 2020 15:33:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319026#M1991073</guid>
      <dc:creator>nmirandaghn</dc:creator>
      <dc:date>2020-12-28T15:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: CDS association: fields do not have compatible types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319027#M1991074</link>
      <description>&lt;P&gt;I’m glad that I could help. Sorry for the delay, with Xmas and weekend.. it took me a while to get back online. &lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 23:13:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cds-association-fields-do-not-have-compatible-types/m-p/12319027#M1991074</guid>
      <dc:creator>luis_sismeiro</dc:creator>
      <dc:date>2020-12-28T23:13:09Z</dc:date>
    </item>
  </channel>
</rss>

