08-23-2012 12:27 PM
Dear Colleagues, Please let me know why this "The work area wa is not aligned correctly" occurs when we have the below code:
TABLES: TYSFLIGHT. TYPES: BEGIN OF TTSFLIGHT,
CARRID TYPE SFLIGHT-CARRID,
CONNID TYPE SFLIGHT-CONNID,
END OF TTSFLIGHT.
DATA:TT_SFLIGHT TYPE TABLE OF TTSFLIGHT,
WA_SFLIGHT TYPE TTSFLIGHT.
WA_SFLIGHT-CARRID = 'KF'.
WA_SFLIGHT-CONNID = '001'.
APPEND WA_SFLIGHT TO TT_SFLIGHT.
CLEAR WA_SFLIGHT.
INSERT TYSFLIGHT FROM TABLE TT_SFLIGHT.
IF SY-SUBRC = 0. WRITE: 'data inserted'. ENDIF.
The question here is that this piece of code was working fine. Here we create a type and declared work area and internal table of that type. Why is not we have to include the entire table structure of tysflight for the wa and internal table like below:
TABLES : TYSFLIGHT.
DATA : ITAB LIKE STANDARD TABLE OF TYSFLIGHT.
DATA : WA_ITAB LIKE LINE OF ITAB.
WA_ITAB-CARRID = 'KF'.
WA_ITAB-CONNID = '001'.
APPEND WA_ITAB TO ITAB.
CLEAR WA_ITAB.
INSERT TYSFLIGHT FROM TABLE ITAB. IF SY-SUBRC = 0.
WRITE: 'data inserted'. ENDIF.
Thanks, Ipsita
08-23-2012 1:19 PM
Go through the below prerequisites to use the workarea or internal table in open SQL statements
Note
The work area or row structure of the internal table should always be built like the database structure. If you work in the Open SQL statement with a single database table or one view, a data object built the same way can be declared with reference to the relevant structure in the ABAP Dictionary. If you work with more than one database table (in the SELECT statement), a data object built the same way can be built as nested structure, which contains, as substructures, the structures of the single database tables or views in the sequence in which they are listed in the statement. No structure should be used in which all components lie on one level, as possible alignment gaps between the single database tables or views are not taken into account.
08-23-2012 12:46 PM
Hi,
you can create an internal table and work area with a database table, it is better to use the complete table only if you are using all the fields or most of the fields.
Insted it will be a memory wastage. As you are using TYSFLIGHT. If i am right u are not using all the fields, so it is not preferable to use complete table to declare a structure.
08-23-2012 1:02 PM
hi mohanty,
As goutam mentioned the performance-wise first code is better than the second one.
because memory wastage as well as time consumption is high in secondone.The reason is u are selecting all the fields in database table in structure.so, it is advisable to go with the first method that u have mentioned.
thanks,
MARIMUTHU.K
08-23-2012 1:14 PM
Hi,
Did check the table TYSFLIGHT in data base? or did create the TYSFLIGHT table?
Regards,
Venkat.
08-23-2012 1:19 PM
Go through the below prerequisites to use the workarea or internal table in open SQL statements
Note
The work area or row structure of the internal table should always be built like the database structure. If you work in the Open SQL statement with a single database table or one view, a data object built the same way can be declared with reference to the relevant structure in the ABAP Dictionary. If you work with more than one database table (in the SELECT statement), a data object built the same way can be built as nested structure, which contains, as substructures, the structures of the single database tables or views in the sequence in which they are listed in the statement. No structure should be used in which all components lie on one level, as possible alignment gaps between the single database tables or views are not taken into account.
08-23-2012 2:00 PM
Hi Ipsita,
Have you confirmed that database table tysflight exists in your system? What is its structure?
There are some prerequisites for the SQL insert statement. The ones I think that are causing a problem for you are:
In practice, the easiest way to meet these prerequisites is to make sure that the database table and the table you are inserting from have the same structure.
Cheers,
Amy
08-24-2012 5:07 AM
Hi All,
Thanks for the quick reply.
I understand that memory wise its advisable to use as many fields that we require rather than selecting all fields from the table.
In the above case:
The structure of the internal table is not as long as the database table structure.
Hence the alignment issue.
And the database exists in the system with fields like carrid ,connid,etc but the alignment issue occurs if the wa and internal table do not have a structure as the table containing all fields.
I just wanted to now how this code was working earlier .
I am facing this issue recently.
Thanks,
Ipsita