ATPC_CDS_AFPO_QTY_DIST

DDL: ATPC_CDS_AFPO_QTY_DIST SQL: ATPC_AFPO_QD Type: view Package: ATP_PAC

CDS View on AFPO,RESB,AFKO for Qty. Dist for ATP

ATPC_CDS_AFPO_QTY_DIST is a CDS View that provides data about "CDS View on AFPO,RESB,AFKO for Qty. Dist for ATP" in SAP S/4HANA. It reads from 3 data sources (afko, afpo, resb) and exposes 25 fields. Part of development package ATP_PAC.

Data Sources (3)

SourceAliasJoin Type
afko afko left_outer
afpo afpo from
resb resb left_outer

Annotations (8)

NameValueLevelField
AbapCatalog.sqlViewName ATPC_AFPO_QD view
ObjectModel.usageType.serviceQuality #X view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.dataClass #MIXED view
AbapCatalog.compiler.compareFilter true view
AccessControl.authorizationCheck #NOT_REQUIRED view
ClientHandling.algorithm #SESSION_VARIABLE view
EndUserText.label CDS View on AFPO,RESB,AFKO for Qty. Dist for ATP view

Fields (25)

KeyFieldSource TableSource FieldDescription
delnr afpo aufnr
delps afpo posnr
mandt afpo mandt
matnr afpo matnr
werks afpo pwerk
lgort afpo lgort
charg afpo charg
sgt_scat afpo sgt_scat
kdauf afpo kdauf
kdpos afpo kdpos
projn afpo projn
atpdate
psmng afpo psmng
wemng afpo wemng
iamng afpo iamng
psamg afpo psamg
krsnraskrsnr
krsps afpo krsps
dfrei afpo dfrei
amein afpo amein
umrez afpo umrez
umren afpo umren
bwtar afpo bwtar
dauty afpo dauty
webaz afpo webaz
@AbapCatalog.sqlViewName: 'ATPC_AFPO_QD'
@ObjectModel.usageType: {
    serviceQuality: #X,
    sizeCategory: #XXL,
    dataClass: #MIXED
}
@AbapCatalog.compiler.compareFilter:true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.algorithm: #SESSION_VARIABLE
@EndUserText.label: 'CDS View on AFPO,RESB,AFKO for Qty. Dist for ATP'
define view ATPC_CDS_AFPO_QTY_DIST
  as select from    afpo
    left outer join afko on  afpo.aufnr = afko.aufnr    //Outer join to check if the product is a co-product

                         and afpo.matnr = afko.plnbez
    left outer join resb on  afpo.krsnr   =  resb.rsnum //Join to fetch Dates for co-products

                         and afpo.krsps   =  resb.rspos
                         and resb.no_disp <> ''
                         and resb.kzkup   =  'X'
{

  //  key the single select

  afpo.aufnr    as delnr,
  afpo.posnr    as delps,

  //  key for mass select

  afpo.mandt    as mandt,
  afpo.matnr    as matnr,
  afpo.pwerk    as werks,
  afpo.lgort    as lgort,
  afpo.charg    as charg,
  afpo.sgt_scat as sgt_scat,

  //  sobkz, but no sskey for performance reasons

  case when afpo.sobkz = 'K' then ''
                        else afpo.sobkz
  end           as sobkz,

  case when afpo.sobkz = 'E' then afpo.kdauf
       when afpo.sobkz = 'Q' then afpo.projn
                             else ''
  end           as sskey,

  case when afpo.sobkz = 'E' then afpo.kdpos
                             else ''
  end           as sskey_ext,

  afpo.kdauf    as kdauf,
  afpo.kdpos    as kdpos,
  afpo.projn    as projn,

  //  ATP Data

  //Additional Case statement to fetch start date and end date

  //In case of Co-products, start date and end date are fetched from RESB

  //In other cases, we fetch start date from AFKO-GSTRP and end date from AFPO_DGLTP


  //Start date

  //Fill start date(GSTRP) only if start date and end date are different and

  //distribution key is filled;

  //Else pass initial values ( for performance reasons)


  case //when afpo.verto is initial               then cast ('' as pm_ordgstrp )

       when afko.aufnr is not null and ( ( afko.gstrp <> afpo.dgltp ) and afpo.verto is not initial ) then afko.gstrp
       when afko.aufnr is null and ( ( resb.bdter <> resb.sbter ) and afpo.verto is not initial )     then resb.bdter
                                                                                                      else cast ('00000000' as pm_ordgstrp )
  end           as gstrp, --Start date

  //End date --atpdate

  case when afko.aufnr is not null then afpo.dgltp
                                   else resb.sbter
  end           as dgltp, --atpdate,  // Basic Finish Date; DGLTP = PEDTR in R3


  afpo.psmng    as psmng,
  afpo.wemng    as wemng,
  afpo.iamng    as iamng,
  afpo.psamg    as psamg,

  //  for check against customizing / masterdata


  //Distribution Key

  //Fill distribution key only if start date and end date are different and

  //distribution key is filled;

  //Else pass initial values ( for performance reasons)


  case when (   afko.aufnr is not null and
              ( afko.gstrp = afpo.dgltp ) )  or
            (   afko.aufnr is null and
              ( resb.bdter = resb.sbter ) ) then ''
                                            else afpo.verto
  end           as verto, --distribution key

  afpo.krsnr    as krsnr,
  afpo.krsps    as krsps,
  afpo.dfrei    as dfrei,
  afpo.amein    as amein,
  afpo.umrez    as umrez,
  afpo.umren    as umren,
  afpo.bwtar    as bwtar,
  afpo.dauty    as dauty,
  afpo.webaz    as webaz

}

where

  (
       afpo.dauty = '40'
    or afpo.dauty = '30'
    or afpo.dauty = '20'
    or afpo.dauty = '10'
  )
  and  afpo.elikz = ''
  and  afpo.dnrel = ''
  and  afpo.wepos = 'X'
  and  afpo.arsnr = '0000000000' // direct procurement (see FORM afpo_check)

;