Home > Net >  Unknown type "zcalc_result"
Unknown type "zcalc_result"

Time:01-16

I am trying to run a unity test on an abap code using Eclipse. I am learning from a video series on youtube from a channel called Abap101. Everything was going well until he uses a variable from the zcalc_result type. It seems to run well on the video, but my code displays the error message "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.

I was expecting to run a test activate the code, but I get the given messsage when a I try to activate it.

CodePudding user response:

It appears that zcalc_result is a custom data-type which still needs to be defined. It could be defined as a type within the program using the TYPES keyword, or as a global type in the data dictionary (transaction SE11). The name starting with the letter z hints at the latter, but it could just as well be the former.

When you are following a tutorial, then it is possible that the author already did that but you skipped that part, that the author is going to do that next, or that the author forgot to mention it.

Judging from context, the intended purpose of this type is to hold a currency value. So if you want to declare it yourself, you would do that as a packed number (type P) with a reasonable length and two decimals. For example with this line at the top of the program:

 TYPES: zcalc_result TYPE p LENGTH 10 DECIMALS 2.
  • Related