Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting dump while using container, can anybody help me to under stand the problem?

utsavar
Explorer

REPORT ZTEST103.
TABLES EKKO.

* table declaration
TYPES: BEGIN OF TY_EKKO,
         EBELN TYPE EBELN,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         SPRAS TYPE SPRAS,
       END OF TY_EKKO.

*internal table declaration
DATA : LT_EKKO TYPE TABLE OF TY_EKKO,
       LS_EKKO TYPE TY_EKKO.

*cl_salv declaration
DATA : ALV TYPE REF TO CL_SALV_TABLE,
       MESSAGE TYPE REF TO CX_SALV_MSG.

*container declartion
DATA : G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, 
       G_TOP_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
       G_BOTTOM_CONTAINER TYPE REF TO CL_GUI_CONTAINER.

*set pf-status declaration
DATA LO_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST.

*selection declaration
DATA LR_SELECTIONS TYPE REF TO CL_SALV_SELECTIONS.

DATA LR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.

DATA : LT_ROWS TYPE SALV_T_ROW,
       LS_ROWS TYPE INT4.

PERFORM FETCH_DATA.
PERFORM INITIALIZE USING 'G_TOP_CONTAINER' LT_EKKO.
PERFORM SELECTION.
PERFORM DISPLAY_ALV.
PERFORM DISPLAY_SELECTION.

*CALL SCREEN 100. 

FORM FETCH_DATA.
  SELECT EBELN AEDAT LIFNR SPRAS
     FROM EKKO
     INTO TABLE LT_EKKO
     UP TO 10 ROWS.
ENDFORM. "FETCH_DATA

FORM INITIALIZE USING CON_NAME T_TAB.
  CREATE OBJECT G_CUSTOM_CONTAINER
    EXPORTING
      CONTAINER_NAME = CON_NAME.

  TRY.
    CL_SALV_TABLE=>FACTORY(
      EXPORTING
        R_CONTAINER = G_CUSTOM_CONTAINER "<---------------
        LIST_DISPLAY = 'X'
      IMPORTING
        R_SALV_TABLE = ALV
      CHANGING
        T_TABLE = T_TAB ).
    LO_FUNCTIONS = ALV->GET_FUNCTIONS( ).
    LO_FUNCTIONS->SET_ALL( ABAP_TRUE ).
  CATCH CX_SALV_MSG INTO MESSAGE.
      " error handling
  ENDTRY.
ENDFORM. " INITIALIZE

FORM SELECTION.
  "Column Selection
  LR_SELECTIONS = ALV->GET_SELECTIONS( ). "<---------------------------
  LR_SELECTIONS->SET_SELECTION_MODE( IF_SALV_C_SELECTION_MODE=>ROW_COLUMN ).

  LR_COLUMNS = ALV->GET_COLUMNS( ).
  LR_COLUMNS->SET_OPTIMIZE( ABAP_TRUE ).
ENDFORM. "SELECTION

FORM DISPLAY_ALV.
  CALL METHOD ALV->DISPLAY.
ENDFORM. " DISPLAY_ALV

FORM DISPLAY_SELECTION.
  LT_ROWS = LR_SELECTIONS->GET_SELECTED_ROWS( ).
* Display the selected rows.

  LOOP AT LT_ROWS INTO LS_ROWS.
    READ TABLE LT_EKKO INTO LS_EKKO INDEX LS_ROWS.
    WRITE: / LS_EKKO-EBELN,
             LS_EKKO-AEDAT,
             LS_EKKO-LIFNR,
             LS_EKKO-SPRAS.
   ENDLOOP.
ENDFORM. "DISPLAY_SELECTION

Here is what I am trying to do.

1. Retrieve the rows selected by user.

2. Have multiple alv in same screen.

3. Problem : Individually it is working but when I combine I get run time error.

4. I have temporarily deleted second alv. I plan to add it after above 2 things work together.(Also I am new in development)

Dump:

An exception occurred that is explained in detail below. The exception, which is assigned to class 'CX_SY_REF_IS_INITIAL', was not caught in procedure "SELECTION" "(FORM)", nor was it propagated by a RAISING clause. Since the caller of the procedure could not have anticipated that the exception would occur, the current program is terminated. The reason for the exception is: You attempted to use a 'NULL' object reference (points to 'nothing') access a component (variable: "ALV"). An object reference must point to an object (an instance of a class) before it can be used to access components. Either the reference was never set or it was set to 'NULL' using the CLEAR statement.

1 ACCEPTED SOLUTION

SimoneMilesi
Active Contributor

Well, the error is that you are not creating the ALV object.

You refer to a container that, in the logic flow, doesn't exist because, i guess, it's in screen 100.

You should move the forms

PERFORM INITIALIZE USING 'G_TOP_CONTAINER' LT_EKKO. 

PERFORM SELECTION.

 PERFORM DISPLAY_ALV. 

PERFORM DISPLAY_SELECTION.

in the PBO of your screen and invoke it (you commented it).
The question is: why to use a custom container with SALV? SALV borns to avoid such stuff and make quick and easy ALV grid.
Plus,you should follow matthew.billingham's suggestions.

6 REPLIES 6

matt
Active Contributor
0 Kudos

In future please put your code into a code block, using the handily titled "code" button in the editor. It makes your code easier to read. I've done it for you this time.

Also note the following issues with your code.

1. TABLES statement is obsolete

2. FORM/PERFORM statemens are obsolete

3. You have declared global variables but used L in their prefix. L denotes local. While you only use them in your forms, they are nonetheless available globally. Local variables should be defined inside the modular unit. (In this case, the obsolete FORM). If you follow DSAG or SAP guidelines you won't use typing prefixes anyway.

This comment is not intended to solve your issue, but to improve your programming.

SimoneMilesi
Active Contributor

Well, the error is that you are not creating the ALV object.

You refer to a container that, in the logic flow, doesn't exist because, i guess, it's in screen 100.

You should move the forms

PERFORM INITIALIZE USING 'G_TOP_CONTAINER' LT_EKKO. 

PERFORM SELECTION.

 PERFORM DISPLAY_ALV. 

PERFORM DISPLAY_SELECTION.

in the PBO of your screen and invoke it (you commented it).
The question is: why to use a custom container with SALV? SALV borns to avoid such stuff and make quick and easy ALV grid.
Plus,you should follow matthew.billingham's suggestions.

0 Kudos

I am getting the same error even if I use screen 100.

I started SALV to get the output easily. I am still in learning phase, so I try to combine things that I have learned recently.

My apologies for late reply.

I have explained in detail below what I wanted to achieve and the program above is not finished.

  • User selects some data from SALV. (done)
  • We fetch the selected row and display it on different screen.(done)
  • Now I wanted to display the data that user selects on same screen only.(problem).
  • After that I wanted to use 'hotspot' on EBELN in second alv that I get. (I learned to use HOTSPOT recently).

I know this is not the kind of requirements customers generally heve, It's just my way to learn things.

Thank you very much for your time. I really appreciate it.

Hi Utsav,

if you are using this report to learn stuff, i suggest you to follow Zevolving's tutorial: it's my reference any time i have a doubt on SALV 🙂

In my opinion, SALV is not the right tool to handle "complex" logic: it's more an easy wrapper for quick-and-dirty reports.

This doesn't mean you cannot achieve what you are trying to do with it: i just believe in the right tool for the right job way to do stuff.

First you should follow Matthew's suggestion to move to OOP because to do what you want to do you need to rely on SALV events and with OOP it's everything easier and more clear.You cannot invoke the form after the DISPLAY_ALV, you need SAP to tell you the user selected something.
In this old thread there is an example on how to implement all.

0 Kudos

Thanks for the inputs. I will follow your suggestions.

utsavar
Explorer
0 Kudos

Thank you for pointing me to the right direction. I will definitely work on your suggestions.