Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KEY FIELDS AND CHAIN QUESTION 1

Status
Not open for further replies.

rstitzel

MIS
Apr 24, 2002
286
US
I have a file named:
WMBLCK

There are 2 key fields:
WBCUST (Type = S, Length = 5, Decimals = 0)
WBBLCK (Type = S, Length = 1, Decimals = 0)

In my program I take two variables and combine them into a variable named CUSTNUMBLCK. CUSTNUMBLCK is 6 digits with 0 decimals)

I want to chain to WMBLCK using CUSTNUMBLCK, but when I compile it tells me that the CUSTNUMBLCK's length is not the same as the first key field in WMBLCK.

How do I code my program to look at both key fields when chaining? I was looking at klist but not sure if that's what I should use and if so how to use it :)

Thanks in advance for any and all help.


 
Are you specifying a Key List made up of your two fields??

 
Yes, use a klist with the 2 variables as your kflds.
 
Thanks both of you. But I have more questions :)

I'm pretty new to RPG programming and I'm not sure how to code the klist

D CUSTNUMBLCK S 6 0

C CUSTNUMBLCK KLIST
KFLD CUSTNUM
KFLD BLOCK

C CUSTNUMBLCK CHAIN WMBLCK

But I'm still getting the same error. How should I code it properly?

Thank you.
 
Do not define CustNumBlck on the "D" spec.
Code should look like this:
Code:
C    CustNumBlck KLIST
C                KFld           CustNum
C                KFld           Block
C
C    CustNumBlck Chain  WmBlck

Not, the D spec defining CustNumBlck is gone.

RedMage1967
IBM Certifed - RPG IV Progammer
 
In V5R2 it would be:

Code:
/free
  chain (CustNum:Block) WmBlck
/end-free

Correct?

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
[URL unfurl="true"]http://www.koldark.net[/URL]
See my progress to converting to linux. [URL unfurl="true"]http://linux.koldark.net[/URL]
 
Codepoet: I'm running 5.1. Is your code supported under this release?
 
V5R2 has a new BIF called %KDS (Keyed data structure). This DOES NOT work under V5R1.
Basically, you define the KLIST on the D specs, not the C specs. It looks real nice to me, but, since I'm on V5R1, I can't used it.

iSeriesCodePoet, you might want to check this out, since you're at V5R2. The free form code for a chain is:
Code:
/Free

 Chain CustNumBlk WmBlk;

/End-Free

rstitzel, I'm running V5R1, free form is supported starting with this release.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Redmadge1967, Yes I'm aware that I can code in free format under 5.1. I've coded a couple of programs using free but they were very simple programs. I'm trying to work on a bit more complex program but have come across several stumbling blocks using free, such as klist, move etc.

I was asking before was if I could use Iseriescodepoet's free form example: chain (CustNum:Block) WmBlck

But I tried it and it doesn't work. So I'm stuck either putting in fixed format in with my free format, which I hate to do. Or upgrade to 5.2 which I don't plan on doing until next year.

My latest problem is trying to evaluate part of a variable. I have a variable named custnum. It's a 5 digit numeric field and I want to take the first three characters of the custnum and assign it to another variable named WRK30 which is a 3 digit numeric field.


I tried
/free
wrk30 = custnum;
/end-free

It compiles but when I run the program it crashes with the error "The target for a numeric operation is too small to hold the result".

Do you know a way in free format to take the three left most characters of a field. Something like wrk30 = LEFT(CUSTNUM,3)?


Thanks in advance for any and all help.
 
Redmadge1967....nevermind I think I found it. In august you replied to a post I made regarding the move operation in free format and in it you describe how to get part of a field by using trim. I'm going to "play" with your suggestions. Thanks again!!

 
It might have been %TRIM used in conjunction with %SUBST, don't remember that far back. What are you trying to do?

RedMage1967
IBM Certifed - RPG IV Progammer
 
I'm writing an interactive program. On the first screen the user types in a customer number and block number. If the block number = 2 this means it's an Albertson's customer. All of our Albertson's customer's begin with 005, 006 or 009. So I want to evaluate the first three characters of the customer number to verify that they keyed in a valid Albertson's customer. If not I redisplay the screen with an error message.

In fixed format I would just create a three digit numeric variable named wrk30 and I would use MOVEL CUSTNUM WRK30. Since the wrk30 is only three digits I would get the first three characters of the custnum. In fixed I use move and movel a lot and need to come up with an alternative in free.

I guess I could loop through the entire customer master looking at only block 2 accounts and comparing the customer number in the customer master to the entire customer number the user keyed in. If no hits then it's an error.

FYI
 
rstitzel

Try this (assume there are D specs with the fields defined to the correct length:
Code:
 /Free
  If BlkNbr = 2;  // if an Albertson's customer
    // convert the custome nbr to a char, with leading 
    // zeros
    CharCustNbr = %EditC(CustNum:'X');  
    If %Subst(CharCustNbr:1:3) = '005' 
        or %Subst(CharCustNbr:1:3) = '006'
        or %Subst(CharCustNbr:1:3) = '009';

      // valid Albertson's customer code here

    Else;
 
     // send error message here

    EndIf;

Alternately, you check check the first three digits to see if the don't equal (<>) 005, 006, 009.
Let me know what you think.


RedMage1967
IBM Certifed - RPG IV Progammer
 
I'll give that a shot.....thanks AGAIN for all your help L-)
 
What I do for free format is to put things in this order.

H specs
F specs
D specs
C specs for SQL definitions, *entry parm lists, and key lists
/free
/end-free
C specs for any SQL sub routines

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
iSeriesCodePoet

The less fixed &quot;C&quot; specs I code, the better I like it. With the %KDS bif, it removes the need to code &quot;C&quot; specs for your KLISTS. Check it out when you've got the time. I wish I could use it, but, since I'm at v5r1, I can't.

RedMage1967
IBM Certifed - RPG IV Progammer
 
I know I am trying to cut it down as well, but at least all free format code is together now. I am working on re-writting a program. I might just try that if I need it. I have been liking to put SQL in instead of reads lately. Just seems so much faster to program.

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
Don't know sql at all, Read and Reade gets the job done for me.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top