2008 Nov 11 11:20 AM
Hi,
I have been asked to changed a document to only display about 40 character texts. The best way I could think to do this would be to take the inidividual strings and concatonate them and then split them up again in 40 character chunks. However, here is the complicated part... I can only split on full words. I thought about doing this by looking at the text finding position 40 and then searching for the next space. I would then output this text and look for the next text. This would loop until the end of the text.
e.g.
TEXT = "here is some test text that I want to loop through and only display about fourty characters. The downside is that I can only seperate on full words. I would also need to remove leading spaces."
RESULT
TEXT1="here is some test text that I want to loop"
TEXT2="through and only display about fourty characters."
TEXT3="The downside is that I can only seperate"
TEXT4="on full words. I would also need to remove "
TEXT5="leading spaces."
any ideas?
Hi,
I have been asked to changed a document to only display about 40 character texts. The best way I could think to do this would be to take the inidividual strings and concatonate them and then split them up again in 40 character chunks. However, here is the complicated part... I can only split on full words. I thought about doing this by looking at the text finding position 40 and then searching for the next space. I would then output this text and look for the next text. This would loop until the end of the text.
e.g.
TEXT = "here is some test text that I want to loop through and only display about fourty characters. The downside is that I can only seperate on full words. I would also need to remove leading spaces."
RESULT
TEXT1="here is some test text that I want to loop"
TEXT2="through and only display about fourty characters."
TEXT3="The downside is that I can only seperate"
TEXT4="on full words. I would also need to remove "
TEXT5="leading spaces."
any ideas?
2008 Nov 11 11:24 AM
Totally irrelevant link deleted by moderator
Edited by: Matt on Nov 17, 2008 5:16 PM
2008 Nov 11 11:28 AM
Hi,
I have seen this thread but it doesn't go into detail around the full word split. I cant just split at a predefined position as this would split the word up.
Regards,
Paul
2008 Nov 11 11:28 AM
Hi
Use Functin Module WORD_WRAP, there u can fix the desired length.
Vijay
2008 Nov 11 11:32 AM
Hi use the below code;
DATA : lv_text(50),lv_line1(20),lv_line2(20),lv_line3(20).
lv_text = 'This is the report to display invoice for customer'.
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
textline = lv_text
DELIMITER = ' '
OUTPUTLEN = 20 " Your line length
IMPORTING
OUT_LINE1 = lv_line1
OUT_LINE2 = lv_line2
OUT_LINE3 = lv_line3
EXCEPTIONS
OUTPUTLEN_TOO_LARGE = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write : / 'lv_text : ', lv_text,/ 'lv_line1: ', lv_line1,/ 'lv_line2: ' ,lv_line2,/ 'lv_line3: ', lv_line3.
Output:
lv_text : This is the report to display invoice for customer
lv_line1: This is the report
lv_line2: to display invoice
lv_line3: for customerHope this will solve your problem.
Update:
This is just an example, you can get all the lines in an internal table using the tables parameters out_lines of the above FM while calling.
Regards
Karthik D
Edited by: Karthik D on Nov 11, 2008 5:04 PM
2008 Nov 11 11:33 AM
2008 Nov 11 11:34 AM
Use the following logic
do while len le 40
SPLIT text AT space INTO: str1 str2.
find string length using string lengh function
len = length of str1.
endwhile.
Cheers,
KD
2008 Nov 11 12:14 PM
RKD_WORD_WRAP is the exact solution - but I need to call this from within my FORM.
I have the following code - but its coming back blank??? Not sure why?
P2 &VBDPA-POSNR(Z)&,,&VBDPA-MATNR&
/: CALL FUNCTION 'RKD_WORD_WRAP'
/: EXPORTING
/: TEXTLINE = &SALES_TEXT_1&
/: DELIMITER = ' '
/: OUTPUTLEN = 40
/: IMPORTING
/: OUT_LINE1 = OUT_LINE1
/: OUT_LINE2 = OUT_LINE2
/: OUT_LINE3 = OUT_LINE3
/: * TABLES
/: * OUT_LINES =
/: EXCEPTIONS
/: OUTPUTLEN_TOO_LARGE = 1
/: OTHERS = 2.
/*
/*
/*
= ,,&OUT_LINE1&</>
2008 Nov 11 12:20 PM
I am not sure whether you can call FM as you did in Script, but its recommended to use a Perform and code the FM call in another Zprogram subroutine. Search the forum with "Perform in script", you will get lots of code samples.
Regards
Karthik D
2008 Nov 11 12:55 PM
/: PERFORM SPLIT_TEXT IN PROGRAM ZSTRING_SPLIT
/: USING &SALES_TEXT_1&
/: CHANGING &OUT_LINE1&
/: CHANGING &OUT_LINE2&
/: CHANGING &OUT_LINE3&
/: ENDPERFORM
P1 &OUT_LINE1&
P1 &OUT_LINE2&
P1 &OUT_LINE3&
SE38 - Sub routine pool
PROGRAM ZSTRING_SPLIT .
&----
*& Form SPLIT_TEXT
&----
text
----
-->INPUT_TABLEtext
-->OUTPUT_TABLtext
----
FORM SPLIT_TEXT TABLES INPUT_TABLE STRUCTURE ITCSY
OUTPUT_TABLE STRUCTURE ITCSY.
DATA : LV_LINE1(100),
LV_LINE2(100),
LV_LINE3(100).
READ TABLE INPUT_TABLE WITH KEY NAME = 'SALES_TEXT_1' .
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE = INPUT_TABLE-VALUE
DELIMITER = ' '
OUTPUTLEN = 10
IMPORTING
OUT_LINE1 = LV_LINE1
OUT_LINE2 = LV_LINE2
OUT_LINE3 = LV_LINE3
EXCEPTIONS
OUTPUTLEN_TOO_LARGE = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE OUTPUT_TABLE WITH KEY NAME = 'OUT_LINE1' .
OUTPUT_TABLE-VALUE = LV_LINE1.
MODIFY OUTPUT_TABLE TRANSPORTING VALUE WHERE NAME = 'OUT_LINE1' .
READ TABLE OUTPUT_TABLE WITH KEY NAME = 'OUT_LINE2' .
OUTPUT_TABLE-VALUE = LV_LINE2.
MODIFY OUTPUT_TABLE TRANSPORTING VALUE WHERE NAME = 'OUT_LINE2' .
READ TABLE OUTPUT_TABLE WITH KEY NAME = 'OUT_LINE3' .
OUTPUT_TABLE-VALUE = LV_LINE3.
MODIFY OUTPUT_TABLE TRANSPORTING VALUE WHERE NAME = 'OUT_LINE3' .
ENDFORM . "SPLIT_TEXT
2008 Nov 17 3:56 PM
So Close now - however the only problem I have is the concatenate string - see the code below
/: CONCATENATE &SALES_TEXT_1& &SALES_TEXT_2& &SALES_TEXT_3&
= INTO &SALES_TEXT_10&
/*
/: PERFORM SPLIT_TEXT IN PROGRAM ZSTRING_SPLIT
/: USING &SALES_TEXT_10&
/: CHANGING &OUT_LINE1&
/: CHANGING &OUT_LINE2&
/: CHANGING &OUT_LINE3&
/: ENDPERFORM
The problem I am experiencing is that value &SALES_TEXT_10& has the incorrect information when it passes it across. Therefore I think there is a problem with the concatenate line.
Bascially I want to concatenate all the text from sales_text_1, sales_text_2 and sales_text_3 into one variable and pass this with the using command as part of the perform.
Anyone see where I am going wrong as I am sure this is obvious. This code is taken from the sapscript page.
Regards
2008 Nov 17 4:02 PM
in Script you cannot use the same statements like in pure ABAP (ok, some of them you can, but differently....)
in this case you have to do the following:
in the SAPScript:
/: PERFORM SPLIT_TEXT IN PROGRAM ZSTRING_SPLIT
/: USING &SALES_TEXT_1&
/: USING &SALES_TEXT_2&
/: USING &SALES_TEXT_3&
/: CHANGING &OUT_LINE1&
/: CHANGING &OUT_LINE2&
/: CHANGING &OUT_LINE3&
/: ENDPERFORM
and in the form routine do the CONCATENATE before the FM call
2008 Nov 17 4:08 PM
The FM works correctly when you merge all the texts into one field and pass it through - however I cant seem to get this concat working. I actually tried what you suggested below and it made no difference - I only got sales_text_1 back correctly spit into 40 characters. However the text contained in sales_text_2 didn't come back at all.
Basically the string needs to be merged together which is the area I am having problems with. Are you saying you cant concatonate strings within sapscript?
I think the problem could be fixed in the program (looking below you will see i only read sales_text_1 as the value
e.g.
READ TABLE INPUT_TABLE WITH KEY NAME = 'SALES_TEXT_1' .
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE = INPUT_TABLE-VALUE
DELIMITER = ' '
OUTPUTLEN = 40
IMPORTING
OUT_LINE1 = LV_LINE1
OUT_LINE2 = LV_LINE2
OUT_LINE3 = LV_LINE3
EXCEPTIONS
OUTPUTLEN_TOO_LARGE = 1
OTHERS = 2.
Regards
2008 Nov 17 4:13 PM
you have this line in the subroutine:
READ TABLE INPUT_TABLE WITH KEY NAME = 'SALES_TEXT_1' .
of course you have to "multiply" it, to read all import parameters of the subroutine, something like:
DATA : lv_text1(100) TYPE c,
lv_text2(100) TYPE c,
lv_text3(100) TYPE c.
READ TABLE INPUT_TABLE WITH KEY NAME = 'SALES_TEXT_1' .
lv_text1 = input_table-value. "Pls. check if this is the field, which actually holds the value
READ TABLE INPUT_TABLE WITH KEY NAME = 'SALES_TEXT_2' .
lv_text2 = input_table-value.
READ TABLE INPUT_TABLE WITH KEY NAME = 'SALES_TEXT_3' .
lv_text3 = input_table-value.
Now concatenate (yes, the CONCATENATE does not work in SAPScript directly):
CONCATENATE lv_text1 lv_text2 lv_text3 INTO ...
Now call the FM...
2008 Nov 17 5:18 PM
create a table with a field of type string
get the number of chars in the string to be splitted..................
loop with the character count when it reaches the count what you want pass the string to the table created above..........keep on adding the lengths as you desired...
while printing print the data from the table created above...
the above logic you can generalize it to a string of any lenght....
use constants you can change however you want.
thanks,
vinayaka
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |