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: 

Assigning value to Field - Symbol ( which is type of internal table field )

0 Kudos

Hi All,

I am facing problem to assign the value to a field symbol. My requirement is creating a dynamic internal table and populate values into that internal table, so that i can display the values .

I am having a structure with fields like status , Plant1 name , Plant2 name.....Plant n .

So i declared an internal table it_tab with this structure.

I am having one more table which having number of records for Plant1 ,Plant 2 ,....Plant n based on some condition.

I need to count the number of records for Plant1 and i need to put in the internal table it_tab.

For this i created field-symbol .

Here, t_deployment table will have the plants 1,2,3...and

t_devobject will have some records for these plants.

LOOP AT T_DEPLOYMENT.

clear w_count.

LOOP AT T_DEVOBJECT WHERE ZDEPLOYMENT = T_DEPLOYMENT-DOMVALUE_L AND

ZADSTATUS = '10'.

w_count = w_count + 1.

ENDLOOP.

concatenate 'it_tab-' t_deployment-domvalue_l into var_bet_name.

assign var_bet_name to <bet_var_name>.

now my internal table field i.e. it_tab-plant1 came into <bet_var_name> . But i want to assign a value for it.

at last what i need is it_tab-plant1 = w_count.

whaterver the w_count has value that needs to assign to it_tab-plant1. But i don't want to assign directly it it_tab-plant1. I want to assign dynamically. Because tommorrow some more plants added to t_deployments , i don't want to make changes to my program. It should take care....w/o changing the program.

I tried the following statement.

(<bet_var_name>) = w_count. But its not working.

Please let me know how i can get this.

Thanks in Advance.

Pavan.

1 ACCEPTED SOLUTION

athavanraja
Active Contributor
0 Kudos

Welcome to SDN.

try this sample code.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <ltable> TYPE ANY TABLE,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

DATA: wf_fldnm(40) .

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

  • Create a new Line with the same structure of the table.

ASSIGN new_table->* TO <ltable>.

CREATE DATA new_line LIKE LINE OF <ltable>.

ASSIGN new_line->* TO <l_line>.

loop at itab .

ASSIGN COMPONENT [fieldname to which the value needs to be assigned] OF STRUCTURE <l_line> TO <l_field>.

<l_field> = wa_set-chavl_ext .

INSERT <l_line> INTO TABLE <ltable>.

endloop .

Regards

Raja

3 REPLIES 3

hymavathi_oruganti
Active Contributor
0 Kudos

Hi pavan,

As ur requirement is creating a dynamic internal table,

try the following way,

remember the fieldcat should be of type LVC not SLIS.

BUILD LT_LVCFIELDCAT in a way that, the value from the internal table becomes the fieldname

ex:-

loop at it_models INTO WA_MODELS.

LS_LVCFIELDCAT-FIELDNAME = WA_models-MODEL.

LS_LVCFIELDCAT-SELTEXT = WA_models-MODEL.

append ls_lvcfieldcat to lt_lvcfieldcat.

endloop.

DATA: DREF TYPE REF TO DATA,WA_REF TYPE REF TO DATA.

FIELD-SYMBOLS: <TEMP_TAB> TYPE TABLE, <TEMP_WA> TYPE ANY.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVCFIELDCAT

IMPORTING

EP_TABLE = DREF.

ASSIGN dref->* TO <TEMP_TAB>.

now basing on the fieldcatalog <temp_tab> is build.

NOW FILL <TEMP_TAB>.

WHILE FILLING, ASSIGN COMPONENT IDX/NAME.....

this statement will be very usefull.

i hope this will be help full.

pls reward the points if it helps u.

regards

Hyma

athavanraja
Active Contributor
0 Kudos

Welcome to SDN.

try this sample code.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <ltable> TYPE ANY TABLE,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

DATA: wf_fldnm(40) .

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

  • Create a new Line with the same structure of the table.

ASSIGN new_table->* TO <ltable>.

CREATE DATA new_line LIKE LINE OF <ltable>.

ASSIGN new_line->* TO <l_line>.

loop at itab .

ASSIGN COMPONENT [fieldname to which the value needs to be assigned] OF STRUCTURE <l_line> TO <l_field>.

<l_field> = wa_set-chavl_ext .

INSERT <l_line> INTO TABLE <ltable>.

endloop .

Regards

Raja

0 Kudos

Hyma & Raja,

Its working fine..Thanks for your quick and prompt reply.

Thanks a Lot! It solved my problem.

Regards,

Pavan.