on 11-30-2004 6:59 PM
Hello all,
When i add table entries I get i times the last entry i added.
Here is the code:
Overrides Protected Sub Zrfc_Projectdata_Import ( _
ByVal Aufnr As String, ByRef Test As String, ByRef Kostprj_Tab As ZPRJAUERTable)
' TODO: add your server code here
Dim i
Dim Kostprj As New ZPRJAUER
For i = 1 To 10
Kostprj.Bmnr = i
Kostprj_Tab.Add(Kostprj)
Next
End Sub
Am i doing anything wrong here?
Thanks in advance
Hello,
You are filling the table with the same table item created outside the loop. You need to create a new item for each table row inside the loop. The code looks like:
For i= 1 to 10
Kostprj = New ZPRJAUER
...
Kostprj_Tab.Add(Kostprj)
Next
Regards,
Guangwei Li
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Move the "new New ZPRJAUER" inside of the loop:
Dim i
Dim Kostprj As ZPRJAUER
For i = 1 To 10
Kostprj = New ZPRJAUER
Kostprj.Bmnr = i
Kostprj_Tab.Add(Kostprj)
Next
This is necessary because ZPRJAUER is a so called "reference type" object - Kostprj_Tab holds a pointer to it. If you don't create new instances for each table row, all rows would point to the same instance of ZPRJAUER.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.