Friday, 5 February 2010

SAP ABAP Rule - Make sure you commit your transactions to Avoid Phantom Numbers

An absolutely bizarre issue ocurred today - I was calling a custom SAP BAPI for the creation of purchase orders from .NET (via a web service) and it was returning a Purchase Order number - but it was never appearing in the client system in SAP. Essentially the Purchase order numbers I was receiving in the web service response never got into the EKKO table in SAP.

Turns out that if you get phantom numbers like this, you may not be committing your transaction correctly. Make sure you call a commit like so:
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.


Otherwise the Purchase Orders will just disappear when your BAPI completes.

FUNCTION Z_PO_CREATE .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_POHEADER) LIKE  BAPIMEPOHEADER STRUCTURE  BAPIMEPOHEADER
*"     VALUE(I_POHEADERX) LIKE  BAPIMEPOHEADERX STRUCTURE
*"        BAPIMEPOHEADERX OPTIONAL
*"     VALUE(I_POADDRVENDOR) LIKE  BAPIMEPOADDRVENDOR STRUCTURE
*"        BAPIMEPOADDRVENDOR OPTIONAL
*"     VALUE(I_TESTRUN) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_MEMORY_UNCOMPLETE) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_MEMORY_COMPLETE) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_POEXPIMPHEADER) LIKE  BAPIEIKP STRUCTURE  BAPIEIKP
*"       OPTIONAL
*"     VALUE(I_POEXPIMPHEADERX) LIKE  BAPIEIKPX STRUCTURE  BAPIEIKPX
*"       OPTIONAL
*"     VALUE(I_VERSIONS) LIKE  BAPIMEDCM STRUCTURE  BAPIMEDCM OPTIONAL
*"     VALUE(I_NO_MESSAGING) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_NO_MESSAGE_REQ) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_NO_AUTHORITY) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_NO_PRICE_FROM_PO) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_PARK_COMPLETE) TYPE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_PARK_UNCOMPLETE) TYPE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(I_PROCESSTITLE) TYPE  ZSBPMLOG-PROCESSTITLE OPTIONAL
*"     VALUE(I_PROCESSSTARTDATE) TYPE  ZSBPMLOG-PROCESSSTARTDATE
*"       OPTIONAL
*"     VALUE(I_PROCESSSTARTTIME) TYPE  ZSBPMLOG-PROCESSSTARTTIME
*"       OPTIONAL
*"     VALUE(I_PROCESSOWNER) TYPE  ZSBPMLOG-PROCESSOWNER OPTIONAL
*"     VALUE(I_STEPNAME) TYPE  ZSBPMLOG-STEPNAME OPTIONAL
*"     VALUE(I_STEPSTARTDATE) TYPE  ZSBPMLOG-STEPSTARTDATE OPTIONAL
*"     VALUE(I_STEPSTARTTIME) TYPE  ZSBPMLOG-STEPSTARTTIME OPTIONAL
*"     VALUE(I_STEPOWNER) TYPE  ZSBPMLOG-STEPOWNER OPTIONAL
*"     VALUE(I_MESSAGE1) TYPE  ZSBPMLOG-MESSAGE1 OPTIONAL
*"     VALUE(I_MESSAGE2) TYPE  ZSBPMLOG-MESSAGE2 OPTIONAL
*"     VALUE(I_MESSAGE3) TYPE  ZSBPMLOG-MESSAGE3 OPTIONAL
*"     VALUE(I_MESSAGE4) TYPE  ZSBPMLOG-MESSAGE4 OPTIONAL
*"     VALUE(I_MESSAGE5) TYPE  ZSBPMLOG-MESSAGE5 OPTIONAL
*"     VALUE(I_OBJKEY) TYPE  SWO_TYPEID
*"     VALUE(I_OBJTYPE) TYPE  SWO_OBJTYP
*"     VALUE(I_LOGSYS) TYPE  LOGSYS OPTIONAL
*"     VALUE(I_TITLE) TYPE  SOOD-OBJDES
*"     VALUE(I_URL) TYPE  SO_URL
*"  EXPORTING
*"     VALUE(E_EXPPURCHASEORDER) LIKE  BAPIMEPOHEADER-PO_NUMBER
*"     VALUE(E_EXPHEADER) LIKE  BAPIMEPOHEADER STRUCTURE
*"        BAPIMEPOHEADER
*"     VALUE(E_EXPPOEXPIMPHEADER) LIKE  BAPIEIKP STRUCTURE  BAPIEIKP
*"     VALUE(E_URL_LINK) TYPE  BORIDENT-OBJKEY
*"  TABLES
*"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      T_POITEM STRUCTURE  BAPIMEPOITEM OPTIONAL
*"      T_POITEMX STRUCTURE  BAPIMEPOITEMX OPTIONAL
*"      T_POADDRDELIVERY STRUCTURE  BAPIMEPOADDRDELIVERY OPTIONAL
*"      T_POSCHEDULE STRUCTURE  BAPIMEPOSCHEDULE OPTIONAL
*"      T_POSCHEDULEX STRUCTURE  BAPIMEPOSCHEDULX OPTIONAL
*"      T_POACCOUNT STRUCTURE  BAPIMEPOACCOUNT OPTIONAL
*"      T_POACCOUNTPROFITSEGMENT STRUCTURE
*"        BAPIMEPOACCOUNTPROFITSEGMENT OPTIONAL
*"      T_POACCOUNTX STRUCTURE  BAPIMEPOACCOUNTX OPTIONAL
*"      T_POCONDHEADER STRUCTURE  BAPIMEPOCONDHEADER OPTIONAL
*"      T_POCONDHEADERX STRUCTURE  BAPIMEPOCONDHEADERX OPTIONAL
*"      T_POCOND STRUCTURE  BAPIMEPOCOND OPTIONAL
*"      T_POCONDX STRUCTURE  BAPIMEPOCONDX OPTIONAL
*"      T_POLIMITS STRUCTURE  BAPIESUHC OPTIONAL
*"      T_POCONTRACTLIMITS STRUCTURE  BAPIESUCC OPTIONAL
*"      T_POSERVICES STRUCTURE  BAPIESLLC OPTIONAL
*"      T_POSRVACCESSVALUES STRUCTURE  BAPIESKLC OPTIONAL
*"      T_POSERVICESTEXT STRUCTURE  BAPIESLLTX OPTIONAL
*"      T_EXTENSIONIN STRUCTURE  BAPIPAREX OPTIONAL
*"      T_EXTENSIONOUT STRUCTURE  BAPIPAREX OPTIONAL
*"      T_POEXPIMPITEM STRUCTURE  BAPIEIPO OPTIONAL
*"      T_POEXPIMPITEMX STRUCTURE  BAPIEIPOX OPTIONAL
*"      T_POTEXTHEADER STRUCTURE  BAPIMEPOTEXTHEADER OPTIONAL
*"      T_POTEXTITEM STRUCTURE  BAPIMEPOTEXT OPTIONAL
*"      T_ALLVERSIONS STRUCTURE  BAPIMEDCM_ALLVERSIONS OPTIONAL
*"      T_POPARTNER STRUCTURE  BAPIEKKOP OPTIONAL
*"      T_POCOMPONENTS STRUCTURE  BAPIMEPOCOMPONENT OPTIONAL
*"      T_POCOMPONENTSX STRUCTURE  BAPIMEPOCOMPONENTX OPTIONAL
*"      T_POSHIPPING STRUCTURE  BAPIITEMSHIP OPTIONAL
*"      T_POSHIPPINGX STRUCTURE  BAPIITEMSHIPX OPTIONAL
*"      T_POSHIPPINGEXP STRUCTURE  BAPIMEPOSHIPPEXP OPTIONAL
*"      T_SERIALNUMBER STRUCTURE  BAPIMEPOSERIALNO OPTIONAL
*"      T_SERIALNUMBERX STRUCTURE  BAPIMEPOSERIALNOX OPTIONAL
*"      T_INVPLANHEADER STRUCTURE  BAPI_INVOICE_PLAN_HEADER OPTIONAL
*"      T_INVPLANHEADERX STRUCTURE  BAPI_INVOICE_PLAN_HEADERX OPTIONAL
*"      T_INVPLANITEM STRUCTURE  BAPI_INVOICE_PLAN_ITEM OPTIONAL
*"      T_INVPLANITEMX STRUCTURE  BAPI_INVOICE_PLAN_ITEMX OPTIONAL
*"      T_URL_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
* Create SAP BPM Log Entry
*  ZSBPMLOG-PROCESSTITLE      = I_PROCESSTITLE.
*  ZSBPMLOG-PROCESSSTARTDATE  = I_PROCESSSTARTDATE.
*  ZSBPMLOG-PROCESSSTARTTIME  = I_PROCESSSTARTTIME.
*  ZSBPMLOG-PROCESSOWNER      = I_PROCESSOWNER.
*  ZSBPMLOG-STEPNAME          = I_STEPNAME.
*  ZSBPMLOG-STEPSTARTDATE     = I_STEPSTARTDATE.
*  ZSBPMLOG-STEPSTARTTIME     = I_STEPSTARTTIME.
*  ZSBPMLOG-STEPOWNER         = I_STEPOWNER.
*  ZSBPMLOG-MESSAGE1          = I_MESSAGE1.
*  ZSBPMLOG-MESSAGE2          = I_MESSAGE2.
*  ZSBPMLOG-MESSAGE3          = I_MESSAGE3.
*  ZSBPMLOG-MESSAGE4          = I_MESSAGE4.
*  ZSBPMLOG-MESSAGE5          = I_MESSAGE5.
*  INSERT ZSBPMLOG.

*Create PO Record
  CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      POHEADER               = I_POHEADER
      POHEADERX              = I_POHEADERX
      POADDRVENDOR           = I_POADDRVENDOR
      TESTRUN                = I_TESTRUN
      MEMORY_UNCOMPLETE      = I_MEMORY_UNCOMPLETE
      MEMORY_COMPLETE        = I_MEMORY_COMPLETE
      POEXPIMPHEADER         = I_POEXPIMPHEADER
      POEXPIMPHEADERX        = I_POEXPIMPHEADERX
      VERSIONS               = I_VERSIONS
      NO_MESSAGING           = I_NO_MESSAGING
      NO_MESSAGE_REQ         = I_NO_MESSAGE_REQ
      NO_AUTHORITY           = I_NO_AUTHORITY
      NO_PRICE_FROM_PO       = I_NO_PRICE_FROM_PO
      PARK_COMPLETE          = I_PARK_COMPLETE
      PARK_UNCOMPLETE        = I_PARK_UNCOMPLETE
    IMPORTING
      EXPPURCHASEORDER       = E_EXPPURCHASEORDER
      EXPHEADER              = E_EXPHEADER
      EXPPOEXPIMPHEADER      = E_EXPPOEXPIMPHEADER
    TABLES
      RETURN                 = T_RETURN
      POITEM                 = T_POITEM
      POITEMX                = T_POITEMX
      POADDRDELIVERY         = T_POADDRDELIVERY
      POSCHEDULE             = T_POSCHEDULE
      POSCHEDULEX            = T_POSCHEDULEX
      POACCOUNT              = T_POACCOUNT
      POACCOUNTPROFITSEGMENT = T_POACCOUNTPROFITSEGMENT
      POACCOUNTX             = T_POACCOUNTX
      POCONDHEADER           = T_POCONDHEADER
      POCONDHEADERX          = T_POCONDHEADERX
      POCOND                 = T_POCOND
      POCONDX                = T_POCONDX
      POLIMITS               = T_POLIMITS
      POCONTRACTLIMITS       = T_POCONTRACTLIMITS
      POSERVICES             = T_POSERVICES
      POSRVACCESSVALUES      = T_POSRVACCESSVALUES
      POSERVICESTEXT         = T_POSERVICESTEXT
      EXTENSIONIN            = T_EXTENSIONIN
      EXTENSIONOUT           = T_EXTENSIONOUT
      POEXPIMPITEM           = T_POEXPIMPITEM
      POEXPIMPITEMX          = T_POEXPIMPITEMX
      POTEXTHEADER           = T_POTEXTHEADER
      POTEXTITEM             = T_POTEXTITEM
      ALLVERSIONS            = T_ALLVERSIONS
      POPARTNER              = T_POPARTNER
      POCOMPONENTS           = T_POCOMPONENTS
      POCOMPONENTSX          = T_POCOMPONENTSX
      POSHIPPING             = T_POSHIPPING
      POSHIPPINGX            = T_POSHIPPINGX
      POSHIPPINGEXP          = T_POSHIPPINGEXP
      SERIALNUMBER           = T_SERIALNUMBER
      SERIALNUMBERX          = T_SERIALNUMBERX
      INVPLANHEADER          = T_INVPLANHEADER
      INVPLANHEADERX         = T_INVPLANHEADERX
      INVPLANITEM            = T_INVPLANITEM
      INVPLANITEMX           = T_INVPLANITEMX.

* Create PO Attachments
  IF I_URL IS NOT INITIAL.
    CALL FUNCTION 'Z_GOS_URL_CREATE'
      EXPORTING
        I_OBJKEY   = I_OBJKEY
        I_OBJTYPE  = I_OBJTYPE
        I_LOGSYS   = I_LOGSYS
        I_TITLE    = I_TITLE
        I_URL      = I_URL
      IMPORTING
        E_URL_LINK = E_URL_LINK
      TABLES
        T_RETURN   = T_URL_RETURN.
  ENDIF.

 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

* Create SAP BPM Log Entry
*  ZSBPMLOG-PROCESSTITLE      = I_PROCESSTITLE.
*  ZSBPMLOG-PROCESSSTARTDATE  = I_PROCESSSTARTDATE.
*  ZSBPMLOG-PROCESSSTARTTIME  = I_PROCESSSTARTTIME.
*  ZSBPMLOG-PROCESSOWNER      = I_PROCESSOWNER.
*  ZSBPMLOG-STEPNAME          = I_STEPNAME.
*  ZSBPMLOG-STEPSTARTDATE     = I_STEPSTARTDATE.
*  ZSBPMLOG-STEPSTARTTIME     = I_STEPSTARTTIME.
*  ZSBPMLOG-STEPOWNER         = I_STEPOWNER.
*  ZSBPMLOG-MESSAGE1          = I_MESSAGE1.
*  ZSBPMLOG-MESSAGE2          = I_MESSAGE2.
*  ZSBPMLOG-MESSAGE3          = I_MESSAGE3.
*  ZSBPMLOG-MESSAGE4          = I_MESSAGE4.
*  ZSBPMLOG-MESSAGE5          = I_MESSAGE5.
*  INSERT ZSBPMLOG.

ENDFUNCTION.

1 comment:

mariamith said...

Anyone can attempt writing on your behalf, however, the question is would you pay someone to do it for you without checking their credibility? Our firm has established itself as the most trustworthy assignment help firm in Australia and globally. Join these thousands of students and achieve high distinction in each and every one of your college tasks. This is the main reason why most students search for assignment help australia over the internet and choose only the most proficient and trusted academic writing experts. So, if you are searching for quality singapore assignment help you can find it right here from the local experts.