cancel
Showing results for 
Search instead for 
Did you mean: 

MII JSON to RFC Table

Joery
Explorer
0 Kudos

Hi all,

I have an MII transaction where I receive a JSON string as input. This string contains all field value pairs that are needed by the RFC on R3 that I want to call from MII. The RFC input consists of a table which can contain multiple lines (with data from the JSON string).

What are the possible ways of handling this or what is the best practice for handling this and where can I find some information/guidelines on how to do this.

Many Thanks in advance,

Joery

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Joery,

If you are using SAP MII 14.0 then you can use Json_To_XML_Converter action block available in MII workbench.

For example if your input JSON string is as below

{

  "geometries" :

  [{

      "xmin" : -4,

      "ymin" : -60,

      "xmax" : 25,

      "ymax" : -41

    }

  ]

}

Then on using Json_To_XML_Converter will provide you an XML output shown as below.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<root>

    <geometries>

        <element>

            <xmin>-4</xmin>

            <ymin>-60</ymin>

            <xmax>25</xmax>

            <ymax>-41</ymax>

        </element>

    </geometries>

</root>

Then you can do an XSLT transformation on the above output XML to generate the RFC/BAPI request structure. May be something like below which is just an indicative xml and not the actual RFC structure.

<RFC_READ_TABLE>

     <TABLE>

          <item>

                 <xmin>-4</xmin>

                 <ymin>-60</ymin>

                 <xmax>25</xmax>

                 <ymax>-41</ymax>

          </item>

     </TABLE>

</RFC_READ_TABLE>

Hope this helps !

Regards,

Prashant Mittal

Joery
Explorer
0 Kudos

Thx for the answers Padma and Prashant.

Both answers are helpfull and I will try to use the second method as it seems the cleaner solution.
For the first method there is the problem that it is (by my knowledge) not possible to itterate over json elements.

For the second I already well on my way. I have trired to convert the json to xml by using an xsl file but that was resulting in a rather complex xsl file. Then I used the json to XML convertor to get an xml file (as these are easier to work with in MII). So all that is left now is to write an xsl file to get the xml in the right format to pass to the RFC.

Thx a lot guys.

Former Member
0 Kudos

Hi,

It is certainly possible to iterate over JSON elements using a "for in" loop:

http://jsfiddle.net/yNfrt/

var x = {

    "a":"element a",

    "b":"element b"

};

for (var key in x) {

    alert(key + " -> " + x[key]);

}

The main question to answer is on your architecture : Do you create simple basic MII transactions that will be reused by others or should MII do the main calculations and transformations and keep the client side complexity minimal?

Joery
Explorer
0 Kudos

Hello again,

I have solved the problem.
Sorry for the somewhat late update here but it has been kind of a hectic week.

The client side complexity has to be minimal for the project.
That said most processing happens on MII and R3.

The solution I used is ass follows:

  1. Transform JSON to XML by using the json_to_xml action block
  2. Loop over the elements in the resulting xml to add them to an MIIxml document
  3. Perform XSL transformation on the resulting MIIxml so that it can be passed to the RFC

I needed to create an MII document instead of using the first normal xml because i had to add another input parameter for the RFC besides the table.

former_member204240
Active Participant
0 Kudos

Great.

You could have used a calculated column action , if it is just one extra input along with your xml to add.

Anyways its good you are done through.

Regards,

Padma

Answers (1)

Answers (1)

former_member204240
Active Participant
0 Kudos

Create transaction parameters which is of same type as RFC item and table, Repeat on your json string and assign to trx parameters.

You can refer below link to do that.

http://scn.sap.com/people/padmavathi.rao2/blog/2009/03/14/mii-odyssey-how-to-pass-table-structure-to...