2009 Jun 17 3:42 PM
Hi All,
iam having ITAB1 with 100 records.Moving corresponding fields from itab1 to itab_final.Itab1 and itab_final have different structure.say itab_final is having 20 fields and itab is having 10 fields.when i move corresponding fields from itab1 to itab_final the respective 10 fields are filled with records.rest of fields(say10) itab_final i need to fetch by some select statment and ineed to do modfiy corresponding fields of itab_final.
-
SELECT
KFRST
DATBI
DATAB
KBSTAT
KNUMH FROM A901 INTO TABLE ITAB2
FOR ALL ENTRIES IN ITAB1
WHERE KNUMH = ITAB1-KNUMH.
LOOP AT ITAB2 INTO LS_ITAB2.
ITAB_final-KFRST = LS_ITAB2-KFRST.
ITAB_final-DATBI = LS_ITAB2-DATBI.
MODIFY ITAB_final INDEX SY-INDEX TRANSPORTING KFRST DATBI .
ENDLOOP.
Here My question is how i can find the exact record in itab_final and fill the itab2 field using read statment.
My modfiy statment with sy-index is not modfiy correct row.
Regrads,
Sri
Hi,
Before MODIFYING, you will have to first READ ITAB_FINAL by matching the fields from ITAB2 so that you get the correct record.
If the read is successful then sy-subrc value will be 0 and sy-tabix will contain the particular row number of ITAB_FINAL which you want to modify.
So now you can modify using INDEX as sy-tabix instead of sy-index.
Regards,
Ankur Parab
2009 Jun 17 3:46 PM
Define a work area for itab_final and read that table with the common key fields that you have between those two tables
LOOP AT ITAB2 INTO LS_ITAB2.
*ITAB_final-KFRST = LS_ITAB2-KFRST.
*ITAB_final-DATBI = LS_ITAB2-DATBI.
*MODIFY ITAB_final INDEX SY-INDEX TRANSPORTING KFRST DATBI .
read table itab_final into ls_final with key field1 = ls_itab2-field1
field2 = ls_itab2-field2.
*now
ITAB_final-KFRST = LS_ITAB2-KFRST.
ITAB_final-DATBI = LS_ITAB2-DATBI.
modify itab_final from ls_final.
ENDLOOP.Edited by: riki frisky on Jun 17, 2009 10:47 AM
2009 Jun 17 3:54 PM
Hi Riki,
my itab_final is table type and not having any key fields.So how can i read without key field.
rEGARDS,
sRI
2009 Jun 17 3:58 PM
Check any common fields are ther between the two table Itab and itab_final.
else try this way..
LOOP AT ITAB2 INTO LS_ITAB2.
Read table itab_final into ls_final with key field1 = ls_itab2-field1
field2 = ls_itab2-field2.
If sy-subrc = 0.
ITAB_final-KFRST = LS_ITAB2-KFRST.
ITAB_final-DATBI = LS_ITAB2-DATBI.
modify itab_final from ls_final index sy-tabix TRANSPORTING KFRST DATBI.
ELSE.
Move-corresponding fields of LS_ITAB2 to ITAB_final. "Add this
append.
ENDIF.
ENDLOOP.
2009 Jun 17 3:49 PM
You cannot MODIFY the records in this manner...
Rather what you can do is...instead of LOOPING ITAB2...you can loop ITAB_FINAL and pass the data...
Check below:
LOOP AT ITAB_final ASSIGNING <fs_itab_final>.
* Read the data from ITAB based on some condition...
<fs_itab_final>-field1 = gs_itab-field1.
....................................................
....................................................
ENDLOOP.
* Now no need of modify, since you have used a field symbol
2009 Jun 17 3:53 PM
Sorry got confused by your question.
the solution is as follows.
SELECT
KFRST
DATBI
DATAB
KBSTAT
KNUMH FROM A901 INTO TABLE ITAB2
FOR ALL ENTRIES IN ITAB1
WHERE KNUMH = ITAB1-KNUMH.
loop at itab1 into ls_itab1.
read table itab2 into ls_itab2 with key knumh = ls_itab1-knumh.
ITAB_final-KFRST = LS_ITAB2-KFRST.
ITAB_final-DATBI = LS_ITAB2-DATBI.
move-corresponding ls_itab1 to ls_final.
append ls_final to itab_final.
endloop.This will work, no need of modify statement.
2009 Jun 17 3:56 PM
Hi,
try this way..
Use SY-tabix not Sy-index...
LOOP AT ITAB2 INTO LS_ITAB2.
Read table itab_final into ls_final with key field1 = ls_itab2-field1
field2 = ls_itab2-field2.
If sy-subrc = 0.
ITAB_final-KFRST = LS_ITAB2-KFRST.
ITAB_final-DATBI = LS_ITAB2-DATBI.
modify itab_final from ls_final index sy-tabix TRANSPORTING KFRST DATBI.
ENDIF.
ENDLOOP.
Regards,
Prabhudas
2009 Jun 18 6:03 AM
Hi,
Before MODIFYING, you will have to first READ ITAB_FINAL by matching the fields from ITAB2 so that you get the correct record.
If the read is successful then sy-subrc value will be 0 and sy-tabix will contain the particular row number of ITAB_FINAL which you want to modify.
So now you can modify using INDEX as sy-tabix instead of sy-index.
Regards,
Ankur Parab
2009 Jun 18 6:11 AM
Hi ,
Kinly Chk this,
data:
w_index type i.
LOOP AT ITAB2 INTO LS_ITAB2.
ITAB_final-KFRST = LS_ITAB2-KFRST.
ITAB_final-DATBI = LS_ITAB2-DATBI.
add 1 to w_index.
MODIFY ITAB_final INDEX w_index TRANSPORTING KFRST DATBI .
ENDLOOP.
Regards,
Mdi.Deeba
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |