Knowledge Base Nr: 00112 saprfc.cpp - http://www.swe-kaiser.de

Downloads:

RFC: SAP Funktion über RFC aufrufen ohne Rückgabewerten

  
//SAPGUI Client muss installiert sein

#include "saprfc.h"
#include "sapitab.h"

ASKSAPDLL_API int CallSAPRFCZETI(char* szFaNr, char* szSollMenge, char* szRestMenge, char* szDatei //input
, char* szResult) //returnvalue //output
{
const MAX_PARA=50;

// RFC Definionen
RFC_HANDLE handle;
RFC_ERROR_INFO_EX error_info_ex;
rfc_char_t connect_string[] = "TYPE=3 "
"ASHOST=153.95.24.5 "
"SYSNR=17 "
"CLIENT=002 "
"USER=*** "
"PASSWD=***";

RFC_RC rfc_rc;
rfc_char_t exception[512];
rfc_char_t* except_ptr = exception;
static RFC_PARAMETER importing[MAX_PARA];
static RFC_PARAMETER exporting[MAX_PARA];
static RFC_PARAMETER changing[MAX_PARA];
static RFC_TABLE tables[MAX_PARA];
RFC_STRING rfcs_fanr;
RFC_STRING rfcs_smenge;
RFC_STRING rfcs_rmenge;
RFC_STRING rfcs_datei;
ITAB_H itab_h;

// RFC Verbindung öffnen und anmelden
handle = RfcOpenEx(connect_string, &error_info_ex);

if (handle == RFC_HANDLE_NULL)
{
strcpy (szResult, "ERROR: RfcOpenEx(): RFC_HANDLE_NULL");
return -1;
}

// RFC Funktion "Z_RFC_FA_DATEN" aufrufen
importing[0].name = NULL;

rfcs_fanr = RfcAllocString(12);
strcpy ((char*)rfcs_fanr, szFaNr);
exporting[0].name = "FANUMMER";
exporting[0].nlen = strlen ((char*) exporting[0].name);
exporting[0].type = RFCTYPE_STRING;
exporting[0].addr = &rfcs_fanr;
exporting[0].leng = strlen((char*)rfcs_fanr);

rfcs_smenge = RfcAllocString(1);
strcpy ((char*)rfcs_smenge, szSollMenge);
exporting[1].name = "SOLLMENGE";
exporting[1].nlen = strlen ((char*) exporting[1].name);
exporting[1].type = RFCTYPE_STRING;
exporting[1].addr = &rfcs_smenge;
exporting[1].leng = strlen((char*)rfcs_smenge);

rfcs_rmenge = RfcAllocString(6);
strcpy ((char*)rfcs_rmenge, szRestMenge);
exporting[2].name = "RESTMENGE";
exporting[2].nlen = strlen ((char*) exporting[2].name);
exporting[2].type = RFCTYPE_STRING;
exporting[2].addr = &rfcs_rmenge;
exporting[2].leng = strlen((char*)rfcs_rmenge);

rfcs_datei = RfcAllocString(12);
strcpy ((char*)rfcs_datei, szDatei);
exporting[3].name = "DATEI";
exporting[3].nlen = strlen ((char*) exporting[3].name);
exporting[3].type = RFCTYPE_STRING;
exporting[3].addr = &rfcs_datei;
exporting[3].leng = strlen((char*)rfcs_datei);

exporting[4].name = NULL;

// Tabelle initialisieren
tables[0].name = NULL;

rfc_rc = RfcCallReceive(handle,
"Z_RFC_ZETI",
exporting,
importing,
tables,
&except_ptr);
if (rfc_rc != RFC_OK)
{
RfcClose(handle);
sprintf(szResult, "ERROR: RfcCallReceive(): key:%s message:%s\r\nexcept_ptr: %s"
, error_info_ex.key
, error_info_ex.message
, except_ptr);
return -2;
}

strcpy (szResult, "OK");

// RFC Verbindung schließen
RfcClose(handle);
return 0;
}