Sept7

CDS View Practise I

CDS View 'ZNKS_CV_CHK':

@AbapCatalog.sqlViewName: 'ZNKS_SV_CHK'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AbapCatalog.dataMaintenance: #RESTRICTED
@ClientHandling.type: #INHERITED
@ClientHandling.algorithm: #AUTOMATED
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Check result of NKS 1st Checking'
define view ZNKS_CV_CHK as 
select from 
znks_chkhd as CH
inner join znks_chkdt as DT
on CH.rstmno = DT.rstmno
left outer join znks_chkdf as DF
on DT.trcidx = DF.trcidx
{
    key CH.rstmno,
        CH.trcid,
        CH.vornr,
        DT.trcidx,
        @Semantics.quantity.unitOfMeasure: 'unit'
        DT.trcnum,
        @Semantics.quantity.unitOfMeasure: 'unit'
        DT.badnum,
        @Semantics.unitOfMeasure: true
        DT.unit,
        DF.defcod
}

CDS View 'ZNKS_CV_TRC':

@AbapCatalog.sqlViewName: 'ZNKS_SV_TRC'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Module Info'
define view ZNKS_CV_TRC as select from znks_trchd as hd
association [1..*] to ZNKS_CV_CHK as _checkDetail
    on $projection.trcid = _checkDetail.trcid 
{
    key hd.trcid,
        hd.aufnr,
        hd.matnr,
    _checkDetail // Make association public
}

ABAP Program:

TYPES:
  BEGIN OF ty_trc,
    trcid   TYPE z9trcid,
    aufnr   TYPE aufnr,
    matnr   TYPE matnr,
    vornr   TYPE vornummer,
    trcidx  TYPE z9trcidx,
    goodnum TYPE z9trcnum,
    badnum  TYPE z9badnum,
    unit    TYPE meins,
    defcod  TYPE z9defmode,
  END OF ty_trc.

DATA:
  gt_trc    TYPE TABLE OF ty_trc,
  go_chkmdp TYPE REF TO zcl_chkinfo.

PARAMETERS:
  p_aufnr  TYPE aufnr DEFAULT '4500256929' OBLIGATORY.


START-OF-SELECTION.


  SELECT from znks_cv_trc
         FIELDS trcid,
                aufnr,
                matnr,
                \_checkDetail-vornr  as vornr,
                \_checkDetail-trcidx as trcidx,
                \_checkDetail-trcnum as goodnum,
                \_checkDetail-badnum,
                \_checkDetail-unit,
                \_checkDetail-defcod
         WHERE  aufnr = @p_aufnr
         ORDER  BY trcid, vornr, trcidx
          INTO  table @gt_trc ##ASSOC_TO_N_OK[_CHECKDETAIL].
  cl_demo_output=>write_data( value = gt_trc ).

  cl_demo_output=>display( ).

2021-09-07_15-49-00.png

本篇文章已有0条评论