‎2009 May 12 4:19 AM
Hi,
I am working on FM in which i have to put highfen mark which is working ok,but the problem if there is when the value of string finds a space it should not insert highfen in it and i am not able to put the condition in it as it showing the higfen even when the word is full in the first line.i want to show highfen where the word is not able to display complete. here is d code which i am using right now. plzz provide me guidlines to solve this problem.
here's d code:-
FUNCTION Z_STRING_LENGTH1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_STRING) TYPE STRING
*" VALUE(LENGTH) TYPE I
*" EXPORTING
*" VALUE(E_STRING) TYPE STRING
*"----------------------------------------------------------------------
data: STRING_F type string, "Stores the value in string format
STRING_LENGTH type i, "Length of the string
DIFF type i, "Difference among the value
DIFF1 TYPE C,
STRING1 type string, "Stores the 1st String
STRING2 type string, "Stores the 2nd String
STRING3 type string, "Stores the 3rd String
STRING4 type string, "Stores the 3rd String
STRING5 type string, "Stores the 3rd String
LENGTH2 type I.
STRING_F = I_STRING.
STRING_LENGTH = STRLEN( I_STRING ).
DIFF = STRING_LENGTH - LENGTH.
IF DIFF LE 0.
DIFF = 0.
ENDIF.
IF LENGTH LE STRING_LENGTH.
STRING1 = STRING_F(LENGTH).
ELSE.
STRING1 = STRING_F(STRING_LENGTH).
ENDIF.
IF LENGTH LE STRING_LENGTH.
STRING2 = STRING_F+LENGTH(DIFF).
ELSE.
STRING2 = STRING_F+STRING_LENGTH(DIFF).
ENDIF.
length2 = length - 1.
STRING3 = STRING1+length2(1).
STRING4 = STRING2+0(1).
IF LENGTH LE STRING_LENGTH AND STRING3 NE SPACE AND STRING4 NE SPACE.
concatenate STRING1 '-' STRING2 into STRING5.
e_string = STRING5.
ELSE.
concatenate STRING1 STRING2 into STRING5.
e_string = STRING5.
ENDIF.
ENDFUNCTION.
Edited by: ricx .s on May 12, 2009 5:20 AM
‎2009 May 12 6:45 AM
Hi,
and also one more change as you said that for space also it is giving a '-' which is not required... do the change at declaration.....
change the data type of string3 and string4 as shown below......
DATA: STRING_F TYPE STRING,
STRING_LENGTH TYPE I,
DIFF TYPE I,
DIFF1 TYPE C,
STRING1 TYPE STRING,
STRING2 TYPE STRING,
STRING3 TYPE C, " Make string3 and string4 as type c, which holds just one character...
STRING4 TYPE C,
" this will surely resolve your issue... 100%
STRING5 TYPE STRING,
LENGTH2 TYPE I.Regards,
Siddarth
‎2009 May 12 5:40 AM
I don't know what exactly u have to do..But can guess whats wrong with ur code..
In the last condition
IF LENGTH LE STRING_LENGTH AND STRING3 NE SPACE AND STRING4 NE SPACE.
concatenate STRING1 '-' STRING2 into STRING5.
e_string = STRING5.
ELSE.
concatenate STRING1 STRING2 into STRING5.
e_string = STRING5.
ENDIF.
Here... string3 will never be space...so ur code will never go into else part..
Bcoz, string with spaces at the last will take only the characters into it..but not the spaces..
Ex: string = 'ABCDE '..
The value in ur string is 'ABCDE'...thats all...no spaces at the last!.
Check this code..
DATA: str TYPE string.
str = '123456789 '.
DATA: i1 TYPE i.
i1 = strlen( str ).
WRITE : str, 'KING'.
What u can do is...
take the character at ur line end as...
STRING+length(index)...string is ur main string...length is length where u have to break the string the put a hifen..and index is value 1.
Edited by: Veeranji Reddy on May 12, 2009 10:12 AM
‎2009 May 12 6:02 AM
Your code is working fine, it is putting hyphen only at the specified position, not between the spaces.
Can u write what exactly u r getting as output string and what u want to display.....
‎2009 May 12 6:22 AM
HI ,
i know that the Fm is working ok but the problem it is also inserting the highfen where it is not requiered.
for example,
'this is demo'.
if i give length = 5, then it is inserting the highfen in it as there is no need of it. bcoz till 4 th position word this is complete and there is no need of inserting highfen in it,but if i pass the value = 6,it should add highfen at position i-s.
how should i do it in my logic?
‎2009 May 12 6:23 AM
Hi ricx,
chk the following part of coding..
NA (contains Not Any)
The logical expression
<f1> NA <f2>
is true if <f1> does not contain any character from <f2>. The comparison is case-sensitive. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of the first character of <f1> that occurs in <f2> .
IF ( LENGTH LE STRING_LENGTH )
AND ( STRING3 Na SPACE )
AND ( STRING4 Na SPACE ).
concatenate STRING1 '-' STRING2 into STRING5.
e_string = STRING5.
write:/ e_string.
ELSE.
concatenate STRING1 STRING2 into STRING5.
e_string = STRING5.
write:/ e_string.
ENDIF.
Hope it helps..
Regards,
Mdi.Deeba
‎2009 May 12 6:27 AM
Hi,
I checked your code... its working fine except for some cases it is giving dumps for which I have added certain if conditions....
Please check the modified code below... have optimized it as well by removing one extra if condition....
you can copy and paste the code below...
DATA: STRING_F TYPE STRING, "Stores the value in string format
STRING_LENGTH TYPE I, "Length of the string
DIFF TYPE I, "Difference among the value
DIFF1 TYPE C,
STRING1 TYPE STRING, "Stores the 1st String
STRING2 TYPE STRING, "Stores the 2nd String
STRING3 TYPE STRING, "Stores the 3rd String
STRING4 TYPE STRING, "Stores the 3rd String
STRING5 TYPE STRING, "Stores the 3rd String
LENGTH2 TYPE I.
STRING_F = I_STRING.
STRING_LENGTH = STRLEN( I_STRING ).
DIFF = STRING_LENGTH - LENGTH.
IF DIFF LE 0.
DIFF = 0.
ENDIF.
IF LENGTH LE STRING_LENGTH.
STRING1 = STRING_F(LENGTH).
STRING2 = STRING_F+LENGTH(DIFF). " added this statement in this if itself instead of one extra if
" which is not required
ELSE.
STRING1 = STRING_F(STRING_LENGTH).
STRING2 = STRING_F+STRING_LENGTH(DIFF).
ENDIF.
IF LENGTH IS NOT INITIAL.
LENGTH2 = LENGTH - 1.
ENDIF.
" put this if condition as there is a dump occuring at this place.
" Dump occurs when you give the length value as 0
" Say for example the value of I_STRING, I passed it as SIDDARTH
" and the length I passed as 0, then it gives me a dump
STRING3 = STRING1+LENGTH2(1).
IF STRING2 IS NOT INITIAL.
STRING4 = STRING2+0(1).
ENDIF.
" put this if condition as there is a dump occuring at this place.
" Dump occurs when you give the length value greater than or equal to
" the string length
" Say for example the value of I_STRING, I passed it as SIDDARTH
" and the length I passed as 8, then it gives me a dump
IF LENGTH LE STRING_LENGTH AND STRING3 NE SPACE AND STRING4 NE SPACE.
CONCATENATE STRING1 '-' STRING2 INTO STRING5.
E_STRING = STRING5.
ELSE.
CONCATENATE STRING1 STRING2 INTO STRING5.
E_STRING = STRING5.
ENDIF.
‎2009 May 12 6:45 AM
Hi,
and also one more change as you said that for space also it is giving a '-' which is not required... do the change at declaration.....
change the data type of string3 and string4 as shown below......
DATA: STRING_F TYPE STRING,
STRING_LENGTH TYPE I,
DIFF TYPE I,
DIFF1 TYPE C,
STRING1 TYPE STRING,
STRING2 TYPE STRING,
STRING3 TYPE C, " Make string3 and string4 as type c, which holds just one character...
STRING4 TYPE C,
" this will surely resolve your issue... 100%
STRING5 TYPE STRING,
LENGTH2 TYPE I.Regards,
Siddarth
‎2009 May 12 10:47 AM
hi sidarth,
i had made up the changes which you had mentioned to do but still it is giving the run time error.
*STRING3 = STRING1+LENGTH2(1).*
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_RANGE_OUT_OF_BOUNDS', was not
caught in
procedure "Z_STRING_LENGTH2" "(FUNCTION)", nor was it propagated by a RAISING
clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
In the running program "SAPLZGROUP_FOR_555", part of a string was about to be
accessed
via an offset.
However, the offset (4) was larger than the current length of the
string (4).
This kind of access is illegal.
Even though i had made up the changes in STRING3 and STRING4.
plzzzprovide me guidleines to solve this problem.
‎2009 May 12 10:52 AM
Hi,
write this statement
STRING3 = STRING1+LENGTH2(1).within if condition ...
if string1 is not initial.
STRING3 = STRING1+LENGTH2(1).
endif.This will solve your problem for sure...
regards,
Siddarth
‎2009 May 12 11:02 AM
Hi,
If i am using the syntax above mentioned by you it is not giving the desired result.
for example,
i had made a change in the code by passing the value as:-
IF STRING1 IS NOT INITIAL.
STRING3 = STRING1+LENGTH2(1).
ENDIF.
If the string is 'THIS' and i pass the value 4,3,2. It is inserting the highfen in it,
but when i pass the value = 5 it is still giving the run time error.
plzz provide me guidelines to this problem.
Edited by: ricx .s on May 12, 2009 12:02 PM
Edited by: ricx .s on May 12, 2009 12:14 PM
Edited by: ricx .s on May 12, 2009 12:21 PM
‎2009 May 12 11:29 AM
Hi,
I apologize for the mistake in if condition....
change the if condition as given below.... its working fine... have checked it out....
IF LENGTH2 LT STRING_LENGTH.
STRING3 = STRING1+LENGTH2(1).
ENDIF.Regards,
Siddarth
‎2009 May 12 11:40 AM
HI,
THANKS A LOT ,u helped a lot and i am assigning full points to you.