Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Function over RFC Call

stefan_koehler
Active Contributor
0 Kudos

Hi.

I try to call an Function in SAP over a RFC Call in C++.

I established a connection via RFC and can send the call.

This is my request:

rfc_rc = RfcCall( handle, cha_prog,exporting, tables);

The function i called in SAP requires an importing parameter. So tried to put the format into the exporting parameter but i don`t know how?

My field definition in SAP is:

Parametername: I_IM_ID

TYPE: CHAR(4)

How do i call the RFC correctly with an exporting paramter?

I tried the follwing code

exporting[0].name = "I_IM_ID";

exporting[0].nlen = 7;

exporting[0].type = RFCTYPE_CHAR;

but it doesn`t work.

Where have my value stand, which i want to export to the function?

Is it the "exporting[0].addr" field?

The value i want to export is put in a CString variable called cst_over;

Can someone post the correctly code for an correct RFC call?

I don`t know, if this is the right forum, if not i am sorry.

Greetz

Stefan

9 REPLIES 9

Former Member
0 Kudos

Hi Stefan,

You need to allocate space for the parameter value to be received into, on exporting[0].addr:

Something like:

exporting[0].addr = malloc(<parm len> + 1);

memset(exporting[0].addr,0, <parm len> + 1);

Cheers.

0 Kudos

Hi thanks,

and in which parameter is the value itself set?

The length of my parameter i want to export is always 4

so the coding have to look like

exporting[0].addr = malloc(4);

memset(exporting[0].addr,0, 4);

What is missed?

Perhaps you can post an correctly RFC Call Coding?

With my parameters.

I am looking forward to your answer thank you!

Greetz

Stefan

Former Member
0 Kudos

Hi Stefan,

Can you go into SE37 and display the source code of your RFC, and cut-n-paste the comment section at the top that describes the interface of the Function Module, into your next post on the Forum. Then I'll code up the interface for you.

Cheers,

Piers Harding.

0 Kudos

Hi,

thanks, hereis the header code.

FUNCTION /YOWN/RFDEL.

*"----


""Globale Schnittstelle:

*" IMPORTING

*" VALUE(I_RACKID) TYPE /BROSE/TRACK-RACKID

*" VALUE(I_BZEIT) TYPE /BROSE/TRACK-BZEIT OPTIONAL

*" VALUE(I_DATUM) TYPE /BROSE/TRACK-DATUM OPTIONAL

*"----


The Parameter i want to export is the I_RACKID, he is from TYPE CHAR(4).

Thank you.

0 Kudos

Hi Stefan,

Now I get it. You need to set the value of the parameter = exporting from your client point of view - not the RFCs point of view.

exporting[0].name = malloc(8);

memcpy(exporting[0].name,"I_RACKID", 8);

exporting[0].nlen = 8;

exporting[0].type = RFCTYPE_CHAR;

exporting[0].leng = 4;

exporting[0].addr = malloc(5);

memset(5,0,exporting[0].addr);

sprintf(exporting[0].addr, "%s", some_cpp_value.c_str());

You are responsible for managing your own memory in RFC calls, except for when dealing with tables, so you need to allocate and free it as appropriate.

Hope this helps.

Cheers,

Piers Harding.

0 Kudos

Hi Piers,

all works instead of one coding line

"sprintf(exporting[0].addr, "%s", some_cpp_value.c_str());"

and so it looks by me

exporting[0].name = malloc(8);

memcpy(exporting[0].name,"I_RACKID", 8);

exporting[0].nlen = 8;

exporting[0].type = RFCTYPE_CHAR;

exporting[0].leng = 4;

exporting[0].addr = malloc(5);

memset(exporting[0].addr,0,5);

sprintf(exporting[0].addr, "%d", value->get_racid());

The value i want to export is returned by the method value->get_racid() .. it is an integer value with 4 places..

If i want to compile my programm follwing error message gets out:

error C2664: 'sprintf' : Convert the Parameters 1 from 'void *' into 'char *' not possible.

What is wrong, what have i to do?

0 Kudos

OK. Well if you are using an integer (this assumes that value->get_racid() returns an integer) to write to your char(4), then you should do something like:

/* casting everything to be sure */

sprintf((char *) exporting[0].addr, "%04d", (int) value->get_racid());

Cheers,

Piers Harding.

0 Kudos

Hi Piers,

i can now compile it but if i run the programm.

The command

"rfc_rc = RfcCall( handle, cha_prog,export,tables);"

aborts with the follwing error code:

"RFC_INVALID_PARAMETER"

can you help me?

Thank you,

greetz stefan

Message was edited by: Stefan Köhler

Message was edited by: Stefan Köhler

0 Kudos

For all here is a code that works.

The error was that i dont send the "exporting[1].name = (char *)0;" value which shows that this is the last export parameter....

here a full working coding

exporting[0].name = malloc(8);

memcpy(exporting[0].name,"I_RACKID", 8);

exporting[0].nlen = 8;

exporting[0].type = RFCTYPE_NUM;

exporting[0].leng = 4;

exporting[0].addr = malloc(5);

memset(exporting[0].addr,0,5);

int_racid = value->get_racid();

sprintf((char *) exporting[0].addr, "%04d", int_racid);

exporting[1].name = (char *)0;

Thanks for all!