Sap Bsp Upload File Store in Sap Table
Uploading a file into a SAP BSP application is really straight forwards and if yous follow the steps beneath you tin accept it upward and running in a few minutes.
Pace 1 - Create new BSP Application
Using SE80 create BSP Awarding (I.e. ZTESTBSP).
Step 2 - Create new page (index.htm)
Correct click on the BSP object name and select create->page (with flow logic).
Pace 3 - Populate 'Layout' tab
Add the following code into the layout department of the new page (alphabetize.htm). Save and activate the page and bsp object.
<%@folio language="abap" %> <%@extension proper name="htmlb" prefix="htmlb" %> <grade method="Mail" enctype="multipart/form-data"> Please enter your file name by using the scan push button: <br><input size="40" type="file" name="filename"> <br><input type=submit name="onInputProcessing(upload)" value="Upload"> </grade>
Step 4 - Populate 'OnInputProcessing'
Within the 'Event Handler' tab add together the following code to the OnInputProcessing event.
* event handler for checking and processing user input and * for defining navigation * data declarations data: ld_value type string, ld_entity type ref to if_http_entity, ld_data type xstring, ld_datatmp blazon xstring, ld_filename blazon cord, ld_type type string, ld_length type string, ld_lengthtmp type string, ld_numparts blazon i, wa_binary_content type SDOKCNTBIN, it_binary_content type O2_DATA_TABLE. data: ld_datastring type string. information: it_stringtab blazon standard table of cord. data: ld_contsize type i. types: begin of t_char, text(1022) blazon c, cease of t_char. data: it_chartab type STANDARD Tabular array OF t_char. *Constants for file processing constants: con_tab blazon c value cl_abap_char_utilities=>HORIZONTAL_TAB, new_line type c value cl_abap_char_utilities=>NEWLINE, cf type c value cl_abap_char_utilities=>CR_LF. *User action value case event_id. when 'upload'. * find number of multiparts of file ld_numparts = request->num_multiparts( ). do ld_numparts times. ld_entity = request->get_multipart( sy-index ). ld_value = ld_entity->get_header_field( '~content_filename' ). if not ld_value is initial. ld_filename = ld_value. ld_type = ld_entity->get_header_field( 'Content-Type' ). * Go file content ld_data = ld_entity->get_data( ). * Get size of file ld_length = xstrlen( ld_data ). * Move BINARY data into itab 1022 characters at a fourth dimension ld_datatmp = ld_data. ld_lengthtmp = ld_length. while ld_lengthtmp > 1022. wa_binary_content-line = ld_datatmp(1022). suspend wa_binary_content to it_binary_content. shift ld_datatmp by 1022 places in byte fashion. ld_lengthtmp = xstrlen( ld_datatmp ). endwhile. * Move rest of file into table wa_binary_content-line = ld_datatmp. append wa_binary_content to it_binary_content. * Convert binary data table into char table, retains line breaks and * put each line of file into new tabular array row ld_contsize = ld_lengthtmp. Call FUNCTION 'SCMS_BINARY_TO_TEXT' EXPORTING INPUT_LENGTH = ld_contsize * FIRST_LINE = 0 * LAST_LINE = 0 APPEND_TO_TABLE = '10' * MIMETYPE = ' ' * WRAP_LINES = ' ' * ENCODING = * IMPORTING * OUTPUT_LENGTH = TABLES BINARY_TAB = it_binary_content TEXT_TAB = it_chartab EXCEPTIONS FAILED = 1 OTHERS = ii. * Catechumen binary information table into string field Phone call Function 'SCMS_BINARY_TO_STRING' EXPORTING INPUT_LENGTH = ld_contsize * FIRST_LINE = 0 * LAST_LINE = 0 * MIMETYPE = ' ' * ENCODING = IMPORTING TEXT_BUFFER = ld_datastring * OUTPUT_LENGTH = TABLES BINARY_TAB = it_binary_content EXCEPTIONS FAILED = i OTHERS = 2. * Dissever string value at line breaks into rows of itab split ld_datastring AT new_line INTO TABLE it_stringtab. endif. enddo. endcase.
Step five - Activate and test
Salve everything and printing the activate button, if all is ok return the the index.htm page and press the test button, this should open up up a browser window and display your newly created BSP.
Click the scan push button and choose your filename from the standard windows file browser functionality and then press upload.
Stride 6 - What should happen??
Well actually naught visually! To make this example as simple equally possible to implement, when you click the upload push button nix should happen on screen, but if you place an external breakpoint at the finish of the code and and so press the upload button you lot should meet that the data from your file is contained inside the following variables in different formats:
ld_datastring - File information stored as a unmarried string value including newline values
it_chartab - File information stored equally a char tabular array with each line of data appearing in a new table row (express row length)
it_datastring - File data stored equally a string table with each line of information appearing in a new table row (allows for larger strings of data per row)
Come across hither for more data and examples of BSP development
Source: https://www.trailsap.com/dev/sap-webapps/bsp/?topic=bsp-upload
Postar um comentário for "Sap Bsp Upload File Store in Sap Table"