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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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.                          
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.