![]() It would be even more useful if they’d add a DISTINCT option to it. This said, I have nothing against exceptions and my now favourite way to insert entries in an internal table is the new VALUE #() which raises exceptions when there are duplicate keys in tables with UNIQUE KEYs. But I don’t really see a reason to use APPEND anymore. Instead, it uses SY-SUBRC to signal errors. ![]() INSERT INTO TABLE has another advantage: it doesn’t raise exceptions. But INSERT INTO TABLE works with every kind of table. This is fine for STANDARD TABLEs, but if you try it on a SORTED TABLE you’ll probably run into problems at some point. But it’s a been a while since SAP is telling us to stop using it and use INSERT INTO TABLE instead.ĪPPEND always adds a line at the end of the table. Since the 20th century that we’ve gotten used to always using the APPEND command to insert in an internal table. How many times in your ABAP consultant life did you have to deal with dumps happening as a consequence of a program trying to insert duplicate lines into an internal table defined with a UNIQUE KEY? ![]() APPEND INITIAL LINE TO itab_alv_c ASSIGNING. APPEND INITIAL LINE TO -t_color ASSIGNING. FIELD-SYMBOLS : LIKE LINE OF itab_alv_c, LIKE LINE OF -t_color. * classical DATA : itab_alv_c TYPE tt_alv_data. TYPES : tt_alv_data TYPE STANDARD TABLE OF ty_alv_data T_color TYPE lvc_t_scol, END OF ty_alv_data. * Example 5 TYPES : BEGIN OF ty_alv_data , Since I declared the variable using the TYPE for the itab, I can use the # to let system determine the type. ltitab lvidx + 1 VALUE ( carrid 'UA' carrname 'United Airlines' connid 941 cityfrom 'Frankfurt' cityto 'San Francisco' ). Where as using the VALUE operator, the variable on the receiving side would be actual typed variable.Įxample 1 – Standard table with Component as TABLE_LINE 'How can I simplify the following code part' DATA (lvidx) lines ( ltitab ). When using the NEW, the variable on the receiving side would be data reference TYPE REF TO DATA. The code from start-of-selection until the 1st perform (which do all the selection) is 60 lines and if you take out the case which is very simple (fill the fields of the 2nd itab according to the month) and is 40 lines, the remaining is almost 20 lines.When you use NEW to create the Itab entries, you get the data reference back, where as when you use the VALUE operator, you get that data reference assigned to the variable on the left side.So you may ask what is the difference between VALUE vs NEW? Here are they: There are few more variation to the VALUE operator and NEW operator, which we will try to explore in next article. The code from start-of-selection until the 1st perform (which do all the selection) is 60 lines and if you take out the case which is very simple (fill the fields of the 2nd itab according to the month) and is 40. You can als construct structures using BASE: struct2 VALUE ( BASE struct1 col3 33 ). I wrote that I want to loop in an itab (itcollectoraction) fill the remaning fields and fill the 2nd itab(ittotalcollectoraction). ![]() At each pass of the loop, a row with initial values is added, after which the table work area is. After the second assignment, itab contains 1, 2, 3, 4, 5, 6. itab is created with two columns and filled in the loop DO. The result of the second expression is initialized with itab and then the other lines are added. If you haven’t got a chance to read it through, please read it once. itab VALUE ( BASE itab ( 4 ) ( 5 ) ( 6 ) ). I would omit all the explanation here as they are same as using the NEW. I have re-written all the example from the previous article on NEW operator for Itab here. Example: Data: Begin of itab occurs 10, col1 type C, col2 type I, end of itab. When done with that particular row finish it with closing bracket ) The system variable SY-TABIX contains the index of the appended line. Specify the name of the component and relevant value, Rule of thumb to use VALUE would be (same as NEW for ITAB):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |