Tuesday, 1 January 2013

OOPS: Constructor Demo


*&---------------------------------------------------------------------*
*&  Report    ZOOPS11
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report    ZOOPS11.


tables:SPFLI.
parameters:    P_CARRID type SPFLI-CARRID.
data:          WA type SPFLI.

*----------------------------------------------------------------------*
*              CLASS  LCL_CONSTDEMO  DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class LCL_CONSTDEMO definition.
    public  section.
        methods:      CONSTRUCTOR 

            importing M_CARRID type SPFLI-CARRID default 'AA' 
            exceptions  NO_DATA  ,
                      DISPLAY.
endclass.                                        "LCL_CONSTDEMO  DEFINITION

*----------------------------------------------------------------------*
*              CLASS  LCL_CONSTDEMO  IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class  LCL_CONSTDEMO  implementation.
    method  CONSTRUCTOR.
        select * from  SPFLI into WA where CARRID = M_CARRID.
            if  SY-SUBRC  ne  0.
                raise  NO_DATA.
            else.
                write:/  WA-CARRID,WA-CONNID,WA-CITYFROM,WA-CITYTO.
            endif.
        endselect.
    endmethod.                                   "CONSTRUCTOR
    method  DISPLAY.
        write:/  'THIS  IS  IN  METHOD'.
    endmethod.                                   "CONSTRUCTOR
endclass.                                        "LCL_CONSTDEMO  IMPLEMENTATION

"LCL_CONSTDEMO  IMPLEMENTATION

start-of-selection.
    data:  OBJ type ref to LCL_CONSTDEMO.
    create  object  OBJ
        exporting
            M_CARRID  =  P_CARRID
        exceptions
            NO_DATA    =  1.
    call  method  OBJ->DISPLAY.

No comments:

Post a Comment