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

Time format issue (Urgent please)

Former Member
0 Likes
2,322

hello experts,

I am pretty new to ABAP. could someone please help me to sort the following mentioned issue.

I have time char (length 6) which is assigned to a data source. Some of the time data in the fields of a flat file are empty. So the system is not accepting empty fields and moreover the time its brining is in

hh:mm: (6 char) format. The actual format is hh:mm:ss

I guess we have to use concatenation to sort this out. Can someone share the code

I used the following code to eliminate blanks

if ( TRAN_STRUCTURE-/bic/zooh_time is initial ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '000000' ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '' ).

clear RESULT.

else.

RESULT = TRAN_STRUCTURE-/bic/zooh_time.

endif.

All inputs are much appreciated.

Thanks in advance,

Harish Mulaka

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,055

if you have the time in a sy-uzeit type of field,

you can use the write statement to move it to a 8 character field.

example

data: v_time(8).

write sy-uzeit to v_time.

or

data: v_uzeit type sy-uzeit.

write v_uzeit to v_time.

or

concatenate v_uzeit+0(2) ':'

v_uzeit+2(2) ':'

v_uzeit+4(2)

into v_time.

In you case:

if ( TRAN_STRUCTURE-/bic/zooh_time is initial ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '000000' ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '' ).

clear RESULT.

else.

concatenate TRAN_STRUCTURE-/bic/zooh_time+0(2) ':'

TRAN_STRUCTURE-/bic/zooh_time+2(2) ':'

TRAN_STRUCTURE-/bic/zooh_time+4(2)

into RESULT.

endif.

Regards,

Ravi

if you have the time in a sy-uzeit type of field,

you can use the write statement to move it to a 8 character field.

example

data: v_time(8).

write sy-uzeit to v_time.

or

data: v_uzeit type sy-uzeit.

write v_uzeit to v_time.

or

concatenate v_uzeit+0(2) ':'

v_uzeit+2(2) ':'

v_uzeit+4(2)

into v_time.

In you case:

if ( TRAN_STRUCTURE-/bic/zooh_time is initial ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '000000' ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '' ).

clear RESULT.

else.

concatenate TRAN_STRUCTURE-/bic/zooh_time+0(2) ':'

TRAN_STRUCTURE-/bic/zooh_time+2(2) ':'

TRAN_STRUCTURE-/bic/zooh_time+4(2)

into RESULT.

endif.

Regards,

Ravi

11 REPLIES 11
Read only

Former Member
0 Likes
2,056

if you have the time in a sy-uzeit type of field,

you can use the write statement to move it to a 8 character field.

example

data: v_time(8).

write sy-uzeit to v_time.

or

data: v_uzeit type sy-uzeit.

write v_uzeit to v_time.

or

concatenate v_uzeit+0(2) ':'

v_uzeit+2(2) ':'

v_uzeit+4(2)

into v_time.

In you case:

if ( TRAN_STRUCTURE-/bic/zooh_time is initial ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '000000' ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '' ).

clear RESULT.

else.

concatenate TRAN_STRUCTURE-/bic/zooh_time+0(2) ':'

TRAN_STRUCTURE-/bic/zooh_time+2(2) ':'

TRAN_STRUCTURE-/bic/zooh_time+4(2)

into RESULT.

endif.

Regards,

Ravi

Read only

Former Member
0 Likes
2,055

Hi,

first take the data in char of lenght 6.

Data : lv_data type char6,
       lv_len  type i,
       lv_time type t.


lv_data = source_data.

lv_len = strlen(lv_data).

case lv_len
  when 0.
*----------Dont do any thing Lv_time ...will have 000000 by default.
  when 4.
    concatenate lv_data '00' into lv_time.
  when 6.
    lv_time = lv_data.
  when 5.
*--------that is hh:mm
    concatenate lv_data+0(2) lv_data+3(2) '00' into lv_time.
endcase.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,055

You can format the time as SAP needs it(XX:XX:XX) and then covert it to internal format (XXXXXX) Then check it if initial.



report zrich_0002 .

data: in_time(6) type c value '09:29:'.
data: fm_time(8) type c.
data: out_time type sy-uzeit.

concatenate in_time '00' into fm_time.

call function 'CONVERT_TIME_INPUT'
  exporting
    input                           = fm_time
*   PLAUSIBILITY_CHECK              = 'X'
 importing
    output                          = out_time
* EXCEPTIONS
*   PLAUSIBILITY_CHECK_FAILED       = 1
*   WRONG_FORMAT_IN_INPUT           = 2
*   OTHERS                          = 3
          .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.


if out_time is initial.


endif.


Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,055

Hello Ravikanth, Rich and Manoj,

Thank you very much for your swift responces.

Ravikanth,

If I am trying your code its bringing time in this 21::0: format.

Rich,

If I am using your code, The load is success but bringing only 00:00:00 to all fields.

Any other inputs guys

Thanks in advance.

Regards,

Harish

Read only

0 Likes
2,055

Post your code.

Regards

Rich Heilman

Read only

0 Likes
2,055

Hello Rich,

I am using the following code.

if ( TRAN_STRUCTURE-/bic/zooh_time is initial ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '000000' ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '' ).

clear RESULT.

else.

data: in_time(6) type c value '09:29:'.

data: fm_time(8) type c.

data: out_time type sy-uzeit.

concatenate in_time '00' into fm_time.

call function 'CONVERT_TIME_INPUT'

exporting

input = fm_time

  • PLAUSIBILITY_CHECK = 'X'

importing

output = out_time

  • EXCEPTIONS

  • PLAUSIBILITY_CHECK_FAILED = 1

  • WRONG_FORMAT_IN_INPUT = 2

  • OTHERS = 3

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

if out_time is initial.

Regards,

Harish

Read only

0 Likes
2,055

What exactly is not working. You may have to adjust my example code a little and use your correct field names.

Regards,

Rich Heilman

Read only

0 Likes
2,055

Hello Rich,

Actually I am using the code with proper fields names. but the load is failing with following error.

Record 1 :Value '21:00: ' of characteristic 0TIME is not a number with 000006 spaces <b></b>

Below is the code which I am using.

data: /bic/zooh_time(6) type c value '09:29:'.

data: fm_time(8) type c.

data: out_time type sy-uzeit.

concatenate /bic/zooh_time '00' into fm_time.

call function 'CONVERT_TIME_INPUT'

exporting

input = fm_time

  • PLAUSIBILITY_CHECK = 'X'

importing

output = out_time

  • EXCEPTIONS

  • PLAUSIBILITY_CHECK_FAILED = 1

  • WRONG_FORMAT_IN_INPUT = 2

  • OTHERS = 3

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

if out_time is initial.

endif.

Any other hints please.

Thanks and Regards,

Harish

Read only

0 Likes
2,055

When does this error occur. Put a break point after the function call and see what the value of out_time is. This is the value that you will want to use.

Regards,

Rich Heilman

Read only

0 Likes
2,055

Thank you,

I will try debugging it and will get back to you.

Cheers

Harish

Read only

0 Likes
2,055

Hello Ravi,

Thank you very much for your help. I got the it fixed with the help of your code.

Rich, Thank you very much for your valuable time to suggest me.

CODE:

if ( TRAN_STRUCTURE-/bic/zooh_time is initial ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '000000' ) or

( TRAN_STRUCTURE-/bic/zooh_time eq '' ).

clear RESULT.

else.

concatenate TRAN_STRUCTURE-/bic/zooh_time+0(2)

TRAN_STRUCTURE-/bic/zooh_time+2(2)

TRAN_STRUCTURE-/bic/zooh_time+4(2)

into RESULT.

endif.

Points are awareded accordingly.

Thanks and Regards,

Harish Mulaka