Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI VB, Column values mismatching in Table Parameter and Database value

Former Member
0 Kudos

Hi,

I am trying to call a BAPI ZBAPI_EMP_INS_TBL, in which I pass a Table parameter with 2 columns and 2 rows.

The column names are EMPID and DOJ which are of Char (8) and Dats data type.

In my BAPI, I loop through the table which has been passed as a parameter and insert data into the Z-table.

The problem is that my program runs without error and insert data in the corresponding Z-table. But the column values are different in Z-table and the ones passed from VB.

For e.g. If I pass 12345678 as EMPID, In Database the value comes as 45678200.
Similarly for the DOJ field the value comes as “7 - -7112”.


Is there any check or methods to be called while passing a Table parameter?
Because if I call another BAPI to insert single record and the BAPI takes 2 parameters i.e. EMPID and DOJ, the program works fine.

Are there any checks to be made while passing the Table parameter?
Once I call the code from VB, is it possible to debug the code from ABAP side?

Regards,

Vikas

Vikas.sreedharan@gmail.com


BAPI ZBAPI_EMP_INS_TBL
data:
  wa_emp type z_emp_dtls,
loop at tbl_emp into wa_emp. "tbl_emp is passed from VB code as a table
insert into z_emp_dtls values wa_emp.
clear wa_emp.
endloop.

VB code


Public Sub InsTable()
Dim obSapFn As Object
Dim obEmp As Object, obTblEmp As Object
Set obSapFn = CreateObject("SAP.Functions")

obSapFn.Connection.ApplicationServer = CNT_STR_APPLN_SRVR
obSapFn.Connection.SystemNumber = CNT_STR_SYS_NUM
obSapFn.Connection.User = CNT_STR_USR
obSapFn.Connection.Password = CNT_STR_PWD
obSapFn.Connection.Language = CNT_STR_LOGON_LANG
obSapFn.Connection.Client = CNT_STR_CLIENT
obSapFn.LogLevel = CNT_INT_LOG_LEVEL
obSapFn.LogFileName = CNT_STR_LOG_FILE

If obSapFn.Connection.Logon(0, True) = False Then
    MsgBox "R/3 connection failed"
    Exit Sub
End If

Set obEmp = obSapFn.Add("ZBAPI_EMP_INS_TBL")
Set obTblEmp = obEmp.Tables("TBL_EMP") ‘Table Parameter to be passed
obTblEmp.FreeTable
‘Add rows to the table which is to be passed
obTblEmp.Rows.Add
obTblEmp.Value(obTblEmp.RowCount, "EMPID") = CStr("K1009008")
obTblEmp.Value(obTblEmp.RowCount, "DOJ") = Now

obTblEmp.Rows.Add
obTblEmp.Value(obTblEmp.RowCount, "EMPID") = CStr("M2009008")
obTblEmp.Value(obTblEmp.RowCount, "DOJ") = Now + 1
‘ Below section is to check the data types .
Dim oColumn As Object
For Each oColumn In obTblEmp.Columns
    'MsgBox oColumn.Name & "," & oColumn.TypeName
Next oColumn
‘ End

‘Verify the data before calling Fn.
Dim iCount As Integer, iLoop As Integer
iCount = obTblEmp.RowCount
For iLoop = 1 To iCount
    'MsgBox obTblEmp(iLoop, "EMPID") & " , " & obTblEmp(iLoop, "DOJ")
Next

If obEmp.Call = False Then
    MsgBox "Error in calling fn "
End If

Set obTblEmp = Nothing
Set obEmp = Nothing
obSapFn.Connection.LogOff
Set obSapFn = Nothing
End Sub

2 REPLIES 2

Former Member
0 Kudos

Hi,

The error was occuring because of primary keys which I had added to table.

Once I recreated the table. It was working fine.

THe first 3 chars of empid was getting transfered to the mandt column.

Regards,

Vikas

Former Member
0 Kudos

Hi,

Just found out a way to debug ABAP code from VB.

For the connection properties add the following code

AbapDebug = True

Tracelevel = 9

RfcWithDialog = True

This will call the ABAP debugger, so this can be used for debugging SAP code

Vikas