Thursday, February 27, 2014

CA CF difference In AS400 Display File

Hi All,  I have seen many places where CA/CF (Command attention and command function) functionality is mixed. So lets understand this with example.

CA -- Command Attention ( Function Key response will be accepted and returned back to RPG program)
CF -- Command function (Function key response will be accepted and returned back to RPG program)

The difference we can check only if there is an input field on screen. With function key indicator set as CA no value typed in input field is returned to RPG program, while if we define function key indicator as CF value typed in input field also returned to RPG program.

Consider the below example : I have a input field with name SCRFLD as name and two function key as CA12 and CF03.

Source code for display file ::
        *************** Beginning of data *************************************
0000.30      A                                      DSPSIZ(24 80 *DS3)         
0000.40      A                                      CF03(03 'Exit')            
0000.50      A                                      CA12(12 'Previous')        
0000.60      A          R RECORD                                               
0000.80      A                                  7 19'Name'                     
0000.90      A            SCRFLD         6A  B  7 26                           
0001.00      A                                 16 20'F3 = Exit'                
0001.10      A                                 16 32'F12=Cancel'               

        ****************** End of data ****************************************

The screen looks like 



When you type Name = Test on screen and press F3. Test will come back to Program. while pressing F12 alone will return the indicator as on and Name field will be blank.

RPG code will be like ::


FCACFTRY   CF   E             workstn
Dname             S              6
C
 /free
   EXFMT Record;
   name = SCRFLD;
   IF *IN03 = *on;
   DSPLY name;
   endif;
   if *in12= *on;
   dsply name;
   endif;
   *inlr = *on;
 /end-free

I hope it is clear how to use CA/CF indicators.

Friday, January 10, 2014

Reading A PF in Reverse Order in CL

I have seen many people discussing about reading a PF in CL in reverse order.

Just remember one thing -- PF should not have key if you are positioning on RRN.

The PF code --

ABCUST file structure :
                                                                         
 A          R RCUST                                                 

 A            CUSNO          5  0                                   
 A            CUSNM         30 


The CL Code -- 

PGM                                                               
             DCL        VAR(&NUBT) TYPE(*DEC) STG(*AUTO) LEN(10)  
             DCL        VAR(&NUBD) TYPE(*DEC) STG(*AUTO) LEN(10)  
             DCL        VAR(&TOT) TYPE(*DEC) STG(*AUTO) LEN(10)   
             DCLF       FILE(GALAXEOBJ/ABCUST) OPNID(ID)          
             RTVMBRD    FILE(GALAXEOBJ/ABCUST) NBRCURRCD(&TOT)    
    /*       CHGVAR     VAR(&TOT) VALUE(&NUBT + &NUBD)      */    
 READ:       OVRDBF     FILE(ABCUST) TOFILE(GALAXEOBJ/ABCUST) +   
                          MBR(*FIRST) POSITION(*RRN &TOT)         
             RCVF       RCDFMT(RCUST) OPNID(ID)                   
             CHGVAR     VAR(&ID_CUSNM) VALUE(&ID_CUSNM)           
             IF         COND(&TOT > 1) THEN(DO)                   
             CHGVAR     VAR(&TOT) VALUE(&TOT - 1)                 
             DLTOVR     FILE(*ALL)                                
             CLOSE      OPNID(ID)                                 
              GOTO READ          
              ENDDO              
 ENDPGM