Print a list of BAPIs using JCo - java

I established connection to a SAP Server and I would like to print a list of BAPIs in my Java program. I am using sapjco3.jar.
Is there any way to do it?

You can also use the function module SWO_QUERY_API_METHODS. The following code snippet works with JCo 2:
IFunctionTemplate functionTemplate = Repository.getFunctionTemplate("SWO_QUERY_API_METHODS");
JCO.Function function = functionTemplate.getFunction();
mConnection.execute(function);
ParameterList exportParameter = function.getExportParameterList();
System.out.println("exportParameter: " + exportParameter);
ParameterList importParameter = function.getImportParameterList();
System.out.println("importParameter: " + importParameter);
ParameterList tableParameter = function.getTableParameterList();
System.out.println("tableParameter: " + tableParameter);

As far as I know, there is no "BAPI to get a list of BAPIs", so this would be a non-trivial task. You could try to use RFC_FUNCTION_SEARCH to search for function modules named BAPI*, but that's not guaranteed to give you a) only official BAPIs and b) all of the official BAPIs...

You can use the BAPI_MONITOR_GETLIST to get a list of all BAPIs in your system together with meta data.

You could make an ABAP function searching for all RFC functions in table TFDIR, with FMODE ='R' (remote). However, This will give you all remote-callable function, not only BAPIs.

Related

How to decrement an IPV4 address using java library?

I am converting a nodejs code into Java8.
In node there are code as shown below
var ipToEndAt = ippp.prev("192.168.1.225");
result of ipToEndAt is "192.168.1.224"
I need to convert this line into a java code. I searched for SubnetUtils library, but couldn't find anything appropriate.
similar i also need to increment ip address by 1
can anyone suggest a library or a code snippet ? which ever would be best
Although it's not overly hard to do it yourself, there's an InetAddresses class in Guava that allows this kind of operations. And Guava is a very useful addition to your toolchest anyways.
InetAddress address = InetAddress.getByName("192.168.1.225");
address = InetAddresses.decrement(address);
See, that looks almost identical to the JS code.
In your comment you state that you are unable to use the decrement method, which indicates that you have a really old version of Guava.
https://github.com/google/guava/commit/d39130651d8a90f5ebe066de7f0b2311806e5152#diff-1207ec0a4b5d3f5e5c2236b7373eefc9
The project home page contains instructions on how to add the current version (25.1) to your project's dependencies.
This can be done with the IPAddress Java library, in a manner that is polymorphic between IPv4 and IPv6. Also, it is not limited to incrementing or decrementing by 1 as with Guava, you can use any long value and catch AddressValueException in the case of overflow. Disclaimer: I am the project manager of IPAddress.
Sample code:
IPAddress result = increment("192.168.1.225", -1);
System.out.println(result);
result = increment("::", 1);
System.out.println(result);
static IPAddress increment(String addrStr, long inc) throws AddressValueException {
return new IPAddressString(addrStr).getAddress().increment(inc);
}
Output:
192.168.1.224
::1
More elaborate sample code at the IPAddress wiki

How do you access RDS databases from AWS

I'm looking at the AWS API and I can't seem to find a method to help me get info on an existing RDS database. I also tried to use a method that gets a list of all the RDS databases but failed at that too.
I looked at 2 methods and apparently they aren't what I'm looking for or I'm using them wrong.
Method 1:
I looked at ModifyDBInstanceRequest, to see if I could specify the name of an existing database and if I could query it for its properties (mysql version, storage size, etc.)
The following piece of code didn't do as I expected. ad-dash-test is an existing db in RDS. When I ran my code, it said the engine version is null, even though this is an existing db and I specified it by its DB Instance name.
ModifyDBInstanceRequest blah = new ModifyDBInstanceRequest("ad-dash-test");
System.out.println("the engine ver is " + blah.getEngineVersion());
Method 2:
I tried using the DescribeDBInstancesResult method but it looks like it's used for newly created RDS databases, not existing ones.
DescribeDBInstancesResult db = new DescribeDBInstancesResult();
List<DBInstance> list = db.getDBInstances();
System.out.println("list length = " + list.size());
The list length that returns is 0 and I have 8 RDS instances.
I didn't find any examples in Amazon's SDK for RDS and using my logic and the API docs didn't seem to help. Hopefully someone can point me in the right direction. Thanks in advance for your help.
In both of your methods, you are just building a Request object, and you are never sending the request to AWS.
Try the following in your second example:
// Instantiating rdsClient directly is deprecated, use AmazonRDSClientBuilder.
// AmazonRDSClient rdsClient = new AmazonRDSClient(/*add your credentials and the proper constructor overload*/);
AmazonRDS rdsClient = AmazonRDSClientBuilder.defaultClient();
DescribeDBInstancesRequest request = new DescribeDBInstancesRequest();
DescribeDBInstancesResult result = rdsClient.describeDBInstances(request);
List<DBInstance> list = result.getDBInstances();
System.out.println("list length = " + list.size());
An example for method 1 (for modifying your instance(s)) should be similar.

Retrieve tweets language or filter by language with TwitterStream

I would like to retrieve or filter by language using TwitterStream class. I want to get only tweets of one language or otherwise retrieve everything and then identify each tweet language.
I have build this code but getIsoLanguageCode() returns null always (see version 3.0.4 JavaDocs). I think they have problems with this method.
TwitterStream twitterStream = TwitterPrintRandomStream.createTwitterConnection();
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
String tw = status.getText() + " " + status.getIsoLanguageCode();
System.out.println(tw);
}
...
}
I also tried the method Status.getUser().getLang() but it returns the user's language not the tweet. Is there any way to do it?
Thanks in advance.
I don't think you can rely on iso_language_code - I couldn't find reference to it in the REST or streaming APIs.
Tweets do have a lang attribute which indicates the language that the Tweet was written in. This was recently added to the API and, unfortunately, Twitter4J does not yet provide you with access to it.
There is a task to add it in version 3.0.4 but the work does not to appear to have started yet. Unfortunately you'll need to wait until they add it or perhaps you could give them a hand and submit a pull-request.
status.getPlace().getCountryCode() should do the trick to get ISO 3166-1 alpha 2 country code
First, Try to get status.getLang() and put em into String then compare it with status.getText() if match you can get the tweets that only contain language in status.getLang()
You can try this following code
String filterTweet=null
String language= status.getLang()
String filterLang="(language code)"
If (filterLang.Matches(language)){
filterTweet=status.getText()}
Cya

How can i send an query from java to lpsolve as String

Hi i formulated a linear programing problem using java
and i want to send it to be solved by lpsolve without the need to create each constraint seperatlly.
i want to send the entire block (which if i insert it to the ide works well) and get a result
so basically instead of using something like
problem.strAddConstraint("", LpSolve.EQ, 9);
problem.strAddConstraint("", LpSolve.LE, 5);
i want to just send as one string
min: 0*x11 + 0*x12 + 0*x13
x11 + x12 + x13= 9;
x12 + x12<5;
can it be done if so how?
LpSolve supports LP files as well as MPS files. Everything is thoroughly detailed in the API documentation (see http://lpsolve.sourceforge.net/5.5/).
You can do your job like this in java :
lp = LpSolve.readLP("model.lp", NORMAL, "test model");
LpSolve.solve(lp)
What is sad with file based approaches is that you will not be able to use warm start features. I would not suggest you to use such approach if you want to optimize successive similar problems.
Cheers

Mysql session variable in JDBC string

am using this connection string to connect to mysql from java:
jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8
is it possible to set the session variable in the string so that SET UNIQUE_CHECKS=0; would be executed upon connecting to server? the obvious
jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&unique_checks=0
doesn't seem to work, based on the fact that
'jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&unique_checks=blahblah`
doesn't generate any error.
Cheers!
How about using sessionVariables:
jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&sessionVariables=unique_checks=0
Your question is thus more "How do I concat Strings in Java?" ?
If so, then just use the + operator:
int uniqueChecks = 0; // Assign session variable here.
String url = "jdbc:mysql://localhost:3306/db?unique_checks=" + uniqueChecks;
Alternatively you can also use String#format() wherein you can use the %d pattern to represent a decimal:
int uniqueChecks = 0; // Assign session variable here.
String url = String.format("jdbc:mysql://localhost:3306/db?unique_checks=%d", uniqueChecks);
You can use Statement.execute() to run pretty much every statement the DB understands, including such a SET-statement.
The advantage of using an URL parameter or a dedicated method is that the JDBC-driver is actually aware that the option was set and can react accordingly. This may or may not be useful or necessary for this particular option, but it's vital for other options (for example toggling autocommit with such a statement is a very bad idea).
BalusC, thanks for a reply! actually I need to do that in Talend etl tool(which itself is a java code generator) and the only line i can edit is the "jdbc:mysql://localhost:3306/db?noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8" string, which gets translated to this java code:
String url_tMysqlBulkExec_1 = "jdbc:mysql://"
+ "localhost" +
":"
+ "3306"
+ "/"
+ "db"
+ "?"
+ "noDatetimeStringSync=true&useUnicode=yes&characterEncoding=UTF-8&unique_checks=0";
that's the limitation, sorry for not pointing that out earlier.
According to mysql docs, there is no possibility to set the unique_checks setting, i guess i need to look for other solution than URL parameters (Joachim, thanks for reminding me that these things are called "URL parameters" - help a lot while googling :)

Categories