09-05-2008 10:15 AM
hi all ,
i want to upload data from excell sheet to BOM (cs01) for a multi level bom .. that is main material is 101(material No)
Subitems for 101 are: 102,103, 104 & 105
102 also has 2 two sub items i.e., 106 & 107
106 also has 3 sub items 108,109,110,
like this they are having several sub components.
for this requirement i will wirite this logic . but its not working .
please give another solution or modiffied this one ..
report z_bom_create
line-size 132
line-count 65
no standard page heading.
type-pools truxs.
*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.
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: i_upload type standard table of t_upload, " to hold data
i_upload1 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_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.
*--Constants
data: c_dot type c value '.',
c_x type c value 'X',
c_comma type c value ','.
data it_type type truxs_t_text_data.
*-------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.
*&----
*& Form f_give_help
*&----
*text
*----
*
*--> p1 text
*<-- p2 text
*----
FORM f_give_help.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file '
IMPORTING
FILE_NAME = p_file .
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 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER =
I_TAB_RAW_DATA = it_type
I_FILENAME = p_file
TABLES
I_TAB_CONVERTED_DATA = i_upload[]
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
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'.
read table i_upload into wa_upload with key col1 = 'FINISHED GOOD:'.
if sy-subrc = 0.
v_matnr = wa_upload-col2.
if v_matnr eq 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.
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.
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_usage = p_stlan.
append wa_header to i_header.
wa_bomgroup-bom_usage = p_stlan.
wa_bomgroup-created_in_plant = p_werks.
append wa_bomgroup to i_bomgroup.
wa_variant-alternative_bom = 1.
wa_variant-base_qty = 1.
wa_variant-valid_from_date = sy-datum.
append wa_variant to i_variant.
loop at i_upload1 into wa_upload1.
wa_item-item_no = wa_upload1-col1.
wa_item-item_cat = wa_upload1-col2.
wa_item-component = wa_upload1-col3.
wa_item-comp_qty = wa_upload1-col4.
append wa_item to i_item.
wa_subitem-subitem_qty = '1'.
wa_subitem-installation_point = wa_upload1-col5.
append wa_subitem to i_subitem.
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 =
*SUBITEMASSIGNMENTS =
*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.
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. " check this
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
09-05-2008 10:32 AM
Hi
Check this [Sample code|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/bdc(bom)tablecontrol]
Regards
Pavan
09-05-2008 10:32 AM
Hi
Check this [Sample code|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/bdc(bom)tablecontrol]
Regards
Pavan
09-05-2008 10:46 AM
hi pavan ,
your code is for uploading data to ca02 . but i want to upload data to cs01 for multi levels of BOM.. plese give for that .
09-05-2008 10:50 AM
01-16-2009 1:08 PM