Application Development and Automation 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: 
Read only

Doing Calculation in Select and Write Stament

Former Member
0 Likes
1,416

Hi,

I have worked quite a lot on Oracle Database Programming. I am tring to do some programming in ABAP , but its failing to do so. What is the normal way of calculating the fields in the ABAP.

Take for Eg below table structure.

Table Name: YSALESTAB. (Sales Table)

Field: ORDERNO (Order Number)

PRODNO (Product Number)

UNITPR (Unit Price)

QTYORD (Qty Ordered)

Question A): I am executing the following select.

SELECT ORDERNO UNITPR QTYORD, <b>UNITPR*QTYORD</b> from YSALESTAB.

WRITE .......

ENDSELECT.

But it is not allowing me to select calculated field. Is there any way in the select statement to use calculated field or I will have to go with other workaround like defining local variable and doing calculation on that variable?

Question B): Is there any way to write out calculated fields in write statement.

eg data : int1 type i value 3, int2 type i value 4.

write 😕 'Values are ', int1 * int2.

Regards

Mitesh

1 ACCEPTED SOLUTION
Read only

sergey_korolev
Active Contributor
0 Likes
681

Hi Mitesh,

Unfotunately there is no possibility to use calcualted fields in an ABAP Open SQL query. Also ABAP has a rudimentary syntax concerning expressions: you cannot use calculated expressions almost anywhere except the right side of an assignment statement. In your question 2 you have to use some intermediate variable.

3 REPLIES 3
Read only

sergey_korolev
Active Contributor
0 Likes
682

Hi Mitesh,

Unfotunately there is no possibility to use calcualted fields in an ABAP Open SQL query. Also ABAP has a rudimentary syntax concerning expressions: you cannot use calculated expressions almost anywhere except the right side of an assignment statement. In your question 2 you have to use some intermediate variable.

Read only

0 Likes
681

Hi Sergei,

Thanks for the reply..

Regards

Mitesh

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
681

Hi ,

try this

types : begin of ty_mara,

matnr type mara-matnr,

quan type n,

end of ty_mara.

DATA: BEGIN OF WA,

matnr type mara-matnr,

quan type n,

END OF WA.

data v_matnr type mara-matnr.

v_matnr = '000000000000000033'.

EXEC SQL.

select matnr, ntgew*3 into :wa from

mara where matnr = :v_matnr

ENDEXEC.

write 😕 wa-matnr, wa-quan.

Hope this help.