08-19-2008 3:35 PM
Hi All,
I have an internal table in which i want to store every alternative pass in another variable. for example for the first pass i want to store in var1, second pass i want to store in var2, again the 3rd pass will go into var1 and 4 th pass will have to go in var2. I mean all the odd passes has to go in var1 and even passes has to go in var2.
is there any logic using loop at or some thing else.
Thanks in advance
08-19-2008 3:41 PM
Hi,
Here is the code.
DATA:
W_REMAINDER LIKE SY-TABIX.
LOOP AT ITAB.
W_REMAINDER = SY-TABIX MOD 3.
CASE W_REMAINDER.
WHEN 1.
W_TEMP = W_VAR1.
WHEN 2.
W_TEMP = W_VAR2.
WHEN 3.
W_TEMP = W_VAR3.
ENDCASE.
ENDLOOP.
Regards,
Rama Chary.Pammi
08-19-2008 3:41 PM
He said every alternate one - not every third one.
data: l_flipflop type i.
l_flipflop = 1.
loop at my_tab into my_wa.
IF l_flipflop EQ '1'.
cumulate into Var1.
ELSE.
cumulate into Var2.
ENDIF.
l_flipflop = 0 - l_flipflop.
endloop
08-19-2008 3:43 PM
Hello,
You might try something like.
loop at it_mtab into is_mytab.
if sy-tabix mod 2 = 0 " ( sy-tabix is even)
var1 = is_mytab-var.
else.
var2 = is_mytab-var.
endif.
endloop.
Regards
Greg Kern
08-19-2008 3:44 PM
Neater than my solution - for standard tables. But it won't work for non-indexed tables like HASHED tables, cos they don't update sy-tabix.
08-19-2008 3:44 PM
Try this way...
loop at itab1.
g_temp = sy-index mod 2. (check syntax)
if g_temp = 0.
move data to val1 and append.
else.
move data to val2 and append.
endif.
endloop.
08-19-2008 3:46 PM
Try something like this:
TYPES: BEGIN OF TY_DATA,
VBELN TYPE VBELN,
FIELD TYPE CHAR10,
END OF TY_DATA.
TYPES: BEGIN OF TY_TAB,
VBELN TYPE VBELN,
FIELD1 TYPE CHAR10,
FIELD2 TYPE CHAR10,
END OF TY_TAB.
DATA: T_DATA TYPE STANDARD TABLE OF TY_DATA,
T_TAB TYPE STANDARD TABLE OF TY_TAB,
WA_DATA TYPE TY_DATA,
WA_TAB TYPE TY_TAB.
DO 6 TIMES.
WA_DATA-VBELN = SY-ABCDE+0(5).
WA_DATA-FIELD = SY-INDEX.
APPEND WA_DATA TO T_DATA.
ENDDO .
DATA: L_CNT TYPE I,
L_DONE TYPE C.
LOOP AT T_DATA INTO WA_DATA.
L_CNT = L_CNT + 1.
CLEAR L_DONE.
CASE L_CNT.
WHEN 1.
WA_TAB-VBELN = WA_DATA-VBELN.
WA_TAB-FIELD1 = WA_DATA-FIELD.
WHEN 2.
WA_TAB-FIELD2 = WA_DATA-FIELD.
APPEND WA_TAB TO T_TAB.
CLEAR L_CNT.
L_DONE = 'X'.
ENDCASE.
AT LAST.
IF L_DONE IS INITIAL.
APPEND WA_TAB TO T_TAB.
ENDIF.
ENDAT.
ENDLOOP.
Regards,
Naimesh Patel