2H1O
asked on
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.
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:
...
varlenkey = %trim(fixedlenfield);
chain (varlenkey) file;
- Gary Patterson
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
...
varlenkey = %trim(fixedlenfield);
chain (varlenkey) file;
- Gary Patterson
ASKER
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.
** 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.
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
Also, please post the code with the trim that left the trailing spaces but didn't throw an error message.
- Gary
This worked fine for me.
DDL:
CREATE TABLE
VARKEY (VARYKEY1 VARCHAR (50 ) NOT NULL WITH DEFAULT PRIMARY KEY,
DATA CHAR (50 ) NOT NULL WITH DEFAULT)
RPG:
fvarkey if e k disk rename(varkey:varkeyl)
d fixed s 15a inz('PATTERSON')
d var s like(varykey1)
/free
var = %trim(fixed);
chain var varkey;
dump(a);
*inlr = *on;
/end-free
ASKER
DEA311 15char
loanr00001 15 var char
loanr S like(loanr00001)
/FREE
LOANR = %TRIM(DEA311);
chain loanr commi4_l1;
/END-FREE
Program won't compile complains that Factor 1 is not the same as the first key field
loanr00001 15 var char
loanr S like(loanr00001)
/FREE
LOANR = %TRIM(DEA311);
chain loanr commi4_l1;
/END-FREE
Program won't compile complains that Factor 1 is not the same as the first key field
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
That would eliminate version issues and compile option issues.
- Gary
ASKER
Thanks still had the convert in the program. Sorry about that.
ASKER