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

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)
}
...

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

Group by catid SQL result in a selectbox

I have a RSform (3.0.18) in Joommla (3.10.9) on server PHP (7.4.21).
One of the fields is a Dropdown (no multiselect) with a query SQL to get article from catid 15 OR 16. Thhe code below is given by RSForm documentation and adapted to my need.
//<code>
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Sélectionnez...[c]";
// Run the SQL query and store it in $results
$db->setQuery("SELECT id, title FROM #__content WHERE catid = 15 or catid = 16");
$results = $db->loadObjectList();
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
$value = $result->id;
$label = $result->title;
$items[] = $value.'|'.$label;
}
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
// Now we need to return the value to the field
return $items;
//</code>
The query works and I get a result like :
Sélectionnez...
Introduction aux médias et à la prise de parole en public
Réussir une prise de parole
Réussir une interview
Médiatraining élus
But I would like it group by catid, which could give something like :
Sélectionnez...
Enterprises formations (not selectable)
Introduction aux médias et à la prise de parole en public
Réussir une prise de parole
Réussir une interview
Administrations formations (not selectable)
Médiatraining élus
Any advice to help writing this ?
Thanks in advance...

Get Wikipedia page paragraph from API

How to get paragraph page from Wikipedia API ?
For instance, I'd like to get the following paragraph:
https://fr.wikipedia.org/wiki/Douarnenez#Urbanisme
I'm only able to get the entire page with:
https://fr.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&titles=Douarnenez&formatversion=2&rvprop=content&rvslots=*
Credits: answer to: How to get a text of a specific section via wikipedia api - by Florian
I followed these steps in order to get the information you need.
First, get the index of the section you want to get - for that, use this endpoint for get the sections of the wiki page:
https://fr.wikipedia.org/w/api.php?action=parse&format=json&page=Douarnenez&prop=sections
Here is the API sandbox link you can try out.
In your specific case, I believe it's index=10:
{
"toclevel": 2,
"level": 3,
"line": "Typologie",
"number": "3.1",
"index": "10",
"fromtitle": "Douarnenez",
"byteoffset": 18641,
"anchor": "Typologie"
}
Then, use this next endpoint for get the text in the given section:
https://fr.wikipedia.org/w/api.php?action=parse&format=json&page=Douarnenez&prop=wikitext&section=10&disabletoc=1&utf8=1
The result is as follows - here is the link of the API sandbox:
{
"parse": {
"title": "Douarnenez",
"pageid": 4596068,
"wikitext": {
"*": "=== Typologie ===\nDouarnenez est une commune urbaine, car elle fait partie des communes denses ou de densité intermédiaire, au sens de la grille communale de densité de l'[[Institut national de la statistique et des études économiques|Insee]]<ref group=Note>Selon le zonage des communes rurales et urbaines publié en novembre 2020, en application de la nouvelle définition de la ruralité validée le {{date-|14 novembre 2020}} en comité interministériel des ruralités.</ref>{{,}}<ref >{{Lien web |url=https://www.observatoire-des-territoires.gouv.fr/typologie-urbain-rural |titre=Typologie urbain / rural |site=observatoire-des-territoires.gouv.fr |consulté le= 26 mars 2021}}.</ref>{{,}}<ref >{{Lien web |url=https://www.insee.fr/fr/metadonnees/definition/c1472|titre=Commune urbaine - définition |site=Insee.fr|consulté le= 26 mars 2021}}.</ref>{{,}}<ref >{{Lien web |url= https://www.observatoire-des-territoires.gouv.fr/methodes/comprendre-la-grille-de-densite|titre= Comprendre la grille de densité|site=observatoire-des-territoires.gouv.fr |consulté le= 26 mars 2021}}.</ref>. \nElle appartient à l'[[unité urbaine]] de Douarnenez, une unité urbaine monocommunale<ref>{{Lien web|url=https://www.insee.fr/fr/metadonnees/cog/unite-urbaine/UU202029306-douarnenez |titre=Unité urbaine 2020 de Douarnenez|site=insee.fr|consulté le= 26 mars 2021}}.</ref> de {{Unité|13902|habitants}} en 2017, constituant une ville isolée<ref name=\"UU2020\">{{Lien web|url=https://www.insee.fr/fr/information/4802589 |titre=Base des unités urbaines 2020 |date=21 octobre 2020|site=insee.fr |consulté le= 26 mars 2021}}.</ref>{{,}}<ref name=\"UU20202b\">{{Lien web|url=https://www.insee.fr/fr/statistiques/4806684 |titre=Toujours plus d’habitants dans les unités urbaines |auteur=Vianney Costemalle |date=21 octobre 2020 |site=insee.fr |consulté le= 26 mars 2021}}.</ref>."
}
}
}
You can use Regex to filter out your paragraph. That's not beautiful, but works.
For example:
((?<=== Urbanisme ==).*?(?=\\n== ))
This selects everything starting behind the headline of the Urbanism paragraph and ending before the next paragraph headline. See: https://regex101.com/r/LlGSay/1

SQL - JOIN and SUBQUERY

I'm trying to make a join in 2 tables (stg.ac_esb and stg.ac_eeb), both have emp_codigo, so im using this column to set the relation. But,when i try to extract the data from the join's result, the error says: ERROR: column reference "emp_codigo" is ambiguous. Can anyone help me with this plssss!
`SELECT
**emp_codigo** as NUMEMP /* Código da Empresa SIM*/
, epg_codigo as TIPCOL /* Tipo do Colaborador SIM*/
, ' ' as NUMCAD /* Cadastro do Colaborador SIM*/
, dtinicial as INIETB /* Data de Início da Estabilidade SIM */
, dtfinal as FIMETB /* Data Final da Estabilidade NÃO */
, codigo as CODETB /* Código da Estabilidade SIM */
FROM
(SELECT *
FROM stg.ac_esb
JOIN stg.ac_eeb
ON ac_esb.emp_codigo = ac_eeb.emp_codigo) AS Estabilidades;`
You can simplify your query ans qualify the emp_codigo column with the specific table where you want this value to come from. For example:
SELECT
ac_esb.emp_codigo as NUMEMP /* Código da Empresa SIM*/
, epg_codigo as TIPCOL /* Tipo do Colaborador SIM*/
, ' ' as NUMCAD /* Cadastro do Colaborador SIM*/
, dtinicial as INIETB /* Data de Início da Estabilidade SIM */
, dtfinal as FIMETB /* Data Final da Estabilidade NÃO */
, codigo as CODETB /* Código da Estabilidade SIM */
FROM stg.ac_esb
JOIN stg.ac_eeb
ON ac_esb.emp_codigo = ac_eeb.emp_codigo
Note: There may be more columns with duplicate names, so make sure you prepend each one with the table name where it belong to.

Prestashop bring cart content to the front page

I want to remove cart button and display the added items to the cart in the top of the page. So it's always visible
So far I have no luck of finding the function I need to override. tried searching in ps_shoppingcart.php
maybe someone knows exactly what should I do to accomplish this mission.
Pour retirer le bouton du panier il faut "décrocher" le hook du bouton du panier dans "Apparence > Positions"
Pour la liste des articles, le plus simple serait de créer un petit module qui prendrait en charge un hook pour "s'accrocher" a la place du bouton du panier, et qui listerait les elements du panier (avec un foreach par exemple)

SQL • Result of join in an array

Good evening,
Here is my problem: I make a select query on my table PROJECT to select (for now) my only test project. I do a join on the table to retrieve screenshots SCREENSHOT associated with it. Only he will get out as many results as there are screenshots! Ie here 5.
Could I go back to more data (name, datesortie, description, etc.) an associative array urls screenshots?
Or would you have a solution to simplify my life? Because the only solution I see is treating it directly in php.
Here is my query:
SELECT P.nom, datesortie, description, lien, icone, tag, S.url
FROM PROJET P
LEFT JOIN CLIENT C
ON C.idclient = P.idclient
LEFT JOIN SCREENSHOT S
ON S.idprojet = P.idprojet
ORDER BY P.nom
Here is what is returned (Sorry, my var_dump shows me that online ... I do not understand why):
array(7) { ["nom"]=> string(10) "BlackStars" ["datesortie"]=> string(10) "2012-07-02" ["description"]=> string(498) "Inspiré par Little Stars for Little Wars, Black Stars se veut être meilleur par bien des aspects. Prenez le contrôle d'une planète et partez à la conquête de l'univers en remportant chacune des batailles, en brisant chacune des planètes ennemies, en devenant le meilleur joueur. Car une fois le mode solo terminé, un mode multi-joueurs (Bluetooth ou Game Center) vous attend afin de vous mesurer au monde entier. Hissez-vous en haut du classement et devenez le maître incontesté de Black Stars. " ["lien"]=> string(69) "http://itunes.apple.com/us/app/black-stars/id512945753?l=fr&ls=1&mt=8" ["icone"]=> string(131) "http://a1775.phobos.apple.com/us/r30/Purple/v4/73/47/b7/7347b764-cff9-c52b-78da-42560a187acf/mza_1097997557772736292.170x170-75.png" ["tag"]=> string(10) "blackstars" ["url"]=> string(119) "http://a1352.phobos.apple.com/us/r30/Purple/v4/51/df/f5/51dff56b-08c6-59db-81df-80a174ec0050/mza_509496145749890361.png" }
===================================================
===================================================
array(7) { ["nom"]=> string(10) "BlackStars" ["datesortie"]=> string(10) "2012-07-02" ["description"]=> string(498) "Inspiré par Little Stars for Little Wars, Black Stars se veut être meilleur par bien des aspects. Prenez le contrôle d'une planète et partez à la conquête de l'univers en remportant chacune des batailles, en brisant chacune des planètes ennemies, en devenant le meilleur joueur. Car une fois le mode solo terminé, un mode multi-joueurs (Bluetooth ou Game Center) vous attend afin de vous mesurer au monde entier. Hissez-vous en haut du classement et devenez le maître incontesté de Black Stars. " ["lien"]=> string(69) "http://itunes.apple.com/us/app/black-stars/id512945753?l=fr&ls=1&mt=8" ["icone"]=> string(131) "http://a1775.phobos.apple.com/us/r30/Purple/v4/73/47/b7/7347b764-cff9-c52b-78da-42560a187acf/mza_1097997557772736292.170x170-75.png" ["tag"]=> string(10) "blackstars" ["url"]=> string(119) "http://a572.phobos.apple.com/us/r30/Purple/v4/db/1d/1d/db1d1d00-3a28-8b6f-d52f-342bf5893912/mza_3642427234916705950.png" }
===================================================
===================================================
array(7) { ["nom"]=> string(10) "BlackStars" ["datesortie"]=> string(10) "2012-07-02" ["description"]=> string(498) "Inspiré par Little Stars for Little Wars, Black Stars se veut être meilleur par bien des aspects. Prenez le contrôle d'une planète et partez à la conquête de l'univers en remportant chacune des batailles, en brisant chacune des planètes ennemies, en devenant le meilleur joueur. Car une fois le mode solo terminé, un mode multi-joueurs (Bluetooth ou Game Center) vous attend afin de vous mesurer au monde entier. Hissez-vous en haut du classement et devenez le maître incontesté de Black Stars. " ["lien"]=> string(69) "http://itunes.apple.com/us/app/black-stars/id512945753?l=fr&ls=1&mt=8" ["icone"]=> string(131) "http://a1775.phobos.apple.com/us/r30/Purple/v4/73/47/b7/7347b764-cff9-c52b-78da-42560a187acf/mza_1097997557772736292.170x170-75.png" ["tag"]=> string(10) "blackstars" ["url"]=> string(120) "http://a1701.phobos.apple.com/us/r30/Purple/v4/60/5f/ae/605fae3e-f00b-c3b7-0f65-ca73f6fd9864/mza_4565911160744621776.png" }
===================================================
===================================================
array(7) { ["nom"]=> string(10) "BlackStars" ["datesortie"]=> string(10) "2012-07-02" ["description"]=> string(498) "Inspiré par Little Stars for Little Wars, Black Stars se veut être meilleur par bien des aspects. Prenez le contrôle d'une planète et partez à la conquête de l'univers en remportant chacune des batailles, en brisant chacune des planètes ennemies, en devenant le meilleur joueur. Car une fois le mode solo terminé, un mode multi-joueurs (Bluetooth ou Game Center) vous attend afin de vous mesurer au monde entier. Hissez-vous en haut du classement et devenez le maître incontesté de Black Stars. " ["lien"]=> string(69) "http://itunes.apple.com/us/app/black-stars/id512945753?l=fr&ls=1&mt=8" ["icone"]=> string(131) "http://a1775.phobos.apple.com/us/r30/Purple/v4/73/47/b7/7347b764-cff9-c52b-78da-42560a187acf/mza_1097997557772736292.170x170-75.png" ["tag"]=> string(10) "blackstars" ["url"]=> string(119) "http://a193.phobos.apple.com/us/r30/Purple/v4/7c/ff/67/7cff67dc-d679-16ee-24cf-7f658c78b9c8/mza_8709328453215958742.png" }
===================================================
===================================================
array(7) { ["nom"]=> string(10) "BlackStars" ["datesortie"]=> string(10) "2012-07-02" ["description"]=> string(498) "Inspiré par Little Stars for Little Wars, Black Stars se veut être meilleur par bien des aspects. Prenez le contrôle d'une planète et partez à la conquête de l'univers en remportant chacune des batailles, en brisant chacune des planètes ennemies, en devenant le meilleur joueur. Car une fois le mode solo terminé, un mode multi-joueurs (Bluetooth ou Game Center) vous attend afin de vous mesurer au monde entier. Hissez-vous en haut du classement et devenez le maître incontesté de Black Stars. " ["lien"]=> string(69) "http://itunes.apple.com/us/app/black-stars/id512945753?l=fr&ls=1&mt=8" ["icone"]=> string(131) "http://a1775.phobos.apple.com/us/r30/Purple/v4/73/47/b7/7347b764-cff9-c52b-78da-42560a187acf/mza_1097997557772736292.170x170-75.png" ["tag"]=> string(10) "blackstars" ["url"]=> string(120) "http://a1443.phobos.apple.com/us/r30/Purple/v4/d7/13/8f/d7138f62-6398-7993-8d0b-23e0ce16dca2/mza_8316005873463209973.png" }
===================================================
===================================================
Thank you in advance for your help.
Cordially.
From what I gather, you just don't want all that repeating information in the first 6 fields?
Normally, accepting the repeating information is the way to go about it. But, you could pull back two record sets. Provided that they're neatly ordered you can do a nested loop to process them.
SELECT P.nom, datesortie, description, lien, icone, tag, idproject
FROM PROJET P
LEFT JOIN CLIENT C
ON C.idclient = P.idclient
LEFT JOIN SCREENSHOT S
ON S.idprojet = P.idprojet
ORDER BY P.nom
SELECT P.idproject S.url
FROM PROJET P
INNER JOIN SCREENSHOT S
ON S.idprojet = P.idprojet
ORDER BY P.nom
Note: The first query now also has the idproject field, which is also present in the second record set. The second record set is also ordered by P.nom, even though it's not selected in the statement; this just ensures that you can do a simple nested loop.
A simplifies pseudo-code could be...
FOR EACH nom IN recordSet1
WHILE recordSet1.idProject = recordSet2.idProject
Do something with the URL
Move to next record in recordSet2
LOOP
LOOP
What I would not do
Another option is to concatenate all of the URLs together into a single string. Perhaps separated by commas to make a CSV field.
But then the existence of a comma in the url will break that. So you probably then want to use XML or something; with added costs to generate and parse.
Unless the network overhead of the repeated fields is actually causing a problem, I would stick to that. And if it is causing a problem, the two-record-set alternative is more robust and relatively simple.