cancel
Showing results for 
Search instead for 
Did you mean: 

Acces to data of every field in a table using a loop

eduardo_gironas
Participant
0 Kudos

Hello:

I have the next code:

// Calling remote function

proxy.Z_Hrpfpa00105("XX", "45", out sts, ref tIVAEmp);

foreach (ZHRRESNOM row in tIVAEmp)

{ Console.WriteLine("{0} …", row.Desc2, row.Betrg, …); } Assuming that tIVAEmp has 100 fields I need to build some loops during Console.WriteLine process, so I asked for your help for one part of the solution: // Getting the field names and lengths of an RFC Table Type structureType = tIVAEmp.GetElementType(); SAPField[] fields = SAPStructure.GetSAPFieldsSchema(structureType); // Verifying foreach (SAPField row in fields) Console.WriteLine(" - ", row.FieldName, row.FieldLength);

It worked, but now I can´t find the connection between SAPField and the content of every RFC Table field for every record, my mind is in blank and a I need help … how can I do in C# something similar to:

foreach (ZHRRESNOM row in tIVAEmp)

+// The next is pseudo-code

for every field F in fields

{ stri += contents of row, column F }

Console.WriteLine(“”, stri);+</i></i>

Thanks again

Accepted Solutions (1)

Accepted Solutions (1)

reiner_hille-doering
Active Contributor
0 Kudos

E.g


proxy.Z_Hrpfpa00105("XX", "45", out sts, ref tIVAEmp);

Type structureType = tIVAEmp.GetElementType();
SAPField[] fields = SAPStructure.GetSAPFieldsSchema(structureType);

foreach (ZHRRESNOM row in tIVAEmp)
{ 
  foreach (SAPField field in fields)
  {
    Console.WriteLine("{0}: {1}", field .FieldName, row[field.FieldName]);
  }
}

Accessing fields by name may be a little bit slow. Alternatively you can access it by index, which is faster:


  for (int i=0; i<fields.Length; i++)
  {
    Console.WriteLine("{0}: {1}", fields<i>.FieldName, row<i>);
  }

Answers (0)