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: 

select statement

Former Member
0 Kudos

Hi Experts,

how can we select line item from item table and on the basis of that line item we can fetch header data

or vise versa

can i have proper answer for that

thanks

Rahul

6 REPLIES 6

Sm1tje
Active Contributor
0 Kudos

in the line item there will also be a reference to the header.

Header: document 1000

item: document 100 item 10

document 100 item 20

etc.

former_member188685
Active Contributor
0 Kudos

See for any thing to select you should have some condition.

if there is no condition that means you are selecting all the records.

Now go to header table and get the Records from Header using the Item and header realtion fields in where condition

use for all entries to get the data from header using item,

Former Member
0 Kudos

Hi,

If you know the line items then you get multiple POs.

For example same line items exists in many documents like POs, SOs etc.

Select the line items from item table and for those documents (the item table also contains the document number) get the header data by passing the document number.

Reward.

Former Member
0 Kudos

You can either use INNER JOIN to select data from both header table and item table or u can select data from header table and using the staement FOR ALL ENTRIES u can selct data from item table.

For eg:

select VBAKVBELN VBAKERDAT VBAP~POSNR

into corresponding fields of table ITAB

from VBAK inner join VBAP

on VBAKVBELN eq VBAPVBELN.

OR

select vbeln from vbak

into corresponding fields of table ITAB.

select POSNR from vbap

into corresponding fields of table ITAB1

for all entries in ITAB

where vbeln eq ITAB-vbeln.

Former Member
0 Kudos

hi,

suppose <f1> is the common field between <header_table > and <item_table>..

then use this query:-

select <f1><f2> from <header_table> into <it_header_table>

where condition.

if sy-subrc = 0.

select <f1><f3> <f4>....

from <item_table> into <it_item_table> for all entries in <it_header_table>

where <f1> = <it_header_table>-<f1>.

endif.

Former Member
0 Kudos

Hi,

The question is not very much clear as u've not specified whether u r using any selction criteria for selecting the records.

U can select the line items from the header data and vice versa.

For example I'm taking EKKO(PO header data) and EKPO(PO Item data).

tables: ekko, ekpo.

data: it_ekko like table of ekko,

it_ekpo like table of ekpo.

data: wa_ekko type ekko,

wa_ekpo type ekpo.

select-options: po for ekko-ebeln.

if not it_ekko is initial.

select * from ekpo into table it_ekpo for all entries in it_ekko where ebeln = it_ekko-ebeln.

if not it_ekpo is initial.

loop at it_ekpo into wa_ekpo.

write:/ wa_ekpo-ebeln, wa_ekpo-ebelp.

endloop.

endif.

endif.

if u want select header data based on line items data just reverse the table names, internal tables and work areas in the select statement mentioned in the above example. While selecting the header data from the line items data, sort and delete the duplicate PO from the internal table which is storing line items records.

U can select the item data based on header data and vice versa based on the KEY field of the header data table.

Reward this solves ur problem.

Regards

ChandraK