Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Passing args to sap function

Help
mentat
2010-12-16
2013-04-11
  • mentat
    mentat
    2010-12-16

    Hello.

    I make a simple module to call a sap query (sq00 transaction) with RSAQ_REMOTE_QUERY_CALL.
    But I have a problem, I can't pass args to limit the lines returns. In the example, I test with a single material.
    But I get this :
    Traceback (most recent call last):
      File "sap_query.py", line 41, in <module>
        s.getQuery('AA_WH_MM','EMPLACEMN_STKS')
      File "sap_query.py", line 25, in getQuery
        EXTERNAL_PRESENTATION="X", DATA_TO_MEMORY="X")
      File "c:\usr\python25\lib\site-packages\pysap.py", line 1380, in __call__
        raise SapRfcError(excep.value)
    pysap.SapRfcError: 'SYSTEM_FAILURE'

    import pysap
    class Sap(object):
        def __init__(self):
            # Connection with sapconn.ini
            # Note: the LANG parameter can be added in sapconn.ini
            self.conn = pysap.Rfc_connection(conn_file='sapconn.ini',
                conn_name='Exploitation')
            self.conn.open()
        def getQuery(self, usergroup, query):
            """Run a query found in sq00 transaction"""
            q = self.conn.get_interface('RSAQ_REMOTE_QUERY_CALL', include_desc=1,
                func_args=['USERGROUP','QUERY','SKIP_SELSCREEN',
                    'EXTERNAL_PRESENTATION','DATA_TO_MEMORY'],
                func_res=['LDATA','SELECTION_TABLE'])
            # In this example, it's a warehouse management query (stock of material)
            # So, we want to get only one material (119004)
            tbl = q['SELECTION_TABLE']
            tbl.append_from_dict({'SELNAME':'SP$00005','KIND':'S','LOW':'119004'})
            print q['SELECTION_TABLE'].to_list()
            q(USERGROUP=usergroup, QUERY=query, SKIP_SELSCREEN="X",
                    EXTERNAL_PRESENTATION="X", DATA_TO_MEMORY="X")
            print q['LDATA'].to_list()
        def getQuerySelectionFields(self, usergroup, query):
            select = self.conn.get_interface('RSAQ_REMOTE_QUERY_FIELDLIST',
                    include_desc=1, func_args=['USERGROUP','QUERY'],
                    func_res=['SEL_FIELDS'])
            res = select(USERGROUP=usergroup, QUERY=query)
            fields = select['SEL_FIELDS'].to_list()
            print fields
        def __del__(self):
            self.conn.close()
    if __name__ == '__main__':
        s=Sap()
        s.getQuery('AA_WH_MM','EMPLACEMN_STKS')
    #vim:encoding:utf8
    
     
  • mentat
    mentat
    2010-12-16

    Ok, I have found an issue in my code. It lack some options. The bad line is :

    tbl.append_from_dict({'SELNAME':'SP$00005','KIND':'S','LOW':'119004'})
    

    It must be :

    tbl.append_from_dict({'SELNAME':'SP$00005','KIND':'S','LOW':'119004','OPTION':'EQ','SIGN':'I'})
    

    It work with alphanumeric code (MAT05 for example) not for numeric (119004).

     
  • ao60661
    ao60661
    2011-06-16

    "It work with alphanumeric code (MAT05 for example) not for numeric (119004)."
    The material number (see table MARA, field MATNR) in SAP ECC has an internal length of 18. Try with 12 leading zeroes like 00000000000119004 instead of 119004 to see if it works.