How to check NOT NULL when calling RFC_READ_TABLE?

1k Views Asked by At

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'])
1

There are 1 best solutions below

5
Sandra Rossi On

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.