Anda di halaman 1dari 4

type-pools: slis.

types: begin of t_purchase, vendor(10) type c, purch_org(4) type c, pur_group(3) type c, comp_code(4) type c, po_item(5) type n, material(18) type c, quantity(13) type i, ewerk(4) type c, end of t_purchase, BEGIN OF t_error, msg TYPE string, typ(2) TYPE c, order(10) TYPE c, END OF t_error. data: i_purchase type table of t_purchase, i_header type table of bapimepoheader, i_headerx type table of bapimepoheaderx, i_item type table of bapimepoitem, i_itemx type table of bapimepoitemx, i_return type table of bapiret2, i_error type table of t_error, i_fieldcatalog type table of slis_fieldcat_alv, w_purchase type t_purchase, w_header type of bapimepoheader, w_headerx type of bapimepoheaderx, w_item type of bapimepoitem, w_itemx type of bapimepoitemx, w_return type of bapiret2, w_error type of t_error, w_fieldcatalog type of slis_fieldcat_alv, v_file type string, v_repid type sy-repid, v_dynnr type sy-dynnr. SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME. parameters: p_file type ibipparms-path. SELECTION-SCREEN END OF BLOCK B. *perform initialize. v_repid = sy-repid. v_dynnr = sy-dynnr. AT SELECTION-SCREEN on VALUE REQUEST FOR p_file. *perform file_path. CALL FUNCTION 'F4_FILENAME' EXPORTING

program_name dynpro_number field_name IMPORTING file_name v_file = p_file.

= v_repid = v_dynnr = P_FILE = p_file.

*perform upload. FORM upload . CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = v_file filetype = 'DAT' has_field_separator = 'X' TABLES data_tab = i_purchase 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. *perform bapi_purchase. LOOP AT i_purchase INTO w_purchase. CLEAR: w_header, w_headerx. W_header-vendor = w_purchase-vendor. W_header-purch_org = w_ purchase-purch_org. W_header-pur_group = w_ purchase-pur_group. W_header-comp_code = w_ purchase-comp_code. APPEND w_header into i_header. w_headerx-vendor = X. w_headerx-purch_org = X. w_headerx-pur_group = X. w_headerx-comp_code = X. APPEND w_headerx into i_headerx.

CLEAR: w_item, w_itemx. w_item-po_item = w_ purchase-po_item. w_item-material = w_ purchase-material. w_item-quantity = w_ purchase-quantity. w_item-ewerk = w_ purchase-ewerk. APPEND w_item to i_item. w_itemx-po_item = X. w_itemx-material = X. w_itemx-quantity = X. w_itemx-ewerk = X. APPEND w_itemx to i_itemx. CALL FUNCTION BAPI CREATE ORDER.. Clear w_purchase. ENDLOOP. LOOP AT i_return INTO w_return. IF w_return-type = 'E'. w_error-typ = w_return-type. w_error-msg = w_return-message. w_error-order = v_salord. APPEND w_error TO i_error. CLEAR: w_return, w_error. ENDIF. ENDLOOP. IF i_error IS NOT INITIAL. PERFORM fieldcatalog. PERFORM display.