Application Development and Automation 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: 
Read only

calling this OO code

Former Member
0 Likes
994

Dear experts,

I want three record of vendors to be retrieved by this method.I am doing something like following

code doesnot compile after third last DATA statement.Plz help.



types: begin of ty_lfa1,
       lifnr type lfa1-lifnr,
       name1 type lfa1-name1,
       name2 type lfa1-name2,
       end of ty_lfa1.

data: t_lfa1 type standard table of ty_lfa1.

class fetchsap definition.
public section.
Methods:
picksalesbudget exporting tp_lfa1 like t_lfa1.
endclass.

class fetchsap implementation.

method picksalesbudget.
select lifnr name1 name2 from lfa1 up to 3 rows into table tp_lfa1.
endmethod.

endclass.

*DATA: obc TYPE REF TO fetchsap.*

create object obc.

call method obc->picksalesbudget ().

Edited by: aditya sharma on Jun 29, 2010 12:19 PM

Edited by: aditya sharma on Jun 29, 2010 12:20 PM

9 REPLIES 9
Read only

Former Member
0 Likes
947

Use this code .. it will work fine ..

types: begin of ty_lfa1,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

name2 type lfa1-name2,

end of ty_lfa1.

data: t_lfa1 type standard table of ty_lfa1.

class fetchsap definition.

public section.

Methods:

picksalesbudget exporting tp_lfa1 like t_lfa1.

endclass.

class fetchsap implementation.

method picksalesbudget.

select lifnr name1 name2 from lfa1 up to 3 rows into table tp_lfa1.

endmethod.

endclass.

start-of-selection.

DATA: obc TYPE REF TO fetchsap.

create object obc.

call method obc->picksalesbudget.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
947

Change to this :

START-OF-SELECTION. "Add the START-OF-SELECTION event name

  DATA: obc TYPE REF TO fetchsap.
  CREATE OBJECT obc.

  CALL METHOD obc->picksalesbudget( IMPORTING tp_lfa1 = t_lfa1 ). "Add the IMPORTING addition

  CHECK t_lfa1 IS NOT INITIAL.

BR,

Suhas

Read only

Former Member
0 Likes
947

types: begin of ty_lfa1,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

name2 type lfa1-name2,

end of ty_lfa1.

data: t_lfa1 type standard table of ty_lfa1.

data: wa_lfa1 like line of t_lfa1.

class fetchsap definition.

public section.

Methods:

picksalesbudget exporting tp_lfa1 like t_lfa1.

endclass.

class fetchsap implementation.

method picksalesbudget.

select lifnr name1 name2 from lfa1 up to 3 rows into table tp_lfa1.

endmethod.

endclass.

DATA: obc TYPE REF TO fetchsap.

START-OF-SELECTION.

CALL METHOD obc->picksalesbudget( IMPORTING tp_lfa1 = t_lfa1 ).

.

loop at t_lfa1 into wa_lfa1.

endloop.

Now i get this error

OBJECTS_OBJREF_NOT_ASSIGNED

CX_SY_REF_IS_INITIAL

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
947

You missed the CREATE OBJECT statement.

Read only

Former Member
0 Likes
947

correct

Read only

Former Member
0 Likes
947

Well this is working well for me.


types: begin of ty_lfa1,
       lifnr type lfa1-lifnr,
       name1 type lfa1-name1,
       name2 type lfa1-name2,
       end of ty_lfa1.

data: t_lfa1 type standard table of ty_lfa1,
      wa_lfa1 like LINE OF t_lfa1.

class fetchsap definition.
public section.
Methods:
picksalesbudget exporting tp_lfa1 like t_lfa1.
endclass.

class fetchsap implementation.

method picksalesbudget.
select lifnr name1 name2 from lfa1 up to 3 rows into table tp_lfa1.
endmethod.

endclass.

START-OF-SELECTION.

DATA: obc TYPE REF TO fetchsap.

create object obc TYPE fetchsap.

call method obc->picksalesbudget( importing tp_lfa1 = t_lfa1 ).

loop at t_lfa1 into wa_lfa1.
  write:/ wa_lfa1.
endloop.

Vikranth

Read only

pramodu
Active Participant
0 Likes
947

Hello,

I did some small correction in your program as marked in bold

( Please set break point for the statement

SELECT lifnr name1 name2 FROM lfa1 UP TO 3 ROWS INTO TABLE tp_lfa1. and you will see three records come

on tp_lfa1 in debuggin)

REPORT yup_oo_test .

TYPES: BEGIN OF ty_lfa1,

lifnr TYPE lfa1-lifnr,

name1 TYPE lfa1-name1,

name2 TYPE lfa1-name2,

END OF ty_lfa1.

DATA: t_lfa1 TYPE STANDARD TABLE OF ty_lfa1.

----


  • CLASS fetchsap DEFINITION

----


*

----


CLASS fetchsap DEFINITION.

PUBLIC SECTION.

METHODS:

picksalesbudget EXPORTING tp_lfa1 LIKE t_lfa1.

ENDCLASS. "fetchsap DEFINITION

----


  • CLASS fetchsap IMPLEMENTATION

----


*

----


CLASS fetchsap IMPLEMENTATION.

METHOD picksalesbudget.

SELECT lifnr name1 name2 FROM lfa1 UP TO 3 ROWS INTO TABLE tp_lfa1.

ENDMETHOD. "picksalesbudget

ENDCLASS. "fetchsap IMPLEMENTATION

START-OF-SELECTION.

DATA: obc TYPE REF TO fetchsap.CREATE OBJECT obc.

CALL METHOD obc->picksalesbudget.

CALL METHOD obc->picksalesbudget.

Best Regards,

Pramod Upadhyay

Read only

karthik_vardhan
Associate
Associate
0 Likes
947

Hi,

Object should be gets created after Start-of-selection Statement Only in Case of Executable Programs.

Write Event Start-of-selection Before U are Going to Create Objects .

You Can Create references & Objects After Start-of-Selection .

But it is Advisable to Create References Before Start of Selection (Type Ref to )&

Create Objects After Start of Selection (Create ) .

Read only

0 Likes
947

Hi

I think Suhas Saha's reply is best because you are using your exporting parameter and passing the value in your method call. then only you will be able to get the values.

CALL METHOD obc->picksalesbudget( IMPORTING tp_lfa1 = t_lfa1 )

Thanks

Lalit Gupta