04-04-2013 6:41 PM
Hello All,
I am working on a requirement, where there a table declared as below:
t_data type lfa1.
this table has some data in it, now I need to change only one field of t_data based on some validation. I tried teh following approach but it didn't work:
it_data = t_data.
read table it_data into wa_data with key lifnr = '100100'.
if sy-subrc = 0.
wa_data-nam1 = 'TEST'.
append wa_data to it_data.
t_data = it_data.
but when i executed the above code I am getting the error message... can anyone please help me with this.
Thank you.
04-05-2013 8:33 AM
In addition to what others have been saying, you can use a field symbol in the READ statement and then you don't even have to use the MODIFY statement. As is the case with field symbols, when you assign a value to them, the value would automatically be changed in the data object to which the field symbol is assigned.
Sample:
READ TABLE it_data ASSIGNING <fs_data> WITH KEY lifnr = '100100' TRANSPORTING nam1.
IF <fs_data> IS ASSIGNED.
<fs_data>-nam1 = 'TEST'.
ENDIF.
04-04-2013 7:08 PM
Hi Rahul,
You would need to use MODIFY instead (APPEND would attempt to create a new entry in your internal table), as following:
MODIFY it_data INDEX sy-tabix FROM wa_data TRANSPORTING nam1.
Guess it will work.
Regards,
Edgar
04-04-2013 8:35 PM
Thanks for the reply... but when I tried the above logic... I got the below error:
it_data is not an internal table.
04-04-2013 8:36 PM
in my case it_data is an exporting parameter of a function module and is declared as
it_data type lfa1.
04-05-2013 5:11 AM
Ahhhh...as expected.
The function module is expecting a structure to be returned and not a table.
You just need an if statement in that function module to check
if it_data-lifnr = '100100'.
it_data-nam1 = 'TEST'.
endif.
** However, I do doubt if there is any data in it_data since it is an exporting parameter **
If you still want to go down the road where it should be a table. Then change the FM parameters, remove it_data from exporting parameter and put it under the tables tab.
Best regards,
Brian
04-05-2013 5:19 AM
Okay, so it_data is not declared as an internal table what I presume is wrong (once you also have READ and APPEND, in case should be MODIFY, in your program. Try to declare it_data as following:
data: it_data type table of lfa1 occurs 0.
But a question about t_data that is also declared as a working area, what it's intended to? You have a single line there or expects to have more? Could you share all your code over here?
04-05-2013 5:28 AM
Sorry, haven't read all the current thread, got it now.
Your code would be more simpler:
it_data = t_data.
IF it_data-lifnr = '100100'.
it_data-nam1 = 'TEST'.
ENDIF.
In addition would you give you, if you allow me, to suggest you to not use prefixes like 'it_', what is usual for internal tables, for simple structures once it could give some wrong meaning.
04-05-2013 6:06 AM
Hi Rahul,
IT_DATA should be declared as :
IT_data type TABLE of lfa1,
Similarly for T_DATA as :
T_DATA type TABLE of lfa1.
Hope it helps.
Thanks
04-05-2013 7:14 AM
we cannot modify internal table from workarea of another internal table, which means we can modify an internal table with its own type workarea.
(please correct me, if i am wrong )
you may try this,:
*******DECLARING STRUCTURE************
TYPES: BEGIN OF IT_DATA_STRUCT,
LIFNR TYPE LFA1-LIFNR,
NAME1 TYPE LFA1-NAME1,
END OF IT_DATA_STRUCT.
*********************DECLARING WORK AREA AND INTERNAL TABLE***********
DATA: IT_DATA TYPE STANDARD TABLE OF IT_DATA_STRUCT,
WA_DATA TYPE IT_DATA_STRUCT,
TABIX_COUNT TYPE SY-TABIX. " variable type data.
********************Now the reading part*******************
SELECT LIFNR NAME1 FROM LFA1 INTO TABLE IT_DATA
WHERE LIFNR = '100100'.
**********************
LOOP AT T_DATA INTO W_DATA .
TABIX_COUNT = sy-tabix.
("Please note T_DATA is the destination internal table - where """""""""""you are trying to finally import data.**************)
READ TABLE IT_DATA INTO WA_DATA WITH KEY lifnr = '100100'.
IF SY-SUBRC = 0.
IF W_DATA- lifnr = WA_DATA-lifnr.
W_DATA-NAME1 = WA_DATA-NAME1.
MODIFY T_DATA INDEX TABIX_COUNT FROM wa_data TRANSPORTING name1.
ENDIF.
ENDIF.
ENDLOOP.
Regards,
Khushboo Singh.
Message was edited by: Khushboo Singh
Message was edited by: Khushboo Singh
04-04-2013 8:21 PM
Hello Rahul,
As suggested by Edgar, You need to modify either table. Before Modifying also check whether there are some duplicate entries are present or not.
Regards,
Sudhir Kothavale.
04-04-2013 8:44 PM
hello,
you could try this -
sflight_wa-planetype = p_plane2.
MODIFY sflight_tab FROM sflight_wa
TRANSPORTING planetype WHERE planetype = p_plane1.
* planetpye is the field you need to modify with new value.
*** where planetype = p_plane1. is your condition for updating the itab.
This way the internal table will be updated for all lines where the condition is satisfying and it will update only the field you need it to update.
best regards,
swanand
04-04-2013 9:55 PM
Hi,
I think that you solve your issue in this way:
data s_tabix like sy-tabix.
loop at t_data.
s_tabix = sy-tabix.
if t_data-lifnr eq '100100'.
t_data-name1 = 'TEST'.
modify t_data index s_tabix trasporting name1.
endif.
endloop.
Regards
Ivan
04-05-2013 2:54 AM
I'm quite interested on what error you are getting. Can you share the error message?
The reason I say this is because the way t_data is declared, it don't seem to be a table. Unless of course, lfa1 is a table type.
Please share the error message.
Best regards,
Brian
04-05-2013 5:33 AM
Hi,
Kindly check the below code.
Data: i_lfa1 type table of lfa1,
w_lfa1 type lfa1.
read table i_lfa1 into w_lfa1 with key lifnr = '100100'.
if sy-subrc = 0.
w_lfa1-nam1 = 'TEST'.
modify i_lfa1 from w_lfa1 INDEX sy-tabix.
endif.
04-05-2013 8:33 AM
In addition to what others have been saying, you can use a field symbol in the READ statement and then you don't even have to use the MODIFY statement. As is the case with field symbols, when you assign a value to them, the value would automatically be changed in the data object to which the field symbol is assigned.
Sample:
READ TABLE it_data ASSIGNING <fs_data> WITH KEY lifnr = '100100' TRANSPORTING nam1.
IF <fs_data> IS ASSIGNED.
<fs_data>-nam1 = 'TEST'.
ENDIF.
04-05-2013 10:59 AM
Hi Rahul,
As you wnated to change the content of one pertucular field, you can follow the below steps.
1. Loop at the internal table t_data.
1.1. Do validations of your choice.
1.1.1. if the validation success change the contents of the pertucular column of the work area.
1.2. Now modify the content of the internal table using contents of the workarea.
1.3 Loop will modify content for all records.
CODE:
LOOP AT t_data INTO x_data.
*--Start of your validation
IF x_data-lifnr EQ '100100'.
*--If the validation success, Modify the comtent
x_data-nam1 = 'TEST'.
*--As the modufy statement is inside the LOOP no need to mention INDEX in syntax
MODIFY t_data FROM x_data TRANSPORTING nam1.
ENDIF.
CLEAR: x_data.
ENDLOOP.
In the above code, you can include the validation of your choice. If the validation is success you can modify the content using above MODIFY statement.
Instead of above MODIFY statement, you can also use
MODIFY t_data FROM x_data.
Hope this will solve your problem.
Thanks & Regards,
Venugopal M N
04-05-2013 11:02 AM
Hi Rahul,
Greetings!
It will give you error where you have written t_data = it_data because
the both are referring to structures i.e. one you have declared and the
other in your exporting parameters.
Instead you can create table type of lfa1 and assign that table type instead of lfa1.
Change it_lfa1 from exporting parameters to table.
Thankyou.
Best Regards,
Varun Deshpande.
04-05-2013 11:40 AM
Hi Rahul,
Use Modify statement instead of append.
Since you are modifying the record Modify will be helpful and append is used for adding a new record to your internal table.
read table it_data into wa_data with key lifnr = '100100'.
if sy-subrc = 0.
wa_data-nam1 = 'TEST'.
modify it_data from wa_data.
endif.