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

regarding this query

Former Member
0 Likes
872

hi experts,

i have a simple query ,earlier i did the same thing but somehow i forgot to do the same thing.

inside the loop i have year filed like this.

2008 010108

2008 010208

2008 030308

2009 010109

2009 020209

2009 010309

for year 2008 i have three records and for 2009 i have three records in a internal table on which i have put loop.

what i want that after reading all three records for 2008 the record will be appended into another table into single row likewise for year 2009.

means at the end of 2008 after reading all three records for year 2008 the record will be appended into another table in a single row the same thing need to be happened with the year 2009.

is it possible with control statement i.e at end,at new etc.

plz help me.........

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
846

Hi , try this code...

yearfield should be 1st field in ur int. table.

DATA flag.

LOOP AT itab.

AT END OF yearfield.

flag = 'X'.

ENDAT.

IF flag EQ 'X'.

APPEND to 2nd int table.

CLEAR flag.

ENDIF.

ENDLOOP.

hi experts,

i have a simple query ,earlier i did the same thing but somehow i forgot to do the same thing.

inside the loop i have year filed like this.

2008 010108

2008 010208

2008 030308

2009 010109

2009 020209

2009 010309

for year 2008 i have three records and for 2009 i have three records in a internal table on which i have put loop.

what i want that after reading all three records for 2008 the record will be appended into another table into single row likewise for year 2009.

means at the end of 2008 after reading all three records for year 2008 the record will be appended into another table in a single row the same thing need to be happened with the year 2009.

is it possible with control statement i.e at end,at new etc.

plz help me.........

6 REPLIES 6
Read only

Former Member
0 Likes
846

Hi,

This is an exanple program.

TYPES :

BEGIN OF flt,

carrid(2) TYPE c,

connid(4) TYPE n,

fldate LIKE sy-datum,

fltyp(3) TYPE c,

max(4) TYPE n,

occ(4) TYPE n,

END OF flt.

DATA :

itab TYPE STANDARD TABLE OF flt

INITIAL SIZE 6,

wa TYPE flt.

CLEAR wa.

wa-carrid = 'LH'.

wa-connid = '400'.

wa-fldate = '19950228'.

wa-fltyp = 'A319'.

wa-max = '300'.

wa-occ = '100'.

APPEND wa TO itab.

CLEAR wa.

wa-carrid = 'LH'.

wa-connid = '400'.

wa-fldate = '19960228'.

wa-fltyp = 'A319'.

wa-max = '300'.

wa-occ = '100'.

APPEND wa TO itab.

CLEAR wa.

wa-carrid = 'LH'.

wa-connid = '400'.

wa-fldate = '20010228'.

wa-fltyp = 'A319'.

wa-max = '300'.

wa-occ = '100'.

APPEND wa TO itab.

CLEAR wa.

wa-carrid = 'LH'.

wa-connid = '400'.

wa-fldate = '20011201'.

wa-fltyp = 'A319'.

wa-max = '150'.

wa-occ = '100'.

APPEND wa TO itab.

&--


Horizontal Lines--
&

ULINE AT 5(132).

SKIP TO LINE 6.

ULINE AT 5(132).

&--


Left Corner Vertical Lines--
&

SKIP TO LINE 4.

POSITION 5.

WRITE '|'.

POSITION 136.

WRITE '|'.

&--


Right Corner Vertical Lines--
&

SKIP TO LINE 5.

POSITION 5.

WRITE : '|'.

POSITION 136.

WRITE '|'.

&----


Inbetween -
&

SKIP TO LINE 4.

POSITION 28.

WRITE '|'.

POSITION 50.

WRITE '|'.

POSITION 72.

WRITE '|'.

POSITION 94.

WRITE '|'.

POSITION 116.

WRITE '|'.

SKIP TO LINE 5.

POSITION 7.

WRITE : 'Airline Carrier ID'.

POSITION 28.

WRITE '|'.

POSITION 29.

WRITE : 'Flight Connection ID'.

POSITION 50.

WRITE '|'.

POSITION 56 .

WRITE : 'Flight Date'.

POSITION 72.

WRITE '|'.

POSITION 77.

WRITE : ' Plane Type '.

POSITION 94.

WRITE '|'.

POSITION 98.

WRITE :'Maximum Capacity'.

POSITION 116.

WRITE '|'.

POSITION 119.

WRITE : 'Occupied Seats'.

DATA :

w_rtbound TYPE i VALUE 5,

w_newlina TYPE i,

w_newlinb TYPE i,

w_lines TYPE i.

DESCRIBE TABLE itab LINES w_lines.

SKIP TO LINE 8.

ULINE AT 5(132).

LOOP AT itab INTO wa.

w_newlina = sy-linno + 1.

SKIP TO LINE w_newlina.

POSITION w_rtbound.

WRITE : '|'.

WRITE : wa-carrid.

POSITION 136.

WRITE :'|'.

ADD 1 TO w_newlina.

SKIP TO LINE w_newlina.

POSITION 5.

WRITE : '|'.

ULINE AT 5(132).

ENDLOOP.

Regards,

N.Neelima

Read only

viquar_iqbal
Active Contributor
0 Likes
846

HI

You can use at new with offsets w_date+0(4). If the year changes then append it to different table

Thanks

Viquar Iqbal

Read only

agnihotro_sinha2
Active Contributor
0 Likes
846

hi,

yes its possible with control stamnt AT END OF year-field.

till the end is reached concatenate the values to a variable m push these values to a single row of another table inside the control statmnt.

regards,

ags

Read only

Former Member
0 Likes
846

Hi Rajat ,

Here s logic for your problem .

In your code you control break statements like at the end of 2008 you want it to append an internal table .

So use

at end year .

append your table to respective internal table

endat .

Hope it helps!

Much Regards ,

Amuktha .

Read only

Former Member
0 Likes
847

Hi , try this code...

yearfield should be 1st field in ur int. table.

DATA flag.

LOOP AT itab.

AT END OF yearfield.

flag = 'X'.

ENDAT.

IF flag EQ 'X'.

APPEND to 2nd int table.

CLEAR flag.

ENDIF.

ENDLOOP.

Read only

Former Member
0 Likes
846

hi Rajat,

if ur requirement is to populate 2008 records and 2009 records in diff tables in single rows.

The following code would help.


TYPES:
  BEGIN OF type_s_year,
    fld1 TYPE i,
    fld2(6) TYPE c,
    END OF type_s_year.

DATA fs_yr TYPE type_s_year." work area

DATA t_yr LIKE TABLE OF fs_yr.                              " table1
DATA t_tab1 TYPE string OCCURS 0 WITH HEADER LINE.          " table2
DATA t_tab3 TYPE string OCCURS 0 WITH HEADER LINE.          " table3

DATA: w_fld1 TYPE string,
      w_fld2 TYPE string.

*defining a macro*
DEFINE m_year.
  clear fs_yr.
  fs_yr-fld1 = &1.
  fs_yr-fld2 = &2.
  append fs_yr to t_yr.
END-OF-DEFINITION.

*populating table*
m_year '2008' '010108'.
m_year '2008' '010208'.
m_year '2008' '030308'.
m_year '2009' '010109'.
m_year '2009' '020209'.
m_year '2009' '010309'.

LOOP AT t_yr INTO fs_yr.
  IF fs_yr-fld1 = '2008'.
    w_fld1 = fs_yr-fld1.
    w_fld2 = fs_yr-fld2.
    CONCATENATE w_fld1 w_fld2 t_tab1 INTO t_tab1 SEPARATED BY space.
    CONDENSE t_tab1.
  ENDIF.

  IF fs_yr-fld1 = '2009'.
    w_fld1 = fs_yr-fld1.
    w_fld2 = fs_yr-fld2.
    CONCATENATE w_fld1 w_fld2 t_tab3 INTO t_tab3 separated by space.
    CONDENSE t_tab3.
   ENDIF.
ENDLOOP.
APPEND t_tab1.
APPEND t_tab3.

LOOP AT t_tab1.
  WRITE:/ t_tab1.
ENDLOOP.


LOOP AT t_tab3.
  WRITE:/ t_tab3.
ENDLOOP.

Regards,

Mdi.Deeba Najam.