在ABAP中访问朋友class的静态方法和属性
Access static methods and attributes of the friend class in ABAP
这是我的两个全局 类 的样子:
CLASS zcl_singleton_class DEFINITION CREATE PRIVATE friends ZCL_FLINFO
PUBLIC SECTION.
CLASS-METHODS:
CLASS_CONSTRUCTOR,
get_instance
RETURNING VALUE(r_instance) TYPE REF TO zcl_singleton_class.
PRIVATE SECTION.
types:
TY_CONNECTION_LIST TYPE STANDARD TABLE OF SPFLI WITH KEY carrid connid.
class-data instance type ref to zcl_singleton_class .
class-data CONNECTION_LIST type TY_CONNECTION_LIST .
ENDCLASS.
CLASS zcl_singleton_class IMPLEMENTATION.
method CLASS_CONSTRUCTOR.
instance = instance.
SELECT * FROM SPFLI INTO TABLE CONNECTION_LIST.
endmethod.
METHOD get_instance.
r_instance = instance.
ENDMETHOD.
ENDCLASS.
CLASS ZCL_FLINFO DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
CLASS_CONSTRUCTOR,
get_connection
IMPORTING im_carrid type S_CARR_ID
RETURNING VALUE(re_connection) TYPE.
ENDCLASS.
CLASS ZCL_FLINFO IMPLEMENTATION.
METHOD get_connection.
LOOP at CONNECTION_LIST TRANSPORTING NO FIELDS WHERE carrid = im_carrid.
re_connection = re_connection + 1.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
如何实现 ZCL_FLINFO
的 get_connection
方法,以便它遍历 zcl_singleton_class
的内部 table CONNECTION_LIST
来计算数量给定航空公司的连接数和 return 它在参数中?
我想出了一些适合我的情况。如果 class A(zcl_singleton_class) 向另一个 class B(ZCL_FLINFO) 提供友谊,B 可以访问 A 的私有组件。所以,我只需访问内部 table(CONNECTION_LIST) 通过在我的循环中调用它。
method GET_N_O_CONNECTIONS.
LOOP AT zcl_singleton_class=>CONNECTION_LIST TRANSPORTING NO FIELDS WHERE CARRID = IM_CARRID.
RE_N_O_CONNECTIONS = RE_N_O_CONNECTIONS + 1.
ENDLOOP.
endmethod.
这是我的两个全局 类 的样子:
CLASS zcl_singleton_class DEFINITION CREATE PRIVATE friends ZCL_FLINFO
PUBLIC SECTION.
CLASS-METHODS:
CLASS_CONSTRUCTOR,
get_instance
RETURNING VALUE(r_instance) TYPE REF TO zcl_singleton_class.
PRIVATE SECTION.
types:
TY_CONNECTION_LIST TYPE STANDARD TABLE OF SPFLI WITH KEY carrid connid.
class-data instance type ref to zcl_singleton_class .
class-data CONNECTION_LIST type TY_CONNECTION_LIST .
ENDCLASS.
CLASS zcl_singleton_class IMPLEMENTATION.
method CLASS_CONSTRUCTOR.
instance = instance.
SELECT * FROM SPFLI INTO TABLE CONNECTION_LIST.
endmethod.
METHOD get_instance.
r_instance = instance.
ENDMETHOD.
ENDCLASS.
CLASS ZCL_FLINFO DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
CLASS_CONSTRUCTOR,
get_connection
IMPORTING im_carrid type S_CARR_ID
RETURNING VALUE(re_connection) TYPE.
ENDCLASS.
CLASS ZCL_FLINFO IMPLEMENTATION.
METHOD get_connection.
LOOP at CONNECTION_LIST TRANSPORTING NO FIELDS WHERE carrid = im_carrid.
re_connection = re_connection + 1.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
如何实现 ZCL_FLINFO
的 get_connection
方法,以便它遍历 zcl_singleton_class
的内部 table CONNECTION_LIST
来计算数量给定航空公司的连接数和 return 它在参数中?
我想出了一些适合我的情况。如果 class A(zcl_singleton_class) 向另一个 class B(ZCL_FLINFO) 提供友谊,B 可以访问 A 的私有组件。所以,我只需访问内部 table(CONNECTION_LIST) 通过在我的循环中调用它。
method GET_N_O_CONNECTIONS.
LOOP AT zcl_singleton_class=>CONNECTION_LIST TRANSPORTING NO FIELDS WHERE CARRID = IM_CARRID.
RE_N_O_CONNECTIONS = RE_N_O_CONNECTIONS + 1.
ENDLOOP.
endmethod.