Blog Layout

BAPI for beginners - Part 2

flabouch • Jan 18, 2021

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': } {'name': 'CPDONLY', 'parameter_type': 'RFCTYPE_CHAR', 'direction': 'RFC_IMPORT', 'nuc_length': 1, 'uc_length': 2, 'decimals': 0, 'default_value': '', 'parameter_text': 'Control indicator: Read one-time customers only', 'optional': True, 'type_description': None} {'name': 'MAXROWS', 'parameter_type': 'RFCTYPE_INT', 'direction': 'RFC_IMPORT', 'nuc_length': 4, 'uc_length': 4, 'decimals': 0, 'default_value': '0', 'parameter_text': 'Maximum number of customers', 'optional': True, 'type_description': None} {'name': 'ADDRESSDATA', 'parameter_type': 'RFCTYPE_TABLE', 'direction': 'RFC_TABLES', 'nuc_length': 258, 'uc_length': 516, 'decimals': 0, 'default_value': '', 'parameter_text': 'Customer Address Data', 'optional': True, 'type_description': } {'name': 'IDRANGE', 'parameter_type': 'RFCTYPE_TABLE', 'direction': 'RFC_TABLES', 'nuc_length': 23, 'uc_length': 46, 'decimals': 0, 'default_value': '', 'parameter_text': 'RANGE Table of Customer Numbers', 'optional': False, 'type_description': } {'name': 'SPECIALDATA', 'parameter_type': 'RFCTYPE_TABLE', 'direction': 'RFC_TABLES', 'nuc_length': 11, 'uc_length': 22, 'decimals': 0, 'default_value': '', 'parameter_text': 'Special Customer Data', 'optional': True, '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.

SII Spain Integration thru API
14 Jul, 2023
SII in Spain: What is it, why does your company need to comply, and how to do it?
Integrating VIES VAT Validation with your ERP
By flabouch 19 May, 2022
How to integrate and automate VIES VAT number validation of EU commission with your ERP.
SAP Idoc parser python library
By flabouch 12 May, 2022
SAP Idoc parser in Python
Share by: