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: 

I need a ABAP code that gets a sentence and put it in a box like the example that I have provided.

0 Kudos
571

Hello,

I need a program that accepts a block and outputs it in a box. For example, "This is a test" becomes:

********

* This *

* is *

* a *

* test *

********

7 REPLIES 7

FredericGirod
Active Contributor

Sandra_Rossi
Active Contributor
470

Why not just editing your question with Actions > Edit ?

Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

matt
Active Contributor
470

Is this your homework question?

VXLozano
Active Contributor
470

I'm not much about helping people who ask me to do their homework, but although it's a pretty useless requirement, sounds funny. What should I do?

  1. split the string into words (in a table)
  2. find the longest word and store in a variable (mylen?) its length plus 4 (2 empty blanks and two asterisks)
  3. write a string of mylen asterisks
  4. loop the words and put them in a string, surrounded by asterisks (outter char) and half the remainder of mylen minus the word's length (minus 4, ofc)
  5. write again the asterisks line

Of course, it's just my algorythm, I'm sure it can be bested, and, obviously I will not provide a single line of code.

0 Kudos
470

Thank you for your help. It was really helpful. I wrote this code, but I want that the box around the words be the size of longest word in the sentence. With what code I can find the longest word and ask it to write that.

REPORT z_words.

PARAMETERS: p_words TYPE string.

DATA: words TYPE TABLE OF string,
word TYPE string.

SPLIT p_words AT ` ` INTO TABLE words.

WRITE 😕 '*******'.

LOOP AT words INTO word.
WRITE :/'*', word, '*'.
ENDLOOP.
WRITE 😕 '*******'.

VXLozano
Active Contributor
0 Kudos
470

Do a first LOOP and get the longest strlen( ). Something like

loop at words into word.
data(maxlen) = cond i( when strlen( word ) > maxlen then strlen( word ) else maxlen ).
endloop.

(you can do it with a FOR, I assume, but I'm not used yet to that sentence.

0 Kudos
470

Yes I have written it until here, but I have no idea what should I do in continuation.

REPORT z_words.

PARAMETERS: p_words TYPE string.

DATA: words TYPE TABLE OF string,
word TYPE string.

SPLIT p_words AT ` ` INTO TABLE words.

WRITE 😕 '*******'.

LOOP AT words INTO word.
WRITE :/'*', word, '*'.
ENDLOOP.

WRITE 😕 '*******'.