Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Field "(MAX_WORD_LENGTH + 2 )" is unkown

0 Kudos
973

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 '*'.
14 REPLIES 14

matt
Active Contributor
0 Kudos
922

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 '*'.

matt
Active Contributor
922

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.

FredericGirod
Active Contributor
0 Kudos
922

What is the goal ?

What did you expect with the REPEATING ?

0 Kudos
922

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.

0 Kudos
922

repeating the asteriks

FredericGirod
Active Contributor
922

What about having a '**************************************' field content and just playing with offset & length ?

Sandra_Rossi
Active Contributor
922

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).

0 Kudos
922

frdric.girod I am a Beginner. I do not know how I can do that.

FredericGirod
Active Contributor
0 Kudos
922

data(my_stars) = '*********************************************************'.

write /1 my_stars+0(the_max_word_length).

0 Kudos
922

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.

FredericGirod
Active Contributor
922

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 '*' |.

Sandra_Rossi
Active Contributor
922

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 ) }|.

FredericGirod
Active Contributor
922

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

0 Kudos
922

Thank you frdric.girod and sandra.rossi

It worked!