Page 1 of 1

(RPG) Transferring parms between offline programs

Posted: Wed Feb 24, 2016 3:20 am
by DavidS
Hello, me again with another awkward question.

In brief I'm trying to pass the user selection in program 1 to program 2 to populate a screen field.

The selection I want to pass is when the user touches a row on a table to pass the value of that row, I assume my code would need to look something like this:
OnRowClicked.Operation
(
Type : PerformAction
Pgm : PROG2
Action : CALLED_FROM_PROG1
Param%1 : ValuefromTable
) +
I can't figure out how to put the value from the table into the parameter though. A couple of methods I've tried (for reference the value is column 2, called stock, linked to field stockcode on a local table.)
Param%1 : col%2
Param%1 : STOCK
Param%1 : ( FLD:STOCKCODE )

In the first two cases it has taken my input to be a character constant, in the third it returned a blank. I assume there is some combination of syntax I'm missing here so hopefully someone can point out :)

The second problem I've got is populating the field in program 2, I think the problem is that I've linked the field to a global variable:
LRNG_SetProperty( '/Form.Fields.S1BARC.Value.&.GVAR': 'LASTSTOCKCODE' );
So when I try to set property on it this doesn't take, I've tested by transferring to a different field on screen:
LRNG_GetProperty( 'CurrentOp.Param%1' : S1STCK : %size(S1STCK) );
This then shows the value (although due to above problem not the right value.)

I'm wondering if what I need to do is to invoke a javascript call in program1 to populate the global variable and so it'll be available in program2?

Re: (RPG) Transferring parms between offline programs

Posted: Wed Feb 24, 2016 7:28 am
by tsupartono
Hi David,
There is currently no way to specify (declaratively) that we want the Param values to come from the row.

The best way would be to write a small ECL script that retrieves the selected stock value, and then programmatically invoke the 'PerformAction' operation, passing the stock value.

I have provided below an example of the script as a starting point.

Code: Select all

lrexec(
	function()
	{
		// Retrieve the stock code from the row that triggered this script              
		this.q_sql("SELECT &(FLD:STOCKCODE)", "scalar");
	},
	function(stockCode)
	{
		this.console("Selected stock code = " + stockCode);
		
		// Now launch the second form
		var op =
		{
			type: "performaction",
			pgm: "VIEWSTOCK",
			param: [ stockCode ]
		};
		this.q_setProperties({ runoperation: op });
	}	
);

With this script, instead of directly setting up the OnRowClick with PerformAction operation, you'd set it up with ExecScript operation.
E.g.

Code: Select all

OnRowClick.Operation 
(
   Type : ExecScript
   Script: "the script goes here"
}
or, you can place the script in a resource file (which is the better approach, but make sure you declare the resource file in the schema properties so it will get downloaded).

Code: Select all

OnRowClick.Operation 
(
   Type : PerformAction 
   Resource: myscript.js
}

Re: (RPG) Transferring parms between offline programs

Posted: Wed Feb 24, 2016 7:47 am
by DavidS
Thanks for the reply tsupartono. As mentioned I was starting to lean towards some sort javascript and it's useful to hear someone confirm it and point the way forward.