2007 Jul 18 3:02 PM
Hi Friends..
Iam using BAPI for to upload data from flatfile to sap instead of BDC.
But after execute this method "BAPI_MATERIAL_SAVEDATA"
Finally no data was updated in master table...
so how can i store the value into base table..
some one told need to give commit statement..
But i dont know where i give the commit statement..
plz reply to me..
Thanks
Gowrishankar
2007 Jul 18 3:09 PM
After executing CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA', execute a CALL FUNCTION 'BAPI_TRANSACTION_COMMIT', use WAIT = X if you want to wait till update process terminates.
Of course, look at the RETURN and RETURNMESSAGES parameter of BAPI_MATERIAL_SAVEDATA before calling the commit, do not commit if an error code 'E' or 'A' has been raised.
Regards
2007 Jul 18 3:19 PM
Hi Gowrishankar,
Check the program I have written for MM01 upload using BAPI. Maybe it will be of some help to you.
*&---------------------------------------------------------------------*
*& Report ZCN_MM_MATMASTER_BASICVIEW
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zcn_mm_matmaster_basicview MESSAGE-ID zmc_mm_messages.
TABLES: t001l, "Storage Locations
mara, "General Material Data
makt, "Material Descriptions
mbew, "Material Valuation
marc. "Plant Data for Material
DATA: bapi_head LIKE bapimathead,
bapi_makt LIKE bapi_makt, "Material Description
bapi_mara1 LIKE bapi_mara, "Client Data
bapi_marax LIKE bapi_marax,
bapi_marc1 LIKE bapi_marc, "Plant View
bapi_marcx LIKE bapi_marcx,
bapi_mbew1 LIKE bapi_mbew, "Accounting View
bapi_mbewx LIKE bapi_mbewx,
bapi_mard1 LIKE bapi_mard, "Storage View
bapi_mardx LIKE bapi_mardx,
bapi_return LIKE bapiret2.
DATA: BEGIN OF int_makt OCCURS 100.
INCLUDE STRUCTURE bapi_makt.
DATA: END OF int_makt.
DATA: BEGIN OF it_data OCCURS 0,
mat_type(4),
ind_sec(1),
plant(4),
stge_loc(4),
mat_desc(40),
base_uom(3),
old_matno(18),
matl_group(9),
document(22),
po_unit(3),
pur_valkey(4),
mfr_no(10),
manu_mat(40),
vendor_lookup(10),
mrp_type(2),
mrp_ctrler(3),
sm_key(3),
proc_type(1),
sloc_exprc(4),
stge_bin(10),
issue_unit(3),
cc_ph_inv(1),
price_ctrl(1),
val_class(4),
moving_pr(11),
price_unit(5),
profit_ctr(10),
matnr(18),
END OF it_data,
is_data LIKE it_data.
DATA: BEGIN OF it_error OCCURS 0,
mat_type(4),
ind_sec(1),
plant(4),
stge_loc(4),
mat_desc(40),
base_uom(3),
old_matno(18),
matl_group(9),
document(22),
po_unit(3),
pur_valkey(4),
mfr_no(10),
manu_mat(40),
vendor_lookup(10),
mrp_type(2),
mrp_ctrler(3),
sm_key(3),
proc_type(1),
sloc_exprc(4),
stge_bin(10),
issue_unit(3),
cc_ph_inv(1),
price_ctrl(1),
val_class(4),
moving_pr(11),
price_unit(5),
profit_ctr(10),
matnr(18),
END OF it_error,
is_error LIKE it_error.
DATA: bdc_tab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA : g_file TYPE string.
DATA : BEGIN OF data_mat OCCURS 0,
datastring TYPE string,
END OF data_mat.
DATA: record(500).
DATA: gv_count TYPE i VALUE 0.
DATA lv_string TYPE string.
TYPES: BEGIN OF ty_string_tab,
line(255),
END OF ty_string_tab.
DATA i_string_tab TYPE STANDARD TABLE OF ty_string_tab.
********************------SELECTION SCREEN----**************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE ibipparms-path.
PARAMETERS: r_local RADIOBUTTON GROUP radi,
r_apps RADIOBUTTON GROUP radi.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
PARAMETERS : p_downld LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
*******************AT SELECTION SCREEN *********************
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.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_downld.
PERFORM get_local_file USING p_downld.
*----------------------------------------------------------------------*
* S T A R T O F S E L E C T I O N
*----------------------------------------------------------------------*
START-OF-SELECTION.
g_file = p_file.
PERFORM upload USING g_file. "Upload takes the file from the presentation
PERFORM conversion_extendedview.
PERFORM download_errors.
*&---------------------------------------------------------------------*
*& Form upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload USING lv_file .
IF r_apps = 'X'.
OPEN DATASET lv_file
FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
IF sy-subrc <> 0.
WRITE: / text-002, sy-subrc.
STOP.
ELSE.
DO.
READ DATASET lv_file INTO record.
SPLIT record AT '~' INTO
it_data-mat_type
it_data-ind_sec
it_data-plant
it_data-stge_loc
it_data-mat_desc
it_data-base_uom
it_data-old_matno
it_data-matl_group
it_data-document
it_data-po_unit
it_data-pur_valkey
it_data-mfr_no
it_data-manu_mat
it_data-vendor_lookup
it_data-mrp_type
it_data-mrp_ctrler
it_data-sm_key
it_data-proc_type
it_data-sloc_exprc
it_data-stge_bin
it_data-issue_unit
it_data-cc_ph_inv
it_data-price_ctrl
it_data-val_class
it_data-moving_pr
it_data-price_unit
it_data-profit_ctr
it_data-matnr.
APPEND it_data.
CLEAR it_data.
ENDDO.
CLOSE DATASET lv_file.
ENDIF.
ELSEIF r_local = 'X'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
filetype = 'ASC'
has_field_separator = '~'
header_length = 0
read_by_line = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
ignore_cerr = 'X'
replacement = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = data_mat
* 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.
ELSE.
LOOP AT data_mat.
SPLIT data_mat-datastring AT '~' INTO
it_data-mat_type
it_data-ind_sec
it_data-plant
it_data-stge_loc
it_data-mat_desc
it_data-base_uom
it_data-old_matno
it_data-matl_group
it_data-document
it_data-po_unit
it_data-pur_valkey
it_data-mfr_no
it_data-manu_mat
it_data-vendor_lookup
it_data-mrp_type
it_data-mrp_ctrler
it_data-sm_key
it_data-proc_type
it_data-sloc_exprc
it_data-stge_bin
it_data-issue_unit
it_data-cc_ph_inv
it_data-price_ctrl
it_data-val_class
it_data-moving_pr
it_data-price_unit
it_data-profit_ctr
it_data-matnr.
APPEND it_data.
CLEAR it_data.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. " upload
*&---------------------------------------------------------------------*
*& Form conversion_extendedview
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM conversion_extendedview .
DATA: lv_matnr LIKE mara-matnr,
lv_lifnr LIKE lfb1-lifnr.
LOOP AT it_data INTO is_data.
CLEAR: lv_matnr,
lv_lifnr.
SELECT SINGLE matnr FROM mara INTO lv_matnr
WHERE bismt = is_data-old_matno AND
meins = is_data-base_uom.
IF sy-subrc NE 0.
MOVE is_data TO is_error.
APPEND is_error TO it_error.
CLEAR is_error.
CONTINUE.
ENDIF.
SELECT SINGLE lifnr INTO lv_lifnr FROM lfb1
WHERE altkn = is_data-vendor_lookup.
IF sy-subrc EQ 0.
SELECT SINGLE lifnr INTO lv_lifnr FROM lfa1
WHERE lifnr = lv_lifnr AND
ktokk = 'ZMNF'.
IF sy-subrc NE 0.
lv_lifnr = ' '.
ENDIF.
ELSE.
lv_lifnr = ' '.
ENDIF.
* Header
bapi_head-material = lv_matnr.
bapi_head-ind_sector = 'C'.
bapi_head-matl_type = is_data-mat_type.
bapi_head-basic_view = 'X'.
bapi_head-purchase_view = 'X'.
bapi_head-account_view = 'X'.
bapi_head-storage_view = 'X'.
IF is_data-mat_type = 'ROH'.
bapi_head-mrp_view = 'X'.
bapi_head-cost_view = 'X'.
ENDIF.
* Material Description
REFRESH int_makt.
int_makt-langu = 'EN'.
int_makt-matl_desc = is_data-mat_desc.
APPEND int_makt.
* Client Data - Basic
bapi_mara1-matl_group = is_data-matl_group.
bapi_mara1-base_uom = is_data-base_uom.
bapi_mara1-old_mat_no = is_data-old_matno.
bapi_mara1-document = is_data-document.
bapi_mara1-po_unit = is_data-po_unit.
bapi_mara1-pur_valkey = is_data-pur_valkey.
bapi_mara1-mfr_no = lv_lifnr.
bapi_mara1-manu_mat = is_data-manu_mat.
bapi_marax-old_mat_no = 'X'.
bapi_marax-document = 'X'.
bapi_marax-po_unit = 'X'.
bapi_marax-pur_valkey = 'X'.
bapi_marax-mfr_no = 'X'.
bapi_marax-manu_mat = 'X'.
bapi_marax-matl_group = 'X'.
bapi_marax-base_uom = 'X'.
* Plant - Purchasing
bapi_marc1-plant = is_data-plant.
bapi_marc1-mrp_type = 'ND'.
bapi_marc1-mrp_ctrler = is_data-plant.
bapi_marc1-sm_key = '000'.
bapi_marc1-proc_type = 'F'.
bapi_marc1-issue_unit = is_data-issue_unit.
bapi_marc1-cc_ph_inv = is_data-cc_ph_inv.
bapi_marc1-profit_ctr = is_data-profit_ctr.
IF is_data-mat_type = 'ROH'.
bapi_marc1-availcheck = 'KP'.
bapi_marcx-availcheck = 'X'.
ENDIF.
bapi_marcx-plant = is_data-plant.
bapi_marcx-mrp_type = 'X'.
bapi_marcx-mrp_ctrler = 'X'.
bapi_marcx-sm_key = 'X'.
bapi_marcx-proc_type = 'X'.
bapi_marcx-issue_unit = 'X'.
bapi_marcx-cc_ph_inv = 'X'.
bapi_marcx-profit_ctr = 'X'.
* Storage View
bapi_mard1-plant = is_data-plant.
bapi_mard1-stge_loc = is_data-stge_loc.
bapi_mard1-stge_bin = is_data-stge_bin.
bapi_mardx-plant = is_data-plant.
bapi_mardx-stge_loc = is_data-stge_loc.
bapi_mardx-stge_bin = 'X'.
* Accounting
bapi_mbew1-val_area = is_data-plant.
IF is_data-mat_type = 'ROH'.
bapi_mbew1-val_class = '1000'.
ELSEIF is_data-mat_type = 'ERSA'.
bapi_mbew1-val_class = '1001'.
ENDIF.
bapi_mbew1-price_ctrl = 'V'.
bapi_mbew1-moving_pr = is_data-moving_pr.
bapi_mbew1-price_unit = '1'.
bapi_mbewx-val_area = is_data-plant.
bapi_mbewx-val_class = 'X'.
bapi_mbewx-moving_pr = 'X'.
bapi_mbewx-price_ctrl = 'X'.
bapi_mbewx-price_unit = 'X'.
* WRITE:/ bapi_head, bapi_marc1.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = bapi_head
clientdata = bapi_mara1
clientdatax = bapi_marax
plantdata = bapi_marc1
plantdatax = bapi_marcx
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
storagelocationdata = bapi_mard1
storagelocationdatax = bapi_mardx
valuationdata = bapi_mbew1
valuationdatax = bapi_mbewx
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA = BAPI_MVKE1
* SALESDATAX = BAPI_MVKEX
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
IMPORTING
return = bapi_return
TABLES
materialdescription = int_makt
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.
* IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
* ENDIF.
* IF bapi_return-type = 'E'.
* gv_count = gv_count + 1.
* is_error-old_matno = is_data-old_matno.
* is_error-plant = is_data-plant.
* is_error-stge_loc = is_data-stge_loc.
* APPEND is_error TO it_error.
* CLEAR is_error.
* WRITE:/'For Old Material Number',is_data-old_matno,bapi_return-message.
* ENDIF.
ENDLOOP.
* WRITE: 'Total Records in Error', gv_count.
PERFORM concatenate_into_string.
PERFORM download_data.
ENDFORM. "conversion_extendedview
*&---------------------------------------------------------------------*
*& Form get_local_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_DOWNLOAD text
*----------------------------------------------------------------------*
FORM get_local_file USING p_p_download.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = ',*.*,*.*.'
mode = 'S'
title = 'Lookup for Upload file'(013)
IMPORTING
filename = p_p_download
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. " get_local_file
*&---------------------------------------------------------------------*
*& Form concatenate_into_string
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM concatenate_into_string .
DATA: lw_error LIKE LINE OF it_error.
DATA: lw_tab_string LIKE LINE OF i_string_tab,
lw_matnr(10),
lw_plant(3),
lw_stloc(4).
LOOP AT it_error INTO is_error.
MOVE is_error-old_matno TO lw_matnr.
MOVE is_error-plant TO lw_plant.
MOVE is_error-stge_loc TO lw_stloc.
CONCATENATE lw_matnr lw_plant lw_stloc INTO lv_string SEPARATED BY '~'.
MOVE lv_string TO lw_tab_string.
APPEND lw_tab_string TO i_string_tab.
CLEAR: lv_string, lw_tab_string.
ENDLOOP.
ENDFORM. " concatenate_into_string
*&---------------------------------------------------------------------*
*& Form download_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_data .
DATA: lv_file TYPE string.
* Move file name to filename of type string acceptable by GUI_DOWNLOAD
lv_file = p_downld.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = lv_file
filetype = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
TABLES
* data_tab = i_empdata
data_tab = i_string_tab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc EQ 0.
MESSAGE s999 WITH 'File saved successfully'(001) 'to' p_file.
ELSE.
MESSAGE s999 WITH 'Error in creating File'(002).
ENDIF.
ENDFORM. " download_data
*&---------------------------------------------------------------------*
*& Form download_errors
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_errors .
DATA: gv_file TYPE string.
gv_file = p_downld.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = gv_file
filetype = 'ASC'
* APPEND = ' '
write_field_separator = '~'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_EOL = ABAP_TRUE
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_error
* FIELDNAMES =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22
.
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. " download_errors
Regards
Aneesh.
2007 Jul 19 4:29 AM
Hi Gowri,
Just you did everything right just call <b>'BAPI_TRANSACTION_COMMIT'</b> after the actual bapi call like this.
* IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
* ENDIF.
Reward points if useful,
Aleem.
2007 Jul 19 5:51 AM
Hi,
I try different FM in uploading material master
check
CALL FUNCTION 'MATERIAL_MAINTAIN_DARK'
might help you.