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

Unable to convert from bool to ABAP Flags #81

Open
gedlbauer opened this issue Feb 23, 2023 · 3 comments
Open

Unable to convert from bool to ABAP Flags #81

gedlbauer opened this issue Feb 23, 2023 · 3 comments

Comments

@gedlbauer
Copy link

Hi @huysentruitw and Team,

in my Application I need to convert from/to bool in .NET. As far as I know, there are no bools in SAP, but there are FLAG Types (CHAR(1)).

According to the Documentation, ABAP_TRUE is an alias for the Character 'X' while ABAP_FALSE is ' '. Using this information it shuld be possible to map FLAGs to bools with the logic 'X' => true, ' ' => false.

Is it possible to add support for boolean mapping?

Kind regards,
Georg Edlbauer

@tom-j-irvine
Copy link

@gedlbauer - I would argue that you don't need any automated mapping. The fact that you provide mapping classes for both the result and parameters give you what you need (and more flexibility overall). A Result class below shows an example:

class SomeFunctionResult
{
    [SapName("RES_ABC")]
    public string Abc { get; set; }

    [SapName("SOME_FLAG")]
    public string SomeFlag { get; set; }

    [SapIgnore]
    public bool SomeBool => SomeFlag.Equals("X");
}

And the opposite, providing input parameters to the function could look like this:

class SomeFunctionParameters
{
    [SapName("RES_ABC")]
    public string Abc { get; set; }

    [SapName("SOME_FLAG")]
    public string SomeFlag => SomeBool ? "X" : "";

    [SapIgnore]
    public bool SomeBool { get; set; }
}

@gedlbauer
Copy link
Author

@tom-j-irvine this is true for primitive (elemtary) types, I haven't thought about that.
But what if your param/return type is a struct in ABAP respectively a class in .NET? I don't want to pollute my domain classes with this mapping overhead and I also don't want to use an additional Component like AutoMapper, as this would make no sense when using RFC to connect the two systems.

Maybe it would be a good idea to open up the api in general to allow the user of the library to add additional mappings on top of the built-in ones? I do not only think about bools but also allowing mapping of enum types, etc. as well?

@tom-j-irvine
Copy link

@gedlbauer Yes, you could do similar things in structure/table classes. But, I'm afraid you lost me with your "mapping overhead" comment. Personally, I just see the ability to control what is often very messy data from SAP. I've used the library extensively and often need to add special handling for a lot of the data from SAP. Examples include where SAP concatenates multiple values into single fields, stores non-character data in character types (numbers, dates, times, and to your point bools), and often just uses non-intuitive values for certain things (single-letter codes, etc). The majority of this "translation" that I've added could not be automated because it is specific to the function being called and the data contained.

Additionally, when calling SAP-delivered functions, some will include multiple structures/tables that often contain hundreds of fields. When consuming these functions, you can just map the structures and fields you need and only those values will be deserialized into your classes.

To be clear, I'm not one of the developers, but I have used the library a lot and am extremely happy with this design. Feel free to add more comments as maybe one of the developers will see an opportunity, but unless you are building completely custom functions in the SAP system, you are likely going to need to add special handling for many things beyond boolean values.

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