Additional Blogs by SAP
Showing results for 
Search instead for 
Did you mean: 
Active Contributor

t's been a very long time since my last "Tasting the mix of" blog post...but here we are to change that -;)

Lately, I have been learning Python...a sexy, powerful and easy to learn programming of course...every time I learn something new, I want to apply it to the SAP world...and lucky me, Piers Harding  ( had already creating an Python SAPRfc connector  ( -:D

So, with everything setup and working I proceeded to start working on the SE16 emulator using the DOS screen...but then I realized that even when didn't do an SE16, my good friend David Hull  (/people/david.hull2/blog) was already using Python, SAPRfc and DOS screen in his blog entitled Python and SAP Adventures  ().

As I had already worked with Micro Frameworks in Ruby, I thought it was a good idea to implement the same using after my research I found two nice candidates (Take note that I love Micro Frameworks and not so streamed Frameworks...meaning that I don't like, don't know and don't use Rails or Djanjo...I like to keep it simple).

These Micro Frameworks are called Bottle  ( and Flask  ( (Weird name, huh?).

So, to make things simple, I used the YAML approach, where we use a configuration like file where we are going to put our connection strings...something like the SAPLogon.ini


ashost: localhostsysnr: "00"client: "001"lang: ENtrace: 1loglevel: warn

For the source codes, let's start with Bottle.<br />

<textarea cols="70" rows="20">from flask import Flask, redirect, request

import sapnwrfc

app = Flask(__name__)

conn = ""


def login():

    return '''<DIV ALIGN='CENTER'><BR><BR><BR><BR>

                <H1>Python (Flask) & SAP - SE16 Emulator</H1>

                <BR><TABLE BORDER='1' BORDERCOLOR='BLUE'


                <FORM ACTION='/login_submit' METHOD='POST'>


                <INPUT TYPE='TEXT' NAME='User'></TD></TR>


                <TD><INPUT TYPE='PASSWORD' NAME='Passwd'></TD></TR>

                <TR><TD COLSPAN='2' ALIGN='CENTER'>

                <INPUT TYPE='SUBMIT' value='Log In' NAME='LOG_IN'>

                <INPUT TYPE='RESET' value='Clear'></TD></TR>




@app.route("/login_submit", methods=['GET', 'POST'])

def login_submit():

    global conn

    if request.method == 'POST':

        user = request.form['User']

        passwd = request.form['Passwd']

        sapnwrfc.base.config_location = "sap.yml"


        conn = sapnwrfc.base.rfc_connect({'user': user,

                                          'passwd': passwd})

        return redirect("/choose")


def choose_table():

    return '''<CENTER>

                <FORM ACTION='/show' METHOD='POST'>

                <INPUT TYPE='TEXT' NAME='Table'><BR>

                <INPUT TYPE='SUBMIT' value='Show Table'




@app.route("/show", methods=['GET', 'POST'])

def show_table():

    global conn

    if request.method == 'POST':

        fields = []

        fields_name = []

        table = str(request.form['Table'])

        func_disc ="RFC_READ_TABLE")

        func = func_disc.create_function_call()




        data_fields = func.DATA.value

        data_names = func.FIELDS.value

        long_fields = len(func.DATA())

        long_names = len(func.FIELDS())

        for line in range(0, long_fields):


        for line in range(0, long_names):


        output = "<table border='1'><tr>"

        for line in range(0, long_names):

            field_name = fields_name[line]

            output += "<th> %s </th>" % field_name

        output += "</tr>"

        for line in range(0, long_fields):

            output += "<tr>"

            data_split = fields[line].split("|")

            for line in range(0, long_names):

                output += "<td> %s </td>" % data_split[line]

            output += "</tr>"

        output += "</table>"

        return output


if __name__ == "__main__":

</textarea></p><p> </p><p>!|alt=|src=!</p><p>!|alt=|src=!</p><p>!|alt=|src=!</body>