cancel
Showing results for 
Search instead for 
Did you mean: 

Convert time 24 hour format to 12 hour format coming from non SAP source

Former Member
0 Kudos

hello all,

I have an oracle based source system and i have created DB Connect datasources for that in SAP BW.

I have a time field which is coming in 24hour format and i would want to convert that into 12 hour format.

issues faced -- when time in source is 12:08:19 AM, in BW it is converted into 240819 which is not plausible.

please suggest how to correct this error?  is there a functional module for the same?

Thanks!

Tanu

Accepted Solutions (1)

Accepted Solutions (1)

former_member185132
Active Contributor
0 Kudos

Looks like it is the opposite here: the incoming data is in 12 hr format (i.e. with AM/PM) and BW requires it to be in 24-hr.

If the incoming data comes exactly in the format "12:08:19 AM", then in the DataSource, model it as a 11-char field, not as a Date field.

Map it to your date field in the transformation and use the below code in the field routine to convert.


DATA: ls_input type c length 11, hh type n length 2, mm type n length 2, ss type n length 2 .

ls_input = source_fields-<<the input field name>>.

hh = ls_input(2).

mm = ls_input+3(2).

ss = ls_input+6(2).

if hh = 12.

     hh = 00.

endif.

if ls_input+9(2) = 'PM'.

     hh = hh + 12.

endif.

concatenate hh mm ss into RESULT.

Regards,

Suhas

Former Member
0 Kudos

hello Suhas,

thanks for your reply...

May be i did not write the question correct...:(

1. in the non sap views, i get data in 24hour format

2. hence, in the db connect datasources in sap bw, i get data in 24hour format

so in this case, when the data is 12:08:19 AM,  i get it as 240819 in the views/datasource

So, need to change it to 12 hour format in SAP BW to correct this error.

former_member185132
Active Contributor
0 Kudos

So if you get "240819" in the datasource itself, then in the transformation routine write this:


DATA: ls_input type c length 11, hh type n length 2, mmss type n length 6.

ls_input = source_fields-<<the input field name>>.

hh = ls_input(2).

mmss = ls_input+2(4).

if hh = 24.

     hh = 00.

endif.

concatenate hh mmss into RESULT.

Former Member
0 Kudos

thank you so much Suhas.. did not strike me before...

however, was just trying to find any standard FM for the same

Former Member
0 Kudos

hi Suhas,

a small change

mmss type n length 4.

if we take 6, it gives wrong result.

Thanks again!

Answers (0)