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: 

How to return an internal table with methods ?

Former Member

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.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor

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

2 REPLIES 2

naimesh_patel
Active Contributor

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

Former Member
0 Kudos

Thanks, that works fine!

Regards,

Christian