Parse Keyword/Value Sets

 

Another conversion to GnuCOBOL of a function I originally wrote in BASIC and have used for many years.

I have long used the practice of creating files where each record (line) is a keyword and its associated value separated by a colon.  I imagine my earliest use of this was when I was unloading data from files for exporting to a different application or storage system.  But I also frequently use this method for storing run time parameters so that they may be easily edited or examined outside of the program(s) that use them.  If the colon poses a problem for a particular set of data fields, it would be fairly simple to substitute a different character, but since it is only significant in its first occurrence, there is no problem with a colon appearing in the data values.  Several of my applications also required multiple iterations of some of the key pairs, so the keyword may also contain an index value appended to the end of the keyword with a numeric value enclosed in parentheses.  The numeric value of the index argument is returned in its own discrete numeric field.

To install the source programs (along with a sample test data file), and compile them, execute the bash script:  downloads/ParseKWsetup  [md5: c5e240b4a690cfb6e20e08d70ea61b76].  Right click and save the script in the location where you want the source program to reside, then execute it.  It will create two files containing the source programs and one file of test data, then execute the GnuCOBOL compiler to compile them into the run unit for the test program.  The GnuCOBOL compiler must be installed prior to executing the bash script.  

Output from the test/verification program:

jay@Phoenix $ ./testParse
Input Record #01 ->Title: 1001 Questions Answered About Trees                                                                                   
Keyword..Title                    
Index....+0000
Value....1001 Questions Answered About Trees                         
----------------------------------------------------------------------
Input Record #02 ->SubTitle:                                                                                                                    
Keyword..SubTitle                 
Index....+0000
Value....                                                            
----------------------------------------------------------------------
Input Record #03 ->Author(1): Platt, Rutherford                                                                                                 
Keyword..Author                   
Index....+0001
Value....Platt, Rutherford                                           
----------------------------------------------------------------------
Input Record #04 ->Publisher: Dodd, Mead & Company                                                                                              
Keyword..Publisher                
Index....+0000
Value....Dodd, Mead & Company                                        
----------------------------------------------------------------------
Input Record #05 ->Year.Published: 1959                                                                                                         
Keyword..Year.Published           
Index....+0000
Value....1959                                                        
----------------------------------------------------------------------
Input Record #06 ->Title: Adult Art Psychotherapy                                                                                               
Keyword..Title                    
Index....+0000
Value....Adult Art Psychotherapy                                     
----------------------------------------------------------------------
Input Record #07 ->SubTitle: Issues and Applications                                                                                            
Keyword..SubTitle                 
Index....+0000
Value....Issues and Applications                                     
----------------------------------------------------------------------
Input Record #08 ->Author(1): Landgarten, Helen B.                                                                                              
Keyword..Author                   
Index....+0001
Value....Landgarten, Helen B.                                        
----------------------------------------------------------------------
Input Record #09 ->Author(2): Lubbers, Darcy                                                                                                    
Keyword..Author                   
Index....+0002
Value....Lubbers, Darcy                                              
----------------------------------------------------------------------
Input Record #10 ->Publisher: Brunner/Mazel                                                                                                     
Keyword..Publisher                
Index....+0000
Value....Brunner/Mazel                                               
----------------------------------------------------------------------
Input Record #11 ->Title: Art Therapy, Race and Culture                                                                                         
Keyword..Title                    
Index....+0000
Value....Art Therapy, Race and Culture                               
----------------------------------------------------------------------
Input Record #12 ->SubTitle:                                                                                                                    
Keyword..SubTitle                 
Index....+0000
Value....                                                            
----------------------------------------------------------------------
Input Record #13 ->Author(1): Campbell, Jean                                                                                                    
Keyword..Author                   
Index....+0001
Value....Campbell, Jean                                              
----------------------------------------------------------------------
Input Record #14 ->Author(2): Liebmann, Marian                                                                                                  
Keyword..Author                   
Index....+0002
Value....Liebmann, Marian                                            
----------------------------------------------------------------------
Input Record #15 ->Author(3): Brooks, Frederica                                                                                                 
Keyword..Author                   
Index....+0003
Value....Brooks, Frederica                                           
----------------------------------------------------------------------
Input Record #16 ->Author(4): Jones, Jenny                                                                                                      
Keyword..Author                   
Index....+0004
Value....Jones, Jenny                                                
----------------------------------------------------------------------
Input Record #17 ->Author(5): Ward, Cathy                                                                                                       
Keyword..Author                   
Index....+0005
Value....Ward, Cathy                                                 
----------------------------------------------------------------------
Input Record #18 ->Publisher: Jessica Kingsley                                                                                                  
Keyword..Publisher                
Index....+0000
Value....Jessica Kingsley                                            
----------------------------------------------------------------------
Input Record #19 ->Year.Published: 1999                                                                                                         
Keyword..Year.Published           
Index....+0000
Value....1999                                                        
----------------------------------------------------------------------
Input Record #20 ->ISBN: 185302578X                                                                                                             
Keyword..ISBN                     
Index....+0000
Value....185302578X                                                  
----------------------------------------------------------------------
Input Record #21 ->Accession Year: 2015                                                                                                         
Keyword..Accession Year           
Index....+0000
Value....2015                                                        
----------------------------------------------------------------------
Input Record #22 ->Next Accession Number: 0000                                                                                                  
Keyword..Next Accession Number    
Index....+0000
Value....0000                                                        
----------------------------------------------------------------------
Input Record #23 ->Next Title RRN: +00002293                                                                                                    
Keyword..Next Title RRN           
Index....+0000
Value....+00002293                                                   
----------------------------------------------------------------------
Input Record #24 ->Print Requests Pending: 0000                                                                                                 
Keyword..Print Requests Pending   
Index....+0000
Value....0000                                                        
----------------------------------------------------------------------
Input Record #25 ->Really Big Index(1024): Value is 32                                                                                          
Keyword..Really Big Index         
Index....+1024
Value....Value is 32                                                 
----------------------------------------------------------------------
Input Record #26 ->This will be reported as an error                                                                                            
RETURN-CODE=+000000008
----------------------------------------------------------------------
Input Record #27 ->Course Name: INTERIOR DESIGN: COLOR AND LIGHT                                                                                
Keyword..Course Name              
Index....+0000
Value....INTERIOR DESIGN: COLOR AND LIGHT                            
----------------------------------------------------------------------
Input Record #28 ->Course Name: HISTORY OF ARCHITECTURE AND INTERIOR DESIGN                                                                     
Keyword..Course Name              
Index....+0000
Value....HISTORY OF ARCHITECTURE AND INTERIOR DESIGN                 
----------------------------------------------------------------------

If you want to be able to dynamically call the subprogram move the object module (parseKWsets.so) to a location included in your COB_LIBRARY_PATH.

* Updated September 20, 2019 *  I was tired of looking for and copying the Working-Storage fields for this, and a few other, routines, so I updated the installation script to provide a copybook that may be used in the calling program for this routine.  For easiest use, you should copy the copybook file into the directory that GnuCOBOL searches during compile time for copy books (on my Linux system that is /usr/local/share/gnucobol/copy).  At the same time I modified the original code to utilize a variable length field for the input field, where the length is determined at execution time.


This page was last updated on September 20, 2019.