4

i'm new in abap (OO) but developed before in java and wrote a class abap "cl_caretaker" which should handle the operations on database table and the local copy (intern table) of it.

I want to make the following method call:

caretaker->show_table( caretaker->get_users( ) ) .

with:

 caretaker = cl_caretaker=>get_instance( ). "singleton instance

METHODS:

"! get a list of all user which registrated for FCP
"!
"! @parameter rt_users    | users which are registrated for FCP
   get_users
      RETURNING value(rt_users) TYPE itty_users,


 "! shows the content of a table
 "!
 "! @parameter it_table             | the table we want to visualize
   show_table
      IMPORTING
        value(it_table) TYPE ANY TABLE.

if I split the call in two and store the result of get_users in a tmp variable it works.

DATA:
  gt_tmp_users TYPE caretaker->itty_users.

  gt_tmp_users = caretaker->get_users( ).
  caretaker->show_table( gt_tmp_users ).

So my questions are:

1) is a call like: caretaker->show_table( caretaker->get_users( ) ). possible and if how?

2) I also tried to create a generic variable, which stores all kind of tables. Because i don't want to create for each table kind i use a tmp/help variable. But i got the information that only (german: Formalparameter) dummy parameters of method definitions are allowed to of generic type (eg. TYPE any TABLE ).

Here some stuff I already tried:

DATA:
*    tmpanytable TYPE TABLE OF any.
*    tmpAnyTable TYPE any.
    tmpanytable TYPE REF TO data.

 " needed to store a temporal table
 FIELD-SYMBOLS: <tmpanytable> TYPE ANY TABLE.

* ASSIGN caretaker->get_users( ) TO <tmpAnyTable>.
* <tmpAnyTable> = caretaker->get_users( ).
* caretaker->get_users( ).
*caretaker->show_table( <tmpAnyTable> ).
*caretaker->show_table( caretaker->get_users( ) ).

*CALL METHOD: caretaker->show_table( IMPORTING it_table = caretaker->get_users ).
*CALL METHOD: caretaker->show_table( it_table = caretaker->get_users( ) ).

*COMPUTE caretaker->show_table( it_table = caretaker->get_users( ) ).

*ASSIGN caretaker->get_users() ->* to <tmpAnyTable>.
*Caretaker->show_table( <tmpAnyTable> ).

*call METHOD caretaker->show_table
*                Exporting It_table = caretaker->get_users( ).

*  CREATE DATA tmpanytable TYPE STANDARD TABLE OF (dbtab)
*                            WITH NON-UNIQUE DEFAULT KEY.
*  ASSIGN tmpanytable->* TO <tmpanytable>.

*  CREATE DATA tmpanytable TYPE tabkind OF any Table .
*  ASSIGN tmpanytable->* TO <tmpanytable>.

*GET REFERENCE OF caretaker->get_users() INTO tmpAnyTable.
*caretaker->show_table( tmpAnyTable ) .
2
  • 1
    What SAP_ABA release are you using?
    – vwegert
    Mar 13, 2015 at 12:27
  • Softwarecomponent : SAP_ABA Release: 701 Level: 0004 highest support package: SAPKA70104
    – cpoliwoda
    Mar 13, 2015 at 13:35

1 Answer 1

1

Method chaining is possible, and methods in operand positions are possible as well, but you need at least SAP_ABA 702 for that.

You can use generic types to pass a table around without knowing its type at runtime. However, you can't create a table without knowing its type. Comparing it to OO principles, you can handle references to an abstract superclass and pass them along between components, but you can't instantiate the abstract superclass. The CREATE DATA statement needs a "concrete data type" to work on, not the "abstract super type STANDARD TABLE". The hard part here is deciding who will know about the type and create the data object.

BTW, you may want to take a look at the built-in Object Services - maybe there's no need to reinvent the database access layer wheel yet again.

2
  • thanks, for your answers and hints. - The Example of "Method Chaining" looks for my like the Builder Design Pattern, but that is not used for nesting the methods as i ask for. - But I will take a closer look at the "Object Services".
    – cpoliwoda
    Mar 16, 2015 at 9:31
  • method or expression chaining info in german wikipedia http://de.wikipedia.org/wiki/ABAP#Seit_Release_7.1_.2F_7.02
    – cpoliwoda
    Mar 31, 2015 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.