Skip to Content
Author's profile photo Konrad Thalheim

Use Case NRO API Access: Dynamic Counter Variable

Usually number range objects in b2b addon are used to count the sent messages one after another.

However it is possible by implementing SAP note 2035054, like found in this blog here: NRO access from mapping (ESR), to use the number range objects as a counter within SAP PO.

Let’s say we want do not have the possibility to use a lookup function to ECC or other systems and we need to implement a counter variable accessed and updated within our mappings.

So here is my solution for this by using the number range objects.

For this we will use the combination of the user defined function getNROWithName  to fetch the current counter value – and for updating the counter value we will use the user defined function getNROWithName.


The UDF getNROWithName will not update the counter value.



Implementation Example

Within the QTY segment we want to populate the field D_6060 with the accumulated already delivered quantity. Further we want to update the value of this counter.

For accomplishing this we need to implement the function getNROwithName. Afterwards we update the counter value with the UDF updateNumberRangeObject.

The UDF getNROWithName reads the current counter value from the NRO and writes it into the field D_6060.

Within the variable updateNRO we do the following:

First, the current counter value is fetched and the current delivery quantity for this value is added (upper tree in the illustration). Then, this updated value is used to update the NRO.


Update of the values / Logging of this specific NRO

Within the log of the Number Range Object (NRO) Maintenance you can investigate the behavior of the last calls of this NRO.

Discussion

Advantages:

  • This solution will be implemented relatively quickly.
  • After a complete restart of the PO, the old value is still included – unlike other replication methods.
  • We stay in the same system (PO) without lookups in other systems.

Disadvantages:

  • This is a business logic implementation within the middleware. This solution is for the department poorly controllable and maintainable.
  • If the mapping fails it will still update the NRO value.
  • Ideally, the IDoc has the appropriate value (user enhancement / user exit).

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rahul Yadav
      Rahul Yadav

      Hi Konrad,

      I tried implementing the same thing, but it is giving me the below mentioned error.
      In the test scenario, I was trying to fetch the current value of NRO.

      UDF:

      Error Desc:

      Could you please help me in this regards.

      NWA Logs are as below:
      Tracing for additional info -runtimeexception
      Thrown:
      com.sap.aii.utilxi.misc.api.BaseRuntimeException: Exception:[java.lang.RuntimeException: The values /B2B/Rahul, in com.sap.aii.mappingtool.tf7.rt.Context@5f26a9f2 could not be processed.] in class com.incture.jangir.sachin.FL_NRO method getNROkeyCustom[/B2B/Rahul, com.sap.aii.mappingtool.tf7.rt.Context@5f26a9f2]
      at com.sap.aii.mappingtool.tf7.rt.MethodImplementedIteratorHelper.executeMethod(MethodImplementedIteratorHelper.java:188)
      at com.sap.aii.mappingtool.tf7.rt.FunctionWrapper.calculateCurrentValue(FunctionWrapper.java:106)
      at com.sap.aii.mappingtool.tf7.rt.AbstractFunctionWrapper.cacheValue(AbstractFunctionWrapper.java:31)
      at com.sap.aii.mappingtool.tf7.rt.AbstractFunctionWrapper.getValue(AbstractFunctionWrapper.java:25)
      at com.sap.aii.mappingtool.tfapi.ResIteratorDump.dump(ResIteratorDump.java:53)
      at com.sap.aii.mappingtool.tf7.AMappingProgram.dumpIterators(AMappingProgram.java:750)
      at com.sap.aii.mappingtool.tf7.AMappingProgram.start(AMappingProgram.java:527)
      at com.sap.aii.mappingtool.tf7.Transformer.start(Transformer.java:152)
      at com.sap.aii.mappingtool.tf7.AMappingProgram.transform(AMappingProgram.java:664)
      at com.sap.aii.ibrep.server.mapping.exec.ExecuteXiMappingCommand.transformInternal(ExecuteXiMappingCommand.java:221)
      at com.sap.aii.ibrep.server.mapping.exec.ExecuteXiMappingCommand.execute(ExecuteXiMappingCommand.java:118)
      at com.sap.aii.ib.server.mapping.exec.CommandManager.execute(CommandManager.java:43)
      at com.sap.aii.ibrep.server.mapping.ServerMapService.execute(ServerMapService.java:40)
      at com.sap.aii.ibrep.server.mapping.MapServiceBean.execute(MapServiceBean.java:40)
      at sun.reflect.GeneratedMethodAccessor13470.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(RequestInvocationContext.java:47)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:166)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke(Interceptors_StatesTransition.java:19)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:50)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.doWorkWithAttribute(Interceptors_Transaction.java:37)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.invoke(Interceptors_Transaction.java:21)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_MethodRetry.invoke(Interceptors_MethodRetry.java:46)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:191)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke(Interceptors_StatelessInstanceGetter.java:23)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:25)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:17)
      at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
      at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:138)
      at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:172)
      at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:99)
      at com.sun.proxy.$Proxy8066.execute(Unknown Source)
      at sun.reflect.GeneratedMethodAccessor13469.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sap.engine.services.rmi_p4.P4DynamicSkeleton.dispatch(P4DynamicSkeleton.java:240)
      at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:482)
      at com.sap.engine.services.rmi_p4.server.ServerDispatchImpl.run(ServerDispatchImpl.java:81)
      at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:72)
      at com.sap.engine.services.rmi_p4.P4Message.execute(P4Message.java:43)
      at com.sap.engine.services.cross.fca.FCAConnectorImpl.executeRequest(FCAConnectorImpl.java:999)
      at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:59)
      at com.sap.engine.services.cross.fca.MessageReader.run(MessageReader.java:55)
      at com.sap.engine.core.thread.execution.Executable.run(Executable.java:122)
      at com.sap.engine.core.thread.execution.Executable.run(Executable.java:101)
      at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:328)
      Caused by: java.lang.reflect.InvocationTargetException: null
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sap.aii.mappingtool.tf7.rt.MethodImplementedIteratorHelper.executeMethod(MethodImplementedIteratorHelper.java:177)
      ... 52 more
      Caused by: java.lang.RuntimeException: The values /B2B/Rahul, in com.sap.aii.mappingtool.tf7.rt.Context@5f26a9f2 could not be processed.
      at com.incture.jangir.sachin.FL_NRO.getNROkeyCustom(FL_NRO.java:37)
      ... 57 more
      Caused by: java.lang.ClassCastException: com.sap.aii.nro.apiaccess.NROApiAccessHome
      at com.sap.engine.services.cross.PortableRemoteObjectContainer.narrow(PortableRemoteObjectContainer.java:238)
      at com.sap.engine.system.PortableRemoteObjectProxy.narrow(PortableRemoteObjectProxy.java:24)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:135)
      at com.sap

      Best Regards,
      Sachin Jangir

      Author's profile photo Konrad Thalheim
      Konrad Thalheim
      Blog Post Author

       

      Hi Jangir,

      in my blog https://blogs.sap.com/2016/09/01/nro-access-from-mapping-esr/ I am also using the NroInterface Java Archive. I am not sure if your incture.com archive is able to do the same or what the purpose of it is.

      However in one project one of my customer was using a custom archive for the NRO access. The outcome was that the UDFs were not running in ESR test anymore - just in runtime test.

      Kind regards

      Konrad

      Author's profile photo Kisan Behera
      Kisan Behera

      Hi Konrad,

      I am also facing same issue in runtime. See the below errors:

      Mapping "http://fresenius.com/FI/BancoPopular/OM_PAYEXT_ZPEXR2003_to_BANCOPAYMENT" failed to execute: MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_MM_PAYEXT_ZPEXR2003_to_BANCOPAYMENT_; Details: com.sap.aii.mappingtool.tf7.MessageMappingException; Runtime exception when processing target-field mapping /ns0:MT_BANCO_PAYMENT_IB/Registry_Of_Header/Sequence; root message: Exception:[java.lang.RuntimeException: The values /B2B/BANCOPOPULAR_NRO, in com.sap.aii.mappingtool.tf7.rt.Context@17ff2f00 could not be processed.] in class com.sap.xi.tf._MM_PAYEXT_ZPEXR2003_to_BANCOPAYMENT_ method getNROWithName[/B2B/BANCOPOPULAR_NRO, com.sap.aii.mappingtool.tf7.rt.Context@17ff2f00], ApplicationRuntimeException: Runtime Exception when executing application mapping program com/sap/xi/tf/_MM_PAYEXT_ZPEXR2003_to_BANCOPAYMENT_; Details:

       

      Author's profile photo JOHN YAJJALA
      JOHN YAJJALA

      I am getting this error

       

      Check Result for Object TBS_NRO

      Source text of object Function Library: TBS_NRO | http://ca.tbs/sap has syntax errors:

      Author's profile photo Lakshmana Kumar Vempadapu
      Lakshmana Kumar Vempadapu

      Hi, How did you resolve this error ?

       

      Author's profile photo Lakshmana Kumar Vempadapu
      Lakshmana Kumar Vempadapu

      FYI - It worked after adding EJBJEEArchive jar into the function library. Thank you!