Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a standard bapi "BAPI_USER_GET_DETAIL" to json

Former Member
0 Kudos
1,351

Can you please help me out how to make a http JSON service for the standard BAPI.

6 REPLIES 6

krishnendu_laha
Active Contributor
0 Kudos
492

Hello,

I do not know if there is specific settings required for web service but to create a web service out of BAPI, you can follow:

SE37 -> display BAPI -> Utilities -> More Utilities -> Create Web Service -> From Function Module

And to see existing services for particular package, go to transaction SE84..

..

Thanks.

0 Kudos
492

Krishnendu Laha ,

1.I am new to json, creation of webservice is ok then how can i proceed..

2. I need the output of the bapi in the json format .

3. How could i do it and what are the steps for that .

0 Kudos
492

hi, did you already recieve an answer on this ?

I have to do the same thing and don't know where to start

thanks,

Joseph_BERTHE
Active Contributor
0 Kudos
492

Hi,

This wiki can be a part of your answer : http://wiki.sdn.sap.com/wiki/display/Snippets/JSON+and+ABAP

But you will face of a performances issue if to process large data because there is double convertion : Table to XML and XML to JSON.

Regards,

dhorions
Contributor
0 Kudos
492

Hi,

I recently created a small tool to allow easy json usage of sap BAPIs using sap jco.

You can find the code here https://github.com/dhorions/jcoSon.

Example :

Input :

{

  "BANKKEY": "083000108",

  "BANKCOUNTRY": "US"

}

java code :

jcoSon jco = new jcoSon(destination.getRepository().getFunction("BAPI_BANK_GETDETAIL"));

jco.setParameters("{\"BANKKEY\":\"083000108\",\"BANKCOUNTRY\":\"US\"}");

String resultJson = jco.execute(destination);

System.out.println("Results :"+ resultJson);

Output:

{

  "BANK_ADDRESS": {

   "BANK_NAME": "First Union Bank & Trust",

   "REGION": "IL",

   "STREET": "500 Main Street",

   "CITY": "Chicago",

   "SWIFT_CODE": "",

   "BANK_GROUP": "",

   "POBK_CURAC": "",

   "BANK_NO": "083000108",

   "POST_BANK": "",

   "BANK_BRANCH": "Main Office",

   "ADDR_NO": ""

  },

  "BANK_DETAIL": {

   "CREAT_DATE": "Fri Jan 03 00:00:00 CET 1997",

   "CREATOR": "GRAVEN",

   "METHOD": "",

   "FORMATTING": "",

   "BANK_DELETE": ""

  }

}

Srdjan
Product and Topic Expert
Product and Topic Expert
0 Kudos
492

Also possible using SAP Open Source Connectors, for Python, nodejs or GO.

nodejs uses JSON natively and Python and GO have built-in support. Here two examples:

Python

result = conn.call('BAPI_USER_GET_DETAIL', USERNAME=abap['user'])

js = simplejson.dumps(result, default=json_serial)

return Response(js, status=200, mimetype='application/json')

nodejs (example from node-rfc test)

client.invoke('BAPI_USER_GET_DETAIL', { USERNAME: 'DEMO' },

  function(err, res) {

  should.not.exist(err);

  res.should.be.an.Object;

  res.should.have.properties(

  'ADDRESS', 'ACTIVITYGROUPS',

  'DEFAULTS', 'GROUPS','ISLOCKED', 'LOGONDATA',

  'PARAMETER','PROFILES', 'RETURN'

  );

  done();

  });