In the start routine transformation ZPP_O55->ZPP_C55
*$*$ begin of 2nd part global - insert your code only below this line *
*begin add by zhangj26 for crd1112 on 26-Apr-2011
*global part data defination and perform in the global part2.
TYPES: BEGIN OF ty_chil,
children TYPE /bi0/oimaterial,
END OF ty_chil.
TYPES ty_t_chil TYPE STANDARD TABLE OF ty_chil.
TYPES: BEGIN OF ty_node,
node TYPE /bi0/oimaterial,
plant TYPE /bi0/oiplant,
END OF ty_node.
DATA: BEGIN OF tree ,
plant TYPE /bi0/oiplant,
node TYPE /bi0/oimaterial,
t_children TYPE STANDARD TABLE OF ty_chil,
parent TYPE /bi0/oimaterial,
qty TYPE /bic/oizcomp_qty, "QUANTITY
stock TYPE /bic/oizclabs_n1, " Unrestricted use
maxbuild TYPE /bic/oizclabs_n2, "max build
END OF tree.
DATA: t_tree LIKE STANDARD TABLE OF tree WITH KEY node parent.
DATA: lt_tree LIKE TABLE OF tree WITH KEY node parent,
wa_tree LIKE LINE OF lt_tree.
*&---------------------------------------------------------------------*
*& Form cal_leaf_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->leafnode text
* -->r_mb text
*----------------------------------------------------------------------*
FORM cal_leaf_maxbuild USING leafnode LIKE tree
CHANGING r_mb TYPE i.
IF leafnode-qty NE 0.
r_mb = leafnode-stock / leafnode-qty.
ENDIF.
ENDFORM. "cal_leaf_maxbuild
*&---------------------------------------------------------------------*
*& Form cal_child_maxbuild
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->I_NODE text
* -->TREE text
* -->MB text
*----------------------------------------------------------------------*
FORM cal_child_maxbuild USING i_node TYPE /bi0/oimaterial
tree LIKE t_tree
CHANGING mb TYPE i.
DATA l_counter TYPE i.
DATA l_child TYPE ty_chil.
DATA l_cur_node LIKE LINE OF tree[].
DATA l_tmp TYPE i.
FIELD-SYMBOLS: LIKE LINE OF tree,
LIKE LINE OF tree,
TYPE ty_chil.
CLEAR mb.
"if the node is a leaf
READ TABLE tree[]
WITH KEY node = i_node
ASSIGNING
.
IF sy-subrc = 0 AND -t_children[] IS INITIAL.
PERFORM cal_leaf_maxbuild USING mb.
-maxbuild = mb.
ELSE.
"Min(maxbuild for children[1]...maxbuild for children[n])
READ TABLE tree[]
WITH KEY node = i_node
INTO l_cur_node.
CHECK sy-subrc = 0.
LOOP AT l_cur_node-t_children[] INTO l_child.
l_counter = sy-tabix.
READ TABLE tree[]
WITH KEY node = l_child
ASSIGNING .
CHECK sy-subrc = 0.
IF l_counter = 1.
PERFORM cal_child_maxbuild USING -node tree
CHANGING mb.
IF -t_children[] IS NOT INITIAL.
mb = mb / -qty.
ENDIF.
ELSEIF l_counter GT 1.
PERFORM cal_child_maxbuild USING -node tree
CHANGING l_tmp.
IF -t_children[] IS NOT INITIAL.
l_tmp = l_tmp / -qty.
ENDIF.
IF l_tmp LT mb.
mb = l_tmp.
ENDIF.
ENDIF.
IF -t_children[] IS NOT INITIAL.
-maxbuild = mb.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "cal_child_maxbuild
*$*$ end of 2nd part global - insert your code only before this line *
************************************************************************
*&---------------------------------------------------------------------
**& Author : ZHANGJ26
**& mail address : zhangjiajuan@hotmail.com
**& Create Date : 2011/04/22
**& Project : ENT MasterAll BW Report
**& CRD Number : CRD11112
**&---------------------------------------------------------------------
**local data defination
DATA: lt_node TYPE STANDARD TABLE OF ty_node,
w_node TYPE ty_node.
FIELD-SYMBOLS: TYPE _ty_s_sc_1.
LOOP AT SOURCE_PACKAGE ASSIGNING .
w_node-node = -material.
w_node-plant = -plant.
APPEND w_node TO lt_node.
CLEAR w_node.
w_node-node = -component.
w_node-plant = -plant.
APPEND w_node TO lt_node.
CLEAR w_node.
ENDLOOP.
*get all node from the source_package
SORT lt_node.
DELETE ADJACENT DUPLICATES FROM lt_node COMPARING node.
*get comp_qty and stock from ZMM_TO57 into lt_mm_to57
DATA: lt_mm_to57 TYPE STANDARD TABLE OF /bic/azmm_to5700.
IF NOT lt_node[] IS INITIAL.
SELECT *
FROM /bic/azmm_to5700
INTO CORRESPONDING FIELDS OF TABLE lt_mm_to57
FOR ALL ENTRIES IN lt_node
WHERE mat_plant = lt_node-node AND
plant = lt_node-plant.
IF sy-subrc = 0.
SORT lt_mm_to57 BY mat_plant plant.
ENDIF.
ENDIF.
* build tree
DATA: lt_children TYPE ty_t_chil.
FIELD-SYMBOLS: TYPE ty_node.
FIELD-SYMBOLS: TYPE /bic/azmm_to5700.
LOOP AT lt_node INTO w_node.
wa_tree-node = w_node.
LOOP AT SOURCE_PACKAGE ASSIGNING WHERE material =
w_node-node.
IF sy-subrc = 0.
APPEND -component TO lt_children.
ENDIF.
ENDLOOP.
wa_tree-t_children = lt_children.
REFRESH lt_children.
READ TABLE SOURCE_PACKAGE ASSIGNING WITH KEY component =
wa_tree-node.
IF sy-subrc = 0.
wa_tree-parent = -material.
ELSE.
CLEAR wa_tree-parent.
ENDIF.
wa_tree-plant = -plant.
wa_tree-qty = -/bic/zcomp_qty.
READ TABLE lt_mm_to57 ASSIGNING WITH KEY mat_plant =
wa_tree-node
plant =
wa_tree-plant
BINARY SEARCH.
IF sy-subrc = 0.
wa_tree-stock = -/bic/zclabs.
ELSE.
CLEAR wa_tree-stock.
ENDIF.
APPEND wa_tree TO lt_tree.
CLEAR wa_tree.
ENDLOOP.
*recursive algorithm to cal the maxbuild.
FIELD-SYMBOLS: LIKE LINE OF t_tree.
DATA: max_build TYPE i.
LOOP AT lt_tree ASSIGNING .
IF -parent IS INITIAL.
PERFORM cal_child_maxbuild USING -node
lt_tree
CHANGING max_build.
-maxbuild = max_build.
clear max_build.
EXIT.
ENDIF.
ENDLOOP.
*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD.
************************************************************************
阅读(1312) | 评论(0) | 转发(0) |