Skip to content

Commit

Permalink
abap-api-tools server client and pool examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Mar 17, 2021
1 parent 3a7d409 commit 053a3f9
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 11 deletions.
10 changes: 5 additions & 5 deletions abap-value-help/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Server component exposing generic Value Helps for [pattern based applications](h
- ABAP Fixed Domain Values (FV)
- ABAP Elementary and complex Search Helps (SH)
- ABAP Check Tables (CT, CH)
- Custom input helps
- Custom value helps

- [Installation](#installation)
- [Usage](#usage)
Expand Down Expand Up @@ -66,7 +66,7 @@ ABAP API: [doc/abap](https://github.com/SAP/fundamental-tools/blob/main/abap-val

Custom attribute will add Search Help icon input addon and run the Search Help dialog using abovementioned routes. Input ui component is updated with the Search Help dialog result:

![](https://raw.githubusercontent.com/SAP/fundamental-tools/main/abap-value-help/doc/assets/ValueInputHelpsDialog.jpg)
![dialog](https://raw.githubusercontent.com/SAP/fundamental-tools/main/abap-value-help/doc/assets/ValueInputHelpsDialog.jpg)

## Components

Expand Down Expand Up @@ -115,9 +115,9 @@ Server routes can be tested by REST client JSON payloads, or from any web browse
```shell
cd server
npm install
node index
node pool # or node client

ABAP Value Help server ready:
Value Helps server ready:
http://localhost:3000/login
http://localhost:3000/fieldvalues
http://localhost:3000/helpselect
Expand All @@ -137,7 +137,7 @@ Aurelia View and View-Model implementation require ca 300 lines of code in total

and the flow:

![](https://raw.githubusercontent.com/SAP/fundamental-tools/main/abap-value-help/doc/assets/shflow.png)
![Choreography](https://raw.githubusercontent.com/SAP/fundamental-tools/main/abap-value-help/doc/assets/shflow.png)

## Known Issues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const express = require("express");
const ValueHelp = require("abap-value-help").ValueInputHelp;
const Client = require("abap-value-help").Client;
const Client = require("node-rfc").Client;

// Generic ABAP Value Help API used in prototyping system
const shlpApi = {
Expand Down Expand Up @@ -46,7 +46,9 @@ app.route("/fieldvalues").all(async (req, res) => {
const result = await valueHelp.getDomainValues(
Object.keys(req.body) > 0 ? req.body : "RET_TYPE"
);
res.json(result);
//res.json(result);
res.header("Content-Type", "application/json");
res.send(JSON.stringify(result, null, 4));
});

// Complex/elementary Value Help descriptor (SH type)
Expand All @@ -58,7 +60,9 @@ app.route("/helpselect").all(async (req, res) => {
const descriptor = await valueHelp.getShlpDescriptor(
Object.keys(req.body) > 0 ? req.body : { type: "SH", name: "CC_VBELN" }
);
res.json(descriptor);
//res.json(descriptor);
res.header("Content-Type", "application/json");
res.send(JSON.stringify(descriptor, null, 4));
});

// Run the search using selection parameters from Value Input Dialog
Expand All @@ -81,7 +85,9 @@ app.route("/search").all(async (req, res) => {

const result = await valueHelp.search(shlpId, selection);

res.json(result);
//res.json(result);
res.header("Content-Type", "application/json");
res.send(JSON.stringify(result, null, 4));
});

// Close the connection (optional)
Expand All @@ -92,7 +98,7 @@ app.route("/logout").all(async (req, res) => {

app.listen(PORT, () =>
console.log(
"ABAP Value Help server ready:",
"Value Helps server ready:",
`\nhttp://localhost:${PORT}/login`,
`\nhttp://localhost:${PORT}/fieldvalues`,
`\nhttp://localhost:${PORT}/helpselect`,
Expand Down
113 changes: 113 additions & 0 deletions abap-value-help/doc/server/pool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: 2014 SAP SE Srdjan Boskovic <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0

const express = require("express");
const ValueHelp = require("abap-value-help").ValueInputHelp;
const Pool = require("node-rfc").Pool;

// Generic ABAP Value Help API used in prototyping system
const shlpApi = {
rfm_domvalues_get: "/COE/RBP_FE_SHLP_DOMVALUES_GET",
rfm_metadata_get: "/COE/RBP_FE_SHLP_METADATA_GET",
rfm_search: "/COE/RBP_FE_SHLP_GET",
};

const PORT = 3000;
const app = express();
let pool;
let valueHelpClient;
let valueHelp;

app.use(express.json());

// Authenticate and open client connection
// Closed in /logout or automatically
app.route("/login").all(async (req, res) => {
try {
pool = new Pool(
Object.keys(req.body) > 0
? req.body
: { connectionParameters: { dest: "MME" } }
);
valueHelpClient = await pool.acquire();
const user = await valueHelpClient.call("BAPI_USER_GET_DETAIL", {
USERNAME: req.body.username || "DEMO",
});
// User parameters (SU3) passed to Value Helps handler
// make user defaults appear in Value Help web forms just like in SAPGUI
valueHelp = new ValueHelp(valueHelpClient, shlpApi, user.PARAMETER);
res.json("connected");
} catch (ex) {
res.json(ex.message);
}
});

// Fixed domain values
app.route("/fieldvalues").all(async (req, res) => {
if (!pool) {
return res.json("Do the login first");
}
const result = await valueHelp.getDomainValues(
Object.keys(req.body) > 0 ? req.body : "RET_TYPE"
);
//res.json(result);
res.header("Content-Type", "application/json");
res.send(JSON.stringify(result, null, 4));
});

// Complex/elementary Value Help descriptor (SH type)
// used to dynamically build the frontend Value Input dialog
app.route("/helpselect").all(async (req, res) => {
if (!pool) {
return res.json("Do the login first");
}
const descriptor = await valueHelp.getShlpDescriptor(
Object.keys(req.body) > 0 ? req.body : { type: "SH", name: "CC_VBELN" }
);
//res.json(descriptor);
res.header("Content-Type", "application/json");
res.send(JSON.stringify(descriptor, null, 4));
});

// Run the search using selection parameters from Value Input Dialog
app.route("/search").all(async (req, res) => {
if (!pool) {
return res.json("Do the login first");
}

const shlpId = req.body.shlpId
? req.body.shlpId
: { type: "SH", name: "VMVAA" };

const selection = req.body.selection
? req.body.selection
: [
//["AUART", "I", "EQ", "OR", ""],
["BSTKD", "I", "EQ", "212345678", ""],
["VKORG", "I", "EQ", "1000", ""],
];

const result = await valueHelp.search(shlpId, selection);

//res.json(result);
res.header("Content-Type", "application/json");
res.send(JSON.stringify(result, null, 4));
});

// Close the connection (optional)
app.route("/logout").all(async (req, res) => {
if (pool && valueHelpClient.alive) await pool.release(valueHelpClient);
res.json("disconnected");
});

app.listen(PORT, () =>
console.log(
"Value Helps server ready:",
`\nhttp://localhost:${PORT}/login`,
`\nhttp://localhost:${PORT}/fieldvalues`,
`\nhttp://localhost:${PORT}/helpselect`,
`\nhttp://localhost:${PORT}/search`,
`\nhttp://localhost:${PORT}/logout`
)
);
1 change: 0 additions & 1 deletion abap-value-help/src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export {
SearchResultHeaderType,
SearchResultLineType,
SearchResultType,
Client,
log,
};

0 comments on commit 053a3f9

Please sign in to comment.