Выгрузка основных данных признака BW (вместе с атрибутами) для PCM

Программа описанная ниже, позволяет выгрузить в XML или ODS (с предварительной выгрузкой в промежуточную таблицу), основные данные признака BW вместе с данными его атрибутов, в формате готовом для загрузки в XML.

Структура для выгрузки в PCM
Структура для выгрузки в PCM
Транзакция для редактирования Simple transformation STRANS

Используемая трансформация в программе ZID

  1. <xsl:transform version="1.0"
  2. xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform"
  3. >
  4. <xsl:template">http://www.w3.org/1999/XSL/Transform"
  5. >
  6. <xsl:template</a> match="/">
  7. <xsl:copy-of select="."/>
  8. </xsl:template>
  9. </xsl:transform>

Полный текст программы:

  1. *&---------------------------------------------------------------------*
  2. *& Report ZZXMLTST2TEST
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8. REPORT ZZXMLTST2TEST.
  9.  
  10. TYPE-POOLS : abap.
  11.  
  12. data atrvsel(32).
  13. data atrvstr(64).
  14. data target2(32).
  15. data saveindex like sy-index.
  16. data: temptab LIKE ZPARENTCHILD.
  17.  
  18. SELECTION-SCREEN BEGIN OF BLOCK rad1
  19. WITH FRAME TITLE text-001.
  20. PARAMETERS: p_table(30) obligatory, " признак содержащий основные данные
  21. target(32) lower case obligatory, " наименование целевого измерения в PCM
  22. model(32) lower case obligatory DEFAULT 'Test 2'. " Наименование целевой модели PCM
  23. SELECT-OPTIONS atrvs for atrvsel. " атрибуты признака подлежащие выгрузке в PCM
  24. SELECTION-SCREEN END OF BLOCK rad1.
  25.  
  26. SELECTION-SCREEN BEGIN OF BLOCK rad2
  27. WITH FRAME TITLE text-002.
  28. PARAMETERS: Diskname(3) obligatory DEFAULT 'C:/',path(255) lower case obligatory DEFAULT 'pcm.xml'. " путь выгрузки файла
  29. PARAMETERS: odss AS CHECKBOX. " выгружать в ОДС
  30. PARAMETERS: cleartab AS CHECKBOX. " очистка временных таблиц (файла)
  31. SELECTION-SCREEN END OF BLOCK rad2.
  32. *-------------- DATA
  33. DATA : ParentChildRecord type TABLE OF ZPARENTCHILDRECORD WITH HEADER LINE. " таблица со структурой для выгрузки в PCM
  34. DATA : ParentChildRecord2 type TABLE OF ZPARENTCHILDRECORD WITH HEADER LINE.
  35. DATA : ParentChildRecord3 type TABLE OF ZPARENTCHILDRECORD WITH HEADER LINE.
  36. DATA : fieldlist type TABLE OF ZFIELDLIST WITH HEADER LINE.
  37. DATA : chartlist type TABLE OF ZFIELDLIST WITH HEADER LINE.
  38. data: fullpath type string.
  39.  
  40. CONCATENATE Diskname path INTO fullpath. " полный путь до файла на PS
  41.  
  42. * так как структура таблиц с основными данными признаков
  43. * может быть разной, для унификации доступа определим динамические таблицы
  44. * через FIELD-SYMBOLS
  45. * field symbols to access the dynamic table
  46. FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, " таблица
  47. <dyn_wa>, " рабочай область
  48. <dyn_field>, " поле
  49. <dyn_field2>. " поле 2
  50. DATA: dy_table TYPE REF TO data, " для построяния динамической структуры
  51. dy_line TYPE REF TO data,
  52. xfc TYPE lvc_s_fcat,
  53. ifc TYPE lvc_t_fcat.
  54.  
  55. * additional data
  56. data: charname(30).
  57. charname = p_table.
  58. REPLACE ALL OCCURRENCES OF '/M'
  59. IN charname WITH '/'.
  60.  
  61.  
  62. DATA : BEGIN OF itab OCCURS 0,
  63. a(100) TYPE c,
  64. END OF itab.
  65.  
  66. DATA: xml_out TYPE string, " для вывода в XML
  67. formstring type string,
  68. tststrv type string.
  69.  
  70.  
  71. DATA : BEGIN OF upl OCCURS 0,
  72. f(255) TYPE c,
  73. END OF upl.
  74. DATA: xmlupl TYPE string .
  75.  
  76.  
  77. *------------------ Fetch Data
  78.  
  79. *******Creates a dynamic internal table*********
  80. PERFORM get_structure. " создать структуры таблицы
  81. PERFORM create_dynamic_itab. " создать таблицу
  82.  
  83.  
  84. * получаем список атрибутов:
  85. loop at atrvs.
  86. fieldlist-name = atrvs-low.
  87. append fieldlist.
  88. * get data
  89. PERFORM get_data.
  90. * PERFORM write_out TABLES fieldlist.
  91. data: cter2(4).
  92. * stage 1 - get char values
  93. LOOP AT <dyn_table> INTO <dyn_wa>.
  94. ASSIGN COMPONENT charname " сами значения признака
  95. OF STRUCTURE <dyn_wa> TO <dyn_field>.
  96. IF sy-subrc <> 0.
  97.  
  98. * cter2 = <dyn_field>+0(4).
  99. * if cter2 eq '0000'.
  100. * SHIFT <dyn_field> LEFT DELETING LEADING '0'.
  101. * ENDIF.
  102. "WRITE: <dyn_field>.
  103. ParentChildRecord-DimensionName = target.
  104. ParentChildRecord-ParentName = target.
  105. ParentChildRecord-ChildName = <dyn_field>.
  106. ParentChildRecord-AttributeFlag = '8'.
  107. ParentChildRecord-ConsolidationType = '+'.
  108. APPEND ParentChildRecord.
  109. chartlist-name = <dyn_field>. " формируем список значений атрибутов как отдельный лист
  110. APPEND chartlist.
  111. * stage 2 - FORMING ATTRIBUTES
  112. target2 = target.
  113. shift target2 by 1 places. " Отрежем справа один символ
  114. CONCATENATE target 'Attributes' into atrvstr SEPARATED BY space. " сформируем строку
  115. LOOP AT fieldlist. " список атрибутов
  116. ParentChildRecord-DimensionName = target.
  117. ParentChildRecord-ParentName = atrvstr.
  118. ParentChildRecord-ChildName = fieldlist-name.
  119. ParentChildRecord-AttributeFlag = '15'.
  120. ParentChildRecord-ConsolidationType = 'OR'.
  121. APPEND ParentChildRecord.
  122. * stage 3 - atributes values
  123. LOOP AT fieldlist. " список атрибутов
  124. LOOP AT <dyn_table> INTO <dyn_wa>.
  125. ASSIGN COMPONENT fieldlist-name " сами значения признака
  126. OF STRUCTURE <dyn_wa> TO <dyn_field>.
  127. IF sy-subrc <> 0.
  128. "WRITE: <dyn_field>.
  129. ParentChildRecord-DimensionName = target.
  130. ParentChildRecord-ParentName = fieldlist-name.
  131. ParentChildRecord-ChildName = <dyn_field>.
  132. ParentChildRecord-AttributeFlag = '15'.
  133. ParentChildRecord-ConsolidationType = '+'.
  134. APPEND ParentChildRecord.
  135.  
  136. LOOP at ParentChildRecord.
  137. COLLECT ParentChildRecord INTO ParentChildRecord2.
  138. DELETE ParentChildRecord2 WHERE ChildName is INITIAL.
  139.  
  140.  
  141. * stage 4 - atributes values mapping
  142.  
  143. LOOP AT chartlist. " список значений признака
  144. LOOP AT fieldlist. " список атрибутов
  145.  
  146. LOOP AT <dyn_table> INTO <dyn_wa>.
  147.  
  148. ASSIGN COMPONENT charname " сами значения признака
  149. OF STRUCTURE <dyn_wa> TO <dyn_field2>.
  150. IF sy-subrc <> 0.
  151. if <dyn_field2> eq chartlist-name.
  152. ASSIGN COMPONENT fieldlist-name " сами значения признака
  153. OF STRUCTURE <dyn_wa> TO <dyn_field>.
  154. IF sy-subrc <> 0.
  155. ParentChildRecord2-DimensionName = target.
  156. ParentChildRecord2-ParentName = <dyn_field>.
  157. ParentChildRecord2-ChildName = chartlist-name.
  158. ParentChildRecord2-AttributeFlag = '12'.
  159. ParentChildRecord2-ConsolidationType = '+'.
  160. APPEND ParentChildRecord2.
  161.  
  162.  
  163.  
  164. DELETE ParentChildRecord2 WHERE ParentName is INITIAL.
  165.  
  166. if odss is INITIAL or odss eq ''.
  167.  
  168. *XML formig
  169.  
  170. *------------------- XML
  171. CALL TRANSFORMATION ('ZID')
  172. SOURCE Action = ParentChildRecord2[]
  173. RESULT XML xml_out.
  174.  
  175. *------------------- EDIT XML
  176. CONCATENATE '<PPAData><Build>10.0.2.313</Build><Model>' model '</Model><Action Type="Update">'
  177. into formstring.
  178.  
  179. REPLACE ALL OCCURRENCES OF '<asx:abap xmlns:asx="<a href="http://www.sap.com/abapxml"">http://www.sap.com/abapxml"</a> version="1.0"><asx:values><ACTION>'
  180. IN xml_out WITH formstring.
  181.  
  182. REPLACE ALL OCCURRENCES OF '</ACTION></asx:values></asx:abap>'
  183. IN xml_out WITH '</Action></PPAData>'.
  184.  
  185. REPLACE ALL OCCURRENCES OF 'ZPARENTCHILDRECORD'
  186. IN xml_out WITH 'ParentChildRecord'.
  187.  
  188. REPLACE ALL OCCURRENCES OF 'CONSOLIDATIONTYPE'
  189. IN xml_out WITH 'ConsolidationType'.
  190.  
  191. REPLACE ALL OCCURRENCES OF 'PARENTNAME'
  192. IN xml_out WITH 'ParentName'.
  193. REPLACE ALL OCCURRENCES OF 'CHILDNAME'
  194. IN xml_out WITH 'ChildName'.
  195. REPLACE ALL OCCURRENCES OF 'ATTRIBUTEFLAG'
  196. IN xml_out WITH 'AttributeFlag'.
  197.  
  198. REPLACE ALL OCCURRENCES OF 'DIMENSIONNAME'
  199. IN xml_out WITH 'DimensionName'.
  200.  
  201.  
  202. *------------- Convert to TABLE
  203.  
  204. CALL FUNCTION 'Z_EFI_CONVERT_STRING_TO_TABLE'
  205. EXPORTING
  206. i_string = xml_out
  207. i_tabline_length = 100
  208. et_table = itab.
  209.  
  210. *-------------- Download
  211.  
  212. CALL FUNCTION 'GUI_DOWNLOAD'
  213. EXPORTING
  214. filetype = 'BIN'
  215. filename = fullpath
  216. data_tab = itab.
  217. ELSEIF odss eq 'X'.
  218.  
  219. if cleartab eq 'X'.
  220. EXEC SQL.
  221. TRUNCATE TABLE "ZPARENTCHILD"
  222. LOOP at ParentChildRecord2.
  223. temptab-DIMENTIONNAME = ParentChildRecord2-DimensionName.
  224. temptab-PARENTNAME = ParentChildRecord2-ParentName.
  225. temptab-CHILDNAME = ParentChildRecord2-ChildName.
  226. temptab-ATTRIBUTEFLAG = ParentChildRecord2-AttributeFlag.
  227. temptab-CONSOLIDATIONTYP = ParentChildRecord2-ConsolidationType.
  228.  
  229. insert ZPARENTCHILD from temptab.
  230. ******FORMES
  231. *write 'hello'.
  232.  
  233. *&---------------------------------------------------------------------*
  234. *& Form get_structure
  235. *&---------------------------------------------------------------------*
  236. FORM get_structure.
  237. DATA : idetails TYPE abap_compdescr_tab,
  238. xdetails TYPE abap_compdescr.
  239. DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
  240. * Get the structure of the table.
  241. ref_table_des ?=
  242. cl_abap_typedescr=>describe_by_name( p_table ).
  243. idetails[] = ref_table_des->components[].
  244. LOOP AT idetails INTO xdetails.
  245. CLEAR xfc.
  246. xfc-fieldname = xdetails-name .
  247. * Correction by Paul Robert Oct 28, 2009 17:04
  248. * xfc-datatype = xdetails-type_kind.
  249. CASE xdetails-type_kind.
  250. WHEN 'C'.
  251. xfc-datatype = 'CHAR'.
  252. WHEN 'N'.
  253. xfc-datatype = 'NUMC'.
  254. WHEN 'D'.
  255. xfc-datatype = 'DATE'.
  256. WHEN 'P'.
  257. xfc-datatype = 'PACK'.
  258. WHEN OTHERS.
  259. xfc-datatype = xdetails-type_kind.
  260. xfc-inttype = xdetails-type_kind.
  261. xfc-intlen = xdetails-length.
  262. xfc-decimals = xdetails-decimals.
  263. APPEND xfc TO ifc.
  264. ENDFORM. "get_structure
  265. *&---------------------------------------------------------------------*
  266. *& Form create_dynamic_itab
  267. *&---------------------------------------------------------------------*
  268. FORM create_dynamic_itab.
  269. * Create dynamic internal table and assign to FS
  270. CALL METHOD cl_alv_table_create=>create_dynamic_table
  271. EXPORTING
  272. it_fieldcatalog = ifc
  273. i_length_in_byte = 'X' "added by Paul Robert Oct 28, 2009 17:04
  274. IMPORTING
  275. ep_table = dy_table.
  276. ASSIGN dy_table->* TO <dyn_table>.
  277. * Create dynamic work area and assign to FS
  278. CREATE DATA dy_line LIKE LINE OF <dyn_table>.
  279. ASSIGN dy_line->* TO <dyn_wa>.
  280. ENDFORM. "create_dynamic_itab
  281.  
  282. *&---------------------------------------------------------------------*
  283. *& Form get_data
  284. *&---------------------------------------------------------------------*
  285. FORM get_data.
  286. * Select Data from table.
  287. SELECT * INTO TABLE <dyn_table>
  288. FROM (p_table).
  289. ENDFORM. "get_data
  290.  
  291. *&---------------------------------------------------------------------*
  292. *& Form write_out
  293. *&---------------------------------------------------------------------*
  294. *FORM write_out TABLES fieldlist.
  295. * LOOP AT <dyn_table> INTO <dyn_wa>.
  296. * " DO.
  297. * ASSIGN COMPONENT 'fieldlist-name'
  298. * OF STRUCTURE <dyn_wa> TO <dyn_field>.
  299. * IF sy-subrc <> 0.
  300. * EXIT.
  301. * ENDIF.
  302. * WRITE: <dyn_field>.
  303. *
  304. * " ENDDO.
  305. * ENDLOOP.
  306. *ENDFORM. "write_out

Комментарии