goenning / SharpSapRfc

Making SAP RFC calls even easier with .NET
MIT License
84 stars 27 forks source link

RfcResult.GetTable<>() can't map nested items list #27

Open ghost opened 9 years ago

ghost commented 9 years ago

SharpSapRfc is a great helper for calling SAP functions and getting the retrieved data mapped. Great work.

Using it in a real project, I ran into a problem handling nested XML "tables".

By calling an SAP Function Module using SoapSapRfcConnection.ExecuteFunction(), I get an XML from SAP that looks like:

<CT_WF_USERS>
    <item>
        <VBELN>4300303500</VBELN>
        <USERS>
            <item>
                <PARVW>ZE</PARVW>
                <PERNR>04040803</PERNR>
            </item>
            <item>
                <PARVW>ZL</PARVW>
                <PERNR>01981291</PERNR>
            </item>
            <item>
                <PARVW>ZM</PARVW>
                <PERNR>04042574</PERNR>
            </item>
        </USERS>
    </item>
    <item>
        <VBELN>4300303477</VBELN>
        <USERS>
            <item>
                <PARVW>ZE</PARVW>
                <PERNR>04042574</PERNR>
            </item>
            <item>
                <PARVW>ZM</PARVW>
                <PERNR>04044878</PERNR>
            </item>
        </USERS>
    </item>
</CT_WF_USERS>

I want to map this XML into an object structure like:

User {
    string PARVW,
    string PERNR
}

WfUsers {
    string VBELN,
    User[] USERS
}

Using RfcResult.GetTable<WfUser>("CT_WF_USERS"), I am not able to achieve this. The reason is, that GetTable<>() does not handle the inner items list correctly, but simply treats it as a string.

Looking at you code in SoapRfcStructureMapper.FromXml<T>() I figured out that SetProperty() is always called passing the InnerText of an XML node. In short, it does not consider inner XML "tables".

Is there a chance to get this functionality added to your component? Otherwise, I would have to create a workaround in order to get this case working.

I'm looking forward to your feedback.

goenning commented 9 years ago

I'm this project is helping you.

This issue made me confused. I always thought that nested strcuture was not supported on Remote Function Call, but I don't know why, because I can't find any reference in SAP docs.

I'll leave this issue open and work on it when I get some time. If you have urgency, I suggest looking for a workaround for now.

HoffmannThomas commented 8 years ago

Nested structures/tables (with theoretically infinite depth) are supported by the new SAP NW RFC SDK besides other things like UTF8, STRING/XSTRING and SSO. With this the serialization transformation to XML for ABAP-OO is now also compatible with RFC calls.

For example FM CTS_WBO_API_READ_REQUESTS_RFC results in a table CTS_REQUESTS of structure CTS_REQUEST, which itself includes another structure CTS_REQ_HEADER and two nested tables CTS_REQ_ATTRS and CTS_TASK_HEADERS.