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

SAP Function Module to Object Method

Former Member
0 Likes
2,647

Howdy folks,

I have a requirement to convert a custom Function Module into an ABAP Object Method. The requirement for this is that the required output is to be in table form, the structure of which will be determined dynamically using RTTC funtionality. Passing the dynamic table back to an output parameter is a lot easier to manage with an Object Method than with a Function Module (or so it seems!).

The downside is that many of the perform routines which are defined in Include programs attached to the Function group now need to be built/copied as new methods within my custom object class because the Include programs are not recognised within the methods.

Many key defintions, particularly variables, internal tables and Type-Pool declarations that are used in a variety of subroutines accross the different include programs are stored in a xxxTOP include. Is there any way of defining type-pools and associated declarations at a global level in the Object Class via SE24, or copying them in en-masse, or do they have to be defined individually? And how do you declare an internal table or type pool in SE24 - via the Attributes tab, Types Tab, or via some other place.

Any assistance would be greatly appreciated.

Cheers,

Stephen Keam

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,855

The requirement for this is that the required output is to be in table form, the structure of which will be determined dynamically using RTTC funtionality. Passing the dynamic table back to an output parameter is a lot easier to manage with an Object Method than with a Function Module (or so it seems!).

I am curious why you think so. In both cases you can use parameter typed ANY TABLE which you can use to pass generic (or dynamic) tables. Maybe you mean using functional method but here this is just a matter of different calling structure.

Also in none of the above you can statically determine line type of dynamic table, so you have to type is generically anyway. So the way you handle your dynamic table stays the same both for function and method. You have to address its components dynamically.

As for the passing one more thing to be noticed. You can pass the reference to a table (type this parameter with type ref to data ), dereference it inside FM/method and work internally with the table behind this reference.

So I don't think there is a need for re-engineering all you procedural code to OO, unless the reason is more serious.

Regards

Marcin

4 REPLIES 4
Read only

gerd_rother
Active Participant
0 Likes
1,855

Hi,

First of all I am afraid that there is no tool to get all the type/type-pools declarations from a program/function group into a class definition (at least to my knowledge, I would like to see me corrected). So you have to do that manually, which should be in principle easy if you edit the public, protected and private sections directly - not via the types/attributes tabs.

But to me your task sounds more like a re-engineering task, so, I would rather do an object oriented redesign than just copy the old code. Maybe you will create more than one class to cover the requirements formerly met by a number of form routines in that function group. Unfortunately budget restrictions might force you to follow a 'copy' strategy, but in the long run thinking a bit bigger might pay off.

Regards, Gerd Rother

Read only

MarcinPciak
Active Contributor
0 Likes
1,856

The requirement for this is that the required output is to be in table form, the structure of which will be determined dynamically using RTTC funtionality. Passing the dynamic table back to an output parameter is a lot easier to manage with an Object Method than with a Function Module (or so it seems!).

I am curious why you think so. In both cases you can use parameter typed ANY TABLE which you can use to pass generic (or dynamic) tables. Maybe you mean using functional method but here this is just a matter of different calling structure.

Also in none of the above you can statically determine line type of dynamic table, so you have to type is generically anyway. So the way you handle your dynamic table stays the same both for function and method. You have to address its components dynamically.

As for the passing one more thing to be noticed. You can pass the reference to a table (type this parameter with type ref to data ), dereference it inside FM/method and work internally with the table behind this reference.

So I don't think there is a need for re-engineering all you procedural code to OO, unless the reason is more serious.

Regards

Marcin

Read only

0 Likes
1,855

Marcin,

Thank you for your reply. The reason behind my assertion that Objects are better suited to Dynamic passback than Function Modules was largely based around the fact that, when I defined the table parameter as 'any table', the Function module would not compile on activation with this definition. The closest I could come was to define the output tables as a table of type string, but then I lost the table structure and it became a string record again.

My issue is largely around how to declare variable and structure data objects globally for all methods in the class given that I cannot use the 'TOP' include functionality as I can for a function module/function group.

Regards,

Steve

Read only

0 Likes
1,855

Steve,

You're welcome.

when I defined the table parameter as 'any table', the Function module would not compile on activation with this definition.

This is true when you use TABLES parameter tab. The system then does not allow to type the parameter fully generically. You can use anyhow STANDARD TABLE type.

But for ANY TABLE you can use one of other parameter type, namely EXPORTING/CHANGING, so this issue will no longer be a valid.

My issue is largely around how to declare variable and structure data objects globally for all methods in the class given that I cannot use the 'TOP' include functionality as I can for a function module/function group.

For all the classes which have to use same data (as global data) you can use INTERFACE for this. You define all data objects there and include this INTEFACE in all the classes you need. This way you don't violate the encapsulation still being able to have kind of "global data" not specific to any of the classes, while all of them can work with these data.

Regards

Marcin