‎2008 Aug 07 12:16 PM
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)
‎2008 Aug 07 12:22 PM
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.
‎2008 Aug 07 12:36 PM
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
‎2008 Aug 07 12:42 PM
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.
‎2008 Aug 07 12:48 PM
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.