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

Material inventory function module

0 Likes
4,313

Hallo,

I have to create a z-program that fill all screen of transaction MI02 from an internal table. So I create a material inventory document.

How can I proceded? Is better calling transaction MI02 or exists a funcion module that fill all item of materila inventory?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,860

hI gILBERT

USE BAPI TO FILL THE MATERIAL INVENTORY DATA FROM INTERNAL TABLE

THE BAPI IS

<b>BAPI_GOODSMVT_CREATE</b>

REFER THE SAMPLE PROGRAM IN

http://www.sap-img.com/abap/bapi-goodsmvt-create-to-post-goods-movement.htm

REGARDS

KISHORE

REWARD IF HELPFUL

19 REPLIES 19
Read only

Former Member
0 Likes
2,861

hI gILBERT

USE BAPI TO FILL THE MATERIAL INVENTORY DATA FROM INTERNAL TABLE

THE BAPI IS

<b>BAPI_GOODSMVT_CREATE</b>

REFER THE SAMPLE PROGRAM IN

http://www.sap-img.com/abap/bapi-goodsmvt-create-to-post-goods-movement.htm

REGARDS

KISHORE

REWARD IF HELPFUL

Read only

Former Member
0 Likes
2,860

Hi,

Try BAPI_MATPHYSINV_CREATE_MULT or MB_PHYSICAL_INVENTORY.

Best Regards,

James Gaddis.

Read only

0 Likes
2,860

Thanks for BAPI name... but I don't know if are the right FM. I have to implement the functionality of the MI31 transaction. I have to create a inventory document, I have to insert the quantities of materials and I have to confirm it.

What (one or more) FM I have to use?

All the data of material code and quantity are in an internal table.

Read only

0 Likes
2,860

Hi

Try to use this Fm 'MB_SELECT_MAT_PHYSINV_STD'

Read only

0 Likes
2,860

In this FM I didn't find where insert the quantity of material that I inventored

Read only

0 Likes
2,860

Hi Gilbert,

I misunderstood your question.

Actually that FM is to get the data based on selection screen similar to MI31 transaction.

So you already got data to post in mi02 transaction, then why dont you use BDC.

Read only

0 Likes
2,860

Sorry. What is BDC?

My work is:

1) I have a file excel with material inventory (code and quantity)

2) I have to create a program that load data file in an internal table (ok)

3) I have to fill automatic the fields of transaction MI31 with werks, lgort and other header data

4) I have to fill automatic the fields (item) with code and quantity of material inventory.

How I can do this?

Read only

0 Likes
2,860

HI Gilbert

you can use BDC for that you have to record the transactiion in SHDB by entering the required fields.

for this you can do this in two ways.

one is convert the excel file into intetnal table and the other the save the excel file as tab delimited text file and upload it into internal table.

i am posting the sample code for the two methods.

<b>EXCEL:</b>

REPORT UPLOAD_EXCEL no standard page heading.

*Data Declaration

*----


data: itab like alsmex_tabline occurs 0 with header line.

  • Has the following format:

  • Row number | Colum Number | Value

  • ---------------------------------------

  • i.e. 1 1 Name1

  • 2 1 Joe

TYPES: Begin of t_record,

name1 like itab-value,

name2 like itab-value,

age like itab-value,

End of t_record.

DATA: it_record type standard table of t_record initial size 0,

wa_record type t_record.

DATA: gd_currentrow type i.

*Selection Screen Declaration

*----


PARAMETER p_infile like rlgrap-filename.

************************************************************************

*START OF SELECTION

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = p_infile

i_begin_col = '1'

i_begin_row = '2' "Do not require headings

i_end_col = '14'

i_end_row = '31'

tables

intern = itab

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

if sy-subrc <> 0.

message e010(zz) with text-001. "Problem uploading Excel Spreadsheet

endif.

  • Sort table by rows and colums

sort itab by row col.

  • Get first row retrieved

read table itab index 1.

  • Set first row retrieved to current row

gd_currentrow = itab-row.

loop at itab.

  • Reset values for next row

if itab-row ne gd_currentrow.

append wa_record to it_record.

clear wa_record.

gd_currentrow = itab-row.

endif.

case itab-col.

when '0001'. "First name

wa_record-name1 = itab-value.

when '0002'. "Surname

wa_record-name2 = itab-value.

when '0003'. "Age

wa_record-age = itab-value.

endcase.

endloop.

append wa_record to it_record.

*!! Excel data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

TAB-DELIMITED:

REPORT ZBDCAPPL.

parameters: V_DATA(132) lower case.

data: begin of record OCCURS 0,

  • data element: MATNR

MATNR_001(018),

  • data element: MBRSH

MBRSH_002(001),

  • data element: MTART

MTART_003(004),

  • data element: XFELD

KZSEL_01_004(001),

  • data element: MAKTX

MAKTX_005(040),

  • data element: MEINS

MEINS_006(003),

  • data element: MATKL

MATKL_007(009),

  • data element: SPART

SPART_008(002),

end of record.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'D:\ABAP\material.txt'

  • FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = RECORD

  • EXCEPTIONS

  • FILE_OPEN_ERROR = 1

  • FILE_READ_ERROR = 2

  • NO_BATCH = 3

  • GUI_REFUSE_FILETRANSFER = 4

  • INVALID_TYPE = 5

  • NO_AUTHORITY = 6

  • UNKNOWN_ERROR = 7

  • BAD_DATA_FORMAT = 8

  • HEADER_NOT_ALLOWED = 9

  • SEPARATOR_NOT_ALLOWED = 10

  • HEADER_TOO_LONG = 11

  • UNKNOWN_DP_ERROR = 12

  • ACCESS_DENIED = 13

  • DP_OUT_OF_MEMORY = 14

  • DISK_FULL = 15

  • DP_TIMEOUT = 16

  • OTHERS = 17

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

regards

kishore

Read only

0 Likes
2,860

Hi Gilbert,

Now you got the data in internal table from excel file

with lgort,werks,quantity etc.

And with this data you want to create Material Inventory with transaction MI01 right?

If this is correct then you have to record the transaction MI01 using transaction SHDB.Then u can loop throug your internal table and post your data to transaction MI01, so that it creates Material inventory.

Read only

ferry_lianto
Active Contributor
0 Likes
2,860

Hi Gilbert,

Try this FM <b>MB_PHYSICAL_INVENTORY</b>.

Perhaps it will help.

Regards,

Ferry Lianto

Read only

0 Likes
2,860

It seem good. Where can I find a documentation on the use of MB_PHYSICAL_INVENTORY F.M.?

Read only

0 Likes
2,860

Gilbert and Ferry,

Just a point of emphasis, MB_PHYSICAL_INVENTORY was suggested by me in my March 14 reply above. Hope it works for you Gilbert. Let us know.

Cheers!

- James Gaddis

Read only

ferry_lianto
Active Contributor
0 Likes
2,860

Hi Gilbert,

Please take a look at SAP Notes <b>314208</b> or you can browse SAP Notes with search term 'MB_PHYSICAL_INVENTORY'.

Hope this will help.

Regards,

Ferry Lianto

Read only

0 Likes
2,860

Ok, but where I insert the quantities of my inventory?

Read only

0 Likes
2,860

Hi glibert,

For inserting quantities you have to use transaction MI10 not mi01.

sample code:



  PERFORM open_group.
  i = 0.
  LOOP AT lt_header WHERE chbx1 = 'X'.
    CONCATENATE lt_header-datum1+6(2) lt_header-datum1+4(2)
 lt_header-datum1(4) INTO d2
     SEPARATED BY '.'.
    CONCATENATE lt_header-datum+6(2) lt_header-datum+4(2)
 lt_header-datum(4) INTO d1
    SEPARATED BY '.'.

*    MOVE itab-datum1 TO d2.
*    MOVE itab-datum  TO d1.
    PERFORM bdc_dynpro      USING 'SAPMM07I' '0700'.
    PERFORM bdc_field       USING 'RM07I-ZLDAT'
                                   d1.
    PERFORM bdc_field       USING 'RM07I-BLDAT'
                                   d2.
    PERFORM bdc_field       USING 'IKPF-WERKS'
                                   lt_header-werks.
    PERFORM bdc_field       USING 'IKPF-LGORT'
                                   lt_header-lgort.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.

    LOOP AT lt_item WHERE status IS initial.
      IF i = maxpo.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BU'.
        PERFORM bdc_transaction USING 'MI10'.
        i = 0.

        PERFORM bdc_dynpro      USING 'SAPMM07I' '0700'.
        PERFORM bdc_field       USING 'RM07I-ZLDAT'
                                       d1.
        PERFORM bdc_field       USING 'RM07I-BLDAT'
                                       d2.
        PERFORM bdc_field       USING 'IKPF-WERKS'
                                       lt_header-werks.
        PERFORM bdc_field       USING 'IKPF-LGORT'
                                       lt_header-lgort.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '/00'.

*        CONTINUE.
      ENDIF.

      PERFORM bdc_dynpro      USING 'SAPMM07I' '0731'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '/00'.
      PERFORM bdc_field       USING 'ISEG-MATNR(01)'
                                     lt_item-matnr.
      PERFORM bdc_field       USING 'ISEG-CHARG(01)'
                                    lt_item-charg.
      PERFORM bdc_field       USING 'ISEG-BSTAR(01)'
                                    lt_item-bstar.
      PERFORM bdc_field       USING 'ISEG-ERFMG(01)'---> Quantity
                                     '0'.

      PERFORM bdc_field       USING 'ISEG-XNULL(01)'
                                    lt_item-xnull.
      i = i + 1.
    ENDLOOP.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '/00'.
    IF i < maxpo.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BU'.
    ENDIF.
    PERFORM bdc_transaction USING 'MI10'.
  ENDLOOP.
  PERFORM close_group.

The above code for zero stock.

Read only

0 Likes
2,860

I use BAPI_PHYSINV_CREATE_ITEMS to create inventory document.

I fill import parameter HEAD with werks,lgort and dates.

I fill table ITEMS with 2 material codes.

After BAPI, return say me that is all ok and "inventory document 100000080 is create".

Now I chack it on MI03 transaction, but it say me that "100000080 document don't exits"

Why!?!?!?

Read only

0 Likes
2,860

Hi Gilbert

After the BAPI have you included

CALL FUNCTION BAPI_TRANSACTION_COMMIT.

this will PERFROM the COMMIT_WORK for the database

regards

kishore

Read only

0 Likes
2,860

Thanks a lot!

It'a all right!

Mondoy I try to use BAPI_MATPHYSINV_COUNT to insert material quantity...

Read only

0 Likes
2,860

With BAPI BAPI_MATPHYSINV_CREATE and after COMMIT, I created the inventory document 100000090 on fiscal year 2006.

In transaction MI02 I can see it.

Now I try to use BAPI_MATPHYSINV_COUNT, with parameters

physinventory = '100000090'

fiscalyear = '2006'

why it return me this error:

E

the invetory document 100000090 doesn't exist in fiscal year 2006.