stransform 日期的 处理

今天在做银行返回报文调用CALL TRANSFORMATION的XML转到SAP结构时,银行返回的日期为YYYYMMDD格式,我定义的SAP结构为SY-DATUM,在STRANS中定义的格式如下

stransform 日期的 处理 - 第1张  | 优通SAP

原来想关应该是能直接转换,可结果报错,

An exception has occurred which is explained in more detail below. The
exception is assigned to class ‘CX_SY_CONVERSION_NO_DATE_TIME’ and was not
caught in procedure
“CONVERT_XML_TO_SAP” “(METHOD)”, nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated this
exception, the current program was terminated.
The reason for the exception is:
Date 20220325 has an invalid format. The system could not interpret it in
the representation “yyyy-mm-dd”.
If the termination occurred when using MOVE EXACT, the rules apply for
MOVE EXACT. Otherwise, the rules for the deserialization of type
XSDDATE_D apply.
stransform 日期的 处理 - 第2张  | 优通SAP
这大概是说,传入的的日期格式应该是要yyyy-mm-dd格式,

所以就想着应该可以在转换中调用一下XLST的函数(格式转换),或者是SAP的函数(比如FORMAT_DATE_4_OUTPUT),可把传入的按YYYY-MM-DD转换,可折腾了一整天都有没调用成功。

最后只能用字符截取办法解决,这也算一办法了。办法如下。

stransform 日期的 处理 - 第3张  | 优通SAP