‎2022 Aug 31 8:33 PM
Hi i create a program that count the number of vowels in a input of a user...
When i run it dump when i put a word that has a lenght more than 6 characters.
My Parameterv"p_char" as a lenght of 20 and it is the max of the length...
Here is the code...
Thanks in advance..
**** Déclaration des variables ****
DATA: vlength_p TYPE i, " Variable pour stocker la longueur d'input
v_vowels(6) TYPE c, " Liste des voyelles
index TYPE i,
occurences TYPE i, " Variable de décompte
v_vbyv TYPE c. " Variable de chaque voyelle
**** Création Paramètres pour input User ****
PARAMETERS : p_char(20) TYPE c.
vlength_p = strlen( p_char ). " On obtien la longueur de l'input user
v_vowels = 'AEIOUY'. " Assignation des voyelles dans la variable
index = sy-index. " Variable système utilisée pour la boucle
WHILE index < vlength_p. " Effectue bloucle tant que cette condition est vraie
v_vbyv = v_vowels+index. " On change
*** On compte les occurences en fonction de la voyelle sur laquelle on est
FIND ALL OCCURRENCES OF v_vbyv IN p_char MATCH COUNT occurences.
ADD 1 TO index.
IF occurences = 0.
ELSE. " Ce qu'on fait si on trouve des occurences
WRITE : / v_vbyv, TEXT-000, occurences, TEXT-001. " On affiche le resultat si occurences
ENDIF.
ENDWHILE.
‎2022 Aug 31 9:32 PM
Hi,
I checked your coding.
The reason why a dumps comes up when the length of your variable is longer that 6 characters is because you set the variable V_VOWELS to 'AEIOUY' (length of 6 characters).
In the while-loop you iterate based on the length of the char you entered as parameter. If this is longer than 6 chars you get an issue with this command:
v_vbyv = v_vowels+index. " On change
As mentioned, the variable V_VOWELS has a length of 6. So in case index gets the value of 7, it is not possible anymore to access this 7th char in this variable using this offset. That's why it is dumping with DATA_OFFSET_TOO_LARGE.
To be honest, I did not really understand what your are trying to achieve with this coding, that's why I cannot propose another possible solution. But I hope this helps you to understand the reason of the dump.
Kind regards
Jens
‎2022 Aug 31 10:39 PM
Thanks you, Yes it help
My program is to count the numbers of vowels of a word enter in a parameter...
I guess this isn't the right code to do...
Hum..
If you have a solution can you just don't give it , just give me Hich to help find the solution by my self.
if i use an internal table to store the vowels instead in a variable, would it be a way ?
Thanks
‎2022 Aug 31 10:48 PM
Okay, now I got your requirement for this coding.
One possible solution could be:
I hope this helps you to solve the issue by your own 🙂
Kind regards
Jens
‎2022 Sep 02 12:03 PM
So i ll processing the check the 6 vowels... with a If statement instead of FIND
‎2022 Sep 01 12:41 AM
Hi fotso
Have a look at this Regex and you will be able to achieve your requirement in just one statement. No looping, no counters, no indexing, no internal tables needed.
Thanks
‎2022 Sep 01 7:50 PM
‎2022 Sep 02 1:02 AM
‎2022 Sep 02 11:59 AM
‎2022 Sep 02 12:35 PM
This worked well for me:
parameters: p_string type text40 obligatory.
find all occurrences of regex '[AEIOU]' in to_upper( p_string ) match count data(occur).
message |Number of vowels:{ occur }| type 'S'.
‎2022 Sep 01 7:25 AM
Please attach the text file of the short dump when you have a question about a short dump, and indicate an example of "a word that has a lenght more than 6 characters", because maybe people will try other words which won't fail.
‎2022 Sep 01 7:29 AM
Hi fotso,
I think this is what you need.
DATA: p_char TYPE string VALUE 'Hello Christian Fotso, nice to meet you!'.
FIND ALL OCCURRENCES OF PCRE '[AEIOUY]' IN p_char IGNORING CASE MATCH COUNT DATA(lv_vowels_count).
WRITE:/ lv_vowels_count.
I'd recommend you to check out this blog: Regular Expressions (RegEx) in Modern ABAP. Also read about the PCRE library which I have used here, you will find details about it the mentioned blog.
RegEx is very powerful and can be very helpful scenarios such as your requirement.
Thanks.
‎2022 Sep 01 7:32 AM
As explained by jzaehringer, I hope you are clear with why you are getting the dump. I wanted to provide you with alternative solution and more importantly let you know about RegEx, which you can use in such scenarios.
‎2022 Sep 02 11:51 AM
Thanks you, but here you count in your variable lv_vowels_counts all the vowels in the p_char,
I want to make a count by vowels in p_char,
‎2022 Sep 02 12:46 PM
Sorry, I don't understand what you are looking for, can you please try and explain again?
What I understand is, you are trying to count the number of vowels present in your input parameter p_char, and then store that result in a variable right? The vowels in your case [AEIOUY] are going to be fixed right?
Please try to explain your requirement if its not what I have mentioned.
‎2022 Sep 02 12:44 PM
‎2022 Sep 02 2:01 PM
For the Loop that what jeansy told me to do.
For the Uppercas/Lowercase i use 'Ignoring Case'
Thanks