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

bdc program for mi01(inventory) error

Former Member
0 Likes
601

HI EXPERTS,

i have written a coding as per the requirement for inventory data upload by using transaction code 'MI01'.but it is always showing an error that " flat file is not found".please help me in solving this problem.

here is the coding.

report ZMM_RDD0009_MATERIAL_INVENTORY

no standard page heading line-size 255.

  • structure declaration.

types : begin of TY_UPLOAD ,

WERKS TYPE IKPF-WERKS,

LGORT TYPE IKPF-LGORT,

MATNR TYPE ISEG-MATNR,

END OF TY_UPLOAD.

  • INTERNAL TABLE DECLARATION.

  • internal table for upload the data.

data:t_upload type standard table of ty_upload initial size 0,

*internal table for bdcdata.

t_bdcdata type standard table of bdcdata initial size 0 ,

*internal table for bdcmsgcoll.

t_bdcmsgcoll type standard table of bdcmsgcoll initial size 0,

t_error type standard table of ty_upload initial size 0,

  • WORK-AREA DECLARATION.

  • work-area for upload the data.

w_upload type ty_upload,

bdcdata type bdcdata,

  • work-area for bdcmsgcoll.

w_bdcmsg type bdcmsgcoll,

*global variable declaration.

g_message(70) type c.

*include bdcrecx1.

start-of-selection.

call function 'GUI_UPLOAD'

exporting

filename = 'D:/FLATFILE.TXT'

filetype = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = t_upload.

  • EXCEPTIONS

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

  • DEST = FILLER8

group = 'ERROR_MAT'

  • HOLDDATE = ''

  • KEEP = 'X'

user = sy-uname

  • RECORD = FILLER1

prog = sy-cprog.

loop at t_upload into w_upload.

refresh t_bdcdata.

*perform open_group.

perform bdc_dynpro using 'SAPMM07I' '0700'.

perform bdc_field using 'BDC_CURSOR'

'IKPF-LGORT'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

*perform bdc_field using 'RM07I-BLDAT'

  • 'W_UPLOAD-BLDAT'.

*perform bdc_field using 'RM07I-GIDAT'

  • 'W_UPLOAD-GIDAT'.

perform bdc_field using 'IKPF-WERKS'

'W_UPLOAD-WERKS'.

perform bdc_field using 'IKPF-LGORT'

'W_UPLOAD-LGORT'.

perform bdc_field using 'RM07I-XLVOCA'

'X'.

perform bdc_dynpro using 'SAPMM07I' '0721'.

perform bdc_field using 'BDC_CURSOR'

'ISEG-MATNR(02)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'ISEG-MATNR(01)'

'W_UPLOAD-MATNR(01)'.

*perform bdc_field using 'ISEG-MATNR(02)'

  • 'W_UPLOAD-MATNR(02)'.

perform bdc_dynpro using 'SAPMM07I' '0721'.

perform bdc_field using 'BDC_CURSOR'

'ISEG-MATNR(01)'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

*perform bdc_transaction using 'MI01'.

*perform close_group.

call transaction 'MI01' using t_bdcdata mode 'N' update 'S'

messages into t_bdcmsgcoll.

if sy-subrc <> 0.

*append w_upload to t_error.

call function 'BDC_INSERT'

exporting

tcode = 'MI01'

tables

dynprotab = t_bdcdata.

endif.

clear w_bdcmsg.

read table t_bdcmsgcoll into w_bdcmsg index 1.

call function 'FORMAT_MESSAGE'

exporting

id = w_bdcmsg-msgid

lang = sy-langu

no = w_bdcmsg-msgnr

v1 = w_bdcmsg-msgv1

v2 = w_bdcmsg-msgv2

v3 = w_bdcmsg-msgv3

v4 = w_bdcmsg-msgv4

importing

msg = g_message

exceptions

not_found = 1

others = 2.

if sy-subrc = 0.

write:/ w_upload-WERKS,'----', g_message.

refresh t_bdcmsgcoll.

endif.

endloop.

call function 'BDC_CLOSE_GROUP'.

  • EXCEPTIONS

  • NOT_OPEN = 1

  • QUEUE_ERROR = 2

  • OTHERS = 3

.

if sy-subrc <> 0.

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

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

endif.

----


  • Start new screen *

----


form bdc_dynpro using program dynpro.

clear bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

append bdcdata to t_bdcdata.

clear bdcdata.

endform.

----


  • Insert field *

----


form bdc_field using fnam fval.

  • IF FVAL <> NODATA.

clear bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

append bdcdata to t_bdcdata.

clear bdcdata.

  • ENDIF.

endform.

Edited by: rohit on Jun 10, 2008 1:09 PM

2 REPLIES 2
Read only

former_member480923
Active Contributor
0 Likes
507


*&---------------------------------------------------------------------*
*& Report  ZTEST_PRG6
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report anirban no standard page heading line-size 255.

types : begin of ty_upload ,
        werks type ikpf-werks,
        lgort type ikpf-lgort,
        matnr type iseg-matnr,
        end of ty_upload.

parameters: p_file type localfile obligatory.


data:t_upload type standard table of ty_upload initial size 0,
*internal table for bdcdata.
     t_bdcdata type standard table of bdcdata initial size 0 ,
*internal table for bdcmsgcoll.
     t_bdcmsgcoll type standard table of bdcmsgcoll initial size 0,
     t_error type standard table of ty_upload initial size 0,
     w_upload type ty_upload,
     w_file   type string,
     bdcdata type bdcdata,
     w_bdcmsg type bdcmsgcoll,
*global variable declaration.
    g_message(70) type c.


at selection-screen on value-request for p_file.


  call function 'F4_FILENAME'
    exporting
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
    importing
      file_name     = p_file.


start-of-selection.

  w_file = p_file.

  call function 'GUI_UPLOAD'
    exporting
      filename            = w_file
      filetype            = 'ASC'
      has_field_separator = 'X'
    tables
      data_tab            = t_upload.

  check sy-subrc = 0.

  call function 'BDC_OPEN_GROUP'
    exporting
      client = sy-mandt
      group  = 'ERROR_MAT'
      user   = sy-uname
      prog   = sy-cprog.

  check sy-subrc = 0.

  loop at t_upload into w_upload.

    refresh t_bdcdata.

    perform bdc_dynpro using 'SAPMM07I' '0700'.
    perform bdc_field using 'BDC_CURSOR'
    'IKPF-LGORT'.
    perform bdc_field using 'BDC_OKCODE' '/00'.
    perform bdc_field using 'IKPF-WERKS'
    'W_UPLOAD-WERKS'.
    perform bdc_field using 'IKPF-LGORT'
    'W_UPLOAD-LGORT'.
    perform bdc_field using 'RM07I-XLVOCA'
    'X'.
    perform bdc_dynpro using 'SAPMM07I' '0721'.
    perform bdc_field using 'BDC_CURSOR'
    'ISEG-MATNR(02)'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'ISEG-MATNR(01)'
    'W_UPLOAD-MATNR(01)'.
*perform bdc_field using 'ISEG-MATNR(02)'
    perform bdc_dynpro using 'SAPMM07I' '0721'.
    perform bdc_field using 'BDC_CURSOR'
    'ISEG-MATNR(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=BU'.
    call transaction 'MI01' using t_bdcdata mode 'N' update 'S'
    messages into t_bdcmsgcoll.
    if sy-subrc = 0.

      call function 'BDC_INSERT'
        exporting
          tcode     = 'MI01'
        tables
          dynprotab = t_bdcdata.

    endif.

    clear w_bdcmsg.
    read table t_bdcmsgcoll into w_bdcmsg index 1.

    call function 'FORMAT_MESSAGE'
      exporting
        id        = w_bdcmsg-msgid
        lang      = sy-langu
        no        = w_bdcmsg-msgnr
        v1        = w_bdcmsg-msgv1
        v2        = w_bdcmsg-msgv2
        v3        = w_bdcmsg-msgv3
        v4        = w_bdcmsg-msgv4
      importing
        msg       = g_message
      exceptions
        not_found = 1
        others    = 2.
    if sy-subrc = 0.

      write:/ w_upload-werks,'----', g_message.

      refresh t_bdcmsgcoll.

    endif.

  endloop.
  call function 'BDC_CLOSE_GROUP'.


* ----------------------------------------------------------------------
* start new screen
* ----------------------------------------------------------------------
form bdc_dynpro using program dynpro.
  clear bdcdata.
  bdcdata-program = program.
  bdcdata-dynpro = dynpro.
  bdcdata-dynbegin = 'X'.
  append bdcdata to t_bdcdata.
  clear bdcdata.
endform.                    "

* --------------------------------------------------------------------
*insert field *
*---------------------------------------------------------------------
form bdc_field using fnam fval.

*  IF fval NODATA.
  clear bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  append bdcdata to t_bdcdata.
  clear bdcdata.

*  ENDIF.
endform.                    "

Please change the program as above

Hope That Helps

Anirban M.

Read only

Former Member
0 Likes
507

Hi Rohit,

Declare a paramter in selection screen say,

P_file type rlgrap-filename.

Default the file path to this parameter and pass p_file to the parameter filename in the FM gui_upload.

Hope this helps,

Keerthi.