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: 

Abap generic type

Former Member
0 Kudos

Hi.

What is the generic type for abap variables?

I tried to use field symbols with any type, but field symbols is a reference. It is invalid when the base variable is released. In debbuger, It changes the value to XXXXXXXXXXXXXXXXXXX

I want to copy a variable value of a unknown type (type any of a method parameter) to a local variable in a method. How I can do this?

Darley.

1 ACCEPTED SOLUTION

rodrigo_paisante3
Active Contributor
0 Kudos

Darley Rodrigo? Abap Workbench class in SP, October 2006???

I am Rodrigo Paisante.. mineiro!

Please, put here your source code, i want to see it.

Regards!!

11 REPLIES 11

rodrigo_paisante3
Active Contributor
0 Kudos

Darley Rodrigo? Abap Workbench class in SP, October 2006???

I am Rodrigo Paisante.. mineiro!

Please, put here your source code, i want to see it.

Regards!!

0 Kudos

hi mineiro, you become a abap expert

Here is an example:

CLASS some_class DEFINITION.

  PUBLIC SECTION.
    METHODS: add_value IMPORTING value TYPE any.

  PRIVATE SECTION.
    TYPES: BEGIN OF y_values,
             value TYPE <what-type?>,
           END OF y_values.

    DATA: t_values TYPE TABLE OF y_values.

ENDCLASS.

CLASS some_class IMPLEMENTATION.

  METHOD add_value.

    DATA: wa_value LIKE LINE OF t_values.

    wa_value-value = value.
    APPEND wa_value TO t_values.

  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

  DATA: o TYPE REF TO some_class.

  CREATE OBJECT o.

  o->add_value( 'some text' ).
  o->add_value( 1 ).
  o->add_value( sy-datum ).

0 Kudos

Helo Darley, i transfer your problem to my friend mineiro 2, Marcelo... he said:

marcsiqueira: vc passa os valores como caracter... depois formata de acordo com o padrão para o type q vc quer.... se vai ser só numero. se vão ter casas decimais, quantas... a ordem das informações, e assim por diante... da mesma forma q trabalhamos pra formatar uma data na máscara '__/__/____'

The expert is right, the type is STRING.

Try it...

0 Kudos

string?

but if i have an object, i cannot set him to a string variable.

I'm trying to use

DATA: o_ref TYPE REF TO data.

GET REFERENCE OF <any type of variable> INTO o_ref.

It works, but the reference is invalid when the base variable is released. In debugger, It changes the value to XXXXXXXXXXXXXXXXXXX, just like field symbols.

0 Kudos

Darley, Marcelo said this:

--- from help ---

The content of two reference variables filled with GET REFERENCE is only the same if - apart from the referenced data objects - the other management information is the same. For example, a reference that is got directly through the specification of the data object is different from a reference that is got through the specification of a field symbol if this has a different data type because of a casting.

Casting:

Handling a Data object assuming a certain Data type. Explicit casting is possible with the statement ASSIGN and with the assignmentsbetween reference variables . An implicit casting sometimes takes place during the handling of operands at certain operand positions.

<b>Creating data references to the individual characters of a data object text and their storage in an internal table. This example is possible as of Release 6.10. Before Release 6.10, dref can only be typed using TYPE REF TO data and cannot be dereferenced, except in ASSIGN.</b>

if you want more information, contact him.

Google Talk: marcsiqueira@gmail.com

0 Kudos

Hi again, see this code:

e pontua as respostas boas...

&----


*& Report ZTESTE02 *

REPORT zteste02 .

----


  • CLASS some_class DEFINITION

----


*

----


CLASS some_class DEFINITION.

PUBLIC SECTION.

METHODS: write_dados IMPORTING tabela TYPE any.

ENDCLASS. "some_class DEFINITION

----


  • CLASS some_class IMPLEMENTATION

----


*

----


CLASS some_class IMPLEMENTATION.

METHOD write_dados.

FIELD-SYMBOLS: <fstable> TYPE table,

<wa> TYPE ANY.

ASSIGN tabela TO <fstable>.

LOOP AT <fstable> ASSIGNING <wa>.

WRITE <wa>.

ENDLOOP.

ENDMETHOD. "some_class

ENDCLASS. "some_class IMPLEMENTATION

START-OF-SELECTION.

DATA: o TYPE REF TO some_class.

DATA: BEGIN OF ti_scustom OCCURS 0.

INCLUDE STRUCTURE scustom.

DATA: END OF ti_scustom.

SELECT * FROM scustom INTO TABLE ti_scustom.

CREATE OBJECT o.

o->write_dados( ti_scustom[] ).

0 Kudos

Rodrigo, see my sample code (some_class)

I want to keep like an attribute of a class the values added with add_value method.

You just output then.

FIELD-SYMBOLS aren't allowed at IMPLEMENTATION section of a class

0 Kudos

Darley, this code works, i use write only to see if the result is correct. If you test the code, it will work. And if you change

write <wa>

to

write <wa>+0(11)

will output only the field ID.

I write this code in Minisap 6.1

0 Kudos

I solve the problem:

  DATA o_ref TYPE REF TO data.

  FIELD-SYMBOLS  <fs_value> LIKE LINE OF t_values.

  LOOP AT t_values ASSIGNING <fs_value>.

    GET REFERENCE OF <fs_value>-value INTO o_ref.

...

  ENDLOOP.

using field-symbols, the referenced value of a value still in memory

tanks mineiro

former_member378318
Contributor
0 Kudos

Try declaring your local variable as type STRING.

Former Member
0 Kudos

hi

plz refer to the link below for ur query

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ff99cb90-0201-0010-e389-ca688964...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c031aa90-0201-0010-b69d-88a278e1...

example

comibining parallel processing (CALL FUNCTION STARTING NEW TASK) with the ABAP OO concept of events.

Here you can find a simple report.

REPORT zcra_parallel2.

----


  • CLASS receiver_class DEFINITION

----


*

----


CLASS receiver_class DEFINITION.

PUBLIC SECTION.

METHODS:

start IMPORTING value(i_taskname) TYPE char8,

receiver1 IMPORTING value(p_task) TYPE clike.

EVENTS:

finished.

ENDCLASS. "receiver_class DEFINITION

----


  • CLASS receiver_class IMPLEMENTATION

----


*

----


CLASS receiver_class IMPLEMENTATION.

METHOD start.

CALL FUNCTION 'ZZ_CRA1' STARTING NEW TASK i_taskname

CALLING me->receiver1 ON END OF TASK

EXPORTING

mytask = i_taskname.

IF sy-subrc = 0.

WRITE: /, i_taskname, ' TASK started...'.

ENDIF.

ENDMETHOD. "start

METHOD receiver1.

DATA:

myinfo TYPE TABLE OF zcra1.

RECEIVE RESULTS FROM FUNCTION 'ZZ_CRA1'

TABLES my_itab = myinfo.

RAISE EVENT finished.

ENDMETHOD. "receiver1

ENDCLASS. "receiver_class IMPLEMENTATION

----


  • CLASS x DEFINITION

----


*

----


CLASS caller DEFINITION.

PUBLIC SECTION.

DATA:

y_ref TYPE REF TO receiver_class,

z_ref TYPE REF TO receiver_class.

METHODS:

constructor,

result FOR EVENT finished OF receiver_class.

ENDCLASS. "callerx DEFINITION

----


  • CLASS callerx IMPLEMENTATION

----


*

----


CLASS caller IMPLEMENTATION.

METHOD constructor.

SET HANDLER: me->result FOR ALL INSTANCES.

CREATE OBJECT: y_ref, z_ref.

CALL METHOD y_ref->start( 'WAIT1' ).

CALL METHOD z_ref->start( 'WAIT2' ).

ENDMETHOD. "constructor

METHOD result.

WRITE: /, 'EVENT TRIGGERD!'.

ENDMETHOD. "result

ENDCLASS. "callerx IMPLEMENTATION

DATA:

mycaller TYPE REF TO caller.

START-OF-SELECTION.

CREATE OBJECT mycaller.

regards

ravish

plz dont forget to reward points if helpful

regards

ravish

<b>plz dont forget to reward points if helpful</b>