Problem solve Get help with specific problems with your technologies, process and projects.

Six quick tips for working with DDS

Here are a few DDS tips when working with logical files, including resizing a field and renaming a function.


Dwight Beech

Data description specifications (DDS) provide a powerful and convenient way to describe data attributes in file descriptions external to the application program that processes the data. People are always uncovering ways, however, for DDS do more than you thought was possible.

Drawing from his own expertise, site expert Dwight Beech offers a few DDS tips when working with logical files. They include resizing a field, renaming a function, and creating a key field for a joined logical using the SST function.

1. Resizing a field:
Have you ever been in the position where you wanted to rename a field or change the size of it for programming purposes? For example suppose you wanted to read a file that had packed fields sized 17,2 into a program that had a field size of 8,0. You can do this easily enough in your DDS file definition by building a logical file with the field a different size. The field will automatically be truncated and resized into the 8,0 field unless the field is too large fit. Then that will result in an error.

Physical File: TEST1

   A          R GLRXX                                              
  *                                                              
 A            TSTN01        17P 2       TEXT('PERIOD  1 AMOUNT') 
 A            TSTN02        17P 2       TEXT('PERIOD  2 AMOUNT') 
 A            TSTN03        17P 2       TEXT('PERIOD  3 AMOUNT') 
 A            TSTN04        17P 2       TEXT('PERIOD  4 AMOUNT')

Logical File: TEST2

   A          R GLRXX                     PFILE(TEST1)   
  *                                                    
 A            TSTN01         8P 0       
 A            TSTN02         8P 0       
 A            TSTN03         8P 0       
 A            TSTN04         8P 0      

2. RENAME function:
If you want to rename the field for RPG or CLP programming purposes, just create the field in DDS with the new name and use the RENAME function on the old field. The field can then be resized at the same time. Using the same physical file TEST1.

Logical File: TEST3

 A            R GLRBX                   PFILE(TEST1)   
   *                                                    
A            TSTN05         8P 0       RENAME(TSTN01) 
A            TSTN06         8P 0       RENAME(TSTN02) 
A            TSTN07         8P 0       RENAME(TSTN03) 
A            TSTN08         8P 0       RENAME(TSTN04)

3. Creating a key field for a joined logical using the SST function:
Another neat trick if you are building joined logical files is to use partial keys or a sub-stringed field for the join. Example: Say the secondary file has a field (CSTCTR) and you want to join it to your primary file but the key field to make the join execute doesn't exist in the primary file. The key portion is embedded within a field in the primary file (CTRACC). Use the SST function on the field containing the key data and extract what will be needed for the join (XXCC). The XXCC field is then used in the join to the secondary file CTRXRFP. The "I" field in the definition represents that it is used for input only.

 R GLRXX                       JFILE(GLPCOM CTRXRFP)     
J                         JOIN(1 2)                 
                               JFLD(XXCC CSTCTR)         
     WDCO                        RENAME(BXCO)              
     WDCOCT             I        SST(CTRACC 1 10)          
     WDEXP              I        SST(CTREXP 12 11)         
     WDACCT                      RENAME(CTRACC)            
     XXCC               I        SST(CTRACC 5 6)   

4. Concatenating fields using the CONCAT function:
Another trick for building a field that doesn't exist in your logical file is to use the CONCAT function. Example: You want to create a field FSTLST (first and last name) from 2 fields FIRST and LAST. This can be done as follows:

     FIRST    R                                            
      LAST     R                                            
   FSTLST                   CONCAT(FIRST LAST) 

5. Using the RANGE function:
In your logical file you may want to select a range of records rather than using the select function to select individual records. Example: You want only the records in your logical file where the selected field is in the range 100 and 900. This can be done as follows:

  S XXPG#                        RANGE('100' '900')   

You can also use the RANGE function on multiple ranges.

6. Using the VALUES function:
In your logical file you may want to select specific records that have certain values by using the VALUES function. Example: You want only the records in your logical file where the selected field has the values 'O', 'P', and 'E'. This can be done as follows:

  S RPTCTR                       VALUES('O     ' 'P     ' 'E     ')

-----------------------------------
About the author: Dwight is superintendent, application support, at Cameco Corp. in Saskatoon, Saskatchewan, Canada, where he manages the operation of the application support group supporting 35 business applications.

==================================
MORE INFORMATION
==================================

  • Add lots of info to your sign-on screen
    Although placing message fields on a sign-on display will allow you to modify the content displayed at sign on, needing a different message field for each line makes it irritating to work with. Fortunately, you can get the same display capability by using just a single message field.
  • Simple way to retrieve mixed-case data
    Follow this tip from site expert John Kohan to learn how to retrieve the key field and ignore the case it's currently in.
  • Physical file changes made easy
    When changing the DDS for a physical file with many logicals, Search400.com member Faithie Lewis says there's one simple way to implement the changes without going through the hassle of removing logicals, copying the file, recompiling the file empty, and mapping the data back in. Use CHGPF.


Dig Deeper on iSeries ILE programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close