1

I am trying to get data by using python connect SAP system. Here I have question about how to filter one specific field IS NOT EMPTY?

For example below, how to filter the field QNAME is not empty. In SAP, we can easily set. Thanks a lot!

table = 'LTAP'
options = [{ 'TEXT': "LGNUM = '586'" and "VLTYP = 'GPA'" and "NLTYP = 'PD2'"}]
fields = ['TANUM','VLTYP','VLPLA','NLTYP','NLPLA','QDATU','QNAME']
pp = PrettyPrinter(indent=4)
rowskips = 0

print("----Begin of Batch---")
result = conn.call("RFC_READ_TABLE",
QUERY_TABLE = table, 
DELIMITER='|',
FIELDS = fields,\
OPTIONS = options,
ROWSKIPS = rowskips, 
ROWCOUNT = 50 )
pp.pprint(result['DATA'])
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
felix12
  • 11
  • 4

1 Answers1

1

In ABAP SQL (A.K.A. Open SQL), "not equal" corresponds to the operator <>. With pyrfc, it will be:

options = [{ 'TEXT': "QNAME <> '' and LGNUM = '586' and VLTYP = 'GPA' and NLTYP = 'PD2'"},
{ 'TEXT': " and QDATU = '20160422'" }]

Note that there are two lines because TEXT is only 72 characters in RFC_READ_TABLE. If you have more than 72 characters, split the condition into several lines, like explained here, i.e. RFC_READ_TABLE will pad each line with spaces to obtain exactly 72 characters, and will collate all the lines without any transformation to form the WHERE clause.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • THANK YOU! Do you know how to get and filter the current date field QDATU? (get the yesterday's date.) Thank you in advance!!! – felix12 Jun 18 '21 at 05:07
  • In databases connected to ABAP-based systems, date fields correspond to a YYYYMMDD CHAR format, and it's always expressed according to Gregorian calendar. So, yesterday, June 17th, 2021, corresponds to the text `20210617`. – Sandra Rossi Jun 18 '21 at 05:51
  • You mean like this?: options = [{ 'TEXT': "QNAME <> '' and LGNUM = '586' and VLTYP = 'GPA' and NLTYP = 'PD2' and QDATU = '20160422'"}] – felix12 Jun 18 '21 at 06:19
  • thank you! I tried to add the option QDATU = '20160422', and then I got error msg. did you mean that after each condition, there should be a new line to split them? like this? options = [{ 'TEXT': "QNAME <> '' and /*new line*/ LGNUM = '586' and /*new line*/ VLTYP = 'GPA' and.... – felix12 Jun 18 '21 at 08:21
  • I completed my answer, I hope it will clarify. – Sandra Rossi Jun 18 '21 at 16:38