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

Split and reformat single record into multiple records

Former Member
0 Likes
521

Hi ,

I need to split 1 record in to 2 records with 1 new field(event)

I have one internal table in this format

No country stdate enddate

1 us 12/01/2006 10/07/2007

i need to reformat this record like ;

NO country event pldate acdate

1 us ga 12/01/2006 12/01/2006

1 us es 10/07/2007 10/07/2007

Can any one resolve this issue?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
484

Hi,

check this example..

DATA: ITAB_RESULT LIKE ITAB OCCURS 0 WITH HEADER LINE.

    • Assuming the ITAB is having the values

LOOP AT ITAB.

MOVE ITAB TO ITAB_RESULT.

ITAB_RESULT-ENDDATE = ITAB_RESULT-STDATE.

APPEND ITAB_RESULT.

ITAB_RESULT-STDATE = ITAB-ENDDATE.

APPEND ITAB_RESULT.

ENDLOOP.

Thanks,

Naren

Hi ,

I need to split 1 record in to 2 records with 1 new field(event)

I have one internal table in this format

No country stdate enddate

1 us 12/01/2006 10/07/2007

i need to reformat this record like ;

NO country event pldate acdate

1 us ga 12/01/2006 12/01/2006

1 us es 10/07/2007 10/07/2007

Can any one resolve this issue?

2 REPLIES 2
Read only

Former Member
0 Likes
485

Hi,

check this example..

DATA: ITAB_RESULT LIKE ITAB OCCURS 0 WITH HEADER LINE.

    • Assuming the ITAB is having the values

LOOP AT ITAB.

MOVE ITAB TO ITAB_RESULT.

ITAB_RESULT-ENDDATE = ITAB_RESULT-STDATE.

APPEND ITAB_RESULT.

ITAB_RESULT-STDATE = ITAB-ENDDATE.

APPEND ITAB_RESULT.

ENDLOOP.

Thanks,

Naren

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
484

Check the example.



report zrich_0001 .

data: begin of itab occurs 0,
      no type i,
      country(3) type c,
      stdate  type sy-datum,
      enddate type sy-datum,
      end of itab.

data: begin of itab2 occurs 0,
      no type i,
      country(3) type c,
      event(2) type c,
      stdate  type sy-datum,
      enddate type sy-datum,
      end of itab2.


itab-no = 1.
itab-country = 'US'.
itab-stdate = '20061201'.
itab-enddate = '20071007'.
append itab.


loop at itab.

  clear itab2.
  move-corresponding itab to itab2.
  itab2-event = 'GA'.
  itab2-enddate = itab-stdate.
  append itab2.

  clear itab2.
  move-corresponding itab to itab2.
  itab2-event = 'ES'.
  itab2-stdate = itab-enddate.
  append itab2.

endloop.


loop at itab2.
  write:/ itab2-no, itab2-country, itab2-event,
          itab2-stdate, itab2-enddate.
endloop.

Regards,

Rich Heilman