Get last letter of a string....
Hi guys.
Have a problem with ABAP in SAP.
I need to get the last character of the string, like this...
'AAAAAAAA BBBB 1 QQQQQQQQ 2'.
i need to take the last letter (2) to do more things b4.
I'm thinking to rotate the string and take the first letter, but i think will exist a FM that do my requirement.
See you.
Thanks: Miguel
Hi,
First get the string lengthof the variable.
data: lv_string type char4 value 'ABCD',
lv_new type i,
lv_new1 type char2.
*lv_new = strlen(lv_string).
CALL FUNCTION 'STRING_LENGTH'
EXPORTING
string = lv_string
IMPORTING
LENGTH = lv_new
lv_new = lv_new - 2.
lv_new1 = lv_string+lv_new(2).
write lv_new1.
You get the last two characters.
reward if useful..
regards,
nazeer
Message was edited by:
nazeer shaik
Similar Messages
-
Formula for getting first letter of the string
Post Author: jmmj
CA Forum: Formula
Hi, I have a problem to get the first letter of the string. I need to compare first letter first and then change the rest of string to number as unit cost for calculation. For example, I have string K100, C200,... if first letter = K then 0 else if first letter = C then tonumber200..... I use CRXI, any assistance will be appreciate.jmmjPost Author: jmmj
CA Forum: Formula
It works, thanks Kai!But when I tried to print the report, there are multiple lines shown same invoice number but different unit price. My formular is: IF {OEINPR3.COINTYPE} = 2 OR CCur({OEINPR3.LINETYPE}) = 1 //line type 1 for item, 2 for misc. charge THEN( IF {OEINPR3.COIN}[1] = "K" OR {OEINPR3.COIN}[1] = "N" THEN TONUMBER(MID({OEINPR3.COIN},2,20)) ELSE 0)ELSE 2 //for testing only The result I have: Line# Inv# unitprice total1 IN001 0.00 10.00 IN001 10.00 10.00 2 IN002 0.00 20.00 IN002 20.00 20.00.......The second line of each invoice is correct. How can I print just one line for each invoice which is correct? Thanks!jmmj -
Good Day All,
I have a string field that does not a Consistence length.
I want to check the last of this field and concatenate some text depending on the result.
I've tried this but does not work.
if mid({usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name,1 Len{usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name}-1) = "M"
then {usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name} & " Managed"
else {usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name} & " Unmanaged
Basically I'm check the length and if return an M it's Managed everything else is Unmanaged.
Thanks
DMif you want to check last letter then try this
if right({usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name},1)="M" then
then {usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name} & " Managed"
else {usp_wb_Reporting_AssetsUnderManagement_A2a_Main;1.account_long_name} & " Unmanaged
Regards,
Raghavendra -
Problem in getting last value of a string in Function Module
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 AMHi,
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. -
HI all ,
how to got the right part of my string in java?
String Name =req.getParameter("Horst");in sql i can use
SELECT right(Name, 2) to got the last letter in string , but when I modify the code as Syear="SELECT right('"+Name+"', 2)"; I got error . is java have function to got last letter in string??
thank you!String s1 = "HELLO";
String s2 = s1.substring(s1.length() - 1); -
User defined function for getting last string in the line
Hi Experts,
I am not java expert, can anyone give me user defined function for getting last string in the line.
for example if the source field is "NEW ARBOUR SQUARE" i want to pass to target field only last string that is "SQUARE"
please help me out of this.
Kind Regards.
Praveen.You don't even need a UDF for this. In the graphical editor look for the standard functions and once you do a scroll over on 'text functions; you will find what you are looking for.
Just a piece of advice, try keeping UDF's to minimum unless really required or it is complicated without it.
regards -
I cant upgrade to itunes 10 "itunes cannot run because some of its files are missing, Please reinstall itunes" It wont let me deleate itunes i get the same message. Another error i get is "error getting file security C:\program files\itunes\cdconfigeration Get last error 5"
Whats the deal?I was having this error too. The good news is I was able to fix it fairly easily. Here's how I did it:
1: Find the directory in windows explorer (C:\Program Data)
2: Right click on the 34BE82C4-E596-4e99-A191-52C6199EB69 directory and select properties.
3: Select the 'Security' tab.
4: In the 'Group or user names' box, there should be the following entries;
SYSTEM
Administrators (xxxx\Administrators)
Users (xxxx\Users)
(where xxxx is the name of your computer)
If these user names do not exist, create them by clicking on 'Edit' and then 'Add' and typing in the user name.
5: Set the permissions for these user names (using the 'Edit' button) as follows;
SYSTEM - check all boxes except 'Special Permissions'
Administrators (xxxx\Administrators) - check all boxes except 'Special Permissions'
Users (xxxx\Users) - check Read & execute, List folder contents and Read.
6: Rember to click 'Apply' after setting up each user name, and when you are done, just OK your way back out of the properties dialog box.
7. Now try to update itunes.
This fix worked for me
I'm running windows 7, btw.
Hope this helps. -
Using Fiscal/Year Period to get last year all months data
Hi,
Had a requirement to get Last Years 1-12 months data based on Fiscal/Year Period. So here i am using Fiscal/Year period as my input. Please let me know with code.
Regards,
VishnuHi ,
Where you want to write code ?
Well the basic logic will be like :
TYPES: BEGIN OF ty_range,
sign TYPE c LENGTH 1,
option TYPE c LENGTH 2,
low TYPE c LENGTH 8,
high TYPE c LENGTH 8,
END OF ty_range.
DATA : t_range TYPE TABLE OF ty_range,
w_range LIKE LINE OF t_range.
DATA :v_lastyear type c length 4 .
v_lastyear = sy-datum(4) - 1 .
w_range-sign = 'I'.
w_range-option = 'EQ'.
concatenate v_lastyear '001' t into w_range-low.
concatenate v_lastyear '012' t into w_range-high.
APPEND w_range TO t_range.
****it will select data from source package for last one year .Internally year and period store like YYYYPPP (2011001)
select SOURCE_PACKAGE WHERE 0fiscper IN t_range.
you can modify selection statement as per your requirement .
hope this will be helpful .
Regards,
Jaya Tiwari -
Finding last char in the string
Hi
i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.
thankslen = strlen(char).
len = len - 1.
if char+len(1) = '/'.
*write ur code
endif.
chk this code
REPORT ychatest.
DATA : str(5) VALUE '123/',
len TYPE i.
len = STRLEN( str ).
len = len - 1.
IF str+len(1) = '/'.
WRITE : '/ found'.
ENDIF.
<b>Reward points if helpful and close thrad if solved</b>
Message was edited by: Chandrasekhar Jagarlamudi -
To extract the last word in a string
Hi
I am using BODS 14.1.1.210
I would like to extract the last word in a string in BODS query. How can I achieve this when I don't know how many words are present in a space delimited string.
Example
Input Output
My name is Tim Tim
Complicated Complicated
there is a bird in the nest nest
Please let me know if there is a query function for this one.
Cheers!Hi,
try this-
word_ext(fieldname,-1,' ')
Atun -
How to get Last Year Sales and YTD Sales without using AGO and TODATE?
Hi all,
I have got Company and Time dimensions and Sales Fact. My requirement is to get Last Year sales for each company without using AGO function and YTD without using TODATE function. (Due to performance issue as AGO and TODATE do not insert a Cache entry).
Can someone please help me to achieve my requirement? Thanks in advance.Hi Satya,
Thanks again for your reply. To start with I don't have data for the years 2012 and 2011 to test as I am using SH sample schema from Oracle. I have applied your solution but it does not seem to be working for the previous years like 2000, 2001. My requirement is to have a dashboard prompt "YEAR" and let the user choose whatever year he wants.
Please have a look at the column formulas of my analysis (As per your solution) :
***here B_YEAR is replaced by CALENDAR_YEAR.
Amount: "F1 Sales"."Amount"
AmountYTD: FILTER("F1 Sales"."Amount" USING "D1 Time"."CALENDAR_YEAR" =YEAR(CURRENT_DATE))
Amount LY: FILTER("F1 Sales"."Amount" USING "D1 Time"."CALENDAR_YEAR" =YEAR(CURRENT_DATE)-1)and the physical query generated by BI Server: (as you can see I have got a filter CALENDAR_YEAR= 2000)
WITH
SAWITH0 AS (select sum(T1074.AMOUNT_SOLD) as c1,
sum(case when T1035.CALENDAR_YEAR = TO_NUMBER(TO_CHAR(TO_DATE('2012-05-03' , 'YYYY-MM-DD'), 'yyyy'), '9999') then T1074.AMOUNT_SOLD end ) as c2,
sum(case when TO_NUMBER(TO_CHAR(TO_DATE('2012-05-03' , 'YYYY-MM-DD'), 'yyyy'), '9999') - 1 = T1035.CALENDAR_YEAR then T1074.AMOUNT_SOLD end ) as c3,
T1035.CALENDAR_MONTH_DESC as c4,
T1035.CALENDAR_YEAR as c5,
T1035.CALENDAR_MONTH_ID as c6
from
TIMES T1035 /* D1 Time */ ,
SALES T1074 /* F1 Sales */
where ( T1035.CALENDAR_YEAR = 2000 and T1035.TIME_ID = T1074.TIME_ID )
group by T1035.CALENDAR_MONTH_DESC, T1035.CALENDAR_MONTH_ID, T1035.CALENDAR_YEAR)
select distinct 0 as c1,
D1.c4 as c2,
D1.c5 as c3,
D1.c1 as c4,
D1.c2 as c5,
D1.c3 as c6,
D1.c6 as c7
from
SAWITH0 D1
order by c3, c2 Thanks in advance. -
I have the following code that functions like a basic RPN calculator:
public class Main {
* @param args the command line arguments
static public ArrayList<Double> stack = new ArrayList<Double>();
static double numberInput;
static double answer;
static String operation;
//Prints Welcome screen, initialized checkforInput
public static void main(String[] args) {
System.out.println();
System.out.println("Welcome to RPNCalc by theCoffeeShop()");
checkForInput();
//Checks for input, redirects to appropriate method
public static void checkForInput() {
Scanner reader = new Scanner(System.in);
String input = reader.nextLine();
if(isDouble(input) == true) {
double number = Double.parseDouble( input );
stack.add(0, number);
repeat();
} else {
operation = input;
operation();
//Processes numeric operations
public static void operation () {
if(operation.equals("+")) {
answer = stack.get(1)+stack.get(0);
stack.add(0, answer);
System.out.println(answer);
repeat();
} else if (operation.equals("-")) {
answer = stack.get(1)-stack.get(0);
stack.add(0, answer);
System.out.println(answer);
repeat();
} else if (operation.equals("*")) {
answer = stack.get(1)*stack.get(0);
stack.add(0, answer);
System.out.println(answer);
repeat();
} else if (operation.equals("/")) {
answer = stack.get(1)/stack.get(0);
stack.add(0, answer);
System.out.println(answer);
repeat();
} else {
System.out.println("Incompatible operation");
repeat();
//Called when ready to recheck for input
public static void repeat() {
checkForInput();
//Checks if string is double
public static boolean isDouble( String input )
try
Double.parseDouble( input );
return true;
catch(Exception e)
return false;
}To perform a basic operation (5+2), you would do the following
5
enter
2
enter
(plus)
enter
Computer prints 7.
I would like it to function like this:
5
enter
2(plus)
enter
Computer prints 7.
To do this, I have to be a be to split a string into 2 parts, the operation and the number. I think I could do this with a StringBuffer, but How to read the LAST char of a StringBuffer, instead of just a specific char? If there is a way to do it w/out a StringBuffer, I'm open to suggestions.Hint:
The last character of a String (or StringBuilder or StringBuffer, etc.) is at the index (length_of_string - 1).
Are you sure you're supposed to solve the problem this way? Usually homework assignments of this sort involve writing a whole parser. -
Hi Gurus,
I want to get the last character of a String.For Ex.
I have name = 'ZXCDFG":?'
And I want to print the last character ?.
How can i do it.
Thanks in Advance.Hi Pradeep,
Just find the String Length and use the offset commands
DATA : DATA TYPE CHAR20 'ABCDEFG',
DATA : DATA1,
DATA : LEN TYPE I.
LEN = STRLEN( DATA ).
LEN = LEN - 1.
DATA1 = DATA+LEN(1).
Regards
Kumar M. -
How to delete the last char in a String?
i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?
Try it in this way
String MyString = "ABCDEF";
MyString = MyString.substring(0,MyString.length()-1); -
How to get a position in a string?
I need to get a position in a string like the word CHEESE, where the c is position 1, the h is position 2, the e is position 3 etc... Which input stream should i use and how does it work really?
indexOf(int ch)
Returns the index within a string of the first occurrence of the specified character.
Maybe you are looking for
-
Additional parameters in the adapter configuration - note 801926
Hi, from help.sap.com I remember that note 801926 is proposed on the file adapter config page for at least 2-3 months by now. but when I try to download it I see: "Note 801926 is not released." can anyone download this note and paste it here? (maybe
-
User Defined Field in Material master
Hi Friends, Can we add any user defined fields in any views in material master (preferably with F4 help) If so, please let me know how to do it and its impact. Regards Ram
-
The FOUR versions of BT Yahoo Webmail
I have been informed that there are currently 4 versions of BT Yahoo Webmail starting with Classic Mail. Can anyone let the community know where these are described and what the differences are ?
-
hello, i want to ask about Jtable. is it possible to add a components in the Jtable. example i want to add button in the jtable in row 1 coloum 1. can u give me some example thanks
-
My photos are on my iphone 4 but when I manually open the folder to transfer to the PC it does not show the photos. How do I copy the photos to PC then?