The final discussion introduces some excerpts from the C source text of the generated client program and comments on the most important function calls and definitions.
Opening the RFC Connection Using
RfcOpen ()/* open connection */
OUT("Opening...",4);
NL;
hRfc = RfcOpen(RfcOptions);LOG(hRfc,"RfcOpen called","");
Local Representation of the Required Parameters
Calling function module RFC_CUSTOMER_GET.
Checking return code and handling errors.
RFC_RC WIN_DLL_EXPORT_FLAGS rfc_customer_get(RFC_HANDLE hRfc
,KNA1_KUNNR *eKunnr
,KNA1_NAME1 *eName1
,ITAB_H thCustomerT
,char *xException)
{
/* RFC variables */
RFC_PARAMETER Exporting[3];
RFC_PARAMETER Importing[1];
RFC_TABLE Tables[2];
RFC_RC RfcRc;
char *RfcException = NULL;
/* install structures */
if (handleOfBRFCKNA1==0) {
RfcRc = RfcInstallStructure("BRFCKNA1",
typeOfBRFCKNA1,
ENTRIES(typeOfBRFCKNA1),
&handleOfBRFCKNA1);
if (RfcRc != RFC_OK) rfc_error("RfcInstallStructure"); }
/* define export params */
Exporting[0].name = "KUNNR";
Exporting[0].nlen = 5;
Exporting[0].type = TYPC;
Exporting[0].leng = sizeof(KNA1_KUNNR);
Exporting[0].addr = eKunnr;
Exporting[1].name = "NAME1";
Exporting[1].nlen = 5;
Exporting[1].type = TYPC;
Exporting[1].leng = sizeof(KNA1_NAME1);
Exporting[1].addr = eName1;
Exporting[2].name = NULL;
/* define internal tables */
Tables[0].name = "CUSTOMER_T";
Tables[0].nlen = 10;
Tables[0].type = handleOfBRFCKNA1;
Tables[0].ithandle = thCustomerT;
Tables[1].name = NULL;
/* ------------------ RfcCall -----------------------*/
/* call function module */
RfcRc = RfcCall(hRfc,"RFC_CUSTOMER_GET",Exporting,Tables);
LOG(hRfc,"RfcCall called","");
switch (RfcRc) {
case RFC_OK :
Importing[0].name = NULL;
/* receive results */
RfcRc = RfcReceive(hRfc,Importing,Tables,&RfcException);
LOG(hRfc,"RfcReceive called","");
switch (RfcRc) {
case RFC_SYS_EXCEPTION : strcpy(xException,RfcException);
case RFC_EXCEPTION : strcpy(xException,RfcException); }
}
return RfcRc;
}
Setting the Export Parameters From the Input Values
/* input export parameters */
OUT("exporting",6);
INS("efi","","KUNNR",8,32,s); SETCHAR(eKunnr,s);
INS("efi","","NAME1",8,32,s); SETCHAR(eName1,s);
Handling Tables
/* init tables */
if (thCustomerT==ITAB_NULL) {
thCustomerT = ItCreate("CUSTOMER_T",sizeof(BRFCKNA1),0,0);
if (thCustomerT==ITAB_NULL) rfc_error("ItCreate CUSTOMER_T"); }
else {
if (ItFree(thCustomerT) != 0) rfc_error("ItFree CUSTOMER_T"); }
Formatting the Table and Displaying the R/3 Data
/* display tables */
OUT("tables",6);
sprintf(s,"%d lines",ItFill(thCustomerT));
OUTS("CUSTOMER_T",8,32,s); NL; t=0;
for (crow = 1;crow <= ItFill(thCustomerT); crow++)
{
if (t!='*') { INS("to","CUSTOMER_T","Get table row? [y]/n",4,24,s); t=s[0]; NL; }
if ((s[0] == 'n')||(s[0] == 'N')) break;
tCustomerT = ItGetLine(thCustomerT,crow);
if (tCustomerT == NULL) rfc_error("ItGetLine CUSTOMER_T");
GETCHAR(tCustomerT->Kunnr,s); OUTS("KUNNR",10,30,s);
GETCHAR(tCustomerT->Anred,s); OUTS("ANRED",10,30,s);
GETCHAR(tCustomerT->Name1,s); OUTS("NAME1",10,30,s);
GETCHAR(tCustomerT->Pfach,s); OUTS("PFACH",10,30,s);
GETCHAR(tCustomerT->Stras,s); OUTS("STRAS",10,30,s);
GETCHAR(tCustomerT->Pstlz,s); OUTS("PSTLZ",10,30,s);
GETCHAR(tCustomerT->Ort01,s); OUTS("ORT01",10,30,s);
GETCHAR(tCustomerT->Telf1,s); OUTS("TELF1",10,30,s);
GETCHAR(tCustomerT->Telfx,s); OUTS("TELFX",10,30,s);
sprintf(s,"%d of %d lines",crow,ItFill(thCustomerT));
OUTS("CUSTOMER_T",8,32,s); NL; }
Closing the RFC Connection
if (hRfc!=0) { RfcClose(hRfc); LOG(hRfc,"RfcClose called",""); }