Application Development 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: 

i am not able to fecth data using this statement

Former Member
0 Kudos

Hi All,

Iam getting problem when i was using select queiry based on vbak,vbap and konv tables.

Error is i am not able to get all condition types but i am getting only first record

Example...

number of the document condition which is KNUMV

condition item number which is KPOSN

condition type which is kshcl

knumv kposn kshcl

00000002 000100 zpro

00000002 000100 zdsc

00000002 000100 zima

00000002 000100 zpak

but iam getting only first fecord not getting all the records

like

000000002 000100 zpro

code is ..........

*select Sales Document: Header Data and Item Data from vbak and vbap

select avbeln aerdat aernam aauart avkorg avtweg aspart akunnr avkbur avkgrp alifsk afaksk aaugru aknumv

bposnr bmatnr bwerks blgort bkwmeng bpstyv babgru bbedae blprio bvstel bntgew bbrgew

bvolum bfaksp bktgrm btaxm1 babfor bkalsm_k bmatkl bkondm bgsber bprctr

into corresponding fields of table it_vbak

from vbak as a inner join vbap as b on avbeln = bvbeln

where a~vbeln in lr_vbeln and

a~vkorg in lr_vkorg and

a~vtweg in lr_vtweg and

a~spart in lr_spart and

b~werks in lr_plant and

a~auart in lr_auart and

a~erdat in lr_erdat.

  • Move all the data to it_sorder

IF sy-subrc = 0.

LOOP AT it_vbak.

MOVE-CORRESPONDING it_vbak TO it_sorder.

APPEND it_sorder.

CLEAR it_sorder.

ENDLOOP.

ENDIF.

*select Conditions from konv

IF NOT it_sorder[] IS INITIAL.

SELECT knumv kposn STUNR KAPPL ZAEHK kschl kbetr KAWRT

INTO CORRESPONDING FIELDS OF TABLE it_konv

FROM konv FOR ALL ENTRIES IN it_sorder

WHERE knumv = it_sorder-knumv and

kposn = it_sorder-posnr.

ENDIF.

  • Read Conditions from it_konv move it to it_sorder

sort it_konv by knumv .

sort it_sorder by knumv .

LOOP AT it_sorder.

READ TABLE it_konv WITH KEY knumv = it_sorder-knumv

kposn = it_sorder-POSNr binary search.

IF sy-subrc = 0.

it_sorder-Kposn = it_konv-kposn.

it_sorder-STUNR = it_konv-STUNR.

it_sorder-KAPPL = it_konv-KAPPL.

it_sorder-ZAEHK = it_konv-ZAEHK.

it_sorder-kschl = it_konv-kschl.

it_sorder-kbetr = it_konv-kbetr.

MODIFY it_sorder.

CLEAR it_sorder.

ENDIF.

CLEAR it_konv.

ENDLOOP.

pls can you help me

thanks

mars

5 REPLIES 5

former_member181995
Active Contributor
0 Kudos

MT,

check yourself in debug mode whether these values have any entry their corresponding tables?

or are you expecting us to run this query and respond you?

Amit.

0 Kudos

Hi

yes I execpting to run this queiry by you

but iam getting data from it_konv

but it is not moving to it_soreder

thanks

mars

Former Member
0 Kudos

Hi mars

The code looks OK to me. There are quite a few steps though. I would be inclined to stick in a breakpoint at the start of the code and walk through it. That way you can narrow down where the problem is eg is the first Select returning the right data, is it_sorder getting populated correctly, is the select from KONV working as expected etc

Once you've isolated where the problem is you should be halfway there!

Andy

former_member70391
Contributor
0 Kudos

Hi,

In MODIFY it_sorder. try to use Modify it_sorder index sy-tabix. It should work. I did try to write this program.

Hope it helps.

Thanks & Regards,

Nagaraj Kalbavi

Former Member
0 Kudos

I think the problem is here:

sort it_konv by knumv .

sort it_sorder by knumv .

LOOP AT it_sorder.

READ TABLE it_konv WITH KEY knumv = it_sorder-knumv kposn = it_sorder-POSNr binary search.

There will be mulitple lines in it_konv with this key so it will only return the first. You need a second loop round it_konv eg:

LOOP AT it_conv WHERE knumv = it_sorder-knumv and kposn = it_sorder-POSNr.
* do stuff here
ENDLOOP.

Try that and see if it helps...

Andy