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: 

Dinamic programing ..

Former Member
0 Kudos

Hi ,

I have two questions .

1.I want to add a field to the internal table passed

from the program inside the global class .

the table is passed as a table type.I need to add one more field to that passed table from with in the global class .

2. How do i call an object dynamicaly ,

for ex : <Objectname>->get_functions( ).

the above statement gives syntax error .

**The object is created from different classes in run time .

Thanks for your help,

Pointes are assured for helpful answers .

Thanks.

7 REPLIES 7

Former Member
0 Kudos

Is the class a core object or a custom object (ie. what is the object name - and table name)?

If it is a core class, it is unlikely that you can alter it.

0 Kudos

suppose i have many classes with same methods defined,

I want to deside in runtime , which class method to call .

My first problem is more important to me though .

0 Kudos

Hi sk,

1. This kind of functionality

(which is available in c++)

i don't think abap allows.

Referencing the method dynamically !

2. Anyway, we can wait for other answers.

regards,

amit m.

0 Kudos

Hi, SK

why don't you write dynamically a subroutine which calls your desired method??

Take a look at


1. GENERATE REPORT prog. 
2. GENERATE SUBROUTINE POOL itab NAME name. 

Maybe u can code the subroutine as....


FORM dynamic_subroutine USING myObj.
  myObj->myMethod().
ENDFORM.

But you have to pay attention, because:

<b>

This statement is for internal use only.

Incompatible changes or further developments may occur at any time without warning or notice.

</b>

Former Member
0 Kudos

Hello SK,

To your first question:

Dynamically changing a table type is not possible in ABAP, I believe. But you can copy an internal table to another one with the additional field as follows.

In order to add one more field to a table of a certain table type, let's say TABLE OF STRUCT, you need to declare a second table of type TABLE OF STRUCT_EXTENDED, where the structure STRUCT_EXTENDED has the additional field NEWFIELD appended. Here is the code:

DATA table1 TYPE STANDARD TABLE OF struct.

DATA table2 TYPE STANDARD TABLE OF struct_extended.

DATA wa1 LIKE LINE OF table1.

DATA wa2 LIKE LINE OF table2.

LOOP AT table1 INTO wa1.

wa2 = wa1.

wa2-newfield = 'ABC'.

APPEND wa2 TO table2.

ENDLOOP.

Michael

Former Member
0 Kudos

Hello SK,

you can dynamically call a class method, if the classes all implement the same interface. Here is an example report.

REPORT test.

INTERFACE intf.

METHODS imeth.

ENDINTERFACE.

CLASS c1 DEFINITION.

PUBLIC SECTION.

INTERFACES intf.

ENDCLASS.

CLASS c1 IMPLEMENTATION.

METHOD intf~imeth.

WRITE: /, 'Class c1'.

ENDMETHOD.

ENDCLASS.

CLASS c2 DEFINITION.

PUBLIC SECTION.

INTERFACES intf.

ENDCLASS.

CLASS c2 IMPLEMENTATION.

METHOD intf~imeth.

WRITE: /, 'Class c2'.

ENDMETHOD.

ENDCLASS.

FIELD-SYMBOLS <fs> TYPE REF TO intf.

DATA: cref1 TYPE REF TO c1,

cref2 TYPE REF TO c2,

iref1 TYPE REF TO intf,

iref2 TYPE REF TO intf,

s TYPE STRING.

START-OF-SELECTION.

  • Create objects.

CREATE OBJECT: cref1, cref2.

  • Assign objects to interface references.

iref1 = cref1.

iref2 = cref2.

  • Dynamically call method of first object.

s = 'iref1'.

ASSIGN (s) TO <fs>.

CALL METHOD <fs>->imeth.

  • Dynamically call method of second object.

s = 'iref2'.

ASSIGN (s) TO <fs>.

CALL METHOD <fs>->imeth.

Former Member
0 Kudos

SK,

You did not tell us the object name(s) involved yet.

If the table type is not a "Y" or "Z" data dic object, then you would need to see if SAP will allow you to extend the definition using an APPEND STRUCTURE in SE11. You would need to try to append onto the underlying STRUCTURE of the table type.

The APPEND STRUCTURE is intended for custom fields. However, in an OO world, the class object may not handle this change well. IF you can append onto the table type at all... thorough testing would be required on all impacted objects.