add columns in a CDS view and fill it with a condition

Viewed 1302

I have been trying for several days, in a cds view, to convert a row of the acdoca table (here the amount of a debit/credit transaction, the hsl attribute in acdoca), into two columns debit and credit.

The amount of a transaction would go into a column depending on the type of debit/credit (attribute drcrk in acdoca which returns H for a debit or S for a credit). Is there a solution to my problem or a doc accessible to a beginner to solve this problem (PS I don't know ABAP so if you have a solution using it is it possible to describe where and how to integrate it to Eclipse).

I tried to declare a direct attribute in the view, to alter the view, but all this does not work. I have been told about the possibility of using a functional table, which seems to work, but I can't structure it correctly just in the typing of my tables.

I can pass my view if necessary.

 define view Z_test_dc as select from acdoca 
inner join  bseg on acdoca.rbukrs = bseg.bukrs 
                and bseg.belnr    = acdoca.belnr 
                and bseg.gjahr    = acdoca.gjahr 
                and bseg.buzei    = acdoca.buzei
left outer join but000 on but000.partner = acdoca.kunnr
left outer join t003t   on t003t.blart   = acdoca.blart
{
    key acdoca.rbukrs,       //Société
    key acdoca.gjahr,        //Exercice comptable
    key acdoca.belnr,        //Numéro de pièce comptable
    key acdoca.racct,        //Numéro de compte    
    key acdoca.docln,        //Ligne d'écriture à six caractères pour ledger
        acdoca.kunnr,        //Client        
        acdoca.fiscyearper,  //Période/exercice
        acdoca.augbl,        //Nº pièce rapprochement
        acdoca.bldat,        //Date de la pièce
        acdoca.budat,        //Date comptable du document
        acdoca.blart,        //Type de pièce
        t003t.ltext,         //Description type de pièce
        acdoca.hsl,          //Montant en devise société
        acdoca.rhcur,        //Devise société
        acdoca.netdt,        //Date echéance nette
        bseg.madat,          //Data de la dernière relance
        bseg.mansp,          //Blocage relance
        bseg.manst,          //Niveau de relance   
        bseg.zterm,          //Conditions de paiement
        but000.bu_group,     //le regroupement du client
        bseg.valut,          //Date valeur delais
        bseg.sgtxt,          //Texte descriptif postes
        acdoca.drcrk         //type debit/credit (return H ou S)        
}
... 
1 Answers

I didn't think it was possible, because I had thought that an alias as just a renamed of my column, but with the right syntax the box works fine here is the code I rendered thanks for your help.

    define view VIEW as select from acdoca
     inner join  bseg on acdoca.rbukrs = bseg.bukrs 
            and bseg.belnr    = acdoca.belnr 
            and bseg.gjahr    = acdoca.gjahr 
            and bseg.buzei    = acdoca.buzei
     left outer join but000 on but000.partner = acdoca.kunnr
     left outer join t003t   on t003t.blart   = acdoca.blart {
     key acdoca.rbukrs,       //Société
     key acdoca.gjahr,        //Exercice comptable
     key acdoca.belnr,        //Numéro de pièce comptable
     key acdoca.racct,        //Numéro de compte    
    
    key acdoca.docln,        //Ligne d'écriture à six caractères pour ledger
    acdoca.kunnr,        //Client        
    acdoca.fiscyearper,  //Période/exercice
    acdoca.augbl,        //Nº pièce rapprochement
    acdoca.bldat,        //Date de la pièce
    acdoca.budat,        //Date comptable du document
    acdoca.blart,        //Type de pièce
    t003t.ltext,         //Description type de pièce
    acdoca.hsl,          //Montant en devise société
    acdoca.rhcur,        //Devise société
    acdoca.netdt,        //Date echéance nette
    bseg.madat,          //Data de la dernière relance
    bseg.mansp,          //Blocage relance
    bseg.manst,          //Niveau de relance   
    bseg.zterm,          //Conditions de paiement
    but000.bu_group,     //le regroupement du client
    bseg.valut,          //Date valeur delais
    bseg.sgtxt,          //Texte descriptif postes
    acdoca.drcrk,       //type debit/credit (return H ou S)   

case acdoca.drcrk when   'H' then    acdoca.hsl  else 0  end as debit,
case acdoca.drcrk when   'S' then   acdoca.hsl else 0 end as credit
}'
Related