String wrap

Share on Facebook3Share on LinkedIn0Tweet about this on TwitterShare on Google+0
Please Share!!
SAP has provided function module ‘RKD_WORD_WRAP‘ to wrap Character type variables. But we cannot use this FM to wrap String type variables. Either you need to transfer the string type data into a character type variable and use this FM or use your own code to wrap the string.But if you want to use the string type variables without transferring it to character type variables, then you can use the below function module or copy the code snippet and use the wrapping logic.
[adToAppearHere]

FUNCTION z_string_wrap.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” VALUE(TEXTLINE) TYPE STRING
*” VALUE(OUTPUTLEN) TYPE I DEFAULT 50
*” TABLES
*” OUT_LINES
*”———————————————————————-
DATA:
lk_line TYPE string,
lv_offset TYPE i,
lv_to_pos TYPE i,
lv_new_target_pos TYPE i,
lv_length TYPE i.

IF outputlen IS INITIAL.
outputlen = ’50’.
ENDIF.
* Get string length
lv_length = STRLEN( textline ).

* If the string length is less than output length requested
IF lv_length LE outputlen.

* Write the string value
lk_line = textline.

* Append the wrapped string
APPEND lk_line TO out_lines[].

* If greater than max characters
ELSE.

* Get the to postion. Default is 50
lv_to_pos = outputlen.

* Breaking the string to fields of max reqested characters
DO.

* Get data to the length
lk_line = textline+lv_offset(lv_to_pos).

* Append the wrapped string
APPEND lk_line TO out_lines[].

* Increasing the offset value
lv_offset = lv_offset + lv_to_pos.

* If offset is equal to the length of the string
IF lv_offset = lv_length.

* Exit from the do-end loop
EXIT.

ENDIF.

* New position till where the string has been written/split
lv_new_target_pos = lv_offset + outputlen.

* If new position is greater than the string length
IF lv_new_target_pos > lv_length.

* The position till where we need to read is this subtraction
* This would be less than OUTPUTLEN
lv_to_pos = lv_length – lv_offset.

ELSE.
* Else just read the OUTPUTLEN value
lv_to_pos = outputlen.
ENDIF.

ENDDO.

ENDIF.

ENDFUNCTION.

If you want to get such practical issues and resolutions straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.

If you liked this post, please hit the share button at the left side of your screen.

Thank you very much for your time!!

Image source : www.aliexpress.com

Share on Facebook3Share on LinkedIn0Tweet about this on TwitterShare on Google+0
Please Share!!

About the Author

SAP Yard
SAP Yard
SAPYard is one stop page for all Technical Folks in SAP. You would find un-conventional explanations, tutorials, and tricks. Please like our Facebook Page and also join our LinkedIn Group.

1 Comment on "String wrap"

  1. This post has a lot of importance to the people, I want to do SAP Online Training so please suggest me best training center in USA.

Comments are closed.