05-30-2009 9:08 PM
I am creating an archiving report in PS module.
I have a table RPSCO .My requirement is to compare the year in the two rows ,if they are identical move it to a new internal table Otherwise delete the entries.How to do that.
Objnr YEAR
PR00002409 2002 KSTP 0 0
PR00002409 2002 KOAO 0 0
05-31-2009 6:57 AM
Hi,
First check the below:
itab is internal table having below fields:
Objnr YEAR
PR00002409 2002 KSTP 0 0
PR00002409 2002 KOAO 0 0
Loop at itab
lv_tabix = sy-tabix. " Assign line number
if lv_tabix = 1 " First Line of the internal table
move into a workarea/variables1
endif.
if lv_-tabix = 2 " Second line of the internal table
move into a workarea/variables2
Now check the variables/workareas
if variable1 NE variable2
--- do ur validation
endif
clear lv_tabix. " Since you need to check two lines/subsequent records.
endif.
endloop.
Hope this helps
Regards
Shiva
05-31-2009 11:49 AM
Hi,
Try like this.
LOOP AT itab INTO wa.
DELETE itab FROM wa.
IF sy-tabix GT 1.
CLEAR wa1.
READ TABLE itab INTO wa WITH KEY year = wa-year.
IF sy-subrc IS INITIAL.
APPEND wa1 TO itab1.
ENDIF.
ELSE.
APPEND wa1 TO itab1.
ENDIF.
ENDLOOP.
Thanks,
Vinod.
05-31-2009 12:14 PM
Hi,
If the structure of the internal table is defined, then you can check the fields and delete any one row if they are equal, or move it into another internal table.
Code like this.
Data : flag type c value u2018Xu2019.
Also declare wa_temp and itab_temp as itab.
Loop at itab into wa.
If flag = u2018Xu2019
move wa into wa_temp.
clear flag.
Continue.
Endif.
If Wa_temp-field1 = wa-field1
And wa_temp-field2 = wa_field2
And -
-
Move wa_temp into itab_temp
append itab_temp
Clear wa_temp.
Endif.
Flag = u2018Xu2019.
Endloop.
This will definitely solve your problem. Check for correct syntax.
All the best.
Regards
Ramesh Sundaram