BAPI in MM01 uploading
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
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.
Similar Messages
-
Profit Center not getting uploaded through BAPI for MM01. Pls help
Hello all,
I am getting an errror while uploading a file through BAPI for MM01 , The error says
Error:
Profit center 1000/sslcommon does not exist
for material: AC2
*& Report ZBAPI_DUMMY
REPORT ZBAPI_MM01.
*& Report ZBAPI2
TABLES
FLAGS *
DATA: F_STOP. " Flag used to stop processing
DATA DECLARATIONS *
DATA : V_EMPTY TYPE I, " No. of empty records
V_TOTAL TYPE I. " Total no. of records.
STRUCTURES & INTERNAL TABLES
*--- BAPI structures
DATA: BAPI_HEAD LIKE BAPIMATHEAD, " Header Segment with Control
BAPI_MAKT LIKE BAPI_MAKT, " Material Description
BAPI_MARA1 LIKE BAPI_MARA, " Client Data
BAPI_MARAX LIKE BAPI_MARAX, " Checkbox Structure for BAPI_MARA
BAPI_MARC1 LIKE BAPI_MARC, " Plant View
BAPI_MARCX LIKE BAPI_MARCX, " Checkbox Structure for BAPI_MARC
BAPI_MBEW1 LIKE BAPI_MBEW, " Accounting View
BAPI_MBEWX LIKE BAPI_MBEWX, " Checkbox Structure for BAPI_MBEW
BAPI_RETURN LIKE BAPIRET2, " Return Parameter
BAPI_MARDL LIKE BAPI_MARD,
BAPI_MARDX LIKE BAPI_MARDX.
*--- Internal table to hold excel file data
DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
*--- Internal table to hold Matetrial descriptions
DATA: BEGIN OF IT_MAKT OCCURS 100.
INCLUDE STRUCTURE BAPI_MAKT.
DATA: END OF IT_MAKT.
*--- Internal to hold the records in the text file
DATA : BEGIN OF IT_DATA OCCURS 100,
WERKS(4), " Plant
MTART(4), " Material type
MATNR(18), " Material number
MATKL(9) , " Material group
MBRSH(1), " Industry sector
MEINS(3), " Base unit of measure
SPART(2), " Division
EKGRP(3), " Purchasing group
PRCTR(10), " Profit Center
VPRSV(1), " Price control indicator
BKLAS(4), "Valuation Class
*stprs(12), " Standard price
PEINH(3), " Price unit
SPRAS(2), " Language key
MAKTX(40), " Material description
LGORT(4) , " storage location
DISMM(2) , "MRP TYPE
VERPR(23), " Moving Average Price
MTVFP(2) , " Availability Check
DISLS(2) , "Lot Size
DISPO(3) , "MRP Controller
BESKZ(1) , "Procurment Type
FHORI(3) , "SCHEDMARGIN KEY
PERKZ(1) , "Period Indicator
END OF IT_DATA.
SELECTION SCREEN. *
SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.
PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY " Input File
PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session
PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines
PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,
P_BEGROW TYPE I DEFAULT 2 NO-DISPLAY,
P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,
P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK SCR1.
AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*--- Validating file
PERFORM VALIDATE_FILE USING P_FILE.
START-OF-SELECTION
START-OF-SELECTION.
*--- Perform to convert the Excel data into an internal table
PERFORM CONVERT_XLS_ITAB.
IF NOT IT_DATA[] IS INITIAL.
*--- Perform to delete Header lines
PERFORM DELETE_HEADER_EMPTY_RECS.
ENDIF.
END OF SELECTION. *
END-OF-SELECTION.
*--- Perform to upload Material Master data
PERFORM UPLOAD_MATMAS.
Form : validate_input_file
Description : To provide F4 help for file if read from PC
FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
FILE_NAME = F_FILE
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE S010(ZLKPL_MSGCLASS). " 'Error in getting filename'.
ENDIF.
ENDFORM. " validate_input_file
*& Form CONVER_XLS_ITAB
text
FORM CONVERT_XLS_ITAB.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_BEGCOL
I_BEGIN_ROW = P_BEGROW
I_END_COL = P_ENDCOL
I_END_ROW = P_ENDROW
TABLES
INTERN = IT_INTERN.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*--- Perform to move the data into an internal data
PERFORM MOVE_DATA.
ENDFORM. " CONVERT_XLS_ITAB
*& Form MOVE_DATA
text
FORM MOVE_DATA.
DATA : LV_INDEX TYPE I.
FIELD-SYMBOLS <FS> .
*--- Sorting the internal table
SORT IT_INTERN BY ROW COL.
CLEAR IT_INTERN.
LOOP AT IT_INTERN.
MOVE IT_INTERN-COL TO LV_INDEX.
*--- Assigning the each record to an internal table row
ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO <FS> .
*--- Asigning the field value to a field symbol
MOVE IT_INTERN-VALUE TO <FS> .
AT END OF ROW.
APPEND IT_DATA.
CLEAR IT_DATA.
ENDAT.
ENDLOOP.
ENDFORM. " MOVE_DATA
*& Form DELETE_HEADER_EMPTY_RECS
To delete the Header and empty records
FORM DELETE_HEADER_EMPTY_RECS.
DATA: LV_TABIX LIKE SY-TABIX.
IF NOT P_HEADER IS INITIAL.
LOOP AT IT_DATA.
IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.
DELETE IT_DATA FROM 1 TO P_HEADER.
P_HEADER = 0.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR IT_DATA.
*--- To delete the empty lines from internal table
LOOP AT IT_DATA.
LV_TABIX = SY-TABIX.
IF IT_DATA IS INITIAL.
V_EMPTY = V_EMPTY + 1.
DELETE IT_DATA INDEX LV_TABIX..
ENDIF.
ENDLOOP.
CLEAR IT_DATA.
*--- Total no of recs in file
DESCRIBE TABLE IT_DATA LINES V_TOTAL.
IF V_TOTAL = 0.
MESSAGE I013(ZLKPL_MSGCLASS). " No records in the file
F_STOP = 'X'.
STOP.
ENDIF.
ENDFORM. " DELETE_HEADER_EMPTY_RECS
*& Form UPLOAD_MATMAS
to upload Material Master data
FORM UPLOAD_MATMAS .
LOOP AT IT_DATA.
Header
BAPI_HEAD-MATERIAL = IT_DATA-MATNR.
BAPI_HEAD-IND_SECTOR = IT_DATA-MBRSH.
BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.
BAPI_HEAD-BASIC_VIEW = 'X'.
BAPI_HEAD-PURCHASE_VIEW = 'X'.
BAPI_HEAD-ACCOUNT_VIEW = 'X'.
BAPI_HEAD-storage_view ='X'.
bapi_head-mrp_view = 'X'.
bapi_head-COST_view ='X'.
Material Description
REFRESH IT_MAKT.
IT_MAKT-LANGU = IT_DATA-SPRAS.
IT_MAKT-MATL_DESC = IT_DATA-MAKTX.
APPEND IT_MAKT.
Client Data - Basic
BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.
BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.
bapi_mara1-unit_of_wt = it_data-gewei.
BAPI_MARA1-DIVISION = IT_DATA-SPART.
BAPI_MARAX-MATL_GROUP = 'X'.
BAPI_MARAX-BASE_UOM = 'X'.
BAPI_MARAX-UNIT_OF_WT = 'X'.
BAPI_MARAX-DIVISION = 'X'.
Plant - Purchasing
BAPI_MARC1-PLANT = IT_DATA-WERKS.
BAPI_MARC1-PUR_GROUP = IT_DATA-EKGRP.
BAPI_MARC1-PROFIT_CTR = IT_DATA-PRCTR.
BAPI_MARC1-MRP_TYPE = IT_DATA-DISMM.
BAPI_MARC1-AVAILCHECK = IT_DATA-MTVFP.
BAPI_MARC1-LOTSIZEKEY = IT_DATA-DISLS.
BAPI_MARC1-MRP_CTRLER = IT_DATA-DISPO.
BAPI_MARC1-PROC_TYPE = IT_DATA-BESKZ.
BAPI_MARC1-SM_KEY = IT_DATA-FHORI.
BAPI_MARC1-PERIOD_IND = IT_DATA-PERKZ.
BAPI_MARCX-PLANT = IT_DATA-WERKS.
BAPI_MARCX-PUR_GROUP = 'X'.
BAPI_MARCX-AVAILCHECK = 'X'.
BAPI_MARCX-PROFIT_CTR = 'X'.
BAPI_MARCX-MRP_TYPE = 'X'.
BAPI_MARCX-MRP_CTRLER = 'X'.
BAPI_MARCX-SM_KEY = 'X'.
BAPI_MARCX-LOTSIZEKEY = 'X'.
Storage Location.
BAPI_MARDL-PLANT = IT_DATA-WERKS.
BAPI_MARDL-STGE_LOC = IT_DATA-LGORT.
BAPI_MARDX-PLANT = IT_DATA-WERKS.
BAPI_MARDX-STGE_LOC = IT_DATA-LGORT.
Accounting
BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.
BAPI_MBEW1-PRICE_CTRL = IT_DATA-VPRSV.
BAPI_MBEW1-VAL_CLASS = IT_DATA-BKLAS.
BAPI_MBEW1-MOVING_PR = IT_DATA-VERPR.
bapi_mbew1-std_price = it_data-stprs.
BAPI_MBEW1-PRICE_UNIT = IT_DATA-PEINH.
BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.
BAPI_MBEWX-PRICE_CTRL = 'X'.
BAPI_MBEWX-STD_PRICE = 'X'.
BAPI_MBEWX-PRICE_UNIT = 'X'.
BAPI_MBEWX-MOVING_PR = 'X'.
*--- BAPI to create material
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_MARDL
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 = IT_MAKT
UNITSOFMEASURE =
UNITSOFMEASUREX =
INTERNATIONALARTNOS =
MATERIALLONGTEXT =
TAXCLASSIFICATIONS =
RETURNMESSAGES =
PRTDATA =
PRTDATAX =
EXTENSIONIN =
EXTENSIONINX =
IF BAPI_RETURN-TYPE = 'E'.
WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,
IT_DATA-MATNR.
ELSEIF BAPI_RETURN-TYPE = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN = BAPI_RETURN
WRITE: 'Successfully created material' ,IT_DATA-MATNR.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN = BAPI_RETURN
ENDLOOP.
ENDFORM. " UPLOAD_MATMASthe Profit center 1000/sslcommon not created. first create the profit center and then upload your data.check tcode KE52 for created profit centers...
-
Hello All,
I am trying to develop a bapi for MM01.For which i have used a code as suggested by one of you.But the problem is when i am trying to upload my Excel sheet it is giving me a dump. I have designed my Excel sheet according to the sequence in my code. Is it necessary to maintain the sequence as in BDC?. Hers the code to have a clear idea.Please help me out as i am new to BAPI.
*& Report ZBAPI2
REPORT ZBAPI2.
TABLES
FLAGS *
DATA: f_stop. " Flag used to stop processing
DATA DECLARATIONS *
DATA : v_empty TYPE i, " No. of empty records
v_total TYPE i. " Total no. of records.
STRUCTURES & INTERNAL TABLES
*--- BAPI structures
DATA: bapi_head LIKE bapimathead, " Header Segment with Control
bapi_makt LIKE bapi_makt, " Material Description
bapi_mara1 LIKE bapi_mara, " Client Data
bapi_marax LIKE bapi_marax, " Checkbox Structure for BAPI_MARA
bapi_marc1 LIKE bapi_marc, " Plant View
bapi_marcx LIKE bapi_marcx, " Checkbox Structure for BAPI_MARC
bapi_mbew1 LIKE bapi_mbew, " Accounting View
bapi_mbewx LIKE bapi_mbewx, " Checkbox Structure for BAPI_MBEW
bapi_return LIKE bapiret2. " Return Parameter
*--- Internal table to hold excel file data
DATA: it_intern TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
*--- Internal table to hold Matetrial descriptions
DATA: BEGIN OF it_makt OCCURS 100.
INCLUDE STRUCTURE bapi_makt.
DATA: END OF it_makt.
*--- Internal to hold the records in the text file
DATA : BEGIN OF it_data OCCURS 100,
werks(4), " Plant
mtart(4), " Material type
matnr(18), " Material number
matkl(9) , " Material group
mbrsh(1), " Industry sector
meins(3), " Base unit of measure
gewei(3), " Weight Unit
spart(2), " Division
ekgrp(3), " Purchasing group
vprsv(1), " Price control indicator
*stprs(12), " Standard price
peinh(3), " Price unit
*spras(2), " Language key
maktx(40), " Material description
END OF it_data.
SELECTION SCREEN. *
SELECTION-SCREEN BEGIN OF BLOCK scr1 WITH FRAME TITLE text-111.
PARAMETER : p_file TYPE rlgrap-filename OBLIGATORY DEFAULT " Input File
'C:\Material_master.XLS'.
PARAMETER : p_max(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session
PARAMETERS: p_header TYPE i DEFAULT 0. " Header Lines
PARAMETERS: p_begcol TYPE i DEFAULT 1 NO-DISPLAY,
p_begrow TYPE i DEFAULT 1 NO-DISPLAY,
p_endcol TYPE i DEFAULT 100 NO-DISPLAY,
p_endrow TYPE i DEFAULT 32000 NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK scr1.
AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--- Validating file
PERFORM validate_file USING p_file.
START-OF-SELECTION
START-OF-SELECTION.
*--- Perform to convert the Excel data into an internal table
PERFORM convert_xls_itab.
IF NOT it_data[] IS INITIAL.
*--- Perform to delete Header lines
PERFORM delete_header_empty_recs.
ENDIF.
END OF SELECTION. *
END-OF-SELECTION.
*--- Perform to upload Material Master data
PERFORM upload_matmas.
Form : validate_input_file
Description : To provide F4 help for file if read from PC
FORM validate_file USING f_file TYPE rlgrap-filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = f_file
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE s010(zlkpl_msgclass). " 'Error in getting filename'.
ENDIF.
ENDFORM. " validate_input_file
*& Form CONVER_XLS_ITAB
text
FORM convert_xls_itab.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = p_begcol
i_begin_row = p_begrow
i_end_col = p_endcol
i_end_row = p_endrow
TABLES
intern = it_intern.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*--- Perform to move the data into an internal data
PERFORM move_data.
ENDFORM. " CONVERT_XLS_ITAB
*& Form MOVE_DATA
text
FORM move_data.
DATA : lv_index TYPE i.
FIELD-SYMBOLS <fs> .
*--- Sorting the internal table
SORT it_intern BY row col.
CLEAR it_intern.
LOOP AT it_intern.
MOVE it_intern-col TO lv_index.
*--- Assigning the each record to an internal table row
ASSIGN COMPONENT lv_index OF STRUCTURE it_data TO <fs> .
*--- Asigning the field value to a field symbol
MOVE it_intern-value TO <fs> .
AT END OF row.
APPEND it_data.
CLEAR it_data.
ENDAT.
ENDLOOP.
ENDFORM. " MOVE_DATA
*& Form DELETE_HEADER_EMPTY_RECS
To delete the Header and empty records
FORM delete_header_empty_recs.
DATA: lv_tabix LIKE sy-tabix.
IF NOT p_header IS INITIAL.
LOOP AT it_data.
IF p_header > 0 AND NOT it_data IS INITIAL.
DELETE it_data FROM 1 TO p_header.
P_HEADER = 0.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR it_data.
*--- To delete the empty lines from internal table
LOOP AT it_data.
lv_tabix = sy-tabix.
IF it_data IS INITIAL.
v_empty = v_empty + 1.
DELETE it_data INDEX lv_tabix..
ENDIF.
ENDLOOP.
CLEAR it_data.
*--- Total no of recs in file
DESCRIBE TABLE it_data LINES v_total.
IF v_total = 0.
MESSAGE i013(zlkpl_msgclass). " No records in the file
f_stop = 'X'.
STOP.
ENDIF.
ENDFORM. " DELETE_HEADER_EMPTY_RECS
*& Form UPLOAD_MATMAS
to upload Material Master data
FORM upload_matmas .
LOOP AT it_data.
Header
bapi_head-material = it_data-matnr.
bapi_head-ind_sector = it_data-mbrsh.
bapi_head-matl_type = it_data-mtart.
bapi_head-basic_view = 'X'.
bapi_head-purchase_view = 'X'.
bapi_head-account_view = 'X'.
Material Description
REFRESH it_makt.
it_makt-langu = it_data-spras.
it_makt-matl_desc = it_data-maktx.
APPEND it_makt.
Client Data - Basic
bapi_mara1-matl_group = it_data-matkl.
bapi_mara1-base_uom = it_data-meins.
bapi_mara1-unit_of_wt = it_data-gewei.
bapi_mara1-division = it_data-spart.
bapi_marax-matl_group = 'X'.
bapi_marax-base_uom = 'X'.
bapi_marax-unit_of_wt = 'X'.
bapi_marax-division = 'X'.
Plant - Purchasing
bapi_marc1-plant = it_data-werks.
bapi_marc1-pur_group = it_data-ekgrp.
bapi_marcx-plant = it_data-werks.
bapi_marcx-pur_group = 'X'.
Accounting
bapi_mbew1-val_area = it_data-werks.
bapi_mbew1-price_ctrl = it_data-vprsv.
bapi_mbew1-std_price = it_data-stprs.
bapi_mbew1-price_unit = it_data-peinh.
bapi_mbewx-val_area = it_data-werks.
bapi_mbewx-price_ctrl = 'X'.
bapi_mbewx-std_price = 'X'.
bapi_mbewx-price_unit = 'X'.
*--- BAPI to create material
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 =
STORAGELOCATIONDATAX =
VALUATIONDATA = BAPI_MBEW1
VALUATIONDATAX = BAPI_MBEWX
WAREHOUSENUMBERDATA =
WAREHOUSENUMBERDATAX =
SALESDATA = BAPI_MVKE1
SALESDATAX = BAPI_MVKEX
STORAGETYPEDATA =
STORAGETYPEDATAX =
IMPORTING
return = bapi_return
TABLES
materialdescription = it_makt
UNITSOFMEASURE =
UNITSOFMEASUREX =
INTERNATIONALARTNOS =
MATERIALLONGTEXT =
TAXCLASSIFICATIONS =
RETURNMESSAGES =
PRTDATA =
PRTDATAX =
EXTENSIONIN =
EXTENSIONINX =
IF bapi_return-type = 'E'.
WRITE:/ 'Error:' ,bapi_return-message ,'for material:' ,
it_data-matnr.
ELSEIF bapi_return-type = 'S'.
WRITE: 'Successfully created material' ,it_data-matnr.
ENDIF.
ENDLOOP.
ENDFORM. " UPLOAD_MATMASHi bnupur14,
Please do place a debugger @ FM ALSM_EXCEL_TO_INTERNAL_TABLE and check p_file, make p_endcol is 12, p_endrow 65000, then check whether its going for dump or not.
I have executed your code there is no dump @ FM ALSM_EXCEL_TO_INTERNAL_TABLE or converting data into internal table.
But where You are getting Dump actually.
Regards,
Suneel G
Edited by: Suneel Kumar Gopisetty on Aug 19, 2009 11:02 AM -
Can we use BAPI BAPI_ACC_DOCUMENT_POST to upload the vendor invoice?
Hi,
Can anybody tell me, can we use bapi BAPI_ACC_DOCUMENT_POST to upload the vender invoice?
If yes, then which parameters we have to pass, and if no, then which is the other BAPI which is used for
this purpose?
Regards,
MrunalHi Mrunal,
Yes you can use BAPI_ACC_DOCUMENT_POST to upload vendor invoices.
Parameters which are required to be passed are :
Import tab :
DOCUMENTHEADER: Mandatory fields for this specififed in documentation for this.
Table tab:
ACCOUNTGL: Enteries aganist GL account will be populated in this(check documentation for mandatory fields)
ACCOUNTPAYABLE: Enteries aganist vendors will be populated in this(check documentation for mandatory fields)
CURRENCYAMOUNT: in this currency amount aganist GL and vendor entries will specified.
ITEMNO_ACC field will act as identifier as to amount belongs to which GL or vendor enteries.
This much parameter are required to post vendor invoices.
Regards,
Brajvir -
IS THERE ANY SUITABLE BAPI'S To Upload data to F-02 ..OR we should use BDC
HI FRIENDS,
IS THERE ANY SUITABLE BAPI'S To Upload data to F-02 ..OR we should use BDC..
WAITING FOR UR REPLY?
THANKS.
KIRANHi,
I need to change the BDC program which is already written for F-02 in 4.7E.The changes are like I need to add 8 new posting keys, Kindly let me know how I can do it ,if already have the coding for the same please share with me.
Thanks in advance,
Jyoti -
Need BAPI program to upload PO creation with flatfile having HEADER N ITEM
Hi abap experts,
I Need sample BAPI program to upload PO creation(ME21) with flatfile having HEADER AND ITEM datas.
arunHi,
Look at the below links
Re: BAPI_PO_CREATE1 and net price
Re: Using BAPI_PO_CREATE1 : Linking service, and account assignment
Regards
Sudheer -
Suitable BAPI interface to upload data intoKP26 T.code (CO)
Hi All I need to know the BAPI interface to upload the data into KP26 Co Activity type /Price Planning
I have these fields to create entries in KP26 t.code.
The Fields are as follows:
Layout (could use the standard layout 1-201)
1.Version --
2. Period from / to --
3. Fiscal Year -
4. Cost Center -
5. Activity type-
6. Fixed price-
7. Variable price-
8. Price unit---
PLease any body help me which BAPI is suitable for KP26 T.Code .. Its Urgent ...
Regards
Purushotham.Ineni.Hi thank you for kind reply i need to create the entries for CO Activity /Price planning .
i have to upload data to KP26 which i have posted the fields ..
i already cheked the function modules which you have been given .. it is not suitable ..
Is there any ohter BAPI is there ... le t me know ...
regards
purushotham.ineni -
Remote enabled BAPI/RFC to upload a Resume
Is there any Remote enabled BAPI/RFC to upload a Resume and how to assign it to Applicant ?
I need to upload Resume from a .Net program and assign it as attachment or otherwise to Applicant.The reason for posting it here is this:
I used Remote Enabled FM BDS_BUSINESSDOCUMENT_CREATEF to create an attachment (.DOC word document) to APPLICANT Object. It works fine when executed from SE37.
When I execute(call) from .Net code, I get exception "ERROR_KPRO".
So I am looking for ANY way to attach or send Resume document into SAP and some how associating it with APPLICANT object, either by solving ERROR_KPRO or by suggesting any other way...
Thanks for the response -
Reading XML file using BAPI and then uploading that xml file data into SAP
I am getting a xml file from Java server. I need to take
data from this file using BAPI and need to upload into SAP using SAP.
Please tell me how to read XML files using BAPI's.<b>SDIXML_DATA_TO_DOM</b> Convert SAP data (elementary/structured/table types) into DOM (XML
<b>SDIXML_DOM_TO_XML</b> Convert DOM (XML) into string of bytes that can be downloaded to PC or application server
<b>SDIXML_DOM_TO_SCREEN</b> Display DOM (XML)
<b>SDIXML_DOM_TO_DATA</b>
data: it_table like t001 occurs 0.
data: l_dom TYPE REF TO IF_IXML_ELEMENT,
m_document TYPE REF TO IF_IXML_DOCUMENT,
g_ixml TYPE REF TO IF_IXML,
w_string TYPE XSTRING,
w_size TYPE I,
w_result TYPE I,
w_line TYPE STRING,
it_xml TYPE DCXMLLINES,
s_xml like line of it_xml,
w_rc like sy-subrc.
start-of-selection.
select * from t001 into table it_table.
end-of-selection.
initialize iXML-Framework ****
write: / 'initialiazing iXML:'.
class cl_ixml definition load.
g_ixml = cl_ixml=>create( ).
check not g_ixml is initial.
write: 'ok'.
create DOM from SAP data ****
write: / 'creating iXML doc:'.
m_document = g_ixml->create_document( ).
check not m_document is initial.
write: 'ok'.
write: / 'converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'IT_TABLE'
DATAOBJECT = it_table[]
IMPORTING
DATA_AS_DOM = l_dom
CHANGING
DOCUMENT = m_document
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
if sy-subrc = 0. write 'ok'.
else. write: 'Err =', sy-subrc.
endif.
check not l_dom is initial.
write: / 'appending DOM to iXML doc:'.
w_rc = m_document->append_child( new_child = l_dom ).
if w_rc is initial. write 'ok'.
else. write: 'Err =', w_rc.
endif.
visualize iXML (DOM) ****
write: / 'displaying DOM:'.
CALL FUNCTION 'SDIXML_DOM_TO_SCREEN'
EXPORTING
DOCUMENT = m_document
EXCEPTIONS
NO_DOCUMENT = 1
OTHERS = 2.
if sy-subrc = 0. write 'ok'.
else. write: 'Err =', sy-subrc.
endif.
convert DOM to XML doc (table) ****
write: / 'converting DOM TO XML:'.
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
DOCUMENT = m_document
PRETTY_PRINT = ' '
IMPORTING
XML_AS_STRING = w_string
SIZE = w_size
TABLES
XML_AS_TABLE = it_xml
EXCEPTIONS
NO_DOCUMENT = 1
OTHERS = 2.
if sy-subrc = 0. write 'ok'.
else. write: 'Err =', sy-subrc.
endif.
write: / 'XML as string of size:', w_size, / w_string.
describe table it_xml lines w_result.
write: / 'XML as table of', w_result, 'lines:'..
loop at it_xml into s_xml.
write s_xml.
endloop.
write: / 'end of processing'.
end of code
Hope this will be useful.
regards
vinod -
Doubt on Good movements using BAPI'S for Uploading
Hi Experts,
i am doing a bdc program to upload for mb1a transaction using BAPI..I am new to BAPI area..But with some reference i have finished the program..But i dont know why in clear statement and in gui upload showing error..IN gui upload when i activate the exception its throwing error..Hereby i am pasting the code...Any idea pls share with me..
<removed by moderator>
I dont know how to make the code show correctly...any help???????
Regards
Karthick
Moderator message: please post only relevant code parts, observe the maximum of 5000 characters per post to preserve formatting, leave out commented lines, etc.
Edited by: Thomas Zloch on Feb 10, 2011 6:05 PM
sorry moderator...it will not happen again..
my scenario is like this i ahve to upload the serial number with respect to the quantity in unit of measure..i am not getting any idea on this..for example if the quantity for the material is 5 then it has to upload five serial numbers...
please help me on this!!!!!!!!
regards
Karthick
Edited by: karthicksap on Feb 12, 2011 5:25 AMHi kris,
Finally i finished the coding..its working fine...but now its throwing material is not maintained in plant..checked with that..but material is maintained there..i dont know why its throwing the error..i checked with debugging and i found that its taking the last serial number only..for every material..my flatfile is like this..
11.01.2011 11.01.2011 abc 9051 5101 stbdx300 3 600001 0 1000000000000001
11.01.2011 11.01.2011 abc 9051 5101 stbdx300 3 600001 0 1000000000000002
11.01.2011 11.01.2011 abc 9051 5101 stbdx300 3 600001 0 1000000000000003
any idea kris.>?????
regards
Karthick -
Error in bapi BAPI_PR_CREATE while uploading
HI Gurus,
I have program for uploading PR with BAPI. BAPI_PR_CREATE.
while uploading without account assignment category it is working fine.
while enter account assignment category v need to enter sales order no and item no. that is mandatory field for account assignment category..
if using program its showing error.
No instance of object type Purchase Requisition has been created. External reference: # 1
Enter sales order
Sd document XXXXXXX is not in the database or has been archived.
but I tried to create manually it is working fine.
I tried to upload with bapi directly with out z program.
tht time also it showing error
No instance of object type Purchase Requisition has been created. External reference: # 1
Enter sales order
If any one give solution
it is very helpful for me.Hi
Thnaks for the Reply,
in normal scenario it ll upload base on header.
if header change it ll generate automatically requisition no. So in program v used AT END OF pr_type.
so if pr_type is diff it will work.
in my case only one header it will not change. v hav only one pr type.
it should generate based on Item.
If item 10 it should generate new requisition No.
my flat file is ,
pr type - material - pur org - plant - storage loc - qty - traking no - .... pr item
xxx abc pqr 1000 xyz 100 11111 10
xxx abc pqr 1000 xyz 200 11111 20
xxx abc pqr 1000 xyz 300 11111 30
xxx abc pqr 1000 xyz 400 11111 10
xxx abc pqr 1000 xyz 500 11111 20
here header is same.. if pr item 10 it should generate new requisition No, means it should commit before value 10.
so before commit v hav to give the logic if item 10 it should generate for before value.
hope u got my requirement. -
Using bapi how to upload the data into sap database?
hi dear all,
im facing problem with bapi ? let me edcuate on bapi ..
i will be waiting for reply.
my e-id :[email protected]
thanks®ards
shiva.Hi
A BAPI is a method of a SAP Business Object. BAPI enables SAP and third party applications to interact and integrate
with each other at the Business Object / Process level.
Check this link to know more about BAPI.
http://www.sapgenie.com/abap/bapi/example.htm
http://sappoint.com/abap/
Batch Data Communication (BDC) is the oldest batch interfacing technique that SAP provided since the early versions of R/3. BDC is not a
typical integration tool, in the sense that, it can be only be used for uploading data into R/3 and so it is not bi-directional.
BDC works on the principle of simulating user input for transactional screen, via an ABAP program. Typically the input comes in the form
of a flat file. The ABAP program reads this file and formats the input data screen by screen into an internal table (BDCDATA). The
transaction is then started using this internal table as the input and executed in the background.
In Call Transaction, the transactions are triggered at the time of processing itself and so the ABAP program must do the error handling.
It can also be used for real-time interfaces and custom error handling & logging features. .
To know more about BDC,
check the link.
http://sappoint.com/abap/
Main differences are...
In case of bdc data transfer takes place from flat file into sap system ie the file existing in sap system to sap sytem
where is bapi's r remotly enabled function modules which are assigned to some business objects n used to transfer the data between different business partners who are using different systems other than sap.
not only that...
when you plan to upgrade your system version then bdc willnot support those upgradations where as bapi's will support.
http://www.sap-img.com/abap/ale-bapi.htm
SAP BAPI
BAPI STEPS
Hope this helps.
ashish -
hi guys,
any BAPI/FM that can be used to upload PGI, i need to put in the storage location for every DOHi,
Please try to use FM WS_DELIVERY_UPDATE.
DATA:
L_VBELN LIKE LIKP-VBELN,
L_VBKOK LIKE VBKOK,
L_PROTT LIKE PROTT OCCURS 0 WITH HEADER LINE.
* carry out goods issue
L_VBKOK-VBELN_VL = L_VBELN. <-- fill this field with your delivery number
L_VBKOK-WABUC = 'X'.
CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
VBKOK_WA = L_VBKOK
SYNCHRON = 'X'
NO_MESSAGES_UPDATE = ' '
UPDATE_PICKING = 'X'
COMMIT = ' '
DELIVERY = L_VBELN
NICHT_SPERREN = 'X'
TABLES
PROT = L_PROTT
EXCEPTIONS
OTHERS = 0.
COMMIT WORK AND WAIT.
Regards,
Ferry Lianto -
DMS - BAPI - BAPI_DOCUMENT_CHECKIN2 - No upload to server
Hi,
I am having a problem with BAPI_DOCUMENT_CHECKIN2. I use it to checkin a document into an existing Document info record.
Example of how I am using the BAPI:
REPORT ztestdms .
DATA: it_files LIKE TABLE OF bapi_doc_files2 WITH HEADER LINE.
DATA: ln_return LIKE bapiret2.
it_files-docfile = 'C:tempDMS_Test.txt'.
it_files-wsapplication = 'TXT'.
APPEND it_files.
CALL FUNCTION 'BAPI_DOCUMENT_SETCOMMITMODE'
EXPORTING
auto_commit = 'X'.
CALL FUNCTION 'BAPI_DOCUMENT_CHECKIN2'
EXPORTING
documenttype = 'TEK'
documentnumber = '0000000000000010000000046'
documentpart = '000'
documentversion = '00'
* HOSTNAME = ' '
* STATUSINTERN = ' '
* STATUSEXTERN = ' '
statuslog = 'test mb'
* REVLEVEL = ' '
* AENNR = ' '
* PF_FTP_DEST = ' '
* PF_HTTP_DEST = ' '
IMPORTING
return = ln_return
TABLES
documentfiles = it_files
* COMPONENTS =
* DOCUMENTSTRUCTURE =
WRITE ln_return.
The BAPI links the file to the DIR but does not upload it, the lock symbol in transaction CV02N is still open and the file is still available at the client. A manual checkin completes the process but this is not wanted.
What I would like to happen is the file to be uploaded (actually checked in) and removed from the client.
Any help is welcome and thanks in advance.Sunil,
I am having the same problem and have already created an OSS note for SAP in which they reply:
<i>However, as you use Visual Basic, your query represents
a consulting issue rather than a problem based on a
software error in R/3 (as you said, the BAPI works in TA
se37). Therefore, I would ask you to contact our Remote
Consulting and to open a new call under component XX-RC.
Our consultants will assist you.
Nevertheless, you could also try to use CVAPI_DOC_CHECKIN
instead of BAPI_DOCUMENT_CHECKIN2, API-s are much more
flexible than BAPI-s.
Thank you for your understanding.!
</i>
I have just finished testing this other function but it has the same result. Below you will find an example program with this other function.
Function SAPCheckinExample()
Dim R3 As Object
Dim conn As Connection
Dim rfcFunc As SAPFunctionsOCX.Function
Dim PF_DOKAR As Object, PF_DOKNR As Object, PF_DOKTL As Object
Dim PF_DOKVR As Object, PSX_MESSAGE As Object, PT_FILES_X As Object
Dim PS_DOC_STATUS As Object
Dim blnResult As Boolean
Dim strMsg As String, strTtl As String, intStl As Integer, strTyp As String
'**** Change these constants as desired *************************************
Const strApplicationServer = "ur_server"
Const strSystemNumber = "XX"
Const strClient = "XXX"
Const strLanguage = "EN"
Const strDocTyp As String = "TEK"
Const strDocNum As String = "0000000000000010000000045"
Const strDocPrt As String = "000"
Const strDocVer As String = "06"
Const strFile As String = "C:CADDEV_RFC.TXT"
Const strApplication As String = "TXT"
Const strStorage As String = "DMS_C1_ST"
'**** Program extract *******************************************************
' Create a new connection object
Set R3 = CreateObject("SAP.Functions")
Set conn = R3.Connection
' Set the logon parameters
'R3.LogFileName = "C:WINDOWSDESKTOPSAPLOG.TXT"
conn.ApplicationServer = strApplicationServer
conn.SystemNumber = strSystemNumber
conn.Client = strClient
conn.Language = strLanguage
conn.AutoLogon = True
' Logon
If conn.Logon(0, False) <> True Then
strMsg = "Logon failure!"
strTtl = "Logon"
intStl = vbOKOnly & vbExclamation
MsgBox strMsg, intStl, strTtl
Exit Function
End If
' Create the checkin rfc in the connection object
Set rfcFunc = R3.Add("CVAPI_DOC_CHECKIN")
' Link the parameters from the rfc to the objects called in this function
With rfcFunc
Set PF_DOKAR = .Exports("PF_DOKAR")
Set PF_DOKNR = .Exports("PF_DOKNR")
Set PF_DOKTL = .Exports("PF_DOKTL")
Set PF_DOKVR = .Exports("PF_DOKVR")
Set PS_DOC_STATUS = .Exports("PS_DOC_STATUS")
Set PSX_MESSAGE = .Imports("PSX_MESSAGE")
Set PT_FILES_X = .Tables("PT_FILES_X")
End With
' Set the parameters for the rfc
PF_DOKAR.Value = strDocTyp ' Document Type
PF_DOKNR.Value = strDocNum ' Document number
PF_DOKTL.Value = strDocPrt ' Document Part
PF_DOKVR.Value = strDocVer ' Document Version
With PT_FILES_X
.Rows.Add
.Value(1, "PATHNAME") = strFile
.Value(1, "DAPPL") = strApplication
.Value(1, "STORAGE_CAT") = strStorage
End With
' Call the rfc
blnResult = rfcFunc.Call
Debug.Print blnResult ' True if the function is called succesfully
'Check if the rfc is executed correctly
Set PSX_MESSAGE = rfcFunc.Imports("PSX_MESSAGE")
Debug.Print PSX_MESSAGE("MSG_TYPE"); PSX_MESSAGE("MSG_ID"); PSX_MESSAGE("MSG_NO"); PSX_MESSAGE("MSG_TXT")
strTyp = PSX_MESSAGE("MSG_TYPE")
strMsg = PSX_MESSAGE("MSG_TXT")
Select Case strTyp
Case "S"
intStl = vbOKOnly + vbInformation
strTtl = "Info"
Case "I"
intStl = vbOKOnly + vbInformation
strTtl = "Info"
Case "E"
intStl = vbOKOnly + vbExclamation
strTtl = "Error!"
Case "W"
intStl = vbOKOnly + vbExclamation
strTtl = "Error!"
Case "A"
intStl = vbOKOnly + vbCritical
strTtl = "Critical error!"
End Select
conn.Logoff
If strMsg = "" Then
strMsg = "File checked in!"
strTtl = "Info"
intStl = vbOKOnly + vbInformation
MsgBox strMsg, intStl, strTtl
Else
MsgBox strMsg, intStl, strTtl
End If
End Function
Message was edited by: Maurice Brouwers -
BAPI Needed of uploading document in already existing Dispute Case
Hi,
I need BAPI for uploading document in already existing Dispute Case...
Thanks,
AjitI tried to use the following program to upload a document and it is not working, any feedback would be helpful:
*& Report ZTEMP_DISPUTE_12
REPORT ztemp_dispute_12.
PARAMETER : l_fname TYPE char255.
DATA : l_file TYPE string,
lv_xstring TYPE xstring,
l_return TYPE bapiret2,
l_filecontent TYPE bapiconten,
i_case TYPE REF TO if_scmg_case_api,
l_initial_dir TYPE string,
l_window_title TYPE string,
l_filename_disp TYPE string,
l_filename_string TYPE string,
l_user_action TYPE i,
l_rc TYPE i,
l_v_lines TYPE i,
l_mime TYPE skwf_mime,
l_filelength TYPE i,
l_component TYPE bapidoccomp,
l_skwf_filnm TYPE skwf_filnm,
li_file_tab TYPE filetable,
lwa_file_tab TYPE file_table,
li_bin_content TYPE STANDARD TABLE OF bapiconten,
l_v_size TYPE i.
DATA: BEGIN OF itab OCCURS 0,
line TYPE sdok_sdatx.
DATA: END OF itab.
DATA: BEGIN OF i_component OCCURS 0,
comp_count TYPE bapipos,
comp_id TYPE bapidocid,
mimetype TYPE bapimimetype,
comp_size TYPE bapipos,
binary_flag TYPE bapigsbool,
comp_num TYPE bapipos.
DATA: END OF i_component.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR l_fname.
l_window_title = 'Upload Document'(001).
Call the file selection dialog
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = l_window_title
initial_directory = l_initial_dir
CHANGING
file_table = li_file_tab
rc = l_rc
user_action = l_user_action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc = 0.
READ TABLE li_file_tab INTO lwa_file_tab INDEX 1.
IF sy-subrc = 0.
l_file = lwa_file_tab-filename.
l_fname = lwa_file_tab-filename.
ENDIF.
ENDIF.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = itab
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.
DESCRIBE TABLE itab LINES l_v_lines.
l_v_size = l_v_lines * 255.
l_filename_string = l_file.
CALL METHOD cl_gui_frontend_services=>file_get_size
EXPORTING
file_name = l_filename_string
IMPORTING
file_size = l_v_size
EXCEPTIONS
OTHERS = 1.
convert binary255 to binary1024 table
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = l_v_size
IMPORTING
buffer = lv_xstring
TABLES
binary_tab = itab
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
rv_failed = 'X'.
RETURN.
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
TABLES
binary_tab = li_bin_content.
l_skwf_filnm = l_file.
CALL FUNCTION 'SKWF_MIMETYPE_OF_FILE_GET'
EXPORTING
filename = l_skwf_filnm
X_USE_LOCAL_REGISTRY =
IMPORTING
mimetype = l_mime.
l_component-comp_count = 1.
l_component-comp_id = l_fname.
l_component-mimetype = l_mime.
l_component-comp_size = l_v_size.
l_component-binary_flag = 'X'.
l_component-comp_num = 1.
APPEND l_component TO i_component.
DATA:
lo_case_api TYPE REF TO cl_scmg_case_api,
lo_case_api_intf TYPE REF TO if_scmg_case_api.
CALL METHOD cl_scmg_case_api=>if_scmg_case_api~open_case
EXPORTING
im_case_guid = 'E99B284FC272B720E100000092D79319'
im_enqueue = 'X'
RECEIVING
re_case = lo_case_api_intf
EXCEPTIONS
failed = 1
enqueue_failed = 2
invalid_guid = 3
cx_srm_gsp_back = 4
OTHERS = 5.
lo_case_api ?= lo_case_api_intf.
*DATA : l_if_case_api TYPE REF TO if_scmg_case_api.
CALL METHOD cl_scmg_case_api=>open_case
EXPORTING
im_case_guid = 'E99B284FC272B720E100000092D79319'
RECEIVING
re_case = l_if_case_api
EXCEPTIONS
failed = 1
enqueue_failed = 2
invalid_guid = 3
cx_srm_gsp_back = 4
no_authority = 5
OTHERS = 6.
CALL FUNCTION 'UDM_BD_CREATE_ATTACHMENT'
EXPORTING
i_guid = 'E99B284FC272B720E100000092D79319' "E99B284FC272B720E100000092D79319
i_case = lo_case_api
i_testrun = space " '003A3A4FAD54D97CE100000092D79319'
TABLES
bin_content = li_bin_content
components = i_component
CHANGING
es_return = l_return.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
CALL FUNCTION 'DEQUEUE_ALL'.
break 50120i1120.
Maybe you are looking for
-
I have a HP laptop & Dell desktop with IE7 and Firefox. I use Firefox more as I like it better than IE, yet the pages in Firefox load so slow. I thought the new version of Firefox was so much faster, but it seems to drag along and take forever to loa
-
Can i upgrade 8.6 to osx on an imac g3?
i'm looking at getting one since my ibook died and i'm skint bit the one i wnt runs on 8.6. is it possible to update it to 10.2.8ish? how easy is this to do? thank you for your help, lou x
-
Business system for idoc reciver communication channel.
hi gurus, iam doing one file to idoc scenerio. for defining reciver idoc adapter ,which type of businees system i required that is configured in SLD. pls guide me . warm regards.
-
IWeb - Main Navigation bar not showing up in Safari
After publishing my site to a folder and uploading to the net the navigation menu is no where to be found. Yet when I publish to a folder and click on the "view site now" button everything looks normal - anyone else have this problem
-
Ive already done this, I added two songs from iTunes to my project but they just overlap and it sounds horrible....Can I take out pieces of a song and put another after it?