Application Development and Automation 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: 
Read only

How do I connect bapi_billingdoc_Create to a open data set upload program

Former Member
0 Likes
453

Hell all, Im doing a project where I need to write an upload program to intake a pipe delimited file from the server and then automatically create an invoice in the background for them. so far heres the code for the upload and it works fine. But I am lost when it comes to connecting the two and the bapi aspect. Please help! thanks!

types: begin of ty_string,
str(1000) type c,
end of ty_string.

data it_final type table of ty_string.
data wa_final type ty_string .


types: begin of ty_split,
*
document_no(20) type c,
document_date(20) type c,
document_amount(20) type c,
document_type(20) type c,
description(20) type c,
vendor_id(20) type c,
image_id(20) type c,
po_number(20) type c,
voucher_no(20) type c,
location(20) type c,
item_code(20) type c,
item_description(20) type c,
po_no(20) type c,
po_line_num(20) type c,
amount(20) type c,
gl_account(20) type c,
profit_center(20) type c,
cost_center(20) type c,
company_code(20) type c,
project_code(20) type c,
purchase_org(20) type c,



end of ty_split.

data: it_split type table of ty_split with header line.
data: wa_split type ty_split.

DATA: v_excel_string(2000) TYPE c,
v_file LIKE v_excel_string VALUE 'D:\TEST\TEST1.CSV', " name of the file
delimiter TYPE c VALUE '|'. " delimiter with default value space

"--------------------selection--screen-------------------------

SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE text-100.
SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK pipe_file
WITH FRAME TITLE text-101.
PARAMETERS:p_path TYPE rlgrap-filename
MEMORY ID xw2,
p_folder TYPE string LOWER CASE,
p_arch TYPE string LOWER CASE.

SELECTION-SCREEN END OF BLOCK pipe_file.


SELECTION-SCREEN END OF BLOCK 1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

* Get the filename from the user
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = ' '
* DEF_PATH = ' '
mask = ',*.txt,*.*.'
* MODE = '0'
title = 'Upload File'(078)
IMPORTING
filename = p_path
* RC = L_RC
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder.
cl_gui_frontend_services=>directory_browse(
EXPORTING
window_title = 'Select import location'
initial_folder = p_folder
CHANGING
selected_folder = p_folder
).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_arch.
cl_gui_frontend_services=>directory_browse(
EXPORTING
window_title = 'Select archive location'
initial_folder = p_arch
CHANGING
selected_folder = p_arch
).
"----------------------------program code--------------------------------------------

START-OF-SELECTION.

v_file = p_path.

OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
WRITE:/ 'error opening file'.
ELSE.
DO." sy-subrc EQ 0 ).
READ DATASET v_file INTO wa_final.
IF sy-subrc = 0. "wa_it_final IS INITIAL.
SPLIT wa_final-str AT '|' INTO

wa_split-document_no
wa_split-document_date
wa_split-document_amount
wa_split-document_type
wa_split-description
wa_split-vendor_id
wa_split-image_id
wa_split-po_number
wa_split-voucher_no
wa_split-location
wa_split-item_code
wa_split-item_description
wa_split-po_no
wa_split-po_line_num
wa_split-amount
wa_split-gl_account
wa_split-profit_center
wa_split-cost_center
wa_split-company_code
wa_split-project_code
wa_split-purchase_org.

APPEND wa_split TO it_split.

WRITE:/ wa_split-document_no,
wa_split-document_date,
wa_split-document_amount,
wa_split-document_type,
wa_split-description,
wa_split-vendor_id,
wa_split-image_id,
wa_split-po_number,
wa_split-voucher_no,
wa_split-location,
wa_split-item_code,
wa_split-item_description,
wa_split-po_no,
wa_split-po_line_num,
wa_split-amount,
wa_split-gl_account,
wa_split-profit_center,
wa_split-cost_center,
wa_split-company_code,
wa_split-project_code,
wa_split-purchase_org.


" APPEND wa_final TO it_final.
ELSE.
EXIT.
ENDIF.
CLEAR wa_final.
ENDDO.
ENDIF.
CLOSE DATASET v_file.

0 REPLIES 0