Sample code: How to create radio buttons in display files

This articles shows a basic example of how to code the display file to create single or multiple choice radio buttons.  The code sample starts with the display file (RADIOFM) and is followed by some simplistic RPG  free format program (RADIO1R) .

S1REGION = "single choice field" where only one button can be selected, the value of field S1REGION will need to be checked.

A          R REGION
A            S1REGION       2Y 0B 02 12SNGCHCFLD                   
A                                      COLOR( WHT )        
A                                      CHOICE(1 '>1. Multiple Regions')   
A                                      CHOICE(2 '>2. Cambodia, Laos, Vietnam')
A                                      CHOICE(3 '>3. Thailand')   
A                                      CHOICE(4 '>4. Taiwan')
A                                      CHOICE(5 '>5. Japan') 
S1REGIONS = "multiple choice field" where more than one button can be selected (CHCCTL fields are checked for values)

A          R REGIONS
A            S1REGIONS      2Y 0B 02 12MLTCHCFLD                   
A                                      COLOR( WHT )        
A                                      CHOICE(1 '>1. Hong Kong')   
A                                      CHOICE(2 '>2. Cambodia, Laos, Vietnam')
A                                      CHOICE(3 '>3. Thailand')   
A                                      CHOICE(4 '>4. Taiwan')
A                                      CHOICE(5 '>5. Japan') 
A                                      CHCCTL(1 &RADIO1)
A                                      CHCCTL(2 &RADIO2)
A                                      CHCCTL(3 &RADIO3)
A                                      CHCCTL(4 &RADIO4)
A                                      CHCCTL(5 &RADIO5)
A            &RADIO1       1Y 0H 
A            &RADIO2       1Y 0H
A            &RADIO3       1Y 0H
A            &RADIO4       1Y 0H
A            &RADIO5       1Y 0H 

Sample free format RPG to display the single select and multiple select radio buttons:

0001.00      FRADIOFM   CF   E             WORKSTN INFDS(FIDS) 
0002.00      D FIDS            DS                              
0003.00      D  STDFIL           *FILE                         
0004.00      D  STDFMT           *RECORD                       
0005.00      D  STACTN               369    369                
0006.00      D  STCSRP               370    371B 0             
0007.00      D  @@L                  370    370                
0008.00      D  @@C                  371    371                
0009.00      D                                                 
0010.00      D msgdt           s             50    inz         
0011.00      D HongKong        s              1    inz         
0012.00      D SEAsia          s              1    inz         
0013.00      D Thailand        s              1    inz         
0014.00      D Taiwan          s              1    inz         
0015.00      D Japan           s              1    inz         
0016.00                                                        
0017.00       /free                                      
0018.00         exfmt region;                            
0019.00         select;                                  
0020.00          when s1region = 1;                      
0021.00            exfmt regions;                        
0022.00           select;                                
0023.00         // multiple choice fields                
0024.00         // check buttons for multiple selections!
0025.00             when radio1 = 1;                     
0026.00              eval HongKong=*on;                  
0027.00             when radio2 = 1;                     
0028.00              eval SEAsia=*on;                    
0029.00             when radio3 = 1;                     
0030.00              eval Thailand=*on;                  
0031.00             when radio4 = 1;                     
0032.00              eval Taiwan=*on;                    
0033.00             when radio5 = 1;                   
0034.00              eval Japan=*on;                   
0035.00             endsl;                             
0036.00         // single choice, check s1region field only
0037.00          when s1region = 2;                    
0038.00              eval msgdt='SE Asia was selected';
0039.00          when s1region = 3;                    
0040.00              eval msgdt='Thailand was selected';
0041.00          when s1region = 4;                    
0042.00              eval msgdt='Taiwan was selected'; 
0043.00          when s1region = 5;                    
0044.00              eval msgdt='Japan was selected';  
0045.00          endsl;                                
0046.00                                                
0047.00         dsply msgdt;                           
0048.00                                                
0049.00         *inlr=*on;                           
0050.00         return;                              
0051.00       /end-free