Hi all,
i am creating a BOM with item & sub item .
i am getting the error like BOM is not valid.
i am giving my coding below.plz suggest where i am doing mistake.
it's urgent.
can u plz give some sample coding where sub-item will be there in that BOM.
any idea will be highly appreaciated.
correct answers will be rewarded.
regards
pabitra
report z_bom_create
line-size 132
line-count 65.
no standard page heading.
*----
DATA DECLARATION
include <icon> .
*---Tables
tables : s076, t100, marc .
*---Types
types : begin of t_upload, " Upload file data
col1(18),
col2(10),
col3(30),
col4(12),
col5(50),
end of t_upload,
begin of t_split,
location like stpu-ebort,
end of t_split.
*data:begin of i_return occurs 10.
*include structure bapiret2.
*data:end of i_return.
data:i_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
types:begin of t_item."occurs 10.
include structure BAPI1080_ITM_C.
types:end of t_item.
types:begin of t_subitem." occurs 10.
include structure BAPI1080_SUI_C.
types:end of t_subitem.
types:begin of t_header." occurs 10.
include structure BAPI1080_MBM_C.
types:end of t_header.
types:begin of t_bomgroup." occurs 10.
include structure BAPI1080_BGR_C.
types:end of t_bomgroup.
types:begin of t_variant." occurs 10.
include structure BAPI1080_BOM_C.
types:end of t_variant.
data:it_itemas LIKE bapi1080_rel_itm_bom_c OCCURS 0 WITH HEADER LINE,
it_subitemas LIKE BAPI1080_REL_SUI_ITM_C OCCURS 0 WITH HEADER LINE.
*--- Tables
data: i_upload type standard table of t_upload, " to hold data
i_upload1 type standard table of t_upload,
i_upload2 type standard table of t_upload,
i_split type standard table of t_split,
i_item type standard table of t_item,
i_subitem type standard table of t_subitem,
i_header type standard table of t_header,
i_bomgroup type standard table of t_bomgroup,
i_variant type standard table of t_variant.
data: wa_upload type t_upload, " to hold file data,
wa_upload1 type t_upload, " to hold plan data,
wa_upload2 type t_upload,
wa_split type t_split,
wa_item type t_item,
wa_subitem type t_subitem,
wa_header type t_header,
wa_bomgroup type t_bomgroup,
wa_variant type t_variant.
data:v_matnr like mara-matnr,
v_start like sy-index,
v_count(3) type c,
v_num(4) type c value '0000'.
*--Constants
data: c_dot type c value '.',
c_x type c value 'X',
c_comma type c value ','.
-------Selection Screen Design -
*Selection screen for input of upload file address
selection-screen skip 2.
selection-screen begin of block blk1 with frame.
parameters : p_file like rlgrap-filename obligatory .
parameters : p_matnr like mara-matnr obligatory,
p_werks like marc-werks obligatory memory id wrk,
p_stlan like afko-stlan obligatory default '1' .
selection-screen end of block blk1.
---AT SELECTION SCREEN -
*at selection-screen on value-request for p_file.
**--For popup to select file.
perform f_give_help.
*at selection-screen on p_matnr.
perform f_check_matnr.
-----START OF SELECTION -
*--Data upload using WS_Upload.
perform f_get_data.
perform f_get_bom_data.
perform f_get_bom_data1.
perform f_call_bapi.
perform f_error_display.
&----
*& Form f_give_help
&----
text
----
--> p1 text
<-- p2 text
----
*FORM f_give_help.
*
*
*call function 'WS_FILENAME_GET'
exporting
mask = ',.,..'
mode = 'O'
importing
filename = p_file
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
if sy-subrc <> 0 and not sy-msgty is initial.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*
*
*ENDFORM. " f_give_help
&----
*& Form f_check_matnr
&----
text
----
--> p1 text
<-- p2 text
----
*FORM f_check_matnr.
*
*
*CALL FUNCTION 'BAPI_MAT_BOM_EXISTENCE_CHECK'
EXPORTING
MATERIAL = p_matnr
PLANT = p_werks
BOMUSAGE = '1'
VALID_FROM_DATE =
VALID_TO_DATE =
TABLES
RETURN = i_return.
.
*ENDFORM. " f_check_matnr
&----
*& Form f_get_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_get_data.
call function 'WS_UPLOAD'
exporting
CODEPAGE = ' '
filename = p_file
filetype = 'DAT'
tables
data_tab = i_upload
exceptions
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
ENDFORM. " f_get_data
&----
*& Form f_get_bom_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_get_bom_data.
delete i_upload where col1 is initial.
delete i_upload where col1 cs 'ITEM'.
i_upload2[] = i_upload[].
delete i_upload2 where col1 cs 'FINISHED GOOD'.
read table i_upload into wa_upload with key col1 = 'FINISHED GOOD:'.
if sy-subrc = 0.
v_matnr = wa_upload-col2.
if v_matnr <> p_matnr.
message e001(zl) with p_matnr.
endif.
else.
message e000(zl).
endif.
ENDFORM. " f_get_bom_data
&----
*& Form f_get_bom_data1
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_get_bom_data1.
loop at i_upload into wa_upload where col1 CS 'FINISHED GOOD'.
v_start = sy-tabix + 1.
loop at i_upload into wa_upload1 from v_start .
if wa_upload1-col1 cs 'FINISHED GOOD'.
exit.
else.
perform f_split_upload_data.
endif.
endloop.
endloop.
ENDFORM. " f_get_bom_data1
&----
*& Form f_split_upload_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_split_upload_data.
if not wa_upload1-col5 is initial.
if wa_upload1-col5 cs c_comma.
split wa_upload1-col5 at c_comma into table i_split.
loop at i_split into wa_split.
v_count = v_count + 1.
endloop.
if wa_upload1-col4 <> v_count.
wa_upload1-col4 = v_count.
endif.
clear wa_upload1-col5.
clear wa_split.
clear v_count.
loop at i_split into wa_split.
wa_upload1-col5 = wa_split-location.
append wa_upload1 to i_upload1.
endloop.
else.
append wa_upload1 to i_upload1.
endif.
else.
append wa_upload1 to i_upload1.
endif.
clear wa_upload1.
ENDFORM. " f_split_upload_data
&----
*& Form f_call_bapi
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_call_bapi.
clear wa_upload1.
wa_header-material = p_matnr.
*wa_header-plant = p_werks.
wa_header-bom_group_identification = 'BAPI_SMP_COL1'.
wa_header-bom_usage = p_stlan.
wa_header-alternative_bom = '1'.
append wa_header to i_header.
wa_bomgroup-bom_usage = p_stlan.
*wa_bomgroup-created_in_plant = p_werks.
*wa_bomgroup-bom_group = ''.
wa_bomgroup-object_id = 'SIMPLE1'.
wa_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.
wa_bomgroup-object_type = 'BGR'.
append wa_bomgroup to i_bomgroup.
wa_variant-alternative_bom = '1'.
wa_variant-base_qty = '1.000'.
wa_variant-valid_from_date = sy-datum.
wa_variant-bom_group_identification = 'BAPI_SMP_COL1'.
wa_variant-object_type = 'BOM'.
wa_variant-object_id = 'VAR'.
wa_variant-bom_status = '1'.
wa_variant-valid_from_date = sy-datum.
wa_variant-function = 'NEW'.
append wa_variant to i_variant.
it_itemas-bom_group_identification = 'BAPI_SMP_COL1'.
it_itemas-sub_object_type = 'ITM'.
it_itemas-sub_object_id = 'SIM'.
it_itemas-super_object_type = 'BOM'.
it_itemas-super_object_id = 'VAR'.
it_itemas-valid_from_date = sy-datum.
it_itemas-function = 'NEW'.
append it_itemas.
it_subitemas-bom_group_identification = 'BAPI_SMP_COL1'.
it_subitemas-sub_object_type = 'SUI'.
it_subitemas-sub_object_id = 'SIMP'.
it_subitemas-super_object_type = 'ITM'.
it_subitemas-super_object_id = 'SIM'.
append it_subitemas.
loop at i_upload2 into wa_upload2.
*wa_item-item_id = v_num.
*v_num = v_num + 1.
wa_item-bom_group_identification = 'BAPI_SMP_COL1'.
wa_item-object_type = 'ITM'.
wa_item-object_id = 'SIM'.
wa_item-item_no = wa_upload2-col1.
wa_item-item_cat = wa_upload2-col2.
wa_item-component = wa_upload2-col3.
wa_item-comp_qty = wa_upload2-col4.
wa_item-valid_from_date = sy-datum.
append wa_item to i_item.
endloop.
loop at i_item into wa_item.
loop at i_upload1 into wa_upload1 where col1 = wa_item-item_no.
wa_subitem-bom_group_identification = 'BAPI_SMP_COL1'.
wa_subitem-object_type = 'SUI'.
wa_subitem-object_id = 'SIMP'.
IF not wa_upload1-col5 is initial.
on change of wa_upload1-col5.
v_num = v_num + 1.
wa_subitem-subitem_no = v_num.
wa_subitem-subitem_qty = '1'.
wa_subitem-installation_point = wa_upload1-col5.
append wa_subitem to i_subitem.
clear wa_subitem.
endon.
endif.
clear wa_upload1.
endloop.
clear v_num.
clear wa_upload.
endloop.
CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'
EXPORTING
TESTRUN = ' '
ALL_ERROR = ' '
TABLES
BOMGROUP = i_bomgroup
VARIANTS = i_variant
ITEMS = i_item
SUBITEMS = i_subitem
MATERIALRELATIONS = i_header
ITEMASSIGNMENTS = it_itemas
SUBITEMASSIGNMENTS = it_subitemas
TEXTS =
RETURN = i_return.
*if i_return[] is initial.
*CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*write: /'BOM created:', stpo-stlnr.
*else.
*if not i_return[] is initial.
*loop at i_return.
*
WRITE:/ i_return-type, i_return-id, i_return-number,
i_return-message.
*ENDLOOP.
IF i_return-TYPE = 'E'.
*
*
errmsg-type = i_return-type.
errmsg-line = i_return-message.
**
append errmsg.
*
ULINE /1(108).
write:/ icon_led_RED as icon, i_return-MESSAGE.
ULINE /1(108).
*
ENDIF.
*
IF i_return-TYPE = 'W'.
*
errmsg-type = i_return-type.
**
errmsg-line = i_return-message.
append errmsg.
*
ULINE /1(108).
write:/ icon_led_YELLOW as icon, i_return-MESSAGE.
ULINE /1(108).
*
ENDIF.
*
*
ENDLOOP.
*
**write: / i_return-id, i_return-number, i_return-message(80).
**endloop.
*
*
**write: /'Error'.
**endif.
*
.
ENDFORM. " f_call_bapi
&----
*& Form f_error_display
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_error_display.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
loop at i_return.
WRITE:/ i_return-type, i_return-id, i_return-number,
i_return-message.
ENDLOOP.
ENDFORM. " f_error_display