Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to use object value in SQL function?

former_member625844
Participant
0 Kudos

I want to query from table ztmm01 the value of column lp plus current month. So I wrote below code but it not work.

DATA:currmonth type i.
currmonth = sy-datum+4(2).
select matnr, ( lp + currmonth ) as p1 FROM ztmm01 where zorderdate = sy-datum INTO TABLE @DATA(t1) .

So can I use an object in SQL function or I have to first put query result to an itab then loop it and add month value? Thx.

4 REPLIES 4

alexis_scotts
Explorer
0 Kudos

A database object is an artefact such as a database table, an SQL view, or a stored procedure. As a rule, a database object is defined with the database’s DDL, e.g. with CREATE VIEW.

Read More - https://blogs.sap.com/2019/02/15/tadir-object-types-and-object-descriptions-via-sql/

Sandra_Rossi
Active Contributor
0 Kudos

Please don't say "it doesn't work", explain the symptom ("it does a syntax error, whose message is ...")

Also please provide correct code, it seems that you typed it manually directly in the forum with many typos.

If you use @ (i.e. strict syntax) then use it everywhere (currmonth, sy-datum).

currmonth or currentmonth?

former_member625844
Participant

@sandra.rossi. Ok. Looks like the reason is I didn't add @ to the currmonth. But normally when I miss an @, the error message is "all hosts must be escaped with @" but this one the error msg is "unknow column currmonth until runtime"

Sandra_Rossi
Active Contributor

In fact, the syntax checker can't know what currmonth can be, here it's guessing that it's merely a typo in the column name. Approximate messages are very common since the Strict SQL Syntax and Constructor Expressions, so you need to guess a lot.