‎2010 Jun 29 11:18 AM
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
‎2010 Jun 29 11:31 AM
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.
‎2010 Jun 29 11:32 AM
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
‎2010 Jun 29 11:55 AM
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
‎2010 Jun 29 11:56 AM
‎2010 Jun 29 11:56 AM
‎2010 Jun 29 11:59 AM
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
‎2010 Jun 29 11:36 AM
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
‎2010 Jun 29 11:43 AM
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 ) .
‎2010 Jun 29 1:16 PM
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