We have added search box. Key in SAP issue keyword to search
TopBottom

Announcement: wanna exchange links? contact me at sapchatroom@gmail.com.

[sap-dev] I am unable sort the itab without the header in CSV

Posted by Admin at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Posted by USER_2325403
on Feb 5 at 12:01 AM
I am using a CSV file with four fields user id, user name, amount, and no of items purchasd. And i have uploaded the csv file to internal table. But the problem is i m unable to sort the table by user id. When trying to sort the itab it sorts along with the header line in the csv file.


This is my program.

REPORT ZITAB_UPLOAD.
TYPES: BEGIN OF ttab,
rec(1000) TYPE c,
END OF ttab.
TYPES: BEGIN OF tdat,
fld1(10) TYPE n,
fld2(10) TYPE c,
fld3(10) TYPE n,
fld4(10) TYPE n,
END OF tdat.
DATA: itab TYPE TABLE OF ttab with header line.
DATA: idat TYPE TABLE OF tdat with header line.
DATA: file_str TYPE string.
PARAMETERS: p_file TYPE localfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = p_file.
START-OF-SELECTION.
file_str = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_str
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.

LOOP AT itab.
SPLIT itab-rec AT ',' INTO idat-fld1
idat-fld2
idat-fld3
idat-fld4.
APPEND idat.
ENDLOOP.
SORT idat by fld1.
LOOP AT idat.
WRITE:/ idat-fld1, idat-fld2, idat-fld3, idat-fld4.
ENDLOOP.
__.____._
Copyright © 2011 Toolbox.com and message author.

Toolbox.com 4343 N. Scottsdale Road Suite 280, Scottsdale, AZ 85251
View this online
  
Most Popular White Papers

In the Spotlight
Toolbox.com for iPhone: Ask Questions & Get Answers Anywhere. Use the New iPhone App
_.____.__

0 comments:

Post a Comment

T r a n s l a t e to your language