Application Development 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: 

PROBLEM IN BDC PROGRAM

Former Member
0 Kudos

HI EXPECTS,

PLEASE HELP ME SOLVING THIS PROBLEM, IT IS NOT UPLOADING THE TO INTERNAL TABLE AND TO TRANSACTION 'MI01'.PLEASE HELP ME SOLVING THE PROBLEM.

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. "

FLAT FILE

PLANT SLOC MATL

KCPT SLC1 689

KCPT SLC1 690

3 REPLIES 3

Former Member
0 Kudos

&----


*& 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

Reward Points..

Former Member
0 Kudos

Remove the quotes in following statements like 'W_UPLOAD-WERKS'.It is taking it as a hard coded value.Try to upload the data by using excel file.Use FM ALSM_EXCEL_TO_INTERNAL_TABLE

*perform bdc_field using 'IKPF-WERKS'

'W_UPLOAD-WERKS'.*

The sample code:

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 22
      i_end_row               = 9999
    TABLES
      intern                  = it_excel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 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.

  CLEAR wa_file.

  LOOP AT it_excel INTO wa_excel.
    CASE wa_excel-col .
      WHEN '1'.
        wa_file-saknr = wa_excel-value.

      WHEN '2'.
        wa_file-bukrs = wa_excel-value.

      WHEN '3'.
        wa_file-ktoks = wa_excel-value.

      WHEN '4'.
        wa_file-xplacct = wa_excel-value.

      WHEN '5'.
        wa_file-xbilk = wa_excel-value.

      WHEN '6'.
        wa_file-txt20_skat = wa_excel-value.

      WHEN '7'.
        wa_file-txt50_skat = wa_excel-value.

      WHEN '8'.
        wa_file-waers_skb1 = wa_excel-value.

      WHEN '9'.
        wa_file-xsalh = wa_excel-value.

      WHEN '10'.
        wa_file-smwsk = wa_excel-value.

      WHEN '11'.
        wa_file-xmwno = wa_excel-value.

      WHEN '12'.
        wa_file-mitkz = wa_excel-value.

      WHEN '13'.
        wa_file-altkt_skb1 = wa_excel-value.

      WHEN '14'.
        wa_file-xopvw = wa_excel-value.

      WHEN '15'.
        wa_file-xkres = wa_excel-value.

      WHEN '16'.
        IF STRLEN( wa_excel-value ) = 1.
          CONCATENATE '00' wa_excel-value INTO con.
          wa_file-dzuawa = con.
        ELSEIF STRLEN( wa_excel-value ) = 2.
          CONCATENATE '0' wa_excel-value INTO con1.
          wa_file-dzuawa = con1.
        ELSE.
          wa_file-dzuawa = wa_excel-value.
        ENDIF.
      WHEN '17'.
        wa_file-brgru = wa_excel-value.

      WHEN '18'.
        wa_file-busab = wa_excel-value.

      WHEN '19'.
        wa_file-fstag = wa_excel-value.

      WHEN '20'.
        wa_file-xintb = wa_excel-value.

      WHEN '21'.
        wa_file-xgkon = wa_excel-value.

      WHEN '22'.
        wa_file-fipos = wa_excel-value.

    ENDCASE.

    AT END OF row.
      CONDENSE:wa_file-saknr,wa_file-bukrs,wa_file-ktoks,wa_file-xplacct,
      wa_file-xbilk,wa_file-txt20_skat,wa_file-txt50_skat,wa_file-waers_skb1,
      wa_file-xsalh,wa_file-smwsk,wa_file-xmwno,wa_file-mitkz,
      wa_file-altkt_skb1,wa_file-xopvw,wa_file-xkres,wa_file-dzuawa,
      wa_file-brgru,wa_file-busab,wa_file-fstag,wa_file-xintb,
      wa_file-xgkon,wa_file-fipos.

      APPEND wa_file TO it_file.
      CLEAR wa_file.
    ENDAT .
  ENDLOOP.

Former Member
0 Kudos

Use either Call Transaction or Session method. Here you are trying to use both. Remove the below statement if u r using Session method.

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

Put the 'ENDLOOP' before (call function 'BDC_INSERT')