Skip to Content
0
Nov 18, 2008 at 02:15 PM

itab like array: how to shift rows ?

226 Views

Hi all, first of all, sorry if this post may result "tricky", can't find a way to formulate it better...

I created an internal tab and wanted to manage in as a static (bidimensional) array. Fields of my table are labeled as follows:

||row_id| COL100 | COL101 | ... | COL 130 ||

,

where row_id type i and COLx type CHAR1.

I created an itab with, say, 100 rows (row_id, which is my key, goes for example from 141 to 240).

Well, I'd like to code this behaviour and ask you an hint/suggestion on how to do it:

"if a row Z has every COLx field marked with 'Y', then:

- shift down any row that precede (e.g., rows having row_id < row_id of row Z) row Z by 1.

Example: status of the table BEFORE condition evaluation:

||row_id|COL100|COL101|COL102|COL103|COL104||
-------------------------------------------------------------------------------------
||   4    |     O    |     Y     |     Y     |     O    |     O     ||
||   5    |     Y    |     Y     |     O     |     O    |     O     ||
||   6    |     O    |     Y     |     Y     |     O    |     Y     ||
||   7    |     Y    |     Y     |     Y     |     Y     |     Y     || "this is the line that satisfies the condition...
||   8    |     O    |     Y     |     Y     |    O     |     O     ||

status of the table AFTER condition evaluation:

||row_id|COL100|COL101|COL102|COL103|COL104||
-------------------------------------------------------------------------------------
||   4    |    _      |     _     |     _     |     _     |     _     ||
||   5    |    O     |     Y     |     Y    |     O    |     O     ||
||   6    |    Y     |     Y     |     O    |     O    |     O     ||
||   7    |    O     |     Y     |     Y    |     O    |     Y     ||row 7 has now same field values of the old row 6
||   8    |    O     |     Y     |     Y    |     O    |     O     ||

I'm wondering if there's an easy way to do this; I can easy check for a "full line" LOOPing AT mytbl INTO wa_mytbl and comparing it with a full line (well, except for row_id, field by field). But then? I should loop in reverse order and copy the precedent row into the current one, till the top of the table is reached (and, of course, mantaining the row_id). Can anybody help me thinking a solution? Thanks in advance.

Edited by: Matteo Montalto on Nov 18, 2008 3:16 PM