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: 

Passing tables to function modules

Former Member
0 Kudos
1,460

Hi, I am trying to port some old ABAP code to the latest release that no longer supports passing TABLES to function module, but tells you to use CHANGING instead. I can't seem to get to the whole thing to work. I have a program that creates an internal table with a header line, passes it to the function module, and the function module is supposed to fill the table. I tried changing the parameter in the function module from TABLES to CHANGING, and use TYPE to reference a database type (which happens to be a view). But the code in the function module that referenecs the table being passed (to fill it) complains that it is not an internal table. I tried using TYPE ANY TABLE in the parameter definition, and then it complains that it is not a "standard" table when it goes to fill it. What I'm trying to do should be simple, but I can't seem to get the right combination of things to work. I cant seem to find a step-by-step on converting from the use of TABLES to CHANGING . Any advice ?? Thanks

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
372

Hi Wendy, when passing tables thru the function module signature using the CHANGING parameters, you must use table types. If one does not exist for your purpose you must create the table type via SE11 and then reference this table type when defining the CHANGING parameter. It also might be a good idea for you to change the internal table that is being passed, get rid of the "with header line" and use a explicit work area instead.

Regards,

Rich Heilman

0 Kudos
372

Thank you so much , but I think I may have compounded problem. I changed the signature to CHANGING and referenced an existing SE11 defined table by using TYPE. The old signature used the TABLES tab and referenced the same table via LIKE.

The first thing I do in the code is try to pass that table as a parameter to a subroutine using the TABLES parameter (which I thought was obsolete but still supported). It looks just like this, sorry it will look messy:

FUNCTION Z_ACCEPT_REQUEST_INFO_BY_APP.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(APPLICATION_ID) TYPE ZSINB-ZPGMID

*" VALUE(JOB_NAME) TYPE ZSRQC-ZJOBNAME

*" VALUE(JOB_NUM) TYPE ZSRQC-ZJOBNUM

*" EXPORTING

*" VALUE(NUMBER_OF_REQUESTS) TYPE SY-DBCNT

*" CHANGING

*" REFERENCE(REQUEST_INFO_TAB) TYPE ZSVRI

*" EXCEPTIONS

*" SELECT_REQUESTS_FAILED

*" UPDATE_STATUS_FAILED

*"----


PERFORM GET_REQUEST_TAB TABLES REQUEST_INFO_TAB

USING APPLICATION_ID

CHANGING NUMBER_OF_REQUESTS.

IF LOCAL_RETURN_CODE <> SUCCESS.

RAISE SELECT_REQUESTS_FAILED.

:

The failure I am getting now on the sytnax is "REQUEST_INFO_TAB" is not an internal table - the "OCCURS n" specification is missing.

So the function does not recognize the table being passed as an internal table. Do I need to copy it to an intermediate work area before using it?

Wendy

0 Kudos
372

Wendy, as you have it now, you are not passing a table, but a structure which is typed like ZSVRI. When using this type in the TABLES parameter, it assumes that it is always a table, but when using in CHANGING parameters it could be either, which is why you need to create a table type for your structure ZSVRI in Se11, you can use this structure when defining your table table. Create the table type ZSVRI_TT, then reference ZSVRI as the line structure, save and activate, Now go to your function module and change the reference for REQUEST_INFO_TAB to the ZSVRI_TT. Now you are passing a table.

Regards,

Rich Heilman

0 Kudos
372

Thank Rich,

I get it now. The question now ( from DBA) is whether is the "correct" approach or a quick fix. I may look into the use generic data type too. Thanks again for the advice - you got me thinking on the right track.

Wendy

0 Kudos
372

To my knowledge the use of table types is the correct way to pass tables in function modules and when passing tables in methods of classes.

Regards,

Rich Heilman