example on constructor in oops abap

3
Code Snippet for use of Constructor *&---------------------------------------------------------------------* *& Report YTEST_OOP_CONSTRUCTOR_DEMO *& This report will generate the Purchasing documents detils *& It will use OOPs Constructor concept *&---------------------------------------------------------------------* *& By Debesh *& Date : 29/05/2013 *&---------------------------------------------------------------------* REPORT ytest_oop_constructor_demo. PARAMETERS : p_ebeln TYPE ekko-ebeln. *----------------------------------------------------------------------* * CLASS lcl_get_purch_doc DEFINITION *----------------------------------------------------------------------* CLASS lcl_get_purch_doc DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING ebeln TYPE ebeln. PRIVATE SECTION. TYPES : BEGIN OF ty_item, ebeln TYPE ebeln,"Purchasing Document Number ebelp TYPE ebelp,"Item Number of Purchasing Document txz01 TYPE txz01,"Short Text matnr TYPE matnr,"Material Number bukrs TYPE bukrs,"Company Code werks TYPE ewerk,"Plant lgort TYPE lgort_d,"Storage Location menge TYPE bstmg,"Purchase Order Quantity netpr TYPE bprei,"Net Price in Purchasing Document (in Document Currency) netgew TYPE entge,"Net Weight END OF ty_item. ENDCLASS. "lcl_get_purch_doc DEFINITION *----------------------------------------------------------------------* * CLASS lcl_get_purch_doc IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_get_purch_doc IMPLEMENTATION. METHOD constructor . DATA : lt_ekpo TYPE TABLE OF ty_item, By Debesh Page 1

Upload: debesh-swain

Post on 01-Dec-2015

3.759 views

Category:

Documents


2 download

DESCRIPTION

Constructor in OOPS ABAP

TRANSCRIPT

Page 1: Example on Constructor in OOPS ABAP

Code Snippet for use of Constructor

*&---------------------------------------------------------------------**& Report YTEST_OOP_CONSTRUCTOR_DEMO*& This report will generate the Purchasing documents detils*& It will use OOPs Constructor concept*&---------------------------------------------------------------------**& By Debesh*& Date : 29/05/2013*&---------------------------------------------------------------------*

REPORT ytest_oop_constructor_demo.

PARAMETERS : p_ebeln TYPE ekko-ebeln.*----------------------------------------------------------------------** CLASS lcl_get_purch_doc DEFINITION*----------------------------------------------------------------------*CLASS lcl_get_purch_doc DEFINITION.

PUBLIC SECTION. METHODS: constructor IMPORTING ebeln TYPE ebeln. PRIVATE SECTION. TYPES : BEGIN OF ty_item, ebeln TYPE ebeln,"Purchasing Document Number ebelp TYPE ebelp,"Item Number of Purchasing Document txz01 TYPE txz01,"Short Text matnr TYPE matnr,"Material Number bukrs TYPE bukrs,"Company Code werks TYPE ewerk,"Plant lgort TYPE lgort_d,"Storage Location menge TYPE bstmg,"Purchase Order Quantity netpr TYPE bprei,"Net Price in Purchasing Document (in Document Currency) netgew TYPE entge,"Net Weight END OF ty_item.ENDCLASS. "lcl_get_purch_doc DEFINITION

*----------------------------------------------------------------------** CLASS lcl_get_purch_doc IMPLEMENTATION*----------------------------------------------------------------------*CLASS lcl_get_purch_doc IMPLEMENTATION. METHOD constructor . DATA : lt_ekpo TYPE TABLE OF ty_item, ls_ekpo TYPE ty_item. IF p_ebeln IS NOT INITIAL.

SELECT * FROM ekpo INTO CORRESPONDING FIELDS OF TABLE lt_ekpo WHERE ebeln = p_ebeln. IF sy-subrc IS INITIAL.

By Debesh Page 1

Page 2: Example on Constructor in OOPS ABAP

Code Snippet for use of Constructor

WRITE: 'Item Details'. NEW-LINE. ULINE AT 2(140). NEW-LINE. WRITE : 2 'Purch Doc No' , 15 'Item No', 25 'Short Text' , 60 'Company Code' , 75 'Plant' , 85 'Storage Loc', 107 'Quantity' , 120 'Price' , 134 'Weight' . NEW-LINE . ULINE AT 2(140). NEW-LINE. LOOP AT lt_ekpo INTO ls_ekpo. NEW-LINE. WRITE : 2 ls_ekpo-ebeln , 15 ls_ekpo-ebelp, 25 ls_ekpo-txz01, 60 ls_ekpo-bukrs , 75 ls_ekpo-werks, 85 ls_ekpo-lgort, 100 ls_ekpo-menge ,115 ls_ekpo-netpr, 125 ls_ekpo-netgew . ENDLOOP. ELSE. MESSAGE 'No data found' TYPE 'I'. ENDIF. ELSE. MESSAGE 'Please eneter a value' TYPE 'I'. ENDIF. ENDMETHOD. "constructorENDCLASS. "lcl_get_purch_doc IMPLEMENTATION* Global data declarationDATA : lo_obj TYPE REF TO lcl_get_purch_doc.

START-OF-SELECTION. CREATE OBJECT lo_obj EXPORTING ebeln = p_ebeln.

Output :

By Debesh Page 2