2005 Jul 11 5:07 PM
hi folks,
I need your help here. I have to populate the internal table 'accitab'.
The 'accitab' has field structure like this.
zdateproductcode
zadnumber
zdescription
zadsize
zrate
zsubtotal
zamount
The first four fields of data has been pulled into 'BDATA' ITAB by a different query while the last three field data has been pulled into CDATA' ITAB.
question 1 is how to merge the data from two different queries and taking into a single record into 'accitab'.
Here The code goes like this....
select vavtyp jhamotbreite_s jhamotHOEHE_S jhagaavm_nr jhagaber_termin from zzjhtfp
INNER JOIN jhamot ON zzjhtfpaubel = jhamotavm_nr
Inner join jhaga on jhamotavm_nr = jhagaavm_nr
INTO corresponding fields of table BDATA WHERE
zzjhtfp~inserent = p_advnum and
jhaga~fakdatum in r_datum.
if sy-subrc = 0.
select * into corresponding fields of table ijha
from jhak
inner join jhaga
on jhakavm_nr = jhagaavm_nr
where jhaga~inserent = p_advnum and
jhaga~fakdatum in r_datum.
select kposn kschl krech kawrt kbetr kwert
from konv into table cdata for all entries in ijha
where konv~knumv = ijha-knumv.
fetching the data for the first three fields.
LOOP AT BDATA into wa.
write:wa-ber_termin to zdate ddmmyy.
write: zdate to zdate1 dd/mm/yy.
write: wa-avm_nr to zadnumber.
write: wa-breite_s to zwidth.
write: wa-HOEHE_S to zheight.
write: wa-vavtyp.
concatenate zdate1 wa-vavtyp into wa1-zdateproductcode separated by space.
concatenate zwidth zheight into wa1-zadsize separated by 'X'.
w_accitab-zdateproductcode = wa1-zdateproductcode.
w_accitab-zadnumber = wa-avm_nr.
w_accitab-zadsize = wa1-zadsize.
fetching the data for the last three fields
loop at cdata into wac.
case wac-kschl.
when 'ZRAT'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zsubtotal.
endif.
when 'ZSED'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zsubtotal.
endif.
when 'ZAC%'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zsubtotal.
endif.
when 'ZBET'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zamount.
endif.
when others.
continue.
endcase.
if sy-subrc = 0.
append accitab.
append w_accitab to accitab.
write: 20 accitab-zrate, 40 accitab-zsubtotal, 60 accitab-zamount.
endif.
clear accitab-zamount.
clear accitab.
clear w_accitab.
endloop.
endloop.
endif.
My second question is when the data is being checked for the condition type 'ZBET' it has to fetch the zamount data append the record to 'accitab' exit from the loop because it completes one set of record and then has to fetch the data from 'bdata' itab.
How to do that?
thanks in advance
Santhosh
hi folks,
I need your help here. I have to populate the internal table 'accitab'.
The 'accitab' has field structure like this.
zdateproductcode
zadnumber
zdescription
zadsize
zrate
zsubtotal
zamount
The first four fields of data has been pulled into 'BDATA' ITAB by a different query while the last three field data has been pulled into CDATA' ITAB.
question 1 is how to merge the data from two different queries and taking into a single record into 'accitab'.
Here The code goes like this....
select vavtyp jhamotbreite_s jhamotHOEHE_S jhagaavm_nr jhagaber_termin from zzjhtfp
INNER JOIN jhamot ON zzjhtfpaubel = jhamotavm_nr
Inner join jhaga on jhamotavm_nr = jhagaavm_nr
INTO corresponding fields of table BDATA WHERE
zzjhtfp~inserent = p_advnum and
jhaga~fakdatum in r_datum.
if sy-subrc = 0.
select * into corresponding fields of table ijha
from jhak
inner join jhaga
on jhakavm_nr = jhagaavm_nr
where jhaga~inserent = p_advnum and
jhaga~fakdatum in r_datum.
select kposn kschl krech kawrt kbetr kwert
from konv into table cdata for all entries in ijha
where konv~knumv = ijha-knumv.
fetching the data for the first three fields.
LOOP AT BDATA into wa.
write:wa-ber_termin to zdate ddmmyy.
write: zdate to zdate1 dd/mm/yy.
write: wa-avm_nr to zadnumber.
write: wa-breite_s to zwidth.
write: wa-HOEHE_S to zheight.
write: wa-vavtyp.
concatenate zdate1 wa-vavtyp into wa1-zdateproductcode separated by space.
concatenate zwidth zheight into wa1-zadsize separated by 'X'.
w_accitab-zdateproductcode = wa1-zdateproductcode.
w_accitab-zadnumber = wa-avm_nr.
w_accitab-zadsize = wa1-zadsize.
fetching the data for the last three fields
loop at cdata into wac.
case wac-kschl.
when 'ZRAT'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zsubtotal.
endif.
when 'ZSED'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zsubtotal.
endif.
when 'ZAC%'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zsubtotal.
endif.
when 'ZBET'.
if wac-kbetr = ' ' AND wac-kwert = ' '.
continue.
else.
MOVE wac-kbetr to w_accitab-zrate.
MOVE wac-kwert to w_accitab-zamount.
endif.
when others.
continue.
endcase.
if sy-subrc = 0.
append accitab.
append w_accitab to accitab.
write: 20 accitab-zrate, 40 accitab-zsubtotal, 60 accitab-zamount.
endif.
clear accitab-zamount.
clear accitab.
clear w_accitab.
endloop.
endloop.
endif.
My second question is when the data is being checked for the condition type 'ZBET' it has to fetch the zamount data append the record to 'accitab' exit from the loop because it completes one set of record and then has to fetch the data from 'bdata' itab.
How to do that?
thanks in advance
Santhosh
2005 Jul 11 7:42 PM
How to transfer the control from the inner loop to the outer loop in case of nested loops.
My problem is I need to transfer the control to the outer loop within the case and endcase statement. while checking the last condition type 'ZBET'
Any leads or suggesstions would really helpful?
Thanks
Santhosh
2005 Jul 11 8:30 PM
I don't know if this is all you are looking for on that last question, but the EXIT statement will kick you out of the inner loop back out to the outer loop. You just need to put that into the case statement, wherever appropriate.
As you have it, the CONTINUE statement will keep you in the inner loop - it just goes to the next record in that inner loop.
Message was edited by: John Carlson
2005 Jul 11 9:02 PM
Do you mean that if wac-kschl = 'ZBET' you want to look at the record you are currently on in WA, or do you want to look at other records in WA?
Rob
2005 Jul 11 9:19 PM
I tried using ' exit' it goes out of the inner loop but reads the same data from the outer loop. the same set of records is getting pulled.
The process has to first fetch the record using the outer loop and then enters the inner loop checks for each case condition after checking for 'ZBET' condition pulls the data, from the inner loop again,
The processing of the code works like this, for every record of data pulled from the outer loop there at least two matching records in the inner loop.
so all the matching records in the inner loop has to be picked up for that record of the outer loop and then come out of the inner loop and fetch the next record in the outer loop
I used the code 'append' for BDATA(internal table for the outer loop) and cdata for the iner loop.
but it is not working.
I do not know how to interlink the loops in this way.
I hope you understood the process here.
santhosh
2005 Jul 11 9:50 PM
This isn't clean, but I think it should work
data: next_rec like sy-tabix,
indexb like sy-tabix,
indexc like sy-tabix.
loop at bdata into wa.
indexb = sy-tabix.
* do some stuff
loop at cdata into wac.
indexc = sy-tabix.
* do some more stuff
if wac-kschl = 'ZBET'.
next_rec = indexb + 1.
read table bdata index next_rec.
* do some more stuff
sy-tabix = indexc.
endif.
endloop.
sy-tabix = indexb.
endloop.
I haven't compiled this so check it. The main thing to do is to keep track of where you are in the tables, determine the index of the next record, read it, reset the index. (I think I've set and reset more times than necessary.)
Also, I'm not sure that this is very efficient. Nested loops will read every record in the second table twice for every pass through the first one in the first table. A better approach is to use indexed reads if possible.
Rob
2005 Jul 12 6:58 AM
Hi,
If the tables BDATA and CDATA is having atleast one common field,then you can merge them.Otherwise,you cannot.
Loop at bdata into w_bdata.
move-corresponding w_bdata to w_output.
*Loop cdata if it is having multiple records for each *BDATA record.Otherwise,read cdata
loop cdata into w_cdata where field = w_bdata-field.
move-corresponding w_cdata to w_output.
append w_output to i_output.
endloop.
endloop.
Hope it helps.
2005 Jul 12 10:46 PM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |