How do I chain to a file with a var char key field from a non varchar file

Need to chain to a sql file with a varchar key. The data used comes from a normal char filed.
Who is Participating?
Gary PattersonConnect With a Mentor VP Technology / Senior Consultant Commented:
My code above works fine on V5R3.  What OS version/release are you running?

Sounds like loanr00001 may not be the first key field in the commi4_l1 table/index/view/logical?

Please post the full compile listing of the failed compile above.  If you use Navigator, you can export the listing as a text file.  (open iSeries Navigator, select your system, Basic Operations, Printer Output, right-click on the listing and select Export).

Also, are you compiling with CVTOPT(*VARCHAR)?  This could possibly cause problems.

- Gary Patterson
2H1OAuthor Commented:
Thanks same here. Is my explanation understandable?
Gary PattersonVP Technology / Senior Consultant Commented:
Can't say I've tried it.  

Are you getting an error?  If so, show your code and the full error (f1 the error for extended help).

Basic process should be:

  • declare a variable with the same data type and length as the key field
  • move the fixed-length character data in using %trim:
  • chain using the variable length field
d varlenkey          s                              like(dbfield)
varlenkey = %trim(fixedlenfield);
chain (varlenkey) file;
- Gary Patterson

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

2H1OAuthor Commented:
I tried a eval with a %trim into the var char field but it keeps trailing blanks and cannot find the record. I also tried move and movel. Then I tried the following:
  ** loanr0001 is the field in the file                                    
  ** This has two components                                            
  **  VFB - A binary prefix that tells OS400 how many bytes to store    
  **  dea - The actual string                                            
 d loanr00001ds    ds                                                  
 d vfb                            2b 0                                  
 d dea                           15          
 move the field into the variable length field        
                  movel(p)  dea311        dea          
 Calculate the last bytes                              
    ' '           checkr    dea           vfb          
                  eval      loanr00001 = loanr00001ds  
and the chain with LOANR00001. It then gives me the error that the field is to short. Please help don't know what to do anymore.                          
Gary PattersonVP Technology / Senior Consultant Commented:
Please post the DDL for the file (or a DSPFFD) and a screen print of the error message, including the second level error message text (F1 on the error message):

Also, please post the code with the trim that left the trailing spaces but didn't throw an error message.

- Gary
Gary PattersonVP Technology / Senior Consultant Commented:
This worked fine for me.



fvarkey    if   e           k disk    rename(varkey:varkeyl) 
d fixed           s             15a   inz('PATTERSON')       
d var             s                   like(varykey1)         
   var = %trim(fixed);                                       
   chain var varkey;                                         
   *inlr = *on;                                              

Open in new window

2H1OAuthor Commented:
DEA311  15char
loanr00001 15 var char

loanr           S                   like(loanr00001)

  LOANR = %TRIM(DEA311);  
  chain loanr commi4_l1;  
Program won't compile complains that Factor 1 is not the same as the first key field  
Gary PattersonVP Technology / Senior Consultant Commented:
Also, suggest you create my example and see if it works for you.  (You'll need to populate one record in teh table, too).

That would eliminate version issues and compile option issues.

- Gary
2H1OAuthor Commented:
Thanks still had the convert in the program. Sorry about that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.