on 2025 May 07 7:45 PM
Hello,
We are working on a project where a SQL developer created plenty of hardcoded cases. Here's an example
CASE WHEN p.[TransportationGroup] IN ('0004', '0005', '0006') THEN '3'
WHEN p.[TransportationGroup] IN ('0007', '0008') THEN '2'
WHEN p.[TransportationGroup] IS NULL THEN NULL
ELSE '1'
END AS [SimplePackingCode]
I would like to avoid such and can quite easily creae a local table (based on csv files) that would look like this.
Request clarification before answering.
The ABAP logic that pushes down to HANA should be in the right direction, so you may try the CDS function(CASE, WHEN...), if you don`t have CDS, create one... 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a Sample on how it could work, I used no tables so that it works on every SQL, but this is a 2-config-table solution, so quite some work, there are over 100 of such cases in his "solution"
SELECT S1.Product
, S1.Cat
, S3.Final
, S4.Final
, CASE WHEN S1.Cat IS NOT NULL AND S3.Final IS NULL THEN S4.Final ELSE S3.Final END AS RealFinal
FROM (SELECT 'X1' AS Product, '0002' AS Cat
UNION ALL
SELECT 'X2' AS Product, '0002' AS Cat
UNION ALL
SELECT 'X3' AS Product, '0003' AS Cat
UNION ALL
SELECT 'X4' AS Product, NULL AS Cat
UNION ALL
SELECT 'X5' AS Product, '9999' AS Cat
) S1
LEFT JOIN (SELECT *
FROM (SELECT '0002' AS Cat, '22' AS Final
UNION ALL
SELECT '0003' AS Cat, '33' AS Final
UNION ALL
SELECT '_NULL_' AS Cat, NULL AS Final
) S2
) S3 ON S3.Cat = COALESCE(S1.CAT,'_NULL_')
CROSS JOIN (SELECT '_ELSE_' AS Cat, '00' AS Final
) S4
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 13 | |
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.