05-28-2008 10:47 AM
How to divide the internal table itab for the months?
I have a field data in internal table itab and now i have need to divide itab in n table for months.
The data interval is max 4 months.
Sorry for my english.
ex. itab.
data: begin of itab occurs 0,
data LIKE vbak-erdat,
num_ord LIKE vbap-vbeln,
gruppo LIKE mara-labor,
end of itab.
05-28-2008 11:02 AM
create another internal table where you put months
then loop at table of months and process related entries in your data table
this is easy because you have your date field so you can check that date is part of month
05-28-2008 12:50 PM
I have solved in this method:
SORT tab_gia DESCENDING BY data.
tmp_mese = tab_gia-data+4(2).
LOOP AT tab_gia.
IF tmp_mese EQ tab_gia-data+4(2).
IF flag1 = 'TRUE'.
MOVE tab_gia-data TO mese1-data.
MOVE tab_gia-gruppo TO mese1-gruppo.
MOVE tab_gia-tipo TO mese1-tipo.
MOVE tab_gia-matnr TO mese1-matnr.
MOVE tab_gia-giacenza TO mese1-giacenza.
APPEND mese1.
ENDIF.
IF flag2 EQ 'TRUE'.
MOVE tab_gia-data TO mese2-data.
MOVE tab_gia-gruppo TO mese2-gruppo.
MOVE tab_gia-tipo TO mese2-tipo.
MOVE tab_gia-matnr TO mese2-matnr.
MOVE tab_gia-giacenza TO mese2-giacenza.
APPEND mese2.
ENDIF.
IF flag3 EQ 'TRUE'.
MOVE tab_gia-data TO mese3-data.
MOVE tab_gia-gruppo TO mese3-gruppo.
MOVE tab_gia-tipo TO mese3-tipo.
MOVE tab_gia-matnr TO mese3-matnr.
MOVE tab_gia-giacenza TO mese3-giacenza.
APPEND mese3.
ENDIF.
IF flag4 EQ 'TRUE'.
MOVE tab_gia-data TO mese4-data.
MOVE tab_gia-gruppo TO mese4-gruppo.
MOVE tab_gia-tipo TO mese4-tipo.
MOVE tab_gia-matnr TO mese4-matnr.
MOVE tab_gia-giacenza TO mese4-giacenza.
APPEND mese4.
ENDIF.
ELSE.
* trovato un altro mese.
cnt = cnt + 1.
tmp_mese = tab_gia-data+4(2).
CASE cnt.
WHEN 2.
flag1 = 'FALSE'.
flag2 = 'TRUE'.
WHEN 3.
flag2 = 'FALSE'.
flag3 = 'TRUE'.
WHEN 4.
flag3 = 'FALSE'.
flag4 = 'TRUE'.
ENDCASE.
ENDIF.
ENDLOOP.
thanks!!!
Edited by: Alfonso Manzo on May 28, 2008 1:51 PM
Edited by: Alfonso Manzo on May 28, 2008 1:52 PM
05-28-2008 12:57 PM
You can define an internal table within an internal table.
This example may help.
data:
begin of period_rec,
month_amount type i,
end of period_rec.
data:
begin of itab occurs 0,
pernr like pa0001-pernr,
total type i,
period_tab like standard table of period_rec,
end of itab occurs 0.
to access the imbedded internal table..
loop at itab.
loop at itab-period_tab into period_rec.
* Do Stuff
modify itab-period_tab from period_rec.
endloop.
endloop.
Edited by: Paul Chapman on May 28, 2008 7:58 AM