Call method from an other program

Like SAP Submit syntax which helps in calling the Perform of other program we can call local methods created in different program.

The Example will explain you who to call local Class method of one program in other prgoram.

PROGRAM 1

REPORT y_test_prog1.
DATA lv_cc TYPE bkpf-bukrs.

CLASS lcl_local_class DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS :
      cc_code IMPORTING lv_cc TYPE bkpf-bukrs.
ENDCLASS.

CLASS lcl_local_class IMPLEMENTATION.
  METHOD cc_code.
    IF lv_cc = ‘1000’.
      WRITE  lv_cc.
    ELSE.
      WRITE : ‘Worked’ , lv_cc.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  lv_cc = ‘1000’.
  CALL METHOD lcl_local_class=>cc_code
    EXPORTING
      lv_cc = lv_cc.

PROGRAM 2

REPORT y_test_prog2.

PARAMETER  lv_cc TYPE bkpf-bukrs.

DATA : go_test         TYPE REF TO object,
       ge_abs_typename TYPE string
          VALUE ‘\PROGRAM=Y_TEST_PROG1\CLASS=LCL_LOCAL_CLASS’.

START-OF-SELECTION.
  CREATE OBJECT go_test TYPE (ge_abs_typename).
BREAK-POINT.
  CALL METHOD go_test->(‘CC_CODE’)
    EXPORTING
      lv_cc = lv_cc.

Leave a Reply

Your email address will not be published. Required fields are marked *