BIF Question
Last Post 29 Jan 2013 07:28 AM by emhill57. 6 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
emhill57
New Member
New Member
Posts:41

--
28 Jan 2013 02:31 PM

I know I am just missing something here but this is my setup:

WBLINE is defined 5A

LINE_KEY is defined 5A

WBLINE = '00001'

LINE_KEY = *BLANKS

I want to add 1 to WBLINE and then store that in LINE_KEY.  I've tried the following but keep getting LINE_KEY = '00000' in each instance:


LINE_KEY = %EDITC(%DEC(WBLINE:5:0) + 1:'X');

LINE_KEY = %EDITC(((%DEC(WBLINE:5:0)) + 1):'X');


I know I am just missing something simple.  Any help is greatly appreciated!!!!!


I ended up doing this and it works great but thought I could make it with one statement (WRK_LINE is 5.0):

wrk_line = %dec(wbline:5:0) + 1;
line_key = %editc(wrk_line:'X');

Brian Rusch
Advanced Member
Advanced Member
Posts:556

--
28 Jan 2013 02:54 PM
The intermediate result of your %DEC(WBLINE:5:0) + 1 expression is greater than 5 decimals (not sure exactly how many). So to cut it down to 5, you would need to code it like this (there may be a better way):

LINE_KEY = %EDITC(%DEC(%DEC(WBLINE:5:0) + 1:5:0):'X');
Rex Reese
New Member
New Member
Posts:44

--
28 Jan 2013 03:04 PM
What Brian said is correct. However if I were doing it I would write it like this.

LINE_KEY = %TRIM(%EDITC(%DEC(WBLINE:5:0) + 1 : 'X'));

emhill57
New Member
New Member
Posts:41

--
28 Jan 2013 03:18 PM

What Brian included worked great but Rex yours still gave me '00000'.

Brian....why would the statement below yield 00002 (numeric) in wrk_line if the decimal numbers are not correct?:

wrk_line = %dec(wbline:5:0) + 1;

Just wondering.....

Barbara Morris
Senior Member
Senior Member
Posts:5201

--
28 Jan 2013 03:54 PM
Rex's code would work if it used EVALR instead of EVAL.

The result of adding 1 to a 5-digit number has 6 digits (in case the 5 digit field had 99,999, the result has to allow for 100,000). %EDITC of the 6 digit value gives '000002', and then using EVAL to assign that to a 5-character field chops off the final character, leaving '00000'. Using EVALR would chop off the first character, giving '00002'.

When I'm trying to see what's going wrong with this type of code, I create a temporary field way bigger than I need, and add an assignment like this:

temp = '{' + %EDITC(%DEC(WBLINE:5:0) + 1 : 'X')  + '}';

Then in debug, I can see that the value of temp is {000002}, which means that the %EDITC result is 6 long, not the 5 long that I might have guessed.

Just by the way, I would use a data structure for this. RPG data structures are also character fields, so you can define WBLINE as a DS with a 5-digit zoned subfield. If you make WBLINE qualified, your code should be fairly easy to understand. (Well, at least, easier than the nested builtin functions, IMO)

D WBLINE          DS                  qualified
D   num                          5S 0 inz
 /free
     WBLINE.num += 1;
Rex Reese
New Member
New Member
Posts:44

--
29 Jan 2013 06:30 AM
Sorry for the confusion. Your correct Barbara (as always). I had not considered the edit code of 'X'. I do this quite often when building XML data but normally use an edit code of 'Z' because I don't want to store/display the leading zeros. Thanks for the clarification.

rex
emhill57
New Member
New Member
Posts:41

--
29 Jan 2013 07:28 AM
Thanks all. Makes more sense now.
You are not authorized to post a reply.

Acceptable Use Policy