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

Newbie Question - How to Return a Table Structure from a Function

Former Member
0 Likes
772

Hello All,

I have defined a table structure ni the Data Dictionary, and would like to create a function which returns "TABLE OF my_structure". How do I do this?

Thanks,

Walter (ABAP newbie)

4 REPLIES 4
Read only

Former Member
0 Likes
689

Try FM 'GET_FIELDTAB'

REPORT ZEXAMPLE.

DATA: BEGIN OF FIELDINFO OCCURS 0.

INCLUDE STRUCTURE DFIES.

DATA: END OF FIELDINFO.

PARAMETERS TABNAME LIKE SUBDFIES-TABNAME.

CALL FUNCTION 'GET_FIELDTAB'

EXPORTING

TABNAME = TABNAME

TABLES

FIELDTAB = FIELDINFO

EXCEPTIONS

INTERNAL_ERROR = 1

NO_TEXTS_FOUND = 2

TABLE_HAS_NO_FIELDS = 3

TABLE_NOT_ACTIV = 4

OTHERS = 5.

IF SY-SUBRC EQ 0.

WRITE:/ 'Structure of', TABNAME,

/ 'Field Name', 20 'Field Type', 40 'Field Size'.

ULINE.

LOOP AT FIELDINFO.

WRITE:/ FIELDINFO-FIELDNAME, 20 FIELDINFO-INTTYPE, 40 FIELDINFO-LENG.

ENDLOOP.

ELSE.

WRITE:/ 'Error retrieving field data'.

ENDIF.

Read only

0 Likes
689

Hi Joyjit,

Thanks for your quick response, but there is something I don't understand. When I create a new function, I have options of adding parameters of type "importing", "exporting", or "return". I do not see a parameter of type "table" - so I don't understand how you use the "TABLE" parameter in your example code.

Can you please explain further?

Thanks,

Walter

Read only

0 Likes
689

I think u r creating a function module..right? in SE37 goto import tab and define the TABNAME field like:

TABNAME LIKE SUBDFIES-TABNAME

Then goto Tables tab and define the table FIELDINFO.

Ans in Source code section call the FM

CALL FUNCTION 'GET_FIELDTAB'

EXPORTING

TABNAME = TABNAME

TABLES

FIELDTAB = FIELDINFO

EXCEPTIONS

INTERNAL_ERROR = 1

NO_TEXTS_FOUND = 2

TABLE_HAS_NO_FIELDS = 3

TABLE_NOT_ACTIV = 4

OTHERS = 5.

Read only

0 Likes
689

To clarify - this is not part of a function module, I have created a class, and want to add a function to the class which returns a table of something. I want to create the table inside the function, and pass it to the calling code.