SAP connectivity is a big topic on this blog—especially when it comes to production and production planning. In this article, we’ll take a look at long texts.
The term “long text” refers to a pattern that is used in many SAP contexts and business objects. A long text lets you store additional information to an object, without any length restriction. All SAP modules handle long texts in the same way.
In our example, we will handle long texts of an operation that is bound to a SAP production order. However, the function module we’re using to read the text can be used for any long text.
Long text in SAP
The following screenshots show what a long text in SAP looks like. We start from the operation line. Then, we double-click on the text column to view and edit the long text. This text is what our Peakboard application will download.
Build the Peakboard application
In a previous article, we explained how to download a production order. We used BAPI_PRODORD_GET_DETAIL
to get a list of components that are used in the order.
Here, we do the same thing, except we download the operations instead of the components. In the Peakboard application, we place two text fields for the production order number and operation number and bind them to two variables that we will use later.
For the data source, we use an XQL statement that uses BAPI_PRODORD_GET_DETAIL
to download a list of operations for the given production order number. The #[OrderNo]#
is a placeholder for the OrderNo
variable.
We are only interested in the operation that the user provided in the text field. So, we use a dataflow to filter the operation list for the operation the user wants.
We now have access to all the structured operation’s fields, including the short description text and the work center. But how do we download the long text for the operation? The magic happens in the refreshed script of the dataflow. The refreshed script executes each time the dataflow refreshes.
RFC_READ_TEXT
You can use the function module RFC_READ_TEXT
to download long texts remotely. However, the way to use it isn’t as you might expect. You must fill a table called TEXT_LINES
with two attributes, as well as a long compound key that identifies the text. Sending these values to the function module makes it fill the table with text lines from the text we request.
Initially, we must fill the table with these values:
Value | Description |
---|---|
TDOBJECT |
The name of the business object to be queried. In our case, this is AUFK , which represents the production order. |
TDID |
The name of the sub object that identifies the text to be queried. In our case, this is AVOT , which is the production order operation text. |
TDNAME |
A compound key. In our case, the pattern is MMMXXXXXXXXXXYYYY , where MMM is the client, XXXXXXXXXX is the routing number of the operation, and YYYY is the counter of the operation. |
The compound key might feel strange if you’re unfamiliar with compound keys, but they’re actually easy to handle. The “client” is fixed, and routing number and counter are both easily accessible from the operation table that is returned by the BAPI_PRODORD_GET_DETAIL
function.
Here’s the script that gets the texts:
Here’s how it works:
- Build the table element and fill it with the three attributes. Concatenate the key from the operations table.
- Execute the XQL. The line,
TEXT_LINES = @MyLines INTO @Outputlines
indicates that the table is sent from the caller to SAP and is also returned from SAP. - Iterate over the text lines of the return table and concatenate the lines to a single string with line breaks.
Result
This video shows the final result. The button triggers the reload of the source, and the dataflow is triggered automatically. Finally, the long text is queried from SAP in the refreshed script.