fgl_lib_c

DDL: FGL_LIB_C Type: view_entity

LIB Base View

fgl_lib_c is a CDS View that provides data about "LIB Base View" in SAP S/4HANA. It reads from 4 data sources (bkpf, bkpf, bseg, bseg_add) and exposes 77 fields with key fields bukrs, gjahr, belnr, buzei, gjahr.

Data Sources (4)

SourceAliasJoin Type
bkpf bkpf inner
bkpf bkpf inner
bseg bseg from
bseg_add bseg union_all

Parameters (3)

NameTypeDefault
p_langu spras
p_refdate sydatum
p_ale abap.char( 1 )

Annotations (7)

NameValueLevelField
AccessControl.authorizationCheck #NOT_REQUIRED view
AccessControl.personalData.blocking #NOT_REQUIRED view
EndUserText.label LIB Base View view
Metadata.ignorePropagatedAnnotations true view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.dataClass #MIXED view

Fields (77)

KeyFieldSource TableSource FieldDescription
KEY bukrs
KEY gjahr
KEY belnr
KEY buzei
counter
quanunit
currkey_00
currkey_0d
currkey_10
shkzgwhenHthen1else1endasnebtrasnebtr
shkzgwhenHthen1else1endasskntoassknto
shkzgwhenHthen1else1endasskfbtasskfbt
pycur
fiscper
kktpl
land1
periv
fikrs
ktopl
ktop2
lifnr
kunnr
hkont
gkont
gkart
rp_ktext
rp_ltext
sp_ktext
sp_ltext
rf_fkbtx
sf_fkbtx
cc_ktext
cc_ltext
or_ktext
mm_maktx
ga_txt20
ga_txt50
sk_txt20
KEY gjahr
KEY belnr
KEY buzei
counter
quanunit
currkey_00
currkey_0d
currkey_10
nebtr
sknto
skfbt
pycur
pyamt
fiscper
kktpl
land1
periv
fikrs
ktopl
ktop2
lifnr
kunnr
hkont
gkont
gkart
rp_ktext
rp_ltext
sp_ktext
sp_ltext
rf_fkbtx
sf_fkbtx
cc_ktext
cc_ltext
or_ktext
mm_maktx
ga_txt20
ga_txt50
sk_txt20
sk_txt50
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST]

@AccessControl.authorizationCheck:#NOT_REQUIRED
@AccessControl.personalData.blocking:#NOT_REQUIRED

@EndUserText.label: 'LIB Base View '

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:
  {
    serviceQuality: #D,
    sizeCategory: #XXL,
    dataClass: #MIXED
  }

define view entity fgl_lib_c
  with parameters
    @Environment.systemField: #SYSTEM_LANGUAGE
    @EndUserText.label: 'Language'
    p_langu   : spras,
    @Environment.systemField: #SYSTEM_DATE
    @EndUserText.label: 'Reference Date'
    p_refdate : sydatum,
    @EndUserText.label: 'ALE-extern as Open Items'
    p_ale     : abap.char( 1 )

  as select from           bseg                                               as bseg
    inner join             bkpf                                                         on  bseg.bukrs =  bkpf.bukrs
                                                                                        and bseg.belnr =  bkpf.belnr
                                                                                        and bseg.gjahr =  bkpf.gjahr
                                                                                        and bkpf.bstat <> 'L'
  // customizing

    left outer to one join t001                                                         on bseg.bukrs = t001.bukrs
    left outer to one join t004                                                         on t001.ktopl = t004.ktopl
  // master data

    left outer to one join fgl_lib_txt_prctr( p_langu : $parameters.p_langu ) as rprctr on  bseg.kokrs   =  rprctr.kokrs
                                                                                        and bseg.prctr   =  rprctr.prctr
                                                                                        and bseg.h_budat >= rprctr.datab
                                                                                        and bseg.h_budat <= rprctr.datbi
    left outer to one join fgl_lib_txt_prctr( p_langu : $parameters.p_langu ) as sprctr on  bseg.kokrs   =  sprctr.kokrs
                                                                                        and bseg.pprct   =  sprctr.prctr
                                                                                        and bseg.h_budat >= sprctr.datab
                                                                                        and bseg.h_budat <= sprctr.datbi
    left outer to one join fgl_lib_txt_fkber( p_langu : $parameters.p_langu ) as rfkbt  on bseg.fkber_long = rfkbt.fkber
    left outer to one join fgl_lib_txt_fkber( p_langu : $parameters.p_langu ) as sfkbt  on bseg.pfkber = sfkbt.fkber
    left outer to one join fgl_lib_txt_kostl( p_langu : $parameters.p_langu ) as rkostl on  bseg.kokrs   =  rkostl.kokrs
                                                                                        and bseg.kostl   =  rkostl.kostl
                                                                                        and bseg.h_budat >= rkostl.datab
                                                                                        and bseg.h_budat <= rkostl.datbi
    left outer to one join aufk                                                         on bseg.aufnr = aufk.aufnr
    left outer to one join fgl_lib_txt_matnr( p_langu : $parameters.p_langu ) as rmatnr on bseg.matnr = rmatnr.matnr
    left outer to one join fgl_lib_txt_skat( p_langu : $parameters.p_langu )  as hkont  on  t001.ktopl = hkont.ktopl
                                                                                        and bseg.hkont = hkont.saknr
    left outer to one join fgl_lib_txt_skat( p_langu : $parameters.p_langu )  as saknr  on  t001.ktopl = saknr.ktopl
                                                                                        and bseg.saknr = saknr.saknr
{
      // KEY

  key cast( bseg.bukrs as bukrs preserving type )                                                                             as bukrs, //<$fix>

  key cast( bseg.gjahr as gjahr preserving type )                                                                             as gjahr, //<$fix>

  key cast( bseg.belnr as belnr_d preserving type )                                                                           as belnr, //<$fix>

  key cast( bseg.buzei as buzei preserving type )                                                                             as buzei, //<$fix>


      // DB COUNTER

      cast( 1 as sydbcnt)                                                                                                     as counter, //<$fix>


      // STANDARD CURRENCIES AND QUANTITIES


      cast( bseg.meins as rounit preserving type )                                                                            as quanunit, //<$fix>

      @Semantics.quantity.unitOfMeasure: 'quanunit'
      cast( case bseg.squan
        when '-' then -1 * bseg.menge
        when '+' then bseg.menge
        when '0' then bseg.menge
        else case bseg.shkzg
              when 'H' then -1 * bseg.menge
              else bseg.menge
             end
      end as fagl_quantity )                                                                                                  as quantity, //<$fix>


      cast( bseg.pswsl as fagl_currkey_00 preserving type )                                                                   as currkey_00, //<$fix>

      @Semantics.amount.currencyCode: 'currkey_00'
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.pswbt as abap.dec(23,2))
        when 'S' then cast( bseg.pswbt as abap.dec(23,2))
        else cast ( 0 as abap.dec(23,2))
      end as fagl_currval_00 )                                                                                                as currval_00, //<$fix>


      cast( bkpf.waers as fagl_currkey_0d preserving type )                                                                   as currkey_0d, //<$fix>

      @Semantics.amount.currencyCode: 'currkey_0D'
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.wrbtr as abap.dec(23,2))
        when 'S' then cast( bseg.wrbtr as abap.dec(23,2))
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_0d )                                                                                                as currval_0d, //<$fix>


      cast( bkpf.hwaer as fagl_currkey_10 preserving type )                                                                   as currkey_10, //<$fix>

      @Semantics.amount.currencyCode: 'currkey_10'
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.dmbtr as abap.dec(23,2))
        when 'S' then cast( bseg.dmbtr as abap.dec(23,2))
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_10 )                                                                                                as currval_10, //<$fix>


      cast( case '11'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_11 )                                                                                                as currkey_11, //<$fix>


      cast( case '12'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_12 )                                                                                                as currkey_12, //<$fix>


      cast( case '30'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_30 )                                                                                                as currkey_30, //<$fix>


      cast( case '31'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_31 )                                                                                                as currkey_31, //<$fix>


      cast( case '32'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_32 )                                                                                                as currkey_32, //<$fix>


      cast( case '40'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_40 )                                                                                                as currkey_40, //<$fix>


      cast( case '50'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_50 )                                                                                                as currkey_50, //<$fix>


      cast( case '60'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_60 )                                                                                                as currkey_60, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_11'
      cast( case '11'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast ( 0 as abap.dec(23,2))
      end as fagl_currval_11 )                                                                                                as currval_11, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_12'
      cast( case '12'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast ( 0 as abap.dec(23,2))
      end as fagl_currval_12 )                                                                                                as currval_12, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_30'
      cast( case '30'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_30 )                                                                                                as currval_30, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_31'
      cast( case '31'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_31 )                                                                                                as currval_31, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_32'
      cast( case '32'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_32 )                                                                                                as currval_32, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_40'
      cast( case '40'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast ( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_40 )                                                                                                as currval_40, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_50'
      cast( case '50'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_50 )                                                                                                as currval_50, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_60'
      cast( case '60'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_60 )                                                                                                as currval_60, //<$fix>


      // CALCULATED FIELDS

      cast ( case
        when bseg.rebzt = '' and bseg.rebzg = ''
          then bseg.belnr
        else bseg.rebzg
      end as rebzg preserving type )                                                                                          as rebzg, //<$fix>


      // set open/cleared item flag

      //  include ALE-extern open config

      cast(
        case
          when bseg.augdt = '00000000' or bseg.augdt > $parameters.p_refdate
           then ''
          when bseg.augbl = 'ALE-extern'
           then case $parameters.p_ale when 'X' then '' else 'X' end
          else 'X'
        end as fagl_x_cleared_item preserving type )                                                                          as x_cleared_item, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_00'
      cast ( cast ( bseg.nebtr as abap.dec(23,2) ) * case bseg.shkzg when 'H' then -1 else 1 end
      as nebtr )                                                                                                              as nebtr, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_10'
      cast ( cast ( bseg.sknto as abap.dec(23,2) ) * case bseg.shkzg when 'H' then -1 else 1 end
      as sknto )                                                                                                              as sknto, //<$fix>


      @Semantics.amount.currencyCode: 'currkey_00'
      cast ( cast ( bseg.skfbt as abap.dec(23,2) ) * case bseg.shkzg when 'H' then -1 else 1 end
      as skfbt )                                                                                                              as skfbt, //<$fix>


      cast( bseg.pycur as pycur preserving type )                                                                             as pycur, //<$fix>

      @Semantics.amount.currencyCode: 'pycur'
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.pyamt  as abap.dec(23,2))
        when 'S' then cast( bseg.pyamt  as abap.dec(23,2))
        else cast( 0 as abap.dec(23,2))
      end as pyamt )                                                                                                          as pyamt, //<$fix>


      cast( concat(bseg.gjahr,concat('0',bseg.h_monat)) as rsfiscper )                                                        as fiscper, //<$fix>


      // replacing fagl_org_info

      cast( t004.kktpl as kktpl preserving type )                                                                             as kktpl, //<$fix>

      cast( t001.land1 as land1 preserving type )                                                                             as land1, //<$fix>

      cast( t001.periv as periv preserving type )                                                                             as periv, //<$fix>

      cast( t001.fikrs as fikrs preserving type )                                                                             as fikrs, //<$fix>

      cast( t001.ktopl as ktopl preserving type )                                                                             as ktopl, //<$fix>

      cast( t001.ktop2 as ktop2 preserving type )                                                                             as ktop2, //<$fix>


      // required for joins in top views

      cast( bseg.lifnr as lifnr preserving type )                                                                             as lifnr, //<$fix>

      cast( bseg.kunnr as kunnr preserving type )                                                                             as kunnr, //<$fix>

      cast( bseg.hkont as hkont preserving type )                                                                             as hkont, //<$fix>

      cast( bseg.gkont as gkont preserving type )                                                                             as gkont, //<$fix>

      cast( bseg.gkart as gkart preserving type )                                                                             as gkart, //<$fix>


      // GENERATION ANCHOR FOR ALL REMAINING FIELDS

      // in BSEG, BKPF, SKA1, SKB1, KNA1, LFA1


      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy



//<$VF>

//<$FIELDS>

//<$VF>



      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy


      // additional texts

      cast( coalesce( rprctr.ktext, cast( '' as fagl_text_prctr_short ) ) as fagl_text_prctr_short preserving type )          as rp_ktext, //<$fix>

      cast( coalesce( rprctr.ltext, cast( '' as fagl_text_prctr_long ) ) as fagl_text_prctr_long preserving type )            as rp_ltext, //<$fix>

      cast( coalesce( sprctr.ktext, cast( '' as fagl_text_pprctr_short ) ) as fagl_text_pprctr_short preserving type )        as sp_ktext, //<$fix>

      cast( coalesce( sprctr.ltext, cast( '' as fagl_text_pprctr_long ) ) as fagl_text_pprctr_long preserving type )          as sp_ltext, //<$fix>

      cast( coalesce( rfkbt.fkbtx, cast( '' as fagl_text_farea ) ) as fagl_text_farea preserving type )                       as rf_fkbtx, //<$fix>

      cast( coalesce( sfkbt.fkbtx, cast( '' as fagl_text_pfarea ) ) as fagl_text_pfarea preserving type )                     as sf_fkbtx, //<$fix>

      cast( coalesce( rkostl.ktext, cast( '' as fagl_text_ccntr_short ) ) as fagl_text_ccntr_short preserving type )          as cc_ktext, //<$fix>

      cast( coalesce( rkostl.ltext, cast( '' as fagl_text_ccntr_long ) ) as fagl_text_ccntr_long preserving type )            as cc_ltext, //<$fix>

      cast( coalesce( aufk.ktext, cast( '' as fagl_text_order_short ) ) as fagl_text_order_short preserving type )            as or_ktext, //<$fix>

      cast( coalesce( rmatnr.maktx, cast( '' as fagl_text_material ) ) as fagl_text_material preserving type )                as mm_maktx, //<$fix>

      cast( coalesce( hkont.txt20, cast( '' as fagl_text_gl_account_short ) ) as fagl_text_gl_account_short preserving type ) as ga_txt20, //<$fix>

      cast( coalesce( hkont.txt50, cast( '' as fagl_text_gl_account_long ) ) as fagl_text_gl_account_long preserving type )   as ga_txt50, //<$fix>

      cast( coalesce( saknr.txt20, cast( '' as fagl_text_saknr_short ) ) as fagl_text_saknr_short preserving type )           as sk_txt20, //<$fix>

      cast( coalesce( saknr.txt50, cast( '' as fagl_text_saknr_long ) ) as fagl_text_saknr_long preserving type )             as sk_txt50 //<$fix>

}
union all select from    bseg_add                                           as bseg
  inner join             bkpf                                                         on  bseg.bukrs = bkpf.bukrs
                                                                                      and bseg.belnr = bkpf.belnr
                                                                                      and bseg.gjahr = bkpf.gjahr
                                                                                      and bkpf.bstat = 'L'
  left outer to one join t001                                                         on bseg.bukrs = t001.bukrs
  left outer to one join t004                                                         on t001.ktopl = t004.ktopl
  left outer to one join fgl_lib_txt_prctr( p_langu : $parameters.p_langu ) as rprctr on  bseg.kokrs =  rprctr.kokrs
                                                                                      and bseg.prctr =  rprctr.prctr
                                                                                      and bkpf.budat >= rprctr.datab
                                                                                      and bkpf.budat <= rprctr.datbi
  left outer to one join fgl_lib_txt_prctr( p_langu : $parameters.p_langu ) as sprctr on  bseg.kokrs =  sprctr.kokrs
                                                                                      and bseg.pprct =  sprctr.prctr
                                                                                      and bkpf.budat >= sprctr.datab
                                                                                      and bkpf.budat <= sprctr.datbi
  left outer to one join fgl_lib_txt_fkber( p_langu : $parameters.p_langu ) as rfkbt  on bseg.fkber = rfkbt.fkber
  left outer to one join fgl_lib_txt_fkber( p_langu : $parameters.p_langu ) as sfkbt  on bseg.pfkber = sfkbt.fkber
  left outer to one join fgl_lib_txt_kostl( p_langu : $parameters.p_langu ) as rkostl on  bseg.kokrs =  rkostl.kokrs
                                                                                      and bseg.kostl =  rkostl.kostl
                                                                                      and bkpf.budat >= rkostl.datab
                                                                                      and bkpf.budat <= rkostl.datbi
  left outer to one join aufk                                                         on bseg.aufnr = aufk.aufnr
  left outer to one join fgl_lib_txt_matnr( p_langu : $parameters.p_langu ) as rmatnr on bseg.matnr = rmatnr.matnr
  left outer to one join fgl_lib_txt_skat( p_langu : $parameters.p_langu )  as hkont  on  t001.ktopl = hkont.ktopl
                                                                                      and bseg.hkont = hkont.saknr

//    left outer to one join fgl_lib_txt_skat( p_langu : $parameters.p_langu )  as saknr   on  t001.ktopl = saknr.ktopl

//                                                                                         and bseg.saknr = saknr.saknr

{
      // KEY

  key cast( bseg.bukrs as bukrs preserving type )                                                                             as bukrs,
  key cast( bseg.gjahr as gjahr preserving type )                                                                             as gjahr,
  key cast( bseg.belnr as belnr_d preserving type )                                                                           as belnr,
  key cast( right(bseg.buzei, 3) as buzei )                                                                                   as buzei,

      // DB COUNTER

      cast( 1 as sydbcnt)                                                                                                     as counter,

      // STANDARD CURRENCIES AND QUANTITIES


      cast( bseg.meins as rounit preserving type )                                                                            as quanunit,
      cast( case bseg.shkzg
              when 'H' then -1 * bseg.menge
              else bseg.menge
      end as fagl_quantity )                                                                                                  as quantity,

      cast( bseg.pswsl as fagl_currkey_00 preserving type )                                                                   as currkey_00,
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.pswbt as abap.dec(23,2))
        when 'S' then cast( bseg.pswbt as abap.dec(23,2))
        else cast ( 0 as abap.dec(23,2))
      end as fagl_currval_00 )                                                                                                as currval_00,

      cast( bkpf.waers as fagl_currkey_0d preserving type )                                                                   as currkey_0d,
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.wrbtr as abap.dec(23,2))
        when 'S' then cast( bseg.wrbtr as abap.dec(23,2))
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_0d )                                                                                                as currval_0d,

      cast( bkpf.hwaer as fagl_currkey_10 preserving type )                                                                   as currkey_10,
      cast( case bseg.shkzg
        when 'H' then cast( -1 * bseg.dmbtr as abap.dec(23,2))
        when 'S' then cast( bseg.dmbtr as abap.dec(23,2))
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_10 )                                                                                                as currval_10,

      cast( case '11'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_11 )                                                                                                as currkey_11,

      cast( case '12'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_12 )                                                                                                as currkey_12,

      cast( case '30'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_30 )                                                                                                as currkey_30,

      cast( case '31'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_31 )                                                                                                as currkey_31,

      cast( case '32'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_32 )                                                                                                as currkey_32,

      cast( case '40'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_40 )                                                                                                as currkey_40,

      cast( case '50'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_50 )                                                                                                as currkey_50,

      cast( case '60'
        when  bkpf.curt2  then bkpf.hwae2
        when  bkpf.curt3  then bkpf.hwae3
        else ''
      end as fagl_currkey_60 )                                                                                                as currkey_60,

      cast( case '11'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast ( 0 as abap.dec(23,2))
      end as fagl_currval_11 )                                                                                                as currval_11,

      cast( case '12'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast ( 0 as abap.dec(23,2))
      end as fagl_currval_12 )                                                                                                as currval_12,

      cast( case '30'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_30 )                                                                                                as currval_30,

      cast( case '31'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_31 )                                                                                                as currval_31,

      cast( case '32'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_32 )                                                                                                as currval_32,

      cast( case '40'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast ( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_40 )                                                                                                as currval_40,

      cast( case '50'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_50 )                                                                                                as currval_50,

      cast( case '60'
        when bkpf.curt2 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe2 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe2 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        when bkpf.curt3 then
          case bseg.shkzg
            when 'H' then cast( -1 * bseg.dmbe3 as abap.dec(23,2))
            when 'S' then cast( bseg.dmbe3 as abap.dec(23,2))
            else cast( 0 as abap.dec(23,2))
          end
        else cast( 0 as abap.dec(23,2))
      end as fagl_currval_60 )                                                                                                as currval_60,

      // CALCULATED FIELDS

      cast ( case
        when bseg.rebzt = '' and bseg.rebzg = ''
          then bseg.belnr
        else bseg.rebzg
      end as rebzg preserving type )                                                                                          as rebzg,

      // set open/cleared item flag

      //  include ALE-extern open config

      cast(
        case
          when bseg.augdt = '00000000' or bseg.augdt > $parameters.p_refdate
           then ''
          when bseg.augbl = 'ALE-extern'
           then case $parameters.p_ale when 'X' then '' else 'X' end
          else 'X'
        end as fagl_x_cleared_item preserving type )                                                                          as x_cleared_item,

      cast( 0 as nebtr )                                                                                                      as nebtr,

      cast( 0 as sknto )                                                                                                      as sknto,

      cast( 0 as skfbt )                                                                                                      as skfbt,

      cast( '' as pycur )                                                                                                     as pycur,

      cast( 0 as pyamt )                                                                                                      as pyamt,

      cast( concat(bseg.gjahr,concat('0',bkpf.monat)) as rsfiscper )                                                          as fiscper,

      //replacing fagl_org_info

      cast( t004.kktpl as kktpl preserving type )                                                                             as kktpl,
      cast( t001.land1 as land1 preserving type )                                                                             as land1,
      cast( t001.periv as periv preserving type )                                                                             as periv,
      cast( t001.fikrs as fikrs preserving type )                                                                             as fikrs,
      cast( t001.ktopl as ktopl preserving type )                                                                             as ktopl,
      cast( t001.ktop2 as ktop2 preserving type )                                                                             as ktop2,

      // required for joins in top views

      cast( '' as lifnr )                                                                                                     as lifnr, //<$fix>

      cast( '' as kunnr )                                                                                                     as kunnr, //<$fix>

      cast( bseg.hkont as hkont preserving type )                                                                             as hkont, //<$fix>

      cast( bseg.gkont as gkont preserving type )                                                                             as gkont, //<$fix>

      cast( bseg.gkart as gkart preserving type )                                                                             as gkart, //<$fix>


      // GENERATION ANCHOR FOR ALL REMAINING FIELDS

      // in BSEG_ADD, BKPF


      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy



//<$VU>

//<$UNIONS>

//<$VU>



      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy

      //context dummy


      // additional texts

      cast( coalesce( rprctr.ktext, cast( '' as fagl_text_prctr_short ) ) as fagl_text_prctr_short preserving type )          as rp_ktext,
      cast( coalesce( rprctr.ltext, cast( '' as fagl_text_prctr_long ) ) as fagl_text_prctr_long preserving type )            as rp_ltext,
      cast( coalesce( sprctr.ktext, cast( '' as fagl_text_pprctr_short ) ) as fagl_text_pprctr_short preserving type )        as sp_ktext,
      cast( coalesce( sprctr.ltext, cast( '' as fagl_text_pprctr_long ) ) as fagl_text_pprctr_long preserving type )          as sp_ltext,
      cast( coalesce( rfkbt.fkbtx, cast( '' as fagl_text_farea ) ) as fagl_text_farea preserving type )                       as rf_fkbtx,
      cast( coalesce( sfkbt.fkbtx, cast( '' as fagl_text_pfarea ) ) as fagl_text_pfarea preserving type )                     as sf_fkbtx,
      cast( coalesce( rkostl.ktext, cast( '' as fagl_text_ccntr_short ) ) as fagl_text_ccntr_short preserving type )          as cc_ktext,
      cast( coalesce( rkostl.ltext, cast( '' as fagl_text_ccntr_long ) ) as fagl_text_ccntr_long preserving type )            as cc_ltext,
      cast( coalesce( aufk.ktext, cast( '' as fagl_text_order_short ) ) as fagl_text_order_short preserving type )            as or_ktext,
      cast( coalesce( rmatnr.maktx, cast( '' as fagl_text_material ) ) as fagl_text_material preserving type )                as mm_maktx,
      cast( coalesce( hkont.txt20, cast( '' as fagl_text_gl_account_short ) ) as fagl_text_gl_account_short preserving type ) as ga_txt20,
      cast( coalesce( hkont.txt50, cast( '' as fagl_text_gl_account_long ) ) as fagl_text_gl_account_long preserving type )   as ga_txt50,
      cast( '' as fagl_text_saknr_short )                                                                                     as sk_txt20,
      cast( '' as fagl_text_saknr_long  )                                                                                     as sk_txt50
}