Posted By

qrist0ph on 08/26/10


Tagged

graph abap


Versions (?)

PD-Org nach GraphViz


 / Published in: Other
 

  1. REPORT zca_export .
  2.  
  3. DATA export TYPE cacs_s_vers1.
  4.  
  5. TYPES: BEGIN OF export,
  6. verion TYPE cacs_ctrtbu-version,
  7. busi_begin TYPE cacs_s_vers1-busi_begin,
  8. busi_end TYPE cacs_s_vers1-busi_end,
  9. tech_begin TYPE cacs_s_vers1-tech_begin,
  10. tech_end TYPE cacs_s_vers1-tech_end,
  11. END OF export.
  12.  
  13. TYPES: lty_knoten LIKE hrp1001-objid.
  14.  
  15. TYPES: BEGIN OF edge,
  16. von TYPE hrp1001-objid,
  17. nach TYPE hrp1001-sobid,
  18. relat TYPE t777e-relat,
  19. level TYPE i,
  20. begda TYPE hrp1001-begda,
  21. enda TYPE hrp1001-endda,
  22. END OF edge.
  23.  
  24. TYPES: BEGIN OF knoten,
  25. id TYPE hrp1001-sobid,
  26. level TYPE i,
  27. ctrtbu_id TYPE cacs_ctrtbu-ctrtbu_id,
  28. orga_nr TYPE hrp1000-short,
  29. END OF knoten.
  30.  
  31. DATA knoten_queue TYPE TABLE OF knoten.
  32. DATA edge_types TYPE TABLE OF t777e-relat.
  33. DATA kanten TYPE TABLE OF kante.
  34. * data knoten_queue TYPE lty_knoten_queue.
  35.  
  36. DATA result_such_nachbarn TYPE TABLE OF edge.
  37. DATA all_edges TYPE TABLE OF edge.
  38. DATA current_node TYPE knoten.
  39. DATA current_neighbour_edge TYPE edge.
  40. DATA tmp TYPE edge.
  41. DATA tmp_knoten TYPE knoten.
  42. * Breitensuchen
  43.  
  44. DATA: out_dat(128).
  45. DATA: ausgabesatz(1000) TYPE c.
  46.  
  47. START-OF-SELECTION.
  48.  
  49. *** Ausgabe
  50. CONCATENATE '/SAPFTP/' sy-sysid '/pdorgtest' INTO out_dat.
  51. OPEN DATASET out_dat FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
  52.  
  53.  
  54. current_node-id = '60045082'.
  55. current_node-id = '40000001'.
  56. current_node-level = 0.
  57.  
  58. APPEND '002' TO edge_types.
  59. APPEND '003' TO edge_types.
  60.  
  61. * Start Knoten einfügen
  62. APPEND current_node TO knoten_queue.
  63.  
  64. * durch die queue loopen
  65. LOOP AT knoten_queue INTO current_node.
  66. * die nachbarn des aktuellen knotens suchen
  67. PERFORM such_nachbarn USING current_node edge_types.
  68. * für alle nachbarn
  69. LOOP AT result_such_nachbarn INTO current_neighbour_edge.
  70.  
  71. * falls nachbar noch nicht in der queue und nicht zu weit entfernt
  72. READ TABLE knoten_queue WITH KEY id = current_neighbour_edge-nach INTO tmp-nach.
  73. IF ( ( current_neighbour_edge-level <= 2 ) AND sy-subrc <> 0 ).
  74. * Knoten sammeln
  75. tmp_knoten-id = current_neighbour_edge-nach.
  76. tmp_knoten-level = current_neighbour_edge-level.
  77. APPEND tmp_knoten TO knoten_queue.
  78. ENDIF.
  79. * Kanten sammeln
  80. APPEND current_neighbour_edge TO all_edges.
  81. ENDLOOP.
  82. ENDLOOP.
  83.  
  84. CONCATENATE 'Digraph G{' '' into ausgabesatz.
  85. TRANSFER ausgabesatz to out_dat.
  86. PERFORM print_nodes.
  87. PERFORM print_edges.
  88. CONCATENATE '}' '' into ausgabesatz.
  89. TRANSFER ausgabesatz to out_dat.
  90. CLOSE DATASET out_dat.
  91. *&---------------------------------------------------------------------*
  92. *& Form such_nachbarn
  93. *&---------------------------------------------------------------------*
  94. * text
  95. *----------------------------------------------------------------------*
  96. * -->START_NODE text
  97. * -->EDGE_TYPE text
  98. *----------------------------------------------------------------------*
  99. FORM such_nachbarn USING start_node TYPE knoten
  100. edge_type LIKE edge_types.
  101. CLEAR result_such_nachbarn.
  102. DATA current_edge TYPE edge.
  103. DATA neighbour_edges TYPE TABLE OF edge.
  104. DATA wa_edge LIKE t777e-relat.
  105.  
  106. * todo schleife fü zeitpunkte
  107. * schleife für kanten typen
  108. LOOP AT edge_types INTO wa_edge.
  109. SELECT objid sobid relat FROM hrp1001 INTO (current_edge-von, current_edge-nach, current_edge-relat)
  110. WHERE objid = start_node-id
  111. AND begda <= sy-datum AND endda >= sy-datum
  112. AND relat = wa_edge.
  113. current_edge-level = start_node-level + 1.
  114. APPEND current_edge TO neighbour_edges.
  115. ENDSELECT.
  116. ENDLOOP.
  117. result_such_nachbarn = neighbour_edges.
  118. ENDFORM. "such_nachbarn
  119.  
  120.  
  121. *&---------------------------------------------------------------------*
  122. *& Form enrich_node
  123. *&---------------------------------------------------------------------*
  124. * text
  125. *----------------------------------------------------------------------*
  126. * -->NODE text
  127. *----------------------------------------------------------------------*
  128. FORM enrich_node USING node TYPE knoten.
  129. SELECT SINGLE short INTO node-orga_nr FROM hrp1000 WHERE objid = node-id.
  130. ENDFORM. "enrich_node
  131.  
  132. *&---------------------------------------------------------------------*
  133. *& Form print_edges
  134. *&---------------------------------------------------------------------*
  135. * text
  136. *----------------------------------------------------------------------*
  137. FORM print_edges.
  138. DATA tmp_edge TYPE edge.
  139. LOOP AT all_edges INTO tmp_edge.
  140. CLEAR ausgabesatz.
  141. CONCATENATE tmp_edge-von
  142. space
  143. ' -> '
  144. space
  145. tmp_edge-nach
  146. '[label="'
  147. tmp_edge-relat
  148. '"];'
  149. into ausgabesatz.
  150. TRANSFER ausgabesatz TO out_dat.
  151.  
  152. ENDLOOP.
  153. ENDFORM. "print_edges
  154.  
  155. *&---------------------------------------------------------------------*
  156. *& Form print_nodes
  157. *&---------------------------------------------------------------------*
  158. * text
  159. *----------------------------------------------------------------------*
  160. FORM print_nodes.
  161. LOOP AT knoten_queue INTO tmp_knoten.
  162. PERFORM enrich_node USING tmp_knoten.
  163.  
  164. CLEAR ausgabesatz.
  165. CONCATENATE tmp_knoten-id
  166. '[label="'
  167. tmp_knoten-orga_nr
  168. '"];'
  169. into ausgabesatz.
  170.  
  171. TRANSFER ausgabesatz TO out_dat.
  172. ENDLOOP.
  173. ENDFORM. "print_nodes
  174. *FUNCTION suche_nachbarn(knoten)
  175. *select objid from hrp1001

Report this snippet  

You need to login to post a comment.