简体   繁体   English

每个 RFC 调用的唯一 ID

[英]Unique ID for every RFC call

I call some RFC module externally which calls other modules and calculates some value inside the call stack and saves it to memory, then reads this value in the end and returns to external caller.我在外部调用一些 RFC 模块,它调用其他模块并在调用堆栈中计算一些值并将其保存到 memory,然后最后读取该值并返回给外部调用者。 The calculation can be different each time so we need to read the memory area accordingly.每次计算可能不同,因此我们需要相应地读取 memory 区域。

The complications of the current case are:目前病例的并发症有:

  1. The module always will be called from the same system, so caller will always be the same该模块总是会从同一个系统调用,所以调用者总是相同的
  2. The user by which the FM will be called is the same, so the user also always be the same调用 FM 的用户相同,因此用户也始终相同
  3. The connections will be reused, exactly like described here , so the ABAP memory also will be the same连接将被重用,就像这里描述的那样,所以 ABAP memory 也将是相同的

The idea is to write to memory with the ID only unique for the current call, not the previous ones, ie the value in the memory will always be relevant.这个想法是写入 memory,其 ID 仅对当前呼叫唯一,而不是以前的呼叫,即 memory 中的值将始终相关。

Let me illustrate the case with this simple FM I created.让我用我创建的这个简单的 FM 来说明这个案例。 The module will return the value only if it is set in the current call, ie only relevant one.只有在当前调用中设置了该值,该模块才会返回该值,即只有相关的一个。

FUNCTION Z_MEM.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     VALUE(E_PAR) TYPE  CHAR50
*"----------------------------------------------------------------------

  DATA id LIKE sy-timlo.

  IMPORT id FROM MEMORY ID 'MAN'.

  IF id IS INITIAL.
  
    id = sy-timlo.
    EXPORT id TO MEMORY ID 'MAN'.
    e_par = id.
    
  ENDIF.

ENDFUNCTION.

I tested it from the outside in a loop for 20 times and got:我从外部循环测试了 20 次,得到:

>>> 154251


    ...
>>> 

So, the memory is reused as expected and all the further runs may consume the wrong value.因此,memory 按预期重用,所有进一步的运行可能会消耗错误的值。

Possible solutions I see here:我在这里看到的可能的解决方案:

  1. To set up JCo client to close RFC connection each time, so that new ABAP memory area will be created each time设置JCo客户端每次关闭RFC连接,这样每次都会创建新的ABAP memory区域
  2. Make unique ID in each run using MD5 hash on FM parameters passed in the current call在当前调用中传递的 FM 参数上使用 MD5 hash 在每次运行中创建唯一 ID

Is there a standard way to uniquely identify RFC call?是否有唯一标识 RFC 调用的标准方法? Maybe some SY field?也许是一些SY领域?

PS In this comment and here they say (and it is quite obvious) closing connection after each call will be slower than usual, so it is not desirable. PS在这个评论这里他们说(而且很明显)每次调用后关闭连接会比平时慢,所以这是不可取的。

The ideas from the comments were useful but unachievable in my case.评论中的想法很有用,但在我的情况下无法实现。

Yes, I could generate the GUID, but the problem was in the way of reading/writing the memory to the same ID.是的,我可以生成 GUID,但问题在于将 memory 读/写到同一 ID 的方式。 The include module that writes the value to memory was located deeply in the call stack, and the READ was conducted in the RFC FM body, so to read/write the value from same memory ID I should have been passed the GUID generated at the RFC entry point (root level of call stack) to the 10th nesting level of call stack, which is obviously impossible, or at least I didn't find a way how to do it.将值写入 memory 的包含模块位于调用堆栈的深处,并且 READ 是在 RFC FM 主体中进行的,因此要从相同的 memory ID 读取/写入值,我应该已经通过在 RFC 生成的 GUID入口点(调用堆栈的根级别)到调用堆栈的第 10 层嵌套,这显然是不可能的,或者至少我没有找到方法。

This is how I solved the problem.这就是我解决问题的方法。 I found an FM which does exactly what I need我找到了一个完全符合我需要的 FM

 CALL FUNCTION 'TH_GET_SESSION_ID'
    IMPORTING
     session_id = id.

I ran some tests with external calling and can confirm that ID generated by the FM is persistent throughout the whole RFC call, but different between calls.我用外部调用运行了一些测试,可以确认 FM 生成的 ID 在整个 RFC 调用中是持久的,但在调用之间是不同的。

The value from SY-MODNO is usefull to track the programm from SUBMIT . SY-MODNO的值对于跟踪SUBMIT的程序很有用。

https://answers.sap.com/questions/627157/how-could-i-create-unique-memory-id.html https://answers.sap.com/questions/627157/how-could-i-create-unique-memory-id.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM