on 01-17-2020 8:13 AM
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.
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'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
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?
User | Count |
---|---|
71 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.