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

Splitting one field into 2 other fields- problems

Former Member
0 Likes
3,444

Hi all,

I am having a problem in BW. Now I know this is an ABAP forum, but this is ABAP related, its just that it is located within BW. There will be some BW terms in my question, but the code is what I am having an issue on.

Ok, I am trying to put data from an external data into 2 fields of an ODS. The field that it is coming from has a data type CHAR 19. Where it is going is into data type DATE 8 and data type TIMS 6.

That is the problem. The data in the field in the external database is formatted this way: dd/mm/yyyy hh:mm

I need to put it into a date field that is formatted like this: yyyy/mm/dd

and a time field that looks like this: hh:mm:ss

I have successfully done this with the SPLIT operator, but a problem that I encounter is that when the data is in an external database, it counts the "/" as a character. Another problem is that it includes the "/" into the data transfer. And the final problem is that if there is a data in the external database with a month of 1-9 it has one less character length than does a date with a month of 10-12 because it does not add the zero to the single month dates....

I have moved away from the SPLIT operator and have used the following:


parameters:
        p_test(19) lower case.
data:   w_test(19)              type n,
        w_length(8) type n,
        w_hours type d.

w_test = p_test.

clear w_length.
  shift w_test by 6 places left circular.
do 10 times.
  if w_test(1) ca '0123456789'.
    add +1 to w_length.
    endif.
enddo.
  w_hours = w_test(w_length).
  shift w_hours by 3 places left circular.

write: / w_test.
write: / w_hours.

It works, but I still have the problem of the length of the date....is there a way around this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,474

Hi Do following changes..

data:

lv_time type string,

lv_date type string,

lv_year type numc4,

lv_month type numc2,

lv_day type numc2,

lv_hour type numc2,

lv_min type numc2,

lv_sec type numc2.

split input at ' ' into lv_date lv_time.

<b>split lv_date at '/' into lv_day lv_month lv_year.

concatenate lv_day lv_month lv_year into date.</b>

split lv_time at ':' into lv_hour lv_min lv_sec.

concatenate lv_hour lv_min lv_sec into time.

Understand it and then Try to modify it according to ur requirement...

Hope ur problem is solved now..

<b>Reward points if useful...</b>

Thanks & Regards

ilesh 24x7

Hi all,

I am having a problem in BW. Now I know this is an ABAP forum, but this is ABAP related, its just that it is located within BW. There will be some BW terms in my question, but the code is what I am having an issue on.

Ok, I am trying to put data from an external data into 2 fields of an ODS. The field that it is coming from has a data type CHAR 19. Where it is going is into data type DATE 8 and data type TIMS 6.

That is the problem. The data in the field in the external database is formatted this way: dd/mm/yyyy hh:mm

I need to put it into a date field that is formatted like this: yyyy/mm/dd

and a time field that looks like this: hh:mm:ss

I have successfully done this with the SPLIT operator, but a problem that I encounter is that when the data is in an external database, it counts the "/" as a character. Another problem is that it includes the "/" into the data transfer. And the final problem is that if there is a data in the external database with a month of 1-9 it has one less character length than does a date with a month of 10-12 because it does not add the zero to the single month dates....

I have moved away from the SPLIT operator and have used the following:


parameters:
        p_test(19) lower case.
data:   w_test(19)              type n,
        w_length(8) type n,
        w_hours type d.

w_test = p_test.

clear w_length.
  shift w_test by 6 places left circular.
do 10 times.
  if w_test(1) ca '0123456789'.
    add +1 to w_length.
    endif.
enddo.
  w_hours = w_test(w_length).
  shift w_hours by 3 places left circular.

write: / w_test.
write: / w_hours.

It works, but I still have the problem of the length of the date....is there a way around this?

10 REPLIES 10
Read only

Former Member
0 Likes
2,474

Hi,

Its kind of confusing.

Can you just tell me what is input and what is the expected output?

or give an example.

Regards,

Ravi

Read only

0 Likes
2,474

sorry bout the confusion...

K, Input is in quotes to read easier: "5/25/2007 13:25:"

Desired Output field 1: "mm/dd/yyyy"

Desired output field 2: This is already done.

BTW, I did make a mistake in my above post stating that I wanted it to be yyyy/mm/dd...

Read only

0 Likes
2,474

hi headlice

data:
  lv_time type string,
  lv_date type string,
  lv_year type numc4,
  lv_month type numc2,
  lv_day type numc2,
  lv_hour type numc2,
  lv_min type numc2,
  lv_sec type numc2.

split input at ' ' into lv_date lv_time.
split lv_date at '/' into lv_year lv_month lv_day.
concatenate lv_year lv_month lv_dy into date.

split lv_time at ':' into lv_hour lv_min lv_sec.
concatenate lv_hour lv_min lv_sec into time.

Regards,

Clemens

Read only

0 Likes
2,474

Hi Clemens,

It looks like your answer would work however I am going from a field with data (19) Type C to data (8) Type date.

It thinks that the info that it is getting is in this format: yyyymmdd instead of the format that it is in: mmddyyyy

So the output that I am getting is yy/ /mmdd

Read only

0 Likes
2,474

Actually, now that I think about it- the ODS is counting out length 8 and converting it to date BEFORE we are even splitting anything so that is why I am getting what I am.

Should I be coding this in the start routine of the ODS?

Read only

matt
Active Contributor
0 Likes
2,474

>Should I be coding this in the start routine of the ODS?

If I understand the scenario correctly, then no.

For conversions like this, you have to do it in the transfer rules, not the start routine of the ODS. The transfer rules are the place to convert the external format into the internal format.

matt

Read only

Former Member
0 Likes
2,475

Hi Do following changes..

data:

lv_time type string,

lv_date type string,

lv_year type numc4,

lv_month type numc2,

lv_day type numc2,

lv_hour type numc2,

lv_min type numc2,

lv_sec type numc2.

split input at ' ' into lv_date lv_time.

<b>split lv_date at '/' into lv_day lv_month lv_year.

concatenate lv_day lv_month lv_year into date.</b>

split lv_time at ':' into lv_hour lv_min lv_sec.

concatenate lv_hour lv_min lv_sec into time.

Understand it and then Try to modify it according to ur requirement...

Hope ur problem is solved now..

<b>Reward points if useful...</b>

Thanks & Regards

ilesh 24x7

Read only

0 Likes
2,473

Ok ilesh, I gave you 2 points but this answer was already given above.

I am working on the transfer of data between 2 different data types and how to get the answer I want.

Read only

0 Likes
2,473

Hi headlice,

I can't definitely answer the question on the spot (at start toutine of ODS) of the conversion because I'm not too familar with BW. But I think it's correct.

Sorry I confused the formatting but I think that change you can do yourself (or with ilesh's help).

Technicvally, an ABAP date or time field is a numerical character field. That means if you have character data as NUMC type (only digits) you can put it into the field directly.

The fields I just named date and time in my code can be the target fields of your ODS.

Regards,

Clemens

Read only

Former Member
0 Likes
2,473

Hi Headlice,

it seems that you r a beginner in ABAP. So I would like to suggest you to go from the basic. And then you will learn it perfectly... And ya I did some modifications in that code which i wrote in previous reply as well..

Go through below link..

For learning <b>ABAP data types

</b>

http://venus.imp.mx/hilario/Libros/TeachYrslfAbap4/ch07.htm

it will really help you a lot...

and for <b>Conversion of data type</b>..

See the <b>DATA conversion</b> topic of below link..

http://venus.imp.mx/hilario/Libros/TeachYrslfAbap4/ch09.htm#AssignmentStatements

Hope it will solve ur doubts...

<b>Reward points if it is helpul</b>

Thanks & Regards

ilesh 24x7