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

Multiply with in select query

Former Member
0 Likes
1,543

Hi,

Could anyone let me know how to achieve below functionality,

Select Node1, (Node2 * 10) into table lt_node from Ztable.

Note: Here Ztable has more than 30K records and I need to select all the records.

Regards,

Raghu.

Hi,

Could anyone let me know how to achieve below functionality,

Select Node1, (Node2 * 10) into table lt_node from Ztable.

Note: Here Ztable has more than 30K records and I need to select all the records.

Regards,

Raghu.

8 REPLIES 8
Read only

Former Member
0 Likes
1,311

Hi Raghu,

You have to use native sql to achieve your requirement.

It is better you process the internal table as per your requirement and avoid native sql.

Read only

0 Likes
1,311

Hello Raheem,

For of all Eid Mubarak !!!

Thanks for your reply. I have been trying native SQL but am getting dump saying 102 error. Will the native SQL depend on DB of my server, we use Oracle DB..

Regards

Raghu

Read only

former_member184158
Active Contributor
0 Likes
1,311

Hello Raghu, Raheem,

I wish you Eid Mubarak .

Could you post your code please.

Regards

Ibrahim

Read only

Former Member
0 Likes
1,311

Hi,

You can check this sample code for native Oracle Sql for Multiply

TYPES: BEGIN OF ty,
          id TYPE N,
          description TYPE C LENGTH 50,
          amount type i,
        END OF TY.

DATA: WA type TY,
       itab type STANDARD TABLE OF ty.

EXEC SQL.
   CONNECT TO 'MYCONNECTION'
ENDEXEC.

EXEC SQL.
   OPEN C FOR
   SELECT ID, DESCRIPTION, NVL(AMOUNT,0) * 10
   FROM  TEST
ENDEXEC.

DO.
   EXEC SQL.
     FETCH NEXT C INTO :wa
   ENDEXEC.
   IF sy-subrc <> 0.
     EXIT.
   ENDIF.
   APPEND wa TO itab.
ENDDO.

EXEC SQL.
   CLOSE C
ENDEXEC.

EXEC SQL.
   DISCONNECT :'MYCONNECTION'
ENDEXEC.

LOOP AT ITAB INTO WA.
   WRITE: / WA-ID, WA-DESCRIPTION, WA-AMOUNT.
ENDLOOP.

Read only

0 Likes
1,311

Hi Abdul,

could you please provide another example with loop , just to avoid native sql?

Read only

0 Likes
1,311

hi Ibrahim,

I don't think there is any other method to multiply field.

In Open SQL it is not possible and therefore you have to process internal table only.

In Native SQL only it is possible as per above demo code.

If you find any other method then please share.

thanks.

Read only

0 Likes
1,311

Could you please give me another example with actual SAP table and fields

Regards

Raghu

Read only

0 Likes
1,311

Hi Raghu,

This is another example using SAP table Mara.

Only connection with the schema SAPSR3 is important.

TYPES: BEGIN OF ty,
          MATNR TYPE MATNR,
          BRGEW TYPE BRGEW,
        END OF TY.

DATA: WA type TY,
       itab type STANDARD TABLE OF ty.

EXEC SQL.
   CONNECT TO 'MYCONN2'
ENDEXEC.

EXEC SQL.
   OPEN C FOR
   SELECT MATNR, NVL(BRGEW,0) * 1000
   FROM  MARA
   WHERE ROWNUM <= 20
ENDEXEC.

DO.
   EXEC SQL.
     FETCH NEXT C INTO :wa
   ENDEXEC.
   IF sy-subrc <> 0.
     EXIT.
   ENDIF.
   APPEND wa TO itab.
ENDDO.

EXEC SQL.
   CLOSE C
ENDEXEC.

EXEC SQL.
   DISCONNECT :'MYCONN2'
ENDEXEC.

LOOP AT ITAB INTO WA.
   WRITE: / WA-MATNR, WA-BRGEW.
ENDLOOP.