There is a best practice to recognize whether a field is blank because its value is blank or the corresponding XML tag is missing.
Precondition: PI must not arbitrarily add missing tags
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>
At Backend side
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