Returning AS/400 parameters from procedures

Tags:
AS/400 Parameters
Parameters
RPG ILE subprocedure
RPGLE Program
If I have a sub procedure :- P SUBP B D SUBP PI X(10) D Parm1 X D Parm2 X D Parm3 X(10) value options(*nopass) D Data_item X(10) C /free C [some][/some]C If %parm < 3 C Return Data_item C Else C Parm3 = Data_item C Return C Endif C /end free P SUBP E And then if I call it using Callp SUBP(A: B: C) Which means that in SUBP it should go down the 'else' leg of returning the parameter. But when it comes back to the calling procedure it fails with RPG procedure SUBP ended without returning a value Can I mix the two ways of returning a parameter? 1. Where I explicitly RETURN Data_item 2. Fill one of the parameters and then just RETURN

Answer Wiki

Thanks. We'll let you know when a new response is added.

I would do it this way:<pre>
if %parms >= 3 ;
Parm3 = Data_item ;
endif ;

return Data_item ;</pre>
You have a return-value coded. I suspect that it’s going to take a portion of the stack whether the calling procedure uses it or not. The prototype defines it, and there is no way to make it optional on the prototype. You should return it and let the calling proc choose to ignore it.

Tom

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    P SUBP B D SUBP PI X(10) D Parm1 X D Parm2 X D Parm3 X(10) value options(*nopass) D Data_item X(10) What is the X(10) ??? As Tom said you must return a value of type X(10) Remember the procedure can also change he values in Parm1, Parm2 and in Data_Item. Phil As Tom said this procedure must return a
    49,950 pointsBadges:
    report
  • MichaelRlancaster
    Thank you for the update. I have tried that option. I hope I have enough room for the update but here goes. Oh by the way the X(10) was me forgetting that I don't code in Cobol anymore. I meant 10A. I changed the procedure to do - P SUBP B D SUBP PI 10A D Parm1 A D Parm2 A D Parm3 10A value options(*nopass) D Data_item S 10A C /free C [some][/some] C If %parm < 3 C Return Data_item C Else C Parm3 = Data_item C Return Parm3 C Endif C /end free P SUBP E ............. I did the call in two formats - one where I supplied the extra optional parameter as part of the call - callp SUBP(parameter1: parameter2: parameter3) This had nothing in parameter3 upon returning from SUBP. However a call of - TenCharField = SUBP(parameter1: parameter2) - was fine. It just seems to be that if I specify a parameter as part of the procedure interface then trying to use one as an extra parameter to hold a return value doesn't work. Does that sound sensible?
    15 pointsBadges:
    report
  • philpl1jb
    I guess we're saying the same thing If you program the precedure with a return value you must return a value. Right type and size but it can be blank if you want. Parameters will also be "returned" - you're Parm1 and Parm2 can be changed by the procedure and since these were passed by address, the values are changed in the calling procedure. Parm3 passed by value or parameters with const keyword will not return values. Phil
    49,950 pointsBadges:
    report
  • TomLiotta
    D Parm3 10A value options(*nopass) The original lack of new-lines helped me to miss this one. If you include VALUE as a keyword, it cannot return anything to the caller. You never pass the parm into the procedure -- you only pass the value of the parm. Remove the VALUE keyword so that the proc has access to the address back in the caller. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    But you should still RETURN a value whether it's used or not. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    coded as D SUBP PI :10A You MUST[/B] a 10 character return a value. coded as: D SUBP PI you MUST never return a value Phil
    49,950 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following