2010 Nov 21 4:13 PM
HI All
I created a method as follows and the problem is that when i enter
to the method the i have dump since the field symbol is not
assigned
there is a nice way that i can by-pass this issue ,
the reason that i created a method for that is that
i need to do this operation several of time in my code
The signature
LS_TARGET_STR Importing Type Z_ATTR_STRUCT
ES_ATTR Exporting Type ANYTHe code
FIELD-SYMBOLS <ls_attr> TYPE any.
DATA lo_attr TYPE REF TO data.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
es_attr = <ls_attr>.Regards
Alex
Edited by: Alex Dean on Nov 21, 2010 5:13 PM
2010 Nov 21 5:21 PM
Hi,
I think you pass something that is not defined as dictionary type
CREATE DATA lo_attr TYPE (ls_target_str)You can check using
IF lo_attr is bound.
ASSIGN lo_attr->* TO <ls_attr>.
else.
raise exception ... "invalid type
endif.Regards
Clemens
2010 Nov 21 5:21 PM
Hi,
I think you pass something that is not defined as dictionary type
CREATE DATA lo_attr TYPE (ls_target_str)You can check using
IF lo_attr is bound.
ASSIGN lo_attr->* TO <ls_attr>.
else.
raise exception ... "invalid type
endif.Regards
Clemens
2010 Nov 22 7:45 AM
HI
The problem is that i call to the method and <ls_structure> is not assigend yet
since than i get dump
convert_types(
EXPORTING
ls_target_str = ls_target_node-data-attribute_struct
IMPORTING
es_gsdo_attr = <ls_structure>
).
Regards
Alex
2010 Nov 22 8:01 AM
Hi Alex,
you can not pass an unassigned field-symbol (<ls_structure>) to a methods (or FORM or FUNCTION) parameter. A field-symbol is like a pointer: If it is not assigned, it points to nowhere.
You can define the parameter as a reference variable, ES_STRUCT_REF TYPE REF TO DATA.
In the method, you can
CREATE DATA ES_STRUCT_REF TYPE (ls_target_str).
You call the method using a local data reference
DATA: lr_struct type ref to data.
convert_types(
EXPORTING
lls_target_str = ls_target_node-data-attribute_struct
IMPORTING
ES_STRUCT_REF = lr_struct ).
if lr_struct is bound.
assign lr_struct to <ls_structure>.
endif.Regards,
Clemens
2010 Nov 22 8:11 AM
Hi Clemens LI
now i am facing differnt issue
FIELD-SYMBOLS <ls_attr> TYPE any.
DATA lo_attr TYPE REF TO data.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
es_attr = <ls_attr>. <- here i have dump!
How can i overcome it ?
Regards
Alex
2010 Nov 22 8:15 AM
Hi Alex,
read the whole thread carefully.
And if you get a dump, read the dump carefully.
And if you ask a quastion, give detailed error description.
Regards,
Clemens
2010 Nov 22 8:18 AM
Hi Clemens LI
now i am facing differnt issue
FIELD-SYMBOLS <ls_attr> TYPE any.
DATA lo_attr TYPE REF TO data.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
es_attr = <ls_attr>. <- here i have dump!
the problem is that i am using the following sighature to this method
LS_TARGET_STR Importing Type Z_ATTR_STRUCT
ES_ATTR Exporting Type ANYthis is export parameter
How can i overcome it ?
2010 Nov 22 8:19 AM
What is the value of ls_target_str on entry to the method? What is the value of sy-subrc after the assign? (4).
2010 Nov 22 8:23 AM
Hi Alex,
you refuse to follow any recommendation.
I will not follow this thread any longer.
Regards,
Clemens
2010 Nov 22 8:25 AM
Hi
Clemens is right.....can you say what you can read on the dump?
You should transfer the data if the ASSIGN is ok only:
ASSIGN lo_attr->* TO <ls_attr>.
if sy-subrc = 0.
es_attr = <ls_attr>
endif.
But it's hard to give you a solution without to know the dump
Max
2010 Nov 22 8:35 AM
HI Matt
The value of the field is acatully data (this part working Ok)
and after the assign the sybrc = 0.
the problem is with the statment
es_attr = <ls_attr>.
The statment is
DATA: lr_struct TYPE REF TO data.
con_types(
EXPORTING
ls_target_str = ls_target_node-data-attribute_struct " Name of Attribute Structure of Node Entity
IMPORTING
es_attr = lr_struct
).And the signature is
LS_TARGET_STR Importing Type Z_ATTR_STRUCT
ES_ATTR Exporting Type ANYThe code of convert types is
FIELD-SYMBOLS <ls_attr> TYPE any.
DATA lo_attr TYPE REF TO data.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
es_attr = <ls_attr>.
***********This is the place that i am
getting the dump . with -> es_attr = <ls_attr>
maybe its becouse that lr_struct is defiend type ref to data .
How can i solve this issue ?
Thanks,
Regards
Alex
Edited by: Alex Dean on Nov 22, 2010 9:36 AM
2010 Nov 22 8:41 AM
Hi
The problem is the variable transfered to exporting paramenter is:
DATA: lr_struct TYPE REF TO data.
and the exporting paramenter is
ES_ATTR Exporting Type ANYThe 2 type are not incompatible
The exporting parameter has to has the same type of the variable, so u can define you exporting parameter like REF TO DATA
Max
2010 Nov 22 8:47 AM
HI max
Now Im getting to my first problem
since when i put a field symbol as export parameter as the code below
I get a dump when i enter the method
so how can i solve this issue nicely.
data <ls_structure> type any .
convert_types(
EXPORTING
ls_target_str = ls_target_node-data-attribute_struct
IMPORTING
es_gsdo_attr = <ls_structure>
).Thanks
Alex
2010 Nov 22 8:54 AM
Hi
you define the variable and exporting parameter as TYPE REF TO DATA:
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: conv_type IMPORTING i_structure TYPE any
EXPORTING e_structure TYPE REF TO data.
ENDCLASS. "lcl_class DEFINITION
CLASS lcl_class IMPLEMENTATION.
METHOD conv_type.
create data e_structure type (i_structure).
ENDMETHOD. "conv_type
ENDCLASS. "lcl_class IMPLEMENTATION
DATA: my_strcture TYPE REF TO data.
FIELD-SYMBOLS: <fs_struct> TYPE ANY.
START-OF-SELECTION.
CALL METHOD lcl_class=>conv_type
EXPORTING
i_structure = 'BKPF'
IMPORTING
e_structure = my_strcture.
ASSIGN my_strcture->* TO <fs_struct>.
SELECT SINGLE * INTO <fs_struct>
FROM bkpf WHERE bukrs = '1000'.
WRITE sy-subrc.Max
2010 Nov 22 9:03 AM
HI Max
Thanks,
Do you think that this is the best way to handle it ?
since i use in many places in my code
and i think to replace it with one method that
can handle this issue.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
Thanks again
ALex
2010 Nov 22 9:11 AM
Hi
I don't know if it's the best soltuion because I don't know what your program does or what you really need to do, but if you need to create an object dynalically, this is should be instanced out of method if you need to use it out of class.
Max
2010 Nov 22 9:20 AM
Hi
I don't know why you wan to use the CLASS, but you can considere to use FORM (But a METHOD is good too) and elaborate a global variable:
DATA: my_strcture TYPE REF TO data.
FIELD-SYMBOLS: <fs_struct> TYPE ANY.
START-OF-SELECTION.
PERFORM conv_type USING 'BKPF'.
SELECT SINGLE * INTO <fs_struct>
FROM bkpf WHERE bukrs = '1000'.
WRITE sy-subrc.
PERFORM conv_type USING 'BSEG'.
SELECT SINGLE * INTO <fs_struct>
FROM bseg WHERE bukrs = '1000'.
WRITE sy-subrc.
FORM conv_type USING i_structure.
CREATE DATA my_strcture TYPE (i_structure).
ASSIGN my_strcture->* TO <fs_struct>.
ENDFORM. "conv_typeOr
DATA: my_strcture TYPE REF TO data.
FIELD-SYMBOLS: <fs_struct> TYPE ANY.
*
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: conv_type IMPORTING i_structure TYPE any.
ENDCLASS. "lcl_class DEFINITION
*
CLASS lcl_class IMPLEMENTATION.
METHOD conv_type.
CREATE DATA my_strcture TYPE (i_structure).
ASSIGN my_strcture->* TO <fs_struct>.
ENDMETHOD. "conv_type
ENDCLASS. "lcl_class IMPLEMENTATION
START-OF-SELECTION.
lcl_class=>conv_type( 'BKPF' ).
SELECT SINGLE * INTO <fs_struct>
FROM bkpf WHERE bukrs = '1000'.
WRITE sy-subrc.
lcl_class=>conv_type( 'BSEG' ).
SELECT SINGLE * INTO <fs_struct>
FROM BSEG WHERE bukrs = '1000'.
WRITE sy-subrc.
2010 Nov 22 9:24 AM
Accatually this method is not related to the program
since this is generic one
I just waht
so the import ls_target_str can be any structrue
so here i dont have any problem (type ref to data)
and the output should be type any since it can be any structure.
this is a no problem to do but the issue
is with the export parameter (field symbol ) when i put it on the method
i have dump since the field-symbol is not assiged
and i dont know how to create the empty assign before
i call to the method
i know that in table there is append initail line to <fs_table>
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
unfortunately we are using a class and i cant use perform there
Thanks
Alex
Edited by: Alex Dean on Nov 22, 2010 10:25 AM
2010 Nov 22 9:30 AM
Hi
The problem is you can't define a generic type, but you can use TYPE ANY for field-symbol or in the interface parameter only.
So if you want to create a class to define an object dynamically, the exporting parameter has to be a REF TO DATA, that means you need to assign it to field-symbol out of the class
Max
2010 Nov 22 9:53 AM
You cannot give an assignation to a field-symbol by calling a method. The ASSIGN must be local. I've written many programs where I pass the reference around and then dereference within a method.
matt
2010 Nov 23 6:24 PM