Skip to Content

NCO3 Newbie

With the success of last weeks single sign on triumph it is time to move on to pastures new and do something different!! I now have a few thousand users who can get in to ESS/MSS with silent credential swapping.

Next on my list is NCO3. Wow, I can plug my favourite .net framework in to the library of SAP FM’s, BAPI’s and BADI’s. Surely that will be the perfect combination? Or will it?

My mission: Start small, get bored, try big.

1) 1)  Simple connection test – get connected retrieve some company data

2) 2)  Recreate something SAP does in GUI on a webpage

I will be using Server 2008 R2, Visual Studio 2010 Ultimate, .net 4 & the latest SAP NCO 3.

Ok Mission 1

  • Installed the SAP web connector components
  • Created brand new webforms application
  • Add two new solution references to sapnco & sapnco_utils (the dll’s can be browsed to in your installation folder for the sap wc components just installed)
  • Created a new class to hold connection parameters (You could do this in web config..)
  • Add a new using reference to the class:

using SAP.Middleware.Connector;

  • This is the code of my class – it handles all of the connection variables:

public RfcConfigParameters GetParameters(String destinationName)

{

if (“QAS315”.Equals(destinationName))

{

RfcConfigParameters parms = new RfcConfigParameters();

parms.Add(RfcConfigParameters.AppServerHost, “your SAP system IP address”);

parms.Add(RfcConfigParameters.SystemNumber, “00”);

parms.Add(RfcConfigParameters.User, “your user name”);

parms.Add(RfcConfigParameters.Password, “Your password”);

parms.Add(RfcConfigParameters.Client, “your client number”);

parms.Add(RfcConfigParameters.Language, “EN”);

parms.Add(RfcConfigParameters.PoolSize, “5”);

parms.Add(RfcConfigParameters.IdleTimeout, “600”);

return parms;

}

else return null;

}

public bool ChangeEventsSupported()

{

return false;

}

public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;

}

  • Ok I have all of this connection information, I now want to do something with it..
  • In my default.aspx I added a button and a datagrid
  • I built a void to handle the actual work being undertaken:

private void getCompanyDetail()

{

   RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());

RfcDestination dest = RfcDestinationManager.GetDestination(“QAS315”);

try

{

RfcRepository repo = dest.Repository;

IRfcFunction bapiGetCompantList = repo.CreateFunction(“BAPI_COMPANY_GETLIST”);

IRfcFunction bapiGetCompanyDetail = repo.CreateFunction(“BAPI_COMPANY_GETDETAIL”);

//Invoke first BAPI using RfcDestiantion as source

   bapiGetCompantList.Invoke(dest);

//Now we are connected and BAPI invoked, we can create the RFC table & populate it…

IRfcTable CompanyTable = bapiGetCompantList.GetTable(“Company_List”);

IRfcStructure RfcReturn = bapiGetCompanyDetail.GetStructure(“RETURN”);

companyDetail.DataSource = GetDataTableFromRFCTable(CompanyTable);

    companyDetail.DataBind();

}

catch (Exception t)

{

    Response.Write(t);

}

}

  • In addition to this I needed code to handle the formatting of the returned values to populate my grid.  I built in a public datatable to do this: (I can’t lay claim to writing this code..)

public DataTable GetDataTableFromRFCTable(IRfcTable myrfcTable)

{

DataTable loTable = new DataTable();

int liElement = 0;

for (liElement = 0; liElement <= myrfcTable.ElementCount – 1; liElement++)

{

RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);

   loTable.Columns.Add(metadata.Name);

}

foreach (IRfcStructure Row in myrfcTable)

{

DataRow ldr = loTable.NewRow();

for (liElement = 0; liElement <= myrfcTable.ElementCount – 1; liElement++)

{

RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);

ldr[metadata.Name] = Row.GetString(metadata.Name);

}

   loTable.Rows.Add(ldr);

}

return loTable;

}

  • With this code in place I can now put a one liner on the button and see what happens
  • In code behind:

protected void Button1_Click(object sender, EventArgs e)

  {

      getCompanyDetail();

      }

  • The code compiles, and hitting the button brings back a simple grid of all company details held in my configured SAP system.
  • Ok this is the simple one – for my next blog I will be ramping up the complexity – I am thinking I might have a go at ME21N – Create Purchase Order – If anyone reading has had experiences of this, drop me a reply or a mail as this will be greatly appreciated.
2 Comments
You must be Logged on to comment or reply to a post.
  • Iain

    Interesting blog. Also enjoyed the SSO blog. Thanks for sharing some good content. One little thing that I find a bit troubling: in RfcConfigParameters one of the required parameters is password. I assume that this is a plain text entry. Is the RfcConfigParameters then encrypted? Leaving a password in plain text does not seem to be a good idea — doubt it would pass a detailed security audit. I found a very similar config parameter file for the BOBJ XI connector.

    Perhaps both connection protocols work over SNC for production environments.

    Regards,

    Kevin Grove

    • Hi Kevin,

      Thanks for your kind comments on my blogs.

      Yes you are correct – I would never look to deploy a plain text password in code behind on a production server.

      I know nco3 bought in several security enhancements surrounding login and authentication, but that doesnt get round the fundimental problem of storing authentication credentials.

      I guess you could paramatise those values and force login each time the user attempts a connection or maybe do something trick around ticket authentication.

      My plan was to ship the whole lot out to webconfig, but I am open to any ideas as like you rightly say, anything out in the production environment will undoutably be audited at some point.

      Iain