This is the sixty-ninth article of Jerry in 2021, and the 346th official account of the Wang Zixi public number.
SAP ui5 sap ui. unified. The fileuploader control, combined with the gateway framework, is not a difficult thing to upload local files to the ABAP server.
However, due to the limitations of the objective conditions of project implementation, how can it be realized without using the two frameworks of SAP ui5 and SAP ABAP gateway?
This is a question a friend asked me recently. In fact, I did something similar as early as 2014. This paper introduces the requirements and steps of file upload by pure manual front-end and back-end programming without using SAP ui5 and SAP ABAP gateway framework.
Let’s understand the implementation details of this requirement from the implementation of the front-end and back-end layers.
Front end implementation
The front-end code is relatively simple, with only 30 lines of code. Create a new HTML file and paste these 30 lines of code.
The design idea is summarized as the following 7 points. Friends who need complete source code, please start from thislinkget.
(1) Define a native form element, and use the enctype field to specify that the encoding format of the form sent to the server is multipart / form data
(2) The data of the form is sent to the server using the HTTP post method.
(3) The form contains three input controls, which are email, text and file The local file upload function introduced in this article is completed with the help of the input control with the type of file in line 8. After clicking the hyperlink implemented with a tag in line 11, the sendform function bound to a tag triggers to send data.
(4) Pass all the data in the form through DOM API document forms. The nameditem is parsed and put into the variable OData
(5) Line 17 demonstrates the method of adding new content to the form data to be sent to the server through code.
(6) This line maintains the specific address where the form data is sent to the ABAP server, and its SiCf path is / SAP / CRM / file_ upload.
After the file is uploaded to the ABAP server, how do we verify whether the upload is successful and whether the content is correct? For verification purposes, I hard coded a sales order ID 55824 After the file is uploaded successfully, I create the uploaded file as an attachment of the sales order in SAP CRM system.
(7) Call the send method of the native API XMLHttpRequest to transfer the form data to the ABAP server.
Open the HTML file, as shown in the figure below, and click the hyperlink to upload the file.
The contents of the text file to be uploaded are as follows:
ABAP backend implementation
Because we do not use any back-end framework, this means that we must parse and process the multipart / form data format data sent by the client based on the bottom HTTP protocol.
First, in the transaction code SiCf, according to the path SAP / CRM / file in the front-end code_ Upload, create a new processing node with the same path.
For more information about SiCf, please refer to Jerry’s article:From the SiCf of ABAP NetWeaver to the lambda function of SAP kyma.
Create a processing class ZCL for this node_ FILE_ Upload, all the back-end processing logic in this article, is written in the handle of this class_ In request.
The complete back-end code can also be obtained from thislinkYes, this article will not post all of them, but only introduce the main points.
The input values maintained through the three input controls of the front-end form, plus the custom form data in the front-end code, are separated by the formboundary randomly generated by the browser. The complete data of the submitted form can be observed in the chrome Developer Tool Network tab.
ZCL_ FILE_ The implementation logic of the upload class is to first parse the formboundary identifier sent by the browser, split the received form data into blocks according to the boundary, and then only deal with the block that we are interested in including the upload of local files.
We just showed the details of the form data sent to the ABAP server in the chrome developer tool. After these data are received on the ABAP server, they are displayed in the debugger as follows:
What do these well marks mean? Use the drop-down menu highlighted in the figure above to switch the fast display to HTML browser at a glance. Originally, these line breaks, carriage return line breaks and other control characters are uniformly displayed as “#” in the fast display view of ABAP debugger.
The actual content of the uploaded file that I am really interested in is stored in the form data block shown in the figure below.
Therefore, my idea is to locate the ABAP variable LV in the figure above according to the carriage return line feed character_ Data contains a form data block. If this block contains content type: text / plain, it means that this block contains the actual content of the uploaded file. The actual content of the uploaded file can be obtained by parsing it.
The common mistake made by many novice friends here is that the carriage return line feed observed in the ABAP debugger is displayed as “##”. Therefore, in the code, these friends also directly use single or double pound signs for string matching, which of course cannot work.
ABAP tool class CL is required to perform operations related to line feed and carriage return line feed in ABAP_ ABAP_ CHAR_ Constants defined by utilities: Cr_ LF and newline:
As I used in the implementation code of this article:
After parsing the contents of the uploaded text file, call SAP CRM attachment to create API, and add the file content as an appendix to the sales order of system ID 55824.
For simplicity, this example only supports uploading local files of text / plain type into attachments of sales order (whose bor type is bus20000115), so both file type and bor type are hard coded.
After the front-end and back-end development is completed, test and upload a file called upload Txt, which is received by the ABAP server and stored as an attachment to the sales order 55824.
Click the attachment hyperlink to open the content of the file. It is found that it is completely consistent with the local file, and the test passes:
Of course, what this article describes is actually a scene of rebuilding wheels. In the actual project development, if there is no special reason, we still try to use the ready-made framework and tools provided by SAP to complete the basic and underlying work such as file upload, so as to focus on the preparation of business logic.
Thanks for reading.
Jerry’s ABAP topic
- What should ABAP developers learn in the future
- Jerry’s May Day holiday in 2017:ABAP implementation of eight classical sorting algorithms
- Jerry’s collection of ABAP original technical articles
- 300 lines of ABAP code implement the simplest blockchain prototype
- Use java + SAP cloud platform + SAP cloud connector to call functions in ABAP on premise system
- Consume ABAP on premise OData service in the cloudfoundry environment of SAP cloud platform
- ABAP vs Java, breaststroke vs freestyle
- Talk about C language and ABAP
- Use ABAP channel to develop some small tools to improve daily work efficiency
- The boring things I’ve done with ABAP
- Don’t like SAP GUI?Try eclipse for ABAP development
- Writing and activating ABAP code using Visual Studio code
- Did your ABAP program give light to the Buddha?Let’s try Jerry’s trick
- Write the first ABAP program on the ABAP programming environment of SAP cloud platform
- ABAP programming specification officially issued by SAP
- Do you know the hidden functions of ABAP code inspector?
- Are you still using ABAP for secondary development of SAP products? Let’s learn about this new concept of secondary development
- Those parasitic programming languages in ABAP NetWeaver
- Start with a blog on the sap community and talk about the feelings behind the naming of SAP products
- ABAP restful service development in the cloud
- How to expose CDs view as OData service in ABAP programming environment of SAP cloud platform
- Use abapgit to transfer code between ABAP on premises system and SAP cloud platform ABAP environment
- 30 minutes to develop a Fiori application supporting addition, deletion, modification and query with restful ABAP programming model
- Jerry takes you through the second in the restful ABAP programming model series: the implementation of action and validation
- Jerry takes you through restful ABAP programming model series 3:Cloud ABAP application debugging
- How to consume third-party services in ABAP programming environment on SAP cloud platform
- It’s time for ABAP developers to go to the cloud – now you can use the trial version of SAP cloud platform ABAP environment for free
- Learning without thinking is useless – the origin and application scenario of ABAP programming environment for SAP cloud platform
- Trident application in SAP cloud platform
- How to develop and deploy a Fiori application that supports addition, deletion, modification and query based on restful ABAP programming model
- Interpretation of SAP 2019 teched key note: how do SAP employees do secondary development in the cloud era?
- What ABAP keywords and syntax can’t be used in the ABAP cloud environment?
- ABAP development environment finally supports automatic formatting of ABAP variable names with hump naming method
- Use the new keyword reduce of ABAP 740 to complete a practical task
- A shivering ABAP code
- Yesterday Halloween ABAP monster level code mystery, announced the answer
- This paper introduces a method of efficient internal table copy in ABAP kernel state
- A practical example of developing OData using SAP cloud application programming model
- When ABAP meets Prometheus
- Draw scalable vector diagram using ABAP
- The things highlighted by ABAP development environment syntax
- Seven weapons for SAP error message debugging:So that all error messages can be located
- Several methods of using ABAP to operate Excel
- Favorite transaction code management tool in SAP GUI
- SAP GUI and windows registry
- Can you do bad things with debug permission? Be careful, your every move is monitored by the system
- What are ABAP, ccdef, ccimp, ccmac, ccau, cmxxx
- Three ways to implement ABAP conditional breakpoints
- Use sat tracking to monitor the performance and call stack of SAP applications opened from the browser
- A 13 year ABAP veteran’s suggestion: understanding these basic knowledge is beneficial to ABAP development
- SAP ABAP NetWeaver containerization, impossible tasks?
- SAP product enhancement technology review
- Complete collection of SAP API development methods
- Talking about the static agent and dynamic agent of Java and SAP ABAP, and the attempt of ABAP aspect oriented programming
- HTTP response status code of SAP ABAP application server
- Is there a collection tool class like Java list in SAP ABAP? CL_ OBJECT_ Collection, find out
- ABAP interview question series: write a group of ABAP programs that will deadlock
- Explanation of standard login mode of SAP ABAP NetWeaver server
- SAP ABAP keyword syntax diagram and ABAP code automatic generation tool Code Composer
- Alternative use of SAP ABAP SM50 – ABAP work process detection of database table reading operations
- A knowledge point about the number of characters of SAP ABAP character variable and string variable, and a murder case
- Usage analysis of a group of keywords is bound, is not initial and is assigned in SAP ABAP
- Weak reference and soft reference in SAP ABAP and Java
- Introduction to sap AMDP – Hana database process hosted by ABAP
- Tag your ABAP object
- Today in history: billion dollar error in null references in programming languages
- Summary of ABAP development tool code template and other practical skills
- Ten tips for SAP ABAP development tool to improve development efficiency
- How to consume soap based web services in ABAP programming environment of SAP BTP platform
- Will ABAP really become obsolete? Talk about ABAP’s past, present and future
- An example of ABAP continuous integration based on abapgit and abaplint
More Jerry’s original articles are: “Wang Zixi”: