Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a range table ( SAP structure) as input to a function module(RFC) #9

Closed
programmingaha opened this issue Jul 6, 2022 · 2 comments

Comments

@programmingaha
Copy link

Hi,
First I want to thank you personally for sharing this awesome library.
I came across this issue yesterday.
Suppose you have a function module (Z_Function) in SAP that takes parameter "I_RANGE" which is based on this structure Z_Erdat.
The structure has these fields:
SIGN -> char -> length 1
Option -> char -> length 2
Low -> ERDAT -> DATS (date with 8 character length)
HIGHT -> ERDAT-> DATS (date with 8 character length)
I want to create this range table based on Z_Erdat and send it to Z_Function as parameter I_RANGE.
Following your code I created this:

` public class I_RANGE
{
public Z_Erdat erdat { get; set; }

}

public class Z_Erdat
{
    [RfcEntityProperty("SIGN", SapDataType = RfcDataTypes.CHAR, Length = 1)]
    public string Sign { get; set; }

    [RfcEntityProperty("OPTION", SapDataType = RfcDataTypes.CHAR, Length = 2)]
    public string Option { get; set; }

    [RfcEntityProperty("LOW", SapDataType = RfcDataTypes.DATE_8)]
    public DateTime Low { get; set; }

    [RfcEntityProperty("HIGH", SapDataType = RfcDataTypes.DATE_8)]
    public DateTime High { get; set; }
}

public class Z_FunctionInputParameter : IRfcInput
{
    [RfcEntityProperty("I_RANGE")]
    public I_RANGE range { get; set; }

}`

Based on these when I try to run ExecuteRFCAsync like below:

var result = await client.ExecuteRfcAsync<Z_FunctionInputParameter , Z_FunctionOutputParameter>("Z_Function", inputParameter);

I get the following error:
RfcException: SAP RFC Error: RFC_CONVERSION_FAILURE with message: I_Range of type RFCTYPE_TABLE cannot be converted to type RFC_STRUCTURE_HANDLE

In a nutshell, I want to pass the I_Range parameter which is based on a range structure Z_Erdat to function module Z_Function.
I appreciate your help.

@metalsimyaci metalsimyaci pinned this issue Aug 16, 2022
@burakayser
Copy link
Collaborator

burakayser commented Aug 17, 2022

Are you sure I_RANGE parameter is a structure. Can it be a table? Please use like below.

public class Z_FunctionInputParameter : IRfcInput
{
    [RfcEntityProperty("I_RANGE")]
    public I_RANGE[] range { get; set; } //ARRAY
}

public class I_RANGE
{
    [RfcEntityProperty("SIGN", SapDataType = RfcDataTypes.CHAR, Length = 1)]
    public string Sign { get; set; }

    [RfcEntityProperty("OPTION", SapDataType = RfcDataTypes.CHAR, Length = 2)]
    public string Option { get; set; }

    [RfcEntityProperty("LOW", SapDataType = RfcDataTypes.DATE_8)]
    public DateTime Low { get; set; }

    [RfcEntityProperty("HIGH", SapDataType = RfcDataTypes.DATE_8)]
    public DateTime High { get; set; }

}

@programmingaha
Copy link
Author

Hi @burakayser ,
It solved my problem. Thanks a lot.
To answer your question I_RANGE is a "Ranges Table Type" when I look it up in SAP which is based on another structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants