2023 May 10 7:37 AM
When I run this code I get this error. Doas anyone have any idea?
Field "(MAX_WORD_LENGTH + 2 )" is unkown
REPORT z_words.
PARAMETERS: p_words TYPE string.
DATA: words TYPE TABLE OF string,
word TYPE string,
max_word_length TYPE i.
SPLIT p_words AT ` ` INTO TABLE words.
" Find the length of the longest word
LOOP AT words INTO word.
IF strlen( word ) > max_word_length.
max_word_length = strlen( word ).
ENDIF.
ENDLOOP.
" Output the box
WRITE 😕 (max_word_length+2) (max_word_length+2) REPEATING '*'.
LOOP AT words INTO word.
WRITE 😕 '|', word CENTERED( max_word_length ), '|'.
ENDLOOP.
WRITE 😕 (max_word_length+2) (max_word_length+2) REPEATING '*'.
2023 May 10 7:46 AM
Please use the CODE button in the editor to post code.
REPORT z_words.
PARAMETERS: p_words TYPE string.
DATA: words TYPE TABLE OF string,
word TYPE string,
max_word_length TYPE i.
SPLIT p_words AT ` ` INTO TABLE words.
LOOP AT words INTO word.
IF strlen( word ) > max_word_length.
max_word_length = strlen( word ).
ENDIF.
ENDLOOP.
WRITE 😕 (max_word_length + 2 ) (max_word_length + 2 ) REPEATING '*'.
LOOP AT words INTO word.
WRITE 😕 '|', word CENTERED( max_word_length ), '|'.
ENDLOOP.
WRITE 😕 (max_word_length + 2) (max_word_length + 2 ) REPEATING '*'.
2023 May 10 7:48 AM
If you edit the program in Eclipse, it's obvious.
You need to read the syntax of WRITE and CENTERED in the ABAP documentation. Braces ( ) are not part of the WRITE statement.
You can't just guess at syntax and hope it works.
2023 May 10 7:50 AM
2023 May 10 8:09 AM
to split the words in a sentence, make them vertical in a box made of asterisks like this,
"It is a Test"
********
* It *
* is *
* a*
* Test *
********
I want that the size of box be equal to longest word in the sentence.
2023 May 10 8:13 AM
2023 May 10 8:18 AM
What about having a '**************************************' field content and just playing with offset & length ?
2023 May 10 8:29 AM
Thank you Matthew, nice to see well-formatted code!
zakariarazi for your information, you can use Actions > Edit to edit your question (to fix the formatting for instance).
2023 May 10 8:51 AM
frdric.girod I am a Beginner. I do not know how I can do that.
2023 May 10 9:42 AM
data(my_stars) = '*********************************************************'.
write /1 my_stars+0(the_max_word_length).
2023 May 10 11:11 AM
frdric.girod
I wrote this code, but I get this error. Do you know how I can fix it?
REPORT z_words.
PARAMETERS: p_words TYPE string.
DATA: words TYPE TABLE OF string,
word TYPE string,
len TYPE i,
max_len TYPE i VALUE 0.
SPLIT p_words AT ` ` INTO TABLE words.
LOOP AT words INTO word.
len = strlen( word ).
IF len > max_len.
max_len = len.
ENDIF.
ENDLOOP.
WRITE 😕 |{ `*` REPEAT( `*`, max_len + 2 ) `*` }|.
LOOP AT words INTO word.
WRITE :/'* ', word, REPEAT( ` `, max_len - strlen( word ) + 1 ), '*'.
ENDLOOP.
WRITE 😕 |{ `*` REPEAT( `*`, max_len + 2 ) `*` }|.
"REPEAT"("could not be interpreted. Possible error causes: Incorrect spelling or comma error.2023 May 10 12:05 PM
maybe you are trying to do this:
WRITE 😕 |{ max_word_length + 2 } { max_word_length + 2 } REPEATING '*' |.
LOOP AT words INTO word.
WRITE 😕 | word CENTERED ( max_word_length ), |.
ENDLOOP.
WRITE 😕 |{ max_word_length + 2 } { max_word_length + 2 } REPEATING '*' |.
2023 May 10 12:37 PM
frdric.girod It was not the question, but in the end I think the OP wants more something like this 😉
WRITE 😕 |{ repeat( val = '*' occ = max_word_length + 2 ) }|.
LOOP AT words INTO word.
WRITE 😕 |*{ word ALIGN = CENTER WIDTH = max_word_length }*|.
ENDLOOP.
WRITE 😕 |{ repeat( val = '*' occ = max_word_length + 2 ) }|.
2023 May 10 12:53 PM
sandra.rossi I put a maybe because I didn't test it. Just correct the code, like ChatGPT I do a readable code, but without logic
2023 May 10 1:20 PM