SAP / PyRFC

Asynchronous, non-blocking SAP NW RFC SDK bindings for Python
http://sap.github.io/PyRFC
Apache License 2.0
509 stars 137 forks source link

How to deal with BAPIs that internally call transactions? #28

Closed Tset-Noitamotua closed 7 years ago

Tset-Noitamotua commented 7 years ago

From PyRFC point of view how to deal with BAPIs that internally call transactions?

For example BAPI_BILLINGDOC_CREATE (TCODE: VF01) - calling it result in a runtime error (Der Laufzeitfehler DYNPRO_SEND_IN_BACKGROUND ist aufgetreten)

# Importing SAP module from `SAP.py` below
>>> from SAP import SAP
>>> dest_01 = SAP('DE9')
>>> dest_01.call_bapi('BAPI_BILLINGDOC_CREATE')
Result: {u'RETURN': [{u'TYPE': u'A', u'MESSAGE_V2': u'', u'NUMBER': u'341', u'MESSAGE_V1': u'DYNPRO_SEND_IN_BACKGROUND', u'LOG_NO': u'', u'MESSAGE_V3': u'', u'MESSAGE_V4': u'', u'MESSAGE': u'Der Laufzeitfehler DYNPRO_SEND_IN_BACKGROUND ist aufgetreten', u'LOG_MSG_NO': u'000000', u'ID': u'00'}]}
{u'RETURN': [{u'TYPE': u'A', u'MESSAGE_V2': u'', u'NUMBER': u'341', u'MESSAGE_V1': u'DYNPRO_SEND_IN_BACKGROUND', u'LOG_NO': u'', u'MESSAGE_V3': u'', u'MESSAGE_V4': u'', u'MESSAGE': u'Der Laufzeitfehler DYNPRO_SEND_IN_BACKGROUND ist aufgetreten', u'LOG_MSG_NO': u'000000', u'ID': u'00'}]} >>>

SAP.py module:

# -*- coding: utf-8 -*-

import os
SAPNWRFC_PATH = os.path.abspath('dependencies/32bit/SAP_NW_RFC_32/lib')
os.environ['PATH'] = SAPNWRFC_PATH + ";" + os.environ['PATH']

import pyrfc
import datetime

class SAP():
  def __init__(self, sap_destination):
    self.sap = pyrfc.Connection(DEST=sap_destination)

  def call_bapi(self, bapi, **kwargs):
        try:
            result = self.sap.call(bapi, **kwargs)
            return result
        except AttributeError as error:
            raise (error)
bsrdjan commented 7 years ago

RFC connector(s) cant help here. Some BAPIs are simply not designed to run in batch mode and open dialogs for the user input. Some other may have parameters or their combinations, to "tell" the BAPI it should run in batch mode, without opening dialogs. The only solution is to check BAPI documentation, OSS notes, SCN threads and look if any alternative BAPIs exist, or build custom replacements.

Tset-Noitamotua commented 7 years ago

Thanks you for reply.

In case of above mentioned BAPI I was able to find an alternative BAPI_BILLINGDOC_CREATEMULTIPLE