‎2008 May 05 11:09 AM
Hi all,
I have a variable 'file1'.This variable stores the names of the pdf files located in SAP directory.
The name of the file is like:'PDFST0000098357US81042008',
which containg order no ,sales org, month and date of that file creation.
Now i have a requirement to extract that month and year from this variable.
Also some filenames have different format like'PDFIPF......' instead of 'PDFST.....'.
so kindly suggest how to extract month and year from this variable.
Thank You.
‎2008 May 05 11:13 AM
hi use this
data: month(2) , year (4),
data: tmp type i, len type i.
len = strlen(file1).
tmp = len - 6.
month = file1+tmp(2).
tmp = tmp + 2.
year = file1+tmp(4).
reward if useful
‎2008 May 05 11:14 AM
Get strlen of the file and get the last 6 characters ..
I think month and year are stored at the last ...
v_len = strlen ( file1 ) .
v_len = v_len - 6.
v_date = file1+v_len.
‎2008 May 05 11:18 AM
Hi,
You can use fm STRING_REVERSE to reverse the name of the filename. Then go ahead and extact eight letters of the reversed string and once again reverse that, so at this you will get the date part in DDMMYYYY.
Again you can manipulate this date string to get back the original date.
1. use string_reverse input filename, output reversed string.
2. reversedstring+0(8) will extract date part ( reverse ).
3. Again reverse this string.
But seeing at the example, this would be tougher if the date in the filename is not in DDMMYYYY, meaning that if the date is 1st april 2008 then if the date format is DMYYYY(142008), then the logic would go for a toss.
Thanks and regards,
S. Chandramouli.
‎2008 May 05 11:19 AM
hi rohan,
u find the length of string , u have month an dyear at last only always, so u can easily cal the month , yr to diff strings
loop at itab into <string>.
x = strlen<string>.
y = x - 6.
z = x - 4.
month = string + y(2).
year = string + z(4).
clear string,x,y,z.
endloop.
reward if useful,
regards,
chandu.
‎2008 May 05 11:22 AM
‎2008 May 05 11:23 AM
But also sometimes the variable conatins 'pdfst0000096286us16c1'.
In such cases i have to add current year to that.
‎2008 May 05 11:58 AM
hi after getting month and year in variables
do validation such as
you have month in month and yar in year variable.
use ISP_GET_MONTH_NAME FM to validate month
and VALIDATE_YEAR to validate year
if any one of fail use current month and year.
reward if useful.