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: 

Changing date during loop

former_member2492
Active Participant
0 Kudos
1,320

Hello,

I am trying to change a date into the desired format 12.12.2012.

LOOP AT DATATAB INTO LS_DATATAB .
 CONCATENATE LS_DATATAB-P0016_EINDT+6(2) LS_DATATAB-P0016_EINDT+4(2) LS_DATATAB-P0016_EINDT(4) INTO DATA(LV_DATE3) SEPARATED BY '.'.
 LS_DATATAB-P0016_EINDT = LV_DATE3.

However now the date is short by 2 chars so its only 12.12.20

Can anybody help me?

Thank You in Advance!

1 ACCEPTED SOLUTION

ArthurParisius
Contributor
1,089

How did you define LS_DATATAB-P0016_EINDT, you might need to change its type.

10 REPLIES 10

ArthurParisius
Contributor
1,090

How did you define LS_DATATAB-P0016_EINDT, you might need to change its type.

0 Kudos
1,089
P0016_EINDT TYPE D

If I declare it char15 for ex or string it dumps and says the field is not the same format

0 Kudos
1,089

Maybe also try defining the LV_DATE3 outside the loop at the same type you define EINDT.

0 Kudos
1,089

that's the way I declare it 😉 the two type D,then I change it to char it dumps

0 Kudos
1,089

I need a way to convert date column to char, a function module or smth

0 Kudos
1,089

Strange I did a little test with your type of coding and I got no issues. My simple code is here below.

Types: BEGIN OF ty_itab,
        datum type c LENGTH 10,
      end of ty_itab.

data: itab TYPE TABLE OF ty_itab,
      l_itab TYPE ty_itab.

l_itab-datum = sy-datum.
append l_itab TO itab.

loop at itab INTO l_itab.
  CONCATENATE l_itab-datum+6(2) l_itab-datum+4(2) l_itab-datum(4) INTO DATA(LV_DATE2) SEPARATED BY '.'.
  l_itab-datum = lv_date2.
  write: / l_itab-datum.
  modify itab FROM l_itab.
endloop.

0 Kudos
1,089
Nope,Its necessary that the LS_DATATAB-P0016_EINDT needs to be type D and during the loop,I need to change it to append it to another table!

0 Kudos
1,089

testing this code gave me the correct results. so the question is, is ls_datatab the type of datatab or of your second table?

Types: BEGIN OF ty_itab,
        datum type d,
      end of ty_itab.

data: itab TYPE TABLE OF ty_itab,
      l_itab TYPE ty_itab.

Types: BEGIN OF ty_itab2,
        datum type c LENGTH 10,
      end of ty_itab2.

data: itab2 TYPE TABLE OF ty_itab2,
      l_itab2 TYPE ty_itab2.

l_itab-datum = sy-datum.
append l_itab TO itab.

loop at itab INTO l_itab.
  CONCATENATE l_itab-datum+6(2) l_itab-datum+4(2) l_itab-datum(4) INTO DATA(LV_DATE2) SEPARATED BY '.'.
  l_itab2-datum = lv_date2.
  APPEND l_itab2 to itab2.
endloop.

0 Kudos
1,089

okay this works only for one field what about for 2 or three other fields that have nothing to do with it

0 Kudos
1,089

Shouldn't be an issue as long as you fill the workarea for the second table inside the loop. Try it out.