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

program is not working

Former Member
0 Likes
2,203

friends, need help once again.

i have created one structre which is based on table pa0000 and pa0001. where pernr is primary key on both table. i have seen both table data and there is more then 5000 records for same key. my datasource ias based on this structre and program but when i am checking in bw it is fetch only one recortd. please check my below code and suggest me where i am worng

code -

Tables: pa0000,

pa0001,

ztest12.

Data: begin of itab_pa0000 occurs 0.

include structure ztest12.

Data : end of itab_pa0000.

Data tab type i.

*<query_head>

select * from pa0000 into corresponding fields of table itab_pa0000.

Select * from pa0001 into corresponding fields of table itab_pa0000 where pernr = itab_pa0000-pernr.

append itab_pa0000.

Loop at itab_pa0000.

move-corresponding itab_pa0000 to ztest12.

*<query_body>.

endloop.

please let me know if yopu need any more information

regards

28 REPLIES 28
Read only

suresh_datti
Active Contributor
0 Likes
2,173

put ur query outside the loop after appending the itab..


Loop at itab_pa0000.
move-corresponding itab_pa0000 to ztest12.
append ztest12.
endloop.
*<query_body>.

~Suresh

Read only

0 Likes
2,173

ztest12 is not an internal table, it is structre where in some fields are from pa0000 and pa0001 table.

Regards

Read only

0 Likes
2,173

Write the code in this way...

Tables: pa0000,

pa0001,

ztest12.

Data: begin of itab_pa0000 occurs 0.

include structure ztest12.

Data : end of itab_pa0000.

Data tab type i.

*<query_head>

select *

into corresponding fields of table itab_pa0000

from pa0000

join pa0001

on pa0000pernr = pa0001pernr.

Loop at itab_pa0000.

move-corresponding itab_pa0000 to ztest12.

*<query_body>.

endloop.

Read only

Former Member
0 Likes
2,173

Please use the below code.

Tables: pa0000,

pa0001,

ztest12.

Data: begin of itab_pa0000 occurs 0.

include structure ztest12.

Data : end of itab_pa0000.

Data tab type i.

*<query_head>

select {list of fields from pa0000 and pa0001}

into corresponding fields of table itab_pa0000

from pa0000 as a inner join pa0001 as b

on apernr = bpernr.

Loop at itab_pa0000.

move-corresponding itab_pa0000 to ztest12.

insert/update ztest112. "depending on your requirement.

*<query_body>.

endloop.

Regards

Anurag

Read only

dani_mn
Active Contributor
0 Likes
2,173

HI,

Tables: pa0000,
pa0001,
ztest12.

Data: begin of itab_pa0000 occurs 0.
include structure ztest12.
Data : end of itab_pa0000.

Data tab type i.

*<query_head>

<b>*here you fill the itab_pa0000 with values from pa0000
*its ok</b>
select * from pa0000 into corresponding fields of table 
itab_pa0000.

<b>*here you are overwritting the old values and just 
*using header value that the reason it is giving one row.
*check the bold code.</b>

Select * from pa0001 into corresponding fields of table
itab_pa0000 where pernr = <b>itab_pa0000-pernr</b>.

<b>*saving the values into another itab OR use APPENDING * option
 
Select * from pa0001 into Table itab_pa0001 
FOR ALL ENTERIES IN itab_pa0000
WHERE pernr = itab_pa0000-pernr.</b>

append itab_pa0000.
Loop at itab_pa0000.

move-corresponding itab_pa0000 to ztest12.

*<query_body>.

endloop.

Regards,

HRA

Read only

Former Member
0 Likes
2,173
Hi

  Try if this works for you. Have changed few portions of your code.

Tables: pa0000,
        pa0001,
        ztest12.

data: itab_pa0000 like ztest12 occurs 0 with header line.
data: itab_pa0001 like ztest12 occurs 0 with header line.

*<query_head>

select * from pa0000 into corresponding fields of table itab_pa0000.

Select * from pa0001 into corresponding fields of table itab_pa0001
for all entries in itab_pa0000
where pernr = itab_pa0000-pernr.

Loop at itab_pa0001.

     move-corresponding itab_pa0001 to ztest12.

*<query_body>.

endloop.


Kind Regards
Eswar
Read only

Former Member
0 Likes
2,173

Hi jain,

i have tried with this examples:

REPORT ZGRO_TESTT.

*

TABLES: MARA.

*

DATA: BEGIN OF IMARA OCCURS 0.

INCLUDE STRUCTURE MARA.

DATA: END OF IMARA.

*

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE IMARA.

*

break-point.

*

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE IMARA

where matnr = imara-matnr.

*

BREAK-POINT.

the Problem is, that the 2 select refresh the itab and find no Record, because tzhe Headerline of imara will not

be filled.

Use select ... endselect.

Regards, Dieter

Read only

0 Likes
2,173

Hellofreinds, thanks for your help. <program is working fine now but it is extractin double entries. i have seent the entry for empl no 1277 , and there are v2 entries in both table. so by default my datasource should alos fetch 2 entries but now any how it is fetch 4 entries.

is there some thing worng in my code ..? please advice.

Read only

0 Likes
2,173

clear internal table headers and try

Loop at itab_pa0001.

move-corresponding itab_pa0001 to ztest12.

<b>clear :itab_pa0001,ztest12.</b>

*<query_body>.

endloop.

Read only

0 Likes
2,173

Hi Jain,

are your sure, that in PA0000 are only one Record for 1277 or more? Test it with SE16 or SE16N.

Perhaps you have to select with the actual date?

Regards, Dieter

Read only

0 Likes
2,173

please note that there are BEGDA and ENDDA in both tables. so data should come based on time dependancy.

entries are like this in both table for empl no 1277

Table Pa0000 -

empl no begda endda

1277 01.01.1994 31.03.1998

1277 01.04.1998 31.12.9999

table pa0001

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.12.9999

so my datasource shld fetch entries in following way

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.03.1998

1277 01.04.1998 31.12.9999

but where as my datasource is fetching the entries is following way and it is wrong.

1277 01.01.1994 31.12.1996

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.12.9999

1277 01.01.1997 31.12.9999

please suggest me ...thanks in advance

regards

Read only

0 Likes
2,173


Hi

  Try this way.

Tables: pa0000,
        pa0001,
        ztest12.

data: itab_pa0000 like ztest12 occurs 0 with header line,
      itab_pa0001 like ztest12 occurs 0 with header line.

Data tab type i.

*<query_head>

select * into corresponding fields of table itab_pa0000
       from pa0000 as a
       left outer join pa0001 as b
       on b~pernr = a~pernr
       and b~begda = a~begda.
       
Loop at itab_pa0001.

move-corresponding itab_pa0001 to ztest12.

*<query_body>.

endloop.


Kind Regards
Eswar

Message was edited by: Eswar Rao Boddeti

Read only

0 Likes
2,173

Hi eswar,

Thanks for yr responce, but do it will check time depenadancy..it should check and modify the date automatically.

it should give me only 3 records by updaing the endda and begda.

thanks

Read only

0 Likes
2,173

Hi Akshay

I have changed my code now with the start date also to be considered. Check if this works.

Kind Regards

Eswar

Read only

0 Likes
2,173

it is fetching only one record

1277 01.01.1994 31.12.1996

other 2 reocrds are missing

regard

Read only

0 Likes
2,173

Hello Akshay,

If you use the code given in my replies and once you have got the data in the internal table itab.

U can use DELETE from itab comparing fields command to delete the adjacent duplicates. (Please use the sort on the fields). Hence you would have unique records in your itab.

Regards

Anurag

Read only

0 Likes
2,173

can we check the tme dependancy through perform statement..can any one please help me in below code,

regards

Read only

0 Likes
2,173

Anurag, but how time dependancy will be there..i am accpecting below data from my code...

please note that there are BEGDA and ENDDA in both tables. so data should come based on time dependancy.

entries are like this in both table for empl no 1277

Table Pa0000 -

empl no begda endda

1277 01.01.1994 31.03.1998

1277 01.04.1998 31.12.9999

table pa0001

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.12.9999

so my datasource shld fetch entries in following way

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.03.1998

1277 01.04.1998 31.12.9999

but where as my datasource is fetching the entries is following way and it is wrong.

1277 01.01.1994 31.12.1996

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.12.9999

1277 01.01.1997 31.12.9999

Read only

0 Likes
2,173
Hi Akshay

I guess this should work for you. Please try and let us know.

Tables: pa0000,
        pa0001,
        ztest12.

data: itab_pa0000 like ztest12 occurs 0 with header line,
      itab_pa0001 like ztest12 occurs 0 with header line.

Data tab type i.

*<query_head>

select * into corresponding fields of table itab_pa0000
       from pa000.
       
select * into corresponding fields of table itab_pa0001
       from pa0001.
       
loop at itab_pa0000.
    clear: itab_pa0001.
    read table itab_pa0001 with key pernr = itab_pa0000-pernr
                                    begda = itab_pa0000-begda.
    if sy-subrc eq 0.
       move-corresponding itab_pa0001 to itab_pa0000.
       modify itab_pa0000.
       delete itab_pa0001 index sy-tabix.
    endif.
endloop.
append lines of itab_pa0001 to itab_pa0000.
       
Loop at itab_pa0001.

move-corresponding itab_pa0001 to ztest12.

*<query_body>.

endloop.



Kind Regards
Eswar
Read only

0 Likes
2,173

eswar, it is fetching 0 records only.

pleaswe advice

Read only

0 Likes
2,173

Tables: pa0000,

pa0001,

ztest12.

data: itab_pa0000 like ztest12 occurs 0 with header line,

itab_pa0001 like ztest12 occurs 0 with header line,

itab_final like ztest12 occurs 0 with header line.

Data tab type i.

*<query_head>

select * into corresponding fields of table itab_pa0000

from pa000.

select * into corresponding fields of table itab_pa0001

from pa0001.

loop at itab_pa0000.

clear: itab_pa0001.

read table itab_pa0001 with key

pernr = itab_pa0000-pernr begda = itab_pa0000-begda.

if sy-subrc eq 0 and itab_pa0000-endda > itab_pa0001-endda.

move-corresponding itab_pa0001 to itab_final.

else.

move-corresponding itab_pa0000 to itab_final.

endif.

append itab_final.

endloop.

Loop at itab_final.

move-corresponding itab_final to ztest12.

*<query_body>.

endloop.

Regards

Anurag

Message was edited by: Anurag Bankley

Read only

0 Likes
2,173
Akshay

  I guess the code given by Anurag after modifications should work for your case.

  Check the same and revert back incase of problems.

Kind Regards
Eswar
Read only

0 Likes
2,173

Thanks Anurag, code is working now but ut us fetching only 2 entries as below -

1277 1.1.1994 31.12.1996

1277 1.4.1998 31.12.9999

where as it shld fetch the entries in following way

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.03.1998

1277 01.04.1998 31.12.9999

Please advice

Regards

Read only

0 Likes
2,173

Sorry missed one of your criteria..check the below now it should work

Tables: pa0000,

pa0001,

ztest12.

data: itab_pa0000 like ztest12 occurs 0 with header line,

itab_pa0001 like ztest12 occurs 0 with header line,

itab_final like ztest12 occurs 0 with header line.

Data tab type i.

*<query_head>

select * into corresponding fields of table itab_pa0000

from pa000.

select * into corresponding fields of table itab_pa0001

from pa0001.

loop at itab_pa0000.

clear: itab_pa0001.

read table itab_pa0001 with key

pernr = itab_pa0000-pernr begda = itab_pa0000-begda.

if sy-subrc eq 0.

if itab_pa0000-endda > itab_pa0001-endda.

move-corresponding itab_pa0001 to itab_final.

else.

move-corresponding itab_pa0000 to itab_final.

endif.

delete itab_pa0001 index sy-index.

endif.

append itab_final.

endloop.

loop at itab_pa0001.

move-corresponding itab_pa0001 to itab_final.

append itab_final.

endloop.

Loop at itab_final.

move-corresponding itab_final to ztest12.

*<query_body>.

endloop.

Regards

Anurag

Message was edited by: Anurag Bankley

Read only

0 Likes
2,173

Hi Anurag, i am getting short dump while fetching the data in RSA3. the short dump is due to worng statement and it is near delete statement (delete itab_pa0001 index sy-index.)

please check and let me know

regards

Read only

0 Likes
2,173

sorry use sy-tabix instead of sy-index.

Regards

Anurag

Read only

0 Likes
2,173

Anurag, luckliy this time 3 record has been extracted but second record is duplication of first record. the entries are as below,

1277 01.01.1994 31.12.1996

1277 01.01.1994 31.12.1996

1277 01.04.1997 31.12.9999

regards

Read only

0 Likes
2,173

I think the below should work...

empl no begda endda

1277 01.01.1994 31.03.1998

1277 01.04.1998 31.12.9999

table pa0001

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.12.9999

so my datasource shld fetch entries in following way

1277 01.01.1994 31.12.1996

1277 01.01.1997 31.03.1998

1277 01.04.1998 31.12.9999

-


XXX----

Tables: pa0000,

pa0001,

ztest12.

data: itab_pa0000 like ztest12 occurs 0 with header line,

itab_pa0001 like ztest12 occurs 0 with header line,

itab_final like ztest12 occurs 0 with header line.

Data tab type i.

*<query_head>

select * into corresponding fields of table itab_pa0000

from pa000.

select * into corresponding fields of table itab_pa0001

from pa0001.

loop at itab_pa0000.

clear: itab_pa0001, itab_final.

loop at itab_pa0001 where pernr = itab_pa0000-pernr

and begda = itab_pa0000-begda.

if itab_pa0000-endda > itab_pa0001-endda.

move-corresponding itab_pa0001 to itab_final.

else.

move-corresponding itab_pa0000 to itab_final.

endif.

delete itab_pa0001.

exit.

endloop.

if sy-subrc ne 0.

move-corresponding itab_pa0000 to itab_final.

endif.

append itab_final.

endloop.

loop at itab_pa0001.

move-corresponding itab_pa0001 to itab_final.

append itab_final.

endloop.

Loop at itab_final.

move-corresponding itab_final to ztest12.

*<query_body>.

endloop.

Regards

Anurag