Handling Records

Procedure

In the statement

MappedRecord output = (MappedRecord) interaction.execute(null, input);

(also refer to Client Programming Model ), the input parameter should be of type MappedRecord . The return object output in this method is also always of type MappedRecord .

  • input MappedRecord contains a list of all import, changing and table parameters, that are defined for the function module represented by this MappedRecord .

  • output MappedRecord contains a list of all export, changing and table parameters that are defined for the function module represented by this MappedRecord . ResultSet represents ABAP tables.

  • MappedRecord represents ABAP structures.

  • Both MappedRecords and ResultSets may contain inner ResultSets and MappedRecords .

To retrieve/set ResultSet , MappedRecord or other objects (e.g. BigInteger ) from/to MappedRecords, use the methods get(…)/ put(…). To retrieve/set them from/to ResultSet, use the methods getObject(…)/updateObject(…) .

For example, to retrieve a structure IMPORTSTRUCT from the input MappedRecord object, you need to call the method get(l..) on it and cast on the MappedRecord class.

MappedRecord input = recordFactry.createMappedRecord("STFC_STRUCTURE");  
MappedRecord importstruct = (MappedRecord)input.get("IMPORTSTRUCT");
         

To get a ResultSet RFCTABLE from input, you would call

ResultSet rfctable = (ResultSet)input.get("RFCTABLE");

If the table rfctable contains another table "MyTable" , you will get the table from the third table entry by

rfctable.relative(3); // set third line
ResultSet myTable3 = (ResultSet)rfctable.get("MyTable"); 

         

If this table line also contains a structure "MyStructure" amongst all the other parameters, you can get it by

MappedRecord myStruct = (MappedRecord) rfctable.getObject("MyStructure");

If this table line also contains an integer parameter "MyInt" , you can get it by

int myInt = rfctable.getInt("MyInt");

In following we will call MappedRecord and ResultSetobjects records.

To set parameters of any non-record type on the MappedRecord instance call the put (key, value) method and pass an according object, for example:

importstruct.put("RFCCHAR1",new Float(1.23456));

For all object values that can be represented by a string, you may also use the short form:

importstruct.put("RFCFLOAT","1.23456");  
importstruct.put("RFCCHAR1",new Character('A'));
         

or:

importstruct.put("RFCCHAR1","A");  
// Here are some more examples to set other java types:  
importstruct.put("RFCINT2", "12345");  
importstruct.put("RFCCHAR4","ABCD");

byte [] b = {(byte)0xf7, (byte)0xf7, (byte)0xf7};  
importstruct.put("RFCHEX3", b);     
importstruct.put "RFCTIME", new java.sql.Time(System.currentTimeMillis());

         

or:

importstruct.put("RFCTIME", "032559");
importstruct.put("RFCDATE", "2001-08-24");
importstruct.put("RFCDATA1", "Comment 1 of type RFCDATA1");  
importstruct.put("RFCDATA1", new String("Some comments"));
         

To get parameters of any type from the MappedRecord instance, call get(key) and cast it to the type you are waiting to receive, for example:

String s = (String) exportstruct.get("RESPTEXT");  
byte [] b = (byte[]) exportstruct.get("RFCHEX3 ");  
int rfcint2 = ((Integer)importstruct.get("RFCINT2")).intValue();
         

To set parameters of any non-record type on ResultSet instance, call

Update<ObjectType>(key, value)

and pass an according object, for example:

rfctable.updateFloat("RFCFLOAT",(float)1.6);
rfctable.updateString("RFCCHAR1","Y");  
rfctable.updateInt("RFCINT2", 260 + i);  
rfctable.updateShort("RFCINT1", (short)i);
rfctable.updateString("RFCCHAR4","EFGH"+i); 
rfctable.updateLong("RFCINT4", Long.parseLong("987654321"));           
rfctable.updateBytes("RFCHEX3", b);  
rfctable.updateObject("RFCCHAR2","AB");  
rfctable.updateTime("RFCTIME", new java.sql.Time(System.currentTimeMillis()));  
rfctable.updateDate("RFCDATE", new java.sql.Date(System.currentTimeMillis()));  
rfctable.updateString("RFCDATA1", "My RFCDATA1");
         

For any java non-primitive type (objects), you may use the method

updateObject("MyObject", object);

where object could be a string, byte[], integer, BigInteger and so on.

Usually, you set some table values by using mechanisms like:

for (int i = 0; i < 5; i++) 

{

          rfctable.moveToInsertRow();

 

          rfctable.updateShort("RFCINT1", (short)i);

          rfctable.updateString("RFCCHAR4","EFGH"+i);

 

          rfctable.insertRow();

}

         

and get values by

int count = 0;

while (rfctable.next())

{

    count += rfctable.getInt("RFCINT2");

}


         

ResultSet has a number of navigation methods (like method next() ).

For homogenous structures it may be convenient to use iterators. For example, for MappedRecord struct with strings everywhere it could be

Iterator keys = struct.keySet().iterator();

String key, myString = "";

while (keys.hasNext())

{

   key = (String)keys.next();

   myString += (String)struct.get(key);

}