Skip to Content

How to solve the problem of different length for the same field

Scenario

In table LFBK, the field BANKN is of length 18.

In table TIBAN, the field BANKN is of length 35.

The problem arises when we have a For All Entries like below:

  SELECT *
FROM tiban
INTO TABLE lt_tiban
FOR ALL ENTRIES IN lt_lfbk
WHERE banks EQ lt_lfbkbanks
AND   bankl EQ lt_lfbkbankl
AND   bankn EQ lt_lfbkbankn
AND   bkont EQ lt_lfbkbkont.

The yellow line will result in an error because the size of TIBAN-BANKN is bigger than LFBK-BANKN.

Solution

A solution would be to create a new structure and add a new field with length 35:

1. Create a type. 


BEGIN OF ty_lfbk_new.
include TYPE lfbk.
TYPES:
bankn35
TYPE tibanbankn,
END OF   ty_lfbk_new.

2. Create a new structure and table with the new type.


DATA:    ls_lfbk_new TYPE ty_lfbk_new,
          lt_lfbk_new
TYPE STANDARD TABLE OF ty_lfbk_new.

3. Fill the new field BANKN35 with the data LS_LFBK-BANKN.

LOOP AT lt_lfbk INTO ls_lfbk.
ls_lfbk_new
= ls_lfbk.
ls_lfbk_new
bankn35 = ls_lfbkbankn.
APPEND ls_lfbk_new to lt_lfbk_new.
ENDLOOP.

4. In the Select statement, use the new table LT_LFBK_NEW for FOR ALL ENTRIES.

SELECT *
FROM tiban
INTO TABLE lt_tiban
FOR ALL ENTRIES IN lt_lfbk_new
WHERE banks EQ lt_lfbk_newbanks
AND   bankl EQ lt_lfbk_newbankl
AND   bankn EQ lt_lfbk_newbankn35
AND   bkont EQ lt_lfbk_newbkont.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.