Constructor Program in ABAP

TYPE-POOLS truxs.
PARAMETERS p_file TYPE rlgrap-filename.
TYPES : BEGIN OF t_tab,
          workstream TYPE char50,
          task       TYPE zci_task,
          task_type  TYPE char50,
        END OF t_tab.
DATA : t_upload1  TYPE STANDARD TABLE OF ZDEMO_TEST2,
       wa_upload1 TYPE ZDEMO_TEST2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

START-OF-SELECTION.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = it_type
      i_filename           = p_file
    TABLES
      i_tab_converted_data = t_upload[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 .
  ENDIF.

CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
  EXPORTING
    i_filename       = p_file
  tables
    e_itab           = t_upload1
 EXCEPTIONS
   FILE_ERROR       = 1
   OTHERS           = 2
          .
IF sy-subrc <> 0.
 Implement suitable error handling here
ENDIF.


END-OF-SELECTION.
  DATA : ls_cc_impl TYPE ZDEMO_TEST2,
         lt_cc_impl TYPE STANDARD TABLE OF  ZDEMO_TEST2.
  LOOP AT t_upload1 INTO wa_upload1.
    ls_cc_impl-mandt = sy-mandt.
    ls_cc_impl-INCIDENT                  = wa_upload1-INCIDENT.
    APPEND ls_cc_impl TO lt_cc_impl.
  ENDLOOP.
  MODIFY ZDEMO_TEST2 FROM TABLE lt_cc_impl.

CLASS cl_grand DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA v_test TYPE char40.
    CLASS-METHODS class_constructor.
    METHODS constructor.
    DATA a type i.
    CLASS-DATA b TYPE i.
ENDCLASS.                    "cl_grand DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_grand IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_grand IMPLEMENTATION.
  METHOD class_constructor.
    v_test = 'Static Constructor - Grand Parent'.
    b = 30.
    WRITE: /3 v_test.
  ENDMETHOD.                    "class_constructor
  METHOD constructor.
    a = 30.
    v_test = 'Instance Constructor - Grand Parent'.
    WRITE: /3 v_test.
  ENDMETHOD.
ENDCLASS.                    "cl_grand IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS cl_parent DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_parent DEFINITION INHERITING FROM cl_grand.
  PUBLIC SECTION.
    CLASS-METHODS class_constructor.
    METHODS constructor.

ENDCLASS.                    "cl_parent DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_parent IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_parent IMPLEMENTATION.
  METHOD class_constructor.
    v_test = 'Static Constructor - Parent'.
    b = 20.
    WRITE: /3 v_test.
  ENDMETHOD.                    "class_constructor
  METHOD constructor .
*    data a type i.

    super->constructor( ).
    a = 20.
    v_test = 'Instance Constructor -Parent'.
    WRITE: /3 v_test.
  ENDMETHOD.
ENDCLASS.                    "cl_parent IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS cl_child DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_child DEFINITION INHERITING FROM cl_parent.
  PUBLIC SECTION.
    CLASS-METHODS class_constructor.
    METHODS constructor.
*    DATA a.
ENDCLASS.                    "cl_child DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_child IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_child IMPLEMENTATION.
  METHOD class_constructor.
    v_test = 'Static Constructor - Child'.
    WRITE: /3 v_test.
    b = 10.
  ENDMETHOD.                    "class_constructor
  METHOD constructor.
    data a type i.
a = 10.
    super->constructor( ).

    v_test = 'Instance Constructor - Child'.
    WRITE: /3 v_test.
  ENDMETHOD.
ENDCLASS.                    "cl_child IMPLEMENTATION
START-OF-SELECTION.
DATA obj_child TYPE REF TO cl_child.
CREATE OBJECT obj_child.
data: a type i,
      b type i.
a = obj_child->a.
write a.

write sy-uname.
delete from ztms_score .
delete from ztms_ans .
TYPES: BEGIN OF TY_DATA, "user defined type
       ID TYPE N ,
       NAME TYPE CHAR20,
       SALARY TYPE I,
      END OF TY_DATA.
DATA : ITAB TYPE TABLE OF TY_DATA. "internal table
DATA : WA TYPE TY_DATA. "work area

WA-ID = 1.
WA-NAME = 'Sapnuts'.
WA-SALARY = 5000.
COLLECT WA INTO ITAB. "collect
CLEAR WA.

WA-ID = 2.
WA-NAME = 'SAPabap'.
WA-SALARY = 50000.
COLLECT WA INTO ITAB. "collect
CLEAR WA.

WA-ID = 1.
WA-NAME = 'Sapnuts'.
WA-SALARY = 15000.
COLLECT WA INTO ITAB. "collect
CLEAR WA.

LOOP AT ITAB INTO WA.
  WRITE:/ WA-ID, WA-NAME, WA-SALARY. "loop and display data
ENDLOOP.
**delete from ztms_score .
**delete from ztms_ans .
delete from ztms_user .
delete from ztms_set .
delete from ztms_ques .

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.