|
Hello, > Can some one try to advise me on how can I eliminate indicators and > replace with builtin functions in my code, is there anyway still i can > reduce my code...if possible pls answer..this code what I ve written is > working for me but nt looking beautiful.. I don't see why you've got both RPG and CL programs. If you examine your CL program carefully, you'll see that it doesn't really do anything except call your RPG program. Why not call the RPG program directly? Here's what I'd do: a) Eliminate the indicators by using an INDDS. This is a data structure that maps the indicators from the display file (IN03 and IN99) to named indicators in RPG. Makes the program easier to read! b) Eliminate teh GOTOs. Your program has two tags, one is to jump back to the top, which can be done easily with a loop, the other is to exit the program, which could be done by simply leaving the loop -- or by executing the RETURN statement. c) Rather than all the logic for checking upper/lower case Y and N, and then setting the return field to match, use %xlate() to convert it to uppercase, and just copy the field over. That'll eliminate a lot of code right there! d) Replace the RPG III factor1/factor2/result op-codes with 1990's RPG IV "extended factor 2" operations. Here's the result of that conversion: FYYESNO CF E WORKSTN indds(ScrnInds) D ScrnInds ds D exit_key 03 03N D error 99 99N c *entry plist c parm rply 1 c eval reply = 'N' c dou error = *off c exfmt dsply c eval error = *off c if exit_key = *on c eval *inlr = *on c leave c endif c eval reply = %xlate(Reply: 'yn': 'YN') c if reply<>'Y' and reply<>'N' c eval Error = *on c endif c enddo c eval Rply = Reply c eval *inlr = *on You can take it a step further by convering it to free-form RPG. Though, frankly with code this simple (and this code is VERY VERY simple) the difference between /FREE and fixed isn't that big of a deal. The biggest change is that you replace the *ENTRY PLIST with a prototype & procedure interface: FYYESNO CF E WORKSTN indds(ScrnInds) D YYESNO PR ExtPgm('YYESNO') D Rply 1A D YYESNO PI D Rply 1A D ScrnInds ds D Exit_Key 03 03N D Error 99 99N /free *INLR = *ON; Reply = 'N'; dou Error = *OFF; exfmt DSPLY; Error = *OFF; if (Exit_Key); leave; endif; Reply = %xlate(Reply: 'yn': 'YN'); if (reply<>'Y' and reply<>'N'); Error = *On; endif; enddo; Rply = Reply; return; /end-free Then, what you SHOULD do is put the prototype in a separate member, and use /COPY to bring it into this program. That way, when you call it from another program, you can re-use that prototype for validity checking. So now you've got the following members: member: yyesno_h D YYESNO PR extpgm('YYESNOR') D Rply 1A member: yeesnor FYYESNO CF E WORKSTN indds(ScrnInds) /copy YYESNO_H D YYESNO PI D Rply 1A D ScrnInds ds D Exit_Key 03 03N D Error 99 99N /free *INLR = *ON; Reply = 'N'; dou Error = *OFF; exfmt DSPLY; Error = *OFF; if (Exit_Key); leave; endif; Reply = %xlate(Reply: 'yn': 'YN'); if (reply<>'Y' and reply<>'N'); Error = *On; endif; enddo; Rply = Reply; return; /end-free And when you call it from another RPG program, you can do it like this: /copy yyesno_h /free .... other program code goes here... YYESNOR(Reply); if (Reply = 'Y'); ... do whatever you'll do if user says YES else; ... do whatever you'll do if user says NO or presses F3. endif; If you wanted to take it even further, you could make it a subprocedure in a service program so that you could use a return value... but I think I've given you enough to think about for now :)
As an Amazon Associate we earn from qualifying purchases.
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.