On RPG-LE Development

Postings on RPG-LE and i5/OS

Posts Tagged ‘RPGLE

RPGLE and DDS MAPVAL

leave a comment »

I have an input date field on a display that I wanted to initially show as blank because it is used as a filter-by-date value.  Blank means nothing was entered by the user so don’t do the filtering.  I wanted DDS to force a valid *USA format for input.    I also wanted blanks to be a valid input value so the user could clear a previously entered filter-date.

DDS provides a very easy approach to solving this problem without a lot of code in the application. The key to this is the DDS MAPVAL function.

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00030A            S1FDATE         L         DATFMT(*MDY) DATSEP('/')
00040A                                      MAPVAL(('01/01/40' *BLANK))

During an output operation, the field data is compared to each program-value on the MAPVAL keyword in the order in which the program-values are specified. For the first match that is found, the corresponding system-value replaces the current field data. If a match does not exist, the field data does not change.

During an input operation, the field data is compared to each system-value on the MAPVAL keyword in the order in which the system-values are specified. For the first match that is found, the corresponding program-value replaces the current field data. If a match does not exist, the field data remains the same.

Option indicators are not valid for this keyword, although you can use option indicators to condition the field for which it is specified.
On output, if the field data equals ’01/01/40′, the field data is changed to all blanks. On input, if the field data is blank, the field data is changed to ’01/01/40′.

Inside the RPGLE application I defined a few dates to perform format conversion.

D SAVFDATE        S               D   DATFMT(*USA)
D DFTFDATE        S               D   DATFMT(*USA) INZ(D'0001-01-01')
D CCYYMMDD        S               D   DATFMT(*ISO)

Finally, the logic created to pull it all together.

 * A valid *USA date will be returned if entered.  A freshly initialized         
 * screen will show the date field as blank, but when it gets to this code       
 * the field has been initialized by RPG to '01/01/0001' which is contained      
 * in DFTFDATE.  Comparing SAVFDATE to DFTFDATE is in essence testing for        
 * the fact the user has not entered a valid search date.                        
C     SAVFDATE      IFNE      DFTFDATE                                           
C                   MOVE      SAVFDATE      CCYYMMDD                             
C                   MOVE      CCYYMMDD      SAVFDATEN                            
C     RHCTDT        IFEQ      SAVFDATEN                                          
C                   MOVEL     @YES          INCLUDE                              
C                   ELSE                                                         
C                   MOVEL     @NO           INCLUDE                              
C                   ENDIF                                                        
C                   ENDIF       

Written by Ben

2010/01/30 at 1:10 am