2012 May 03 7:58 AM
form create_hierarchy.
data: ls_sflight type sflight,
lt_sflight type sflight occurs 0,
l_yyyymm(6) type c, "year and month of sflight-fldate
l_yyyymm_last(6) type c,
l_carrid like sflight-carrid,
l_carrid_last like sflight-carrid.
data: l_month_key type lvc_nkey,
l_carrid_key type lvc_nkey,
l_last_key type lvc_nkey.
* §4a. Select data
select * from sflight into table lt_sflight up to g_max rows.
* §4b. Sort output table according to your conceived hierarchy
* We sort in this order:
* year and month (top level nodes, yyyymm of DATS)
* carrier id (next level)
* day of month (leaves, dd of DATS)
sort lt_sflight by fldate+0(6) carrid fldate+6(2).
* Note: The top level nodes do not correspond to a field of the
* output table. Instead we use data of the table to invent another
* hierarchy level above the levels that can be build by sorting.
* §4c. Add data to tree
loop at lt_sflight into ls_sflight.
* Prerequesite: The table is sorted.
* You add a node everytime the values of a sorted field changes.
* Finally, the complete line is added as a leaf below the last
* node.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
* Top level nodes:
if l_yyyymm <> l_yyyymm_last. "on change of l_yyyymm
l_yyyymm_last = l_yyyymm.
*Providing no key means that the node is added on top level:
perform add_month using l_yyyymm
''
changing l_month_key.
* The month changed, thus, there is no predecessor carrier
clear l_carrid_last.
endif.
* Carrier nodes:
* (always inserted as child of the last month
* which is identified by 'l_month_key')
if l_carrid <> l_carrid_last. "on change of l_carrid
l_carrid_last = l_carrid.
perform add_carrid_line using ls_sflight
l_month_key
changing l_carrid_key.
endif.
* Leaf:
* (always inserted as child of the last carrier
* which is identified by 'l_carrid_key')
perform add_complete_line using ls_sflight
l_carrid_key
changing l_last_key.
endloop.
endform. " create_hierarchyThis program is BCALV_TREE_01.
Anyone mind explain how create hierarchy works?
How §4b works?? Is that really sorting the whole table?
§4c is adding data to the tree, but I dont understand how it determine which is the leaf node or top level node.
Please advice.
Thanks,
Wong
form create_hierarchy.
data: ls_sflight type sflight,
lt_sflight type sflight occurs 0,
l_yyyymm(6) type c, "year and month of sflight-fldate
l_yyyymm_last(6) type c,
l_carrid like sflight-carrid,
l_carrid_last like sflight-carrid.
data: l_month_key type lvc_nkey,
l_carrid_key type lvc_nkey,
l_last_key type lvc_nkey.
* §4a. Select data
select * from sflight into table lt_sflight up to g_max rows.
* §4b. Sort output table according to your conceived hierarchy
* We sort in this order:
* year and month (top level nodes, yyyymm of DATS)
* carrier id (next level)
* day of month (leaves, dd of DATS)
sort lt_sflight by fldate+0(6) carrid fldate+6(2).
* Note: The top level nodes do not correspond to a field of the
* output table. Instead we use data of the table to invent another
* hierarchy level above the levels that can be build by sorting.
* §4c. Add data to tree
loop at lt_sflight into ls_sflight.
* Prerequesite: The table is sorted.
* You add a node everytime the values of a sorted field changes.
* Finally, the complete line is added as a leaf below the last
* node.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
* Top level nodes:
if l_yyyymm <> l_yyyymm_last. "on change of l_yyyymm
l_yyyymm_last = l_yyyymm.
*Providing no key means that the node is added on top level:
perform add_month using l_yyyymm
''
changing l_month_key.
* The month changed, thus, there is no predecessor carrier
clear l_carrid_last.
endif.
* Carrier nodes:
* (always inserted as child of the last month
* which is identified by 'l_month_key')
if l_carrid <> l_carrid_last. "on change of l_carrid
l_carrid_last = l_carrid.
perform add_carrid_line using ls_sflight
l_month_key
changing l_carrid_key.
endif.
* Leaf:
* (always inserted as child of the last carrier
* which is identified by 'l_carrid_key')
perform add_complete_line using ls_sflight
l_carrid_key
changing l_last_key.
endloop.
endform. " create_hierarchyThis program is BCALV_TREE_01.
Anyone mind explain how create hierarchy works?
How §4b works?? Is that really sorting the whole table?
§4c is adding data to the tree, but I dont understand how it determine which is the leaf node or top level node.
Please advice.
Thanks,
Wong
2012 May 03 9:33 AM
2012 May 03 9:34 AM
Hi,
Well, everything is described in comments... What is that you don't understand??
* Prerequesite: The table is sorted.
* You add a node everytime the values of a sorted field changes.
* Finally, the complete line is added as a leaf below the last
* node.
* Top level nodes ---> "on change of l_yyyymm
*Providing no key means that the node is added on top level:
* The month changed, thus, there is no predecessor carrier
* Carrier nodes:
* (always inserted as child of the last month
* which is identified by 'l_month_key')
* Leaf:
* (always inserted as child of the last carrier
* which is identified by 'l_carrid_key')
Cheers,
Manu.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |