FM????? Text file to Internal table in Background
Hi,
I need to execute my prog in background and as per my req i need to dwnload a file from prsentation server to internal table for processing. I'm not sure whch FM to use to dwnload from text file to internal table. I cannot use GUI_UPLOAD FM for background runs.....pls help
Thanks in advance
Chesat,
You can not work for this requirement.You will have an idea on it.
Introduction
The use of FTP from ABAP seems to have been a hot topic on the ABAP Forums of late. I thought I might sit down and document whatever I could find on this subject and share it as a weblog.
Over the years I have seen lots of different solutions for moving files on and off of a SAP system. I have seen external FTP scripts written in OS shell languages. I have seen full blown custom applications that are made to interface to the SAP system. However I think you will find that most of the technology you need to perform a simple FTP from ABAP is already contained in the standard system. All of my examples and screen shots will be coming from a 46C system.
SAP's Solution
If you have ever taken a look at the kernel directory of your SAP system, you might have noticed an interesting little executable: sapftp.exe (the name of the file on Windows SAP Kernels). It is this part of the Kernel that exposes FTP functionality to the ABAP Programming language.
So you have a suspicion that there is FTP functionality in ABAP, but youre not quite sure how to use it. Where do you start? I always turn to the Service Marketplace first. A quick search on SAPFTP reveals there is an entire component (BC-SRV-COM-FTP) on the subject. The most general note and our starting place is OSS Note 93042. This note starts off with a nice description of what SAPFTP is: A client RFC application that is accessed via RFC from ABAP. But we also find out that in addition to SAPFTP being part of the kernel, it is also part of the SAPGui. That means that we can perform FTP commands originating from our R/3 Server or from a Client Workstation.
Well if this solution is accessed via RFC, then we must have to setup some RFC destinations. In fact we have two that we need; SAPFTP for Front-end FTP and SAPFTPA for access on the application server. Luckily we don't even have to mess with setting these RFC destinations up in SM59. SAP has supplied a program, RSFTP005, to generate the destinations for us.
Now before we go off and start written code on our own to hit these FTP functions, why don't we make sure everything is setup and working. Once again SAP has helped us out by providing us with a test program, RSFTP002. (In case you are wondering the FTP functionality and many other test programs are all contained in SAP Development Class SFTP). When we run this test, we get a set input parameters for the server, username password, etc. We want to start out simple and just make sure we are getting a connection. Therefore we will just execute the pwd command (Print Working Directory).
Your answer back should look something like this:
If you are wanting to see a list of FTP commands, try using the command HELP in place of PWD:
If something did go wrong during the test, I suggest that you active the trace option in SM59 for the FTP Destination. You can then use program RSFTP001 to display the current trace file.
Programming the FTP
Not only does the RSFTP002 program give us a test environment, but it also provides us with a programming example. We can see that the FTP functionality is really provided by a set of function modules all within the SFTP Function Group. We have the basic commands such as FTP_CONNECT, FTP_COMMAND, and FTP_DISCONNECT that can be strung together to create a complete file operation action. The FTP_COMMAND Function allows you to issue arbitrary FTP commands as long as the SAPFTP function, the Host, and the Destination server all support the command. Then you have the specialized functions such as FTP_R3_TO_SERVER, FTP_R3_TO_CLIENT, and FTP_CLIENT_TO_R3. This lets you take some data in memory and transfer it someplace else. This has the advantage of not having to write the data to the file system first and not to have to issue any FTP commands. However these functions are also limited to the scope described.
If you are already familiar with FTP in general, working with these function modules should not seem to difficult. The Connect, Command, Disconnect actions would seem somewhat self explanatory. So instead of looking at the entire program in detail let's focus on two things that may be unfamiliar. First the program starts off with an ABAP Kernel System call to AB_RFC_X_SCRAMBLE_STRING. Well we don't want to pass a potentially sensitive password openly. Therefore the FTP_CONNECT function module requires that the password be encrypted before it receives it. It is this System call that performs that one-way encryption. Now I checked a 620 SP42 system and in this example, SAP has replace the AB_RFC_X_SCRAMBLE_STRING with a function call to HTTP_SCRAMBLE. Unfortunately HTTP_SCRAMBLE doesn't even exist in my 46C system. The only other thing that I wanted to point out about these function calls is the exporting parameter on the FTP_CONNECT. It passes back a parameter called handle. This handle then becomes an importing parameter to all subsequent calls: FTP_COMMAND and FTP_CLOSE. This handle is the pointer to the instance of FTP that we started with the FTP_CONNECT. This assures that we get reconnected to the same FTP session with each command we issue.
FTP Development
I thought I would share a few of the things that can be built using this FTP functionality. First off I didn't want a bunch of ABAP programs directly working with the SAP FTP Function modules. As you can see there is already a difference in the examples for encrypting the password between 46C and 620. Therefore I thought it would be best to encapsulate all the FTP function in one custom ABAP OO Class. Not only did I get the opportunity to hid the inner SAP functionality and make it easy to switch out during upgrades, but I also get consistent error handling as well. I accept the User Name, Password, Host, and RFC Destination in during the Constructor of the class. I then store these values away in Protected Attributes. Each function module is then implemented as a Instance Method. The Password encryption functionality is then all tucked away nicely in the class. Also the calling program doesn't have to worry about keeping track of the FTP handle either since it is an instance attribute as well.
Next I got really carried away. I wanted a way to record entire FTP scripts that could be filled with values at runtime and ran as a step in a background job. My company used to have many interfaces that ran frequently sending files all over the place. We needed a mechanism to monitor and support these file moves. This was really the root of this tool, but it also gives you an idea of how powerful these functions can be.
Closing
I hope that anyone interested in FTP from ABAP will find this resource useful. If anyone has any other resources that should be included here, feel free to post them.
Thomas Jung is an Application Developer for Kimball Electronics Group (www.kegroup.com) and a huge fan of ABAP.
Comment on this weblog
Showing messages 1 through 7 of 7.
Titles Only
Main Topics
Oldest First
New to SAP/ABAP-4
2005-02-24 13:03:06 Thomas Godfrey Business Card [Reply]
I've been in IT for over 30 years as a mainframe contract programmer/analyst. Recently a company hired me for my legacy knowledge of there business to become a developer on SAP for these same systems.
My first task is to develop a generalized ftp application to send data to the mainframe and then on to financial institutions. I have created an ABAP/4 test program with literals for the dest/host etc. And it works fine. I need more detail/guidance in creating the Class/Method/Function you have described to make this parameter driven and callable by other programs. I know this is a lot to ask, any help in pointing me in the right direction would be greatly appreciated. When I mention class creation to the existing staff they all say "Oh, we don't use or know anything about that object oriented stuff, we just right programs."
Thanks,
Tom
New to SAP/ABAP-4
2005-02-24 13:13:33 Thomas Jung Business Card [Reply]
"we don't use or know anything about that object oriented stuff" That's something I might have expected to hear 4 years ago. That's kind of like saying that you only want to use half of the programming lanuage (the old half at that).
However it is true that you have to learn to walk before you run. There are some fundamentals to ABAP that are usefull to have down before you start in with ABAP OO. But I wouldn't let that hold you back for long.
I'm afraid that I wouldn't be able to teach you everything you would need to know to create a function module or a class in this posting. There was a nice weblog that was just posted the other day that had the steps to create your first simple class. I suggest you start there.
As far as my FTP class goes, I don't mind sending you the code for the class. My email address is already all over SDN (and spammers' lists) so just send me the address that you want the details sent to. My email is [email protected].
New to SAP/ABAP-4
2005-02-24 13:05:42 Thomas Godfrey Business Card [Reply]
I just read what I typed, I meant "write programs" not "right programs" ... duh
Good suggestions - now...
2004-11-24 09:15:27 Jacques Claassen Business Card [Reply]
...any chance you've used FTP via an HTTP proxy?
Any help using the HTTP* functions in the ZFTP function group will be greatly appreciated. Any one?
Thx
Good suggestions - now...
2004-11-24 09:59:11 Thomas Jung Business Card [Reply]
I'm afraid I haven't done either. However I have used the HTTP client functionality in the WebAS 620 (if_http_client) along with an HTTP proxy. I have an example of this in another weblog.
Pretty insightful
2004-11-15 19:27:26 Subramanian Venkateswaran Business Card [Reply]
Thanks for this weblog, and I can be pretty sure there are some(many) more weblogs in the waiting.
Regards,
Subramanian V.
I have been using a local include ...
2004-11-15 16:29:39 Swapan Sarkar Business Card [Reply]
On the other hand I have been using a local include of ZCL_FTP_BASE in my programs for some time. Here's the signature:
<quote>
*& Include ZHR9_FTP_CLASSES
*& Utility class ZCL_FTP_BASE having all the
functions to upload and download files from an
FTP server.
CLASS zcl_ftp_base DEFINITION.
PUBLIC SECTION.
Output file type
TYPES: BEGIN OF t_scratch,
data(1024) TYPE c,
END OF t_scratch,
t_str_tab TYPE STANDARD TABLE OF t_scratch.
CONSTANTS: co_crlf(2) TYPE x VALUE '0D0A'.
DATA: status TYPE c VALUE space.
METHODS: constructor IMPORTING im_user TYPE string im_pwd TYPE string
im_server TYPE string,
send_table_data IMPORTING im_file TYPE string
im_table TYPE t_str_tab,
get_table_data IMPORTING im_file TYPE string
EXPORTING ex_table TYPE t_str_tab,
send_string_data IMPORTING im_file TYPE string
im_string TYPE string,
get_string_data IMPORTING im_file TYPE string
EXPORTING ex_string TYPE string,
disconnect.
PRIVATE SECTION.
DATA: v_user(64) TYPE c,
v_pwd_clear(30) TYPE c,
v_pwd(64) TYPE c,
v_server(30) TYPE c,
v_filename TYPE rlgrap-filename,
v_handle TYPE i.
METHODS: pwd_scramble IMPORTING im_pwd TYPE c.
ENDCLASS. "ZCL_FTP_BASE DEFINITION
</quote>
Showing messages 1 through 7 of 7.
Pls. mark if this doc. is useful
Similar Messages
-
Is it possible upload local file to internal table in background mode?
Hi, all,
Is it possbile to upload local file(not server file) to internal table in background mode.
If possbile ,please tell me detail . Thanks in advance.
Regards,
LilyHello,
This is possible.
If you report has to be executed in background using schedule Job. Then the file path should be constant and it can be hard coded in the report itself while populationg the internal table.
Then create a variant for your report and use that variant in the job.
This will solve your problem I guess.
Regards
Arindam -
How to get data of tabulated text file into internal table
hi all,
i want to get data from tabulated text file(notepad) into internal table. i searched in SCN and got lot of post regarding how to convert excel file into internal table but i didnt get posts regarding text file.
thanks
SAchintry:
DATA: BEGIN OF tabulator,
x(1) TYPE x VALUE '09',
END OF tabulator.
READ DATASET file INTO wa.
split wa at tabulator into table itab.
A. -
FM to upload TAB DELIMITED TEXT file into Internal table.
Hello Friends,
The FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' is used to upload EXCEL file into a Internal table.
Is there any FM which performs the simillar operation on TAB DELIMITED TEXT FILE.
Thanks in advance!
AshishHi,
To upload text file with tab delimated you can use FM
GUI_OPLOAD.
In this function you have put X in the field HAS_FIELD_SEPARATOR.
Regards,
Sujit -
Data transfer from text file to internal table
Hi, i am uploading data from a text file to an internal table itab.
one of the field in the text file is in the format of p(7,2).
while uploading , this is not not getting uploaded correctly,
for ex instead of uploading 00008.00 in the itab, it gives a strange value of 30303030382>3.03. how to correct this?
pls helpHello Rahul,
Do the following:
types: begin of ty_upload,
string type string,
end of ty_upload.
types: begin of ty_fields,
text1(20),
wert type p decimals 2,
text2(20),
end of ty_fields.
data: it_upload type table of ty_upload,
it_fields type table of ty_fields,
wa_upload type ty_upload,
wa_fields type ty_fields.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\aa_upload.txt'
FILETYPE = 'ASC'
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = it_upload
EXCEPTIONS
FILE_OPEN_ERROR = 1
Populate the internal table it_fields accordingly in a loop run, e.g.
loop at it_upload into wa_upload.
wa_fields-text1 = wa_upload-string(20).
wa_fields-wert = wa_upload-string+20(10).
wa_fields-text2 = wa_upload-string+30.
append wa_fields to it_fields.
endloop.
When your offsets are set correctly, there shouldn't be any problem.
Regards,
Heinz -
GUI_UPLOAD to upload flat file to internal table
Hi Experts,
I have to upload a flat file which has multiple records ,from a local server.The fields in records are ~ saperated.
Presently i am only looking into uploading the flat file into internal table.
I have done the following coding;
TYPES: BEGIN OF gt_frmgt ,
tablety type c length 10 ,
tablenm type c length 30,
numin type c length 2,
END OF gt_frmgt.
TYPES: begin of gt_frmgto,
rec(1000) type c,
end of gt_frmgto.
DATA: Itgt_frmgt type table of gt_frmgt with header line.
DATA: itgt_frmgto type table of gt_frmgto with header line.
DATA: lfile_path type string.
PARAMETERS: f_path type localfile.
at selection-screen on value-request for f_path.
call function 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = f_path.
start-of-selection.
lfile_path = f_path.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = lfile_path
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = itgt_frmgto
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
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
delete itgt_frmgto index 1.
loop at itgt_frmgto.
clear Itgt_frmgt.
split itgt_frmgto-rec at cl_abap_char_utilities=>vertical_tab
into Itgt_frmgt-tablety
Itgt_frmgt-tablenm
Itgt_frmgt-numin.
append Itgt_frmgt.
endloop.
loop at Itgt_frmgt.
write:/ Itgt_frmgt-tablety, Itgt_frmgt-tablenm, Itgt_frmgt-numin.
The input file in Local path is ;
XXXXXXX~~Export the invoice
2~19980501~19980531
// The first invoice:
0~00130698114000010004119980512059611000276233.350.1711076.66????321000789010005???????????????????130601000000000??????????18? 3352051????532611-3357211???~~~
0~????????176233.350.1711076.6676233.350~1510
// The second invoice:
0~00130698114000010007219980512059611000440482.000.175882.00????110108078901007?????????61? 68744479?????????????462088-07?????130601000000000??????????18? 3352051????532611-3357211???????????~~~
0~????????139780.000.175780.0039780.000~1510
0~????3.5"10702.000.17102.0070.20~1510
and the output is :
XXXXXXX~~
2~~1998050
// The fir
0~00~1
0~????~?
// The sec
0~00~1
0~????~?
0~????
I am unable to understand why this split is happening .According to me the first 3 fields should be displayed without field saperater.
It would be very much appreciated if any body has little idea about this.
Thankx,
Priya
Message was edited by:
Priya Parmeshwar Shiggaon
Message was edited by:
Priya Parmeshwar Shiggaonif it is one time upload then u can use transaction CG3Z n upload file on application server.
u can tno use Gui_upload in background.
Program to upload file via gui_upload in foreground -(open fiel in Excel format and then make changes and save it as text tab file and upload tht file) -
REPORT Z_AMIT_BAPI
no standard page heading line-size 255.
parameters: p_file like rlgrap-filename default 'C:\temp\emp.txt'.
data :begin of itab occurs 0,
pernr(8),
bdate(10),
edate(10),
mail(30) ,
end of itab.
Start-of-selection.
Perform read_file.
*& Form read_file
text
--> p1 text
<-- p2 text
FORM read_file .
DATA: full_file_name TYPE string.
full_file_name = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = full_file_name
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ','
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
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
IF SY-SUBRC <> 0.
MESSAGE e000(000) WITH 'Upload-Error; RC:' sy-subrc.
ENDIF.
ENDFORM. " read_file
reward points if helpfull
amit -
Getting Issue while uploading CSV file into internal table
Hi,
CSV file Data format as below
a b c d e f
2.01E14 29-Sep-08 13:44:19 2.01E14 SELL T+1
actual values of column A is 201000000000000
and columen D is 201000000035690
I am uploading above said CSV file into internal table using
the below coding:
TYPES: BEGIN OF TY_INTERN.
INCLUDE STRUCTURE KCDE_CELLS.
TYPES: END OF TY_INTERN.
CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT'
EXPORTING
I_FILENAME = P_FILE
I_SEPARATOR = ','
TABLES
E_INTERN = T_INTERN
EXCEPTIONS
UPLOAD_CSV = 1
UPLOAD_FILETYPE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
am getting all columns data into internal table,
getting problem is columan A & D. am getting values into internal table for both; 2.01E+14. How to get actual values without modifying the csv file format.
waiting for your reply...
thanks & regards,
abhiHi Saurabh,
Thanks for your reply.
even i can't double click on those columns.
b'se the program needs be executed in background there can lot of csv file in one folder. No manual interaction on those csv files.
regards,
abhi -
Problem converting data in XML file to internal table data
Hi all,
I have a requirement. I need to convert an XML file to internal table data and based on that data do Goods Receipt in SAP.
With the help of this blog /people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
I am able to convert the XML file to data in SAP. But this blog will display the output on screen as ELELEMNT = nodename VALUE= value of that node.
But I donu2019t want in that way, I want to store all the data in XML file in an internal table so that I can make use of those values and do Goods Recipt in SAP.
Can some one suggest how should I read the data in an internal table.
Here is my code..what changes should I make?
*& Report z_xit_xml_check
REPORT z_xit_xml_check.
TYPE-POOLS: ixml.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_parser TYPE REF TO if_ixml_parser,
l_istream TYPE REF TO if_ixml_istream,
l_document TYPE REF TO if_ixml_document,
l_node TYPE REF TO if_ixml_node,
l_xmldata TYPE string.
DATA: l_elem TYPE REF TO if_ixml_element,
l_root_node TYPE REF TO if_ixml_node,
l_next_node TYPE REF TO if_ixml_node,
l_name TYPE string,
l_iterator TYPE REF TO if_ixml_node_iterator.
DATA: l_xml_table TYPE TABLE OF t_xml_line,
l_xml_line TYPE t_xml_line,
l_xml_table_size TYPE i.
DATA: l_filename TYPE string.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:\temp\orders_dtd.xml'.
Validation of XML file: Only DTD included in xml document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.
wrap the table containing the file into a stream
l_istream = l_streamfactory->create_istream_itable( table = l_xml_table
size = l_xml_table_size ).
Creating a document
l_document = l_ixml->create_document( ).
Create a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
IF pa_val EQ 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
ENDIF.
Parse the stream
IF l_parser->parse( ) NE 0.
IF l_parser->num_errors( ) NE 0.
DATA: parseerror TYPE REF TO if_ixml_parse_error,
str TYPE string,
i TYPE i,
count TYPE i,
index TYPE i.
count = l_parser->num_errors( ).
WRITE: count, ' parse errors have occured:'.
index = 0.
WHILE index < count.
parseerror = l_parser->get_error( index = index ).
i = parseerror->get_line( ).
WRITE: 'line: ', i.
i = parseerror->get_column( ).
WRITE: 'column: ', i.
str = parseerror->get_reason( ).
WRITE: str.
index = index + 1.
ENDWHILE.
ENDIF.
ENDIF.
Process the document
IF l_parser->is_dom_generating( ) EQ 'X'.
PERFORM process_dom USING l_document.
ENDIF.
*& Form get_xml_table
FORM get_xml_table CHANGING l_xml_table_size TYPE i
l_xml_table TYPE STANDARD TABLE.
Local variable declaration
DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab TYPE TABLE OF string.
l_filename = pa_file.
upload a file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Writing the XML document to the screen
CLEAR l_str1.
LOOP AT l_xml_table INTO l_xml_line.
c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data replacement = space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.
ENDLOOP.
l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
WRITE: /.
WRITE: /' XML File'.
WRITE: /.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN
l_str1 WITH space.
WRITE: / l_str1.
ENDLOOP.
WRITE: /.
ENDFORM. "get_xml_table
*& Form process_dom
FORM process_dom USING document TYPE REF TO if_ixml_document.
DATA: node TYPE REF TO if_ixml_node,
iterator TYPE REF TO if_ixml_node_iterator,
nodemap TYPE REF TO if_ixml_named_node_map,
attr TYPE REF TO if_ixml_node,
name TYPE string,
prefix TYPE string,
value TYPE string,
indent TYPE i,
count TYPE i,
index TYPE i.
node ?= document.
CHECK NOT node IS INITIAL.
ULINE.
WRITE: /.
WRITE: /' DOM-TREE'.
WRITE: /.
IF node IS INITIAL. EXIT. ENDIF.
create a node iterator
iterator = node->create_iterator( ).
get current node
node = iterator->get_next( ).
loop over all nodes
WHILE NOT node IS INITIAL.
indent = node->get_height( ) * 2.
indent = indent + 20.
CASE node->get_type( ).
WHEN if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
WRITE: / 'ELEMENT :'.
WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
IF NOT nodemap IS INITIAL.
attributes
count = nodemap->get_length( ).
DO count TIMES.
index = sy-index - 1.
attr = nodemap->get_item( index ).
name = attr->get_name( ).
prefix = attr->get_namespace_prefix( ).
value = attr->get_value( ).
WRITE: / 'ATTRIBUTE:'.
WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',
value COLOR COL_TOTAL INVERSE.
ENDDO.
ENDIF.
WHEN if_ixml_node=>co_node_text OR
if_ixml_node=>co_node_cdata_section.
text node
value = node->get_value( ).
WRITE: / 'VALUE :'.
WRITE: AT indent value COLOR COL_GROUP INVERSE.
ENDCASE.
advance to next node
node = iterator->get_next( ).
ENDWHILE.
ENDFORM. "process_dom
Any help would be highly apperciated.
regards,
Jessica SamPavel Vera,
With your example i tries doing the following .....
I tried to convert the data of XML file to internal table data. I am collecting the data in internal table to do goos recipt with that data.
Please find my XML file, ABAP pgm and XSLT pgm . I donu2019t know what I am missing I am not getting any output. I donu2019t know what is wrong please help me with this
Below is my XML file, My code and XSLT Program. In the below XML file I need to collect Vendor Number, Order Number, and Date tags which occur only once for one XML file.
I also need to collect the following tags from <Shipmentdetail>
<Shipmentdetail> has following child nodes and I need to collect them
TrackingNumber
Freight
Weight
ShipmentDate
ShipmentMethod
Need to collect to collect the following tags from <ProductInformation>
<ProductInformation> has following child nodes and I need to collect them
LineNumber
SKUNumber
OrderedQuantity
ShippedQuantity
UOM
The <Shipmentdetail> and <ProductInformation> are child nodes of <OrderShipment>
The <Shipmentdetail> occurs only ones but the <ProductInformation> can occur once or many times and will be dynamic and differs depening on the input file.
My XML file is as follows
<?xml version="1.0" encoding="iso-8859-1" ?>
- <ShipmentHeader>
<AccountID />
- <OrderShipment>
<VendorNumber>1000</VendorNumber>
<OrderNumber>P00009238</OrderNumber>
<OrderType>Stock</OrderType>
<Company />
<Division />
<Department />
<Date>20061120</Date>
<CartonCount>2</CartonCount>
<ShipAllProducts>No</ShipAllProducts>
- <ShipmentDetail>
<TrackingNumber>1ZR3W891PG47477811</TrackingNumber>
<Freight>000000010000</Freight>
<ShipmentDate>20061120</ShipmentDate>
<ShipmentMethod>UPS1PS</ShipmentMethod>
</ShipmentDetail>
- <ProductInformation>
<LineNumber>000000001</LineNumber>
<SKUNumber>110FR</SKUNumber>
<AdvSKUNumber>003 4518</AdvSKUNumber>
<SKUID />
<OrderedQuantity>00000001000000</OrderedQuantity>
<ShippedQuantity>00000001000000</ShippedQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</ProductInformation>
- <ProductInformation>
<LineNumber>000000002</LineNumber>
<SKUNumber>938EN</SKUNumber>
<AdvSKUNumber>001 7294</AdvSKUNumber>
<SKUID />
<OrderedQuantity>00000000450000</OrderedQuantity>
<ShippedQuantity>00000000450000</ShippedQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</ProductInformation>
- <CaseInformation>
<LineNumber>000000001</LineNumber>
<SKUNumber>110FR</SKUNumber>
<AdvSKUNumber>003 4518</AdvSKUNumber>
<SKUID />
<SSCCNumber>00000001668000002487</SSCCNumber>
<CaseQuantity>00000001000000</CaseQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</CaseInformation>
<CaseInformation>
<LineNumber>000000001</LineNumber>
<SKUNumber>110FR</SKUNumber>
<AdvSKUNumber>003 4518</AdvSKUNumber>
<SKUID />
<SSCCNumber>00000001668000002487</SSCCNumber>
<CaseQuantity>00000001000000</CaseQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</CaseInformation>
- </OrderShipment>
</ShipmentHeader>
My Program
TYPE-POOLS abap.
CONSTANTS gs_file TYPE string VALUE 'C:\temp\test.xml'.
* This is the structure for the data from the XML file
TYPES: BEGIN OF ts_shipment,
VendorNumber(10) TYPE n,
OrderNumber(20) TYPE n,
OrderType(8) TYPE c,
Date(8) TYPE c,
END OF ts_shipment.
TYPES: BEGIN OF ts_shipmentdetail,
TrackingNumber(30) TYPE n,
Freight(12) TYPE n,
Weight(14) TYPE n,
ShipmentDate(8) TYPE c,
ShipmentMethod(8) TYPE c,
END OF ts_shipmentdetail.
TYPES: BEGIN OF ts_productinformation,
LineNumber(9) TYPE n,
SKUNumber(20) TYPE c,
OrderedQuantity(14) TYPE n,
ShippedQuantity(14) TYPE n,
UOM(4) TYPE c,
END OF ts_productinformation.
* Table for the XML content
DATA: gt_itab TYPE STANDARD TABLE OF char2048.
* Table and work ares for the data from the XML file
DATA: gt_shipment TYPE STANDARD TABLE OF ts_shipment,
gs_shipment TYPE ts_shipment.
DATA: gt_shipmentdetail TYPE STANDARD TABLE OF ts_shipmentdetail,
gs_shipmentdetail TYPE ts_shipmentdetail.
DATA: gt_productinformation TYPE STANDARD TABLE OF ts_productinformation,
gs_productinformation TYPE ts_productinformation.
* Result table that contains references
* of the internal tables to be filled
DATA: gt_result_xml TYPE abap_trans_resbind_tab,
gs_result_xml TYPE abap_trans_resbind.
* For error handling
DATA: gs_rif_ex TYPE REF TO cx_root,
gs_var_text TYPE string.
* Get the XML file from your client
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gs_file
CHANGING
data_tab = gt_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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "ISHIPMENT".
GET REFERENCE OF gt_shipment INTO gs_result_xml-value.
gs_result_xml-name = 'ISHIPMENT'.
APPEND gs_result_xml TO gt_result_xml.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "ISHIPDET".
GET REFERENCE OF gt_shipmentdetail INTO gs_result_xml-value.
gs_result_xml-name = 'ISHIPDET'.
APPEND gs_result_xml TO gt_result_xml.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "IPRODDET".
GET REFERENCE OF gt_productinformation INTO gs_result_xml-value.
gs_result_xml-name = 'IPRODDET'.
APPEND gs_result_xml TO gt_result_xml.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION z_xml_to_abap3
SOURCE XML gt_itab
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
* Writing the data from file for gt_shipment
*Collecting the Shipping Data from the XML file to internal table gt_shipment
*and writing the data to the screen
LOOP AT gt_shipment INTO gs_shipment.
WRITE: / 'VendorNumber:', gs_shipment-VendorNumber.
WRITE: / 'OrderNumber :', gs_shipment-OrderNumber.
WRITE: / 'OrderType :', gs_shipment-OrderType.
WRITE: / 'Date :', gs_shipment-Date.
WRITE : /.
ENDLOOP. "gt_shipment.
LOOP AT gt_shipmentdetail INTO gs_shipmentdetail.
WRITE: / 'TrackingNumber:', gs_shipmentdetail-TrackingNumber.
WRITE: / 'Freight :', gs_shipmentdetail-Freight.
WRITE: / 'Weight :', gs_shipmentdetail-Weight.
WRITE: / 'ShipmentDate :', gs_shipmentdetail-ShipmentDate.
* WRITE: / 'ShipmentMethod :' gs_shipmentdetail-ShipmentMethod
WRITE : /.
ENDLOOP. "gt_shipmentdetail.
LOOP AT gt_productinformation INTO gs_productinformation.
WRITE: / 'LineNumber:', gs_productinformation-LineNumber.
WRITE: / 'SKUNumber :', gs_productinformation-SKUNumber.
WRITE: / 'OrderedQuantity :', gs_productinformation-OrderedQuantity.
WRITE: / 'ShippedQuantity :', gs_productinformation-ShippedQuantity.
WRITE: / 'UOM :', gs_productinformation-UOM.
WRITE : /.
ENDLOOP. "gt_productinformation.
XSLT Program
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ISHIPMENT>
<xsl:apply-templates select="//OrderShipment"/>
</ISHIPMENT>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="OrderShipment">
<item>
<VENDORNUMBER>
<xsl:value-of select="VendorNumber"/>
</VENDORNUMBER>
<ORDERNUMBER>
<xsl:value-of select="OrderNumber"/>
</ORDERNUMBER>
<ORDERTYPE>
<xsl:value-of select="OrderType"/>
</ORDERTYPE>
<DATE>
<xsl:value-of select="Date"/>
</DATE>
</item>
</xsl:template>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ISHIPDET>
<xsl:apply-templates select="//OrderShipment/ShipmentDetail"/>
</ISHIPDET>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="ShipmentDetail">
<item>
<TRACKINGNUMBER>
<xsl:value-of select="TrackingNumber"/>
</TRACKINGNUMBER>
<FREIGHT>
<xsl:value-of select="Freight"/>
</FREIGHT>
<SHIPMENTDATE>
<xsl:value-of select="ShipmentDate"/>
</SHIPMENTDATE>
<SHIPMENTMETHOD>
<xsl:value-of select="ShipmentMethod"/>
</SHIPMENTMETHOD>
</item>
</xsl:template>
</xsl:transform> .
Any help is highly appreciated. If anyone encountered this situation before please let me know where i am going wrong in my XSLT transformation.
Any Help will be highly apppreciated. Thanks in advance
Regards,
Jessica Sam -
Question about reading csv file into internal table
Some one (thanks those nice guys!) in this forum have suggested me to use FM KCD_CSV_FILE_TO_INTERN_CONVERT to read csv file into internal table. However, it can be used to read a local file only.
I would like to ask how can I read a CSV file into internal table from files in application server?
I can't simply use SPLIT as there may be comma in the content. e.g.
"abc","aaa,ab",10,"bbc"
My expected output:
abc
aaa,ab
10
bbb
Thanks again for your help.Hi Gundam,
Try this code. I have made a custom parser to read the details in the record and split them accordingly. I have also tested them with your provided test cases and it work fine.
OPEN DATASET dsn FOR input IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET dsn INTO record.
PERFORM parser USING record.
ENDDO.
*DATA str(32) VALUE '"abc",10,"aaa,ab","bbc"'.
*DATA str(32) VALUE '"abc","aaa,ab",10,"bbc"'.
*DATA str(32) VALUE '"a,bc","aaaab",10,"bbc"'.
*DATA str(32) VALUE '"abc","aaa,ab",10,"b,bc"'.
*DATA str(32) VALUE '"abc","aaaab",10,"bbc"'.
FORM parser USING str.
DATA field(12).
DATA field1(12).
DATA field2(12).
DATA field3(12).
DATA field4(12).
DATA cnt TYPE i.
DATA len TYPE i.
DATA temp TYPE i.
DATA start TYPE i.
DATA quote TYPE i.
DATA rec_cnt TYPE i.
len = strlen( str ).
cnt = 0.
temp = 0.
rec_cnt = 0.
DO.
* Start at the beginning
IF start EQ 0.
"string just ENDED start new one.
start = 1.
quote = 0.
CLEAR field.
ENDIF.
IF str+cnt(1) EQ '"'. "Check for qoutes
"CHECK IF quotes is already set
IF quote = 1.
"Already quotes set
"Start new field
start = 0.
quote = 0.
CONCATENATE field '"' INTO field.
IF field IS NOT INITIAL.
rec_cnt = rec_cnt + 1.
CONDENSE field.
IF rec_cnt EQ 1.
field1 = field.
ELSEIF rec_cnt EQ 2.
field2 = field.
ELSEIF rec_cnt EQ 3.
field3 = field.
ELSEIF rec_cnt EQ 4.
field4 = field.
ENDIF.
ENDIF.
* WRITE field.
ELSE.
"This is the start of quotes
quote = 1.
ENDIF.
ENDIF.
IF str+cnt(1) EQ ','. "Check end of field
IF quote EQ 0. "This is not inside quote end of field
start = 0.
quote = 0.
CONDENSE field.
* WRITE field.
IF field IS NOT INITIAL.
rec_cnt = rec_cnt + 1.
IF rec_cnt EQ 1.
field1 = field.
ELSEIF rec_cnt EQ 2.
field2 = field.
ELSEIF rec_cnt EQ 3.
field3 = field.
ELSEIF rec_cnt EQ 4.
field4 = field.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CONCATENATE field str+cnt(1) INTO field.
cnt = cnt + 1.
IF cnt GE len.
EXIT.
ENDIF.
ENDDO.
WRITE: field1, field2, field3, field4.
ENDFORM.
Regards,
Wenceslaus. -
How to Download XML File to internal table
Hi Friends,
This is my urgent requirement. How to download XML File to Internal table.
regards
pauldharmaHai,
Please check this Link
http://www.sap-img.com/abap/upload-direct-excel.htm
PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
begcol TYPE i DEFAULT 1 NO-DISPLAY,
begrow TYPE i DEFAULT 1 NO-DISPLAY,
endcol TYPE i DEFAULT 100 NO-DISPLAY,
endrow TYPE i DEFAULT 32000 NO-DISPLAY.
* Tick don't append header
PARAMETERS: kzheader AS CHECKBOX.
DATA: BEGIN OF intern OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF intern.
DATA: BEGIN OF intern1 OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF intern1.
DATA: BEGIN OF t_col OCCURS 0,
col LIKE alsmex_tabline-col,
size TYPE i.
DATA: END OF t_col.
DATA: zwlen TYPE i,
zwlines TYPE i.
DATA: BEGIN OF fieldnames OCCURS 3,
title(60),
table(6),
field(10),
kz(1),
END OF fieldnames.
* No of columns
DATA: BEGIN OF data_tab OCCURS 0,
value_0001(50),
value_0002(50),
value_0003(50),
value_0004(50),
value_0005(50),
value_0006(50),
value_0007(50),
value_0008(50),
value_0009(50),
value_0010(50),
value_0011(50),
value_0012(50),
value_0013(50),
value_0014(50),
value_0015(50),
value_0016(50),
value_0017(50),
value_0018(50),
value_0019(50),
value_0020(50),
value_0021(50),
value_0022(50),
value_0023(50),
value_0024(50),
value_0025(50),
value_0026(50),
value_0027(50),
value_0028(50),
value_0029(50),
value_0030(50),
value_0031(50),
value_0032(50),
value_0033(50),
value_0034(50),
value_0035(50),
value_0036(50),
value_0037(50),
value_0038(50),
value_0039(50),
value_0040(50),
value_0041(50),
value_0042(50),
value_0043(50),
value_0044(50),
value_0045(50),
value_0046(50),
value_0047(50),
value_0048(50),
value_0049(50),
value_0050(50),
value_0051(50),
value_0052(50),
value_0053(50),
value_0054(50),
value_0055(50),
value_0056(50),
value_0057(50),
value_0058(50),
value_0059(50),
value_0060(50),
value_0061(50),
value_0062(50),
value_0063(50),
value_0064(50),
value_0065(50),
value_0066(50),
value_0067(50),
value_0068(50),
value_0069(50),
value_0070(50),
value_0071(50),
value_0072(50),
value_0073(50),
value_0074(50),
value_0075(50),
value_0076(50),
value_0077(50),
value_0078(50),
value_0079(50),
value_0080(50),
value_0081(50),
value_0082(50),
value_0083(50),
value_0084(50),
value_0085(50),
value_0086(50),
value_0087(50),
value_0088(50),
value_0089(50),
value_0090(50),
value_0091(50),
value_0092(50),
value_0093(50),
value_0094(50),
value_0095(50),
value_0096(50),
value_0097(50),
value_0098(50),
value_0099(50),
value_0100(50).
DATA: END OF data_tab.
DATA: tind(4) TYPE n.
DATA: zwfeld(19).
FIELD-SYMBOLS: <fs1>.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
mask = '*.xls'
static = 'X'
CHANGING
file_name = filename.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filename
i_begin_col = begcol
i_begin_row = begrow
i_end_col = endcol
i_end_row = endrow
TABLES
intern = intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE:/ 'Upload Error ', SY-SUBRC.
ENDIF.
END-OF-SELECTION.
LOOP AT intern.
intern1 = intern.
CLEAR intern1-row.
APPEND intern1.
ENDLOOP.
SORT intern1 BY col.
LOOP AT intern1.
AT NEW col.
t_col-col = intern1-col.
APPEND t_col.
ENDAT.
zwlen = strlen( intern1-value ).
READ TABLE t_col WITH KEY col = intern1-col.
IF sy-subrc EQ 0.
IF zwlen > t_col-size.
t_col-size = zwlen.
* Internal Table, Current Row Index
MODIFY t_col INDEX sy-tabix.
ENDIF.
ENDIF.
ENDLOOP.
DESCRIBE TABLE t_col LINES zwlines.
SORT intern BY row col.
IF kzheader = 'X'.
LOOP AT intern.
fieldnames-title = intern-value.
APPEND fieldnames.
AT END OF row.
EXIT.
ENDAT.
ENDLOOP.
ELSE.
DO zwlines TIMES.
WRITE sy-index TO fieldnames-title.
APPEND fieldnames.
ENDDO.
ENDIF.
SORT intern BY row col.
LOOP AT intern.
IF kzheader = 'X'
AND intern-row = 1.
CONTINUE.
ENDIF.
tind = intern-col.
CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
ASSIGN (zwfeld) TO <fs1>.
<fs1> = intern-value.
AT END OF row.
APPEND data_tab.
CLEAR data_tab.
ENDAT.
ENDLOOP.
CALL FUNCTION 'DISPLAY_BASIC_LIST'
EXPORTING
file_name = filename
TABLES
data_tab = data_tab
fieldname_tab = fieldnames.
*-- End of Program
http://sap.ittoolbox.com/groups/technical-functional/sap-dev/excel-file-download-to-an-internal-table-in-sap-crm-1719453#
tables: zinv_release,
zpo_release.
** decleration of data
DATA: BEGIN OF my_tab OCCURS 0.
INCLUDE STRUCTURE zinv_release.
DATA: END OF my_tab.
*DATA: hex_tab TYPE x VALUE '09'.
DATA: rec(200)."'/usr/test.dat'.
DATA:
zhours(20) TYPE c,
MINS(20) type c. "decimals.
data: coma.
coma = ','.
SELECTION-SCREEN BEGIN OF BLOCK txt
WITH FRAME TITLE text-001.
PARAMETERS: dsn(60) DEFAULT '\\sapdev01\prod\'.
SELECTION-SCREEN END
OF BLOCK txt.
*using a dataset to get text
OPEN DATASET dsn FOR INPUT IN TEXT MODE.
IF sy-subrc = 0.
DO.
READ DATASET dsn INTO rec.
IF sy-subrc <> 0.
EXIT.
ENDIF.
split rec at coma into
zpo_release-REL_GRP
zpo_release-REL_CODE
zpo_release-RESPREL
zpo_release-ALTREL
zpo_release-MANAGER
ZHOURS
MINS
zpo_release-FROMTIME
zpo_release-TOTIME
zpo_release-EXCLWKENDS.
move zpo_release-REL_GRP to my_tab-REL_GRP.
move zpo_release-REL_CODE to my_tab-REL_CODE.
move zpo_release-RESPREL to my_tab-RESPREL.
move zpo_release-ALTREL to my_tab-ALTREL.
move zpo_release-MANAGER to my_tab-MANAGER.
move ZHOURS to my_tab-ZHOURS.
move MINS to my_tab-mins.
move zpo_release-FROMTIME to my_tab-fromtime.
move zpo_release-TOTIME to my_tab-totime.
move zpo_release-EXCLWKENDS to my_tab-exclwkends.
APPEND my_tab.
ENDDO.
INSERT zpo_release FROM TABLE my_tab ACCEPTING DUPLICATE KEYS.
** DELETE zmm_ppa_cc FROM TABLE tab.
** INSERT zzzak_emp FROM TABLE my_tab ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
MESSAGE i000(zv) WITH 'File Successful stored in DB.' '' '' ''.
** ELSE.
MESSAGE i000(zv) WITH 'File already stored in DB.' '' '' ''.
endif.
ENDIF.
reward if helpful
raam -
FROM EXCEL FILE TO INTERNAL TABLE
HI GURU'S,
i'm using the following code to conver the excel file into internal table.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER =
I_TAB_RAW_DATA = IT_TAB_RAW_DATA
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT_MM01
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
What is the exact format for the to send the Excel File.
My requirement is the Excel file contains the several fields , that should be stored as a records in the internal table
My problem is when i send the data in the excel file as one column, i'm getting all the data in the first column of the Internal Table.
If i send the data in the excel file as a record it is not filling the internal table.
what is the problem??/
if the Excel files contain multiple records is it able to convert the data into internal table records.
Regards,
Adi.**Internal Table to hold the records in the text file
Hello Adi,
Put the fields in excel in the same format in which u want in ur internal table(here record)
U can refer the following code.
data: begin of record occurs 0,
General Data
data element: BUKRS
bukrs_001(004), " Company Code
data element: EKORG
ekorg_002(004), " Purchase Orgn
data element: KTOKK
ktokk_003(004), " Account Group
end of record.
Internal Table
data:it_excel like table of alsmex_tabline with header line.
**SELECTION-SCREEN**
selection-screen begin of block blk.
parameters: p_file like rlgrap-filename default 'c:\vendor_creation.xls'
selection-screen end of block blk.
A T S E L E C T I O N - S C R E E N O U T P U T
***************START*********************** F4 Help for field p_file
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
program_name = syst-repid
dynpro_number = syst-dynnr
FIELD_NAME = ' '
STATIC = ' '
MASK = ' '
changing
file_name = p_file
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
if sy-subrc <> 0.
message e006(zhnc).
endif.
S T A R T - O F - S E L E C T I O N
start-of-selection.
data : vf_index type i.
data : vf_start_col type i value '1', "start column
vf_start_row type i value '4', "start row
vf_end_col type i value '200', "maximum column
vf_end_row type i value '2500', "maximum row
p_text(20). "stores error messages
*/ Work Area
data: wa_intern like it_excel.
*/ Field symbol
field-symbols : <fs>.
*********Fn Module to convert the excel file data into internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'c:\vendor_creation.xls'
i_begin_col = vf_start_col
i_begin_row = vf_start_row
i_end_col = vf_end_col
i_end_row = vf_end_row
tables
intern = it_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
if it_excel[] is initial.
p_text = 'No Data Uploaded'.
else.
sort it_excel by row col.
loop at it_excel.
move : it_excel-col to vf_index.
assign component vf_index of structure record to <fs>.
move : it_excel-value to <fs>.
at end of row.
append record.
clear record.
endat.
endloop.
endif.
In case of any problem u can revert back.
Aastha -
FM to upload the Excel file to internal table
Hi
Is any FM available to upload the Excel file to internal table.
Thanks
AnbuHi
se this code
EXCEL to INTERNAL TABLE and then to APPLICATION SERVER
*& Report ZSD_EXCEL_INT_APP
REPORT ZSD_EXCEL_INT_APP.
parameter: file_nm type localfile.
types : begin of it_tab1,
f1(20),
f2(40),
f3(20),
end of it_tab1.
data : it_tab type table of ALSMEX_TABLINE with header line,
file type rlgrap-filename.
data : it_tab2 type it_tab1 occurs 1,
wa_tab2 type it_tab1,
w_message(100) TYPE c.
at selection-screen on value-request for file_nm.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = 'X'
MASK = ' '
CHANGING
file_name = file_nm
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
start-of-selection.
refresh it_tab2[].clear wa_tab2.
file = file_nm.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '10'
i_end_row = '35'
tables
intern = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at it_tab.
case it_tab-col.
when '002'.
wa_tab2-f1 = it_tab-value.
when '004'.
wa_tab2-f2 = it_tab-value.
when '008'.
wa_tab2-f3 = it_tab-value.
endcase.
at end of row.
append wa_tab2 to it_tab2.
clear wa_tab2.
endat.
endloop.
data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*--- Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT it_tab2 INTO wa_tab2.
TRANSFER wa_tab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
loop at it_tab2 into wa_tab2.
write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
endloop. -
Excel file to internal table gui_upload
Hi every 1,
I want to upload excel file to internal table through GUI_UPLOAD FM,
Will you please help me out.
Regards,You might want to try the following function module. This progam uploads an excel file to a dynamic internal table.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: it_fldcat type lvc_t_fcat,
wa_it_fldcat type lvc_s_fcat.
type-pools : abap.
data: new_table type ref to data,
new_line type ref to data.
data: xcel type table of alsmex_tabline with header line.
selection-screen begin of block b1 with frame title text .
parameters: p_file type rlgrap-filename default 'c:Test.csv'.
parameters: p_flds type i.
selection-screen end of block b1.
start-of-selection.
* Add X number of fields to the dynamic itab cataelog
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'C'.
wa_it_fldcat-inttype = 'C'.
wa_it_fldcat-intlen = 10.
append wa_it_fldcat to it_fldcat .
enddo.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
* Upload the excel
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
tables
intern = xcel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
* Reformt to dynamic internal table
loop at xcel.
assign component xcel-col of structure <dyn_wa> to <dyn_field>.
if sy-subrc = 0.
<dyn_field> = xcel-value.
endif.
at end of row.
append <dyn_wa> to <dyn_table>.
clear <dyn_wa>.
endat.
endloop.
* Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Regards,
Rich Heilman -
Uploading a file to internal table
Hi experts,
I have a peculiar problem with loading a file into internal table.
While loading the file the first record(line) only is getting uploaded in to the internal table, although i hve many records(lines).
what could be the problem.
thnx very much,
the code is something like this:
data: begin of t_line occurs 0,
data(150) type c,
end of t_line.
OPEN DATASET FILENAME FOR INPUT IN TEXT MODE.
if sy-subrc = 0.
perform process_file_contents.
FORM PROCESS_FILE_CONTENTS.
DO.
read dataset filename into t_line.
IF SY-SUBRC NE 0.
IF REC_READ < 1.
MESSAGE E009(ZM) WITH 'No records in the file' FILENAME.
ENDIF.
EXIT.
ELSE.
ADD 1 TO REC_READ.
ENDIF.
append t_line.
ENDDO.Hi sey ni,
check if this sample code can be of some help to u.:
TABLES: kna1.
TYPES: BEGIN OF s_file,
customer TYPE kna1-kunnr,
name TYPE kna1-name1,
country TYPE kna1-land1,
region TYPE kna1-regio,
post_code TYPE kna1-pstlz,
street TYPE kna1-stras,
END OF s_file.
DATA: it_file TYPE s_file OCCURS 0 WITH HEADER LINE.
*-- selection screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE rlgrap-filename DEFAULT 'Customer_download.txt'
OBLIGATORY.
*SELECT-OPTIONS s_cust FOR kna1-kunnr.
SELECTION-SCREEN END OF BLOCK b1.
*-- start processing
at selection-screen on value-request for p_file.
perform file_help using p_file.
START-OF-SELECTION.
**-- Extract data from DB
PERFORM extract_data.
*-- Transfer data to file
PERFORM file_transfer USING p_file.
*-- write to o/p
END-OF-SELECTION.
LOOP AT it_file.
WRITE:/ it_file-customer, it_file-name, it_file-country, it_file-region,
it_file-post_code, it_file-street.
ENDLOOP.
*& Form extract_data
FORM extract_data .
SELECT kunnr
name1
land1
regio
pstlz
stras
APPENDING TABLE it_file
FROM kna1
WHERE kunnr IN s_cust.
ENDFORM. " extract_data
*& Form file_transfer
FORM file_transfer USING p_p_file.
DATA: l_message(30).
*-- Open File for write
OPEN DATASET p_p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE
l_message.
IF sy-subrc NE 0.
MESSAGE i002 WITH p_p_file.
ENDIF.
*-- Transfer data from FILE TO internal table
DO.
READ DATASET p_p_file INTO it_file.
IF sy-subrc = 0.
APPEND it_file.
CLEAR it_file.
ELSE.
EXIT.
ENDIF.
ENDDO.
*-- Close file
CLOSE DATASET p_p_file.
endform.
*& Form file_hepl
text
-->P_P_FILE text
form file_help using p_p_file.
data:l_filepath type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = l_filepath
p_p_file = l_filepath .
endform. " file_hepl
regards,
keerthi. -
Uploading CSV file into internal table
Hi,
I want to upload a CSV file into internal table.The flat file is having values as below:
'AAAAA','2003-10-11 07:52:37','167','Argentina',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'AAAA BBBB',NULL,NULL,NULL,'1',NULL,NULL,'AR ',NULL,NULL,NULL,'ARGENT','M1V','MX1',NULL,NULL,'F','F','F','F','F',NULL,'1',NULL,'MX','MMI ',NULL
'jklhg','2004-06-25 08:01:57','456','hjllajsdk','MANAGUA ',NULL,NULL,'265-5139','266-5136 al 38','MX1',NULL,NULL,'hjgkid GRÖBER','sdfsdf dfs asdfsdf 380 ad ased,','200 as ads, sfd sfd abajao y 50 m al sdf',NULL,'1',NULL,NULL,'NI ',NULL,NULL,NULL,'sdfdfg','M1V','dds',NULL,NULL,
Here I can not even split at ',' because some of the values are having value like NULL and some have values with comma too,
The delimiter is a quote and the separator is a comma here.
Can anyone help on this?
Thanks.
Edited by: Ginger on Jun 29, 2009 9:08 AMAs long as there can be a comma in a text literal you are right that the spilt command doesn't help. However there is one possibility how to attack this under one assumption:
- A comma outside a text delimiter is always considered a separator
- A comma inside a text delimiter is always considered a comma as part of the text
You have to read you file line by line and then travel along the line string character by character and setting a flag or counter for the text delimiters:
e.g.
"Text","Text1, Text2",NULL,NULL,"Text"
String Index 1: EQ " => lv_delimiter = 'X'
String Index 2: EQ T => text literal (because lv_delimiter = 'X')
String Index 3: EQ e => text literal (because lv_delimiter = 'X')
String Index 4: EQ x => text literal (because lv_delimiter = 'X')
String Index 5: EQ t => text literal (because lv_delimiter = 'X')
String Index 6: EQ " => lv_delimiter = ' ' (because it was 'X' before)
String Index 7: EQ , => This is a separator because lv_delimiter = ' '
String Index 8: EQ " => lv_delimiter = 'X' (because it was ' ' before)
String Index 9: EQ T => text literal (because lv_delimiter = 'X')
String Index 10: EQ e => text literal (because lv_delimiter = 'X')
String Index 11: EQ x => text literal (because lv_delimiter = 'X')
String Index 12: EQ t => text literal (because lv_delimiter = 'X')
String Index 13: EQ 1 => text literal (because lv_delimiter = 'X')
String Index 14: EQ , => text literal (because lv_delimiter = 'X')
String Index 15: EQ T => text literal (because lv_delimiter = 'X')
Whenever you hit a 'real' separator (lv_delimiter = ' ') you pass the value of the string before that up to the previous separator into the next structure field.
This is not an easy way to do it, but if you might have commas in your text literal and NULL values I gues it is probably the only way to go.
Hope that helps,
Michael
Maybe you are looking for
-
How can I locate the 'Windows system path' with in java?
Hi, Is it possible to locate the System path (usu x:\winnt\system32\) of the OS at run time? What classes and methods should I use? Thanks in advance
-
h:selectOneRadio problem
Hi every body , I have a serious problem in jsf <h:selectOneRadio> component. I am using two different <h:selectOneRadio> component .When I am clicking the first radio button I can get data from the data base & showing in my jsf , same as in the seco
-
Head-Up Display Greatly Simplifies Navigation - CRM On Demand 17 Release
I'm an admin of CRM On Demand. I'd like to apply new features of CoD 17 Release. In particular, I want to use Head-Up Display in detail page of each objects. I mean, How can I apply Head-Up Display function as admin ? Please let me know how can I set
-
550 #5.1.0 Address rejected
Generating server: spamfirewall.xxx.xxx [email protected] #< #5.0.0 X-Spam-&-Virus-Firewall; host unmcip1.unmc.edu[192.198.54.156] said: 550 #5.1.0 Address rejected. (in reply to RCPT TO command)> #SMTP# please advice. Thank You
-
Hello all! What can cause the error " CREA/00001 / Internal error in item 0000000000: asset row is not complete" when ASKBN is running? I check with AUVA, but there are no any assets there. Thanks in advance!