Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

"RFC_READ_TABLE" #84

Closed
siasty opened this issue May 25, 2021 · 6 comments
Closed

"RFC_READ_TABLE" #84

siasty opened this issue May 25, 2021 · 6 comments
Labels
question Further information is requested

Comments

@siasty
Copy link

siasty commented May 25, 2021

Can you give example how to use "RFC_READ_TABLE"

@fw2568
Copy link
Contributor

fw2568 commented May 25, 2021

try this example:

var clientTable = await context.CallFunction("RFC_READ_TABLE",
    Input: f => f.SetField("QUERY_TABLE", "T000"),
    Output: f => 
        from fields in f.MapTable("FIELDS", s=>
            from fieldname in s.GetField<string>("FIELDNAME")
            from offset in s.GetField<int>("OFFSET")
            from length in s.GetField<int>("LENGTH")
            select new { fieldname, offset, length }
            )
        from lines in f.MapTable("DATA", s=>s.GetField<string>("WA"))
        select lines.Map(line =>
            fields.ToDictionary(field => field.fieldname, field =>
                {
                    //special handling for last field, as nwrfc truncates string at end
                    var length = field.offset + field.length > line.Length
                        ? line.Length - field.offset
                        : field.length;

                    return line.Substring(field.offset, length);
                })
        )
).IfLeftAsync(l=>throw new Exception(l.Message));

foreach (var row in clientTable)
{
    foreach (var column in row)
    {
        Console.Write($"{column.Value}\t");
        
    }
    Console.WriteLine();
}

However, as an ABAP developer, I can only advise you against using RFC_READ_TABLE.
This function module has some limitations and does not work for all tables. There is no type conversion and the like. It is better to use your own function modules with the table structure as export parameter.

@siasty
Copy link
Author

siasty commented May 25, 2021

thanks, I know that RFC_READ_TABLE has some limitations and is not worth using but it is a good example for testing.
can you tell me how to fill the tables in input and structure?

M.

@fw2568
Copy link
Contributor

fw2568 commented May 25, 2021

can you tell me how to fill the tables in input and structure?

I'm sorry, but I didn't get that. Do you mean in general how to fill input parameter?

@siasty
Copy link
Author

siasty commented May 25, 2021

Yes, it's about the parameter SetTable(tableName , inputList , map)
how to define SetTable in input

@fw2568
Copy link
Contributor

fw2568 commented May 25, 2021

Ok, yes I know the signature looks tricky ;-)

in input list you pass a IEnumerable of any type. The mapping function map will then be called for any entry in inputList and with a new structure entry for the input table.

here a sample that returns all users that starts with A, B, or C.

var userNamesSearch = new string[] {"A*", "B*", "C*"};

var userList = await context.CallFunction("BAPI_USER_GETLIST",
    Input:f => f.SetTable("SELECTION_RANGE", userNamesSearch , (structure,userName) => structure
            .SetField("PARAMETER", "USERNAME")
            .SetField("SIGN", "I")
            .SetField("OPTION", "CP")
            .SetField("LOW", userName)
        ),

    Output: f=> f.MapTable("USERLIST", s=>s.GetField<string>("USERNAME"))
).IfLeftAsync(l=>throw new Exception(l.Message));

foreach (var userName in userList)
{
    Console.WriteLine(userName);
}

@siasty
Copy link
Author

siasty commented May 25, 2021

thanks for the help

@fw2568 fw2568 closed this as completed May 25, 2021
@fw2568 fw2568 added the question Further information is requested label May 25, 2021
@dbosoft dbosoft locked and limited conversation to collaborators May 25, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants