iT邦幫忙

0

SAP Query 語法錯誤

  • 分享至 

  • xImage

各位好

小弟在SAP Infoset寫了一段資料讀取的程式如下:

DATA: revenue like ce110tw-vvs10.
DATA: qty like ce110tw-vvq10.
SELECT
t1~kmvtnr,
t2~sname,
t1~kaufn,
t1~fadat,
t1~rbeln,
t1~artnr,
t1~prodh,
case
when @revenue > 0 then @revenue
else 0
END AS t1~salesamt,
case
when @revenue <= 0 then @revenue
else 0
END AS t1~reamt,
t1~vvs50,
t1~vvs60,
t1~vvs70,
case
when @revenue > 0 then @qty
else 0
END AS t1~saleqty,
case
when @revenue <= 0 then @qty
else 0
END AS t1~reqty
FROM ce110tw AS t1
LEFT JOIN pa0001 AS t2 ON t1~kmvtnr = t2~pernr
INTO CORRESPONDING FIELDS OF zsd_sales_rpt_emp
WHERE t1~fadat IN s_fadat.
APPEND zsd_sales_rpt_emp TO it_data.
ENDSELECT.

很困擾的是,如果我在欄位名稱後加上',',SAP會出現語法錯誤訊息:Comma without preceding colon (after SELECT ?).;如果我把','移除,SAP又會不認識第一個'case'指令,是否能請熟悉ABAP的專家協助小第修正這個問題?
謝謝!!

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2021-02-19 15:42:14

其實我不會 SAP
/images/emoticon/emoticon25.gif

參考這篇

SELECT num1, num2,
           CASE WHEN num1 <  50 AND num2 <  50 THEN @both_l
                WHEN num1 >= 50 AND num2 >= 50 THEN @both_gt
                ELSE @others
           END AS group
           FROM demo_expressions
           ORDER BY group
           INTO TABLE @DATA(results).

如果正確的話
一點一點改成你的指令

rogermou iT邦新手 5 級 ‧ 2021-02-19 16:25:33 檢舉

了解,謝謝!!

通靈亡 iT邦高手 1 級 ‧ 2021-02-19 17:35:11 檢舉

這個寫法有兩個地方要注意一下版本:

ABAP 7.40 SP 5 以前,在 SELECT 欄位之間使用逗號,必須在括號裡面,之後的版本開始支援 (Comma-Separated Lists),可以參考官方文件,和官方論壇的這個問題中,回答1的第二個評論

Commas have been allowed in SELECT statements in older versions, but only within parentheses, such as:
SELECT (carrid, connid, fldate) FROM sflight INTO.........

Comma-separated lists are now also possible in programs of ABAP language version Standard ABAP (Unicode) where the program attribute fixed point arithmetic is activated:
※ In the statement SELECT
When columns, aggregate expressions, or SQL expressions are specified in the SELECT list

能直接在 SELECT 欄位當中寫 Case When 是從 ABAP 7.4 SP08 開始支援:

The SQL expressions introduced with 7.40, SP05 into the SELECT list were enhanced with 7.40, SP08 as follows:

You can use SQL expressions after GROUP BY
You can use SQL expressions together with aggregates
You can use SQL expressions as argument of aggregates
You can use a seached CASE expression besides the simple CASE

https://blogs.sap.com/2014/10/08/abap-news-for-740-sp08-open-sql/

rogermou iT邦新手 5 級 ‧ 2021-03-17 14:53:23 檢舉

感謝通靈亡~~感恩~

我要發表回答

立即登入回答