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: 

READ TABLE is not working

former_member206394
Active Participant
0 Kudos

READ TABLE .......... INTO ............ is not executing in one of my programs.



LOOP AT i_bseg INTO struct_bseg.

  READ TABLE I_BKPF INTO STRUCT_BKPF WITH KEY
                        BUKRS = STRUCT_BSEG-BUKRS
                        BELNR = STRUCT_BSEG-BELNR
                        GJAHR = STRUCT_BSEG-GJAHR.

IF SY-SUBRC = 0.
STRUCT_BKPF_BSEG-LIFNR = STRUCT_BSEG-LIFNR.
STRUCT_BKPF_BSEG-MENGE = STRUCT_BSEG-MENGE.
STRUCT_BKPF_BSEG-MEINS = STRUCT_BSEG-MEINS.
STRUCT_BKPF_BSEG-DMBTR = STRUCT_BSEG-DMBTR.
STRUCT_BKPF_BSEG-MATNR = STRUCT_BSEG-MATNR.
STRUCT_BKPF_BSEG-EBELN = STRUCT_BSEG-EBELN.
STRUCT_BKPF_BSEG-BUKRS = STRUCT_BKPF-BUKRS.
STRUCT_BKPF_BSEG-BELNR = STRUCT_BKPF-BELNR.
STRUCT_BKPF_BSEG-BUDAT = STRUCT_BKPF-BUDAT.
STRUCT_BKPF_BSEG-XBLNR = STRUCT_BKPF-XBLNR.
STRUCT_BKPF_BSEG-WAERS = STRUCT_BKPF-WAERS.
 APPEND STRUCT_BKPF_BSEG TO I_BKPF_BSEG.
ENDLOOP.

but the same statement is working fine in some other program. What may be the reason?

8 REPLIES 8

Former Member
0 Kudos

Hi,

are you getting sy-subrc 4?

if yes, check

1) if the I_BKPF & STRUCT_BKPF have same structures.

2)I_bkpf is not initial.

3)STRUCT_bseg has same values as in struct_bkpf.

What error are you getting?

deepak_dhamat
Active Contributor
0 Kudos

hi,

use below code

LOOP AT i_bseg INTO struct_bseg.
 
  READ TABLE I_BKPF   WITH KEY  BUKRS = STRUCT_BSEG-BUKRS
                                                         BELNR = STRUCT_BSEG-BELNR
                                                        GJAHR = STRUCT_BSEG-GJAHR.
 
IF SY-SUBRC = 0.

STRUCT_BKPF_BSEG-LIFNR = STRUCT_BSEG-LIFNR.
STRUCT_BKPF_BSEG-MENGE = STRUCT_BSEG-MENGE.
STRUCT_BKPF_BSEG-MEINS = STRUCT_BSEG-MEINS.
STRUCT_BKPF_BSEG-DMBTR = STRUCT_BSEG-DMBTR.
STRUCT_BKPF_BSEG-MATNR = STRUCT_BSEG-MATNR.
STRUCT_BKPF_BSEG-EBELN = STRUCT_BSEG-EBELN.
STRUCT_BKPF_BSEG-BUKRS = I_BKPF-BUKRS.
STRUCT_BKPF_BSEG-BELNR = I_BKPF-BELNR.
STRUCT_BKPF_BSEG-BUDAT = I_BKPF-BUDAT.
STRUCT_BKPF_BSEG-XBLNR = I_BKPF-XBLNR.
STRUCT_BKPF_BSEG-WAERS = I_BKPF-WAERS.
 APPEND STRUCT_BKPF_BSEG TO I_BKPF_BSEG.
ENDLOOP.

REGARDS

dEEPAK.

matt
Active Contributor
0 Kudos

Your code is syntactically incorrect - you don't close the IF clause with an ENDIF. The only other reasons that you'd not get anything read are

1. You have nothing in I_BKPF which matches STRUCT_BSEG-BUKRS/BELNR/GJAHR

2. There's nothing in I_BSEG.

Statements in ABAP don't just "not work". They do exactly what they're supposed to do. Have you debugged your code to check the contents of I_BKPF and I_BSEG?

former_member300258
Participant
0 Kudos

hi..

First check the internal table "i_bseg" and "i_bkpf" has values.

If both have values, check whether the values in both are same..that you can find it with the SY-SUBRC value..if sy-subrc = 0. the it should read the value definitely..

Former Member
0 Kudos

Hi,

Please include the SORT I_BKPF statement before the the LOOP.

SORT I_BKPF BY BUKRS

BELNR

GJAHR.

Please try to implement this logic and let me know in case of any.

Regards,

SRinivas

Former Member
0 Kudos

1.ENDIF Statement is missing IF sy-subrc = 0. within the LOOP AT., ENDLOOp.

2.Checks the INTO strcture(STRUCT_BKPF) with I_BKPF.

Pls, Let me know if its right or wrong

Former Member
0 Kudos

Check the values in the internal table I_BKPF and see if it matches with the read criteria.

former_member206394
Active Participant
0 Kudos

finally its working...........thanks a lot for replies