Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

To Split a variable to get the date.

Former Member
0 Likes
1,041

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.

7 REPLIES 7
Read only

Former Member
0 Likes
871

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

Read only

Former Member
0 Likes
871

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.

Read only

former_member784222
Active Participant
0 Likes
871

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.

Read only

Former Member
0 Likes
871

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.

Read only

Former Member
0 Likes
871

Hi,

Try to use this code,

Thanks

Dharmishta

Read only

Former Member
0 Likes
871

But also sometimes the variable conatins 'pdfst0000096286us16c1'.

In such cases i have to add current year to that.

Read only

Former Member
0 Likes
871

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.