How to upload a file from application server?
Hi experts,
I am going to create a conversion program using call function 'HR_INFOTYPE_OPERATION'.In my conversion I am going to upload per_area,emp_subgroup,payroll_area,work contract and orgn_key for the infotype IT0001 and the input file is from application server.I am using check boxes for these 5 fields and for the fields I am selecting the checkbox.I want to upload the datas in the IT0001 using HR_INFOTYPE_OPERATION.That is using the call transaction function.Its urgent give me some ideas or codings for that infotype updating.
Thanks,
Sakthi.C
Hi
you can use <b>open dataset for input</b>,<b>Read dataset</b> for uploading data from a application server.
Message was edited by:
Raghu Reddy
Similar Messages
-
How to upload XML file from Application server.
Hi,
How to upload XML file from Application server.Please tell me as early as possible.
Regards,
Sagar.Hi,
parameters : p_file type ibipparms-path obligatory.
***DOWNLOAD---->SAP INTO EXCEL
filename1 = p_file.
call function 'GUI_DOWNLOAD'
exporting
BIN_FILESIZE =
filename = filename1
filetype = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = it_stock
FIELDNAMES =
exceptions
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
others = 22
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Regards,
Deepthi. -
How to upload .CSV file from Application Server
Hi Experts,
How to upload .CSV file separated by ',' from Application server to an internal table.
Invoice No,Cust No,Item Type,Invoice Date,days,Discount Amount,Gross Amount,Sales Amount,Customer Order No.,Group,Pay Terms
546162,3233,1,9/4/2007,11,26.79,5358.75,5358.75,11264,HRS,11
546163,2645,1,9/4/2007,11,3.07,305.25,305.25,10781,C,11
Actually I read some already answered posts. But still I have some doubts.
Can anybody please send me the code.
Thanks in Advance.Hi Priya,
Check this code
Yhe logic used here is as follows,
Get all the data into an internal table in the simple format ie: a row with one field contains an entire line
After getting the data, we split each line of the table on every occurrence of the delimiter (comma in your case)
Here, I have named the fields as field01, field02 etc, you could use your own names according to your requirement
parameters: p_file(512).
DATA : BEGIN OF ITAB OCCURS 0,
COL1(1024) TYPE C,
END OF ITAB,
WA_ITAB LIKE LINE OF ITAB.
DATA: BEGIN OF ITAB_2 OCCURS 0,
FIELD01(256),
FIELD02(256),
FIELD03(256),
FIELD04(256),
FIELD05(256),
FIELD06(256),
FIELD07(256),
FIELD08(256),
FIELD09(256),
FIELD10(256),
FIELD11(256),
FIELD12(256),
FIELD13(256),
FIELD14(256),
FIELD15(256),
FIELD16(256),
END OF ITAB_2.
DATA: WA_2 LIKE LINE OF ITAB_2.
OPEN DATASET p_FILE FOR INPUT IN TEXT MODE ENCODING NON-UNICODE.
IF SY-SUBRC = 8.
WRITE:/ 'File' , p_FILE , 'cannot be opened'.
LV_LEAVEPGM = 'X'.
EXIT.
ENDIF.
WHILE SY-SUBRC <> 4.
READ DATASET p_FILE INTO WA_ITAB.
APPEND WA_ITAB TO ITAB.
ENDWHILE.
CLOSE DATASET p_FILE.
LOOP AT ITAB INTO WA_ITAB.
SPLIT WA_ITAB-COL1 AT ',' " where comma is ur demiliter
INTO WA_2-FIELD01 WA_2-FIELD02 WA_2-FIELD03 WA_2-FIELD04
WA_2-FIELD05 WA_2-FIELD06 WA_2-FIELD07 WA_2-FIELD08 WA_2-FIELD09
WA_2-FIELD10 WA_2-FIELD11 WA_2-FIELD12 WA_2-FIELD13 WA_2-FIELD14
WA_2-FIELD15 WA_2-FIELD16.
APPEND WA_2 TO ITAB_2.
CLEAR WA_2.
ENDLOOP.
Message was edited by:
Kris Donald -
How to upload a file in application server to an internal table
Hi,
I am asked to upload a file from application server to internal table. Can you please suggest me the ways to do it or the function module which helps to browse the application server file names.
I have done a program. But its giving problem in searching the files from application server. I am pasting my code for ur review. Please tell me which part i have to correct or suggest me some other ways to do it.
*& Report ZUPLOAD1
REPORT ZUPLOAD1.
type-pools: truxs.
parameters: p_upl_ps radiobutton group g1 default 'X', "upload from pres. server
p_path type rlgrap-filename,
p_upl_as radiobutton group g1, "upload from appln server
<b>p_dir LIKE filepath-pathintern DEFAULT 'Y_ABAP',
p_file LIKE filepath-pathintern lower case,</b>
p_test as checkbox.
constants: c_x value 'X',
c_tab type c value cl_abap_char_utilities=>horizontal_tab.
types: ty_data(1000) type c. "structure to hold legacy data
data: i_data type standard table of ty_data. "internal table of ty_data
types: begin of stritab,
land1 type v_t604-land1, "structure of legacy file.
stawn type v_t604-stawn,
bemeh type v_t604-bemeh,
impma type v_t604-impma,
minol type v_t604-minol,
end of stritab.
data: gi_itab type standard table of stritab, "internal table of legacy file
gw_itab type stritab. "work area
data: i_raw type truxs_t_text_data,
v_fullpath type string.
at selection-screen on value-request for p_path.
if p_upl_ps = c_x. "if presentation server is selected
perform get_file.
else. "if application server is selected
perform set_file_path.
perform upload_from_server.
perform split_data.
endif.
form get_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_path. "getting the file name of pres server
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X' "converting excel to sap and filling in
I_TAB_RAW_DATA = i_raw "internal table
I_FILENAME = p_path
TABLES
I_TAB_CONVERTED_DATA = gi_itab
EXCEPTIONS
CONVERSION_FAILED = 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.
endform.
form set_file_path. "Getting the file path of application server
data: lv_file type p_file.
lv_file = p_file.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
CLIENT = SY-MANDT
LOGICAL_PATH = p_dir
OPERATING_SYSTEM = SY-OPSYS
PARAMETER_1 = ' '
PARAMETER_2 = ' '
PARAMETER_3 = ' '
USE_BUFFER = ' '
FILE_NAME = lv_file
USE_PRESENTATION_SERVER = ' '
ELEMINATE_BLANKS = 'X'
IMPORTING
FILE_NAME_WITH_PATH = v_fullpath
EXCEPTIONS
PATH_NOT_FOUND = 1
MISSING_PARAMETER = 2
OPERATING_SYSTEM_NOT_FOUND = 3
FILE_SYSTEM_NOT_FOUND = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.
form upload_from_server.
data: lv_msg type string,
lw_data type ty_data.
open dataset v_fullpath for input message lv_msg in text mode encoding default.
if sy-subrc <> 0.
message lv_msg type 'i'.
stop.
endif.
do.
read dataset v_fullpath into lw_data.
if sy-subrc <> 0.
write:/5 'Error in processign data set'.
exit.
endif.
append lw_data to i_data.
enddo.
close dataset v_fullpath.
if sy-subrc <> 0.
write: /5 'Error closing dataset'.
endif.
endform.
form split_data.
data: lw_data type ty_data.
data: lw_itab type stritab.
data: begin of ty_itab,
land1 type v_t604-land1,
stawn type v_t604-stawn,
bemeh type v_t604-bemeh,
impma type v_t604-impma,
minol type v_t604-minol,
end of ty_itab.
loop at i_data into lw_data.
split lw_data at c_tab into
ty_itab-land1
ty_itab-stawn
ty_itab-bemeh
ty_itab-impma
ty_itab-minol.
lw_itab-land1 = ty_itab-land1.
lw_itab-stawn = ty_itab-stawn.
lw_itab-bemeh = ty_itab-bemeh.
lw_itab-impma = ty_itab-impma.
lw_itab-minol = ty_itab-minol.
append lw_itab to gi_itab.
endloop.
endform.
start-of-selection.
loop at gi_itab into gw_itab.
write: /5 'COUNTRY', 'IMPORT CODE', 'SUP UNIT', 'FIRST UOM', 'SECOND UOM',
/5 gw_itab-land1, gw_itab-stawn,gw_itab-bemeh,gw_itab-impma,gw_itab-minol.
endloop.
end-of-selection.
I hope problem must be in p_dir and p_file which are in bold.. Kindly help me out. Thanks in advance.see the following ex:
*& Form SUB_GET_FILEPATH
text
--> p1 text
<-- p2 text
FORM SUB_GET_FILEPATH .
GFILE = 'D:\SAP_INT\INBOUND\INBOX'. "Path
ENDFORM. " SUB_GET_FILEPATH
*& Form SUB_GET_FILE
text
--> p1 text
<-- p2 text
FORM SUB_GET_FILE .
DATA: P_FDIR(200) TYPE C.
DATA: IT_FILEDIR1 TYPE STANDARD TABLE OF TY_FILEDIR WITH HEADER LINE.
P_FDIR = GFILE.
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
EXPORTING
NAME = P_FDIR
TABLES
FILE_TBL = IT_FILEDIR.
REFRESH : IT_FILEDIR1.
LOOP AT IT_FILEDIR.
IF IT_FILEDIR-NAME(4) = 'ZINC' OR IT_FILEDIR-NAME(4) = 'zinc'.
MOVE IT_FILEDIR-NAME TO IT_FILEDIR1-NAME.
APPEND IT_FILEDIR1.
ENDIF.
ENDLOOP.
IF IT_FILEDIR1[] IS INITIAL.
STOP.
ENDIF.
LOOP AT IT_FILEDIR1.
REFRESH: I_TAB.
CLEAR: I_TAB.
NAME = IT_FILEDIR1-NAME.
CONCATENATE: GFILE '\' NAME INTO G_FILE.
OPEN DATASET G_FILE FOR INPUT IN TEXT MODE
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF SY-SUBRC EQ 0.
CONCATENATE 'FILENAME : ' G_FILE INTO I_MSG1.
APPEND I_MSG1.
DO.
READ DATASET G_FILE INTO RECORD.
IF SY-SUBRC = 0.
SPLIT RECORD AT ',' INTO I_TAB-BUKRS I_TAB-EBELN
I_TAB-BLDAT I_TAB-XBLNR I_TAB-LIFNR I_TAB-AMOUNT
I_TAB-CURR I_TAB-BUSAREA
I_TAB-BKTXT I_TAB-DMBTR I_TAB-MENGE I_TAB-SRNO.
MOVE-CORRESPONDING I_TAB TO I_TAB1.
ELSE.
EXIT.
ENDIF.
APPEND I_TAB1.
CLEAR: I_TAB, I_TAB1.
ENDDO.
ENDIF.
CLOSE DATASET G_FILE. -
How to delete a file from application server?
Hi gurus,
i want delete a file from application server . can any one tell me the BAPI/Fm .
thanks in advanceSee the replies of the thread;
How to delete File from the Application Server,ABAP
But i can smell something fishy in both The specified item was not found. and The specified item was not found. style of posting questions. Also both of you have similar questions in your profile....
Hmmm, Mods have to take care of the Rest...
Regards
Karthik D -
Uploading xml file from application server
HI everybody guys having promblem reading xml file from application server.Here is the solution. the sample program is below.
TYPE-POOLS: ixml. "iXML Library Types
*TABLES : rbkp.
TYPE DECLERATIION
TYPES: BEGIN OF type_tabpo,
ebeln TYPE ekko-ebeln, "PO document number
ebelp TYPE ekpo-ebelp, "PO line item
END OF type_tabpo.
TYPES: BEGIN OF type_ekbe,
belnr TYPE rbkp-belnr, "Invoice document
gjahr TYPE rbkp-gjahr, "fiscal year
END OF type_ekbe.
TYPES: BEGIN OF type_invoice,
belnr TYPE rbkp-belnr, "PO document number
gjahr TYPE rbkp-gjahr, "Fiscal Year
rbstat TYPE rbkp-rbstat, "invoice status
END OF type_invoice.
TYPES: BEGIN OF t_xml_line, "Structure for holding XML data
data(256) TYPE x,
END OF t_xml_line.
INTERNAL TABLE DECLERATIION
DATA: gi_tabpo TYPE STANDARD TABLE OF type_tabpo,
gi_ekbe TYPE STANDARD TABLE OF type_ekbe,
gi_invoice TYPE STANDARD TABLE OF type_invoice,
gi_bapiret2 TYPE STANDARD TABLE OF bapiret2.
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 swif_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, " XML Table of the structure
l_xml_line TYPE t_xml_line, " Record of structure t_xml_line
l_xml_table_size TYPE i. " XML table size
DATA: l_filename TYPE string.
WORK AREA DECLARATION
DATA: gw_tabpo TYPE type_tabpo,
gw_ekbe TYPE type_ekbe,
gw_invoice TYPE type_invoice,
gw_bapiret2 TYPE bapiret2.
BEGIN OF SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE pathintern LOWER CASE DEFAULT '/usr/sap/tmp/'.
Validation of XML file: Only DTD included in XML document is supported
SELECTION-SCREEN END OF BLOCK blk1.
INTIALISATION.
INITIALIZATION.
SELECTION SCREEN VALIDATION
AT SELECTION-SCREEN.
To validate p_file is not initial
PERFORM sub_validate_file.
PERFORM sub_validate_path.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Request for filename for xml file from the application server
PERFORM sub_get_filename_appl USING p_file.
START OF SELECTION SCREEN
START-OF-SELECTION.
PERFORM sub_fetch_po_details.
PERFORM sub_get_invoice.
PERFORM sub_rel_invoice.
END OF SELECTION SCREEN
END-OF-SELECTION.
*& Form sub_validate_file
To Validate the file
FORM sub_validate_file .
IF p_file IS INITIAL.
MESSAGE e000. "specify the file path
ENDIF.
ENDFORM. " sub_validate_file
*& Form sub_get_filename_appl
form sub_get_filename_appl USING l_fname TYPE any.
DATA: l_fname TYPE filename-fileintern. " File name
*GET THE FILENAME FROM THE APPLICATION SERVER
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = l_fname
filemask = '*'
IMPORTING
serverfile = l_fname
EXCEPTIONS
canceled_by_user = 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.
ENDFORM. " sub_get_filename_appl
*& Form sub_fetch_po_details
To fetch the PO details from the application server
Format of file is XML
FORM sub_fetch_po_details .
TYPE DECLERATIION
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table.
LOOP AT gi_tabpo INTO gw_tabpo.
WRITE:/ gw_tabpo.
ENDLOOP.
ENDFORM. " sub_fetch_po_details
*& Form get_xml_table
Read from the xml file
FORM get_xml_table .
Local variable declarations
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 = p_file.
code to upload data from application server
OPEN DATASET l_filename FOR INPUT IN BINARY MODE.
IF sy-subrc <> 0.
WRITE:/ 'invalid file path'.
ENDIF.
DO.
READ DATASET l_filename INTO l_xml_line.
IF sy-subrc EQ 0.
APPEND l_xml_line TO l_xml_table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
code to find the table size
DESCRIBE TABLE l_xml_table.
l_xml_table_size = ( sy-tleng ) * ( sy-tfill ).
*code to convert hexadecimal to XML
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.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN
l_str1 WITH space.
ENDLOOP.
CALL TRANSFORMATION ('ID') " code to put in internal table
SOURCE XML l_str1
RESULT tab = gi_tabpo[].
ENDFORM. " get_xml_tableHi Raja,
I tried the same. But it not populating the table and giving an error message in the return table "line 1 col 1-unexpected symbol; expected '<', '</', entity reference, charac".
I can't find any ' ; ' in the XML file. What could be the possible reason of error? -
Upload XML file from Application Server to Internal Table
Hi Experts,
i have xml file in application server and i want to convert to internal table .
i have tried this link http://wiki.sdn.sap.com/wiki/display/ABAP/UploadXMLfiletointernal+table.
Here the file is loaded from local(presentation Server) ..
i want to know how to select file from application layer ..and schedule in background..
i also tried FM '/SAPDMC/LSM_F4_SERVER_FILE' but this need front end selection of file from application server..
i need to select a xml file from application server and convert into internal table in background.. help me on this..Have a look on
Re: How to convert XML data to different ABAP internal table
Thanks
Ravin -
How to Upload Excel file to Application Server
Hi Friends,
ALSM_EXCEL_TO_INTERNAL_TABLE this F.M is to upload the excel format into internal table , The problem here is after uploading the excel file the format has been changed according to the F.M ... so Im not able to compare the value with my final internal table because the structure is different ... even if I could match with the values Im not able to upload it to my application server ... is there any F.M which doesn't change the excel format and upload it to the internal table ? ... Or is there any other way of doing it other than using at new , case endcase. ? ...
Thanks in advance ...
CheersHi friend,
Simply use GUI_UPLOAD function to get data from excel, txt etc.., into internal table in program.
Try this program.. It performs downloading and uploading functions in both excel and .txt format.
*& Report ZAWI_DEMODOWNLOAD *
REPORT zawi_demodownload .
*Types
TYPES: BEGIN OF g_r_mara,
matnr LIKE mara-matnr,
ersda LIKE mara-ersda,
laeda LIKE mara-laeda,
mtart LIKE mara-mtart,
mbrsh LIKE mara-mbrsh,
END OF g_r_mara.
TYPES: BEGIN OF g_r_mara1,
matnr TYPE string,
ersda TYPE string,
laeda TYPE string,
mtart TYPE string,
mbrsh TYPE string,
END OF g_r_mara1.
*Data
DATA: g_t_mara TYPE TABLE OF g_r_mara,
g_t_mara1 TYPE TABLE OF g_r_mara,
g_t_mara2 TYPE TABLE OF g_r_mara1,
filename TYPE string,
f1 TYPE string,
f2 TYPE string,
x TYPE string,
x1 TYPE string,
x2 TYPE string,
x3 TYPE strng,
c TYPE string,
g_r_wa TYPE g_r_mara,
g_r_wa1 TYPE g_r_mara1,
g_r_wa2 TYPE g_r_mara1,
g_t_mara2 TYPE TABLE OF g_r_mara1,
str TYPE string.
*Tables
TABLES: mara.
*Selection Screen
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(20) text-001 FOR FIELD p1.
PARAMETERS:p1 RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(20) text-002 FOR FIELD p2.
PARAMETERS p2 RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF LINE.
*Input validation.
DATA: s_high TYPE mara-matnr,
s_low TYPE mara-matnr.
AT SELECTION-SCREEN ON s_matnr.
IF NOT s_matnr-high IS INITIAL.
s_high = s_matnr-high.
SELECT SINGLE * FROM mara WHERE matnr = s_high.
IF sy-subrc <> 0.
IF NOT s_matnr-low IS INITIAL.
s_low = s_matnr-low.
SELECT SINGLE * FROM mara WHERE matnr = s_low.
IF sy-subrc <> 0.
MESSAGE e012(zawi_demo).
ELSE.
MESSAGE e011(zawi_demo).
ENDIF.
ENDIF.
ENDIF.
AT SELECTION-SCREEN.
SELECT SINGLE * FROM mara WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
IF s_matnr-low IS INITIAL.
str = s_matnr-high.
ELSE.
str = s_matnr-low.
ENDIF.
MESSAGE e010(zawi_demo) WITH str..
ENDIF.
START-OF-SELECTION.
*Data retrival
SELECT matnr ersda laeda mtart mbrsh
INTO CORRESPONDING FIELDS OF TABLE g_t_mara
FROM mara
WHERE matnr IN s_matnr.
IF p1 = 'X'.
filename = 'C:\Testing.xls'.
Downloading data from internal table to excel or txt
f1 = filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
append = 'X'
write_field_separator = 'X'
col_select = 'X'
TABLES
data_tab = g_t_mara.
ELSE.
filename = 'C:\Testing.txt'.
f2 = filename.
LOOP AT g_t_mara INTO g_r_wa.
CONCATENATE g_r_wa-matnr ';' INTO g_r_wa1-matnr.
CONCATENATE g_r_wa-ersda ';' INTO g_r_wa1-ersda.
CONCATENATE g_r_wa-laeda ';' INTO g_r_wa1-laeda.
CONCATENATE g_r_wa-mtart ';' INTO g_r_wa1-mtart.
CONCATENATE g_r_wa-mbrsh ';' INTO g_r_wa1-mbrsh.
APPEND g_r_wa1 TO g_t_mara2.
ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
append = 'X'
write_field_separator = 'X'
col_select = 'X'
TABLES
data_tab = g_t_mara2.
ENDIF.
Uploading data from excel to internal table 1
IF filename = f1.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = g_t_mara1.
WRITE: / 'Uploaded data' COLOR = 1.
WRITE:/.
CLEAR g_r_wa.
LOOP AT g_t_mara1 INTO g_r_wa.
WRITE:/ g_r_wa-matnr, g_r_wa-ersda, g_r_wa-laeda, g_r_wa-mtart, g_r_wa-mbrsh.
ENDLOOP.
ELSE.
IF filename = f2.
IF sy-subrc <> 0.
ENDIF.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
has_field_separator = 'X'
replacement = ''
TABLES
data_tab = g_t_mara2.
WRITE: / 'Uploaded data' COLOR = 1.
WRITE:/.
CLEAR g_r_wa1.
LOOP AT g_t_mara2 INTO g_r_wa1.
g_r_wa2-matnr = g_r_wa1-matnr.
TRANSLATE g_r_wa2-matnr USING '; ' .
WRITE:/ g_r_wa2-matnr, g_r_wa2-ersda, g_r_wa2-laeda, g_r_wa2-mtart, g_r_wa2-mbrsh.
CLEAR g_r_wa2.
ENDLOOP.
ENDIF.
ENDIF.
OR
Use T-codes:
CG3Y - Download file - Download file from Application server
CG3Z - Upload file - Upload file to Application server -
How to download a file from application server to presentation server
Hi experts,
I want to download a file from application server to presentaion server, file contaims three fields customer name, customer email id and status..
help me out i m new into sap.Dear Aditya,
Please check below thread
http://scn.sap.com/thread/1010164
it will help you.
BR
Atul -
How to display a file from Application server without downloading it to local drive
I want to dispaly a file from Application server without downloading it to my local system.
i tried the below method but it didn't work.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION = L_FILE
DEFAULT_DIRECTORY = L_DIRHi,
Use open dataset to read file from application server.
try like this sample code:
data : p_file like ibipparms-path.
data : rec(350) type c.
data: g_delimiter(1) type c value ','.
maintain the file path in p_file. then
open dataset p_file for input in text mode encoding default.
IF SY-SUBRC = 0.
do n times.
READ dataset p_file into rec.
split rec at g_delimiter into your internal table fields like it-id it-name it-age.
append it.
clear it.
enddo.
close dataset p_file.
Now you have the data in internal table it. -
How to copy a file from application server to local system
Guys,
Need to copy a file from application server to local system.Is there an FM for the same.
Tried searching for it but couldn't find anything useful.
Code snippets will be highly appreciated.
Warm Regards,
P.
Moderator message: very frequently asked and answered question, obviously you did not search thoroughly, all points removed.
Edited by: Thomas Zloch on Dec 3, 2010 4:48 PMhi,
You can use the transactions CG3Y or through program u can do like this..
DATA: BEGIN OF IT_FILE OCCURS 0,
LINE TYPE STRING,
END OF IT_FILE.
OPEN DATASET <file_name> FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC IS INITIAL.
DO.
READ DATASET<file_name> INTO IT_FILE-LINE.
IF SY-SUBRC = 0.
APPEND IT_FILE.
CLEAR IT_FILE.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET <file_name>.
Download it to local system using FM - GUI_DOWNLOAD -
How to upload excel file in application server??
Hi,
How to upload an excel file into internal table in background mode from application server?
ThanksHi vipin,
check this it may help you...
hope below links helps you
Export the report list to Excel Sheet
http://www.sapdevelopment.co.uk/file/file_updown.htm
or below is a sample programme which helps you upload and download
REPORT ytest5 LINE-SIZE 80
LINE-COUNT 65
NO STANDARD PAGE HEADING.
TABLES: dd02l, dd03l.
* selection screen
SELECTION-SCREEN BEGIN OF BLOCK b00 WITH FRAME TITLE text-b00.
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
PARAMETERS: tabname LIKE dd02l-tabname OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.
SELECTION-SCREEN BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
PARAMETERS: path(30) TYPE c DEFAULT 'C:SAPWorkdir'.
SELECTION-SCREEN END OF BLOCK b03.
SELECTION-SCREEN BEGIN OF BLOCK b04 WITH FRAME TITLE text-b04.
PARAMETERS: p_exp RADIOBUTTON GROUP radi,
p_imp RADIOBUTTON GROUP radi,
p_clear AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b04.
SELECTION-SCREEN END OF BLOCK b00.
* data
DATA: q_return LIKE syst-subrc,
err_flag(1) TYPE c,
answer(1) TYPE c,
w_text1(62) TYPE c,
w_text2(40) TYPE c,
winfile(128) TYPE c,
w_system(40) TYPE c,
winsys(7) TYPE c,
zname(8) TYPE c,
w_line(80) TYPE c.
* internal tables
DATA : BEGIN OF textpool_tab OCCURS 0.
INCLUDE STRUCTURE textpool.
DATA : END OF textpool_tab.
* table for subroutine pool
DATA : itab(80) OCCURS 0.
* events
INITIALIZATION.
PERFORM check_system.
AT SELECTION-SCREEN ON tabname.
PERFORM check_table_exists.
START-OF-SELECTION.
PERFORM init_report_texts.
PERFORM request_confirmation.
END-OF-SELECTION.
IF answer = 'J'.
PERFORM execute_program_function.
ENDIF.
TOP-OF-PAGE.
PERFORM process_top_of_page.
* forms
* FORM CHECK_TABLE_EXISTS *
FORM check_table_exists.
SELECT SINGLE * FROM dd02l
INTO CORRESPONDING FIELDS OF dd02l
WHERE tabname = tabname.
CHECK syst-subrc NE 0.
MESSAGE e402(mo) WITH tabname.
ENDFORM.
* FORM INIT_REPORT_TEXTS *
FORM init_report_texts.
READ TEXTPOOL syst-repid
INTO textpool_tab LANGUAGE syst-langu.
LOOP AT textpool_tab
WHERE id EQ 'R' OR id EQ 'T'.
REPLACE '&1............................'
WITH tabname INTO textpool_tab-entry.
MODIFY textpool_tab.
ENDLOOP.
ENDFORM.
* FORM REQUEST_CONFIRMATION *
FORM request_confirmation.
* import selected, confirm action
IF p_imp = 'X'.
* build message text for popup
CONCATENATE 'Data for table'
tabname
'will be imported' INTO w_text1 SEPARATED BY space.
* check if delete existing selected, and change message text
IF p_clear = ' '.
w_text2 = 'and appended to the end of existing data'.
ELSE.
w_text2 = 'Existing Data will be deleted'.
ENDIF.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
defaultoption = 'N'
textline1 = w_text1
textline2 = w_text2
titel = 'Confirm Import of Data'
cancel_display = ' '
IMPORTING
answer = answer
EXCEPTIONS
OTHERS = 1.
ELSE.
* export selected, set answer to yes so export can continue
answer = 'J'.
ENDIF.
ENDFORM.
* FORM EXECUTE_PROGRAM_FUNCTION *
FORM execute_program_function.
PERFORM build_file_name.
CLEAR: q_return,err_flag.
IF p_imp = 'X'.
PERFORM check_file_exists.
CHECK err_flag = ' '.
PERFORM func_import.
ELSE.
PERFORM func_export.
ENDIF.
ENDFORM.
* FORM BUILD_FILE_NAME *
FORM build_file_name.
MOVE path TO winfile.
WRITE '' TO winfile+30.
WRITE tabname TO winfile+31.
WRITE '.TAB' TO winfile+61(4).
CONDENSE winfile NO-GAPS.
ENDFORM.
* FORM CHECK_FILE_EXISTS *
FORM check_file_exists.
CALL FUNCTION 'WS_QUERY'
EXPORTING
filename = winfile
query = 'FE'
IMPORTING
return = q_return
EXCEPTIONS
OTHERS = 1.
IF syst-subrc NE 0 OR q_return NE 1.
err_flag = 'X'.
ENDIF.
ENDFORM.
* FORM func_export *
FORM func_export.
CLEAR itab. REFRESH itab.
APPEND 'PROGRAM SUBPOOL.' TO itab.
APPEND 'FORM DOWNLOAD.' TO itab.
APPEND 'DATA: BEGIN OF IT_TAB OCCURS 0.' TO itab.
CONCATENATE 'INCLUDE STRUCTURE'
tabname
'.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'DATA: END OF IT_TAB.' TO itab.
CONCATENATE 'SELECT * FROM'
tabname
'INTO TABLE IT_TAB.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'CALL FUNCTION ''WS_DOWNLOAD''' TO itab.
APPEND 'EXPORTING' TO itab.
CONCATENATE 'filename = ' ''''
winfile '''' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'filetype = ''DAT''' TO itab.
APPEND 'TABLES' TO itab.
APPEND 'DATA_TAB = IT_TAB.' TO itab.
APPEND 'DESCRIBE TABLE IT_TAB LINES sy-index.' TO itab.
APPEND 'FORMAT COLOR COL_NORMAL INTENSIFIED OFF.' TO itab.
APPEND 'WRITE: /1 syst-vline,' TO itab.
APPEND '''EXPORT'',' TO itab.
APPEND '15 ''data line(s) have been exported'',' TO itab.
APPEND '68 syst-index,' TO itab.
APPEND '80 syst-vline.' TO itab.
APPEND 'ULINE.' TO itab.
APPEND 'ENDFORM.' TO itab.
GENERATE SUBROUTINE POOL itab NAME zname.
PERFORM download IN PROGRAM (zname).
ENDFORM.
* FORM func_import *
FORM func_import.
CLEAR itab. REFRESH itab.
APPEND 'PROGRAM SUBPOOL.' TO itab.
APPEND 'FORM UPLOAD.' TO itab.
APPEND 'DATA: BEGIN OF IT_TAB OCCURS 0.' TO itab.
CONCATENATE 'INCLUDE STRUCTURE'
tabname
'.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'DATA: END OF IT_TAB.' TO itab.
APPEND 'DATA: BEGIN OF IT_TAB2 OCCURS 0.' TO itab.
CONCATENATE 'INCLUDE STRUCTURE'
tabname
'.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'DATA: END OF IT_TAB2.' TO itab.
APPEND 'CALL FUNCTION ''WS_UPLOAD''' TO itab.
APPEND 'EXPORTING' TO itab.
CONCATENATE 'filename = ' ''''
winfile '''' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'filetype = ''DAT''' TO itab.
APPEND 'TABLES' TO itab.
APPEND 'DATA_TAB = IT_TAB.' TO itab.
IF p_clear = 'X'.
CONCATENATE 'SELECT * FROM'
tabname
'INTO TABLE IT_TAB2.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'LOOP AT IT_TAB2.' TO itab.
CONCATENATE 'DELETE'
tabname
'FROM IT_TAB2.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'ENDLOOP.' TO itab.
APPEND 'COMMIT WORK.' TO itab.
ENDIF.
APPEND 'LOOP AT IT_TAB.' TO itab.
CONCATENATE 'MODIFY'
tabname
'FROM IT_TAB.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'ENDLOOP.' TO itab.
APPEND 'DESCRIBE TABLE IT_TAB LINES sy-index.' TO itab.
APPEND 'FORMAT COLOR COL_NORMAL INTENSIFIED OFF.' TO itab.
APPEND 'WRITE: /1 syst-vline,' TO itab.
APPEND '''IMPORT'',' TO itab.
APPEND '15 ''data line(s) have been imported'',' TO itab.
APPEND '68 syst-index,' TO itab.
APPEND '80 syst-vline.' TO itab.
APPEND 'ULINE.' TO itab.
APPEND 'ENDFORM.' TO itab.
GENERATE SUBROUTINE POOL itab NAME zname.
PERFORM upload IN PROGRAM (zname).
ENDFORM.
* Form CHECK_SYSTEM
* Check users workstation is running
* WINDOWS 95, or WINDOWS NT.
* OS/2 uses 8.3 file names which are no good for
* this application as filenames created are 30 char
* same as table name.
* You could change the logic to only use the first 8 chars
* of the table name for the filename, but you could possibly
* get problems if users had exported already with a table
* with the same first 8 chars.
* As an alternate method you could request the user to input
* the full path including filename and remove the logic to
* build the path using the table name.
FORM check_system.
CALL FUNCTION 'WS_QUERY'
EXPORTING
query = 'WS'
IMPORTING
return = winsys.
IF winsys NE 'WN32_95'.
WRITE: 'Windows NT or Windows 95/98 is required'.
EXIT.
ENDIF.
ENDFORM. " CHECK_SYSTEM
* FORM PROCESS_TOP_OF_PAGE *
FORM process_top_of_page.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
CONCATENATE syst-sysid
syst-saprl
syst-host INTO w_system SEPARATED BY space.
WRITE : AT /1(syst-linsz) w_system CENTERED.
WRITE : AT 1 syst-vline, syst-uname.
syst-linsz = syst-linsz - 11.
WRITE : AT syst-linsz syst-repid(008).
syst-linsz = syst-linsz + 11.
WRITE : AT syst-linsz syst-vline.
LOOP AT textpool_tab WHERE id EQ 'R'.
WRITE : AT /1(syst-linsz) textpool_tab-entry CENTERED.
ENDLOOP.
WRITE : AT 1 syst-vline, syst-datum.
syst-linsz = syst-linsz - 11.
WRITE : AT syst-linsz syst-tcode(004).
syst-linsz = syst-linsz + 11.
WRITE : AT syst-linsz syst-vline.
LOOP AT textpool_tab WHERE id EQ 'T'.
WRITE : AT /1(syst-linsz) textpool_tab-entry CENTERED.
ENDLOOP.
WRITE : AT 1 syst-vline, syst-uzeit.
syst-linsz = syst-linsz - 11.
WRITE : AT syst-linsz 'Page', syst-pagno.
syst-linsz = syst-linsz + 11.
WRITE : AT syst-linsz syst-vline.
ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
LOOP AT textpool_tab WHERE id EQ 'H'.
WRITE : AT /1(syst-linsz) textpool_tab-entry.
ENDLOOP.
ULINE.
ENDFORM.
if it helps you reward with points.
regards,
venu
regards,
venu. -
Regarding uploading the file from Application Server
I am trying to upload a .csv file to Application Server through CG3Z tcode.
But i am getting dump ad below..
What happened?
While a text was being converted from code page '4102' to '1100', one
the following occurred:
- an character was discovered that could not be represented in one of
the two code pages;
- the system established that this conversion is not supported.
The running ABAP program, 'SAPLC13Z' had to be terminated, since the
conversion could cause incorrect data to be generated.
1 characters could not be represented (and thus could not converted).
If 1 = 0, a second or a different error has occurred.
Please let me know..how can i resolve this??
Thanks
PriyankaCheck if your CSV file is UNICODE encoding.
If CG3Z steel not works you can check on OSS SUPPORT if a note solve your problem. -
Upload 1gb file from application server to PSA
Hi,
The following is the requirement my client has,
1) there will be a 1gb file on application server
2) pick up the file, and validate if the number of records are equal to number provided in the footer, if they dont match, reject the file
3) then validate the first field, employees number, with a database table
if the employee exisits insert this file in PSA ( BW)
else reject this file and proceed to next file.
this file is a fixed length file, and not a CSV.
can you please provide me with some hint or link or answers.
Thanks
ajayHi,
The following is the requirement my client has,
there will be a 1gb file on application server pick up the file, and validate if the number of records are equal to number provided in the footer, if they dont match, reject the file then validate the first field, employees number,
with a database table if the employee exisits insert this file in PSA (
BW) else reject this file and proceed to next file.
this file is a fixed length file, and not a CSV.
can you please provide me with some hint or link or
answers.
Thanks
ajay
for my above queries, i have an idea but need your help to solve.
i want to read the file on application server ( for example 1st record to 100th record) and store it in the internal table 1, and again i want to read the same file on application server from 101th record to 200th record and store it in the internal table 2. and so on.
can anyone help me to this, what is it that i should code for this?
open data set
read data set (any conditions???)
close dataset.
ill surely award points for all the replies.
thankyou
ajay -
Issue with uploading XML file from application server into internal table
i Need to fetch the XML file from the application server and place into internal table and i am getting error message while using the functional module SMUM_XML_PARSE and the error message is "line 1 col 1-unexpected symbol; expected '<', '</', entity reference, character data, CDATA section, processing instruction or comment" and could you please let me know how to resolve this issue?
TYPES: BEGIN OF T_XML,
raw(2000) TYPE C,
END OF T_XML.
DATA:GW_XML_TAB TYPE T_XML.
DATA: GI_XML_TAB TYPE TABLE OF T_XML INITIAL SIZE 0.
DATA:GI_STR TYPE STRING.
data: GV_XML_STRING TYPE XSTRING.
DATA: GI_XML_DATA TYPE TABLE OF SMUM_XMLTB INITIAL SIZE 0.
data:GI_RETURN TYPE STANDARD TABLE OF BAPIRET2.
OPEN DATASET LV_FILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'File does not exist' TYPE 'E'.
ELSE.
DO.
* Transfer the contents from the file to the work area of the internal table
READ DATASET LV_FILE1 INTO GW_XML_TAB.
IF SY-SUBRC EQ 0.
CONDENSE GW_XML_TAB.
* Append the contents of the work area to the internal table
APPEND GW_XML_TAB TO GI_XML_TAB.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
* Close the file after reading the data
CLOSE DATASET LV_FILE1.
IF NOT GI_XML_TAB IS INITIAL.
CONCATENATE LINES OF GI_XML_TAB INTO GI_STR SEPARATED BY SPACE.
ENDIF.
* The function module is used to convert string to xstring
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = GI_STR
IMPORTING
BUFFER = GV_XML_STRING
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE 'Error in the XML file' TYPE 'E'.
ENDIF.
ENDIF.
IF GV_SUBRC = 0.
* Convert XML to internal table
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = GV_XML_STRING
TABLES
XML_TABLE = GI_XML_DATA
RETURN = GI_RETURN.
ENDIF.
READ TABLE GI_RETURN TRANSPORTING NO FIELDS WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
MESSAGE 'Error converting the input XML file' TYPE 'E'.
ELSE.
DELETE GI_XML_DATA WHERE TYPE <> 'V'.
REFRESH GI_RETURN.
ENDIF.Could you please tel me why the first 8 lines were removed, till <Soap:Body and also added the line <?xml version="1.0" encoding="UTF-8"?> in the beggining .
Becuase there will be lot of XML files will be coming from the Vendor daily and that should be uploaded in the application server and should update in the SAP tables based on the data in the XML file.
what information i need to give to vendor that do not add the first 8 lines in the XML file and add the line in the beggining <?xml version="1.0" encoding="UTF-8"?> ??????
Is there any other way we can do with out removing the lines?
Maybe you are looking for
-
Ipod Touch Stuck on Itunes and USB screen(more details inside)
Right. Couldn't quite explain the whole thing just from the topic description, but I'm pretty sure you're all familiar with this issue. I tried to restore my Ipod using Itunes and once it was done, the Ipod Touch(2nd Generation), simply stayed on a s
-
Is it true if you have a mobleme account apple will send you a copy of osx snow leopard 10.6
is it true if you have a mobileme account apple will send you a free copy of snow leopard 10.6?
-
i have a new computer and want to sync my phone to the new but dont want to lose the information. how do i transfer. i was told there was a way but not sure how
-
Audigy 4, 5.1 not working in W 7
I have just installed windows 7 and after installing the audio drivers i opened winamp to listen to music and i cannot hear anything in my rear speakers. I have tried WMP also and it's the same thing. I tried a DVD though and that seemed to work in 5
-
Hi everyone, I am developing an application for a pocket PC in flash and want to have a dropdown menu with an event listener on it so that each time a user selects a different item on the listen an event is triggered. I have tried using the ordinary