× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Scott. You answered my questions AND provided a solution.

The reason I headed down the wrong path I did was that I had originally prototyped the return value of the method as void because of the way that I had used it in Java. I had never seen a return value from a put method. I had only seen the method called on the object itself. When I prototyped it this way and called it, I got a signature violation (naturally) because the Java prototype was looking for an object to be returned and the Javadocs I looked at (the same one you referenced) indicated that the method does return an object but I had failed to read the JavaDoc carefully. I expected it would return the modified object (incorrectly). So, although I fixed the signature violation by returning an object, I had an incorrect understanding of what the Java method did and coded the wrapper incorrectly as well.

After making the change I still had a null value but I changed the Java code to give me a bit more information about what is null. Looks like I had a null object reference. Using my newfound understanding of the "put" method, I realized that my RPG wrapper was stomping on the object and setting it to null. So I changed the RPG wrapper code to:

*------------------------------------------------------------
* Add elements to a Hashmap
*
*------------------------------------------------------------
P rre_jMap_put...
P B EXPORT
D rre_jMap_put...
D PI like(jObject)
D peMap like(jMap)
D peKey like(jobject)
D peValue like(jObject)
D lMap s like(jMap)
/free
lMap = JMAP_put(peMap:peKey:peValue);
return lMap;
/end-free
P E
which does what the Java method does and is clearer to me now. Everything works fine.

Thanks for the quick tutorial. I really appreciate it!

Pete


Scott Klement wrote:
HashMap reportParameters = new HashMap();
reportParameters.put("selectName", "BALL");

I understand it to mean that I create a new HashMap object called "reportParameters". It is basically a container into which I can put key/value pairs. So, after creating a new "empty" object, I add the key/value pair I want to assign using "put".

Correct. That's what it does. However, consider the following Java code:

Consider this Java code:

HashMap reportParameters = new HashMap();
Object retval = reportParameters.put("selectName", "BALL");

If you displayed the value of 'retval' after running this code, you'd find that it's set to null, because that's what the 'put' method is returning... it's returning null. For some reason you seem to want to blame the RPG prototypes for this behavior, but it's not the RPG prototypes fault, because the Java code has the same exact result. The only difference was, you weren't checking the return value from the put method (until I added the code, above)


The assignment of the key/value pairs is what I am after so this

lReParam = new_jMap();


...and it does.


is supposed to create the object, and this code:

lkey = new_String('selectName');
lvalue = new_String('BALL');
lReParam = rre_jMap_put(lReParam:lkey:lvalue);

Okay, let's modify your RPG code slightly to look like this:

lkey = new_String('selectName');
lvalue = new_String('BALL');
retval = rre_jMap_put(lReParam:lkey:lvalue);

Assuming that retval is defined as like(jObject) this code does exactly the same thing as the Java code, above. If you check the value of 'retval' you'll see that it's set to *NULL.

What I didn't notice when I read your previous message (but I see it now) is that you're replaces lReParam with the return value from the put method. i.e. you're doing this:

lReParam = rre_jMap_put(lReParam:lkey:lvalue);

This will, quite correctly, assign the key & value to the hash map. However, and here's the problem, it then sets the hashmap object to the return value of the put method, which will be *NULL -- so you're effectively discarding the hashmap.

If you wanted to do the same thing in Java, you'd be doing this:

HashMap lReParam = new HashMap();
lReParam = lReParam.put("selectName", "BALL");

See what I mean? You're replacing the value of lReParam with whatever the 'put' method returns. The put method will return the prior value of "selectName", but since there was no prior value, it'll return null.

Effectively, you're wiping out the value of lReParam.

If you want your RPG code to work like the Java code, do this instead:

lReParam = new_jMap();
lkey = new_String('selectName');
lvalue = new_String('BALL');
rre_jMap_put(lReParam:lkey:lvalue);

You don't want to assign the return value from rre_jMap_put to lReParam, because if you do that, you're setting lReParam to null.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.