‎2006 Jul 18 10:13 PM
hi,
I am new to ABAP. This is an Inbound ABAP Proxy written for XI implementation.
Trying to do a SORT on 2 fields in the table on the resultset row based on a field in <b>wa_data_records-FTL_TimeStamp</b> and <b>wa_data_records-FTL_ActionType</b>. Trying to explore on the sort by on the above fields. If anyone has any quick suggestions i would really appreciate.
I have laid out the program below.
This is the program i have:
DATA: i_zta TYPE TABLE OF zta_freight.
DATA: wa_zta LIKE LINE OF i_zta.
DATA: wa_data_records TYPE LINE OF zresultset_row_tab1.
DATA: d_numberrange TYPE i.
DATA: wa_t005f TYPE t005f.
Loop at internal table into work area.
LOOP AT input-resultset-row INTO wa_data_records.
d_numberrange = d_numberrange + 1.
wa_ztamko-VSTEL = wa_data_records-WHSE.
wa_ztamko-REGIO = wa_data_records-DEST_STATE.
wa_ztamko-ORT01 = wa_data_records-DEST_CITY.
wa_ztamko-ZZ_MILEAGE = wa_data_records-MILEAGE.
SELECT SINGLE * FROM t005f INTO wa_t005f WHERE spras = sy-langu
AND land1 = 'US'
AND regio = wa_data_records-DEST_STATE
AND bezei = wa_data_records-DEST_COUNTY.
IF sy-subrc = 0.
wa_zta-COUNC = wa_t005f-counc.
ELSE.
wa_zta-COUNC = ' '.
ENDIF.
IF wa_data_records-FTL_ACTION_TYPE = 'D'.
DELETE zta_freight FROM wa_zta.
ELSE.
APPEND wa_zta TO i_zta.
ENDIF.
CLEAR wa_zta.
ENDLOOP.
Modify the Z table with the internal table.
MODIFY zta_freight FROM TABLE i_zta.
COMMIT WORK.
ENDMETHOD.
Thanks in advance.
Tirumal
‎2006 Jul 18 10:26 PM
SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].
Refer this link for help on SORTING internal table
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/frameset.htm
Regds
Manohar
‎2006 Jul 18 10:27 PM
Hi,
Are you asking how to sort your internal table input-resultset-row by the two fields? If so then you can try inserting the following statement before the loop (assuming the internal table is already filled with values and that the structure of your internal table contains the two fields mentioned):
SORT input-resultset-row BY ftl_timestamp ftl_actiontype.
Cheers,
James g.
‎2006 Jul 18 11:45 PM
James -
When i try to issue the sort statement, and when doing the syntax-check it gives an error as
"You may only read from table "input-resultset-row". - reading.
Any ideas.
Thanks,
Tirumal
‎2006 Jul 19 1:40 PM
Hi,
I guess I'd need to see more of the context of the code listed. Here is an example based on your code that gives no syntax error (Note that I had to declare the internal table and the related types):
REPORT ztest.
TYPES: BEGIN OF zresultset_row,
ftl_timestamp TYPE timestamp,
ftl_actiontype TYPE c,
END OF zresultset_row.
TYPES: zresultset_row_tab1 TYPE TABLE OF zresultset_row.
DATA: wa_data_records TYPE LINE OF zresultset_row_tab1,
input-resultset-row TYPE zresultset_row_tab1,
d_numberrange TYPE i.
SORT input-resultset-row BY ftl_timestamp ftl_actiontype.
* Loop at internal table into work area.
LOOP AT input-resultset-row INTO wa_data_records.
d_numberrange = d_numberrange + 1.
* ...
ENDLOOP.
I see now that your code ends with ENDMETHOD, so it would seem that the syntax error is probably related to where your code is located. Someone else suggested in a different reply that you could copy your itab to another one and sort the copied version... I'd try this.
Regards,
James G.
‎2006 Jul 19 2:05 PM
You would need to transfer the data into another internal table and apply the SORT.
Regards
Anurag
‎2006 Jul 19 4:22 AM
Its not allowing you to SORT as you directly changing the incoming parameters. Copy the internal table into another local internal table and do your SORT operation on that, that should work.
Regards,
Ravi
Note : Please mark all the helpful answers