Reputation: 21
I am developing a creation/modification web service in SAP. Creation is OK but for modification the calling system has a standard:
In SAP, I am in a class and see a simple structure of fields. No view of the XML. In addition, between me and other system is SAP-PI, a middleware. Apparently, PI always sends all tags. So how do I detect the three states?
For now our solution is PI sends me all tags and for those that he detects as "present" he adds an attribute is_present='X' to the tag. With this all the fields become structures with two fields: CONTENT, IS_PRESENT.
Before I rework my code, does anybody know if there is another way to do this?
Upvotes: 2
Views: 1135
Reputation: 1803
There is a best practice to recognize whether a field is blank because its value is blank or the corresponding XML tag is missing.
Because
Apparently, PI always sends all tags
is generally false. I don't know if your PI mapping adds missing tags for some reason but generally speaking PI definitely has the ability keep a tag absent in the xml resulted after the conversion.
If your PI mapping must add those missing tags or you can't change it, you can stop reading further.
Assuming you have the following situation:
[Source xml] -> PI -> [Converted xml] -> ECC or S/4
And source xml contains
<root>
<field1>changed value</field1>
<field2></field2> <!-- value to be cleared -->
<!--
<field3> is missing in this particular message
-->
</root>
The message resulting after the PI conversion should be like
<root_proxy>
<field1>changed value</field1>
<field2>value to be cleared</field2>
<!--
<field3> is missing in this particular message
-->
</root_proxy>
And not
<root_proxy>
<field1>changed value</field1>
<field2></field2> <!-- value to be cleared -->
<field3></field3> <!-- tag added by PI -->
</root_proxy>
In the input data of your inbound method you'll find some fields called CONTEXT
(PRXCTRLTAB
type). You have one CONTEXT
for every structure, in case of deep structures.
In this table you can find the field names where XML is missing. Example:
loop at input-root_proxy-context into data(ls_context). " cycle through all input fields
case ls_context-value.
when sai_ctrl_none. " handle missing xml tag
when sai_ctrl_initial. " handle fields with initial value
endcase.
endloop.
To activate this feature implement the CONSTRUCTOR
of your ABAP Proxy class and set SET_EXTENDED_XML_HANDLING = 'X'
. For example:
DATA:
lo_context TYPE REF TO if_ws_server_context,
lo_protocol TYPE REF TO if_wsprotocol_payload.
lo_context = cl_proxy_access=>get_server_context( ).
lo_protocol = lo_context->get_protocol( if_wsprotocol=>payload ).
lo_protocol->set_extended_xml_handling( abap_true ).
Source: Activating Extended XML Handling
Upvotes: 2