This programming example shows how to pass structures and tables from the ABAP function module STFC_STRUCTURE to an external RFC Client program:
RFC_RC STFC_STRUCTURE(RFC_CONNECTION_HANDLE rfcHandle,
RFC_FUNCTION_DESC_HANDLE funcDesc)
{
RFC_ERROR_INFO error;
RFC_RC rc = RFC_OK;
RFC_FLOAT test_float = 12345.6789, veri_float;
RFC_INT test_int = 12345, veri_int;
RFC_BYTE test_rfchex3[3] = {0x41, 0x42, 0x43}; // "ABC"
RFC_BYTE veri_rfchex3[3] = {0, 0, 0};
const SAP_UC* test_data1 = cU("Hello World");
SAP_UC veri_data1[50 + 1] = iU("");
/*Create a function handle*/
RFC_FUNCTION_HANDLE funcHandle = NULL;
funcHandle = RfcCreateFunction(funcDesc, &error);
/*Create a structure handle: do not create using RfcCreateStructure, but just call*/
RFC_STRUCTURE_HANDLE structHandle = NULL;
rc = RfcGetStructure(funcHandle,cU("IMPORTSTRUCT"), &structHandle, &error);
RfcSetFloat(structHandle, cU("RFCFLOAT"), test_float, 0);
RfcGetFloat(structHandle, cU("RFCFLOAT"), &veri_float, 0);
RfcSetInt(structHandle, cU("RFCINT4"), 12345, 0);
RfcGetInt(structHandle, cU("RFCINT4"), &veri_int, 0);
RfcSetBytes(structHandle, cU("RFCHEX3"), test_rfchex3,
sizeofR(test_rfchex3), 0);
RfcGetBytes(structHandle, cU("RFCHEX3"), veri_rfchex3,
sizeofR(veri_rfchex3), 0);
RfcSetChars(structHandle, cU("RFCDATA1"), test_data1,
strlenU(test_data1), 0);
RfcGetChars(structHandle, cU("RFCDATA1"), veri_data1,
sizeofU(veri_data1), 0);
/*Create a structure handle: do not create using RfcCreateTable, but just call*/
RFC_TABLE_HANDLE tableHandle = NULL;
rc = RfcGetTable(funcHandle,cU("RFCTABLE"), &tableHandle, 0);
for(unsigned i = 0; i < count; i++)
{
RfcAppendRow(tableHandle, structHandle, 0);
}
SAP_UC buffer[256] = iU("");
printfU( cU("RFC test with STFC_STRUCTURE\n"));
RfcInvoke(rfcHandle, funcHandle, &error);
RfcGetChars(funcHandle, cU("RESPTEXT"), buffer, 255, 0);
EndTrim(buffer, cU(' '), 255);
printfU( cU("RESPTEXT : %s\n"), buffer);
RfcGetChars(funcHandle, cU("RESPTEXT"), buffer, 255, 0);
structHandle = NULL;
RfcGetStructure(funcHandle, cU("ECHOSTRUCT"), &structHandle, 0);
RfcGetFloat(structHandle, cU("RFCFLOAT"), &veri_float, 0);
RFC_INT rfcint4 = 0;
RfcGetInt(structHandle, cU("RFCINT4"), &veri_int, 0);
RfcGetBytes(structHandle, cU("RFCHEX3"), veri_rfchex3,
sizeofR(veri_rfchex3), 0);
RfcGetChars(structHandle, cU("RFCDATA1"), veri_data1,
sizeofU(veri_data1)-1, 0);
EndTrim(veri_data1, cU(' '), sizeofU(veri_data1));
printfU( cU("ECHOSTRUCT.RFCFLOAT : %f\n") ,veri_float);;
printfU( cU("ECHOSTRUCT.RFCINT4 : %d\n") , veri_int );
printfU( cU("ECHOSTRUCT.RFCHEX3 : %p\n") ,veri_rfchex3 );
printfU( cU("ECHOSTRUCT.RFCDATA1 : %s\n") , veri_data1);
tableHandle = NULL;
RfcGetTable(funcHandle, cU("RFCTABLE"), &tableHandle, 0);
RfcGetRowCount(tableHandle, &count, 0); //<-- moving table
cursor
RfcMoveToFirstRow(tableHandle, 0);
for(unsigned i = 0; i < count; i++)
{
RFC_STRUCTURE_HANDLE row = NULL;
row = RfcGetCurrentRow(tableHandle, 0);
RfcGetChars(row, cU("RFCDATA1"), veri_data1,
sizeofU(veri_data1), 0);
EndTrim(veri_data1, cU(' '), sizeofU(veri_data1));
printfU( cU("RFCTABLE[%d].RFCDATA1 : %s\n"),i,
veri_data1 );
RfcMoveToNextRow(tableHandle, 0); //<-- moving table
cursor
}
/*Clean up*/
RfcDestroyFunction(funcHandle, 0);
return rc;
}