eclipse 未知类型“zcalc_result”

dgjrabp2  于 2023-01-13  发布在  Eclipse
关注(0)|答案(1)|浏览(146)

我正在尝试使用Eclipse对一个abap代码运行一个统一测试。我正在学习YouTube上一个名为Abap101的频道的视频系列。一切都很顺利,直到他使用了来自zcalc_result类型的变量。它似乎在视频上运行得很好,但我的代码显示错误消息“ZCALC_RESULT TYPE IS UNKNOWN”

REPORT zfsaf_tdd3_babysteps.

*Desenvolvedores:
*Salário igual ou aima de $3000, desconto de 20%
*Salário abaixo de $3000, desconto de 10%
*
*DA e Testadores:
*Salário igual ou acima de de $2500, desconto de 25%
*Salário de $2500, desconto de 15%

CLASS employee DEFINITION.

    PUBLIC SECTION.

        METHODS constructor IMPORTING employee_name TYPE string
                                      employee_salary TYPE zcalc_result
                                      employee_position TYPE string.
        METHODS get_salary RETURNING VALUE(salary) TYPE zcalc_result.
        METHODS get_position RETURNING VALUE(position) TYPE string.

    PRIVATE SECTION.
        DATA name TYPE string.
        DATA salary TYPE zcalc_result.
        DATA position TYPE string.

ENDCLASS.

CLASS employee IMPLEMENTATION.

    METHOD constructor.
        me->name = emplyee_name.
        me->position = employee_position.
        me->salary = employee_salary.
    ENDMETHOD.

    METHOD get_salary.
        salary = me->salary.
    ENDMETHOD.

    METHOD get_position.
        position = me->position.
    ENDMETHOD.

ENDCLASS.

CLASS test_payment_calculator DEFINITION FOR TESTING RISK LEVEL HARMLESS.
    PRIVATE SECTION.
        DATA test_employee TYPE REF TO employee.
        DATA test_payment_calculator TYPE REF TO payment_calculator.
        METHODS setup.
        METHODS calc_developer_bellow_limit FOR TESTING.
ENDCLASS.

CLASS test_payment_calculator IMPLEMENTATION.
    METHOD setup.
        CREATE OBJECT me->test_payment_calculator.
    ENDMETHOD.
    
    METHOD calc_developer_bellow_limit.
        CREATE OBJECT me->test_employee
            EXPORTING
                employee_name = 'Chaves'
                employee_position = 'Developer'
                employee_salary = '1500.00'.
                
                DATA(value) = me->test_payment_calculator->calculate_payment(  ).
                
                cl_abap_unit_assert=>assert_equals( exp = '1350' act = value ).
             
    ENDMETHOD.

ENDCLASS.

CLASS payment_calculator DEFINITION.
    PUBLIC SECTION.
        METHODS calculate_payment IMPORTING emploee TYPE REF TO employee
                                  RETURNING VALUE(value) TYPE zcalc_result.
ENDCLASS.
    
CLASS payment_calculator IMPLEMENTATION.
    METHOD calculate_payment.
        value = '1350.00'.
    ENDMETHOD.
ENDCLASS.

我期待运行一个测试激活代码,但我得到了给定的消息时,我试图激活它。

flmtquvp

flmtquvp1#

zcalc_result似乎是一个仍需定义的自定义数据类型。可以使用TYPES关键字将其定义为程序中的一个类型,也可以将其定义为数据字典中的一个全局类型(事务处理SE11)。以字母z开头的名称暗示了后者,但也可以是前者。
当你在学习一个教程时,有可能作者已经做了,但你跳过了这一部分,有可能作者接下来要做这一部分,或者有可能作者忘记提到这一部分。
从上下文判断,这个类型的目的是保存货币值。所以如果你想自己声明它,你应该把它声明为一个压缩的数字(类型P),有一个合理的长度和两位小数。例如,在程序的顶部有这样一行:

TYPES: zcalc_result TYPE p LENGTH 10 DECIMALS 2.

相关问题