0

I am new to python. I want to pull data from SAP System. I have created a connection with SAP system using below code and trying to pull data using SQL query:

select col1,col2,col3 from table_name where col1= 2019

Program:

    import pyrfc
    from pyrfc import Connection

    conn = Connection(ashost='myhost', sysnr='00', client='000', user='xxx', passwd='***')

    fields = ['col1','col2','col3']

    table = 'table_name'

    where = ['col1=2019']

    MaxRows =5

    fromrow = 0

    tables = conn.call("RFC_READ_TABLE", QUERY_TABLE=table, FIELDS = fields,OPTIONS=where,ROWCOUNT = MaxRows,ROWSKIPS=fromrow)

Is there any direct way to write SQL query (how we write in Oracle/SQL)?

The above code gives data in dict form and runs very slow.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

0

is there any direct way to write sql query

no. PyRFC is not intended for direct SQL queries, it can only call existing SAP RFC-modules.

What concerns function modules which eats pure SQL look at the function groups RSDU_SQL_XXX

enter image description here

if we speak about Oracle DB then it is RSDU_EXEC_SQL_ORA module and generic RSDU_EXEC_SQL.

However, they are not RFC so cannot be used with PyRFC without some alteration, so you need an ABAP developer or you are out of the luck.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • thank you ..just need one more info..If I need to select all columns from table , what to mention in Fields variable. If I give blank , it ask for list. Also how to give multiple where condition with AND. – Sapna Basantani Jun 10 '20 at 09:51
  • I want also to run this statement: select * from table where col1 = value and col2= value and col3= value I wrote: fields = [''] table = 'table' where = [ 'col1 = value and col2= value and col3= value'] ABAPApplicationError: RFC_ABAP_EXCEPTION (rc=5): key=FIELD_NOT_VALID, message= Number:000 [MSG: class=, type=, number=000, v1-4:=;;;] – Sapna Basantani Jun 10 '20 at 10:09
  • to the FIELDS you should pass fieldnames, not the empty list. There are number examples of RFC_READ_TABLE on SO, for example [this one](https://stackoverflow.com/questions/27633332/rfc-read-table-passing-options-and-fields-parametrs-c) – Suncatcher Oct 08 '20 at 06:14