Now that all prerequisite are installed, we can do our first call to BAPI. I personally never found the literature needed regarding BAPI and python, and my first struggle was to understand the structure of the BAPI and how to call them.
Good news is that it is possible with pyrfc to discover the structure of a BAPI; this has been a game changer for me.
Your Python script would look like this:
from pyrfc import Connection
conn = Connection(ashost='x.x.x.x', sysnr='y', client='z', user='user', passwd='xxxx')
ds = conn.get_function_description('BAPI_CUSTOMER_GETLIST')
dir(ds.parameters)
for p in ds.parameters:
print (p)
the output would be:
{'name': 'RETURN', 'parameter_type': 'RFCTYPE_STRUCTURE', 'direction': 'RFC_EXPORT', 'nuc_length': 470, 'uc_length': 940, 'decimals': 0, 'default_value': '', 'parameter_text': 'Return parameter', 'optional': False, 'type_description':
In the code snippet above, you only need to update your SAP server Ip (ashost), the SAP instance number (sysnr), user name and password. then you are good to go and explore the different BAPI.