SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

SAP RFC SDK and C++



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
A_Smith
Участник
Участник



Joined: 28 Nov 2007
Posts: 30

PostPosted: Tue Apr 01, 2008 5:18 pm    Post subject: SAP RFC SDK and C++ Reply with quote

В первую очередь хотелось бы узнать кто писал и каких успех добился. Хочу вызвать ФМ средствами C++. ФМ получает информацию из спула и передает в экспортируемую таблицу. на PHP модуль отрабатывает, а средствами C++ удается только запустить ФМ, но не получить выходные данные)))если кто поможет, буду только рад. Хотелось бы увидеть любые исходники и даже кусочки строк.
Back to top
View user's profile Send private message
Lord
Профессионал
Профессионал



Joined: 10 Sep 2007
Posts: 168

PostPosted: Tue Apr 01, 2008 8:37 pm    Post subject: Reply with quote

Примеры и исходники на С идут вместе SAP GUI в архиве RFC.SAR
Для распаковки запустите
sapcar -xvf [путь к sapgiu]\SDK\NT\I386\RFC.SAR

Про C++ почитайте документ RFC C++ Class Library (BC-FES-AIT)
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Wed Apr 02, 2008 8:53 pm    Post subject: Reply with quote

Примеры:
SAP RFC Multithreading Examples on CPP
List active SAP users via RFC calls - C program and Remote FM

Code:
//RFC: SAP Funktion ьber RFC aufrufen mit Rьckgabewerten

//SAPGUI Client muss installiert sein

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

/* some limit for parameter to allow static allocation */
#define MAX_PARA 4
#define MAX_SIZE 100

typedef struct
{
  char strPLNBEZ[MAX_SIZE];
  char strGLTRS[MAX_SIZE];
  char strGSTRS[MAX_SIZE];
  char strGAMNG[MAX_SIZE];
  char strMAKTX[MAX_SIZE];
  char strFERTH[MAX_SIZE];
  char strMATNR[MAX_SIZE];
  char strWKZNR[MAX_SIZE];
} MYDATA;

MIRSAP_API int GetSAPData(char *strFANR,
                          char *strPLNBEZ,
                          char *strGLTRS,
                          char *strGSTRS,
                          char *strGAMNG,
                          char *strMAKTX,
                          char *strFERTH,
                          char *strMATNR,
                          char *strWKZNR,
                          char *strDummy1,
                          char *strDummy2)
{
  RFC_HANDLE          handle;
  RFC_ERROR_INFO_EX   error_info_ex;
  rfc_char_t          connect_string[] = "TYPE=3 ASHOST=153.95.24.7 SYSNR=06 CLIENT=002 USER=*** PASS
WD=***";


  // RFC Funktion
  RFC_RC        rfc_rc;
  rfc_char_t    exception[512];
  rfc_char_t    *except_ptr = exception;
  rfc_char_t    *ptr;
  static RFC_PARAMETER  importing[MAX_PARA],
                        exporting[MAX_PARA],
                        changing[MAX_PARA];
  static RFC_TABLE      tables[MAX_PARA];
  RFC_STRING    input;
  ITAB_H        itab_h;
  RFC_BCD       test;

  int i;
  int nLineLength;

  MYDATA myData;

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

  if (handle == RFC_HANDLE_NULL)
  {
    return (-1);
  }

  // RFC Funktion "Z_RFC_FA_DATEN" aufrufen

  importing[0].name = NULL;

  input = RfcAllocString (200);

  strcpy ((char *) input, strFANR);


  exporting[0].name = "FANUMMER";
  exporting[0].nlen = strlen ((char *) exporting[0].name);
  exporting[0].type = RFCTYPE_STRING;
  exporting[0].addr = &input;
  exporting[0].leng = strlen((char *)input);

  exporting[1].name = NULL;

  // Tabelle initialisieren
  itab_h = ItCreate ("Z_SG_FADATEN", 10000, 0 , 0);


  tables[0].name     = "Z_SG_FADATEN";
  tables[0].nlen     = strlen ((char *) tables[0].name );
  tables[0].ithandle = itab_h;
  tables[0].leng     = 10000;
  tables[0].type     = RFCTYPE_CHAR;

  rfc_rc = RfcCallReceive (handle,
                           "Z_RFC_FA_DATEN",
                           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);
  }

  i = ItFill (itab_h);

  if (i>0)
  {
    nLineLength = ItLeng (itab_h);
    ptr = (char *) ItGetLine (itab_h, 1);


    // Daten ьbernehmen

    memset (&myData, 0, sizeof(MYDATA));

    // PLNBEZ   CHAR 18
    strncpy (myData.strPLNBEZ, ptr, 18);
    myData.strPLNBEZ[18]=0;
    ptr += 18;

    // GLTRS   DATS 8
    strncpy (myData.strGLTRS, ptr, 8);
    myData.strGLTRS[8]=0;
    ptr += 8;
    // GSTRS   DATS 8
    strncpy (myData.strGSTRS, ptr, 8);
    myData.strGSTRS[8]=0;
    ptr += 8;
    // GAMNG   CHAR 13
    RfcConvertBcdToChar ( (RFC_BCD *) ptr,  /* @parm Input data to convert */
                          7,                /* @parm Length of input data  */
                          3,                /* @parm No. of digits after , */
                          myData.strGAMNG,  /* @parm Output data           */
                          20                /* @parm Length of output data */
                          );
    // strncpy (myData.strGAMNG, ptr, 7);
    // myData.strGAMNG[7]=0;
    ptr += 7;
    // MAKTX   CHAR 40
    strncpy (myData.strMAKTX, ptr, 40);
    myData.strMAKTX[40]=0;
    ptr += 40;
    // FERTH   CHAR 18
    strncpy (myData.strFERTH, ptr, 18);
    myData.strFERTH[18]=0;
    ptr += 18;
    // MATNR   CHAR 18
    strncpy (myData.strMATNR, ptr, 18);
    myData.strMATNR[18]=0;
    ptr += 18;
    // WKZNR   CHAR 18
    strncpy (myData.strWKZNR, ptr, 18);
    myData.strWKZNR[18]=0;
    ptr += 18;

    strcpy (strPLNBEZ, myData.strPLNBEZ);
    strcpy (strGLTRS, myData.strGLTRS);
    strcpy (strGSTRS, myData.strGSTRS);
    strcpy (strGAMNG, myData.strGAMNG);
    strcpy (strMAKTX, myData.strMAKTX);
    strcpy (strFERTH, myData.strFERTH);
    strcpy (strMATNR, myData.strMATNR);
    strcpy (strWKZNR, myData.strWKZNR);
  }
  else
  {
    RfcClose (handle);
    return -2;
  }

  // RFC Verbindung schlieЯen
  RfcClose (handle);

  return 0;
}


Code:

That's okay. Here is an example for retrieving the company code list using BAPI
function "BAPI_COMPANYCODE_GETLIST". I've put everything together except SAP RFC
H/lib

Enjoy coding

=============================================
/*
Company Code - RFC
Author: Shaw1236
Date  : March 8, 2004 (to remember this)
------------------------------------------------------------------------
*/
#pragma warning(disable: 4786)

#include <iostream>   // cout, cerr
#include <fstream>    // ifstream, ofstream

#include "..\common\saprfc.h"
#include "..\common\sapitab.h"

typedef struct tagRFC_DATA {
RFC_CHAR COMP_CODE[4];
   RFC_CHAR COMP_NAME[25];
} RFC_DATA;

/* structure type handle and element definition */
static RFC_TYPEHANDLE handleOfRFC_DATA;

static RFC_TYPE_ELEMENT typeOfRFC_DATA[] = {
 {"COMP_CODE", TYPC, 4, 0},
 {"COMP_NAME", TYPC, 25, 0},
};

/* entries */
#ifndef ENTRIES
#define ENTRIES(tab) (sizeof(tab)/sizeof((tab)[0]))
#endif

// SAP RFC lib
#pragma comment (lib, "librfc32.lib")     

//--------------------------------------------------------------------
#include <map>
#include <string>
using namespace std;

//#define _PROD_ _PROD_
//#define _QA_   _QA_
#define _DEV_  _DEV_

namespace SAP_LOGON {
const char _Mode_[] = "R/3";
const char _Language_[] = "EN";

const char _User[] = "shaw1236";  //
const char _Password[] = "shaw1236";  //

   /* Prod */
#if defined(_PROD_)
const char _Destination[] = "CP1";   // CD1, CQ1, BD1, BQ1, BP1
const char _Client[] = "310";        // 120, 110, 270, 500   
const char _Hostname[] = "sapr3pr";  // sapr3dv, sapr3qa, sapr3pr,
sapbwqa, sapbwpr
const char _Sysnr[] = "03";          // 01, 02, 03, 21, 22, 23
const char Gwhost[] = "sapr3pr";     // sapr3pr, sapr3dv, sapr3qa
   const char Gwservice[] = "sapgw03";  // sapgw03, sapgw02, sapgw01
   // _PROD_

   // Dev
#elif defined(_DEV_)
   const char _Destination[] = "CD1";   // CD1, CQ1, BD1, BQ1, BP1
const char _Client[] = "110";        // 120, 110, 270, 500   
const char _Hostname[] = "sapr3dv";  // sapr3dv, sapr3qa, sapr3pr,
sapbwqa, sapbwpr
const char _Sysnr[] = "01";          // 01, 02, 03, 21, 22, 23
const char Gwhost[] = "sapr3dv";     // sapr3pr, sapr3dv, sapr3qa
const char Gwservice[] = "sapgw01";  // sapgw03, sapgw02, sapgw01
  // _DEV_

#elif defined(_QA_)
   // QA
   const char _Destination[] = "CQ1";   // CD1, CQ1, BD1, BQ1, BP1
const char _Client[] = "310";        // 120, 110, 270, 500   
const char _Hostname[] = "sapr3qa";  // sapr3dv, sapr3qa, sapr3pr,
sapbwqa, sapbwpr
const char _Sysnr[] = "02";          // 01, 02, 03, 21, 22, 23
const char Gwhost[] = "sapr3qa";     // sapr3pr, sapr3dv, sapr3qa
const char Gwservice[] = "sapgw02";  // sapgw03, sapgw02, sapgw01
   // _QA_
#else
#error ERROR: SAP system parameters are required!
#endif

enum { TRACE_OFF = 0, TRACE_ON = 1 } TRACE;
};


map<string, string> mapData;
map<string, string>::const_iterator it;

//
// Trim the blank pads on left and right sides
//
char* trim(char *p)
{
// Left blank pads
while (isspace(*p)) p++;

// Wipe out the right blank pads
char *q = p + strlen(p) - 1;
while (isspace(*q) && q > p) q--;
*(q + 1) = '\0';

return p;
}

// Globe routines
void printData()
{
//RFCCUST_DATA *cust;

   for (it = mapData.begin(); it != mapData.end(); it++) {
cout << "** Data **" << '\n';
cout << it->first << " -- " << it->second << '\n';
   }
}

//--------------------------------------------------------------------
#define SETCHAR(var,str) memcpy(var,str,__min(strlen(str),sizeof(var))); \
                     if (sizeof(var)>strlen(str)) memset(var+strlen(str),' ',sizeof
(var)-strlen(str))
#define GETCHAR(var,str) sprintf(str,"%.*s",sizeof(var),var)

#define SETDATE(var,str) memcpy(var,str,__min(strlen(str),sizeof(var))); \
                      if (sizeof(var)>strlen(str)) memset(var+strlen(str),'0',sizeof
(var)-strlen(str))
#define GETDATE(var,str) sprintf(str,"%.*s",sizeof(var),var)

#define SETFLOAT(var,str) *var=atof(str);
#define GETFLOAT(var,str) sprintf(str,"%f",var);

#define SETINT(var,str) *var=atol(str);
#define GETINT(var,str) sprintf(str,"%ld",var);

#define SETNUM(var,str) memcpy(var+(sizeof(var)-__min(strlen(str),sizeof
(var))),str,__min(strlen(str),sizeof(var))); \
                      if (sizeof(var)>strlen(str)) memset(var,'0',sizeof(var)-strlen
(str))
#define GETNUM(var,str) sprintf(str,"%.*s",sizeof(var),var)

#define SETTIME(var,str) memcpy(var,str,__min(strlen(str),sizeof(var))); \
                      if (sizeof(var)>strlen(str)) memset(var+strlen(str),'0',sizeof
(var)-strlen(str))
#define GETTIME(var,str) sprintf(str,"%.*s",sizeof(var),var)

#define SETINT1(var,str) *var=atoi(str);
#define GETINT1(var,str) sprintf(str,"%hu",var);

#define SETINT2(var,str) *var=atoi(str);
#define GETINT2(var,str) sprintf(str,"%d",var);

#define SETBYTE(var,str) str2nbyte(str,var,sizeof(var))
#define GETBYTE(var,str) nbyte2str(str,var,sizeof(var))

static void str2nbyte(char *str,unsigned char *byte,size_t size)
{
/* convert string to byte, e.g. str "818283" to byte 'abc' */
size_t c; char tmp[1024]; int i;
strcpy(tmp,str); for (c=0;c<strlen(tmp);++c) tmp[c]=toupper(tmp[c]);
for (c=strlen(tmp);c<(size<<1);c++) tmp[c] = '0';
for (c=0;c<size;c++) { sscanf(& tmp[c<<1],"%2x",& i); byte[c]=i; }
}

static void nbyte2str(char *str,unsigned char *byte,size_t size)
{
/* convert byte to string, e.g. byte 'abc' to str "818283" */
size_t c;
for ( c=0; c<size; c++ ) sprintf( &str[c<<1], "%02X", byte[c] );
str[size<<1] = 0;
}

#define SETBCD(var,str,dec) str2nbcd(str,var,sizeof(var),dec)
#define GETBCD(var,str,dec) nbcd2str(str,var,sizeof(var),dec)

static void str2nbcd(char *str,unsigned char *bcd,size_t size, int decimals)
{
/* convert string to bcd, e.g. str "+012.3" to bcd '01230C' length 3
decimals 2 */
char s[1024],*p; size_t c, strs=size<<1;
if (str[0]=='-') {s[strs-1]='D'; str++;}
else {s[strs-1]='C'; if (str[0]=='+') str++;}
if (p=strchr(str,'.')) *(p++)=0; else p=str+strlen(str);
c=strs-1-decimals;
if (strlen(str)>c) memcpy(s,str+strlen(str)-c,c);
else {memset(s,'0',c-strlen(str)); memcpy(s+c-strlen(str),str,strlen
(str));}
while((*p) && (c < strs-1)) s[c++]=*(p++);
while(c < strs-1) s[c++]='0';
str2nbyte(s,bcd,size);
}

static void nbcd2str(char *str,unsigned char *bcd,size_t size,int decimals)
{
/* convert bcd to string, e.g. bcd '01230C' length 3 decimals 2 to
str "+012.30" */
char s[1024]; size_t c, strs=size<<1;
nbyte2str(s,bcd,size);
if (s[strs-1]=='D') *(str++)='-'; else *(str++)='+';
for(c=0;c<strs-decimals-1;c++) *(str++)=s[c];
if (decimals>0) { *(str++)='.'; while (c<strs-1) *(str++)=s[c++];}
*str=0;
}

static char* str2upper(char *str)
{
unsigned i;
for (i=0;i<strlen(str);++i) str=toupper(str);
return str;
}

static RFC_HANDLE logon(RFC_OPTIONS *RfcOptions,RFC_CONNOPT_CPIC
*RfcConnoptCpic,RFC_CONNOPT_R3ONLY *RfcConnoptR3only)
{
static char lDestination[4],lClient[4],lUser[13],lPassword[11],lLanguage
[3];
static char lMode[4],lHostname[31],lSysnr[3],lGwhost[31],lGwservice[31];
static RFC_HANDLE hRfc;

/* logon defaults */
strcpy(lDestination, SAP_LOGON::_Destination);
strcpy(lClient,SAP_LOGON::_Client);
strcpy(lUser, SAP_LOGON::_User);
strcpy(lPassword, SAP_LOGON::_Password);
strcpy(lLanguage, SAP_LOGON::_Language_);
strcpy(lMode, SAP_LOGON::_Mode_);
strcpy(lHostname, SAP_LOGON::_Hostname);
strcpy(lSysnr, SAP_LOGON::_Sysnr);
strcpy(lGwhost, SAP_LOGON::Gwhost);
strcpy(lGwservice, SAP_LOGON::Gwservice);

   // To invoke the ABAP debugger, we need a dialog user
   RfcOptions->trace = SAP_LOGON::TRACE_OFF;

/* logon settings */
RfcOptions->destination = lDestination;
RfcOptions->client = lClient;
RfcOptions->user = lUser;
RfcOptions->password = lPassword;
RfcOptions->language = lLanguage;

RfcOptions->mode = RFC_MODE_R3ONLY;
if (lHostname[0] == '\0')
RfcConnoptR3only->hostname = NULL;
else
RfcConnoptR3only->hostname = lHostname;
 
if (lSysnr[0] != '\0') RfcConnoptR3only->sysnr = atoi(lSysnr);

if (lGwhost[0] == '\0')
   RfcConnoptR3only->gateway_host = NULL;
else
   RfcConnoptR3only->gateway_host = lGwhost;

if (lGwservice[0] == '\0')
   RfcConnoptR3only->gateway_service = NULL;
else
   RfcConnoptR3only->gateway_service = lGwservice;
RfcOptions->connopt = RfcConnoptR3only;

/* open connection */
hRfc = RfcOpen(RfcOptions);
return hRfc;
}

static void WIN_DLL_EXPORT_FLAGS rfc_error(char *operation)
{
RFC_ERROR_INFO RfcErrorInfo;

std::cerr << "RFC error\n" ;
memset(&RfcErrorInfo,0,sizeof(RfcErrorInfo));
RfcLastError(&RfcErrorInfo);
std::cerr << "key = " << RfcErrorInfo.key;
std::cerr << ", status = " << RfcErrorInfo.status;
std::cerr << ", message = " << RfcErrorInfo.message;
std::cerr << ", internal status = " << RfcErrorInfo.intstat << std::endl;
RfcClose (RFC_HANDLE_NULL);

exit(1);

}

/*
------------------------------------------------------------------------
 Call function
------------------------------------------------------------------------
*/
static RFC_RC WIN_DLL_EXPORT_FLAGS theFunction(RFC_HANDLE hRfc

 ,ITAB_H thItTab

 ,char *xException)
{
/* RFC variables */
RFC_PARAMETER Exporting[1];
RFC_PARAMETER Importing[1];
RFC_TABLE Tables[2];
RFC_RC RfcRc;
char *RfcException = NULL;

/* install structures */
if (handleOfRFC_DATA == 0) {
RfcRc = RfcInstallStructure("BAPI_COMPANYCODE_GETLIST",
                           typeOfRFC_DATA,
                                   ENTRIES(typeOfRFC_DATA),
                                   &handleOfRFC_DATA);
if (RfcRc != RFC_OK)
rfc_error("RfcInstallStructure");
}

/* define export params */
Exporting[0].name = NULL;

/* define internal tables */
Tables[0].name     = "COMPANYCODE_LIST";
Tables[0].nlen     = strlen("COMPANYCODE_LIST");
Tables[0].type     = handleOfRFC_DATA;
Tables[0].ithandle = thItTab;

Tables[1].name = NULL;

/* call function module */
RfcRc = RfcCall(hRfc,"BAPI_COMPANYCODE_GETLIST",Exporting,Tables);

switch (RfcRc) {
case RFC_OK :
Importing[0].name = NULL;
/* receive results */
RfcRc = RfcReceive(hRfc,Importing,Tables,&RfcException);

switch (RfcRc) {
case RFC_SYS_EXCEPTION: strcpy
(xException,RfcException);
case RFC_EXCEPTION: strcpy(xException,RfcException);
}
}
return RfcRc;
}

static RFC_RC WIN_DLL_EXPORT_FLAGS call_function(RFC_HANDLE hRfc)
{
/* RFC variables */
static RFC_RC RfcRc;
char str[256];

/* param variables */
ITAB_H thItTab = ITAB_NULL;
char xException[256];

/* table row variables */
RFC_DATA *tItTab;
unsigned crow;

/* input export parameters */

/* init tables */
if (thItTab==ITAB_NULL) {
thItTab = ItCreate("COMPANYCODE_LIST", sizeof(RFC_DATA),0,0);

if (thItTab==ITAB_NULL)
rfc_error("ItCreate COMPANYCODE_LIST");
}

string comp_code, comp_name;

/* call RFC function */
RfcRc = theFunction(hRfc,thItTab, xException);

switch (RfcRc) {
case RFC_OK:
/* display tables */
for (crow = 1;crow <= ItFill(thItTab); crow++) {
// one row
tItTab = (RFC_DATA *)ItGetLine
(thItTab,crow);
if (tItTab == NULL)
rfc_error("ItGetLine IT_TAB");

// Code
GETCHAR(tItTab->COMP_CODE,str);
comp_code = trim(str);

GETCHAR(tItTab->COMP_NAME,str);
comp_name = trim(str);

// Add to the container
mapData[comp_code] = comp_name;
}
break;

case RFC_EXCEPTION :
/* exception raised */
 std::cerr << "exception";
break;

case RFC_SYS_EXCEPTION:
rfc_error("system exception raised");

case RFC_FAILURE:
rfc_error("failure");

default:
rfc_error("other failure");
     
}

   /* delete tables */
if (ItDelete(thItTab) != 0)
rfc_error("ItDelete IT_TAB");

/*
---------------------------------------------------
 end of caller example code
---------------------------------------------------
*/
return RfcRc;
}

int main(int argc, char** argv)
{
   /* RFC variables */
static RFC_OPTIONS RfcOptions;
static RFC_CONNOPT_CPIC RfcConnoptCpic;
static RFC_CONNOPT_R3ONLY RfcConnoptR3only;
static RFC_ENV RfcEnv;
static RFC_HANDLE hRfc;
static RFC_RC RfcRc;

// Go starting
/* install error handler */
   RfcEnv.allocate = NULL;
RfcEnv.errorhandler = rfc_error;
RfcEnvironment(&RfcEnv);

hRfc = logon(&RfcOptions, &RfcConnoptCpic, &RfcConnoptR3only);

   // Call the function
RfcRc = call_function(hRfc);

if (hRfc != 0)
  RfcClose(hRfc);

printData();

return RfcRc;
}



thefirst.zip
 Description:
Пример проекта на Visual C++

Download
 Filename:  thefirst.zip
 Filesize:  158.12 KB
 Downloaded:  1507 Time(s)

Back to top
View user's profile Send private message Blog Visit poster's website
Lord
Профессионал
Профессионал



Joined: 10 Sep 2007
Posts: 168

PostPosted: Wed Apr 02, 2008 9:56 pm    Post subject: Reply with quote

Если с проблемой еще не разобрались, выложите пример вашего кода
Back to top
View user's profile Send private message
A_Smith
Участник
Участник



Joined: 28 Nov 2007
Posts: 30

PostPosted: Thu Apr 03, 2008 8:12 am    Post subject: Reply with quote

Code:
#include "stdafx.h"
#include "conio.h"
#include "saprfc.h"
#include "sapitab.h"
#include "string.h"
 
void main()
{
   static RFC_OPTIONS        rfc_opt;
   static RFC_CONNOPT_R3ONLY rfc_connopt_r3only;
   static RFC_PARAMETER      exporting[2];
   static RFC_PARAMETER      importing[1];
   static RFC_TABLE          tables[1];
   RFC_HANDLE                handle;
   RFC_RC                    rc;
   char *                    exception_ptr;
   ITAB_H                    ltab;
   char                      lst[100];
   char *                    lpt;
   int                       line, lnr, len;
   
   rfc_connopt_r3only.hostname = "HostAddress";
   rfc_connopt_r3only.sysnr = 1;
 
   rfc_opt.client   = "910";
   rfc_opt.user     = "UserName";
   rfc_opt.language = "E";
   rfc_opt.password = "PassWord";
   rfc_opt.trace    = 1;
   rfc_opt.mode     = RFC_MODE_R3ONLY;
   rfc_opt.connopt = &rfc_connopt_r3only;
   
   ltab    = ItCreate( "buff", 100, 0, 0 );
 
   importing[0].name = NULL;

   exporting[0].name = "ZZ_INPUT_DOC_2_STEP2";
   exporting[0].nlen = 20;
   exporting[0].type = TYPC;
   exporting[0].addr = ltab;

   exporting[1].name = "6";
   exporting[1].nlen = 1;
   exporting[1].type = TYPC;
   exporting[1].addr = ltab;

   tables[0].name = "I_BUFF";
   tables[0].nlen = 6;
   tables[0].type = TYPC;
   tables[0].ithandle = ltab;
   tables[0].leng = 100;
   
   exporting[0].name = NULL;

   handle = RfcOpen( &rfc_opt );
   if( handle == RFC_HANDLE_NULL )
   {
     printf("\nConnect error!");   
   }
   else {printf("\nconnect is OK!");}

   rc = RfcCallReceive( handle,                         
                        "Z_ASM_MON_PERCH",
                  exporting,
                        importing,
                        tables,
                        &exception_ptr );
   RfcClose( handle );

   switch(rc)
   {
      case RFC_OK:                  printf("\nO.K.");break;
      case RFC_FAILURE:             printf("\nError occurred");break;
      case RFC_EXCEPTION:           printf("\nException raised");break;
      case RFC_SYS_EXCEPTION:       printf("\nSystem exception raised, connection closed");break;
      case RFC_CALL:                printf("\nCall received");break;
      case RFC_INTERNAL_COM:        printf("\nInternal communication, repeat (internal use only");break;
      case RFC_CLOSED:              printf("\nConnection closed by the other side");break;
      case RFC_RETRY:               printf("\nNo data yet (RfcListen or RfcWaitForRequest only)");break;
      case RFC_NO_TID:              printf("\nNo Transaction ID available");break;
        case RFC_EXECUTED:            printf("\nFunction already executed");break;
      case RFC_SYNCHRONIZE:         printf("\nSynchronous Call in Progress (only for Windows)");break;
      case RFC_MEMORY_INSUFFICIENT: printf("\nMemory insufficient");break;
      case RFC_VERSION_MISMATCH:    printf("\nVersion mismatch");break;
      case RFC_NOT_FOUND:           printf("\nFunction not found (internal use only)");break;
      case RFC_CALL_NOT_SUPPORTED:  printf("\nThis call is not supported");break;
      case RFC_NOT_OWNER:           printf("\nCaller does not own the specified handle");break;
        case RFC_NOT_INITIALIZED:     printf("\nRFC not yet initialized");break;
        case RFC_SYSTEM_CALLED:       printf("\nA system call such as RFC_PING for connection test is executed");break;
      case RFC_INVALID_HANDLE:      printf("\nAn invalid handle was passed to an API call");break;
      case RFC_INVALID_PARAMETER:   printf("\nAn invalid parameter was passed to an API call or parameter length mismatch (expected and received) has been detected.");break;
      case RFC_CANCELED:            printf("\nAn rfc call has been canceled by user");break;
      case RFC_CONVERSION:          printf("\nAn error during conversion has been detected");break;
      case RFC_INVALID_PROTOCOL:    printf("\nThe received data has an unsupported format. e.g.: non unicode application receives data sended in unicode format");break;      
   }

   if (rc) {printf("\nThe call was successfully completed");}
   else {printf("\nThe call was successfully completed");}
   
 
   lnr = ItFill( ltab );
   if (lnr==0) printf("\nEnpty lines");
   for ( line=1; line <= lnr; line++)
   {
     lpt = (char *) ItGetLine( ltab, line );
     len = strlen(lpt);
     memcpy( lst, (char *) ItGetLine( ltab, line ), len);
     lst[len] = '\0';
     printf( "%s\n", lst );
   } 
   _getch();
}


Запускает ФМ Z_ASM_MON_PERCH(Exporting JOB_NAME, JOB_STEP Import I_BUFF) Входные 2 строковых параметра, на выходе значение взятое из спула фонового задания ZZ_INPUT_DOC_2_STEP2.
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Thu Apr 03, 2008 9:43 am    Post subject: Reply with quote

A_Smith wrote:
Code:
   
   ltab    = ItCreate( "buff", 100, 0, 0 );
 
   importing[0].name = NULL;

   exporting[0].name = "ZZ_INPUT_DOC_2_STEP2";
   exporting[0].nlen = 20;
   exporting[0].type = TYPC;
   exporting[0].addr = ltab;

   exporting[1].name = "6";
   exporting[1].nlen = 1;
   exporting[1].type = TYPC;
   exporting[1].addr = ltab;

   tables[0].name = "I_BUFF";
   tables[0].nlen = 6;
   tables[0].type = TYPC;
   tables[0].ithandle = ltab;
   tables[0].leng = 100;
   
   exporting[0].name = NULL;

}




Видимые спорные моменты. Почему у экспортных параметров указывается itab?
exporting[0].addr = ltab;

Видимо вы должны создать переменную нужного типа, заполнить ее значением и передать через параметр addr указатель на эту переменную. Например так:

Code:
  RFC_STRING    input0;
  input = RfcAllocString (32);
  strcpy ((char *) input0, "ZZ_INPUT_DOC_2_STEP2");
  exporting[0].name = "JOB_NAME";
  exporting[0].nlen = strlen ((char *) exporting[0].name);
  exporting[0].type = RFCTYPE_STRING;
  exporting[0].addr = &input0;
  exporting[0].leng = strlen((char *)input0);

  RFC_STRING    input1;
  input1 = RfcAllocString (10);
  strcpy ((char *) input1, "6");
  exporting[1].name = "JOB_STEP";
  exporting[1].nlen = strlen ((char *) exporting[1].name);
  exporting[1].type = RFCTYPE_STRING;
  exporting[1].addr = &input1;
  exporting[1].leng = strlen((char *)input1);


С табличными параметрами тоже нужно поаккуратней

Code:
ltab    = ItCreate( "I_BUFF", 100, 0, 0 );

tables[0].name = "I_BUFF";
tables[0].nlen = 6;
tables[0].type     = RFCTYPE_CHAR;
tables[0].leng = 100;
tables[0].itmode = RFC_ITMODE_BYREFERENCE;
tables[0].ithandle = ltab;
Back to top
View user's profile Send private message Blog Visit poster's website
A_Smith
Участник
Участник



Joined: 28 Nov 2007
Posts: 30

PostPosted: Thu Apr 03, 2008 2:26 pm    Post subject: Reply with quote

Спасибо большое всем, что не проходите мимо...сейчас попробую внести коррективы Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.