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

append problem

Former Member
0 Likes
1,406

hallow

i have a problem with my table. I have I do read structure(CALL FUNCTION 'RHPH_STRUCTURE_READ' ) of org unit and I get it in order in the organization (the order I get is important) .

Like that

Org unit.

123

456

156

238

after that my program is running and If I find more data on the org.unit I doing append for more line in my table but the problem is that the line in the append come in the last line and I wont to append it in the after the line he belong to

Ex.

Org

123

123

456

456

156

238

I now that I can do <b>sort</b> after the append but I <b>don’t won</b>t ,I wont to keep the order that I get in structure

That i get from

CALL FUNCTION 'RHPH_STRUCTURE_READ'

their is option to do append in index or somting else

regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,184

LOOP AT ITAB.

READ TABLE ITAB1 WITH KEY ORG = ITAB-ORG.

IF SY-SUBRC = 0.

INSERT ITAB1 INTO ITAB INDEX SY-TABIX.<OR YOU MAY ADD 1 TO SY-TABIX>.

ENDIF.

ENDLOOP.

REGARDS

SHIBA DUTTA

7 REPLIES 7
Read only

Former Member
0 Likes
1,184
Read only

Former Member
0 Likes
1,184

Hi Antonio,

Use INSERT with index instead of APPEND.

Regards,

John.

Read only

Former Member
0 Likes
1,185

LOOP AT ITAB.

READ TABLE ITAB1 WITH KEY ORG = ITAB-ORG.

IF SY-SUBRC = 0.

INSERT ITAB1 INTO ITAB INDEX SY-TABIX.<OR YOU MAY ADD 1 TO SY-TABIX>.

ENDIF.

ENDLOOP.

REGARDS

SHIBA DUTTA

Read only

0 Likes
1,184

hi SHIBA DUTTA

i try like u say and i have runtime erorr

what can be the problem

regards

LOOP AT emp_tab INTO wa_emp_tab.

READ TABLE t_itab INTO wa_t_itab

WITH KEY jobid = wa_emp_tab-stell.

IF sy-subrc NE 0.

wa_t_itab-org_unit = wa_emp_tab-orgeh.

INSERT wa_t_itab INTO t_itab INDEX sy-tabix.

ADD 1 TO sy-tabix.

CLEAR wa_t_itab.

ENDIF.

ENDLOOP.

Read only

0 Likes
1,184

IF sy-subrc eq 0.

wa_t_itab-org_unit = wa_emp_tab-orgeh.

INSERT wa_t_itab INTO t_itab INDEX sy-tabix.

ADD 1 TO sy-tabix.

CLEAR wa_t_itab.

else.

wa_t_itab-org_unit = wa_emp_tab-orgeh.

append wa_t_itab TO t_itab .

ENDIF.

if you are using ne 0 then you have to append else insert because when you are trying to insert with ne 0 the sy-tabix value is 0.

regards

shiba dutta

Read only

0 Likes
1,184

Within a LOOP , on an internal table, you do not have to specify the insertion point with INDEX idx . The source table is then inserted before the current LOOP line in the target table.

so use APPEND wa to itab.

Read only

Former Member
0 Likes
1,184

<b>APPEND ... SORTED by will not work here....</b>

APPEND [wa TO] itab SORTED BY f.

Effect

Inserts the new entry into table and re-sorts the table by the sub-field f in descending order. This only makes sense if the table was sorted beforehand. When the number of table entries reaches the OCCURS parameter value, the last entry is deleted if the value f of a new entry is greater (particularly suitable for ranked lists). You can only sort by one sub-field.

If you specify wa TO , the new line is taken from the contents of the explicitly specified work area wa . Otherwise, it comes from the header line of the internal table itab .

Example

DATA: BEGIN OF COMPANIES OCCURS 3,

NAME(10), SALES TYPE I,

END OF COMPANIES.

COMPANIES-NAME = 'big'.

COMPANIES-SALES = 90.

APPEND COMPANIES.

COMPANIES-NAME = 'small'.

COMPANIES-SALES = 10.

APPEND COMPANIES.

COMPANIES-NAME = 'too small'.

COMPANIES-SALES = 5.

APPEND COMPANIES.

COMPANIES-NAME = 'middle'.

COMPANIES-SALES = 50.

APPEND COMPANIES SORTED BY SALES.

The table now has three (-> OCCURS 3 ) entries. The line with the contents 'too small' in the sub-field NAME is deleted from the table because the entry for 'middle' has a greater value in the sub-field SALES . This entry now appears in the second table line (after 'big' and before 'small' ).

Notes

Whenever an internal table is processed with APPEND SORTED BY , it should always be filled in this way.

If you specify APPEND with the parameter SORTED BY , the system always searches the entire table. Therefore, it is sometimes better to create the table with a simple APPEND and then use SORT to sort in descending ot ascending order afterwards.

You can also sort in ascending order by first determining the insert position with READ TABLE itab WITH KEY f = itab-f BINARY SEARCH and then by inserting the new entry into the table (perhaps read SY-SUBRC beforehand) with INSERT itab INDEX SY-TABIX .

However, you should be aware that, in such cases, the table may contain more entries than specified in the OCCURS parameter .

If several lines with an identical value f are added, lines added later are treated as smaller, i.e. they are inserted after existing lines with the same value f .

If you use APPEND ... SORTED BY f with an explicitly specified work area, this must be compatible with the line type of the internal table.

If the sort criterion f is not known until runtime, you can use SORTED BY (name) to specify it dynamically as the contents of the field name . If name is blank at runtime or contains an invalid component name, a runtime error occurs.

Regardless of whether you specify it statically or dynamically, you can restrict the sort criterion f further by defining an offset and/or length.