Skip to Content
avatar image
Former Member

Looking for help with new Open SQL Features

I want to return the material description in the user's logon language. If it doesn't exist return the English version. The following works, it seems with the new features available (we are on 7.5) there should be a more elegant solution. Any ideas ?

SELECT mara~matnr,
CASE WHEN lng~maktx IS NOT NULL THEN lng~maktx
ELSE eng~maktx
END AS desc
FROM mara
LEFT OUTER JOIN makt AS eng
ON eng~matnr = mara~matnr
AND eng~spras = 'E'
LEFT OUTER JOIN makt AS lng
ON lng~matnr = mara~matnr
AND lng~spras = @sy-langu
WHERE mara~matnr IN @s_matnr
INTO TABLE @DATA(m).

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jul 14, 2017 at 09:26 AM

    The only thing that I can think of is replacing case/when with coalesce.

    Something like

    Sathya

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 13, 2017 at 07:41 PM

    Not sure if there's something on 7.50. On 7.51 CTEs might be useful for this:

    https://blogs.sap.com/2016/10/18/abap-news-release-7.51-common-table-expressions-cte-open-sql/

    I don't have access to a 7.51 system but I assume something along those lines should work?

    WITH
      +texts AS (
        SELECT ktext, CASE WHEN langu = 'E' THEN 2 ELSE 1 END AS order
          FROM tcurt
          UP TO 1 ROWS
          WHERE spras IN ('E', @sy-langu )
          ORDER BY order ASCENDING
      )
      SELECT tcurc~waers, t~ktext
        FROM tcurc
        LEFT OUTER JOIN +texts AS t ON tcurc~waers = t~waers
        INTO TABLE @DATA(gt_waers).
    
    Add comment
    10|10000 characters needed characters exceeded

  • Jul 13, 2017 at 08:07 PM

    More elegant? Hello, in SQL? ;-)

    Add comment
    10|10000 characters needed characters exceeded