Reputation: 81
I want to create a model for SAC. I have an initial CDS view to collect the data like this:
@AbapCatalog.sqlViewName: 'ZWODPROBLEMZZ'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Init view warehouse Outbound problems'
define view Z_WAREHOUSE_ODPROBZ as select from /scdl/db_proci_o as outbound
left outer join /scdl/db_proch_o as header on outbound.docid = header.docid
left outer join makt as ItemMasterDescription on ItemMasterDescription.matnr = outbound.productno and ItemMasterDescription.spras = 'E'
left outer join /scwm/aqua as phyStock on phyStock.matid = outbound.productid
left outer join mara as mat on mat.matnr = outbound.productno
left outer join /sapapo/matlwh as matStra on matStra.matid = mat.scm_matid_guid22
{
ltrim(outbound.docno, '0') as docNr,
outbound.status_wm as statusWM,
phyStock.quan as PhyQuan,
matStra.put_stra as PUTSTRA,
phyStock.lgpla as StorageBin_1,
phyStock.coo as COO_item,
outbound.ocountry as Origin2,
outbound.itemcat as ITEMCAT,
outbound.itemtype as ITEMTYPE,
outbound.refdocno_so as Sales_Order,
outbound.productno as Product,
outbound.qty as Quantity,
outbound.uom as UnitOfMeasure,
outbound.batchno as BatchNo,
outbound.ocountry as Regio_Country_of_Origin,
outbound.status_wm as Status_WM,
outbound.status_pick as Status_PickNr,
case
when outbound.status_pick = '0' then 'Not Relevant'
when outbound.status_pick = '1' then 'Not Started'
when outbound.status_pick = '2' then 'Partially Completed'
when outbound.status_pick = '7' then 'Overpicking'
when outbound.status_pick = '9' then 'Completed'
else outbound.status_pick
end as Status_Pick,
case
when outbound.status_gi = '0' then 'Not Relevant'
when outbound.status_gi = '1' then 'Not Started'
when outbound.status_gi = '2' then 'Partially Completed'
when outbound.status_gi = '7' then 'Overpicking'
when outbound.status_gi = '9' then 'Completed'
else outbound.status_gi
end as Status_GoodIssue,
case
when outbound.status_compl = '0' then 'Not Relevant'
when outbound.status_compl = '1' then 'Not Started'
when outbound.status_compl = '2' then 'Partially Completed'
when outbound.status_compl = '7' then 'Overpicking'
when outbound.status_compl = '9' then 'Completed'
else outbound.status_gi
end as Status_Compl,
outbound.doccat as Document_Category,
outbound.tstfr_act_gi as Actual_GoodIssueDate,
outbound.tstfr_act_gi_date_wh as Actual_GoodIssueDatedate_wh,
outbound.tstfr_act_gi_time_wh as Actual_GoodIssueDatetime_wh,
outbound.tstfr_act_gi_wh as Actual_GoodIssueDate_wh,
outbound./scwm/procty as Whse_Process_Type,
outbound./scwm/whno as whNO,
outbound.zzcoo as Country_of_Origin,
ItemMasterDescription.maktx as Product_short_Description,
ltrim(outbound.refitemno_so, '0') as Sales_Order_Item,
outbound.stock_doccat as Type,
outbound.stock_docno as Sales_Order_Project,
outbound.stock_itmno as Sales_Order_Item2,
outbound.tstfr_pick as Picking_Actual,
-- 0 = not relevant, 1 = Not Started, 2 = Partially Completed, 7 = Overpicking, 9 = Completed
case
when outbound.status_pick = '9' and outbound.status_gi = '9' then 'Completed'
else 'Not Picked'
end as Picking_Status_GI
}
where header.doctype = 'OUTB'
and outbound.status_pick = '1'
I need to make a string aggregration as this is not possible out of the box with CDS views I need to create an ABAP class which references this view and makes the aggregation.
The ABAP class:
CLASS zcl_warehouse_quan DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb.
CLASS-METHODS:
ODPROB FOR TABLE FUNCTION Z_WH_ODPROBZ_TABLE_FUNC.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ZCL_WAREHOUSE_QUAN IMPLEMENTATION.
METHOD ODPROB
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING ZWODPROBLEMZZ.
itab_coo =
SELECT
ZWODPROBLEMZZ.mandt as client,
ZWODPROBLEMZZ.docNr as docNr,
ZWODPROBLEMZZ.Country_of_Origin as restriction,
cast(ZWODPROBLEMZZ.quantity as INT) as ODQuantity,
ZWODPROBLEMZZ.product as product,
sum(ZWODPROBLEMZZ.phyquan) as total_phyquan,
STRING_AGG(concat(ZWODPROBLEMZZ.coo_item, concat('-',cast(ZWODPROBLEMZZ.phyquan as INT))), ', ') as coo_x_qty,
STRING_AGG(concat(ZWODPROBLEMZZ.storagebin_1, concat('-QTY:',cast(ZWODPROBLEMZZ.phyquan as INT))), ', ') as storageBin_1
FROM ZWODPROBLEMZZ
GROUP BY ZWODPROBLEMZZ.mandt,ZWODPROBLEMZZ.docNr,ZWODPROBLEMZZ.Country_of_Origin,ZWODPROBLEMZZ.quantity,ZWODPROBLEMZZ.product;
RETURN
SELECT client,
docNr,
restriction,
ODQuantity,
product,
total_phyquan as total_phyquan,
coo_x_qty,
storageBin_1
FROM :itab_coo
GROUP BY client,product,restriction, ODQuantity, docNr,total_phyquan,coo_x_qty,storageBin_1;
ENDMETHOD.
ENDCLASS.
To call this in a CDS view I need to make a table function. So the main CDS view will call the table function and fetch the data.
@AbapCatalog.sqlViewName: 'ZWHODPROBMAINZ'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Main view of OD Problem View'
define view Z_WAREHOUSE_ODPROBZ_MAIN as select from Z_WH_ODPROBZ_TABLE_FUNC as odProb
{
odProb.docNr as OD,
odProb.restriction as Restriction,
odProb.ODQuantity as ODqty
sum(odProb.ODQuantity) as ODqty,
odProb.product as Product,
odProb.total_phyquan as AvailableQty,
odProb.coo_x_qty as QTY_X_COO,
odProb.storageBin_1 as StorageBin_X_QTX
}
After this I make the Cube view like this:
@AbapCatalog.sqlViewName: 'ZWHODPROBQUBEZZ'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.dataClass: #MIXED
@Analytics.dataCategory: #CUBE
@EndUserText.label: 'Cube view for wh outb prob'
define view Z_WAREHOUSE_ODPROBZ_CUBE as select from Z_WAREHOUSE_ODPROBZ_MAIN as odProb
{
odProb.OD as OD,
odProb.Restriction as Restriction,
odProb.ODqty as ODqty
odProb.Product as Product,
odProb.AvailableQty as AvailableQty,
odProb.QTY_X_COO as QTY_X_COO,
odProb.StorageBin_X_QTX as StorageBin_X_QTX
}
Then the analytical query view:
@AbapCatalog.sqlViewName: 'ZWHODPROBQUERYZ'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@EndUserText.label: 'Qube view for wh outb prob'
define view Z_WAREHOUSE_ODPROBZ_QUERY as select from Z_WAREHOUSE_ODPROBZ_CUBE as odProb
{
@AnalyticsDetails.query.axis: #ROWS
odProb.OD as OD,
@AnalyticsDetails.query.axis: #ROWS
odProb.Restriction as Restriction,
@AnalyticsDetails.query.axis: #COLUMNS
odProb.ODqty as ODqty
@AnalyticsDetails.query.axis: #ROWS
odProb.Product as Product,
@AnalyticsDetails.query.axis: #ROWS
odProb.AvailableQty as AvailableQty,
@AnalyticsDetails.query.axis: #COLUMNS
odProb.QTY_X_COO as QTY_X_COO,
@AnalyticsDetails.query.axis: #ROWS
odProb.StorageBin_X_QTX as StorageBin_X_QTX
}
Ok so when I run this directly in eclipse this is the result, all fine:
Now the problem:
When uploading into SAC referenced as a Live Data Connection Model I am not able to create the model, there is an error:
The datasource query has no measures. Correlation ID: 30858743-2182-4505-8882-271664747438
Cannot read properties of null (reading 'type') Correlation ID: 38480528-0025-4608-a156-613481472482
The first error "no measures" is funny because actually there is a measure the quantity? Or what is the problem?
The second error is strange.
My question is, is it possible to handle ABAP classes and CDS views in combination or do I need to be aware of something?
Thanks for any help!
Upvotes: 0
Views: 211