Skip to Content
author's profile photo Former Member
Former Member

Receiving and sending binary in a function

Hi,

at first, something I did in another project I have made, just to describe the problem better:

Previously, I have programmed a WebDynpro Java Application and the BAPIs for that. The Webdynpro had to send objects, like jpg pictures or something else, to the backend system by calling a bapi.

That was possible to handle by using an importing parameter from the type "RAWSTRING". Inside the function, I have writte the content of that string to a file on the SAP server.

Later on, with another function, I had to read this jgp from the SAP server again and send it back in in an exporting parameter of the type "RAWSTRING".

That was possible without any problems....

Now, I have a situation, which is a little bit more difficult. Now In have an external system with a c++ application, whcih should send XML files in binary (rawstring) to the SAP, SAP should then read that xml file, select some data from the database, build a response XML and send this as binary (rawstring) back to the server.

This is almost the same like I did in my other project. but now, I have to read the XML-tags of the binary file, work with the content and build a XML file in a binary stream as result.

Do you think, I should save the incoming XML-binary stream in a temporary file on the SAP server, read it as textfile, interprete the XML tags, select the data, build the xml, write it to a binary file on the sap server and send that back?

Or how to read the XML tags directly from the binary stream I´m getting inside of the function.

Hopefully my description was understandable and you know, what I mean! 😊

Greetings Michael

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2007 at 01:37 PM

    Hi,

    ABAP provides the feature called as Transformation which you can use here.

    Using transformation, you can convert XML message into ABAP structures and vice versa.

    You need not parse the xml in your code. That transformation wil take care of that.

    Hope this will help you.

    ~ Ramanath.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2007 at 02:22 PM

    yeah it is possible to do that provided you are ready to write your own parser for that..

    but i wud suggest you to use the existing features provided in ABAP instead of Reinventing the wheel..

    ~ Ramanath.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hey, you are right!

      But I´m getting the file as binary in an importing paramter of the type rawstring. So how to read the XML of this binary stream without saving it to the SAP system and reading it in text mode again?

      Can you give me an advice on that?

      Thank you very much

  • author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2007 at 02:33 PM

    Hi,

    You can pass the rawstring to the transformation and it will take care of reading it appropriately and return you the ABAP structures.

    Have a look at the sample code below.

    CALL TRANSFORMATION <transformation_name>

    SOURCE XML <xmlsource>

    RESULT msg_hdr = lv_msg_comm_hdr

    where xmlsouce is the rawstring and msg_hdr is the ABAP type which you want to be populated from that xml message.

    Hope this will help you.

    ~ Ramanath.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Ok, super!

      What about <transformation_name> ?

      And I have heard, if I also use transformation to build XML files from an internal table, the tag names are inculding something with "ABAP", right?

      I think, to build up exactly the XML files, the server application needs, I have to

      use the classes and methods I have used in my example programs.

  • author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2007 at 02:54 PM

    Hi,

    The transformation_name is the Transformation Object that you will create (just like a report program or a function module)

    Go to transaction SE80. Right click on the package name and select "Create transformation". Choose the type of transformation as Simple Transformation.

    Typically the transformation has 2 tags named <Serialize> and <Deserialize>.

    Serialize tag will come into picture when you are converting ABAP structure into XML and Deserialize will come into picture when you are converting XML message into ABAP structures.

    The example which i had given you was of DESERIALIZATION.

    For serialization the syntax would look like,

    CALL TRANSFORMATION <transformation_name>

    SOURCE

    msg_hdr = ls_xcs_message_comm_header

    RESULT XML <xml_output>.

    you can pass as many source ABAP structures as you want.

    Hope this will help you.

    ~ Ramanath.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Ok, thank you for the detailed description.

      And what about the tag names in the output XML? Is there something included, like "ABAP" in the tagnames?

      And how would you convert the XML data string in a binary rawstring?

      Thanks!

  • author's profile photo Former Member
    Former Member
    Posted on Sep 06, 2007 at 03:11 PM

    Hi,

    The output of the transformation will be in rawstring format only.. u need not do anything for that..

    As i mentioned earlier, the <deserialize> tag will convert the ABAP structure into XML message.

    You can specify the XML tag names in the <deserialize> tag as shown below.

    <tt:deserialize>

    <Msg>

    <tt:attribute name="type" value-ref="msg_hdr.MESSAGE_TYPE"/>

    <tag_name>

    <tt:attribute name="attr" value-ref="$wa-attr"/>

    </tag_name>

    </Msg>

    </tt:deserialize>

    The tag_name can also be decided at run time. For that you can have a LOOP construct inside this transformation template and deciding the tag_name dynamically.

    Hope this helps.

    ~ Ramanath.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 08:48 AM

    Hi Michael,

    Is your problem resolved or are you stuck on some point.

    Do let me know if you have any problem in solving this issue.

    ~ Ramanath.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.