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

help in code

Former Member
0 Likes
1,443

hallow

i have two tables that i wont to move the data((price) to third table itab

i wont to now how i can do that?

i give ex.

INTAB_A132[]

resrc date key

0000123456 20070101 <b>0000014834</b>

0000123456 20070601 <b> 0000014835</b>

2) intab_konp

key <b>price</b>

<b>0000014834</b> 20000.00

<b>0000014834</b> 250000.00

this is what i wont

itab

1 0000123456 <b>012007</b> <b>20000.00</b>

2 0000123456 022007 20000.00

3 0000123456 032007 20000.00

4 0000123456 042007 20000.00

5 0000123456 052007 20000.00

6 0000123456 <b>062007</b> <b>250000.00</b>

7 0000123456 072007 250000.00

8 0000123456 082007 250000.00

9 0000123456 092007 250000.00

10 0000123456 102007 250000.00

11 0000123456 112007 250000.00

12 0000123456 122007 250000.00

13 0000123456 012008 250000.00

<b>

i reward kindly</b>

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,420

hi shnya tal,

here the below code helps you.

if you hav internal tables <b>it1 with fld1, fld2, fld3</b>

<b>it2 with fld1 fld2</b>

<b>it3 with fld1, fld2, fld3</b>.

as you given in your example.

the below code will compare <b>it1-fld3 and it2-fld1</b>.

and made changes as you need and append in <b>it3.</b>

loop at It1.

loop at it2.
if it1-fld3 = it2-fld1.
  it3-fld1 = it1-fld1.
  CONCATENATE it1-fld2+4(2) it1-fld2(4) into s.
  it3-fld2 = s.
  it3-fld3 = it2-fld2.
    append it3.
  endif.
  ENDLOOP.
  ENDLOOP.

thanks and regards

Vijaykumar Reddy. S

13 REPLIES 13
Read only

Former Member
0 Likes
1,421

hi shnya tal,

here the below code helps you.

if you hav internal tables <b>it1 with fld1, fld2, fld3</b>

<b>it2 with fld1 fld2</b>

<b>it3 with fld1, fld2, fld3</b>.

as you given in your example.

the below code will compare <b>it1-fld3 and it2-fld1</b>.

and made changes as you need and append in <b>it3.</b>

loop at It1.

loop at it2.
if it1-fld3 = it2-fld1.
  it3-fld1 = it1-fld1.
  CONCATENATE it1-fld2+4(2) it1-fld2(4) into s.
  it3-fld2 = s.
  it3-fld3 = it2-fld2.
    append it3.
  endif.
  ENDLOOP.
  ENDLOOP.

thanks and regards

Vijaykumar Reddy. S

Read only

0 Likes
1,420

Hi,

You can avoid loop with in loop. Use read statment instead.

like this.

loop at itab1.

read table itab2 with key fields field1 = itab1-field3.

if sy-subrc eq 0.

CONCATENATE itab1-field2+4(2) itab1-fild2(4) into l_date.

itab3-field2 = l_date.

itab3-field3 = itab2-fld2.

append itab3.

endif.

Regards,

Niyaz

endloop.

Read only

0 Likes
1,420

hi vijaykumar reddy

i try your suggstion but its not working .

for what u do the concatnte?

regards

Read only

0 Likes
1,420

Since you want the output in format 012007 , we are concatenating

else no need to concatenate

Read only

0 Likes
1,420

hi niyaz

in my table itab i have already fields with date and i need to modify table itab with price .

thankes

Read only

0 Likes
1,420

hi,

Please see the output which you have given. its

itab

1 0000123456 012007 20000.00

2 0000123456 022007 20000.00

Note the date format, its 012007. but in the input table you have given as

0000123456 <b>20070101</b> 0000014834

Thats y we are concatenating.

Did you try my code? i hope it will be working.

Regards,

Niyaz

Read only

0 Likes
1,420

hi niyaz

i try your code and its not working.

this what i have in itab(table 3)

0000123456 012007

and i wont to add 20000.00 to the thired colman modify

and its not working.

Thankes for your time

Regards

Read only

0 Likes
1,420

Try this

types: begin of ty_itab3,

field1 type ..

field2 type ...

field3 type ...

end of ty_itab3.

data itab3 type table of ty_itab3 with header line.

loop at itab1.

read table itab2 with key fields field1 = itab1-field3.

if sy-subrc eq 0.

itab3-field1 = itab1-field1

CONCATENATE itab1-field2+4(2) itab1-fild2(4) into l_date.

itab3-field2 = l_date.

itab3-field3 = itab2-fld2.

append itab3.

endif.

endloop.

Not: Please keep a break point and watch the code.

Read only

Former Member
0 Likes
1,420

Hello Shnya,

You can write simple logic :

INTAB_A132[] -> this is one internal table

resrc date key

0000123456 20070101 0000014834

0000123456 20070601 0000014835

2) intab_konp -> this is second internal table

key price

0000014834 20000.00

0000014834 250000.00

this is what i wont

itab -> this is final internal table

1 0000123456 012007 20000.00

2 0000123456 022007 20000.00

3 0000123456 032007 20000.00

4 0000123456 042007 20000.00

5 0000123456 052007 20000.00

6 0000123456 062007 250000.00

7 0000123456 072007 250000.00

8 0000123456 082007 250000.00

9 0000123456 092007 250000.00

10 0000123456 102007 250000.00

11 0000123456 112007 250000.00

12 0000123456 122007 250000.00

13 0000123456 012008 250000.00

Logic :

loop at INTAB_A132.

read table intab_konp with key key = intab_a132-key.

if sy-subrc eq 0.

  • here move the values to itab -> this is your final internal table

itab-price = intab_konp-price.

itab-resrc = intab_a132-resrc.

itab-date = intab_a132-date.

append itab.

endif.

clear : itab,

intab_a132,

intab_konp.

endloop.

the above logic should work.

Thanks

Seshu

Read only

0 Likes
1,420

hi Seshu Maramreddy

i try it but its not working

Thankes anyay.

Regards

Read only

0 Likes
1,420

Okay ,please check the below code and i hardcoded values to internal table

REPORT ZJOINS message-id z01. .

  • Internal table intab_a132

data : begin of intab_a132 occurs 0,

resrc(10) type c,

date(8) type c,

key(10) type c,

end of intab_a132.

  • Internal table intab_konp

data : begin of intab_konp occurs 0,

key(10) type c,

price like konp-kbetr,

end of intab_konp.

  • internal table ITAB

data : begin of itab occurs 0,

resrc(10) type c,

date(8) type c,

price like konp-kbetr,

end of itab.

start-of-selection.

  • filling values to ITAB_A132

  • 1st record

intab_a132-resrc = '0000123456'.

intab_a132-date = '012007'.

intab_a132-key = '0000014834'.

append intab_a132.

clear intab_a132.

  • 2nd record

intab_a132-resrc = '0000123456'.

intab_a132-date = '022007'.

intab_a132-key = '0000014834'.

append intab_a132.

clear intab_a132.

*3rd Record

intab_a132-resrc = '0000123456'.

intab_a132-date = '032007'.

intab_a132-key = '0000014834'.

append intab_a132.

clear intab_a132.

  • 4th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '042007'.

intab_a132-key = '0000014834'.

append intab_a132.

clear intab_a132.

  • 5th Record

intab_a132-resrc = '0000123456'.

intab_a132-date = '052007'.

intab_a132-key = '0000014834'.

append intab_a132.

clear intab_a132.

  • 6th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '062007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 7th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '072007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 8th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '082007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 9th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '092007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 10th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '102007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 11th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '112007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 12th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '122007'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • 13th record

intab_a132-resrc = '0000123456'.

intab_a132-date = '012008'.

intab_a132-key = '0000014835'.

append intab_a132.

clear intab_a132.

  • Fill values to intab_konp

intab_konp-key = '0000014834'.

intab_konp-price = '20000.00'.

append intab_konp.

clear intab_konp.

intab_konp-key = '0000014835'.

intab_konp-price = '25000.00'.

append intab_konp.

clear intab_konp.

loop at intab_a132.

read table intab_konp with key key = intab_a132-key.

if sy-subrc eq 0.

itab-price = intab_konp-price.

itab-resrc = intab_a132-resrc.

itab-date = intab_a132-date.

append itab.

endif.

clear : intab_a132,

intab_konp.

endloop.

loop at itab.

write:/ itab-resrc,itab-date,itab-price.

endloop.

Thanks

Seshu

Read only

0 Likes
1,420

thankes seshu for your time

i am not in office but itry it tomarow

Best Regards

Read only

Former Member
0 Likes
1,420

Dear Shnya Tal,

It seems to me that previous codes does not capture your requirement,

that is to display active price for all period 'between' the data in A132 ,

and I think there is a miss in your requirement,

that is how come the output stops in 012008 if there is no limitation in the table ?

Herewith I assume the 012008 as your preset value from selection screen.

The code below should works, please reward as well ^_^

  • START OF PROGRAM

REPORT ZTEST002R .

DATA : Begin of INTAB_A132 occurs 3,

resrc(10) type N,

date type d,

key(10) type N,

end of intab_a132,

begin of intab_konp occurs 3,

key(10) type N,

price like vbap-netwr,

end of intab_konp ,

begin of itab occurs 0,

no type i,

resrc(10) type N,

period(6) type N,

price like vbap-netwr,

end of itab,

tmp_a132 like intab_a132 occurs 0 with header line,

tmp_period1(6) type N,

tmp_period2(6) type N,

tmp_month(2) type N,

tmp_year(4) type N,

cntr type i,

indx1 like sy-tabix,

indx2 like sy-tabix,

last type i.

  • SELECTION SCREEN

parameters : p_edate like sy-datum default '20080101'.

  • EVENTS

initialization.

intab_a132-resrc = '0000123456'.

intab_a132-date = '20070101'.

intab_a132-key = '0000014834'.

append intab_a132.

intab_a132-resrc = '0000123456'.

intab_a132-date = '20070601'.

intab_a132-key = '0000014835'.

append intab_a132.

tmp_a132[] = intab_a132[].

intab_konp-key = '0000014834'.

intab_konp-price = 200000.

append intab_konp.

intab_konp-key = '0000014835'.

intab_konp-price = 250000.

append intab_konp.

  • MAIN PROGRAM

Start-of-selection.

clear cntr.

describe table intab_a132 lines last.

loop at intab_a132.

clear : tmp_month, tmp_a132.

indx1 = sy-tabix.

indx2 = sy-tabix + 1.

tmp_month = intab_a132-date+4(2) .

tmp_year = intab_a132-date(4).

concatenate tmp_year tmp_month

into tmp_period2 .

read table tmp_a132 index indx2.

if sy-subrc = 0 or indx1 = last.

read table intab_konp with key key = intab_a132-key.

if sy-subrc = 0.

while ( tmp_period2 <= p_edate(6) ) .

if tmp_period2 >= tmp_a132-date(6)

and not tmp_a132-date is initial .

exit.

endif.

" For output purpose

cntr = cntr + 1.

concatenate tmp_month tmp_year into tmp_period1 .

itab-no = cntr.

itab-resrc = intab_a132-resrc.

itab-price = intab_konp-price.

itab-period = tmp_period1.

append itab.

" For period comparison purpose

if tmp_month <= 11.

tmp_month = tmp_month + 1.

else.

tmp_month = 1.

tmp_year = tmp_year + 1.

endif.

concatenate tmp_year tmp_month into tmp_period2 .

endwhile.

endif. " intab_konp

endif. " tmp_a132

endloop. " intab_a132

write:/1(3) 'no', (10) 'resrc', (6) 'period', (10) 'price'.

loop at itab.

write:/1(3) itab-no, (10) itab-resrc,

(6) itab-period, (10) itab-price.

endloop.

  • END of PROGRAM

Output :

no resrc period price

1 0000123456 012007 200000,00

2 0000123456 022007 200000,00

3 0000123456 032007 200000,00

4 0000123456 042007 200000,00

5 0000123456 052007 200000,00

6 0000123456 062007 250000,00

7 0000123456 072007 250000,00

8 0000123456 082007 250000,00

9 0000123456 092007 250000,00

10 0000123456 102007 250000,00

11 0000123456 112007 250000,00

12 0000123456 122007 250000,00

13 0000123456 012008 250000,00

Regards,

TS WINEDYA

Message was edited by:

TUWUHSIH WINEDYA