2012 May 31 5:41 PM
how to declare parameter of a class method , so that it can accept a workarea or an internal table ?
2012 May 31 7:09 PM
If it is not a RETURNING parameter, you may use TYPE ANY. But then you must determined the actual type (table or not) and assign it to a field-symbol. Otherwise you may get errors in syntax check.
If you tell us what you are going to do (details please), we can help you.
Regards
Clemens
2012 May 31 10:02 PM
We are to create document change log, for that the class we have created, should accept either a workarea or internal table of any kind.
I was trying to create a import parameter of type 'ANY", but when iam trying to pass internal table its erroring out.
2012 May 31 11:07 PM
Hello Sirisha,
You can design your methods to accept either tables / structures of any types. Below is a working example of passing any DDIC type as structure and working on it in further mehtods.
Check out this sample code.
CLASS lcl_zclass DEFINITION.
TYPE-POOLS: abap.
PUBLIC SECTION.
DATA:
mt_dfies TYPE DDFIELDS read-only,
r_dfies TYPE DFIES.
METHODS:
constructor
IMPORTING
value(id_tabname) TYPE tabname,
method1
IMPORTING
value(it_dfies) TYPE DDFIELDS.
ENDCLASS.
CLASS lcl_zclass IMPLEMENTATION.
METHOD constructor.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = id_tabname
* FIELDNAME = ' '
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* GROUP_NAMES = ' '
* UCLEN =
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
DFIES_TAB = me->mt_dfies
* FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMETHOD.
METHOD method1.
LOOP AT mt_dfies INTO r_dfies.
BREAK-POINT.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
" Instantiate your class and use its methods
DATA: go_myclass TYPE REF TO lcl_zclass.
CREATE OBJECT go_myclass
EXPORTING
id_tabname = 'TVARVC'.
CALL METHOD go_myclass->method1
EXPORTING
it_dfies = go_myclass->mt_dfies.
Regards,
Shyam
2012 Jun 01 8:14 AM
Hello Sirisha,
I just tried to build a method which imports a table of type 'ANY' and for structure I used the type 'DATA' and it works.
Inside the method I used Field-symbols as below:
FIELD-SYMBOLS: <FS_TAB> TYPE ANY TABLE,
<FS_STR> TYPE DATA.
ASSIGN MI_TABLE TO <FS_TAB>. "MI_TABLE is importing parameter of type ANY. Pass by Value.
ASSIGN MI_STRUC TO <FS_STR>. " MI_STRUC is importing param. of type DATA. Pass by Value.
Are you looking for something else or something specific? Do let know.
Regards,
Kumud