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

How to use same Data Type and Length for two fields

Former Member
0 Likes
5,193

How to use same data type and length for two fields when using 'FOR ALL ENTRIES IN' in a select statement? For instance the select queries are :

SELECT bukrs gjahr belnr lifnr budat bldat zlspr dmbtr waers shkzg

FROM bsik

INTO TABLE it_bsik

WHERE bukrs = p_bukrs

AND lifnr IN s_lifnr.

IF it_bsik IS NOT INITIAL.

SELECT belnr gjahr awkey awtyp

FROM bkpf

INTO TABLE it_bkpf

FOR ALL ENTRIES IN it_bsik

WHERE belnr = it_bsik-belnr

AND gjahr = it_bsik-gjahr.

IF it_bkpf IS NOT INITIAL.

SELECT belnr gjahr lifnr xblnr

FROM rbkp

INTO TABLE it_rbkp

FOR ALL ENTRIES IN it_bkpf

WHERE belnr = it_bkpf-awkey+0(10)

AND gjahr = it_bkpf-awkey+10(4).

ENDIF.

ENDIF.

Here it gives an error in the 3rd select query that 'When you use the addition "FOR ALL ENTRIES IN itab", the fields "GJAHR" and "IT_BKPF2-AWKEY+10(4)" must have the same type and the same length.'

Kindly clarify.

How to use same data type and length for two fields when using 'FOR ALL ENTRIES IN' in a select statement? For instance the select queries are :

SELECT bukrs gjahr belnr lifnr budat bldat zlspr dmbtr waers shkzg

FROM bsik

INTO TABLE it_bsik

WHERE bukrs = p_bukrs

AND lifnr IN s_lifnr.

IF it_bsik IS NOT INITIAL.

SELECT belnr gjahr awkey awtyp

FROM bkpf

INTO TABLE it_bkpf

FOR ALL ENTRIES IN it_bsik

WHERE belnr = it_bsik-belnr

AND gjahr = it_bsik-gjahr.

IF it_bkpf IS NOT INITIAL.

SELECT belnr gjahr lifnr xblnr

FROM rbkp

INTO TABLE it_rbkp

FOR ALL ENTRIES IN it_bkpf

WHERE belnr = it_bkpf-awkey+0(10)

AND gjahr = it_bkpf-awkey+10(4).

ENDIF.

ENDIF.

Here it gives an error in the 3rd select query that 'When you use the addition "FOR ALL ENTRIES IN itab", the fields "GJAHR" and "IT_BKPF2-AWKEY+10(4)" must have the same type and the same length.'

Kindly clarify.

9 REPLIES 9
Read only

Former Member
0 Likes
2,457

Hi

first you need to check if you have declared table IT_BKPF2.

I believe you have fetched the data in IT_BKPF, there is no table IT_BKPF2 and you are not doing any selection in this table.

According to error the type and length of GJAHR and AWKEY should be same.

check the type of GJAHR and AWKEY.

Or you can change the type while declaring the internal table.

thanks

Lalit Gupta.

Read only

Former Member
0 Likes
2,457

it_bkpf-awkey+0(10)

it_bkpf-awkey+10(4).

1.in it_bkpf filed make provision for two fields with same data type as belnr and gjahr .

2.populate this new fields with appropriate string manipulations.

3.refer to the internal table with direct datatype

as

WHERE belnr = it_bkpf-belnr

AND gjahr = it_bkpf-gjahr.

ENDIF.

ENDIF.

Read only

Former Member
0 Likes
2,457

Hi,

Yeah i've made the change in the table BKPF for the field GJAHR as:

LOOP AT it_bkpf INTO wa_bkpf.

wa_bkpf2-belnr = wa_bkpf-belnr.

wa_bkpf2-awkey = wa_bkpf-awkey.

wa_bkpf2-awtyp = wa_bkpf-awtyp.

wa_bkpf2-gjahr = wa_bkpf-gjahr.

APPEND wa_bkpf2 to it_bkpf2.

ENDLOOP.

taking GJAHR field in the table BKPF2 as character type with length 20. But it is further required to select that field from RBKP table. So even if i write

SELECT belnr gjahr lifnr xblnr

FROM rbkp

INTO TABLE it_rbkp

FOR ALL ENTRIES IN it_bkpf2

WHERE belnr = it_bkpf2-awkey+0(10)

AND gjahr = it_bkpf2-awkey+10(4).

it gives the same error. Kindly explain how to resolve it.

Read only

0 Likes
2,457

Hi Saurabh,

If you want to use FOR ALL ENTRIES, the data types must be matched in the where condition. You ask ur Functional consultant for some other fields for GJAHR and BELNR instead of AWKEY, otherwise use LOOP and ENDLOOP, instead of for all entries.

Hope this helps.

Regards,

Chandu.

Edited by: chandra sekhar narra on Mar 9, 2011 8:57 AM

Read only

0 Likes
2,457

Hi Saurabh,

Please see the example code that I have developed for you. It will help you solve the problem.

REPORT ZTEST_3 .

tables : BKPF.

data : begin of it_bkpf occurs 1,
         belnr type RE_BELNR,
         awkey type awkey,
         awtyp type awtyp,
         gjahr type GJAHR,
       end of it_bkpf.

data : begin of it_bkpf1 occurs 1,
         belnr type RE_BELNR,
         awkey type gjahr,              " change the data type
         awtyp type awtyp,
         gjahr type GJAHR,
       end of it_bkpf1.

data : begin of it_rbkp occurs 1,
         belnr type BELNR_D,
         gjahr type gjahr,
         lifnr type LIFRE,
         xblnr type XBLNR,
       end of it_rbkp.

select belnr
       awkey
       awtyp
       gjahr
       from bkpf
       into table it_bkpf
       where BUKRS = 'TELH'.

loop at it_bkpf.
it_bkpf1-belnr = it_bkpf-belnr.
it_bkpf1-awkey = it_bkpf-awkey+10(4).           "Here only append the required length.
it_bkpf1-awtyp = it_bkpf-awtyp.
it_bkpf1-gjahr = it_bkpf-gjahr.
append it_bkpf1.
clear it_bkpf1.
endloop.

select  belnr
        gjahr
        lifnr
        xblnr
        from RBKP
        into table it_rbkp
        for all entries in it_bkpf1
        where belnr = it_bkpf1-belnr

This is just an example. Change the fields according to your requirement.

Regards

Abhii

Edited by: Abhii on Mar 9, 2011 9:08 AM

Read only

0 Likes
2,457

Hi saurabh,

Please try the below code

table bkpf2 only contains two fields belnr and gjahr.

LOOP AT it_bkpf INTO wa_bkpf.

wa_bkpf2-belnr = wa_bkpf-wa_bkpf-awkey+0(10)..

wa_bkpf2-gjahr = wa_bkpf-awkey+10(4).

APPEND wa_bkpf2 to it_bkpf2.

ENDLOOP.

SELECT belnr gjahr lifnr xblnr

FROM rbkp

INTO TABLE it_rbkp

FOR ALL ENTRIES IN it_bkpf2

WHERE belnr = it_bkpf2-belnr

AND gjahr = it_bkpf2-gjahr.

Read only

0 Likes
2,457

But the select query will continue to throw the error message until you change the data type of AWKEY to GJAHR in internal table.

In IT_BKPF1 declare AWKEY as below :-

data : begin of it_bkpf occurs 1,
         belnr type RE_BELNR,
         awkey type awkey,
         awtyp type awtyp,
         gjahr type GJAHR,
       end of it_bkpf.

data : begin of it_bkpf1 occurs 1,
         belnr type RE_BELNR,
         awkey type gjahr,
         awtyp type awtyp,
         gjahr type GJAHR,
       end of it_bkpf1.

.

Do refer the code I have posted above.

Regards

Abhii

Read only

0 Likes
2,457

Hi Abhii,

I'm not getting an error when I modify the code as per Niraj mentioned. I modified it as :

SELECT belnr gjahr awkey awtyp

FROM bkpf

INTO TABLE it_bkpf

FOR ALL ENTRIES IN it_bsik

WHERE belnr = it_bsik-belnr

AND gjahr = it_bsik-gjahr.

LOOP AT it_bkpf INTO wa_bkpf.

wa_bkpf2-belnr = wa_bkpf-awkey+0(10).

wa_bkpf2-gjahr = wa_bkpf-awkey+10(4).

APPEND wa_bkpf2 to it_bkpf2.

ENDLOOP.

Read only

Former Member
0 Likes
2,457

Hi Saurabh,

In internal table IT_RBKP, try declaring both the variables BELNR and GJAHR as type AWKEY.

Regards,

Chandu.