11-11-2008 6:23 AM
Hi All,
Is there any Function Module to find the list of Equipment BOM's attached to the given Material Numbers.
11-11-2008 6:27 AM
11-11-2008 8:54 AM
11-11-2008 9:10 AM
check thsi code...this explodes the BOM for material...
Do the req changes...
Does not deals with Quantity...get it from stpo and do the changes
TYPES:BEGIN OF ty_push,
matnr TYPE matnr,
END OF ty_push.
TYPES:BEGIN OF ty_store,
pmatnr TYPE matnr,
cmatnr TYPE matnr,
END OF ty_store.
TYPES:BEGIN OF ty_push2,
pmatnr TYPE matnr,
cmatnr TYPE matnr,
pmaktx TYPE maktx,
cmaktx TYPE maktx,
END OF ty_push2.
DATA:t_push TYPE STANDARD TABLE OF ty_push INITIAL SIZE 0.
DATA:t_push_temp TYPE STANDARD TABLE OF ty_push INITIAL SIZE 0.
DATA:t_sb_push TYPE STANDARD TABLE OF ty_push2 INITIAL SIZE 0.
DATA:t_makt TYPE STANDARD TABLE OF makt INITIAL SIZE 0.
DATA:t_stpo TYPE STANDARD TABLE OF stpo_api02 INITIAL SIZE 0.
DATA:wa_matnr TYPE ty_push.
DATA:wa_push TYPE ty_push.
DATA:wa_tmp TYPE ty_push.
DATA:wa_sb_push TYPE ty_push2.
DATA:wa_makt TYPE makt.
DATA:wa_stpo TYPE stpo_api02.
parameters:pa_matnr type mara-matnr obligatory.
parameters:pa_plant type marc-werks obligatory.
parameters:p_usage type stlan obligatory.
DATA:g_lines TYPE sy-tfill.
start-of-selection.
*Initializle Global itabs and work areas.
PERFORM init_globals.
*Select Parts from Masters
SELECT mara~matnr INTO wa_matnr
FROM mara INNER JOIN marc
ON mara~matnr EQ marc~matnr
WHERE mara~matnr = pa_matnr
* WHERE mara~mtart EQ 'FERT' "Finished Goods
where mara~lvorm EQ space "Deletion Indicator Material Level
AND marc~werks EQ g_plant "Plant Data of Material
AND marc~lvorm EQ space. "Deletion Indicator Plant Level
CHECK sy-subrc EQ 0.
MOVE wa_matnr-matnr TO wa_push-matnr.
APPEND wa_push TO t_push.
*Explode Bill of Material matrix
PERFORM get_below_comp.
ENDSELECT.
IF sy-subrc NE 0.
message e000(zpp) with 'No data found'.
stop.
else.
IF t_sb_push[] IS NOT INITIAL.
return-type = 'S'.
return-message = 'BOM Pulled Successfully'.
*Get Parent and Child Texts
PERFORM get_material_texts.
IF t_makt[] IS NOT INITIAL.
SORT t_makt[] BY matnr ASCENDING.
LOOP AT t_sb_push[] INTO wa_sb_push WHERE pmaktx EQ space.
READ TABLE t_makt[] INTO wa_makt WITH KEY matnr = wa_sb_push-pmatnr
BINARY SEARCH
TRANSPORTING maktx.
CHECK sy-subrc EQ 0.
MOVE wa_makt-maktx TO wa_sb_push-pmaktx.
MODIFY t_sb_push[] FROM wa_sb_push
TRANSPORTING pmaktx
WHERE pmatnr EQ wa_sb_push-pmatnr.
CLEAR wa_sb_push.
ENDLOOP.
LOOP AT t_sb_push[] INTO wa_sb_push WHERE cmaktx EQ space.
READ TABLE t_makt[] INTO wa_makt WITH KEY matnr = wa_sb_push-cmatnr
BINARY SEARCH
TRANSPORTING maktx.
CHECK sy-subrc EQ 0.
MOVE wa_makt-maktx TO wa_sb_push-cmaktx.
MODIFY t_sb_push[] FROM wa_sb_push
TRANSPORTING cmaktx
WHERE cmatnr EQ wa_sb_push-cmatnr.
CLEAR wa_sb_push.
ENDLOOP.
ENDIF.
SORT t_sb_push[] BY pmatnr ASCENDING.
ENDIF.
ENDIF.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_BELOW_COMP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_below_comp .
DESCRIBE TABLE t_push[] lines g_lines.
IF g_lines EQ 0.
EXIT.
ENDIF.
LOOP AT t_push[] INTO wa_push.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
material = wa_push-matnr
plant = p_plant
bom_usage = p_usage
TABLES
t_stpo = t_stpo
t_stpu = t_stpu
EXCEPTIONS
error = 1
OTHERS = 2.
IF t_stpo[] IS NOT INITIAL.
LOOP AT t_stpo INTO wa_stpo.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_push-matnr
IMPORTING
output = wa_sb_push-pmatnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_stpo-component
IMPORTING
output = wa_sb_push-cmatnr.
APPEND wa_sb_push TO t_sb_push.
MOVE wa_stpo-component TO wa_tmp-matnr.
APPEND wa_tmp TO t_push_temp[].
ENDLOOP.
REFRESH t_stpo[].
ENDIF.
ENDLOOP.
t_push[] = t_push_temp[].
REFRESH t_push_temp[].
PERFORM get_below_comp. "Recursive Call
ENDFORM. " GET_BELOW_COMP
*&---------------------------------------------------------------------*
*& Form GET_MATERIAL_TEXTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_material_texts .
SELECT * FROM makt INTO TABLE t_makt FOR ALL ENTRIES IN
t_sb_push[] WHERE matnr = t_sb_push-pmatnr.
SELECT * FROM makt APPENDING TABLE t_makt FOR ALL ENTRIES IN
t_sb_push[] WHERE matnr = t_sb_push-cmatnr.
ENDFORM. " GET_MATERIAL_TEXTS
*&---------------------------------------------------------------------*
*& Form INIT_GLOBALS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_globals .
REFRESH: t_push[],
t_push_temp[],
t_sb_push[],
t_makt[],
t_stpo[],
t_stpu[],
t_ctref[].
CLEAR: wa_matnr,
wa_push,
wa_tmp,
wa_sb_push,
wa_makt,
wa_stpo,
wa_stpu,
wa_ctref,
g_plant,
g_usage.
ENDFORM. " INIT_GLOBALS