10-13-2008 7:59 PM
Hi,
I am an Java programmer and very new to ABAP.
How do I return a internal table with a method? I have the table GP1_PRODUCTS and want to return a copy of this table as an internal table called PRODUCTS.
Here is my code that does not work:
class PRODUCTS definition
public
final
create public .
public section.
*"* public components of class PRODUCTS
*"* do not include other source files here!!!
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type GP1_PRODUCTS .
protected section.
*"* protected components of class PRODUCTS
*"* do not include other source files here!!!
private section.
*"* private components of class PRODUCTS
*"* do not include other source files here!!!
ENDCLASS.
CLASS PRODUCTS IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method PRODUCTS->GET_PRODUCT_LIST
* +-------------------------------------------------------------------------------------------------+
* | [<-()] PRODUCTS TYPE GP1_PRODUCTS
* +--------------------------------------------------------------------------------------</SIGNATURE>
method GET_PRODUCT_LIST.
DATA: it_products TYPE STANDARD TABLE OF GP1_PRODUCTS.
select * from GP1_PRODUCTS into table it_products.
PRODUCTS = it_products.
endmethod.
ENDCLASS.
10-13-2008 8:08 PM
You have to create a table type for your table GP1_PRODUCTS.
If you use global class (created in SE24), than:
Create a Table Type in SE11
Go to SE11, Enter a name like ZPRODUCTS in the Data Type
There will be popup when you press the Create button to decide a type. Select the Table Type
Enter GP1_PRODUCTS in the Line Type.
* method declaration
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type ZPRODUCTS.
If you use local class:
TYPES: ty_products type standard table of GP1_PRODUCTS..
* method declaration
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type ty_products
Regards,
Naimesh Patel
10-13-2008 8:08 PM
You have to create a table type for your table GP1_PRODUCTS.
If you use global class (created in SE24), than:
Create a Table Type in SE11
Go to SE11, Enter a name like ZPRODUCTS in the Data Type
There will be popup when you press the Create button to decide a type. Select the Table Type
Enter GP1_PRODUCTS in the Line Type.
* method declaration
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type ZPRODUCTS.
If you use local class:
TYPES: ty_products type standard table of GP1_PRODUCTS..
* method declaration
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type ty_products
Regards,
Naimesh Patel
10-13-2008 8:25 PM