BAPI SAMPLE CODE FOR FLAT FILE in SAP ABAP
REPORT ZBAPI.
DATA: BEGIN OF i_data OCCURS 0,
text(255),
END OF i_data.
DATA: i_ekko TYPE bapiekkoc.
DATA: it_ekko LIKE TABLE OF i_ekko INITIAL SIZE 0 WITH HEADER LINE.
DATA: BEGIN OF i_ekpo OCCURS 0,
po_item(5),
pur_mat(18),
plant(4),
net_price(23),
disp_quan(13),
END OF i_ekpo.
DATA: it_ekpo LIKE TABLE OF bapiekpoc INITIAL SIZE 0 WITH HEADER LINE .
DATA: BEGIN OF i_eket OCCURS 0,
po_item(5),
deliv_date(8),
quantity(13),
END OF i_eket.
DATA: it_eket LIKE TABLE OF bapieket INITIAL SIZE 0 WITH HEADER LINE.
DATA: v_index TYPE i.
DATA: return TYPE TABLE OF bapireturn INITIAL SIZE 0 WITH HEADER LINE.
DATA: po_num(10).
START-OF-SELECTION.
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = ' '
FILETYPE = ' '
ITEM = ' '
FILEMASK_MASK = ' '
FILEMASK_TEXT = ' '
FILETYPE_NO_CHANGE = ' '
FILEMASK_ALL = ' '
FILETYPE_NO_SHOW = ' '
LINE_EXIT = ' '
USER_FORM = ' '
USER_PROG = ' '
SILENT = 'S'
IMPORTING
FILESIZE =
CANCEL =
ACT_FILENAME =
ACT_FILETYPE =
TABLES
data_tab = i_data
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7
.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at i_data.
if i_data-text(1) = 'H'.
shift i_data-text.
v_index = v_index + 1.
split i_data-text at ',' into i_ekko-doc_type
i_ekko-purch_org
i_ekko-pur_group
i_ekko-vendor.
append i_ekko to it_ekko.
elseif i_data-text(1) = 'I'.
shift i_data-text.
split i_data-text at ',' into i_ekpo-po_item
i_ekpo-pur_mat
i_ekpo-plant
i_ekpo-net_price
i_ekpo-disp_quan.
append i_ekpo.
move-corresponding i_ekpo to it_ekpo.
append it_ekpo.
clear it_ekpo.
else.
shift i_data-text.
split i_data-text at ',' into i_eket-po_item
i_eket-deliv_date
i_eket-quantity.
append it_eket .
move-corresponding i_eket to it_eket.
append it_eket.
clear it_eket.
endif.
endloop.
CALL FUNCTION 'BAPI_PO_CREATE'
EXPORTING
po_header = i_ekko
PO_HEADER_ADD_DATA =
HEADER_ADD_DATA_RELEVANT =
PO_ADDRESS =
SKIP_ITEMS_WITH_ERROR = 'X'
ITEM_ADD_DATA_RELEVANT =
HEADER_TECH_FIELDS =
IMPORTING
PURCHASEORDER =
tables
po_items = it_ekpo
PO_ITEM_ADD_DATA =
po_item_schedules = it_eket
PO_ITEM_ACCOUNT_ASSIGNMENT =
PO_ITEM_TEXT =
RETURN = return
PO_LIMITS =
PO_CONTRACT_LIMITS =
PO_SERVICES =
PO_SRV_ACCASS_VALUES =
PO_SERVICES_TEXT =
PO_BUSINESS_PARTNER =
EXTENSIONIN =
POADDRDELIVERY =
.
write: po_num.
loop at return.
write:/ return-message,return-type.
endloop.
0 Comments