OOPS IN ABAP

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

SRINUM

OOPS IN ABAP

Post by SRINUM » Sun Nov 27, 2005 10:46 pm

HI FRIENDS I HAVE CODED A SIMPLE OO ABAP MODULE POOL BUT IT IS GIVING ME A RUNTIME ERROR. CODE IS AS BELOW

*&---------------------------------------------------------------------*
*& Module pool ZMYOOPSPROG2 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

PROGRAM ZMYOOPSPROG2 .
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
TABLES: KNA1.
CLASS CL_LOCAL DEFINITION.
PUBLIC SECTION.
METHODS:SELECT_DATA IMPORTING
VALUE(CUST) TYPE ZMYLTYPE1-KUNNR,
DISPLAY_DATA.
PRIVATE SECTION.
DATA: WA TYPE ZMYLTYPE1,
ITAB TYPE ZMYRTYPE1.
ENDCLASS.
CLASS CL_LOCAL IMPLEMENTATION.
METHOD SELECT_DATA.
SELECT KUNNR LAND1 NAME1 FROM KNA1 INTO TABLE ITAB WHERE KUNNR = CUST.
ENDMETHOD.
METHOD DISPLAY_DATA.
LOOP AT ITAB INTO WA.
MOVE-CORRESPONDING WA TO KNA1.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
DATA: OBJ_CL_LOCAL TYPE REF TO CL_LOCAL.
START-OF-SELECTION.
CREATE OBJECT OBJ_CL_LOCAL.
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'DISPLAY'.
CALL METHOD OBJ_CL_LOCAL->SELECT_DATA
EXPORTING
CUST = KNA1-KUNNR.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
*CALL METHOD OBJ_CL_LOCAL->DISPLAY_DATA.
ENDMODULE. " STATUS_0100 OUTPUT


IAM UNABLE TO KNOW WHAT THE ERROR IS

PLZ HELP ME IN THIS REGARDS.

THANKING YOU IN ADVANCE.

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Sun Nov 27, 2005 11:33 pm

Ouch .... my ears.
srinum wrote:IAM UNABLE TO KNOW WHAT THE ERROR IS
Neither do we unless you tell us.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

srinum

Post by srinum » Mon Nov 28, 2005 1:52 am

mr rich(poor)
that is really a pathetic joke....
my all sympathies are with u...
i wanted the errr in the code ... if u try it out then i suppose u will get the error too..do look into it...

its a runtime error ... thats what i can say....

ilya
Posts: 2327
Joined: Thu Oct 31, 2002 4:49 am
Contact:

Post by ilya » Mon Nov 28, 2005 3:09 am

srinum wrote:my all sympathies are with u...
May I ask who is that 'u'? A girlfriend? (Sounds like a Chinese name...)
ilya

More input data: http://abaplog.wordpress.com
Sapfans ABAP FAQ: viewtopic.php?t=94198
Rich's ABAP Knowledge Corner: http://www.richard-harper.me.uk/Kb/default.html
Function modules documentation: http://www.se37.com

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Mon Nov 28, 2005 3:29 am

srinum wrote:mr rich(poor)
that is really a pathetic joke....
my all sympathies are with u...
i wanted the errr in the code ... if u try it out then i suppose u will get the error too..do look into it...

its a runtime error ... thats what i can say....
Srinum,

You know what the run time error is. By including at least the top portion of the short dump, then someone such as myself may be able to answer your question straight away.

We all are working on systems that have a variety of restrictions on them. I for one have to account for all my time, and having to create a temporary program on this project also has to be accounted for so there is no way that I can (nor will) cut and paste someones code onto a system without spending even more time analysing what the code does. In anycase, why should we spend time recreating something that you have just encountered ?

So if you will not help us to help you in the first place, how can you expect an answer?
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

VLozano
Posts: 5142
Joined: Mon Sep 13, 2004 8:17 am
Location: Idiocity
Contact:

Post by VLozano » Mon Nov 28, 2005 3:35 am

Mr (or Ms) Srinum, I was thinking in a proper way to give my support to Rich, saying something like "joke was less pathetic than question" or so... then I noticed you posted the subject in caps... the proper subject had to be

"Error in Object Oriented Programming in ABAP" or, being lazy "OOPS in ABAP" (notice I wrote "in" without caps)... I'm not sure about it, but I believe OOPS was a kind of joke... more or less pathetical than Rich's? (by the way, Rich's one was not a joke, just a bit of sarcasm because we are tired about posts like yours).

I CLAIM FOR A LOCK!
Tuly Idiots
Because we know we are part of the problem

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Mon Nov 28, 2005 4:09 am

VLozano wrote:Mr (or Ms) Srinum, I was thinking in a proper way to give my support to Rich, saying something like "joke was less pathetic than question" or so... then I noticed you posted the subject in caps... the proper subject had to be

"Error in Object Oriented Programming in ABAP" or, being lazy "OOPS in ABAP" (notice I wrote "in" without caps)... I'm not sure about it, but I believe OOPS was a kind of joke... more or less pathetical than Rich's? (by the way, Rich's one was not a joke, just a bit of sarcasm because we are tired about posts like yours).

I CLAIM FOR A LOCK!
<Heavy sigh>

What gets me is that very often the cause of these run time errors is actually spelt out in the short dump. Ok, they can look a bit daunting especially when you print them out but generally the answer is right there on the first page, staring you in the face. All you need to do is to read what it says.

And even then, if you've already left the short dump, ST22 will display it again for you so you can easily get the information.

So, lets try again. Srinum, if you want help, help yourself first. At least rather than dumping just a badly formatted program on us and expecting us to do what you have already done, give us something to work with. Like the actual error message itself.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

srinum

Post by srinum » Mon Nov 28, 2005 4:39 am

ok friends ..
sorry for my quotes....
here is the error iam getting

"access is not possible using 'NULL' object reference


the same program i tried in reports and it worked fine.


any clue of the error now

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Mon Nov 28, 2005 5:00 am

Ok,

Now, further down the short dump there should be a code extract.

Post that.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

srinum

Post by srinum » Mon Nov 28, 2005 5:14 am

i have kept the error ocation in bold letters

TABLES: KNA1.
CLASS CL_LOCAL DEFINITION.
PUBLIC SECTION.
METHODS:SELECT_DATA IMPORTING
VALUE(CUST) TYPE ZMYLTYPE1-KUNNR,
DISPLAY_DATA.
PRIVATE SECTION.
DATA: WA TYPE ZMYLTYPE1,
ITAB TYPE ZMYRTYPE1.
ENDCLASS.
CLASS CL_LOCAL IMPLEMENTATION.
METHOD SELECT_DATA.
SELECT KUNNR LAND1 NAME1 FROM KNA1 INTO TABLE ITAB WHERE KUNNR = CUST.
ENDMETHOD.
METHOD DISPLAY_DATA.
LOOP AT ITAB INTO WA.
MOVE-CORRESPONDING WA TO KNA1.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
DATA: OBJ_CL_LOCAL TYPE REF TO CL_LOCAL.
START-OF-SELECTION.
CREATE OBJECT OBJ_CL_LOCAL.
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'DISPLAY'.
CALL METHOD OBJ_CL_LOCAL->SELECT_DATA
EXPORTING
CUST = KNA1-KUNNR.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
CALL METHOD OBJ_CL_LOCAL->DISPLAY_DATA.
ENDMODULE. " STATUS_0100 OUTPUT

srinum

TABLES: KNA1. CLASS CL_LOCAL DEFINITION. PUBLIC SECTION.

Post by srinum » Mon Nov 28, 2005 5:15 am

MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
----->CALL METHOD OBJ_CL_LOCAL->DISPLAY_DATA.
ENDMODULE. " STATUS_0100 OUTPUT



error at this point marked by an arrow call method

m@t
Posts: 4119
Joined: Thu Sep 04, 2003 7:37 am
Location: Switzerland

Post by m@t » Mon Nov 28, 2005 5:23 am

Use the "Code" button!

Code: Select all

PROGRAM ZMYOOPSPROG2 .
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
TABLES: KNA1.
CLASS CL_LOCAL DEFINITION.
  PUBLIC SECTION.
    METHODS:SELECT_DATA IMPORTING
      VALUE(CUST) TYPE ZMYLTYPE1-KUNNR,
      DISPLAY_DATA.
  PRIVATE SECTION.
  DATA: WA TYPE ZMYLTYPE1,
            ITAB TYPE ZMYRTYPE1.
ENDCLASS.

CLASS CL_LOCAL IMPLEMENTATION.
  METHOD SELECT_DATA.
    SELECT KUNNR LAND1 NAME1 FROM KNA1 INTO TABLE ITAB WHERE   KUNNR = CUST.
  ENDMETHOD.
  METHOD DISPLAY_DATA.
    LOOP AT ITAB INTO WA.
       MOVE-CORRESPONDING WA TO KNA1.
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.

DATA: OBJ_CL_LOCAL TYPE REF TO CL_LOCAL.

START-OF-SELECTION.
  CREATE OBJECT OBJ_CL_LOCAL.

MODULE USER_COMMAND_0100 INPUT.
  CASE SY-UCOMM.
    WHEN 'DISPLAY'.
       CALL METHOD OBJ_CL_LOCAL->SELECT_DATA
          EXPORTING
             CUST = KNA1-KUNNR.
    WHEN 'EXIT'.
        LEAVE PROGRAM.
    ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text 
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
*CALL METHOD OBJ_CL_LOCAL->DISPLAY_DATA.
ENDMODULE. " STATUS_0100 OUTPUT 
That's better.

m@t
TULY Image The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

m@t
Posts: 4119
Joined: Thu Sep 04, 2003 7:37 am
Location: Switzerland

Post by m@t » Mon Nov 28, 2005 5:29 am

That error message probably means that for whatever reason, OBJ_CL_LOCAL is dereferenced.

Try single stepping in the debugger.

m@t
TULY Image The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

srinum

Post by srinum » Mon Nov 28, 2005 5:31 am

i didnt get u

wizbongre
Posts: 255
Joined: Thu Dec 19, 2002 8:19 am

Post by wizbongre » Mon Nov 28, 2005 5:31 am

srinum wrote:ok friends ..
sorry for my quotes....
here is the error iam getting

"access is not possible using 'NULL' object reference


the same program i tried in reports and it worked fine.


any clue of the error now
and
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
----->CALL METHOD OBJ_CL_LOCAL->DISPLAY_DATA.
ENDMODULE. " STATUS_0100 OUTPUT
Probably means you don't have an instance of the object OBJ_CL_LOCAL - maybe the create is failing?

The short dump is pretty clear, as has been suggested just single step through and figure it out. This really isn't rocket-science.

Locked