cancel
Showing results for 
Search instead for 
Did you mean: 

MODIFY COMPONENT of a Structure (of type any)

Hi Friends,

I have two structures: <l_s_data> & <l_s_data2>.

Both are of type "ANY" I would like to modify a particular field's value in the structure: <l_s_data2> based on the keys from another structure: <l_s_data> .

In this example I would like to update the Field: RCOOP value from 9.00 to 8.00

Can anyone please help me achieve this ?

Is there a statement similar to ASSIGN COMPONENT where I would ideally like to write something like this:

MODIFY COMPONENT 'RCOOP' OF STRUCTURE <l_s_data2> to <fs1>

I can get <fs1> value using the statement: ASSIGN COMPONENT 'RCOOP' OF STRUCTURE <l_s_data> to <fs1>.

Please see the screenshot.

FredericGirod
Active Contributor
0 Kudos

You need to provide more informations.

Can we see the code you are using ?

Do you know the structure of the field-symbol ? is it from the ddic ? from a local type ?

Sandra_Rossi
Active Contributor
0 Kudos

Are you asking how to read the line of the internal table based on dynamic key fields? Is your internal table sorted or hashed by the components you mention? Do you have a variable number of key components or is it always 11 components? For more information about dynamic access, look at the ABAP documentation of READ TABLE and of Table Expressions.

0 Kudos

Hi frdric.girod,

Both field symbols (<l_s_data> & <l_s_data2>) are of type: ANY

Below is the slice of my code:

FIELD-SYMBOLS:
<lt_c_th_data>  TYPE HASHED TABLE,
<ls_c_th_data>  TYPE any,
<l_s_data>      TYPE any,
<l_s_data2>     TYPE any,
<fs1> 		TYPE any,
<fs2> 		TYPE any.

* c_th_data is a parameter of type HASHED TABLE

  CREATE DATA l_r_t_data_copy LIKE c_th_data.
  ASSIGN l_r_t_data_copy->* TO <lt_c_th_data>.
  <lt_c_th_data>  = c_th_data.

LOOP AT <lt_c_th_data> into <ls_c_th_data>.
   MOVE-CORRESPONDING <ls_c_th_data> TO <l_s_data2>.
   ASSIGN COMPONENT 'RCOOP' OF STRUCTURE <l_s_data>  to <fs1>.
   ASSIGN COMPONENT 'RCOOP' OF STRUCTURE <l_s_data2> to <fs2>.

* Below is not correct syntax but ideally this is what I would like to do
   MODIFY COMPONENT 'RCOOP' OF STRUCTURE <l_s_data2> to <fs1>

ENDLOOP.


* Below doesn't work for me because it updates ALL key figures (i.e. non Key fields) from * <l_s_data> and not just the field: RCOOP
MODIFY TABLE c_th_data FROM <l_s_data>. 

Tomas_Buryanek
Active Contributor
0 Kudos

How do you identify which fields are key?

0 Kudos

Hi sandra.rossi

Here are my responses to your questions:

My internal table is Hashed.

Yes, I want to modify a line of my Hashed table (<l_s_data2>, but ONLY FOR ONE non-key Field (ex. RCOOP) based on the key fields of another Hashed table (<l_s_data>).

Yes, I will have variable number of key components (it's just those 11 in this scenario I've run)

Thanks!

Hi Tomas Buryanek

The keys are determined by the standard incoming hash table c_th_data (defined by SAP standard objects)

I just declare my internal hash tables (ex. <lt_c_th_data>) based on c_th_data

FredericGirod
Active Contributor
0 Kudos

I don't understand what you are trying to perform with your statement.

is this not working ?

FIELD-SYMBOLS:
<lt_c_th_data>  TYPE HASHED TABLE,
<ls_c_th_data>  TYPE any,
<l_s_data>      TYPE any,
<l_s_data2>     TYPE any,
<fs1> 		TYPE any,
<fs2> 		TYPE any.

* c_th_data is a parameter of type HASHED TABLE

  CREATE DATA l_r_t_data_copy LIKE c_th_data.
  ASSIGN l_r_t_data_copy->* TO <lt_c_th_data>.
  <lt_c_th_data>  = c_th_data.

LOOP AT <lt_c_th_data> into <ls_c_th_data>.
   MOVE-CORRESPONDING <ls_c_th_data> TO <l_s_data2>.
   ASSIGN COMPONENT 'RCOOP' OF STRUCTURE <l_s_data>  to <fs1>.
   ASSIGN COMPONENT 'RCOOP' OF STRUCTURE <l_s_data2> to <fs2>.

* Below is not correct syntax but ideally this is what I would like to do
   <fs2> = <fs1>.

ENDLOOP.


* Below doesn't work for me because it updates ALL key figures (i.e. non Key fields) from * <l_s_data> and not just the field: RCOOP
MODIFY TABLE c_th_data FROM <l_s_data>. 
stanislaslemaire
Participant
0 Kudos

Hello,
as fields symbols for structure are declared as ANY, cannot use named component to access it. Instead use ASSIGN COMPONENT 12 OF STRUCTURE <...> (RCOOP is at position 12 in structure).
But I guess I don't understand very well your issue...

0 Kudos

Hi Frederic Girod

<fs2> = <fs1>. - This doesn't work, because they only contains the field value (ex. 8.00).

I want to be able to change the RCOOP field value (to 8.00) in the original structure: <l_s_data2>

See the screenshot from my debugger:

FredericGirod
Active Contributor

Sorry I don't understand

<fs2> should have exactly the same content as <l_s_data2>-RCOOP

because fs2 is pointing to this field.

Could you in your debug display the content of the <l_s_data2> structure ?

Sandra_Rossi
Active Contributor

venkatasreekar.krothapalli, I think you should listen to Frederic Girod and try what he tells you.

0 Kudos

Hi Frederic Girod

Since I assigned the component RCOOP (stays in my variable lv_kf) of strucutre <l_s_data2>, <fs1> only contains the value 8.00.

You can see the content of <l_s_data2> structure in my original post's screenshot.

Sandra_Rossi
Active Contributor
0 Kudos

Endless discussion, that would end up with "please do <fs_2> = <fs_1>" as Gaurav proposed initially.

And you replied: "My requirement is to get the entire structure with all the fields. (as shown in below screenshot) with the required field (RCOOP) value only to be changed to 8.00"

But I don't (and nobody, it seems) understand what you want to achieve. You should better ask in a different way.

DoanManhQuynh
Active Contributor

so i think people answers you all, i just want to try to convince you one more time 🙂 :

when you want to modify one or few components in a structure with generic type (any), you would have to use field symbols to point to that component. so when you change value of a pointer (field symbols) the value of component of original structure also changed without any explicit MODIFY COMPONENT as what you said. it's just simple as it is:

ASSIGN structure-component TO <pointer>.
<pointer> = any value. "at this point the original component value changed.
View Entire Topic
Sandra_Rossi
Active Contributor

Not sure what you are asking exactly. Maybe how to read a line of a dynamic internal table based on its primary key made of a variable number of components, in that case use READ TABLE <itab> FROM <wa>:

DATA: scarr_s   TYPE SORTED TABLE OF scarr WITH UNIQUE KEY carrid,
      scarr_key TYPE scarr.
FIELD-SYMBOLS:
  <dyn_key>  TYPE any,
  <dyn_itab> TYPE SORTED TABLE.

scarr_s = VALUE #(
  ( carrid = 'QA' carrname = 'Qatar Airways' )
  ( carrid = 'LH' carrname = 'Lufthansa' )
  ( carrid = 'AF' carrname = 'Air France' ) ).
scarr_key-carrid = 'LH'.

ASSIGN scarr_s TO <dyn_itab>.
ASSIGN scarr_key TO <dyn_key>.

READ TABLE <dyn_itab> FROM <dyn_key> ASSIGNING FIELD-SYMBOL(<dyn_wa>).
ASSERT sy-subrc = 0.

ASSIGN COMPONENT 'CARRNAME' OF STRUCTURE <dyn_wa> TO FIELD-SYMBOL(<dyn_field>).
<dyn_field> = 'LUFTHANSA'.

ASSERT scarr_s[ carrid = 'LH' ]-carrname = 'LUFTHANSA'.
0 Kudos

Hi sandra.rossi

Let me explain it a little differently.

In my Class, I receive the incoming data in a Hashed Table called: c_th_data. The structure of this table will vary depending on the run. FYI, this Class is used by a BW-IP file upload functionality.

In my current run you can see the data in the table: c_th_data as shown in the below screenshot.

< Screenshot 1 >

My goal is to manipulate the highlighted (in yellow) record based on the structure: <L_S_DATA> but ONLY FOR A DESIRED FIELD (in this example RCOOP)

<L_S_DATA> looks like in the below screenshot:

< Screenshot 2 >

However if I use the below statement, it modifies the entire record as shown in the screenshot that follows:

MODIFY TABLE c_th_data FROM <l_s_data>. 

< Screenshot 3 >

Note: the keys in this example are the first 11 chars. But this will change based on the execution.

<l_s_data> is defined and populated as shown below:

FIELD-SYMBOLS:
<l_s_data>        TYPE any.
* Create field-symbol for InfoProvider data
  CREATE DATA n_r_data LIKE LINE OF c_th_data.
  ASSIGN n_r_data->* TO <l_s_data>.

LOOP AT <l_t_file_2> ASSIGNING <l_s_file_2>.
	MOVE-CORRESPONDING <l_s_file_2> TO <l_s_data>.
	MODIFY TABLE c_th_data FROM <l_s_data>. 
"This MODIFY statement doesn't do the job as it modifies all the key figure (non-key) values based on <l_s_data>
ENDLOOP.

I hope I'm clear with the requirement this time?

Thanks very much for helping out,

Regards,

PS - Sorry I'm attaching the 3 screenshots separately as it doesn't allow me to add all 3 screenshots in one post (probably size issues)

0 Kudos

Screenshot 1:

0 Kudos

Screenshot 2:

0 Kudos

Screenshot 3:

Sandra_Rossi
Active Contributor
0 Kudos

I'm sorry again, it seems that there's something you don't understand in all our answers, maybe you don't understand what a field symbol is, it's a pointer to any data object, dynamic or static, changing the field symbol means changing the data object.

So, if the field symbol points to RCOOP, only RCOOP will be changed.

You can run my example and debug it. I think it conforms all your expectations. Field symbols are defined as if the internal table was dynamic with a sorted key (I could have used a hashed key too, it would work). I used CARRNAME to mimic RCOOP. Only CARRNAME is changed, other fields are not changed.

But you don't provide an example one can run, so nobody understands and no body can try with a real case. Can't you make a standalone example that we can run?

0 Kudos

I cannot explain with any simpler example. But that's okay, I've found a work around .. still using field symbols. Also your code doesn't suit my case.

Thanks for your inputs anyway.

Sandra_Rossi
Active Contributor
0 Kudos

OK. That will remain a mysterious question then... 🙂