Counting using RPGLE

Tags:
AS/400
RPGLE
I tried to do flames program in RPGLE. I counted and removed the common words. For example:
STRING1 - RAJESH

STRING2 - KUMAR - I GET 7 AS OUTPUT
Flames count is 6 but I have 7. How do I count the word F as 7 and set the next pointer L as starting pointer.


Software/Hardware used:
RPGLE
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 12  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.
  • pdraebel
    How do you count the number of letters ? Checking for first blank ? If so you need to substract 1 from the result.
    You may want to look at BIFs %LEN or %SIZE to get good result.
    7,545 pointsBadges:
    report
  • ToddN2000
    In addition set up a start and end variable and use the %SCAN BIF.
    Should not be too hard.
    126,110 pointsBadges:
    report
  • rajeshkmr571
    Dude I already done that program. This is my copy of the program.

    0003.02 DPOS              S              2S 0                                 
    0003.03 DCHAR             S              1A                                   
    0003.04 DI                S              2S 0                                 
    0003.05 DMSG              S             30A                                   
    0003.06 C                   EVAL      MSG = 'ENTER THE FIRST NAME'            
    0004.00 C     MSG           DSPLY                   STR1                      
    0005.00 C                   EVAL      MSG = 'ENTER THE SECOND NAME'           
    0006.00 C     MSG           DSPLY                   STR2                      
    0006.01 .*                                                                    
    0006.02 .****************************************************************     
    0006.03 .*/ TO GET THE LENGTH OF BOTH STRING                            *  
    0006.04 .****************************************************************  
    0011.00 C                   EVAL      LEN1 = %LEN(%TRIM(STR1))             
    0011.01 C                   EVAL      LEN  = %LEN(%TRIM(STR2))             
    0011.02 .**                                                                
    0011.03 .****************************************************************  
    0011.04 .*/ GET A LETTER FROM STRING 1 AND SCAN WITH STRING2               
    0011.05 .****************************************************************  
    0012.00 C                   FOR       I = 1 TO LEN                         
    0012.01 C                   EVAL      CHAR = %SUBST(STR1:I)                   
    0012.05 C                   EVAL      POS= %SCAN(CHAR:STR2)                   
    0012.06 C                   IF        POS <> 0                                
    0012.07 C                   EVAL      STR2 = %REPLACE(' ':STR2:POS:1)         
    0012.12 C                   ENDIF                                             
    0012.14 C                   ENDFOR                                            
    0012.15 .**                                                                   
    0012.16 C                   EVAL      LEN = LEN - %LEN(%TRIM(STR2))           
    0012.17 C                   EVAL      LEN1 = (LEN1 - LEN) + %LEN(%TRIM(STR2)) 
    0012.18 C                   EVAL      MSG='COMMON LETTERS IN UR STRING:'        
    0012.19 C     MSG           DSPLY                   LEN                         
    0012.20 C                   EVAL      MSG='UNCOMMON LETTERS IN UR STRiING:'     
    0012.21 C     MSG           DSPLY                   LEN1                        
    0013.00 C                   EVAL      *INLR = *ON                               
            ****************** End of data **************************************** 



    First Input - Rajesh
    Second Input - Kumar
    Total word - 7
    (This was my first half of the program)
    The main part I need to do is count FLAMES(6 letters) with my output(7)

    for ex:
    Flames - Lames (1st loop)
    Lames - Lmes(2nd loop)
    Lmes - Lms(3rd loop)
    Lms - MS(4th loop)
    Ms - S (s -stands for sister) like that.
    I know how to replace and substring. All i want to know is, how to count the word FLAME and set the pointer.

    220 pointsBadges:
    report
  • rajeshkmr571
    and i don't need that hard coded values like 
    2,4,7,9 -  for Letter E
    3,5,14 - for Letter F
    6,11,15 for Letter M
    10 for L
    8 For Letter A
    I juz want the logic for counting the same char/letter again and again. 

    220 pointsBadges:
    report
  • pdraebel
    When you replace the "Common" letters in STR2 with blanks the %LEN BIF on the Trimmed string (remove trailing blanks) cannot be determined. It depends on the End characters being Common or not.
    Check if the Char is in the string. If not (POS=0) put in Uncommon String, else Put in Common String. At end the %LEN of the strings (trimmed) should give you the correct output.
    7,545 pointsBadges:
    report
  • TheRealRaven
    There can be no answer until we know what the question is.

       for ex:
       Flames - Lames (1st loop)

    Why? Where did the "F" go? Why was it removed?

    What happens with duplicate letters? What if one of the strings is "AAAABBB"? Are all A's "common"? Or is only one common?

    What are the data definitions of STR1 and STR2? Are they fixed- or variable-length? That might make some of the logic more clear. And as pdraebel asks, why are you replacing with blanks? That really messes up the %LEN() values.

    If we don't know the precise definitions of common/uncommon, we can't help much.
    32,480 pointsBadges:
    report
  • philpl1jb
    if this isn't homework ...
    54,090 pointsBadges:
    report
  • ToddN2000
    I feel the same as philpl1jb, if this is real world issue, can you explain the business logic / practical use of this problem?
    126,110 pointsBadges:
    report
  • rajeshkmr571
    I think all of you would know the FLAMES game played by school students and teenagers. 
    Using this game, they predict the relationship between two persons.
    F-Friends
    L-Love
    A-Affection
    M-Marriage
    E-Enemies
    S-Siblings

    Fist, you should take the two names:

    ABCD
    DEFA

    The common letters(AD) are stroked off(Shown in bold here).
    Then the remaining letters(BCEF) are counted. Here it is 4.
    MY PROGRAM HAVE THIS FIRST HALF.THAT IS THE OUTPUT VALUE AS 4.

    I DIDN'T WRITE A SINGLE LINE OF CODE FOR THE SECOND HALF. THE BELOW IS THE LOGIC FOR SECOND HALF. I DON'T KNOW HOW TO WRITE IN RPGLE. I NEED HELP WITH THAT.



    Now, the calculation is done as follows
    REMEMBER OUTPUT IS: 4
    FLAMES - 4TH LETTER REMOVED
    FLA ES - COUNT START WITH E 
    F A ES - 4TH LETTER REMOVED(L) 
    A ES   - COUNT START WITH A AND 4TH LETTER REMOVED(F)
    ES  - COUNT START WITH A AND 4TH LETTER REMOVED (A)
    E - COUNT START WITH E AND REMOVED THE FOURTH LETTER(S)
    THE REMAINING IS E 
    E MEANS ENEMY THAT IS THE ANSWER

    220 pointsBadges:
    report
  • rajeshkmr571
    FLAMES
    FLA ES
    F A ES
    A ES
    ES
    E
    IF YOU NEED MORE ABOUT THE LOGIC. pLEASE REFER THIS SITE http://www.crazyengineers.com/threads/flames-code.22952/
    THIS IS A SIMPLE GAME
    220 pointsBadges:
    report
  • TheRealRaven
    Okay, so it's modulo arithmetic with the modulo being reduced by 1 each iteration. You could do it with a recursive proc that would go five (six?) levels deep  before returning the resulting indexed letter. Again, it looks like variable-length strings should be used all the way through.

    Some special cases might need to be handled. It's technically possible that two names could have all letters in common, e.g., Tokyo and Kyoto. (I'd have to think to come up with names of people that would cancel out other than names that might be completely the same.)
    32,480 pointsBadges:
    report
  • rajeshkmr571
    could some one please complete the FLAMES program for me. I am a beginner in rpgle. I don't know how to complete the second half. If any one knows please complete the full program for me.
    220 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: