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

Connect two tables

Former Member
0 Likes
2,388

Hi Experts,

I am new to ABAP. The dump shows that the mistake in the select statement, I checked few codes, I think it is right but still giving dump of dbif_rsql_invalid_rsql. Please guide me where I am lacking.

The requirement is that I need to get tcode field from bkpf table so I have connected it to bsak. Is the connection wrong?

select bukrs

          lifnr

          budat

          wrbtr

          belnr

          shkzg

          zuonr

          umskz

          sgtxt

          gjahr

     from bsak

     into table it_bsak

     where bukrs in s_bukrs and lifnr in s_lifnr and budat in s_date.

if not it_bsak is INITIAL.

select bukrs belnr tcode

   from bkpf

   INTO table it_bkpf

   FOR ALL ENTRIES IN it_bsak

   where bukrs = s_bukrs and belnr = it_bsak-belnr.

endif.

Regards

Mani

Hi Experts,

I am new to ABAP. The dump shows that the mistake in the select statement, I checked few codes, I think it is right but still giving dump of dbif_rsql_invalid_rsql. Please guide me where I am lacking.

The requirement is that I need to get tcode field from bkpf table so I have connected it to bsak. Is the connection wrong?

select bukrs

          lifnr

          budat

          wrbtr

          belnr

          shkzg

          zuonr

          umskz

          sgtxt

          gjahr

     from bsak

     into table it_bsak

     where bukrs in s_bukrs and lifnr in s_lifnr and budat in s_date.

if not it_bsak is INITIAL.

select bukrs belnr tcode

   from bkpf

   INTO table it_bkpf

   FOR ALL ENTRIES IN it_bsak

   where bukrs = s_bukrs and belnr = it_bsak-belnr.

endif.

Regards

Mani

15 REPLIES 15
Read only

FredericGirod
Active Contributor
0 Likes
2,355

Hi Mani,

in the dump, trans ST22, SAP put an arrow where the program dump. What is this line

maybe your table IT_BSAK didn't have the same number of columns ...  try to replace : INTO TABLE IT_BSAK by  INTO CORRESPONDING FIELDS OF TABLE IT_BSAK

regards

Fred

Read only

Former Member
0 Likes
2,355

Please, post your DUMP report. Probably your query is resulting in too much records.

Dump is occurring at the first or the second select statement?

The WHERE clause of the BKPF selection is wrong on the BUKRS field. Change the '=' to 'IN' and test it again.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,355

You wrote "bukrs = s_bukrs" (so type mismatch btween a field and a table of range) where you should have written "bukrs = it_bsak-bukrs", also you forgot the last key of BKPF : "and gjahr = it_bask-gjahr".

Regards,

Raymond

Read only

Former Member
0 Likes
2,355

Hi,

the mismatch is in this code:

if not it_bsak is INITIAL.

select bukrs belnr tcode

   from bkpf

   INTO table it_bkpf

   FOR ALL ENTRIES IN it_bsak

   where bukrs = s_bukrs and belnr = it_bsak-belnr.

endif.

You try with this code:

if not it_bsak[] is INITIAL.

select bukrs belnr tcode

   from bkpf

   INTO table it_bkpf

   FOR ALL ENTRIES IN it_bsak

   where bukrs IN s_bukrs

      and belnr = it_bsak-belnr

      and gjahr = it_bsak-gjahr.

endif.

Regards

Ivan

Read only

Former Member
0 Likes
2,355

Hi,

I appreciate your replies. Please check the following screenshot:

Please do let me know if any other screenshot is required?

Regards

Mani

Read only

Former Member
0 Likes
2,355

Hi Mani,

After corrections as suggested by the experts above, if still it doesn't solve, please check the target locations (it_bsak/it_bkpf). I recently faced this error. If the dump is coming in the first query then check the structure of it_bsak and it the dump is coming in the second query then check structure of it_bkpf.

Please check the order of the fields in the structure with the select query and the data types of fields with the fields in the select query. Can you show us the structures and and the error analysis in the dump?

Regards

Purnand

Read only

former_member209120
Active Contributor
0 Likes
2,355

Hi Mani,

Correct like this

select bukrs

          lifnr

          budat

          wrbtr

          belnr

          shkzg

          zuonr

          umskz

          sgtxt

          gjahr

     from bsak

     into table it_bsak

     where bukrs in s_bukrs and lifnr in s_lifnr and budat in s_date.

if not it_bsak is INITIAL.

select bukrs belnr tcode

   from bkpf

   INTO table it_bkpf

   FOR ALL ENTRIES IN it_bsak

   where bukrs = s_bukrs

     where bukrs in s_bukrs

    and belnr = it_bsak-belnr.

endif.

Read only

sivaganesh_krishnan
Contributor
0 Likes
2,355

HI mani,

You have to change the '=' sign with IN in the second select statement. and also you have to add extra where claues in that statement , as the table bkpf also has the primary key gjahr so you have to add it.

                      SELECT      bukrs   belnr   tcode

                          FROM      bseg
                INTO TABLE     it_bkpf

FOR ALL ENTRIES IN     it_bsak 
                        WHERE     bukrs IN  s_bukrsAND
                                 

                                         belnr EQ it_bkpf-belnr AND

                                         gjahr EQ it_bkpf-gjahr.

Regards,

Sivaganesh

Read only

Former Member
0 Likes
2,355

Hi mani,

Replace : INTO TABLE IT_BSAK by  INTO CORRESPONDING FIELDS OF TABLE IT_BSAK in the first select query

and sort the table it_bsak

replace in second select query

INTO table it_bkpf  by INTO CORRESPONDING FIELDS OF TABLE it_bkpf.

write like below

select bukrs

          lifnr

          budat

          wrbtr

          belnr

          shkzg

          zuonr

          umskz

          sgtxt

          gjahr

     from bsak

     into corresponing fields of table it_bsak

     where bukrs in s_bukrs and lifnr in s_lifnr and budat in s_date.

if not it_bsak is INITIAL.

sort it_bsak by bukrs.

select bukrs belnr tcode

   from bkpf

   INTO corresponing fields of table it_bkpf

   FOR ALL ENTRIES IN it_bsak

   where bukrs  IN s_bukrs and belnr = it_bsak-belnr and gjahr  = it_bsak-gjhar.

endif.


Read only

Former Member
0 Likes
2,355

Thank you experts. I had written belnr type belnr instead of belnr type belnr_d. But there were one more mistake that I had written bukrs = s_bukrs instead of bukrs in s_bukrs.

I would like to thank all the experts above for taking time to read, understand and answer my query. I am very happy. This is a great website.

Cheers

Mani

Read only

0 Likes
2,355

Also :

  • Add gjahr to your type ty_bkpf as well as in the SELECT FROM BKPF statement, and sort criteria (SORT statement or definition TYPE SORTED TABLE) to get the correct document header.
  • Read BKPF with it_bsak-bukrs and not use the IN s_bukrs. (even if result will be correct if READ TABLE use a correct bukrs, you may read unecessary records in BKPF)

Regards,

Raymond

Read only

0 Likes
2,355

Hi Raymond,

Added both the points. I am sure the select query is more strong now.

Thanking you

Mani

Read only

Former Member
0 Likes
2,355

hi,

check the structure of the target field and also check the order of selected fields....

sharmistha

Read only

Former Member
0 Likes
2,355

This message was moderated.

Read only

Former Member
0 Likes
2,355

Hi Mani,

Please check carefully before posting thread in SCN.  Since SAP is having 45 years of history almost all the solutions are available for the Queries.

You missed the basic thing that instead of using IN Operator you used = for S_BUKRS. so be cautious.

Welcome to SCN.

Thanks

Pavan.N