本文介绍了动态方法调用区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最小工作示例:

CLASS lcl_some_class DEFINITION. ""// <-- this is obviously lower case
  PUBLIC SECTION.
    CLASS-METHODS some_static_method. ""// <-- this is obviously lower case
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.
CLASS lcl_some_class IMPLEMENTATION.
  METHOD some_static_method.
    " nothing
  ENDMETHOD.
ENDCLASS.
END-OF-SELECTION.

DATA: lc_class_name_upper  TYPE string VALUE 'LCL_SOME_CLASS',
      lc_class_name_lower  TYPE string VALUE 'lcl_some_class',
      lc_method_name_upper TYPE string VALUE 'SOME_STATIC_METHOD',
      lc_method_name_lower TYPE string VALUE 'some_static_method'.

CALL METHOD LCL_SOME_CLASS=>SOME_STATIC_METHOD. ""ok
CALL METHOD (lc_class_name_upper)=>(lc_method_name_upper). ""ok

CALL METHOD lcl_some_class=>SOME_STATIC_METHOD. ""ok
CALL METHOD (lc_class_name_lower)=>(lc_method_name_upper). ""failure

CALL METHOD LCL_SOME_CLASS=>some_static_method. ""ok
CALL METHOD (lc_class_name_upper)=>(lc_method_name_lower). ""failure

CALL METHOD lCl_SoMe_ClAsS=>sOmE_sTaTiC_mEtHoD. ""ok

我期望带有注释失败"的行表现得与上面相应的行完全一样:区分大小写.但相反,它们失败并显示以下消息之一:

I expected the lines with comment "failure" to behave exactly like the corresponding lines above: To be case-insentive. But instead they fail with one of the following messages:

CX_SY_DYN_CALL_ILLEGAL_CLASS/DYN_CALL_METH_CLASS_NOT_FOUND

zh: 在动态方法调用期间找不到该类.

en: The class could not be found during the dynamic method call.

de: Die Klasse beim dynamischen Methodenaufruf konnte nicht gefunden werden.

de: Die Klasse beim dynamischen Methodenaufruf konnte nicht gefunden werden.

CX_SY_DYN_CALL_ILLEGAL_METHOD/DYN_CALL_METH_NOT_FOUND

zh: 在动态调用过程中找不到该方法.

en: The method could not be found during the dynamic call.

de: Die Methode konnte beim dynamischen Aufruf nicht gefunden werden.

de: Die Methode konnte beim dynamischen Aufruf nicht gefunden werden.

有没有办法让动态调用区分大小写in(除了明显的将字符串转换为大写)?

Is there a way to make the dynamic call case-insensitive (except for the obvious converting the strings to upper case)?

推荐答案

CALL METHOD - dynamic_meth 很简单,关于 (class_name)=>(meth_name)(class_name)=> 方法:

The official ABAP documentation of CALL METHOD - dynamic_meth is straight forward, concerning (class_name)=>(meth_name) and (class_name)=>meth:

class_name 需要一个类似字符的字段,该字段必须在执行语句时以大写字母包含类名

我没有看到任何使内核将名称转换为大写的解决方案.

I don't see any solution to make the kernel convert the name to upper case itself.

注意:我不明白为什么在进行动态调用之前将自己的名称转换为大写是有问题的.

NB: I don't see why it is a problem to convert yourself the name to upper case before doing the dynamic call.

这篇关于动态方法调用区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:40