Skip to Content
0
Former Member
Dec 03, 2007 at 03:11 PM

Is possible convert a form to a method?

421 Views

Can I convert this form to a method?

The original perform is:

************************************************

DATA: num1 TYPE i,

num2 TYPE i,

sum TYPE i.

num1 = 2. num2 = 4.

PERFORM addit USING num1 num2 CHANGING sum.

num1 = 7. num2 = 11.

PERFORM addit USING num1 num2 CHANGING sum.

FORM addit

USING add_num1 TYPE any

add_num2 TYPE any

CHANGING add_sum TYPE any.

add_sum = add_num1 + add_num2.

PERFORM out USING add_num1 add_num2 add_sum.

ENDFORM.

FORM out

USING out_num1 TYPE any

out_num2 TYPE any

out_sum TYPE any.

WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum.

ENDFORM.

*************************************************

I convert the last code in oriented object:

*************************************************

REPORT zcu04_pruebaperform.

CLASS one DEFINITION.

PUBLIC SECTION.

METHODS: addit

IMPORTING

add_num1 TYPE any

add_num2 TYPE any

EXPORTING

add_sum TYPE any.

CLASS one IMPLEMENTATION.

method addit.

add_sum = add_num1 + add_num2.

ENDMETHOD.

ENDCLASS.

class two definition inheriting from one.

PUBLIC SECTION.

METHODS: out IMPORTING

out_num1 TYPE any

out_num2 TYPE any

out_sum TYPE any.

ENDCLASS.

CLASS two IMPLEMENTATION.

method out.

WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA o_one TYPE REF TO one.

DATA o_two TYPE REF TO two.

CREATE OBJECT: o_one, o_two.

DATA: num1 TYPE i,

num2 TYPE i,

sum TYPE i.

num1 = 2. num2 = 4.

*when is called is used EXPORTING

CALL METHOD o_one->addit

EXPORTING

add_num1 = num1

add_num2 = num2

IMPORTING

add_sum = sum.

*PERFORM addit USING num1 num2 CHANGING sum.

CALL METHOD o_two->out

EXPORTING

out_num1 = num1

out_num2 = num2

out_sum = sum.

num1 = 7. num2 = 11.

CALL METHOD o_one->addit

EXPORTING

add_num1 = num1

add_num2 = num2

IMPORTING

add_sum = sum.

*PERFORM addit USING num1 num2 CHANGING sum.

CALL METHOD o_two->out

EXPORTING

out_num1 = num1

out_num2 = num2

out_sum = sum.

************************************************

But, How can I to call method in the class equal that the FORM, PERFORM to other FORM?

**FORM addit

  • USING add_num1 TYPE any

  • add_num2 TYPE any

  • CHANGING add_sum TYPE any.

**

  • add_sum = add_num1 + add_num2.

  • PERFORM out USING add_num1 add_num2 add_sum.

**

**ENDFORM.

...

...

CLASS one IMPLEMENTATION.

method addit.

add_sum = add_num1 + add_num2.

CALL METHOD o_two->out

EXPORTING

out_num1 = num1

out_num2 = num2

out_sum = sum.

ENDMETHOD.

ENDCLASS.

...

...

Error:

Field "O_TWO->OUT" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement.

Can you help me, please?