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

Invalid Memory Alignment

ruchirsaxena
Participant
0 Likes
2,128

Hi,

I have created a dynamic structure using RTTS for the view 'FINSV_MASS_CTRLC', and at the same time, dynamically appended 2 single character flags to the structure to create a type handle for casting.

I have used the same code for several other views, and never faced any issue. It ran fine for this view as well for the first run (. After that I filled the View (earlier empty) with data , and now the following statement is throwing dump:

ASSIGN <fs_appl_t1> TO <fs_appl_t2> CASTING TYPE HANDLE lr_struct_type_hndl.

<fs_appl_t1> is a structure of type char200.

Following is the error:

  • an error occurred when setting the field symbol "<FS_APPL_T2>" with ASSIGN or ASSIGNING (maybe in the combination with the CASTING addition). When converting the base entry of field symbol "<FS_APPL_T2>" (number in base table: 32781), 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.

I do not have much knowledge on memory alignment yet. I went through a few a question on the same, but it did not make a lot of sense to me. Any help is deeply appreciated.

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
1,921

Alignment of data objects is explained in the ABAP documentation.

If those characters were initialized from a structure to a character variable using CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C, you may retrieve its content using:

CL_ABAP_CONTAINER_UTILITIES=>READ_CONTAINER_C
Read only

ruchirsaxena
Participant
0 Likes
1,921

Thank you Sandra for responding.

I have gone through the SAP Help of 'Alignment of data objects', it does say, that in case of casting, the alignment needs to be checked. But provided not much info on how to check and adjust the same.

If you can maybe shed some light on the same, that would be of great help.

I also tried to check a few notes, but it was not really of great help,

I am already able to retrieve the contents from standard code. I am trying to cast to a dynamic structure, which works for all other views, but this particular one (I have tried with 10-15 views complex views)

If you can provide a means to adjust the alignment, through code or without it, that would be of great help.

The structure of the dynamic type handle includes 2 nested structures, with first one filling from the aforementioned view

followed by 2 structure containing 2 flags (char01).

What do you think?

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,921

A nested structure doesn't imply gaps. Only a mix of character, deep and numeric types may imply gaps (with memory address alignments of 2, 4, 8 or 16 bytes).

I think that you should post a minimal reproducible example so that I can analyze and answer with code corrected and solution explained.

Read only

ruchirsaxena
Participant
0 Likes
1,921

Hi Sandra,

I have attached the code:

ytest-alignment-dump-reproduce.txt

I would like to point out that the view 'FINSV_MASS_CTRLC' should have data for this dump to be properly reproduced.

Would be of great help to get your insights. 🙂

Read only

ruchirsaxena
Participant
0 Likes
1,921

Hi Sandra,

I am still not sure why casting (with data present will not work, or how to make it work,

but I created new data by casting with the type handle which i earlier created within the code (no data involved), and then used CL_ABAP_CONTAINER_UTILITIES=>READ_CONTAINER_C on that, and it works fine. Even though my doubt persists, my issue is resolved. Thank you 🙂