How does equal to operator work in RPGLE free format when v compare file field with constant value.

140 pts.
Tags:
AS/400
RPGLE
I have a file field which has values 'X' or 'Y' and it is of 10 length.
Chain f1:f2:f3 filename

if %found filename

if f4 = 'X'
In free format RPGLE when I tried to compare it fails even though value of f4 is ' X' . Note: f4 is of 10length. Work around is trimming F4 before equating but I would like to know the reason for this issue. because it works in STRSQL and in other programs too


Software/Hardware used:
AS400
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
Physical File : XARRPF1

0001.00      A          R USER                  
0002.00      A            FNAME         10A     
0003.00      A            MNAME         10A     
0004.00      A            LNAME         10A     
0005.00      A          K FNAME       

RECORDS  of Physical FIle (XARRPF1) :

 
            FNAME       MNAME       LNAME   
 000001 ROCK        ABCD        RIGHT   
 000002 X                 Y                   Z       
 ****** ********  End of report  *******

RPGLE Program : XARRPGM2

HOPTION(*NODEBUGIO)                         
F* F I L E    D E F I N I T I O N           
FXARRPF1   IF   E           K DISK          
                                            
DVAR1             S             10A         
                                            
 /FREE                                      
                                            
   VAR1 = ‘X’;                              
   CHAIN(E) VAR1 XARRPF1;                   
   IF %FOUND(XARRPF1);                      
     IF VAR1 = ‘X’;                         
        DSPLY ‘ITS WORKING’;                
     ENDIF;                                 
   ENDIF;                                   
                                            
  *INLR = *ON;                              
 /END-FREE                                            

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • CharlieBrowne
    Is the value in f4 right or left justified? If it is right justified, it will not be equal to 'X' because 'X' is left justified.
    62,385 pointsBadges:
    report
  • CharlieBrowne
    It the value is always in the same position, they it is best to just substr to do the compare or set up a constant 10 long with the X in the correct position.
    62,385 pointsBadges:
    report
  • azohawk

    As CharlieBrowne indicated, the fact that the field sizes do not match is going to be an issue.

    A couple of things I would try:

    If %Trim(f4) = 'X'

    or try to substring the f4 parm.


    4,055 pointsBadges:
    report
  • ToddN2000
    As mentioned by the other posters it's most likely a justification issue.
    Check the field with a DFU or WRKQRY. See what the actual location of the X is in the 10 char field. The most effective way to handle this would be to use the trim function that azohawk mentions.. If it's always a constant position then charliebrowns substring is a good method. You could also break the field up into an array or data structure and check that..
    133,645 pointsBadges:
    report
  • GregManzo
    Is the F4 a variable length field? Because if it is then trailing blanks can become significant in the compare. Otherwise what's mentioned above looks good.
    2,960 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: