Hi,
I have a few questions about offline coding, &TEMPLATE, etc.
In an offline program, I noticed that the program structure usually starts with
IF (RequestACTION = &TEMPLATE);
. .
ENDIF;
LRNG_SendReceive((MainLoopCount > 1):RequestPROGRAM:RequestACTION);
*InLR = True;
Return;
whereas in an Online mode, the structure usually has the Main Loop:
DoU (RequestPROGRAM <> ProgramINFO.Name);
MainLoopCount += 1;
Exsr Handle_RequestACTION;
LRNG_SendReceive((MainLoopCount > 1):RequestPROGRAM:RequestACTION);
EndDo;
*InLR = True;
Return;
So my questions are:
1. Why does the Offline structure doesn't have the (DoU (RequestPROGRAM <> ProgramINFO.Name) loop? How does it know when to keep on displaying the form view and not exit the program when it does not have this Do Until loop?
2. In an online structure, if I have several actions to perform like "Button.Onclick : SEARCHEMPLOYEE" and "Button.OnClick : CHECKJOBINFO", in the main loop of the same program I can do a Select Statement on RequestACTION,
SELECT;
WHEN (RequestACTION = SEARCHEMPLOYEE);
...
WHEN (RequestACTION = CHECKJOBINFO);
...
ENDSL;
Can I do the same in an Offline program? If the offline program will always test for "IF (RequestACTION = &TEMPLATE)" and I have several Actions to perform (e.g. SEARCHEMPLOYEE, CHECKJOBINFO), would it be possible to check for these RequestACTION's inside the same program? That means, at some point, I will be operating under a different RequestACTION and not the offline &TEMPLATE?
I checked some of the shipped examples (like EXAM0303), when it comes to its OnClick operations, most of the offline programs calls another program to do some of its routines, like:
Type : PerformAction
Pgm : EXAM0301
Action : CALLED_FROM_EXAM0303
I have never seen an example of an offline program where it checks for different RequestACTIONs inside the same program. I may be wrong, but any clarification on this will be greatly appreciated.
Thanks!
Rocel
(RPG) Offline: Questions about Offline structure
-
MarkDuignan
- Posts: 346
- Joined: Wed Apr 18, 2012 10:33 am
Re: (RPG) Offline: Questions about Offline structure
1.
An offline (or local) program does not execute on the server – the only part that ever executes on the server is when the schema is first loaded. A call is placed to the program to send the “template” of the form view and it behavior to the client. After that initial call the form view works offline and the server side RPG program is never called again. Also see RPG Offline Foundation Tutorial
2
Generally you would not (and could not) structure on offline application that way. Code that you put in your RPG program only ever executes on the server. It generally only once when the schema is being loaded – so the extra code is not going to ever be executed. Offline/local forms are very different in structure to online forms.
3
That example is sending the request to an RPG program (EXAM0301 or EXAM0302) running on the server.
The 'CALLED_FROM_EXAM0303' in the requested action is to let the server program (EXAM0301 or EXAM0302) know what they are being asked (requested) to do.
This means handling of the requested action must be in an online environment (ie: the client can only call server programs when there is an internet connection). EXAM0301 or the tutorial contacts uploaders and downloader – so they are useable when you are online.
In general when an event (say a button click) happen in an offline form view you can handle it in two broad ways:
Send a request to a server program. You would have to be offline to do that of course.
Handle it locally – generally by executing an SQL request, executing some ECL script, or invoking another local form view.
The example you seem to be mentioning is EXAM0303?
The RPG Offline Foundation Tutorials break EXAM0303 example down step by step in the tutorial ‘Code an Offline Form View to Browse Rows in TutorialContacts’. It shows some examples of handling events (button clicks and row selection) locally . eg: All of the buttons on the bottom of the form (except Download Employees and Upload Employees) are events (ie: requested actions) that are handled locally. The upload and download buttons send request to RPG programs that need to be online and execute on the server.
An offline (or local) program does not execute on the server – the only part that ever executes on the server is when the schema is first loaded. A call is placed to the program to send the “template” of the form view and it behavior to the client. After that initial call the form view works offline and the server side RPG program is never called again. Also see RPG Offline Foundation Tutorial
2
Generally you would not (and could not) structure on offline application that way. Code that you put in your RPG program only ever executes on the server. It generally only once when the schema is being loaded – so the extra code is not going to ever be executed. Offline/local forms are very different in structure to online forms.
3
That example is sending the request to an RPG program (EXAM0301 or EXAM0302) running on the server.
The 'CALLED_FROM_EXAM0303' in the requested action is to let the server program (EXAM0301 or EXAM0302) know what they are being asked (requested) to do.
This means handling of the requested action must be in an online environment (ie: the client can only call server programs when there is an internet connection). EXAM0301 or the tutorial contacts uploaders and downloader – so they are useable when you are online.
In general when an event (say a button click) happen in an offline form view you can handle it in two broad ways:
Send a request to a server program. You would have to be offline to do that of course.
Handle it locally – generally by executing an SQL request, executing some ECL script, or invoking another local form view.
The example you seem to be mentioning is EXAM0303?
The RPG Offline Foundation Tutorials break EXAM0303 example down step by step in the tutorial ‘Code an Offline Form View to Browse Rows in TutorialContacts’. It shows some examples of handling events (button clicks and row selection) locally . eg: All of the buttons on the bottom of the form (except Download Employees and Upload Employees) are events (ie: requested actions) that are handled locally. The upload and download buttons send request to RPG programs that need to be online and execute on the server.
Re: (RPG) Offline: Questions about Offline structure
Thanks, Mark for your explanation. That helps a lot.
Now, following your explanation...
1. Does this mean that "TYPE: Performaction" can only be used when calling a program on the server side? Can I use the 'Performaction' to call an offline program?
2. If use 'Openform' to call another local form view, is it possible code this other form view without having a display file? (e.g. I just want to do a pop-up window for the error message)
3. Is it possible to call an RPG program inside an offline program that simply does a batch job process, like perform some calculations? Is there a CALLP (call a prototyped procedure or program) equivalent in the offline structure?
Just wanted to be sure that my understanding is right.
Thanks again!
Now, following your explanation...
1. Does this mean that "TYPE: Performaction" can only be used when calling a program on the server side? Can I use the 'Performaction' to call an offline program?
2. If use 'Openform' to call another local form view, is it possible code this other form view without having a display file? (e.g. I just want to do a pop-up window for the error message)
3. Is it possible to call an RPG program inside an offline program that simply does a batch job process, like perform some calculations? Is there a CALLP (call a prototyped procedure or program) equivalent in the offline structure?
Just wanted to be sure that my understanding is right.
Thanks again!
-
MarkDuignan
- Posts: 346
- Joined: Wed Apr 18, 2012 10:33 am
Re: (RPG) Offline: Questions about Offline structure
Does this mean that "TYPE: Performaction" can only be used when calling a program on the server side? Can I use the 'Performaction' to call an offline program?
I don’t think so. Calling client side logic falls into 2 broad categories. If it’s another formview use OpenForm - either stacking the call so control returns to your formview, or have it replace your program’s formview enirely. If it just ‘logic’ then you probably are best to just code some ECL script and invoke that.
2. If use 'Openform' to call another local form view, is it possible code this other form view without having a display file? (e.g. I just want to do a pop-up window for the error message)
Using DDS is optional with LongRange and no longer the recommended way to use LongRange (see latest tutorials – using DDS is not even mentioned until optional step 11). Also see some of the later offline examples that use the EZI layer without using any DDS.
Your formview program needs to have a formview ‘template’ stored on the client. That normally is provided by an RPG program on the server that sends it up at initialization (the &TEMPLATE request). It can provide that template by DDS, by just setting properties or by using EZI (which is just a faster way to set properties) – or some combination of those. Its important to understand that the RPG program’s logic never runs on the client. The RPG program’s job is just to deliver the formview template, along with SQL binds and commands and sometimes ECL scripting. The SQL binds and commands and ECL scripting are actually the client side logic. They really have nothing to do with the RPG program that delivers the initial template to the client.
So it you wanted just a pop up I would be inclined to use a small amount of ECL scripting to display it. If you look at the example that acts like a calculator I think it displays the calculation in a message box.
If you wanted to use a formview, it would just be a popover of the current form I guess. You’d need the option that tells LR to just update the current screen.
3. Is it possible to call an RPG program inside an offline program that simply does a batch job process, like perform some calculations? Is there a CALLP (call a prototyped procedure or program) equivalent in the offline structure?
Yes. There is no CALLP. PerformAction has pgm parameter See http://www.longrangemobile.com/docs/LRP ... action.htm. That program is expected to be a formview, so IU guess that if it does not want to do anything visual it returns the setting telling LongRange to only update the current screen with changes. If there are no changes – then nothing should happen on the client. That;s the theory – I can’t say I have ever tried that.
I don’t think so. Calling client side logic falls into 2 broad categories. If it’s another formview use OpenForm - either stacking the call so control returns to your formview, or have it replace your program’s formview enirely. If it just ‘logic’ then you probably are best to just code some ECL script and invoke that.
2. If use 'Openform' to call another local form view, is it possible code this other form view without having a display file? (e.g. I just want to do a pop-up window for the error message)
Using DDS is optional with LongRange and no longer the recommended way to use LongRange (see latest tutorials – using DDS is not even mentioned until optional step 11). Also see some of the later offline examples that use the EZI layer without using any DDS.
Your formview program needs to have a formview ‘template’ stored on the client. That normally is provided by an RPG program on the server that sends it up at initialization (the &TEMPLATE request). It can provide that template by DDS, by just setting properties or by using EZI (which is just a faster way to set properties) – or some combination of those. Its important to understand that the RPG program’s logic never runs on the client. The RPG program’s job is just to deliver the formview template, along with SQL binds and commands and sometimes ECL scripting. The SQL binds and commands and ECL scripting are actually the client side logic. They really have nothing to do with the RPG program that delivers the initial template to the client.
So it you wanted just a pop up I would be inclined to use a small amount of ECL scripting to display it. If you look at the example that acts like a calculator I think it displays the calculation in a message box.
If you wanted to use a formview, it would just be a popover of the current form I guess. You’d need the option that tells LR to just update the current screen.
3. Is it possible to call an RPG program inside an offline program that simply does a batch job process, like perform some calculations? Is there a CALLP (call a prototyped procedure or program) equivalent in the offline structure?
Yes. There is no CALLP. PerformAction has pgm parameter See http://www.longrangemobile.com/docs/LRP ... action.htm. That program is expected to be a formview, so IU guess that if it does not want to do anything visual it returns the setting telling LongRange to only update the current screen with changes. If there are no changes – then nothing should happen on the client. That;s the theory – I can’t say I have ever tried that.
Re: (RPG) Offline: Questions about Offline structure
Thanks Mark. You've been most helpful. Really appreciate it.