Saturday, 16 February 2013

as400 sub systems


Introduction to IBM AS/400 Sub Systems

AS/400 entire system performance is actually carried out in sub systems. All the AS/400 sub systems are specialized.
The main general purpose sub system of AS/400 is known as QBASE.

QBASE – Sub System

This general purpose sub system is provided by IBM
We can configure AS/400 machine to run the entire system operations using QBASE or else we can split the jobs among several sub systems. If we run AS/400 machine is QBASE, all interactive and batch jobs run in QBASE. It has its own advantages as well as disadvantages.
Advantages
  • Simplicity in management, here only one sub system needs to be controlled.
  • All system functions runs in easy mode, system startup, shutdown, control operations Etc.
Disadvantages
  • In this mode of system functioning, only one sub system QBASE is forced to do all the Jobs/system functions Etc.
  • In this mode of operations, its tough to tune AS/400 machine well and machine won’t perform well.

Multiple Sub Systems

Running the AS/400 machine with multiple sub systems is always a better choice because each sub system is specialized for certain kind of job and we will get better control over the system. Tuning up AS/400 becomes very easier in multiple sub systems environment.
There is three main sub systems present.
QCTL
OCTL is the controlling sub system. Its called QCTL because it control the system and also another sub system to which the system console is attached.
If the QCTL is ended all the sub systems ends automatically.
QCTL shouldn’t be used for regular application software jobs such as interactive jobs and batch jobs as it will slow down the entire system performance.
It should be reserved for system console only.

QINTER
QINTER is a interactive sub system.
All Interactive jobs should run in QINTER. And batch jobs never run under QINTER.
Never submit a batch job under QINTER. If you ran any batch jobs under QINTER it will slow down machine performance.
We can use QINTER to sign on to all display stations except the system console. Ending the QINTER affects all display stations except the system console.
We can use the below command to end the QINTER sub system.
ENDSBS QINTER (*CNTRLD) or ENDSBS QINTER (*IMMED)
ENDSBS QINTER (*CNTRLD) ends the QINTER and allows all interactive jobs continue to run for a certain amount of time.
ENDSBS QINTER (*IMMED) ends QINTER and all interactive jobs immediately.
Ending QINTER is an easier way to prevent users to access the system
QBATCH
QBATCH is used to process the batch jobs.
Batch jobs are the jobs which are submitted to a job queue for processing.
QBATCH is specially designed to run batch jobs and will perform poorly with interactive jobs.
We can use the below command to end the QBATCH sub system.
ENDSBS QBATCH OPTION (*CNTRLD) DELAY (*NOMAX)
===================
 
 

Tuesday, 21 August 2012

Embedding SQL in Free Format

Embedding SQL in /free

 
To embed SQL into an RPG program, the SQL pre-compiler has to go through the source code first and convert the SQL statements to program calls. To do this, we have to signal the pre-compiler that a particular section of source code is in fact SQL by wrapping the code in c/exec sql and c/end-exec compiler directives. On top of that, each line inside these directives must have c+ in positions 6 and 7. Here is an example:
c/exec sql
c+   select *
c+     into :mainDS
c+     from MYLIB/MYFILE
c+    where IDFIELD = :KEY_VALUE
c/end-exec
For the embedded SQL newcomer, the statement above will get all the fields from a record and place the contents into a data structure named mainDS. This block of code would execute just fine in either fixed- or free-format, but free-format it means first issuing a /end-free statement and then reissueing a /free statement after the SQL. There is lots of room for improvement here, and more than likely we want to deal with a group of records, which means DECLARE CURSOR, OPEN, FETCH, CLOSE, and possibly PREPARE statements. Explanation of these is beyond the scope of this article, but here is a sample bit of code that uses all the above in free-format:
d mainDS        e ds                  extname(MYNAMES)

d sql             s          32000a   varying
d                                     inz( 'Select * from mynames +
d                                     order by USERNAME' )
d message         s             52a   inz

c/exec sql
c+ declare mainCursor cursor
c+     for mainStatement
c/end-exec
c/exec sql
c+ prepare mainStatement
c+    from :sql
c/end-exec
c/exec sql
c+ open mainCursor
c/end-exec
c/exec sql
c+ fetch next from mainCursor
c+  into :mainDS
c/end-exec
 /free
   dow sqlstt = '00000' ;
     message = %trimr( m_USERNAME ) + ' ' + %trimr( m_USEREMAIL ); 
     dsply message ;
 /end-free
c/exec sql
c+   fetch next from mainCursor
c+    into :mainDS
c/end-exec
 /free
    enddo ;
 /end-free
c/exec sql
c+ close mainCursor
c/end-exec
 /free
    *inlr = *on ;
 /end-free
The Ugly Factor
The issue with embedded SQL in free-format has primarily to do with the need to constantly drop in and out of /free to execute SQL statements. As demonstrated above, this can be quite messy. In fact, this is downright ugly. And it can easily get worse! Multiple cursors, additional select statements, updates, deletes, and inserts can all be interspersed with sections of free-format code. Eventually you have as much time invested in compiler directives as you do in actual code. This approach can be difficult to read, which means it is difficult to manage.
I have personally written enough code with embedded SQL that I can pretty much ignore the ugliness, but many people contend that we shouldn't have to deal with this in the first place. There is enough discontent with this particular topic that some people refuse to use /free. IBM should be paying attention: If the party line is to adopt free-format RPG, then it needs to be cleaner, especially when dealing with SQL. No matter your opinion on the matter--and there are many--this is the current state of things, so let's discuss getting rid of the ugliness.
So how do we conquer the ugliness? Embedded SQL requires the c/exec sql and c/end-exec blocks, so there isn't any way to get rid of those. And we already know that we cannot use embedded SQL statements inside free-format. Our only recourse then is to separate the embedded SQL from the free-format code. Naturally, for such an operation, we are going to turn to our trusty tool: the subprocedure.
Using SQL in Subprocedures
Subprocedures are an excellent mechanism for detaching our ugly SQL statements from our program logic. Ultimately, since we can't change the rules, the ugliness still remains, but the final affect is much more palatable. Before we begin breaking our program up into smaller chunks, there are some pesky rules to go over.
First, the SQL Precompiler, at least through V5R2, requires that some of the SQL statements occur in the source code in the correct physical order. Specifically, since the DECLARE statement must be logically executed before the related OPEN the precompiler expects them to be in this order in the actual source code. If you try to compile a program that has the OPEN statement physically before the DECLARE statement, you should receive an SQL0504 ("Position xx Cursor %CURSORNAME% not declared.") compile error. The same rule however is not true for OPEN and FETCH statements, which compile just fine out of order. Honestly, I don't know if this applies to any others or not, but to avoid confusion and compile problems, I always try to place the subprocedures in the same physical order as their logical execution.
Second, the use of local variables. Since we are moving these statements to subprocedures, we can take advantage of local variables, but with restrictions. Namely, if the variable name is also not a global variable name, an SQL statement should be able to use the local variable as a host variable. To complicate matters, this is not always true. The local name can be the same as a global name, provided that both variables are defined the same. Otherwise, SQL will get confused and not recognize the value of either variable. This is only a problem if the local and global variables are defined differently. But don't let any of this odd behavior fool you into thinking something is wrong with the SQL precompiler: the manual in V5R3 still states: "The names of host variables must be unique within the program, even if the host variables are in different procedures." So ultimately, this has nothing to do with global versus local! The solution is to ensure that your host variable names unique no matter what.
To avoid confusion, I've adopted the convention that all host variables should be global. For update and insert statements, I like to use an externally defined DS based on the same file. This way the variable definitions are guaranteed to be correct. As a result, no data conversion is ever required so I get a little performance boost. You can populate the variables before calling the procedure or use local variables to populate the global host variables if you like. While it is a little extra work, being cognizant of this issue beforehand can save you time and aggravation.
Modularizing the Program
Now that we know what the rules are, we can transfer the SQL statements out of our mainline and into subprocedures. This really couldn't be any easier: Simply move the offending statements to a basic procedure shell, add the prototype to the D-Specs, and replace the original code with the new procedure call. Apply this to the code posted above and here is the result:
d mainDS        e ds                  extname(MYNAMES) prefix(m_)

 * Prototypes
d declare         pr
d openCursor      pr
d fetchNext       pr
d closeCursor     pr

 * Standalone Variables
d sql             s          32000a   varying
d                                     inz( 'Select * from mynames +
d                                     order by USERNAME' )
d message         s             52a   inz

 /free
   declare();
   openCursor();
   fetchNext();
   dow sqlstt = '00000' ;
     message = %trimr( m_USERNAME ) + ' ' + %trimr( m_USEREMAIL ); 
     dsply message ;
     fetchNext();
   enddo ;
   closeCursor();
   *inlr = *on ;
 /end-free

 *-------------------------------------------------------------------
p declare         b
d declare         pi

c/exec sql
c+ declare mainCursor cursor
c+     for mainStatement
c/end-exec
c/exec sql
c+ prepare mainStatement
c+    from :sql
c/end-exec

p declare         e
 *-------------------------------------------------------------------
p openCursor      b
d openCursor      pi

c/exec sql
c+ open mainCursor  
c/end-exec

p openCursor      e
 *-------------------------------------------------------------------
p fetchNext       b
d fetchNext       pi

c/exec sql
c+ fetch next from mainCursor
c+  into :mainDS   
c/end-exec

p fetchNext       e 
 *-------------------------------------------------------------------
p closeCursor     b
d closeCursor     pi

c/exec sql
c+ close mainCursor
c/end-exec

p closeCursor     e
 *-------------------------------------------------------------------

You'll notice quickly that there isn't much to any of the procedures. The real gem here is in the main line. Hopefully you'll agree that this is much more palatable than what we started with. We certainly have a lot less jumping in and out of free-format, even in the subprocedures, since they are primarily SQL.
Obviously this is a very simple example, but let me point out a couple of things. At first glance, it appears that the declare() and open() procedures could be combined. While in this case that may be true, what if the cursor had a variable where clause? To handle this, the SQL statement would include a parameter marker for the where value:
d sql             s          32000a   varying
d                                     inz( 'Select * from mynames +
d                                     where USEREMAIL like (?) +
d                                     order by USERNAME' )
If the declare() and open() procedures were combined, then the statement would get re-prepared and the cursor re-declared every time the where clause changes. That's a lot of unnecessary overhead, so most of the time it makes sense to separate these into their own procedures. If you really want to get the declare() statement out of the mainline, try setting a global variable such as isDeclared and checking its state in the open() subprocedure, calling declare() if it the subprocedure hasn't been executed yet.

A Few More Tidbits
For scrollable cursors, is to have a single fetch procedure (instead of our unidirectional fetchNext) that accepts a parameter for the fetch method and some branching logic. Below is a simple example, you could easily add the rest of the scroll types (i.e. FIRST, LAST, CURRENT, etc.) to this code.
In the declare() subprocedure:
c/exec sql
c+ declare mainCursor scroll cursor
c+     for mainStatement
c/end-exec
And the fetch() subprocedure:
p fetch           b
d fetch           pi
d  scrollType                   10a   const options(*nopass)

 /free
   if %parms() = 0 or scrollType = 'NEXT' ;
 /end-free
c/exec sql
c+   fetch next from mainCursor
c+    into :mainDS  
c/end-exec
 /free
   elseif scrollType = 'PRIOR' ;
 /end-free
c/exec sql
c+   fetch prior from mainCursor
c+    into :mainDS
c/end-exec
 /free
   endif ;
 /end-free

p fetch           e
Granted, a bit of the ugliness has returned with this sort of branching. Remember, I said we couldn't get rid of the ugliness, but we could reduce it. At least we are limiting it to this subprocedure and getting it out of the mainline. And of course, you could have separate subprocedures for each of these instead of one subprocedure.
Another thing you could do is to make your fetch() routine(s) return a boolean value representing whether or not a record was found. I'm not going to demonstrate it, just check the value of SQLSTT and return *ON or *OFF based on your particular needs. The benefit of this is a little less mainline:
 /free
   declare();
   openCursor();
   dow fetchNext();
     message = %trimr( m_USERNAME ) + ' ' + %trimr( m_USEREMAIL ); 
     dsply message ;
   enddo ;
   closeCursor();
   *inlr = *on ;
 /end-free
You also no longer have the "priming" call to fetchNext() and the "continuing" call.
Final Thoughts
I do, as always, have a few items on my wish list. The first is to find a solution to the problems with the local variables discussed above. Second, I'd like to have enhanced cursor support, more like an actual OO-style result set. Looping through a cursor is OK, but sometimes I want to know how many records the cursor has, or maybe dump the contents of a cursor into an array or even an outfile. I can imagine a lot of similar tasks and uses. I'd really like to be able to pass a cursor between programs and to be able to retrieve data from a cursor by referencing field name or ordinal position. Mostly, and more in line with the topic of this article, I'd like to see a set of SQL Built-In Functions (BIFs). For example, %execSQL(), %declareSQL(), %prepareSQL(), %opencursor(), %fetchSQL(), etc. could certainly eliminate the need for the c/exec-sql and c/end-exec directives, which would go a long way to improving the use of SQL in free-format RPG.
In the meantime, while the techniques in this article aren't perfect, they can simplify and cleanse your mainline code. This is especially true when you have a lot of conditional updating, multiple cursors, and the like. It certainly provides some relief for those of us wishing to take advantage of both SQL and free-format RPG

Sunday, 8 April 2012

Example : ILE RPG Date Formatting Code


H option(*nodebugio)                                                  
D @charA          S              8    inz('04/12/01')                 
D @charB          S             10    inz('12/02/2004')               
D @charC          S              8    inz('12/03/04')                 

D @dateA          S               d   inz(D'2004-12-04')              
D @numA           S              6  0 inz(041205)                     
D @numB           S              7  0 inz(1041206)                    
D @numC           S              8  0 inz(20041207)                   
D @numD           S              6  0 inz(120804)                     
D @numE           S              8  0 inz(12092004)                   

/free                                                                                          
// character to character...                                                                  
@charB = %char(%date(@charA:*ymd/):*usa/);                // 'yy/mm/dd'     to  'mm/dd/ccyy'  
@charC = %char(%date(@charA:*ymd/):*mdy/);                // 'yy/mm/dd'     to  'mm/dd/yy'    
@charA = %char(%date(@charB:*usa/):*ymd/);                // 'mm/dd/ccyy'   to  'yy/mm/dd'    
@charC = %char(%date(@charB:*usa/):*mdy/);                // 'mm/dd/ccyy'   to  'mm/dd/yy'    
@charA = %char(%date(@charC:*mdy/):*ymd/);                // 'mm/dd/yy'     to  'yy/mm/dd'    
@charB = %char(%date(@charC:*mdy/):*usa/);                // 'mm/dd/yy'     to  'mm/dd/ccyy'  

// character to date...                                                                       
@dateA = %date(@charA:*ymd/);                             // 'yy/mm/dd'     to  D'ccyy-mm-dd' 
@dateA = %date(@charB:*usa/);                             // 'mm/dd/ccyy'   to  D'ccyy-mm-dd' 
@dateA = %date(@charC:*mdy/);                             // 'mm/dd/yy'     to  D'ccyy-mm-dd' 

// character to numeric...                                                                    
@numA = %dec(%char(%date(@charA:*ymd/):*ymd0):6:0);       // 'yy/mm/dd'     to  yymmdd        
@numB = %dec(%char(%date(@charA:*ymd/):*cymd0):7:0);      // 'yy/mm/dd'     to  cyymmdd       
@numC = %dec(%char(%date(@charA:*ymd/):*iso0):7:0);       // 'yy/mm/dd'     to  ccyymmdd      
@numD = %dec(%char(%date(@charA:*ymd/):*mdy0):7:0);       // 'yy/mm/dd'     to  mmddyy        
@numE = %dec(%char(%date(@charA:*ymd/):*usa0):7:0);       // 'yy/mm/dd'     to  mmddyyyy      
@numA = %dec(%char(%date(@charB:*usa/):*ymd0):6:0);       // 'mm/dd/ccyy'   to  yymmdd        
@numB = %dec(%char(%date(@charB:*usa/):*cymd0):7:0);      // 'mm/dd/ccyy'   to  cyymmdd       
@numC = %dec(%char(%date(@charB:*usa/):*iso0):7:0);       // 'mm/dd/ccyy'   to  ccyymmdd        
@numD = %dec(%char(%date(@charB:*usa/):*mdy0):7:0);       // 'mm/dd/ccyy'   to  mmddyy          
@numE = %dec(%char(%date(@charB:*usa/):*usa0):7:0);       // 'mm/dd/ccyy'   to  mmddyyyy        
@numA = %dec(%char(%date(@charC:*mdy/):*ymd0):6:0);       // 'mm/dd/yy'     to  yymmdd          
@numB = %dec(%char(%date(@charC:*mdy/):*cymd0):7:0);      // 'mm/dd/yy'     to  cyymmdd         
@numC = %dec(%char(%date(@charC:*mdy/):*iso0):7:0);       // 'mm/dd/yy'     to  ccyymmdd        
@numD = %dec(%char(%date(@charC:*mdy/):*mdy0):7:0);       // 'mm/dd/yy'     to  mmddyy          
@numE = %dec(%char(%date(@charC:*mdy/):*usa0):7:0);       // 'mm/dd/yy'     to  mmddyyyy        

// date to character...                                                                         
@charA = %char(@dateA:*ymd/);                             // D'ccyy-mm-dd'  to  'yy/mm/dd'      
@charB = %char(@dateA:*usa/);                             // D'ccyy-mm-dd'  to  'mm/dd/ccyy'    
@charC = %char(@dateA:*mdy/);                             // D'ccyy-mm-dd'  to  'mm/dd/yy'      

// date to numeric...                                                                           
@numA = %dec(%char(@dateA:*ymd/):6:0);                    // D'ccyy-mm-dd'  to  yymmdd          
@numB = %dec(%char(@dateA:*cymd/):7:0);                   // D'ccyy-mm-dd'  to  cyymmdd         
@numC = %dec(%char(@dateA:*iso-):8:0);                    // D'ccyy-mm-dd'  to  ccyymmdd        
@numD = %dec(%char(@dateA:*mdy/):6:0);                    // D'ccyy-mm-dd'  to  mmddyy          
@numE = %dec(%char(@dateA:*usa/):8:0);                    // D'ccyy-mm-dd'  to  mmddccyy        

// numeric to character...                                                                      
@charA = %char(%date(@numA:*ymd):*ymd/);                  // yymmdd         to  'yy/mm/dd'      
@charB = %char(%date(@numA:*ymd):*usa/);                  // yymmdd         to  'mm/dd/ccyy'    


@charC = %char(%date(@numA:*ymd):*mdy/);                  // yymmdd         to  'mm/dd/yy'   
@charA = %char(%date(@numB:*cymd):*ymd/);                 // cyymmdd        to  'yy/mm/dd'   
@charB = %char(%date(@numB:*cymd):*usa/);                 // cyymmdd        to  'mm/dd/ccyy' 
@charC = %char(%date(@numB:*cymd):*mdy/);                 // cyymmdd        to  'mm/dd/yy'   
@charA = %char(%date(@numC:*iso):*ymd/);                  // D'ccyy-mm-dd'  to  'yy/mm/dd'   
@charB = %char(%date(@numC:*iso):*usa/);                  // D'ccyy-mm-dd'  to  'mm/dd/ccyy' 
@charC = %char(%date(@numC:*iso):*mdy/);                  // D'ccyy-mm-dd'  to  'mm/dd/yy'   
@charA = %char(%date(@numD:*mdy):*ymd/);                  // mmddyy         to  'yy/mm/dd'   
@charB = %char(%date(@numD:*mdy):*usa/);                  // mmddyy         to  'mm/dd/ccyy' 
@charC = %char(%date(@numD:*mdy):*mdy/);                  // mmddyy         to  'mm/dd/yy'   
@charA = %char(%date(@numE:*usa):*ymd/);                  // mmddccyy       to  'yy/mm/dd'   
@charB = %char(%date(@numE:*usa):*usa/);                  // mmddccyy       to  'mm/dd/ccyy' 
@charC = %char(%date(@numE:*usa):*mdy/);                  // mmddccyy       to  'mm/dd/yy'   

// numeric to date...                                                                        
@dateA = %date(@numA:*ymd);                               // yymmdd         to  D'ccyy-mm-dd'
@dateA = %date(@numB:*cymd);                              // cyymmdd        to  D'ccyy-mm-dd'
@dateA = %date(@numC:*iso);                               // ccyymmdd'      to  D'ccyy-mm-dd'
@dateA = %date(@numD:*mdy);                               // mmddyy         to  D'ccyy-mm-dd'
@dateA = %date(@numE:*usa);                               // mmddccyy       to  D'ccyy-mm-dd'

// numeric to numeric...                                                                     
@numB = %dec(%char(%date(@numA:*ymd):*cymd0):7:0);        // yymmdd         to  cyymmdd      
@numC = %dec(%char(%date(@numA:*ymd):*iso0):8:0);         // yymmdd         to  ccyymmdd     

@numD = %dec(%char(%date(@numA:*ymd):*mdy0):6:0);         // yymmdd         to  mmddyy    
@numE = %dec(%char(%date(@numA:*ymd):*usa0):8:0);         // yymmdd         to  mmddccyy  
@numA = %dec(%char(%date(@numB:*cymd):*ymd0):6:0);        // cyymmdd        to  yymmdd    
@numC = %dec(%char(%date(@numB:*cymd):*iso0):8:0);        // cyymmdd        to  ccyymmdd  
@numD = %dec(%char(%date(@numB:*cymd):*mdy0):6:0);        // cyymmdd        to  mmddyy    
@numE = %dec(%char(%date(@numB:*cymd):*usa0):8:0);        // cyymmdd        to  mmddccyy  
@numA = %dec(%char(%date(@numC:*iso):*ymd0):6:0);         // ccyymmdd       to  yymmdd    
@numB = %dec(%char(%date(@numC:*iso):*cymd0):7:0);        // ccyymmdd       to  cyymmdd   
@numD = %dec(%char(%date(@numC:*iso):*mdy0):6:0);         // ccyymmdd       to  mmddyy    
@numE = %dec(%char(%date(@numC:*iso):*usa0):8:0);         // ccyymmdd       to  mmddccyy  
@numA = %dec(%char(%date(@numD:*mdy):*ymd0):6:0);         // mmddyy         to  yymmdd    
@numB = %dec(%char(%date(@numD:*mdy):*cymd0):7:0);        // mmddyy         to  cyymmdd   
@numC = %dec(%char(%date(@numD:*mdy):*iso0):8:0);         // mmddyy         to  ccyymmdd  
@numE = %dec(%char(%date(@numD:*mdy):*usa0):8:0);         // mmddyy         to  mmddccyy  
@numA = %dec(%char(%date(@numE:*usa):*ymd0):6:0);         // mmddccyy       to  yymmdd    
@numB = %dec(%char(%date(@numE:*usa):*cymd0):7:0);        // mmddccyy       to  cyymmdd   
@numC = %dec(%char(%date(@numE:*usa):*iso0):8:0);         // mmddccyy       to  ccyymmdd  
@numD = %dec(%char(%date(@numE:*usa):*mdy0):6:0);         // mmddccyy       to  mmddyy    

*inlr = *on;

Tuesday, 18 October 2011

RPGLE - Retrieve deleted records from file

 RPGLE  - Retrieve deleted records from file

D TotalC          S              9S 0
     D Len             S              9B 0 Inz( 265 )
     D Fmt             S              8    Inz( 'MBRD0200' )
     D FilNam          S             20    Inz( 'LOCDTP    LOCATOR   ' )
     D MbrNam          S             10    Inz( '*FIRST' )
     D OvrPrs          S              1    Inz( '0' )
     D Error           S             30

     D Out             DS           265
     D  BytRet                 1      4B 0
     D  BytAvl                 5      8B 0
     D  MbrName               29     38
     D  PFLF                 137    137
     D  Total                141    144B 0
     D  DelRcd               145    148B 0
     D  NoMbrs               157    160B 0

     C     APIList       PList
     C                   Parm                    Out
     C                   Parm                    Len
     C                   Parm                    Fmt
     C                   Parm                    FilNam
     C                   Parm                    MbrNam
     C                   Parm                    OvrPrs
     C                   Parm                    Error
     C                   Call      'QUSRMBRD'    APIList
     C                   Z-Add     Total         TotalC
     C     BytRet        Dsply
     C     BytAvl        Dsply
     C     MbrName       Dsply
     C     PFLF          Dsply
     C     TotalC        Dsply
     C     DelRcd        Dsply
     C     NoMbrs        Dsply
     C                   Eval      *InLR = *On

RPGLE - QLGSORT - Use APi to sort subfile data

    RPGLE  - QLGSORT - Use APi to sort subfile data

*==============================================================
      * Subroutine - SortSfl
      *
      *  For information on Sort API's see
      *  OS/400 National Language Support API Guide
      *  This subroutine sorts the subfile records.
      *==============================================================

     c     $SortSFL      begsr
      *
      * Initialize the key fields to sort on.
      * Load S1PRO#     field as key field, 07 byte, dec, ascending sequence.
      *
     c                   eval      KeyStart   = 1
     c                   eval      KeySize    = 07
     c                   eval      KeyDtaTyp  = 2
     c                   eval      KeyAscDesc = 1
     c                   eval      KeyInf(1)  = KeyInfDs
      *
      * Load S1CNAM     field as key field, 30 byte, char , descending sequence.
      *
     c                   eval      KeyStart   = 8
     c                   eval      KeySize    = 30
     c                   eval      KeyDtaTyp  = 6
     c                   eval      KeyAscDesc = 2
     c                   eval      KeyInf(2)  = KeyInfDs
      *
      * Load other sort parameters.
      *
     c                   eval      BlockLen  = 80 + 16 * MaxKey
     c                   eval      NbrOfKeys = 2                                Variable
     c                   eval      RecLen    = %size(SFLRCD)
      *
      * Initialize Sort I/O API fields.
      *
     c                   eval      IORecLen = RecLen
     c                   eval      IORecCnt = 1
      *
      * All done initializing.
      * First step - Initialize the sort routine.
      *
     c                   call      'QLGSORT'
     c                   parm                    SortBlock
     c                   parm                    NotUsed
     c                   parm                    NotUsed
     c                   parm                    SizeList
     c                   parm                    ReturnSize
     c                   parm                    Error
      *
      * Next step - write records to I/O routine.
      *
     c                   eval      IOType = 1
      *
      * read the entire subfile
      *
     c                   for       count   = 1 to Savrrn
      *
     c     count         chain     SUB01
      *
     c                   if        %found
      *
     c                   call      'QLGSRTIO'
     c                   parm                    SortIOBloc
     c                   parm                    SflRcd
     c                   parm                    NotUsed
     c                   parm                    SizeList
     c                   parm                    NotUsed
     c                   parm                    Error
      *
     c                   endif
      *
     c                   endfor
      *
      * Next step - Signal end of input, clear subfile for reload.
      *
     c                   eval      IOType = 2
     c
     c                   call      'QLGSRTIO'
     c                   parm                    SortIOBloc
     c                   parm                    SflRcd
     c                   parm                    NotUsed
     c                   parm                    SizeList
     c                   parm                    NotUsed
     c                   parm                    Error
      *
      *    Clear the subfile
      *
     c                   exsr      $ClearSFL
      *
      * Final step - write the records back to the subfile.
      *
     c                   eval      IOType = 3
      *
      *
      * read the entire subfile
      *
     c                   for       count   = 1 to Savrrn
      *
     c                   call      'QLGSRTIO'
     c                   parm                    SortIOBloc
     c                   parm                    NotUsed
     c                   parm                    SflRcd
     c                   parm                    IORecLen
     c                   parm                    NotUsed
     c                   parm                    Error
      *
     c                   eval      RRN1 = Count
     c                   eval      SCRRN = RRN1
     c                   write     Sub01
      *
     c                   endfor
     c                   eval      SubfileEnd = *on
     c                   z-add     SCRRN         SavRrn
      *
     c                   if        SavRrn = *Zeros  And   SubfileEnd
     c                   eval      DisplaySubfile = *Off
     c                   else
     c                   eval      RRN1  = 1.
     c                   eval      SCRRN = 1.
     c                   endif
      *
     c                   endsr
      *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-==-
      *  $PosSubfile - Position the subfile
      *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-==-
     cSR   $PosSubfile   begsr
      *
     c                   for       count   = 1 to Savrrn
      *
     c     count         chain     SUB01
     c                   if        %found        and
     c                             S1PRO# = C1PRO#  or
     c                             %found        and
     c                             S1PRO# > C1PRO#  or
     c                             count = Savrrn
      *
     c                   eval      RRN1 = Count
     c                   eval      SCRRN = Count
      *
      * check to see last pink record and un-pink it
      *
     c                   if        LastPinkRRN > *Zeros
     c     LastPinkRRN   chain     SUB01
     c                   if        %found
     c                   eval      Pink = *Off
     c                   update    SUB01
     c                   clear                   LastPinkRRN
     c                   endif
     c                   endif
      *
     c     Count         chain     SUB01
     c                   if        %found
     c                   clear                   C1PRO#
     c                   eval      Pink = *On
     c                   update    SUB01
     c                   eval      Pink = *Off
     c                   z-add     Count         LastPinkRrn
     c                   leave
     c                   endif
      *
     c                   endif
      *
     c                   endfor
      *
     c                   endsr
      *

RPGLE - Generate a random number


    RPGLE  - Generate a random number

d instartnumber   s             15  5
     d inendnumber     s             15  5
     d inrandomnumber  s             15  5
     d wkseed          s              9  9
     d wkstartnumber   s              6  0
     d wkendnumber     s              6  0
     d wkrandomnumber  s              6  0
     d range           s              6  0
     d time            s             12  0
     c     *entry        plist
     c                   parm                    instartnumber
     c                   parm                    inendnumber
     c                   parm                    inrandomnumber
      *
     c                   eval      wkstartnumber  = instartnumber
     c                   eval      wkendnumber    = inendnumber
     c                   eval      wkrandomnumber = inrandomnumber
      *
     c                   if        wkseed = *zeros
     c                   time                    time
     c     .000000001    mult      time          wkseed
     c                   endif
      *
     c                   if        wkstartnumber = *zeros and
     c                             wkendnumber = *zeros   or
     c                             wkendnumber < wkstartnumber
     c                   eval      wkstartnumber = 1
     c                   eval      wkendnumber = 999999
     c                   endif
      *
     c                   eval      range = (wkendnumber -wkstartnumber) + 1
      *
     c                   mult      9821          wkseed
     c                   add       .211327       wkseed
     c                   eval      wkrandomnumber =  (wkseed * range) +
     c                             wkstartnumber
     c                   eval      *inlr = *on

RPGLE - CALENDAR


        RPGLE  - CALENDAR

**********************************************************************
      *                                                                    *
     ‚*  Program Name  : CALENDAR                                          *
     ‚*  Function      : To Select date.                                   *
      *                                                                    *
      **********************************************************************
      * Å¡Logic         :€It Uses output fields to display the date.        *
      *                  1. Current date is obtained from system           *
      *                  2. For the current month, the first day of        *
      *                     of the month and no. of days in the month      *
      *                     is calculated.                                 *
      *                  3. Using this the datastructure is populated      *
      *                     then this value is copied to the display       *
      *                     fields.                                        *
      **********************************************************************

     ‚* Header Specifications
     ‚* =====================
      *
     H DFTACTGRP(*NO)

     ‚* Files Used
     ‚* ==========
      *
     Å¡* Display file - Calendar
     FCALENDARFMCF   E             WORKSTN

     ‚* Procedures Used
     ‚* ===============
      *
     Å¡* To get the day of the week
     D GetDay          PR             1  0
     D  Date                           D   Value
      *
     Å¡* To get No of days in a month
     D GetDate         PR             2  0
     D  Date                           D   Value
      *
     Å¡* This will return the month(Text) for the numeric passed.
     D GetMonth        PR             9
     D  Month                         2  0 Value

     ‚* Data Structures Used
     ‚* ====================
      *
     Å¡* This DS is for Finding first day of the month.
     D Date_DS_1       DS
     D  DS_1_Date                      D   DATFMT(*USA) INZ
     D  DS_1_MM                       2S 0 OVERLAY(DS_1_Date:1)
     D  DS_1_DD                       2S 0 OVERLAY(DS_1_Date:4) inz(1)
     D  DS_1_YYYY                     4S 0 OVERLAY(DS_1_Date:7)
      *
     Å¡* This DS will hold current date values.
     D Date_DS_2       DS
     D  DS_2_Date                      D   DATFMT(*USA) INZ
     D  DS_2_MM                       2S 0 OVERLAY(DS_2_Date:1) inz(5)
     D  DS_2_DD                       2S 0 OVERLAY(DS_2_Date:4) inz(31)
     D  DS_2_YYYY                     4S 0 OVERLAY(DS_2_Date:7) inz(2003)

     ‚* Variables Used
     ‚* ==============
      *
     D FirstDay        S              1  0
     D CurrDay         S              1  0
     D MaxDate         S              2  0
     D LiveMonth       S              2  0
     D LiveDate        S              2  0
     D LiveYear        S              4  0
      *
     D Dates           S              2    DIM(37)
     D Count           S              2  0
     D Temp            S              2  0
     D I               S              2  0
     D Selected        S               N   Inz(*Off)
     D Res             S              1

      **********************************************************************
     ‚*                 M A I N L I N E   P R O C E S S I N G              *
      **********************************************************************

     ˜* Exfmt the Calendar display till F3 or a date is Selected
     C                   DoW       Selected = *Off And *IN03 = *Off

     ˜* This calculates the date as per the (M+ or M-) and (Y+ or Y-)
     ˜* Triggered by the user and restores the display.
     C                   Select
     C                   When      OptYearM  = 1
     C                   Eval      DS_2_Date = DS_2_Date - %Years(1)
     C                   MoveA     '0010'        *In(41)
     C                   When      OptMonthM = 1
     C                   Eval      DS_2_Date = DS_2_Date - %Months(1)
     C                   MoveA     '1000'        *In(41)
     C                   When      OptMonthP = 1
     C                   Eval      DS_2_Date = DS_2_Date + %Months(1)
     C                   MoveA     '0100'        *In(41)
     C                   When      OptYearP  = 1
     C                   Eval      DS_2_Date = DS_2_Date + %Years(1)
     C                   MoveA     '0001'        *In(41)
     C                   EndSl

     ˜* Assigns the current values to the Datastructure one
     ˜* so that the maximum no of days and first day of the month
     ˜* is calculated.
     C                   Eval      Count = 0
     C                   Eval      DS_1_MM   = DS_2_MM
     C                   Eval      DS_1_YYYY = DS_2_YYYY

     ˜* This gets the first day of the month
     C                   Eval      FirstDay = GetDay(DS_1_Date)

     ˜* This gets the Current day (Today)
     C                   Eval      CurrDay = GetDay(DS_2_Date)

     ˜* This gets the no of days in the month
     C                   Eval      MaxDate  = GetDate(DS_1_Date)

     ˜* This gets the month(Text) of the month so that it can
     ˜* be displayed on the DSPF
     C                   Eval      Month = getMonth(DS_2_MM)
     C                   Move      DS_2_YYYY     Year

     ˜* This Subroutine populates the Datastructure for the Current
     ˜* Selection(Month and Year)
     C                   ExSr      InitDates

     ˜* This Turns the required indicators for display
     C                   ExSr      SetIndicators

     ˜* This assigns the values from the datastructure to the DSPF fields
     C                   ExSr      SetValues

     ˜* Displays the Calendar for the Current month and Year Selection
     C                   ExFmt     CALENDAR

     ˜* If user strikes Enter key apart from F3 then we have to see
     ˜* whether user has chosed any date.
     C                   If        *In03 = *Off
     C                   ExSr      CheckSel
     C                   EndIf
     C                   EndDo

     C                   If        Selected = *On
     C                   Move      Dates(I)      DS_2_DD
     C     DS_2_Date     Dsply                   Res
     C                   EndIf

     C                   Eval      *inlr = *on

      **********************************************************************
     ‚*    *INZSR        ==> Initialize Sub-Routine                        *
      **********************************************************************
     C     *INZSR        BegSr

     ˜* Current date is retrieved for initial display
     C                   Eval      DS_2_Date = %Date()
     C                   Eval      LiveMonth = DS_2_MM
     C                   Eval      LiveYear  = DS_2_YYYY
     C                   Eval      LiveDate  = DS_2_DD

     ˜* This frames the string which is displayed at the bottom
     C                   Eval      OutPut = %Char(LiveDate)   + ' ' +
     C                             %Trim(getMonth(LiveMonth)) + ', ' +
     C                             %Char(LiveYear)

     C                   Eval      *In41 = *On

     C                   EndSr

      **********************************************************************
     ‚*    InitDates     ==> Initialize the Datastructure                  *
     ‚*                      For Eg. consider the date September 2003      *
     ‚*                      1. The month has got 30 days                  *
     ‚*                      2. First day is Monday                        *
     ‚*                      Hence the DS is populated as follows:         *
     ‚*                        --> DS(1) = *Blanks                         *
     ‚*                        --> DS(2) = '1'                             *
     ‚*                        --> DS(3) = '2' .....                       *
     ‚*                        --> DS(32)= '30'                            *
     ‚*                        --> DS(33)= *Blanks .....                   *
     ‚*                        --> DS(37)= *Blanks                         *
      **********************************************************************
     C     InitDates     BegSr

     C                   Clear                   Dates

     C                   Eval      Temp = MaxDate + FirstDay

     C                   For       I = 1 to 37

     C                   Select
     C                   When      I <= FirstDay Or I > Temp
     C                   Eval      Dates(I) = *BLANKS
     C                   When      I > FirstDay And I <= Temp
     C                   Eval      Count = Count + 1
     C                   Move      Count         Dates(I)
     C                   EndSl

     C                   EndFor

     C                   EndSr

      **********************************************************************
     ‚*    SetIndicators ==> Turn Reqd. Indicators for display             *
      **********************************************************************
     C     SetIndicators BegSr

     C                   For       I = 50 to 56
     C                   Eval      *In(I) = *Off
     C                   EndFor

     C                   For       I = 60 to 96
     C                   Eval      *In(I) = *Off
     C                   EndFor

     C                   If        LiveMonth = DS_2_MM And
     C                             LiveYear  = DS_2_YYYY
     C                   Eval      *In(50 + CurrDay) = *On
     C                   Eval      *In(60 + LiveDate + FirstDay - 1) = *On
     C                   EndIf

     C                   EndSr

      **********************************************************************
     ‚*    SetValues     ==> Copies the DS to DSPF fields                  *
      **********************************************************************
     C     SetValues     BegSr

     C                   Move      Dates(1)      SET1
     C                   Move      Dates(2)      SET2
     C                   Move      Dates(3)      SET3
     C                   Move      Dates(4)      SET4
     C                   Move      Dates(5)      SET5
     C                   Move      Dates(6)      SET6
     C                   Move      Dates(7)      SET7

     C                   Move      Dates(8)      SET8
     C                   Move      Dates(9)      SET9
     C                   Move      Dates(10)     SET10
     C                   Move      Dates(11)     SET11
     C                   Move      Dates(12)     SET12
     C                   Move      Dates(13)     SET13
     C                   Move      Dates(14)     SET14

     C                   Move      Dates(15)     SET15
     C                   Move      Dates(16)     SET16
     C                   Move      Dates(17)     SET17
     C                   Move      Dates(18)     SET18
     C                   Move      Dates(19)     SET19
     C                   Move      Dates(20)     SET20
     C                   Move      Dates(21)     SET21

     C                   Move      Dates(22)     SET22
     C                   Move      Dates(23)     SET23
     C                   Move      Dates(24)     SET24
     C                   Move      Dates(25)     SET25
     C                   Move      Dates(26)     SET26
     C                   Move      Dates(27)     SET27
     C                   Move      Dates(28)     SET28

     C                   Move      Dates(29)     SET29
     C                   Move      Dates(30)     SET30
     C                   Move      Dates(31)     SET31
     C                   Move      Dates(32)     SET32
     C                   Move      Dates(33)     SET33
     C                   Move      Dates(34)     SET34
     C                   Move      Dates(35)     SET35

     C                   Move      Dates(36)     SET36
     C                   Move      Dates(37)     SET37

     C                   EndSr

      **********************************************************************
     ‚*    CheckSel      ==> Checks whether user has msde any selection    *
      **********************************************************************
     C     CheckSel      BegSr

     C                   For       I = 1 to 37
     C                   If        FLD = 'SET'+ %Char(I) and
     C                             Dates(I) <> *Blanks
     C                   Eval      Selected = *ON
     C                   Leave
     C                   EndIf
     C                   EndFor

     C                   EndSr

      **********************************************************************
     ‚*    GetDay        ==> This returns the day of the Date              *
     ‚*                      The logic implemented is:                     *
     ‚*                      %Rem(((Date) - (Standard Date)) / 7)          *
     ‚*                      The Standard date will be any Reference       *
     ‚*                      Day. If the reminder is Zero then the         *
     ‚*                      current day is standard day. If it is         *
     ‚*                      '1' then its monday like so...                *
      **********************************************************************
     P GetDay          B

     D  GetDay         PI             1  0
     D   Date                          D   Value

     D  Days           S             15P 0
     D  Day            S              1  0
     D  Sunday         C                   D'1999-12-19'

     C     Date          SubDur    Sunday        Days:*DAYS
     C                   Eval      Day = %Rem(Days:7)
     C                   If        Day < 0
     C                   Eval      Day = Day + 7
     C                   EndIf

     C                   Return    Day

     P                 E

      **********************************************************************
     ‚*    GetDay        ==> This returns the no of days in the month      *
     ‚*                      The logic implemented is:                     *
     ‚*                      Difference between Current date and           *
     ‚*                      (Current Date + One Month) in No of Days      *
      **********************************************************************
     P GetDate         B

     D  GetDate        PI             2  0
     D   Date                          D   Value

     D   Date1         S               D

     C                   Eval      Date1 = Date + %Months(1)
     C                   Return    %Diff(Date1:Date:*D)

     P                 E

      **********************************************************************
     ‚*    GetMonth      ==> This returns the Month in Text for the        *
     ‚*                      Numeric passed                                *
      **********************************************************************
     P GetMonth        B

     D  GetMonth       PI             9
     D   Month                        2  0 VALUE

     C                   Select
     C                   When      Month = 01
     C                   Return    'January'
     C                   When      Month = 02
     C                   Return    'February'
     C                   When      Month = 03
     C                   Return    'March'
     C                   When      Month = 04
     C                   Return    'April'
     C                   When      Month = 05
     C                   Return    'May'
     C                   When      Month = 06
     C                   Return    'June'
     C                   When      Month = 07
     C                   Return    'July'
     C                   When      Month = 08
     C                   Return    'August'
     C                   When      Month = 09
     C                   Return    'September'
     C                   When      Month = 10
     C                   Return    'October'
     C                   When      Month = 11
     C                   Return    'November'
     C                   When      Month = 12
     C                   Return    'December'
     C                   Other
     C                   Return    ' '
     C                   EndSl

     P                 E


**======================================================
                                              D  D  S
**======================================================


A*%%TS  SD  20030717  173714  USC2643     REL-V5R1M0  5722-WDS
     A*%%EC
     A                                      DSPSIZ(24 80 *DS3)
     A                                      CF03(03 'EXIT')
     A                                      MOUBTN(*ULP ENTER)
     A          R CALENDAR
     A*%%TS  SD  20030717  173714  USC2643     REL-V5R1M0  5722-WDS
     A                                      WINDOW(7 25 14 35)
     A                                      RTNCSRLOC(&REC &FLD)
     A            FLD           10A  H
     A            REC           10A  H
     A                                  1 14'Calendar'
     A                                      DSPATR(BL)
     A                                      DSPATR(HI)
     A                                  2  2'Month. .:'
     A                                      COLOR(BLU)
     A                                  3  2'Year. . :'
     A                                      COLOR(BLU)
     A            YEAR           4A  O  3 12COLOR(TRQ)
     A                                  5  2'SUN'
     A N50                                  COLOR(YLW)
     A  50                                  COLOR(WHT)
     A                                  5  7'MON'
     A N51                                  COLOR(BLU)
     A  51                                  COLOR(WHT)
     A                                  5 12'TUE'
     A N52                                  COLOR(BLU)
     A  52                                  COLOR(WHT)
     A                                  5 17'WED'
     A N53                                  COLOR(BLU)
     A  53                                  COLOR(WHT)
     A                                  5 22'THU'
     A N54                                  COLOR(BLU)
     A  54                                  COLOR(WHT)
     A                                  5 27'FRI'
     A N55                                  COLOR(BLU)
     A  55                                  COLOR(WHT)
     A                                  5 32'SAT'
     A N56                                  COLOR(YLW)
     A  56                                  COLOR(WHT)
     A            SET1           2A  O  6  3
     A N60                                  COLOR(YLW)
     A  60                                  COLOR(WHT)
     A            SET2           2A  O  6  8
     A N61                                  COLOR(GRN)
     A  61                                  COLOR(WHT)
     A            SET3           2A  O  6 13
     A N62                                  COLOR(GRN)
     A  62                                  COLOR(WHT)
     A            SET4           2A  O  6 18
     A N63                                  COLOR(GRN)
     A  63                                  COLOR(WHT)
     A            SET5           2A  O  6 23
     A N64                                  COLOR(GRN)
     A  64                                  COLOR(WHT)
     A            SET6           2A  O  6 28
     A N65                                  COLOR(GRN)
     A  65                                  COLOR(WHT)
     A            SET7           2A  O  6 33
     A N66                                  COLOR(YLW)
     A  66                                  COLOR(WHT)
     A            SET8           2A  O  7  3
     A N67                                  COLOR(YLW)
     A  67                                  COLOR(WHT)
     A            SET9           2A  O  7  8
     A N68                                  COLOR(GRN)
     A  68                                  COLOR(WHT)
     A            SET15          2A  O  8  3
     A N74                                  COLOR(YLW)
     A  74                                  COLOR(WHT)
     A            SET16          2A  O  8  8
     A N75                                  COLOR(GRN)
     A  75                                  COLOR(WHT)
     A            SET22          2A  O  9  3
     A N81                                  COLOR(YLW)
     A  81                                  COLOR(WHT)
     A            SET23          2A  O  9  8
     A N82                                  COLOR(GRN)
     A  82                                  COLOR(WHT)
     A            SET29          2A  O 10  3
     A N88                                  COLOR(YLW)
     A  88                                  COLOR(WHT)
     A            SET30          2A  O 10  8
     A N89                                  COLOR(GRN)
     A  89                                  COLOR(WHT)
     A            SET36          2A  O 11  3
     A N95                                  COLOR(YLW)
     A  95                                  COLOR(WHT)
     A            SET37          2A  O 11  8
     A N96                                  COLOR(GRN)
     A  96                                  COLOR(WHT)
     A            SET10          2A  O  7 13
     A N69                                  COLOR(GRN)
     A  69                                  COLOR(WHT)
     A            SET11          2A  O  7 18
     A N70                                  COLOR(GRN)
     A  70                                  COLOR(WHT)
     A            SET12          2A  O  7 23
     A N71                                  COLOR(GRN)
     A  71                                  COLOR(WHT)
     A            SET13          2A  O  7 28
     A N72                                  COLOR(GRN)
     A  72                                  COLOR(WHT)
     A            SET14          2A  O  7 33
     A N73                                  COLOR(YLW)
     A  73                                  COLOR(WHT)
     A            SET17          2A  O  8 13
     A N76                                  COLOR(GRN)
     A  76                                  COLOR(WHT)
     A            SET18          2A  O  8 18
     A N77                                  COLOR(GRN)
     A  77                                  COLOR(WHT)
     A            SET19          2A  O  8 23
     A N78                                  COLOR(GRN)
     A  78                                  COLOR(WHT)
     A            SET20          2A  O  8 28
     A N79                                  COLOR(GRN)
     A  79                                  COLOR(WHT)
     A            SET21          2A  O  8 33
     A N80                                  COLOR(YLW)
     A  80                                  COLOR(WHT)
     A            SET24          2A  O  9 13
     A N83                                  COLOR(GRN)
     A  83                                  COLOR(WHT)
     A            SET25          2A  O  9 18
     A N84                                  COLOR(GRN)
     A  84                                  COLOR(WHT)
     A            SET26          2A  O  9 23
     A N85                                  COLOR(GRN)
     A  85                                  COLOR(WHT)
     A            SET27          2A  O  9 28
     A N86                                  COLOR(GRN)
     A  86                                  COLOR(WHT)
     A            SET28          2A  O  9 33
     A N87                                  COLOR(YLW)
     A  87                                  COLOR(WHT)
     A            SET31          2A  O 10 13
     A N90                                  COLOR(GRN)
     A  90                                  COLOR(WHT)
     A            SET32          2A  O 10 18
     A N91                                  COLOR(GRN)
     A  91                                  COLOR(WHT)
     A            SET33          2A  O 10 23
     A N92                                  COLOR(GRN)
     A  92                                  COLOR(WHT)
     A            SET34          2A  O 10 28
     A N93                                  COLOR(GRN)
     A  93                                  COLOR(WHT)
     A            SET35          2A  O 10 33
     A N94                                  COLOR(YLW)
     A  94                                  COLOR(WHT)
     A            OUTPUT        25A  O 13  2COLOR(PNK)
     A            OPTMONTHM      2Y 0B  2 24PSHBTNFLD((*NUMCOL 2) (*GUTTER 2))
     A  41                                  DSPATR(PC)
     A                                      PSHBTNCHC(1 '-')
     A            OPTMONTHP      2Y 0B  2 29PSHBTNFLD((*NUMCOL 2) (*GUTTER 2))
     A  42                                  DSPATR(PC)
     A                                      PSHBTNCHC(1 '+')
     A            OPTYEARM       2Y 0B  3 24PSHBTNFLD((*NUMCOL 2) (*GUTTER 2))
     A  43                                  DSPATR(PC)
     A                                      PSHBTNCHC(1 '-')
     A            OPTYEARP       2Y 0B  3 29PSHBTNFLD((*NUMCOL 2) (*GUTTER 2))
     A  44                                  DSPATR(PC)
     A                                      PSHBTNCHC(1 '+')
     A                                  4  1'__________________________________-
     A                                      _'
     A                                      COLOR(BLU)
     A                                 12  1'__________________________________-
     A                                      _'
     A                                      COLOR(BLU)
     A            MONTH          9A  O  2 12COLOR(TRQ)
     A          R DUMMY
     A                                      KEEP
     A                                      ASSUME
     A                                  1  3' '