Is there a way to do Goto and Tags within free form? Is there a different way to do it without using Goto's and tags?
Announcement
Collapse
No announcement yet.
Goto Tag in Free Form
Collapse
X
-
Re: Goto Tag in Free Form
You can not do goto in free, the opcode has been canned!
I'm with Bryce -- please give a detailed description of what you are trying
to do....
thanks
jamieAll my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: Goto Tag in Free Form
Just example code.......I am going to change the in03 to not run below code if *on.
Code:C $start tag /free *in31 = *on; write commands1; write xrefctl01; *in31 = *off; setll (ehtrdprt : ehbeg03) ep_850hdr1; rrn1 = *zero; read ep_850hdr1; dow not %eof(ep_850hdr1); rrn1 += 1; write xrefsfl01; read ep_850hdr1; enddo; exfmt xrefctl01; /end-free C if *in03 = *on C goto $end C endif C if *in05 = *on C goto $start C endif /free readc xrefsfl01; dow not %eof(ep850xrffm); if actxrf = 'R'; exsr $reject; endif; if actxrf = 'A'; exsr $accept; endif; readc xrefsfl01; enddo; /end-free C $end tag /free *inlr = *on; return; /end-free * C EndDo
Last edited by Dhascup; January 30, 2008, 09:51 AM.
Comment
-
Re: Goto Tag in Free Form
Wrap the whole thing inside a dow loop that is DOW not *in03;
then you can set *in03=*on; and it won't iterate anymore. Or, the better way, without indicators...
DOW (*insert some natural program stop such as some sort of EOF*)
*if at anytime you would hit the condition that set *in03=*on; you just do a LEAVE; instead.
That will jump you out of the loop
ENDDO
//now you do the ending
*inlr=*on;
return;
try not to use indicators for program control. Its messy, hard to read, and hard to get right.
Comment
-
Re: Goto Tag in Free Form
you just do a LEAVE; instead.
That will jump you out of the looptry not to use indicators for program control. Its messy, hard to read, and hard to get right.
next you'll be suggesting using ITER next...You don't stop playing games because you get old, You get old because you stop playing games!
Comment
-
Re: Goto Tag in Free Form
LEAVE is nothing more than a goto. It's a bit of a marmite opcode. I guess it depends where you've come from. I learnt to program in Java first where such nasties are possible but generally avoided like the plague. My project manager cut his teeth on RPG II where he tells me GOTO and indicators were all you had. Having said that he agrees with me on the LEAVE opcode but not everyone does.Ben
Comment
-
Re: Goto Tag in Free Form
I find it very useful for when I'm checking if the user pressed F3 or F12. The screen is in a loop of DOW not Exit or Return. Have them defined as F3 or F12 and if that then Leave. Maybe I'm doing this wrong, but at this point I don't know a better way... What do you suggest instead of using a LEAVE? As long as you are using LEAVE not in a nested loop it really is pretty straight forward. You get into trouble when you rely on it to jump 3 or 4 or more hops out of the structure...that is not good, I agree.
Please enlighten me.
Comment
-
Re: Goto Tag in Free Form
If you need to exit processing immediately, and not execute the remainder of the code then probably something like:
Code:Dow not F3 and not F12; \\ some code If not F3 and not F12; \more code Endif; Enddo;
You don't stop playing games because you get old, You get old because you stop playing games!
Comment
-
Re: Goto Tag in Free Form
So you reverse the logic and make your code inclusive instead of exclusive...
I see where you are going on this...I'll have to take a look at it later...I'd ask the question is which is more prone to error, but I'm guessing everybody would say that using the LEAVE would be more error prone...
Comment
-
Re: Goto Tag in Free Form
something like this
Code:d EndScreen1 s 1 inz('N') //-------------------------------------------------------- // $Screen1 - parameter screen //-------------------------------------------------------- begsr $Screen1; reset EndScreen1; dow EndScreen1 = 'N'; if ScreenError = 'N'; $clearmsg('*' : *zero : *Blanks : '*ALL' : APIError); endif; write FKEY01; write MSGCTL; exfmt SUB01CTL; $clearmsg('*' : *zero : *Blanks : '*ALL' : APIError); reset ScreenError; if Currec <> *Zeros; RRN1 = Currec; SCRRN = Currec; endif; select; // // F3 pressed end the program F3 = LeaveP // when Choice = LeaveProgram; EndScreen1 = 'Y'; // // F4 pressed vendor lookup // when Choice = prompt; $VendorLookup(OutVendor : OutName : Inabreviation : Insubgroup : InOptions ); // // Enter Key pressed // when Choice = enterKey; if c1vendor = *blanks; // exsr $validate; else; exsr $search; if SQLGroup# > *zeros; clear c1vendor; else; screenerror = 'Y'; messageid = 'PCH3201'; messagedata = %trim(c1vendor); messagelen = %len(%trim(messagedata)); $sendmsg(messageID : messageFile : messagedata : messageLen : '*DIAG' : @PGM : messagecsc : messagekey : APIError ); endif; endif; endsl; enddo; endsr;
All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: Goto Tag in Free Form
I like your use of the select/when Jamie. I truly never thought of using that. Its still using an "indicator" type of boolean variable. This is acceptable and using an actual indicator is not? I think the stigma against indicators is that programmers will use the friggin indicator number instead of naming it and turning it off and on by name. On/Off or True/False or 'Y'/'N'. Its all the same.
I see that I can definitely get rid of the LEAVE but I don't think you can really get away from boolean control...
Comment
-
Re: Goto Tag in Free Form
In the dds you define every friggen key as well as (INDARA) this will send the
HEX byte bit whatever back to the RPG program.
PHP Code:A*%%TS SD 20080123 165037 FLANARY REL-V5R4M0 5722-WDS
A*%%EC
A DSPSIZ(24 80 *DS3)
A INDARA
A CF01
A CF02
A CF03
A CF04
A CF05
A CF06
A CF07
A CF08
A CF09
A CF10
A CF11
A CF12
A CF13
A CF14
A CF15
A CF16
A CF17
A CF18
A CF19
A CF20
A CF21
A CF22
A CF23
A CF24
A N41 PAGEDOWN
A PAGEUP
Code:fBRC06INTADcf e workstn INFDS(INFDS) f SFILE(SUB01:RRN1) f SFILE(SUB02:RRN2) // notice 369 = the hex code returned d Infds ds d Choice 369 369 d Currec 378 379I 0 // define the keys rename them to something that makes sense // Command Keys d Cmd01 c const(x'31') d Cmd02 c const(x'32') d LeaveProgram c const(x'33') d RetrieveLabel c const(x'34') d Cmd05 c const(x'35') d Cmd06 c const(x'36') d Cmd07 c const(x'37') d PrintLabels c const(x'38') d SaveLabels c const(x'39') d CenterLine c const(x'3A') d Cmd11 c const(x'3B') d Cmd12 c const(x'3C') d Cmd13 c const(x'B1') d Cmd14 c const(x'B2') d Cmd15 c const(x'B3') d Cmd16 c const(x'B4') d Cmd17 c const(x'B5') d Cmd18 c const(x'B6') d Cmd19 c const(x'B7') d Cmd20 c const(x'B8') d Cmd21 c const(x'B9') d Cmd22 c const(x'BA') d Cmd23 c const(x'BB') d Cmd24 c const(x'BC') d EnterKey c const(x'F1') d RollUp c const(x'F5') d RollDown c const(x'F4')
All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: Goto Tag in Free Form
I use it as a shell so I just keep em all there....
also when someone mods your program later on
they only have to look to the d specs and add a
function key......no need to compile the DDS
Your a very smart young manAll my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
Comment