Persistent Key - GetList method from GeneralLedgerAccount Business Object

I'm new in BAPI Programming, I'm trying to call GetList method from GeneralLedgerAccount Business Object, and got this error message 'The persistent key for an business object instance of type GeneralLedgerAccount has not been set. Cannot invoke method GetList'. 
How can I set the persistent key, and what is the persistent key exactly ?
How can I check the persistent key in the BOR ?
I'm using SAP R/3 version 3.1g and VB version 6.0

Answer:

Although we are currently using SAP 4.0B, the GeneralLedgerAccount BAPI has not changed significantly (if at all). I have had this error message many times working with HR BAPI's and it took a lot of research to finally puzzle out what SAP actually wants in these situations. On the other hand, I took a look at the GetList method for this BAPI and I cannot see why you would be getting this error! There are three kinds of BAPI's I have encountered so far - those that return actual tables of data based on key fields you fill in (i.e.. Employee.GetList), those that return tables of keys that point to the actual data within SAP (think of C pointers! ie.EmployeePersonalData.GetList), and BAPI's that have no input parameters at all but can retrieve extra information directly related to a particular 'instance' of a business object that you have previously 'instantiated' (translation - the last 'record' you 'read' from the table! i.e.. EmployeePersonalData.GetDetail). GeneralLedgerAccount is of the first type, while the error you get is related to BAPI's of the third type. It is usually caused by calling a GetDetail method without calling GetSAPObject with a complete, unique key value first. The following code fragment shows how I read Employee.GetList - this may shed some light on what you might be missing. The second fragment shows how to 'instantiate' a 'persistant' object (don't we just love this terminology?) before calling a GetDetail BAPI. Hope this helps you out!

===================================================
Dim oBapiControl As Object
Dim oConnection As Object
Dim oEmployee As Object
Dim oReturn As Object
Dim otabPersonalData As Object
Dim otabOrgAssignment As Object
Dim oRow As Object

oBapiControl = CreateObject("SAP.BAPI.1")
Set oConnection = oBapiControl.Connection
'SET UP ALL oConnection PARAMETERS HERE AND CALL oConnection.Logon(0, True)
Set oEmployee = oBapiControl.GetSAPObject("Employee")
oEmployee.Getlist Lastname:="*", _
                           Return:=oReturn, _
                           PersonalData:=otabPersonalData, _
                           OrgAssignment:=otabOrgAssignment
For Each oRow In otabPersonalData.Rows
    Print "Personnel Number = " + oRow.Value("PERNO")
...
Next oRow

 - Substitute the word 'GeneralLedgerAccount' for 'Employee' and this should work for you!

===================================================
Private Sub LoadFamily(sPerno As String)
  Dim cSep           As String * 1
  Dim sToday         As Date
  Dim oCol           As Object
  Dim oDelRow        As Object
  Dim oReturn        As Object
  Dim oFReturn       As Object
  Dim otabFKeyList   As Object
  Dim oFamilyKey     As Object
  Dim oFamilyMem     As Object
  Dim sFirstName     As String
  Dim sSecondName    As String
  Dim sLastName      As String
  Dim sGender        As String
  Dim sBirthdate     As Date

  cSep = Chr(9)
  sToday = Date

  ' RETRIEVE ALL FAMILY MEMBERS FOR A GIVEN PERSONNEL NUMBER.
  ' NOTE THAT THE BAPI RETURNS A TABLE OF KEYS (Familykey) AND
  ' NOT THE ACTUAL DATA!
  Set otabFKeyList = Nothing
  oFamilyMembers.Getlist EmployeeNumber:=sPerno, _
                            Subtype:="", _
                            Timeintervallow:=sToday, _
                            Timeintervalhigh:=sToday, _
                            Return:=oFReturn, _
                            Familykey:=otabFKeyList
  If oFReturn.Value("TYPE") <> "E" Then             'IF THE CALL SUCCEEDED,
    For Each oFamilyKey In otabFKeyList.Rows         THEN FOR EACH KEY IN THE TABLE... 
      On Error Resume Next
      ' INSTANTIATE A PERSISTANT LOCAL BUSINESS OBJECT HERE USING THE
      ' FULL KEY VALUE
      Set oFamilyMem = oBapiControl.GetSAPObject("EmployeeFamilyMember", _
                                                  oFamilyKey.Value("EMPLOYEENO"), _
                                                  oFamilyKey.Value("SUBTYPE"), _
                                                  oFamilyKey.Value("OBJECTID"), _
                                                  oFamilyKey.Value("LOCKINDIC"), _
                                                  oFamilyKey.Value("VALIDEND"), _
                                                  oFamilyKey.Value("VALIDBEGIN"), _
                                                  oFamilyKey.Value("RECORDNR"))
      If Err.Number = 0 Then                               ' AND IF THAT WORKED, THEN FINALLY
        ' WE CAN GET THE INFORMATION WE WANT BY CALLING GETDETAIL. THIS BAPI
        ' USES THE KEY INFORMATION IN THE FamilyMem OBJECT TO IDENTIFY THE SAP
        ' DATA THAT SHOULD BE RETURNED....VERY COMPLEX!!!
        oFamilyMem.GetDetail Return:=oReturn, _
                             Firstname:=sFirstName, _
                             Initials:=sSecondName, _
                             Lastname:=sLastName, _
                             Gender:=sGender, _
                             Dateofbirth:=sBirthdate
        If oReturn.Type <> "E" Then
          Print #2, sPerno; cSep; _
                    sFirstName; cSep; _
                    sSecondName; cSep; _
                    sLastName; cSep; _
                    sGender; cSep; _
                    sBirthdate; cSep; _
                    " "
        End If
      Else
        Err.Clear
      End If
    Next oFamilyKey
  End If
End Sub

*-- End of Program

ABAP Tips

See Also
BAPI_NETWORK_CONF_ADD

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.