Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ERROR

former_member190312
Active Participant
0 Likes
793

HI all,

while creating BOM with subitem by 'BAPI_MATERIAL_BOM_GROUP_CREATE' ,

bom is creating in sap but only one sub-item is taking for each item.& that to one & same subitem is repetating for each item.

plz suggest, where i am doing mistake?

my upload file structure is like

FINISHED GOOD: BAPIBOMFG1

ITEM ITEM CATEGORY PART NUM QTY LOCATION

0010 L BAPIBOMRW1 2 c1,c2

0020 L BAPIBOMRW2 5 B1,B2,B3,B4,B5

0030 L BAPIBOMRW3 3 q1,q2,q3

0040 L BAPIBOMRW4 6 x1,x2,x3,x4,x5,x6,x7

now BOM is creating but for each item(10 0r 20 0r 30), c1 is stored as the location.

& the quantity for each item is comming as 1 in CS03 after cration of BOM.

but i am passing different quantities to item table of that BAPI?

can u plz suggest why i am getting this type of result?

Regards

pabitra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
745

get data to internal table....loop the table and inside the loop use the FM so that it will create different line items for same document...

6 REPLIES 6
Read only

Former Member
0 Likes
746

get data to internal table....loop the table and inside the loop use the FM so that it will create different line items for same document...

Read only

0 Likes
745

Hi all,

for this bapi, we need to pass some internal tables.i also tried by putting this FM inside loop but i am getting same result.my coding is below.plz suggest where i am doing mistake?

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,

i_bomgroup LIKE bapi1080_bgr_c OCCURS 0 WITH HEADER LINE,

i_variants LIKE bapi1080_bom_c OCCURS 0 WITH HEADER LINE,

i_items LIKE bapi1080_itm_c OCCURS 0 WITH HEADER LINE,

i_matrel LIKE bapi1080_mbm_c OCCURS 0 WITH HEADER LINE,

i_itemas LIKE bapi1080_rel_itm_bom_c OCCURS 0 WITH HEADER LINE,

i_subitemas LIKE BAPI1080_REL_SUI_ITM_C OCCURS 0 WITH HEADER LINE,

i_subitem LIKE BAPI1080_SUI_C 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_upload3 type standard table of t_upload,

i_split type standard table of t_split,

i_split1 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_upload3 type t_upload,

wa_split type t_split,

wa_split1 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_count1(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.

*loop at i_upload into wa_upload3.

*

*split wa_upload-col5 at c_comma into table i_split1.

*loop at i_split1 into wa_split1.

*v_count1 = v_count1 + 1.

*endloop.

*

*if wa_upload-col4 <> v_count1.

  • wa_upload3-col4 = v_count1.

*

*endif.

*clear v_count1.

*append wa_upload3 to i_upload3.

*clear wa_upload3.

*

*endloop.

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.

append wa_upload1 to i_upload3.

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.

clear i_matrel.

i_matrel-material = p_matnr.

*wa_header-plant = p_werks.

i_matrel-bom_group_identification = 'BAPI_SMP_COL1'.

i_matrel-bom_usage = p_stlan.

i_matrel-alternative_bom = '01'.

append i_matrel.

clear i_bomgroup.

i_bomgroup-bom_usage = p_stlan.

*wa_bomgroup-created_in_plant = p_werks.

*wa_bomgroup-bom_group = ''.

i_bomgroup-object_id = 'SIMPLE1'.

i_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.

i_bomgroup-object_type = 'BGR'.

i_bomgroup-ltxt_lang = sy-langu.

i_bomgroup-technical_type = ' '.

i_bomgroup-bom_text = 'Simple BoM - FM'.

append i_bomgroup.

clear i_variants.

i_variants-alternative_bom = '01'.

*i_variants-base_qty = '1.000'.

i_variants-valid_from_date = sy-datum.

i_variants-bom_group_identification = 'BAPI_SMP_COL1'.

i_variants-object_type = 'BOM'.

i_variants-object_id = 'VAR'. "SIMPLE1

i_variants-bom_status = '01'.

i_variants-valid_from_date = sy-datum.

i_variants-function = 'NEW'.

append i_variants.

clear i_itemas.

i_itemas-bom_group_identification = 'BAPI_SMP_COL1'.

i_itemas-sub_object_type = 'ITM'.

i_itemas-sub_object_id = 'SIM'."----


SIMPLE1

i_itemas-super_object_type = 'BOM'.

i_itemas-super_object_id = 'VAR'."----


SIMPLE1

i_itemas-valid_from_date = sy-datum.

i_itemas-function = 'NEW'.

append i_itemas.

i_subitemas-bom_group_identification = 'BAPI_SMP_COL1'.

i_subitemas-sub_object_type = 'SUI'.

i_subitemas-sub_object_id = 'SIMP'.

i_subitemas-super_object_type = 'ITM'.

i_subitemas-super_object_id = 'SIM'.

append i_subitemas.

loop at i_upload3 into wa_upload3.

*wa_item-item_id = v_num.

*v_num = v_num + 1.

clear i_items.

i_items-bom_group_identification = 'BAPI_SMP_COL1'.

i_items-object_type = 'ITM'.

i_items-object_id = 'SIM'."----


SIMPLE1

i_items-item_no = wa_upload3-col1.

i_items-item_cat = wa_upload3-col2.

i_items-component = wa_upload3-col3.

i_items-comp_qty = wa_upload3-col4.

i_items-valid_from_date = sy-datum.

append i_items.

endloop.

loop at i_items.

loop at i_upload1 into wa_upload1 where col1 = i_items-item_no.

clear i_subitem.

i_subitem-bom_group_identification = 'BAPI_SMP_COL1'.

i_subitem-object_type = 'SUI'.

i_subitem-object_id = 'SIMP'.

IF not wa_upload1-col5 is initial.

on change of wa_upload1-col5.

v_num = v_num + 1.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_num

IMPORTING

OUTPUT = i_subitem-subitem_no.

i_subitem-subitem_qty = '1'.

i_subitem-installation_point = wa_upload1-col5.

append i_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 = 'X'

TABLES

BOMGROUP = i_bomgroup

VARIANTS = i_variants

ITEMS = i_items

SUBITEMS = i_subitem

MATERIALRELATIONS = i_matrel

ITEMASSIGNMENTS = i_itemas

SUBITEMASSIGNMENTS = i_subitemas

  • TEXTS =

RETURN = i_return.

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

Read only

Former Member
0 Likes
745

hi,

can you give some more details on how u wrote the code.

thank u

santhosh

Read only

Former Member
0 Likes
745

try to refresh the internal table work area may be helpful

Read only

Former Member
0 Likes
745

bapi call should with in a loop.

Read only

0 Likes
745

Hi sadiqulla,

Thanks for ur help.

after putting this bapi inside loop also, i am getting the same result.only one sub-item is creating for each item.plz see my coding below.plz suggest if there ia any error.

Regards

pabitra

REPORT ZTEST_CHIN message-id 01.

  • This code will create a material BoM for the material

  • MAINMATERIAL with the components COMPON1 and COMPON2.

  • Data Declaration

DATA:

it_bomgroup LIKE bapi1080_bgr_c OCCURS 0 WITH HEADER LINE,

it_variants LIKE bapi1080_bom_c OCCURS 0 WITH HEADER LINE,

it_items LIKE bapi1080_itm_c OCCURS 0 WITH HEADER LINE,

it_matrel LIKE bapi1080_mbm_c OCCURS 0 WITH HEADER LINE,

it_itemas LIKE bapi1080_rel_itm_bom_c OCCURS 0 WITH HEADER LINE,

it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

it_subitems LIKE bapi1080_sui_c OCCURS 0 WITH HEADER LINE,

it_subitemas LIKE BAPI1080_REL_SUI_ITM_C OCCURS 0 WITH HEADER LINE.

  • Fill the data

  • Material BoM Group Header Data

CLEAR it_bomgroup.

it_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.

it_bomgroup-object_type = 'BGR'.

it_bomgroup-object_id = 'SIMPLE1'.

it_bomgroup-bom_usage = '1'. " YOU COULD CHANGE THE BOM USAGE TO YOUR

it_bomgroup-ltxt_lang = sy-langu.

it_bomgroup-technical_type = ' '.

it_bomgroup-bom_text = 'Simple BoM - FM'.

APPEND it_bomgroup.

  • Header Details of the different variants

CLEAR it_variants.

it_variants-bom_group_identification = 'BAPI_SMP_COL1'.

it_variants-object_type = 'BOM'.

it_variants-object_id = 'SIMPLE1'.

it_variants-alternative_bom = '01'.

it_variants-bom_status = '01'.

it_variants-base_qty = '1.000'.

it_variants-valid_from_date = sy-datum.

it_variants-function = 'NEW'.

APPEND it_variants.

  • Details of the materials of the different variants

CLEAR it_matrel.

it_matrel-bom_group_identification = 'BAPI_SMP_COL1'.

it_matrel-material = 'BAPIBOMFG1'.

it_matrel-bom_usage = '1'.

it_matrel-alternative_bom = '01'.

APPEND it_matrel.

  • Linking subitems to the corresponding variants

CLEAR it_subitemas.

it_subitemas-bom_group_identification = 'BAPI_SMP_COL1'.

it_subitemas-sub_object_type = 'SUI'.

it_subitemas-sub_object_id = 'SIM1'.

it_subitemas-super_object_type = 'ITM'.

it_subitemas-super_object_id = 'SIMPLE1'.

APPEND it_subitemas.

  • Linking items to the corresponding variants

CLEAR it_itemas.

it_itemas-bom_group_identification = 'BAPI_SMP_COL1'.

it_itemas-sub_object_type = 'ITM'.

it_itemas-sub_object_id = 'SIMPLE1'.

it_itemas-super_object_type = 'BOM'.

it_itemas-super_object_id = 'SIMPLE1'.

it_itemas-valid_from_date = sy-datum.

it_itemas-function = 'NEW'.

APPEND it_itemas.

  • Details of the items of the variants

CLEAR it_items.

it_items-bom_group_identification = 'BAPI_SMP_COL1'.

it_items-object_type = 'ITM'.

it_items-object_id = 'SIMPLE1'.

it_items-item_no = '0010'.

it_items-item_cat = 'L'.

it_items-component = 'BAPIBOMRW1'.

it_items-comp_qty = '2'.

it_items-valid_from_date = sy-datum.

APPEND it_items.

CLEAR it_subitems.

it_subitems-bom_group_identification = 'BAPI_SMP_COL1'.

it_subitems-object_type = 'SUI'.

it_subitems-object_id = 'SIM1'.

it_subitems-subitem_no = '0001'.

it_subitems-INSTALLATION_POINT = 'ab1'.

it_subitems-subitem_qty = '1'.

APPEND it_subitems.

CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'

EXPORTING

all_error = 'X'

TABLES

bomgroup = it_bomgroup

variants = it_variants

items = it_items

materialrelations = it_matrel

itemassignments = it_itemas

subitems = it_subitems

subitemassignments = it_subitemas

return = it_return.

CLEAR it_subitems.

it_subitems-bom_group_identification = 'BAPI_SMP_COL1'.

it_subitems-object_type = 'SUI'.

it_subitems-object_id = 'SIM1'.

it_subitems-subitem_no = '0002'.

it_subitems-INSTALLATION_POINT = 'ab2'.

it_subitems-subitem_qty = '1'.

APPEND it_subitems.

CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'

EXPORTING

all_error = 'X'

TABLES

bomgroup = it_bomgroup

variants = it_variants

items = it_items

materialrelations = it_matrel

itemassignments = it_itemas

subitems = it_subitems

subitemassignments = it_subitemas

return = it_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

LOOP AT it_return.

WRITE:/ it_return-type, it_return-id, it_return-number,

it_return-message.

ENDLOOP.