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

picking up data from internal table

Former Member
0 Likes
377

Hi Group,

for eg: below is the data in the internal table:

ZOFFRCONT DOC_TYPE ZOFFRCONTD ZPRO_EFF_DATE ZODEACQE ZPROFILE_ID

6000000449 DECO01 test1 Description 18.02.2010 100,000 P0050

6000000449 DECO01 test1 Description 03.03.2010 15,000 P0050

6000000449 DECO01 test1 Description 03.03.2011 20,000 P0050

6000000450 DECO01 test2 Description 25.02.2010 130,000 P0051

6000000450 DECO01 test2 Description 15.03.2010 145,000 P0051

6000000450 DECO01 test2 Description 07.07.2011 120,000 P0051

I want to pick the data where for field ZOFFRCONT , if the ZPRO_EFF_DATE field has current year the latest record has to be picked (i.e 6000000449, 03.03.2010 ), and if its for future years the latest record has to be picked that is ( 6000000449, 03.03.2011) in this case.

Hence over all in the above internal table, I should get only these below records:

6000000449 DECO01 test1 Description 03.03.2010 15,000 P0050

6000000449 DECO01 test1 Description 03.03.2011 20,000 P0050

6000000450 DECO01 test2 Description 15.03.2010 145,000 P0051

6000000450 DECO01 test2 Description 07.07.2011 120,000 P0051

please could you help me on this.

Many Thanks,

Jagan.

2 REPLIES 2
Read only

Former Member
0 Likes
346

Hi Jagan,

Use the following code :

SORT <Internal Table> By ZOFFRCONT DOC_TYPE ZPRO_EFF_DATE.

DELETE ADJACENT DUPLICATES FROM <Internal Table> COMPARING ZOFFRCONT DOC_TYPE.

Regards,

Chandravadan

Edited by: Chandravadan Jaiswal on Mar 9, 2010 3:43 PM

Read only

Former Member
0 Likes
346

Hi,

Use below logic.Here i m considering table with only two fields ,for simplicity ,you can use your own internal table with all the fields.

TYPES : BEGIN OF t_type,

ZOFFRCONT(20) TYPE c,

ZPRO_EFF_DATE(20) TYPE c,

END OF t_type.

DATA : i_type TYPE STANDARD TABLE OF t_type,

wa_type LIKE LINE OF i_type,

*Declare another internal table same structure with same structure.

i_type1 TYPE STANDARD TABLE OF t_type,

wa_type1 LIKE LINE OF i_type1,

l_year(4) TYPE c,

l_temp_year(4) TYPE c,

l_month(2) TYPE c,

l_temp_month(4) TYPE c,

l_date(2) TYPE c.

wa_type-ZOFFRCONT = '6000000449'.

wa_type-ZPRO_EFF_DATE = '18.02.2010'.

APPEND wa_type TO i_type.

wa_type-ZOFFRCONT = '6000000449'.

wa_type-ZPRO_EFF_DATE = '03.03.2010'.

APPEND wa_type TO i_type.

wa_type-ZOFFRCONT = '6000000449'.

wa_type-ZPRO_EFF_DATE = '03.03.2011'.

APPEND wa_type TO i_type.

wa_type-ZOFFRCONT = '6000000450'.

wa_type-ZPRO_EFF_DATE = '25.02.2010'.

APPEND wa_type TO i_type.

wa_type-ZOFFRCONT = '6000000450'.

wa_type-ZPRO_EFF_DATE = '15.03.2010'.

APPEND wa_type TO i_type.

wa_type-ZOFFRCONT = '6000000450'.

wa_type-ZPRO_EFF_DATE = '07.07.2011'.

APPEND wa_type TO i_type.

*Take current year and month into temporory variables and year and month from an internal tabel into another variable and compare it.

LOOP AT i_type INTO wa_type.

l_year = sy-datum(4).

l_temp_year = wa_type-ZPRO_EFF_DATE+6(4).

l_month = sy-datum+4(2).

l_temp_month = wa_type-ZPRO_EFF_DATE+3(2).

IF l_temp_year GE l_year AND l_temp_month GE l_month.

wa_type1-ZOFFRCONT = wa_type-ZOFFRCONT.

wa_type1-ZPRO_EFF_DATE = wa_type-ZPRO_EFF_DATE.

APPEND wa_type1 TO i_type1.

ENDIF.

ENDLOOP.

Use this code .it is working.

Hope this helps.

Tejaswini Khante