DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Kafka JDBC Source Connector for Large Data
  • Kafka Connect: Strategies To Handle Updates and Deletes
  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance

Trending

  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Building Multi-Rail Payment Failover to Stop Latency Spikes and Double Debits
  • Why Scraping Pipelines Break in Production
  • AI Didn't Replace Software Engineering; It Changed the Bottleneck

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Read SAP Tables With RFC_READ_TABLE in Mule 4 Using SAP Connector

Read SAP Tables With RFC_READ_TABLE in Mule 4 Using SAP Connector

Learn how to make an RFC to SAP, how to use various operators (like AND, OR, IN, etc.), and what the default structure of RFC_READ_TABLE input looks like.

By 
Prathamesh Kulkarni
·
Mar. 07, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In this article, we are going to see how to make an RFC (Remote Function Call) to SAP and what different options are available to get your desired data. We'll also learn how to make use of various operators like AND, OR, IN, and many more, and what the default structure of RFC_READ_TABLE input looks like.

Whenever you are working with SAP, you will surely go with RFC calls and a lot of developers struggle to write XML queries for RFC.

Depending on your use case you may want to include a different number of fields and different types of operators, which will give you your desired data from SAP.

MuleSoft SAP Connector enables Mule runtime engines to support SAP integration as a certified SAP Java Connector (JCo) that leverages SAP JCo libraries. For connecting Mule with SAP, please check out this article. 

Assuming you have established the connection successfully, it is now time to make the first call to RFC (Remote Function Call).

Here I am going to use the Synchronous Remote Function Call and the function will be RFC_READ_TABLE.

To make a call to SAP RFC, you need to build the required XML Format,

 
%dw 2.0
output application/xml
---

{
   RFC_READ_TABLE: {
      "import": {
         DELIMITER:";",
         QUERY_TABLE: "The Name of your query table",
         ROWCOUNT: 0
      },
      tables: {
         FIELDS: {
                    
            row: {
               FIELDNAME: "Field 1"               
            },
            row: {
               FIELDNAME: "Field 2"               
            },
            row: {
               FIELDNAME: "Field 3"               
            },
            row: {
               FIELDNAME: "Field 4"               
            }
         }
      }
   	}
}

DELIMITER is basically for separating your data, you can use PIPE "|" or any other separator as well.

ROWCOUNT: 0 indicates you want to have a full copy of data from the queried table, or else you can specify the number of lines. If we can relate it with SQL, then it is like a LIMIT keyword.

Now I will be querying a table and we will see how it gives you output. SAP gives you output in XML only. We can easily convert it to JSON using the transform message.

JSON
 
{
  "RFC_READ_TABLE": {
    "import": {
      "DELIMITER": ";",
      "NO_DATA": null,
      "QUERY_TABLE": "ZPB40_IBDN",
      "ROWCOUNT": "3",
      "ROWSKIPS": "0"
    },
    "tables": {
      "DATA": {
        "row": {
          "WA": "0180035892;20170119;000000000000021112                      ;L-ARGININE C 20 KG                      ;                    ;20161220;C"
        },
        "row": {
          "WA": "0180035892;20170119;000000000000021112                      ;L-ARGININE C 20 KG                      ;                    ;20161220;C"
        },
        "row": {
          "WA": "0180035892;20170119;000000000000021112                      ;L-ARGININE C 20 KG                      ;                    ;20161220;C"
        }
      },
      "FIELDS": {
        "row": {
          "FIELDNAME": "VBELN",
          "OFFSET": "000000",
          "LENGTH": "000010",
          "TYPE": "C",
          "FIELDTEXT": "Delivery"
        },
        "row": {
          "FIELDNAME": "LFDAT",
          "OFFSET": "000011",
          "LENGTH": "000008",
          "TYPE": "D",
          "FIELDTEXT": "Delivery Date"
        },
        "row": {
          "FIELDNAME": "MATNR",
          "OFFSET": "000020",
          "LENGTH": "000040",
          "TYPE": "C",
          "FIELDTEXT": "Material Number"
        },
        "row": {
          "FIELDNAME": "ARKTX",
          "OFFSET": "000061",
          "LENGTH": "000040",
          "TYPE": "C",
          "FIELDTEXT": "Short text for sales order item"
        },
        "row": {
          "FIELDNAME": "ZWF_STATUS",
          "OFFSET": "000102",
          "LENGTH": "000020",
          "TYPE": "C",
          "FIELDTEXT": "Workflow Status"
        },
        "row": {
          "FIELDNAME": "ERDAT",
          "OFFSET": "000123",
          "LENGTH": "000008",
          "TYPE": "D",
          "FIELDTEXT": "Date on which the record was created"
        },
        "row": {
          "FIELDNAME": "WBSTK",
          "OFFSET": "000132",
          "LENGTH": "000001",
          "TYPE": "C",
          "FIELDTEXT": "Goods Movement Status (All Items)"
        }
      },
      "OPTIONS": null
    }
  }
}

As you can see, I gave the row count as three and that is the reason we got three rows in the output. It is separated by the ;.

If you see the object FIELDS, it tells you which values columns you selected with the description as well. OPTIONS are showing as null because we have not provided any value to it. OPTIONS are basically the where clause of SQL, which means you can get data for a specified column value.
Let's see how to implement it in Mule 4:
Mule 4 implementation

The input payload to SAP looks like the above image, and in OPTIONS, I have given two values and used the AND operator for that. It will return all the values that match these conditions.

You can use different types of logical operators depending on your requirement, such as OR, IN, and LIKE.

The operators =, <>, <, >, <=, and >= are equivalent to EQ, NE, LT, GT, LE, and GE respectively.

This is how you can get the data from the SAP RFC Read Table.  

Database Connector (mathematics) sql

Opinions expressed by DZone contributors are their own.

Related

  • Kafka JDBC Source Connector for Large Data
  • Kafka Connect: Strategies To Handle Updates and Deletes
  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook