SAP 定义类
report z_test2. *----------------------------------------------------------------------* * CLASS adding DEFINITION 定义一个类 *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class adding definition. public section. class-data num type i. events:return. "定义事件 methods:accumulate. endclass. "adding DEFINITION *----------------------------------------------------------------------* * CLASS adding IMPLEMENTATION 实现一个类 *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class adding implementation. method:accumulate. data:res type i. num = num + 1. res = num mod 10. if res = 0. raise event return. "类中调用事件 endif. endmethod. "accumulate endclass. "adding IMPLEMENTATION *----------------------------------------------------------------------* * CLASS handler DEFINITION *----------------------------------------------------------------------* * 处理类的定义 用来处理事件 *----------------------------------------------------------------------* class handler definition. public section. methods handle_excute for event return of adding . endclass. "handler DEFINITION *----------------------------------------------------------------------* * CLASS handler IMPLEMENTATION *----------------------------------------------------------------------* * 处理类的实现 *----------------------------------------------------------------------* class handler implementation. method handle_excute. write:'the present number is:',adding=>num. endmethod. "handle_excute endclass. "handler IMPLEMENTATION data: o_adding type ref to adding. "定义adding 对象 data: o_handler type ref to handler. "定义 handler 对象 start-of-selection. create object: o_adding, o_handler. set handler o_handler->handle_excute for o_adding. "将定义的事件处理方法运用到adding 对象中 do 50 times. call method o_adding->accumulate. " 达到条件时就会自动处理 enddo. ===================================================
    最爱江南烟雨如画:浩浩宇宙,朗朗乾坤,花花世界,滚滚红尘
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号