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: 

how to handle this error: ASSIGN_BASE_WRONG_ALIGNMENT

Private_Member_124810
Participant
0 Kudos

Hi, sap pros, In table maintenance source code Include LSVIMF44 line 14, I tried writing the same code as it in view cluster event 03, but above error occurs:

DATA: L_VIEWNAME TYPE C LENGTH 20.
DATA: LS_IT TYPE YVIT_FOOD,
 LT_IT TYPE TABLE OF YVIT_FOOD,
 LS_TJ TYPE YTTJ_FOOD.
DATA: eflag type vcl_flag_type.
FIELD-SYMBOLS: <FS_IT> TYPE ANY,
 <FS_IT_TEMP> TYPE ANY,
 <FS_IT_STRUC> TYPE ANY.
L_VIEWNAME = 'YVIT_FOOD'.
PERFORM VCL_SET_TABLE_ACCESS_FOR_OBJ USING 'YVIT_FOOD' CHANGING EFLAG.
APPEND INITIAL LINE TO <VCL_TOTAL> ASSIGNING <FS_IT>.
ASSIGN: <FS_IT> TO <FS_IT_TEMP> CASTING TYPE c.
ASSIGN <FS_IT> TO <FS_IT_STRUC> CASTING TYPE (L_VIEWNAME).  "-------------->>>>error line
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

It's probably due to the fact that your table or view YVIT_FOOD contains probably other types than character-like types C, D, N and T (and that <VCL_TOTAL> always points to a table of characters (C)).

In fact, <VCL_TOTAL> is a generic container, its lines are C but internally it's mapped with the following type (here it's for table or view YVIT_FOOD, but it will depend on the current active table or view in the cluster):

TYPES BEGIN OF ty_yvit_food.
INCLUDE TYPE yvit_food.
INCLUDE TYPE vimflagtab.
TYPES END OF ty_yvit_food.

You cannot transfer or assign directly. Instead, you have to cast both source and target as bytes (X) for allowing the transfer (same principle as in methods FILL_CONTAINER_C and READ_CONTAINER_C of class CL_ABAP_CONTAINER_UTILITIES):

DATA line_of_yvit_food TYPE ty_yvit_food.
FIELD-SYMBOLS: <line_of_yvit_food_x> TYPE x,
               <total_line>          TYPE x.

ASSIGN line_of_yvit_food TO <line_of_yvit_food_x> CASTING.

LOOP AT <vcl_total> ASSIGNING <total_line> CASTING.
  <line_of_yvit_food_x> = <total_line>.
  line_of_yvit_food-yourcolumn1 = VALUE #( ).
  line_of_yvit_food-yourcolumn2 = VALUE #( ).
  <total_line> = <line_of_yvit_food_x>.
ENDLOOP.
11 REPLIES 11

Mohamed_Mukhtar
Active Contributor
0 Kudos

Hi,

Can you try with below code.

DATA : ls_yvit_food type yvit_food type.
ASSIGN <FS_IT> TO <FS_IT_STRUC> CASTING TYPE ls_yvit_food.

Field Symbols - Casting Documentation

Regards,

Mukhtar

Private_Member_124810
Participant
0 Kudos

Hi Mukhtar, error still. And the code should be LIKE not TYPE .

ASSIGN <FS_IT> TO <FS_IT_STRUC> CASTING LIKE ls_yvit_food.

Private_Member_124810
Participant
0 Kudos

error details as below

In the current program "YV_FOOD_PROG", an error occurred when setting the field symbol "<FS_IT_STRUC>" with ASSIGN or ASSIGNING (maybe in the combination with the CASTING addition). When converting the base entry of field symbol "<FS_IT_STRUC>" (number in base table: 33040), the system detected that the target type requires memory alignment 4. The source data object has an invalid memory alignment however, as it is not divisible by 4. If you want to assign a subfield of a structure to a field symbol for example, the offset from the start of the structure should be a multiple of 4. The structure should also contain a type that has at least the alignment 4.

0 Kudos

Hola,

how did you declare/assign <VCL_TOTAL> ?

0 Kudos

<VCL_TOTAL> is system declaration, same structure as TOTAL in table maintenance

0 Kudos

Sorry I do not understand, the field-symbol <VLC_TOTAL> is a table, and the structure of this table contains only a field Total. And this field is typed with the data element TOTAL ?

And you try to assign a part of this TOTAL to a type of the view YVIT_FOOD ?

and the view YVIT_FOOD contains certainly a CHAR4 or a NUMC4 ?

0 Kudos

TOTAL is not a field in the table, TOTAL is a table declared in table maintenance source code. Debug any table maintenance you would see how it's structured.

0 Kudos

You need to send more information about your issue

We need all the structure of the objects used by your Field-Symbols.

We cannot help you based on name of view/table/field

Sandra_Rossi
Active Contributor
0 Kudos

It's probably due to the fact that your table or view YVIT_FOOD contains probably other types than character-like types C, D, N and T (and that <VCL_TOTAL> always points to a table of characters (C)).

In fact, <VCL_TOTAL> is a generic container, its lines are C but internally it's mapped with the following type (here it's for table or view YVIT_FOOD, but it will depend on the current active table or view in the cluster):

TYPES BEGIN OF ty_yvit_food.
INCLUDE TYPE yvit_food.
INCLUDE TYPE vimflagtab.
TYPES END OF ty_yvit_food.

You cannot transfer or assign directly. Instead, you have to cast both source and target as bytes (X) for allowing the transfer (same principle as in methods FILL_CONTAINER_C and READ_CONTAINER_C of class CL_ABAP_CONTAINER_UTILITIES):

DATA line_of_yvit_food TYPE ty_yvit_food.
FIELD-SYMBOLS: <line_of_yvit_food_x> TYPE x,
               <total_line>          TYPE x.

ASSIGN line_of_yvit_food TO <line_of_yvit_food_x> CASTING.

LOOP AT <vcl_total> ASSIGNING <total_line> CASTING.
  <line_of_yvit_food_x> = <total_line>.
  line_of_yvit_food-yourcolumn1 = VALUE #( ).
  line_of_yvit_food-yourcolumn2 = VALUE #( ).
  <total_line> = <line_of_yvit_food_x>.
ENDLOOP.

0 Kudos

Yes, it works when I convert them into bytes(X). But it still confuses me why SAP's own source code in table maintenance Include LSVIMF44 line 14 is working fine without converting. I merely copied the same code!


DATA: L_VIEWNAME TYPE C LENGTH 20,
      L_TABIX TYPE SY-INDEX.
DATA: LS_IT TYPE YVIT_FOOD ,
      LT_IT TYPE TABLE OF YVIT_FOOD,
      LS_TJ TYPE YTTJ_FOOD.
DATA: EFLAG TYPE VCL_FLAG_TYPE.
FIELD-SYMBOLS: <FS_XFROM> TYPE X,
        <FS_XTO> TYPE X.

L_VIEWNAME = 'YVIT_FOOD'.
PERFORM VCL_SET_TABLE_ACCESS_FOR_OBJ USING 'YVIT_FOOD' CHANGING EFLAG.

LOOP AT <VCL_TOTAL> ASSIGNING <FS_XFROM> CASTING.
  L_TABIX = SY-TABIX.
  APPEND INITIAL LINE TO LT_IT ASSIGNING <FS_XTO> CASTING.
  <FS_XTO> = <FS_XFROM>.

  READ TABLE LT_IT INTO LS_IT INDEX L_TABIX.

  SELECT SINGLE *
    INTO CORRESPONDING FIELDS OF LS_TJ
    FROM YTTJ_FOOD
   WHERE BELNR = LS_IT-BELNR
     AND BUZEI = LS_IT-BUZEI
     AND USNAM = SY-UNAME.
  IF SY-SUBRC = 0.
    LS_IT-YSELECTED = LS_TJ-YSELECTED.
  ELSE.
    LS_IT-YSELECTED = ''.
  ENDIF.

  MODIFY LT_IT FROM LS_IT INDEX L_TABIX .
  <FS_XFROM> = <FS_XTO>.

ENDLOOP.

<VCL_EXTRACT> = <VCL_TOTAL>.

Yes, it's a good remark and I don't know why, and I didn't find an explanation in the documentation.

The difference is that ABAP reacts differently between assigning a line of an internal table and a structure as you can see here:

  TYPES: BEGIN OF ty_target,
           comp TYPE i,
         END OF ty_target.
  FIELD-SYMBOLS <target> TYPE ty_target.
  TYPES: BEGIN OF ty_line,
           line(2048) TYPE c,
         END OF ty_line.
  TYPES: ty_table TYPE STANDARD TABLE OF ty_line.
  DATA itab TYPE ty_table.
  DATA line TYPE ty_line.
  APPEND INITIAL LINE TO itab.
  ASSIGN line TO <target> CASTING.      " <=== works very well
  ASSIGN itab[ 1 ] TO <target> CASTING. " <=== syntax error
  FIELD-SYMBOLS <line> TYPE ANY.
  ASSIGN itab[ 1 ] TO <line>.
  ASSIGN <line> TO <target> CASTING.    " <=== short dump ASSIGN_BASE_WRONG_ALIGNMENT