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

Read Table BSEG

Former Member
0 Likes
1,847

I want to filter the data from BSEG table for a given period. Since, there is no document date in BSEG, I have done the following.

First : I have taken the data from BKPF table for a given period into an internal table IT_BKPF.

Then, Looping at IT_BKPF, i am reading the table BSEG for BELNR field. But the system gives the following error.

" Field BELNR is unkown. It is in neither in one of the specified tables not defined by "DATA statment. "DATA" statement"

I have declared the tables BSEG, BKPF.

My code is given below for your reference.

LOOP AT IT_BKPF.

READ TABLE BSEG WITH KEY BELNR = IT_BKPF-BELNR.

IF SY-SUBRC = 0.

MOVE : BSEG-BUKRS TO IT_GROSS-BUKRS,

BSEG-BELNR TO IT_GROSS-BELNR,

BSEG-DMBTR TO IT_GROSS-DMBTR,

BSEG-SHKZG TO IT_GROSS-SHKZG.

APPEND IT_GROSS.

ENDIF.

ENDLOOP.

Pls let me know what is the error and how to solve the same.

Regards,

A S VINCENT

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,379

select * from bseg into table it_bseg

for all entries of it_bkpf

where belnr = it_bkpf-belnr

.

LOOP AT IT_BSEG.

MOVE : IT_BSEG-BUKRS TO IT_GROSS-BUKRS,

IT_BSEG-BELNR TO IT_GROSS-BELNR,

IT_BSEG-DMBTR TO IT_GROSS-DMBTR,

IT_BSEG-SHKZG TO IT_GROSS-SHKZG.

APPEND IT_GROSS.

ENDIF.

ENDLOOP.

5 REPLIES 5
Read only

former_member186741
Active Contributor
0 Likes
1,379

your immediate problem is that you are trying to do a read of an internal table BSEG rather than doing a select from the database table BSEG.

Read only

Former Member
0 Likes
1,380

select * from bseg into table it_bseg

for all entries of it_bkpf

where belnr = it_bkpf-belnr

.

LOOP AT IT_BSEG.

MOVE : IT_BSEG-BUKRS TO IT_GROSS-BUKRS,

IT_BSEG-BELNR TO IT_GROSS-BELNR,

IT_BSEG-DMBTR TO IT_GROSS-DMBTR,

IT_BSEG-SHKZG TO IT_GROSS-SHKZG.

APPEND IT_GROSS.

ENDIF.

ENDLOOP.

Read only

former_member186741
Active Contributor
0 Likes
1,379

you would probably be better off doing something like:

select BSEGBUKRS BSEGBELNR BSEGDMBTR BSEGSHKZG inTO corresponding fields of table IT_GROSS

from bseg

for all entries in it_bkpf

where bseg~belnr = it_bkpf-belnr.

Read only

Former Member
0 Likes
1,379

Hi Vincent ,

try the below code , the other thing that you have to do before running the below code is .

1.) did u define internal table properly

2.) did you do "select * from bkpf into it_bkpf

check this and run the below code , i think this should sove your problem

Do reward points if found useful.

-


select * from bseg into table it_gross

for all entries in it_bkpf

where belnr = it_bkpf

-


Read only

Former Member
0 Likes
1,379

Hello Vincent,

Problem here, from what i saw is, BSEG is a cluster table in the database.So, it has to be read using SELECT query.

Try using the follwing code:

SELECT BUKRS BELNR DMBTR SHKZG FROM BSEG

INTO TABLE IT_GROSS FOR ALL ENTRIES IN IT_BKPF

WHERE BELNR = IT_BKPF-BELNR.

check for sy-subrc.

Hope this would be of use to you,

Please revert for further help.

Regards,

Partha