0

I was trying run this program copied from a tutorial. But I am getting Null exception I this line

 CALL METHOD list->SET_TABLE_FOR_FIRST_DISPLAY.

form My understanding the list object should be created in the class-constructor.

Method CLASS_CONTRUCTOR.
        CREATE OBJECT list
          EXPORTING
            i_parent = cl_gui_container=>screen0.
      ENDMETHOD.

//code please have a look.

class select_display_sflight DEFINITION.
  public section.
    CLASS-METHODS class_contructor.
    Methods: constructor
    importing i_carrid type sflight-carrid
              i_connid type sflight-connid
     Exceptions nothing_found,
       display_sflight.

  private section.
    CLASS-DATA list type ref to CL_GUI_ALV_GRID.
    data sflight_tab TYPE TABLE OF  sflight.
ENDCLASS.


class select_display_sflight IMPLEMENTATION.
  Method CLASS_CONTRUCTOR.
    CREATE OBJECT list
      EXPORTING
        i_parent = cl_gui_container=>screen0.
  ENDMETHOD.

  Method CONSTRUCTOR.
    select * from sflight
    into table sflight_tab
    where carrid = i_carrid and
    connid = i_connid.
    if sy-subrc = 4 .
      raise NOTHING_FOUND.
    ENDIF.
  ENDMETHOD.

  Method display_sflight.
    CALL METHOD list->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        i_structure_name = 'SFLIGHT'
      CHANGING
        it_outtab        = sflight_tab.
    call screen 100.
  ENDMETHOD.

ENDCLASS.

Selection-SCREEN begin of screen 500.
parameters: p_carrid type sflight-carrid,
p_connid type sflight-connid.
selection-screen end of screen 500.

data: begin of ref_tab_line,
  carrid type sflight-carrid,
  connid type sflight-connid,
  oref type ref to select_display_sflight,
  end of ref_tab_line,
  ref_tab like sorted table of ref_tab_line
  with unique key carrid connid.

START-OF-SELECTION.
  do.
    call SELECTION-SCREEN 500 starting at 10 10.
    if sy-subrc <> 0.
      leave program.
    endif.
    ref_tab_line-carrid = p_carrid.
    ref_tab_line-connid = p_connid.

    read table ref_tab into ref_tab_line
    from ref_tab_line.
    if sy-subrc <> 0.
      CREATE OBJECT ref_tab_line-oref
        EXPORTING
          i_carrid      = p_carrid
          i_connid      = p_connid
        EXCEPTIONS
          nothing_found = 4.
      IF sy-subrc = 4.
        Message i888(sabapdocu) with 'No data'.
        CONTINUE.
      else.
        insert ref_tab_line into table ref_tab.
      ENDIF.
    endif.
    CALL METHOD ref_tab_line-oref->display_sflight.
  ENDDO.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Philip Puthenvila
  • 512
  • 1
  • 8
  • 19

1 Answers1

3

You have committed a typo. You ate the letter S in the CLASS_CONSTRUCTOR name.

It is:

CLASS-METHODS class_contructor.
Method CLASS_CONTRUCTOR.

Should be:

CLASS-METHODS class_constructor.
Method CLASS_CONSTRUCTOR.

Therefore the static constructor is and will never be invoked ergo the list is not getting initialised.

Jagger
  • 10,350
  • 9
  • 51
  • 93
  • Thanks, I thought Object ABAP will catch these type of errors at compile time like Java. – Philip Puthenvila Sep 14 '14 at 23:01
  • Happy to have helped. It would be very hard for the compiler to give a hint, because your situation is not an error at all. You just defined a static method with a name that is not reserved in any way. In Java you have this advantage that static block is clearly defined by `static { }` and constructors are named exactly like the class they are created and they do not return any values therefore if you made a typo by defining a constructor, a Java compiler would complain. – Jagger Sep 15 '14 at 08:02
  • just to clarify, if class_constructor is not reserve word then why class_contructor method is not get executed, I used the same name in the implementation and definition. trying get a better understanding. – Philip Puthenvila Sep 16 '14 at 01:02
  • Where did I write that `class_conStructor` is not a reserved word for a method? I wrote that `class_contructor` is not a reserved word. Method with the typo cannot be executed because the virtual machine is looking for a class method named `class_constructor` and not `class_contructor` or `class_conductor` or `class_room` or whatever. – Jagger Sep 16 '14 at 05:33