cancel
Showing results for 
Search instead for 
Did you mean: 

Fileld Symbols

Former Member
0 Kudos

Hi All,

Iam creating a structure and table dynamically as below.

**filed symbols

FIELD-SYMBOLS: <table> TYPE table,

<row> TYPE data.

struct_type = cl_abap_structdescr=>create( comp_tab ).

struct_type = node_info->get_static_attributes_type( ).

table_type = cl_abap_tabledescr=>create( p_line_type = struct_type ).

CREATE DATA my_table TYPE HANDLE table_type.

ASSIGN my_table->* TO <table>.

CREATE DATA my_row TYPE HANDLE struct_type.

ASSIGN my_row->* TO <row>.

Now in runtime I would be able to see the structure of <table> and <row> and also the data if it has. My problem is how would I read that data in to an internal table.

For example if the table has structure of 5 columns how would i read 5th column?

I would like to overwrite the content of 5th column with the content of 4th column.

is it possible? If it is please help me out.

Thank You,

Suresh.

Accepted Solutions (1)

Accepted Solutions (1)

Yashpal
Active Contributor
0 Kudos

Hi Suresh ,

use the following code to solve ur problem

field-symbols : <data1> type any,

<data2> type any.

In the loop like

loop at <table> into <row>.

write the following code.

ASSIGN COMPONENT 5 of <row> to <data1>.

ASSIGN COMPONENT 4 of <row> to <data2>.

<data1> = <data2> .

modify statement for the table.

Endloop.

for more help on this follow the link.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3145358411d1829f0000e829fbfe/frameset.htm

Hope this will solve ur problem.

Regards

Yashpal

Message was edited by:

Yashpal Gupta

Former Member
0 Kudos

Hi Yashpal,

I have tried that way. It was fine upto <data2> = <data1>. Iam getting errors while Iam appending into table.

Pls look at the follwing code.

loop at <table> into <row>.

assign component 4 of structure <row> to <data1>.

assign component 5 of structure <row> to <data2>.

<data2> = <data1>.

<b>modify table <table> from <row> transporting <data2>.</b>

endloop.

I tried that modify with different ways. I was always getting errors.

Any suggestions pls?

Thank you,

Gajendra.

Yashpal
Active Contributor
0 Kudos

Hi ,

In loop you will get index sy-index write

modify <table> index sy-tabix from <row> transporting <data2>

try this it may help u .

Regards

Yashpal

Message was edited by:

Yashpal Gupta

Former Member
0 Kudos

Hi,

I have tried that. It gives the following error.

The specified type has no structure and therefore no component called"<data2>".

Is there any way we can assign the column5 value to <row> itself so that we can modify <table > from <row>.

Pls suggest.

Thank You.

Yashpal
Active Contributor
0 Kudos

Hi ,

u have to pass the name of the field name not the value i.e <data2>.

so create a vairable of type string say lv_string .

lv_string = name_of_column .

then after transporting write (lv_string)

like this

modify <table> index sy-index from <row> transporting (lv_string).

Regards,

Yashpal

Former Member
0 Kudos

Thank You so much Yash.

It worked. I have few more issues like this. If you had worked on this you would be able to help me.

Can I post my other issues aswell?

Is it ok for you to give me your mail id?

Thank You,

Suresh.

Yashpal
Active Contributor
0 Kudos

Yes sure u can post it on SDN becoz ur query can be analyised by many experts and u can get a better solution.

Regards

Yashpal

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Suresh,

I had same requirements where I had ti fill table with plants.

Check out for the code snippet. And reward points if its helpful.

Code:

*******************************************************************************************

method FILL_PLANT .

types : begin of str_cost,

kostl type zcostcenter-kostl ,

end of str_cost.

types : begin of str_ekgrp,

ekgrp type zekgrp-ekgrp,

end of str_ekgrp.

data : itab_cost type table of str_cost with default key .

data : itab_ekgrp type table of str_ekgrp with default key.

data : wa_mara type str_cost.

data : lt_attributes type If_Request_Ior=>Elements_Plantnode,

wa_attributes type If_Request_Ior=>Element_Plantnode.

field-symbols : <fs_cost> type str_cost.

CALL FUNCTION 'ZPD_RFC_COSTCENTER' DESTINATION 'tr3_clnt800'

TABLES IT_COST = itab_cost.

*

CALL FUNCTION 'ZPD_RFC_PURGROUP' DESTINATION 'tr3_clnt800'

TABLES IT_EKGRP = itab_ekgrp .

loop at itab_cost assigning <fs_cost> .

wa_attributes-plant = <fs_cost>-kostl.

insert wa_attributes into table lt_attributes.

endloop.

node->bind_elements( lt_attributes ).

endmethod.

*******************************************************************************************

Hope this will help you.

Cheers,

Darshna.

Former Member
0 Kudos

Hi Darshana,

If you could see the field symbol declaration in your code its of type some structure. But in my case it is just <row> type data and <table> type table.

so when i say <row>-cloumn5 it's giving an error saying <row> is not of type structure.

Pls suggest.

Thank You,

Suresh.

Former Member
0 Kudos

Hi Suresh,

If you specify the addition STRUCTURE instead of typing for a field symbol, and struc is a local program structure (a data object, not a data type) or a flat structure from the ABAP Dictionary, this structure is cast for the field symbol <fs>. You have to specify a data object dobj that is initially assigned to the field symbol.

The field symbol copies the technical attributes of structure struc as if it were completely typed. When you assign a data object using the addition DEFAULT, or later using ASSIGN, its complete data type is not checked in non- Unicode programs. Instead, the system merely checks whether it has at least the length of the structure and its alignment.

In Unicode programs, we differentiate between structured and elementary data objects. For a structured data object dobj, its Unicode fragment view has to match the one of struc. In the case of an elementary data object, the object must be character-type and flat, and struc must be purely character-type. The same applies to assignments of data objects to field symbols typed using STRUCTURE when using the ASSIGN statement.

Note

Field symbols declared using the addition STRUCTURE are a mixture of typed field symbols and a utility for casting structured data types. You should use the additions TYPE or LIKE for the FIELD-SYMBOLS statement to type field symbols, while the addition CASTING of the ASSIGN statement is used for casting.

This is the example:

DATA wa2 TYPE c LENGTH 512.

FIELD-SYMBOLS <scarr2> TYPE scarr.

ASSIGN wa2 TO <scarr2> CASTING.

<scarr2>-carrid = '...'.

Hope this works!

Cheers,

Darshna.