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

Native SQL - Get query

Former Member
0 Likes
807

Hi there,

I have many codes like this:

EXEC SQL.

  INSERT INTO T_ORACLE_TABLE ( field1, field2, field3 )

  VALUES ( :t_sap_table-field1, :t_sap_table-field2, :t_sap_table-field3 )

ENDEXEC.

This is just an example, but the real queries are bigger than that.

I would like to save this query with values in a Ztable, something like a string "insert into oracle_Table(field1,field2,field3) values('value1', 'value2', 'value3')".

Does anyone know if is it possible to get the query I'm doing?

1 ACCEPTED SOLUTION
Read only

raphael_almeida
Active Contributor
0 Likes
764

Why you just do not use the ADBC and tries to dynamically run your DML statements?


(Just a suggestion for improvements).


BR,


Raphael Pacheco.

4 REPLIES 4
Read only

juan_suros
Contributor
0 Likes
764

You can execute one or more pre-created queries in your Z table by doing the following steps:

1) Loop through the Z table of queries

2) for each query you want to execute, add five rows to a itab of code lines as follows:

code_itab = 'FORM one_of_n.'.      APPEND code_itab.

code_itab = 'EXEC SQL.'.           APPEND code_itab.

code_itab = '<query string here>'. APPEND code_itab.

code_itab = 'ENDEXEC.'.            APPEND code_itab.

code_itab = 'ENDFORM.'.            APPEND code_itab.

3) create a utility report containing your query using this command:


GENERATE SUBROUTINE POOL code_itab NAME zmy_utility MESSAGE errors.

4) Call each query in turn


PERFORM one_of_n   in PROGRAM z_my_utility CHANGING results.

PERFORM two_of_n   in PROGRAM z_my_utility CHANGING results2.

PERFORM three_of_n in PROGRAM z_my_utility CHANGING results3.




that should work nicely. Here are a couple of tips.



You might try defining "code_itab" as follows:


DATA: code_itab TYPE STANDARD TABLE OF tline-tdline.

See below for a complete solution to a simpler but similar problem:

Read only

raphael_almeida
Active Contributor
0 Likes
765

Why you just do not use the ADBC and tries to dynamically run your DML statements?


(Just a suggestion for improvements).


BR,


Raphael Pacheco.

Read only

0 Likes
764

Thanks for your suggestion, but I will not use ABDC because this is not a mine development. There is another guy who works with me and he doesn't know how to do that by himself, I just posted here to help him.

Thanks for your suggestion too, !

Read only

0 Likes
764

Thanks for your feedback.

Show to him the demo program called "ADBC_DEMO", it's a sample program what explain all statements using ADBC.

Warm regards,

Raphael Pacheco.