Skip to Content
0
Former Member
Jul 29, 2014 at 06:29 AM

Instantiation in INITIALIZATION or START-OF-SELECTION?

538 Views

Generally In oops we create object in start-of-selection event, but in this program I created in initialization event.

In this program after specifying class definition I am defining the object and I am creating the object in the initialization event. For suppose I am keeping that create object statement in comment state. Program has to throw the error but it is not throwing any error why? May I know the purpose?

When we create the object in initialization event and when we create in start-of-selection event (is there any specific reason)

In start of selection event I am calling the methods.

You can see in the below program



*----------------------------------------------------------------------*

TABLES:ekko.

*----------------------------------------------------------------------*

* selection screen for block b1

*----------------------------------------------------------------------*

SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS:s_ebeln FOR ekko-ebeln. " Purchasing doc number

SELECTION-SCREEN:END OF BLOCK b1.

*----------------------------------------------------------------------*

* class cl_purchase_order definition

*----------------------------------------------------------------------*

CLASS lcl_purchase_order DEFINITION.

PUBLIC SECTION.

METHODS:

fetch_data,

display_data.

*--------------------------------------------------------------------*

* structure declarations

*--------------------------------------------------------------------*

* structure for ekko.

TYPES:

BEGIN OF t_ekko,

ebeln TYPE ebeln, " Purchasing document number

END OF t_ekko.

*structure for ekpo.

TYPES:

BEGIN OF t_ekpo,

ebeln TYPE ebeln, " Purchasing document number

ebelp TYPE ebelp, " Item number for purchasing doc.

END OF t_ekpo.

*structure for eket.

TYPES:

BEGIN OF t_eket,

ebeln TYPE ebeln, " Purchasing document number

ebelp TYPE ebelp, " Item number for purchasing doc

etenr TYPE eeten, " Delievary schedule line counter

menge TYPE menge_d, " Scheduled quantity

wemng TYPE wemng, " Quantity of goods received

END OF t_eket.

*----------------------------------------------------------------------*

* internal table declaration for ekko,ekpo and eket structure

*----------------------------------------------------------------------*

DATA:i_ekko TYPE TABLE OF t_ekko,

i_ekpo TYPE TABLE OF t_ekpo,

i_eket TYPE TABLE OF t_eket.

*----------------------------------------------------------------------*

*work area declaration for ekko,ekpo and eket structure

*----------------------------------------------------------------------*

DATA:i_ekko_line LIKE LINE OF i_ekko,

i_ekpo_line LIKE LINE OF i_ekpo,

i_eket_line LIKE LINE OF i_eket.

ENDCLASS. " LCL_PURCHASE_ORDER DEFINITION



DATA : obj TYPE REF TO lcl_purchase_order.

INITIALIZATION.

*CREATE OBJECT obj. " i put this statement in comment

*----------------------------------------------------------------------*

* class cl_purchase_order implementation

*----------------------------------------------------------------------*

CLASS lcl_purchase_order IMPLEMENTATION.

METHOD fetch_data.

SELECT ebeln

FROM ekko

INTO TABLE i_ekko

WHERE ebeln IN s_ebeln.

IF sy-subrc EQ 0.

IF i_ekko IS NOT INITIAL.

SELECT ebeln

ebelp

FROM ekpo

INTO TABLE i_ekpo

FOR ALL ENTRIES IN i_ekko

WHERE ebeln = i_ekko-ebeln.

IF sy-subrc EQ 0.

IF i_ekpo IS NOT INITIAL.

SELECT ebeln

ebelp

etenr

menge

wemng

FROM eket

INTO TABLE i_eket

FOR ALL ENTRIES IN i_ekpo

WHERE ebeln = i_ekpo-ebeln

AND ebelp = i_ekpo-ebelp.

ELSE.

ENDIF. " If i_ekpo......

ELSE.

write:/10 text-008.

ENDIF. " If sy-subrc......

ENDIF. " If i_ekko......

ENDIF. " If sy-subrc....

ENDMETHOD. " END FETCH_DATA.

METHOD display_data.

SORT i_eket BY ebeln.

LOOP AT i_eket INTO i_eket_line.

AT FIRST.

WRITE:/40 text-003 COLOR 1.

ULINE.

WRITE:/10 text-004 COLOR 3.

WRITE:/30 text-005 COLOR 4,

50 text-006 COLOR 4,

75 text-007 COLOR 4.

ENDAT. " At first.......

IF i_eket_line-menge > i_eket_line-wemng.

AT NEW ebeln.

ULINE.

WRITE:/10 i_eket_line-ebeln COLOR 3 .

ENDAT. " At new.......

WRITE:/30 i_eket_line-ebelp COLOR 4,

50 i_eket_line-menge UNIT ' ' COLOR 4,

75 i_eket_line-wemng UNIT ' ' COLOR 4.

ENDIF.

ENDLOOP.

ENDMETHOD. " DISPLAY_DATA

ENDCLASS. " CL_PURCHASE_ORDER IMPLEMENTATION

*----------------------------------------------------------------------*

* object creation for class cl_purchase_order

*----------------------------------------------------------------------*

*start-of-selection event.

START-OF-SELECTION.

* CREATE OBJECT obj.

CALL METHOD:obj->fetch_data,

obj->display_data.


Thanks in Advance.

Regards,

Avinash.


Moderator message: Please use proper subject lines in the future

Message was edited by: Suhas Saha