on 01-27-2014 9:18 AM
Dear Experts,
I have a transaction where I dynamically determine an MDO name and then need to perform an insert into this MDO.
As the MDO name is dynamically determined, I want to write a dynamic insert query using a generic MDO object. Has anyone experience in how to dynamically pass the attribute names and values to the insert query? As I would not know the structure of the MDO upfront, I cannot populate the AttributeName and AttributeValues parameters.
Or is there something I am overlooking?
Any pointers towards the solution would be highly appreciated.
Regards,
Saumya Govil
Hi Saumya,
It is possible to dynamically insert values in an MDO. These are the parameters you might need,
Here, the MDO could be your any generic MDO (Persistent MDO) . To insert into an MDO, the columns or the attributes should be the custom ones and the MDO should not have a data provider. Moreover, for insert, we do not need a data provider too. "MDO Insert Mode : Inserts persisted data for an MDO with custom attributes only. Persisted data cannot be inserted for an MDO with a data provider and data attributes."- SAP Help Doc
AttributeName.X and AttributeValue.X determines the columns and columns values. Here Column1 and Column2 are columns/attributes of my MDO.
Mode would be Insert,
Server would be MDOConnector.
I used the MDOQuery Action block in a transaction, the same parameters can also be used via illuminator URL.
http://localhost:50000/XMII/Illuminator?server=MDOConnector&Mode=Insert&MDO=MyMDOPath&<Rest of the param name and value pairs> .
Regards
Tufale Ashai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Tufale,
Thanks a lot for your reply.
Actually I am doing exactly what you stated above. The only difference is that I would not know till run time how many attributes I would like to insert. So, I cannot pass name and values in the AttributeName and AttributeValues though it works fine if I do that (as you stated in your reply).
If I do that, it would be almost like hard-coding for a particular MDO type.
Is there any other way to pass the attributes? May be in the parameter 'Attributes' as a form of some XML/map with name value pair?
Regards,
Saumya Govil
To add to it, if you need to get the structure of the MDO dynamically, then one way is to do select * in MDO. This is possible by passing the values of "Attributes" param as "*".
This will give you the output, from which column names could be got and passed on to the insert query.
Note: This is a two step process. Select (need this to get column names) and then Insert .
Regards
Tufale Ashai
Message was edited by: Tufale Ashai
I don't think so Saumya,
If I have to pass "n" attribute name and values at runtime, and 'n' is a runtime value, then I would pass AttributeName.1 till AttributeName.n and similarly AttributeValue.1 till AttributeValue.n , these are the name value pairs.
I can either make use of a transaction or an Illuminator call.
Regards
Tufale Ashai
Thanks again Tufale.
I was just wondering how would I pass the 'n' attributes. I know it is a real technical question, but that is where I am stuck at. I understand that I can get the attribute list using the select statement, but how to pass it dynamically to a single insert query?
Any ideas please?
Regards,
Saumya Govil
Saumya,
If I understand your query correctly, you have to do a insert dynamically, and you would pass the attributes at runtime.
Let us consider an example that we have a scenario where we determine that we need to insert two columns, Assuming that we know the MDO and its attributes.
If we are directly calling Illuminator URL, then
http://localhost:50000/XMII/Illuminator?server=MDOConnector&Mode=Insert&MDO=MyMDOPath&<This attribute list we pass the >
For direct web calls, it would be used quite easy, use as many AttributeName.x and AttributeValue.x in ascending order as the number of columns in MDO. Then make a http call via JS/Jquery/AJAX
However, if we do the same thing through a transaction, then we would not be able to use the configuration dialog. We need to use the link editor to dynamically generate links.
This is how it can be done, I am not sure how links can be generated dynamically, however, we can use the same concept as we used in web page. Generate the URL dynamically.
"server://XMII/Illuminator?server=MDOConnector&Mode=Insert&MDO=TufaleAshai/MIIOBJ/MDO1&&content-type=text/xml&AttributeName.1=ID&AttributeValue.1=100&AttributeName.2=Name&AttributeValue.2=Hunter"
The Attribute Name and Values(URL in bold) can be concatenated to form as many pairs we want. Append it to out base URL(URL in Italics) and the do a HTTPPost.
Here we may not be using the the standard query action block to do the job, but this would achieve the purpose.
Regards
Tufale Ashai.
User | Count |
---|---|
11 | |
6 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.