Append 3 workarea into internal table
Hi,
I have 3 workarea and i want to append into one internal table.so how to append.
Thanks,
Deesanth
HIII
then you need to use MODIFY statement like below code..
IF sy-subrc EQ 0.
LOOP AT i_output INTO wa_output.
READ TABLE i_mard INTO wa_mard WITH KEY matnr = wa_output-matnr.
wa_output-lgort = wa_mard-lgort.
MODIFY i_output FROM wa_output.
CLEAR wa_output.
ENDLOOP. " LOOP AT i_output
ENDIF. " IF sy-subrc EQ 0
here you need to use READ statement to get workarea data from different tables and use MODIFY statement to append that data in the same row.
reagrds
twinkal
Similar Messages
-
Selecting multiple records from the list and append it into internal table.
hi
there is a list of 10 records in the output screen with check boxes. if the user select any 3 records then those records should get appended in some other internal table of same structure.
this is the requirement. can anybody help me it is very urgent.
regards
samiHi,
Loop at the internal table which contains the value in table control and move it to a work area. apend the work area to the next internal table. Like:
loop at it1 into wa1 where sel = 'X'.
append wa1 to it2.
endloop.
or
loop at it1 into wa1.
if wa1-sel = 'X'.
append wa1 to it2.
endif.
endloop.
Regards,
RM -
Getting data into internal table wa_final
Hi Guys
I have change the logic for this program , I have created 2 workareas and internal table now I need help to place the data into
wa_final-max_date = wa_data-idate.
wa_final-min_date = wa_data-idate.
wa_final-max_km = wa_data-recdv.
wa_final-min_km = wa_data-recdv.
wa_final-max_hR = wa_data-recdv.
wa_final-min_hR = wa_data-recdv.
wa_final-max_lit = wa_data-recdv.
wa_final-min_lit = wa_data-recdv.
wa_final-t_max_min_km = wa_data-recdv. " min_km - max_km
wa_final-t_max_min_hr = wa_data-recdv. " min_hr - max_hr
wa_final-t_max_min_lit = wa_data-recdv. " min_lit - max_lit.
so how can I put the logic to the value please correct my program.seeing my program can anyone give some idea ?
REPORT Z_FUEL_MONTHLY_QTY LINE-SIZE 260 LINE-COUNT 75
NO STANDARD PAGE HEADING.
TABLES : equi,
equz,
imptt,
imrg,
eqkt,
iloa.
Type Declaration
*DATA: BEGIN OF ty_equi occurs 0,
equnr type equi-equnr,
END OF ty_equi.
*DATA: BEGIN of ty_eqkt occurs 0,
equnr type eqkt-equnr,
eqktx type eqkt-eqktx,
END OF ty_eqkt.
*DATA: BEGIN of ty_iloa occurs 0,
iloan type iloa-iloan,
eqfnr type iloa-eqfnr,
END OF ty_iloa.
*DATA: BEGIN of ty_imptt occurs 0,
mpobj type imptt-mpobj,
END of ty_imptt.
*DATA: BEGIN of ty_imrg occurs 0,
idate type imrg-idate,
recdv type imrg-recdv,
recdu type imrg-recdu,
END of ty_imrg.
TYPES: BEGIN OF ty_data ,
equnr type equnr, " Euipment no
eqktx type eqkt-eqktx, " Equipment Text
eqfnr type iloa-eqfnr, " Equipment Sort field
idate type imrg-idate, " Measuring Date
recdu type imrg-recdu, " Unit of measuring ='KM','L','H'
recdv type imrg-recdv, " Counter reading data
END OF ty_data.
TYPES: BEGIN OF ty_final,
equnr type equnr, " Equipment no
eqktx type eqkt-eqktx, " Equipment Text
eqfnr type iloa-eqfnr, " Equipment Sort field
min_date type imrg-idate, " Min Date
min_km type p decimals 2, " Max Km
max_km type p decimals 2, " Min km
t_max_min_km type i, " Total min_km-max_km
max_date type imrg-idate, " Max Date
min_hr type imrg-recdv, " Max hr
max_hr type imrg-recdv, " Min hr
t_max_min_hr type i, " Total min_hr-max_hr
min_lit type imrg-recdv, " Max lit
max_lit type imrg-recdv, " Min lit
t_max_min_lit type i, " Total min_lit-max_lit
fuel_con type p decimals 2, " Total_hrs / t_max_min_hr
km_l type p decimals 2, " km / L
lit_per_hr type i , " fuel comsumed / t_max_min_hr
END OF ty_final.
DATA: i_data TYPE TABLE OF ty_data, " internal table
wa_data TYPE ty_data, " work area
i_final TYPE TABLE OF ty_final, " internal table
wa_final TYPE ty_final. " work area
DATA : max_date type date ,
min_date type date,
max_km TYPE p DECIMALS 2,
min_km TYPE p DECIMALS 2,
max_hr TYPE p DECIMALS 2,
min_hr TYPE p DECIMALS 2,
max_lit TYPE p DECIMALS 2,
min_lit TYPE p DECIMALS 2,
t_max_min_km TYPE p DECIMALS 2,
t_max_min_hr TYPE p DECIMALS 2,
t_max_min_lit TYPE p DECIMALS 2.
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: p_equnr FOR equi-equnr, "no-extension no intervals,
p_idate FOR imrg-idate. "NO-EXTENSION NO INTERVALS OBLIGATORY,
"p_recdu FOR imrg-recdu NO-EXTENSION NO INTERVALS ."default 'M3'" OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
SELECTION-SCREEN END OF BLOCK blk2.
SELECTION-SCREEN END OF BLOCK blk.
TOP-OF-PAGE.
FORMAT INTENSIFIED ON.
WRITE:/1(40) ' INVESTMENT LIMITED '.
WRITE:/50(40) ' FUEL CONSUMPTION REPORT ' CENTERED ,
2 'Page', sy-pagno.
FORMAT INTENSIFIED OFF.
WRITE:/50(40) '----
' CENTERED .
FORMAT INTENSIFIED ON.
WRITE:/2 sy-datum COLOR 3, sy-uzeit .
"WRITE:/1 S903-SPMON ."p_yearf.
ULINE.
"CENTERED.
write: /2 'Date From :'.
write: /2 'Equipment No :'.
write: /2 'Unit :'.
SKIP.
ULINE.
WRITE:/1 sy-vline,
2 'EQUIP NO', 10 sy-vline,
11 'NAME', 40 sy-vline,
41 'SORT', 60 sy-vline,
61 'MIN DATE', 74 sy-vline,
75 'MAX DATE', 87 sy-vline,
88 'MIN KM', 100 sy-vline,
101 'MAX KM' , 113 sy-vline,
114 'TOTALK', 126 sy-vline,
127 'MIN HR', 139 sy-vline,
140 'MAX HR', 152 sy-vline,
153 'TOTALH' , 167 sy-vline,
168 'MIN LIT', 180 sy-vline,
181 'MAX LIT', 193 sy-vline,
194 'TOTALL', 206 sy-vline,
207 'FUEL CON', 219 sy-vline,
220 'KM L', 232 sy-vline,
233 'LIT PER KM', 246 sy-vline.
FORMAT COLOR 3 ON.
ULINE.
END-OF-PAGE.
START-OF-SELECTION.
select a~equnr d~eqktx f~eqfnr e~idate e~recdu e~recdv
into table i_data
from equi AS a
inner join equz as b
on a~equnr = b~equnr
inner join iloa as f
on b~iloan = f~iloan
inner join imptt as c
on a~objnr = c~mpobj
inner join eqkt as d
on a~equnr = d~equnr
inner join imrg as e
on e~point = c~point
where a~equnr in p_equnr
and
e~idate in p_idate.
loop at i_data into wa_data.
CLEAR: wa_final.
READ TABLE i_final into wa_final
with key equnr = wa_data-equnr.
if sy-subrc EQ 0.
PERFORM prepare_final_rec USING'M'. " Modify Existing Record
ElSE.
PERFORM prepare_final_rec USING'A'. " Append New Record.
ENDIF.
ENDLOOP.
LOOP AT i_final into wa_final.
WRITE:/1 sy-vline,
2 wa_final-equnr , 10 sy-vline,
11 wa_final-eqktx , 40 sy-vline,
41 wa_final-eqfnr , 60 sy-vline,
61 wa_final-min_date , 74 sy-vline,
75 wa_final-max_date , 87 sy-vline,
88 wa_final-min_km EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 100 sy-vline,
101 wa_final-max_km EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 113 sy-vline,
114 wa_final-t_max_min_km EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 126 sy-vline,
127 wa_final-min_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 139 sy-vline,
140 wa_final-max_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 152 sy-vline,
153 wa_final-t_max_min_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 167 sy-vline,
168 wa_final-min_lit EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 180 sy-vline,
181 wa_final-max_lit EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 193 sy-vline,
194 wa_final-t_max_min_lit EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 206 sy-vline,
207 wa_final-fuel_con EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 219 sy-vline,
220 wa_final-km_l EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 232 sy-vline,
233 wa_final-lit_per_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED , 246 sy-vline.
ULINE.
endloop.
FORM prepare_final_rec USING p_mode TYPE char1.
SORT i_data BY equnr idate descending .
if wa_data-recdu = 'KM'.
max_km = wa_data-recdv.
min_km = wa_data-recdv.
endif.
if wa_data-recdu ='H'.
max_hr = wa_data-recdv.
min_hr = wa_data-recdv.
endif.
if wa_data-recdu ='L'.
max_lit = wa_data-recdv.
min_lit = wa_data-recdv.
endif.
at new equnr.
read table i_final into wa_final index sy-tabix.
write:/ wa_final-equnr, wa_final-eqktx ,wa_final-eqfnr ,wa_final-idate ,
'Min KM',min_km EXPONENT 0 DECIMALS 2 color 7 ,
'Min H',min_hr EXPONENT 0 DECIMALS 2 color 7 ,
'Min L',min_lit EXPONENT 0 DECIMALS 2 color 7.
endat.
*at end of equnr.
read table i_data into wa_data index sy-tabix.
write:/ wa_final-equnr, wa_final-eqktx ,wa_final-eqfnr ,wa_final-idate ,
'Max KM', max_km EXPONENT 0 DECIMALS 2 color 7,
'Max H', max_hr EXPONENT 0 DECIMALS 2 color 7,
'Max L', max_lit EXPONENT 0 DECIMALS 2 color 7.
*endat.
wa_final-max_date = wa_data-idate.
wa_final-min_date = wa_data-idate.
wa_final-max_km = wa_data-recdv.
wa_final-min_km = wa_data-recdv.
wa_final-max_hR = wa_data-recdv.
wa_final-min_hR = wa_data-recdv.
wa_final-max_lit = wa_data-recdv.
wa_final-min_lit = wa_data-recdv.
wa_final-t_max_min_km = wa_data-recdv. " min_km - max_km
wa_final-t_max_min_hr = wa_data-recdv. " min_hr - max_hr
wa_final-t_max_min_lit = wa_data-recdv. " min_lit - max_lit.
IF p_mode = 'A'.
wa_final-equnr = wa_data-equnr.
wa_final-eqktx = wa_data-eqktx.
wa_final-eqfnr = wa_data-eqfnr.
APPEND wa_final TO i_final.
ELSE.
MODIFY i_final FROM wa_final
TRANSPORTING
max_date
min_date
max_km
min_km
max_hr
min_hr
max_lit
min_lit
t_max_min_km
t_max_min_hr
where equnr = wa_data-equnr.
ENDIF.
ENDFORM. " PREPARE_FINAL_REC
regards;Hi
Thanks , where to use the loop and endloop.
I want individual data to go into wa_final but confused how to start to get
min date..max..date..minkm_value..maxkm_value...total min-max,
min_hr,max_hr,total diff , min_lit,max_lit, total as in the program but how the data will go according to the values in wa_final
regards
Piroz -
Why using workarea for internal table is better in performance
Please tell me
why using workarea for internal table is better in performanceHi Vineet ,
Why would we choose to use an internal table without a header line when it is easier to code one with a header line?
it has following reason.
1)Separate Internal Table Work Area:
The work area (staging area) defined for the internal table is not limited to use with just one internal table.
take ex-
Suppose you want two internal tables for EMPLOYEE one to contain all records and one to contain only those records where country = USA. You could create both of these internal tables without header lines and use only one work area to load data into both of them. You would append all records from the work area into the first internal table. You would conditionally append the USA records from the same work area into the second internal table.
2) Performance Issues: Using an internal table without a header line is more efficient than one with a header line
3) Nested Internal Tables: If you want to include an internal table within a structure or another internal table, you must use one without a header line.
If this one is helpful ,then rewards me
Regards
Shambhu -
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? -
Hi Friends,
See the followong code which converts xml data into itab.
*& Report ZTEST_XML1 *
REPORT ZTEST_XML1 .
*PURPOSE: This program transfers XML data into SAP internal table format
*The nodes in DOM can be stored as fields in SAP Internal table
type pool definitions
TYPE-POOLS: ixml. "iXML Library Types
type definitions
TYPES: BEGIN OF t_xml_line, "Structure for holding XML data
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, " XML Table of the structure
*t_xml_line
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. " String to hold filename
data: begin of i_final occurs 0,
pnumber(20),
pname(50),
pdes(70),
end of i_final.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'C:\product.xml'.
Validation of XML file: Only DTD included in XML document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
start of selection
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( ).
Creating a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
IF pa_val = 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
ENDIF.
Parse the stream
IF l_parser->parse( ) <> 0.
IF l_parser->num_errors( ) <> 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
text
<--P_L_XML_TABLE_SIZE text
<--P_L_XML_TABLE text
FORM get_xml_table CHANGING p_l_xml_table_size
p_l_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 = pa_file.
Upload 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
text
-->P_L_DOCUMENT text
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.
*delete adjacent duplicates from i_final.
*loop at i_final.
*write:/ i_final-pnumber,i_final-pname,i_final-pdes.
*endloop.
*if not i_final[] is initial.
*modify ztestproduct from table i_final.
*endif.
ENDFORM. " process_dom
in the above code at line no: 268 there is a method:
value = node->get_value( ).in which actual data from XML file is coming.
So the varibale "Value" contains the data.
see line no: 270:
WRITE: AT indent value COLOR COL_GROUP INVERSE.
what ever values i am getting here i want to append to a Internal table ...
Can any body tell me how to do that?
i am sure of reward points.Hai Ravi
REPORT abc.
DATA
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string .
FIRST PHASE
FIRST PHASE
FIRST PHASE
Fetch Data
SELECT * FROM t001 INTO TABLE t001.
XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = itab.
Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = 'd:\xx.xml'
TABLES
data_tab = itab.
SECOND PHASE
SECOND PHASE
SECOND PHASE
BREAK-POINT.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\XX.XML'
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[].
Regards
Sreeni -
Function module to get data into internal table from Excel file sheets
Hi,
I have to upload customers from excel file.
we are donloading customer data excel file sheets.
Customer data in 1 sheet, tax data the other sheet of same excel file, Customer master-Credit data in other sheet of same excel file.
so i have 3-4 sheet in one excel file.
now my requirement is to get the data from excel file into internal table.
is there any function module.
Thanks & RegardsI am sending you the idea with an example how you can upload data from an EXCEL file into an internal table. I am not sure if you can take data from different sheet in the same EXCEL file. I think that this is not possible (try it )
Upload the data into an internal table, like the way that I am describing in the above:
DATA: L_MAX_COL_NB TYPE I.
DATA: l_file_name LIKE RLGRAP-FILENAME.
Just to be sure that is the correct type for the FM.
l_file_name = P_FILE_NAME.
L_MAX_COL_NB = 58. "Maximum nb of colums that the FM can read.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = l_file_name
I_BEGIN_COL = 1
I_BEGIN_ROW = 2
I_END_COL = L_MAX_COL_NB
I_END_ROW = 9999
TABLES
INTERN = PT_EXCEL
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
Now you should upload the data into your own itab. The Function Module will return to you all the an itab
from all fields and columns. Define the structure of the uploading file into SE11 - Data Dictionary. Then read the fieldcatalog of this structure. In the code that I am sending to you, I am insearting an empty line into the internal table and then I am assigning this line into a corresponding field-symbol. Then I am able to change the working area - so and the line of the itab. Propably you could you the statement APPEND INITIAL LINE TO (your_table_name) ASSIGNING <your_field_symbol>, but the example was written in an old SAP version.
FIELD-SYMBOLS:
<F_REC> LIKE WA_UPLOAD_FILE, "working are of the uploading file
<F_FIELD> TYPE ANY.
DATA: COLUMN_INT TYPE I,
C_FIELDNAME(30) TYPE C.
PERFORM GET_FIELDCATOLG TABLES FIELDCAT
USING 'ZECO_CHARALAMBOUS_FILE'.
LOOP AT PT_EXCEL.
AT NEW ROW.
ASSIGN WA_UPLOAD_FILE TO <F_REC>.
ENDAT.
COLUMN_INT = PT_EXCEL-COL.
READ TABLE FIELDCAT INTO WA_FIELDCAT INDEX COLUMN_INT.
CONCATENATE '<F_REC>-' WA_FIELDCAT-FIELDNAME INTO C_FIELDNAME.
ASSIGN (C_FIELDNAME) TO <F_FIELD>.
<F_FIELD> = PT_EXCEL-VALUE.
AT END OF ROW.
APPEND WA_UPLOAD_FILE TO GT_UPLOAD_FILE.
CLEAR WA_UPLOAD_FILE.
ENDAT.
ENDLOOP.
With Regards
George
Edited by: giorgos michaelaris on Mar 4, 2010 3:44 PM -
Hi Experts,
I am new comer to ABAP, have some very important task to be done, need help from all of you. I have a program which displays the results(inform about the infocubes). I want to insert the output of this prgm into an internal table, I am looking lot into the documentation, but so far not much help and i am not able to execute it. And one more task, I want to join this internal table and one database table and get the result, my question is , Is it possible to join this internal table and database table based on some common field.
Any help will be of grt help
Thanks,
Hem.Hi,
For joining internal table with database table,you need to write the logic as below.
This is the pseudo code.
select * from database into table itab2 where condition.
loop at itab1 into wa1.
move-corresponding wa1 to wa3.
loop at itab2 into wa2 where field = wa1-field.
move-corresponding wa2 to wa3.
endloop.
append wa3 to itab3.
endloop.
1. select the required data from database table into internal table.
2. loop the first internal table which you already have.
3. Based on the key fields in these two internal tables[database],place the condition in READ or LOOP statement for the second internal table inside the loop of the first internal table.
4. If there are more records in second internal table for a single record in first internal table,then use LOOP the second internal table within the first internal table.Otherwise, read the second internal table within the first internal table.
5.Then move the corresponding fields from both the internal tables inside the loop to third internal table.Append the record to the third internal table.
Hope it helps.
Regards,
J.Jayanthi -
Read info about files in specific folder into internal table
Hi Experts
I need to have last modified date and filename information read into an internal table. I need to read in the information of all files in a specific (UNIX) folder (I do not know the name of the single files).
I really hope someone can help.
Thanks a lot
Kind regards,
TorbenHi Guys
Thanks a lot for you input.
I managed to get my program to works as follows:
REPORT ZDELETE_ARCHIVING_FILES.
*Step 1: Get the list of files in the directory into internal table :
DATA: DLIST LIKE EPSFILI OCCURS 0 WITH HEADER LINE,
DPATH LIKE EPSF-EPSDIRNAM,
MDATE LIKE SY-DATUM,
MTIME LIKE SY-UZEIT.
DATA: BEGIN OF FATTR OCCURS 0,
FILE_NAME LIKE EPSF-EPSFILNAM,
FILE_SIZE LIKE EPSF-EPSFILSIZ,
FILE_OWNER LIKE EPSF-EPSFILOWN,
FILE_MODE LIKE EPSF-EPSFILMOD,
FILE_TYPE LIKE EPSF-EPSFILTYP,
FILE_MTIME(12),
END OF FATTR.
DATA: P_PATH(50) TYPE C.
CONCATENATE '/ARCHIVE/' sy-sysid '/archive' INTO P_PATH.
* WRITE: / P_PATH.
DPATH = P_PATH.
*Get files in folder - read into internal table DLIST
*if filenames are longer than 40 characters
*then use FM SUBST_GET_FILE_LIST.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
DIR_NAME = DPATH
TABLES
DIR_LIST = DLIST
EXCEPTIONS
INVALID_EPS_SUBDIR = 1
SAPGPARAM_FAILED = 2
BUILD_DIRECTORY_FAILED = 3
NO_AUTHORIZATION = 4
READ_DIRECTORY_FAILED = 5
TOO_MANY_READ_ERRORS = 6
EMPTY_DIRECTORY_LIST = 7
OTHERS = 8.
IF SY-SUBRC EQ 0.
*Step 2: Read the file attributes into an internal table
*Read info about the files (attributes) into the internal table FATTR
*as we need info about the last time it was changed (MTIME)
LOOP AT DLIST.
CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
EXPORTING
FILE_NAME = DLIST-NAME
DIR_NAME = DPATH
IMPORTING
FILE_SIZE = FATTR-FILE_SIZE
FILE_OWNER = FATTR-FILE_OWNER
FILE_MODE = FATTR-FILE_MODE
FILE_TYPE = FATTR-FILE_TYPE
FILE_MTIME = FATTR-FILE_MTIME
EXCEPTIONS
READ_DIRECTORY_FAILED = 1
READ_ATTRIBUTES_FAILED = 2
OTHERS = 3.
IF SY-SUBRC EQ 0.
FATTR-FILE_NAME = DLIST-NAME.
APPEND FATTR.
ENDIF.
ENDLOOP.
SORT FATTR BY FILE_NAME.
DATA: time(10), date LIKE sy-datum.
DATA: months TYPE i.
DATA: e_file TYPE string.
LOOP AT FATTR.
CLEAR: time, months, e_file.
IF FATTR-FILE_NAME(10) = 'archive_BW'.
*Convert the unix time into readable time
PERFORM p6_to_date_time_tz(rstr0400) USING FATTR-FILE_MTIME
time
date.
*Calculate the number of months between date (MTIME) and current day
*ex 31.03.2009 - 01.04.2009 = 1 month
*ex 01.02.2009 - 01.04.2009 = 2 month
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_von = date
i_datum_bis = sy-datum
IMPORTING
e_monate = months.
CONCATENATE DPATH '/' FATTR-FILE_NAME INTO e_file.
* WRITE: / FATTR-FILE_NAME,
* FATTR-FILE_SIZE,
* date,
* time,
* sy-datum,
* months,
* e_file.
*Step 3: Delete files where months > 1
IF months > 1.
OPEN dataset e_file for output in text mode encoding default.
DELETE dataset e_file.
CLOSE dataset e_file.
ENDIF. "months > 1
ENDIF.
ENDLOOP.
ENDIF. -
Read Application server file and upload into internal table
Another help needed guys,
My file in the application server is of format
Name Marks 1 Marks 2 Marks 3............
A 10 15 20
The only thing separating the columns is space.
Actually this file was downloaded from an internal table into the app server.
Now I want to load it back into the internal table.
How do I load this into internal table so that each column goes in separate internal table field.
Currently am using cl_abap_char_utilities=>HORIZONTAL_TAB but I can get only the first column name in my field1 of the internal table.
How should I applroach this?
Points will be awarded for useful answers.
Regards
AnkitHi ankit,
i think u have uploaded the tab delimited file in the application sever.
then suppose see if u r file is in the format of name#marks1#marks2#marks3.
then in the program u do like this..
first declare one internal table with one filed.
data:
c_hextab(1) TYPE x VALUE '09'.
data:
begin of t_data occurs 0,
line(256) type c,
endof t_data.
and declare one more intternal table
data:
begin of t_itab occurs 0,
name(15) type c,
marks1(4) type c,
marks2(4) type c,
marks3(4) type c,
endof t_itab.
then
open the file with
OPEN DATASET p_file FOR INPUT IN TEXT MODE.
then between do and endo do like this..
DO.
clear t_data.
READ DATASET p_file INTO t_data.
if sy-subrc ne 0.
exit.
else.
split t_data at c_hextab
into t_itab-name
t_itab-marks1
t_itab-marks2
t_itab-marks3.
append t_itab.
endif.
enddo.
i think it will be helpful to u
Please let me know wht type of file has been uploaded into application server.(tab deleimted, comma separated or something else).
Regards,
Sunil Kumar Mutyala. -
Import an open office spreadsheet into internal table
hi all,
i have one requirment to import excel into sap but i dont have MS office on my system
is there any way to import an open office spreadsheet into internal table
by using ALSM_EXCEL_TO_INTERNAL_TABLE fm or any other ways.Hi,
You can use this function module 'ALSM_EXCEL_TO_INTERNAL_TABLE',
It works fine, Here is a sample code hwich I developed and working fine.
FIELD-SYMBOLS: <FS1>.
Variables
DATA: LV_BEGCOL TYPE I VALUE 1,
LV_BEGROW TYPE I VALUE 1,
LV_ENDCOL TYPE I VALUE 100,
LV_ENDROW TYPE I VALUE 32000.
DATA: LV_FILENAME LIKE RLGRAP-FILENAME.
DATA: LV_ZWLEN TYPE I,
LV_ZWLINES TYPE I.
DATA: LV_TIND(4) TYPE N.
DATA: LV_ZWFELD(30).
DATA: KZHEADER TYPE XFELD.
Internal Tables
DATA: BEGIN OF LT_INTERN OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA: END OF LT_INTERN.
DATA: BEGIN OF LT_INTERN1 OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA: END OF LT_INTERN1.
DATA: BEGIN OF LT_COL OCCURS 0,
COL LIKE ALSMEX_TABLINE-COL,
SIZE TYPE I.
DATA: END OF LT_COL.
DATA: BEGIN OF LT_FIELDNAMES OCCURS 3,
TITLE(60),
TABLE(6),
FIELD(10),
KZ(1),
END OF LT_FIELDNAMES.
No of columns
DATA: BEGIN OF LT_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).
DATA: END OF LT_DATA_TAB.
Initialization
LV_FILENAME = P_UFILE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = LV_FILENAME
I_BEGIN_COL = LV_BEGCOL
I_BEGIN_ROW = LV_BEGROW
I_END_COL = LV_ENDCOL
I_END_ROW = LV_ENDROW
TABLES
INTERN = LT_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
WRITE:/ 'Uploading Error'(019), SY-SUBRC.
ENDIF.
Arrange Data
LOOP AT LT_INTERN.
LT_INTERN1 = LT_INTERN.
CLEAR LT_INTERN1-ROW.
APPEND LT_INTERN1.
ENDLOOP.
SORT LT_INTERN1 BY COL.
LOOP AT LT_INTERN1.
AT NEW COL.
LT_COL-COL = LT_INTERN1-COL.
APPEND LT_COL.
ENDAT.
LV_ZWLEN = STRLEN( LT_INTERN1-VALUE ).
READ TABLE LT_COL WITH KEY COL = LT_INTERN1-COL.
IF SY-SUBRC EQ 0.
IF LV_ZWLEN > LT_COL-SIZE.
LT_COL-SIZE = LV_ZWLEN.
Internal Table, Current Row Index
MODIFY LT_COL INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDLOOP.
DESCRIBE TABLE LT_COL LINES LV_ZWLINES.
SORT LT_INTERN BY ROW COL.
IF KZHEADER = 'X'.
LOOP AT LT_INTERN.
LT_FIELDNAMES-TITLE = LT_INTERN-VALUE.
APPEND LT_FIELDNAMES.
AT END OF ROW.
EXIT.
ENDAT.
ENDLOOP.
ELSE.
DO LV_ZWLINES TIMES.
WRITE SY-INDEX TO LT_FIELDNAMES-TITLE.
APPEND LT_FIELDNAMES.
ENDDO.
ENDIF.
SORT LT_INTERN BY ROW COL.
LOOP AT LT_INTERN.
IF KZHEADER = 'X'
AND LT_INTERN-ROW = 1.
CONTINUE.
ENDIF.
LV_TIND = LT_INTERN-COL.
CONCATENATE 'LT_DATA_TAB-VALUE_' LV_TIND INTO LV_ZWFELD.
ASSIGN (LV_ZWFELD) TO <FS1>.
<FS1> = LT_INTERN-VALUE.
AT END OF ROW.
APPEND LT_DATA_TAB.
CLEAR LT_DATA_TAB.
ENDAT.
ENDLOOP.
Thanks & Regards,
Dileep .C -
How to transfer data of RFC into Internal Table inside a WD4A program?
Hi Experts,
I have created WD4A program. This program calls RFC. The output of RFC has to populate a UI table. THe different cells of the table should have different color based on data.
I have gone through following link:
http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/707fb792-c181-2d10-61bd-ce15d58b5cf1
The above link fetches data from directly from table. Then it passes the data into internal table.
If I am using RFC, then how I can insert data of RFC into a internal table in WD4A program (se80 In drop down Web Dynpro Comp / Intf)
My motto is to have table ouput whose different cells should have different color based on data.
Please help.
Regards,
Gary
Edited by: Jason Lax on Dec 28, 2011 2:52 PM (Fixed broken link)Hi Experts,
I have resolved the issue. I have created WD4A program. This WD4A program calls the RFC.
The RFC has a structure as export parameters called 'RESULT_FINAL'. I have altered the associated type of this table export parameter. I added Component 'Color' of component type 'WDUI_TABLE_CELL_DESIGN'.
In the RFC I have added some code. The code is as below:
loop at it_t1.
select pernr from pa0000 into table it_t2 where pernr = it_t1-pernr and stat2 ='3'
and begda <= sy-datum AND endda >= sy-datum.
if sy-subrc = 0.
result_final-org_unit = result_objec-objid.
result_final-pernr = it_t1-pernr.
result_final-name = it_t1-name.
result_final-color = '02'. append result_final.
endif.
endloop.
The line result_final-color = '02'.
code returns Color.
In the WD4A program, I have changed the Cell Design property of selected table coloumn to Color.
This resolved the issue.
Thanks every one for the reply.
I have added above information for other SDN users.
I am closing this thread,
Regards,
Gary -
Urgent - Append data to internal table from Application server
Hi All,
I encountered the problem while read the input file from Application server...then append it to internal table. I manage to read the input file from presentation and append the data to internal table.
Below are my coding which cause me not able the append data from Application server. Please kindly help me to solving/correct my coding. Thanks in advance .
PARAMETERS : p_inpfl LIKE rlgrap-filename. "Material Input File
SELECTION-SCREEN BEGIN OF LINE.
Application Server
SELECTION-SCREEN COMMENT 1(19) text-002 FOR FIELD rb_ux.
SELECTION-SCREEN POSITION 33.
PARAMETERS: rb_ux RADIOBUTTON GROUP g1.
Presentation Server
SELECTION-SCREEN COMMENT 40(21) text-003 FOR FIELD rb_pc.
SELECTION-SCREEN POSITION 65.
PARAMETERS: rb_pc RADIOBUTTON GROUP g1 DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK b01.
FORM f_Input_file.
CLEAR: v_f_exists.
CHECK NOT p_inpfl IS INITIAL. "input file exist
IF NOT rb_pc IS INITIAL. " Pc check
PERFORM f_read_tab_delimited_file TABLES i_input
USING c_09
p_inpfl
rb_ux
CHANGING v_ifile_str_with_tab
v_f_exists
v_ifile_record_count
v_message.
IF v_f_exists EQ '1' .
UPLOAD FILE could not be read
MESSAGE e546 .
ENDIF .
IF v_ifile_record_count EQ 0 .
Zero records in upload file
MESSAGE e547 .
ENDIF.
ELSE.
OPEN DATASET p_inpfl FOR INPUT IN TEXT MODE.
DO.
READ DATASET p_inpfl INTO i_input.
IF sy-subrc EQ 0.
APPEND i_input.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_inpfl.
ENDIF.Hi,
Refere the following code for the poulating internal from the application server.
PARAMETERS : pr_sfile TYPE filename-fileintern,
Here give the logical file name from the application serevr.
data : w_param_1 LIKE filename-fileintern,
x_file(500),
w_move_file LIKE epsf-epsfilnam,
w_from_dir LIKE epsf-epsdirnam,
w_path LIKE rlgrap-filename,
input_line(1000),
w_path LIKE rlgrap-filename,
w_file LIKE rlgrap-filename,
w_dir LIKE rlgrap-filename,
w_dir1 LIKE epsf-epsdirnam,
w_file1 LIKE epsf-epsfilnam,
**************Start of the code***************
MOVE '*' TO w_param_1.
PERFORM get_file_name USING pr_sfile w_param_1.
LOOP AT it_file WHERE name CP w_file1.
CLEAR : x_file, w_path,
w_move_file, w_from_dir.
REFRESH : it_input,
it_input_err.
IF w_flag IS INITIAL.
CONCATENATE w_dir it_file-name INTO x_file.
CONDENSE x_file.
TO Move file from sever for backup storing the file name and path
w_path = x_file.
CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = x_file
IMPORTING
stripped_name = w_move_file
file_path = w_from_dir
EXCEPTIONS
x_error = 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.
********here it_input will be the structure of the file present on the application server
PERFORM read_file TABLES it_input
USING x_file.
CLEAR it_input_err.
REFRESH it_input.
ENDLOOP.
*******************end of the code****************
*& Form read_file
text
-->P_X_FILE text
FORM read_file TABLES it_tab
USING x_file.
OPEN DATASET x_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
WRITE : / text-006.
ELSE.
DO.
READ DATASET x_file INTO input_line.
IF sy-subrc = 0.
CLEAR: it_input, count.
DO.
ADD 1 TO count.
ASSIGN COMPONENT count OF STRUCTURE it_tab TO <fs>.
IF sy-subrc = 0.
SPLIT input_line AT separator INTO <fs> input_line.
ELSE.
EXIT.
ENDIF.
ENDDO.
APPEND it_tab.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET x_file.
*& Form get_file_name
text
-->P_P_SFILE text
-->P_W_PARAM_1 text
FORM get_file_name USING p_sfile
w_param_1.
CHANGING x_file.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
client = sy-mandt
logical_filename = p_sfile
parameter_1 = w_param_1
IMPORTING
file_name = x_file
EXCEPTIONS
file_not_found = 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.
w_path = x_file.
CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = w_path
IMPORTING
stripped_name = w_file
file_path = w_dir
EXCEPTIONS
x_error = 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.
w_dir1 = w_dir.
w_file1 = w_file.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = w_dir1
file_mask = w_file1
TABLES
dir_list = it_file
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
IF sy-subrc <> 0.
WRITE : / text-006.
ENDIF.
Hope this will help you. -
How to transfer excel files(on ftp server) into internal table?
hello,everyone
pls tell me how to transfer excel files those on a ftp server into internal table?
ps.i know the function 'ftp_server_to_r3',it can help to transfer flat file.Hi,
I believe you want to get the data from the FTP Server to R3.
I am also sending the code. Have a look and it would help you.
First get the Password and user name and the FTP Server Path where file is stored and FTP Server Host name
FUNCTION zfi_ftp_get.
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_FILENAME) TYPE C
*" TABLES
*" T_BLOB STRUCTURE ZFI_TLM_LENGTH OPTIONAL " is a table type with a field called line of length 992
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
DATA : i_password(30) TYPE c,
i_user(30) TYPE c,
i_host(30) TYPE c,
i_rfc_destination TYPE rfcdes-rfcdest,
i_length TYPE i,
i_folder_path(100) TYPE c.
DATA: lv_blob_length TYPE i.
DATA: lv_length TYPE i, "Password length
lv_key TYPE i VALUE 26101957,
lv_password(30) TYPE c,
lv_ftp_handle TYPE i,
lv_cmd(80) TYPE c.
DATA: BEGIN OF result OCCURS 0,
line(100) TYPE c,
END OF result.
TYPES: BEGIN OF ty_dummy,
line(392) TYPE c,
END OF ty_dummy.
DATA: lt_dummy TYPE TABLE OF ty_dummy,
ls_dummy LIKE LINE OF lt_dummy.
i_password = 'vnhdh'.
i_user = 'sdkgd'.
i_host = 'sbnksbg'.
i_rfc_destination = 'SAPFTP'.
i_length = '992'.
i_folder_path = '/hioj/hohjk/hh'.
lv_length = STRLEN( i_password ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = i_password
sourcelen = lv_length
key = lv_key
IMPORTING
destination = lv_password.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = i_user
password = lv_password
host = i_host
rfc_destination = i_rfc_destination
IMPORTING
handle = lv_ftp_handle
EXCEPTIONS
not_connected = 1
OTHERS = 2.
IF sy-subrc = 1.
return-type = 'E' .
return-message = 'FTP Connection not Successful'.
APPEND return.
ELSEIF sy-subrc = 2.
return-type = 'E' .
return-message = 'FTP Connection not Successful'.
APPEND return.
ELSEIF sy-subrc EQ 0.
return-type = 'S' .
return-message = 'FTP Connection Successful'.
APPEND return.
CONCATENATE 'cd' i_folder_path INTO lv_cmd SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_ftp_handle
command = lv_cmd
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc = 1.
return-type = 'E' .
return-message = 'Command Error Occured during open of FTP Folder'.
APPEND return.
ELSEIF sy-subrc = 2.
return-type = 'E' .
return-message = 'TCIP Error Occured during open of FTP Folder'.
APPEND return.
ELSE.
REFRESH t_blob.
lv_blob_length = 992.
TRANSLATE i_filename TO LOWER CASE.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = lv_ftp_handle
fname = i_filename
IMPORTING
blob_length = lv_blob_length
TABLES
blob = lt_dummy.
t_blob[] = lt_dummy[].
ENDIF.
ENDIF.
ENDFUNCTION.
Regards
Sajid
Edited by: shaik sajid on Nov 16, 2010 7:25 AM -
How to upload the flat file records into internal table by position?
Hi
I have a flat file which has 7 records in each row and they are NOT provided with CSV or Tab demilited...
They are continous text without spaces....
but i know the fixed length of each field Eg : 1st field 7 char and seconc field 3 char and so on...
How can i upload this file into internal table by reading positions of each field...I know we can use GUI_UPLOAD and Read dataset and Open dataset...
But please let me know to read the file with the fixed postions and load into internal table...
Thanks in advance
MMHi
As per my knowledge i dont think thr is some function module or so to read with a fixed positions.
You can use the below method if you think this is the best way.
Suppose your file has
types : begin of ty_itab,
field1 type char7,
field2 type char3,
field3 type chat3,
field4 type char3,
end of ty_itab.
types : begin of ty_upload,
str type string,
end of ty_upload.
data : it_itab type standatd table of ty_itab,
it_upload type standard table ot ty_upload,
wa_itab type ty_itab,
wa_upload type ty_upload.
use gui_upload.get the data in it_upload.
here you know that u have first 16 charcters makes a first row n then next 16 charcters next row
Loop at it_upload into wa_upload.
v_len = strlen ( wa_upload ).
v_len = v_len / 16.
You get number of rows per record ,if it is decimal value make it final value if 3.9 make to 4.
do v_len times.
wa_itab = wa_upload.
By this only first 16 characters are moved and respective fields will get a value.or else u can use offset
wa_upload+0(16).
append wa_itab to it_itab.
Now shift 16 characters using shift command in wa_upload.
enddo.
endloop.
Hope this syntax help you to resolve your issue.May be something i have missed .Right now i don't have sap system to send you the full correct syntax code.
Cheers
Joginder
Maybe you are looking for
-
HT1311 How do I delete an old Apple ID for the sake of updating?
I have managed to change my Apple ID but when my ipod touch updates it still comes up with the old ID. Ive checked in my iTunes & App Store and it has the correct ID. How do I remove the old ID completely?
-
How do i autorise music from iPod to iMac?
put music from ipod to new imac and don't know how to autorise it
-
Hi, I can't get my old wacom intuos2 to work with mountain lion, any suggestions? Apart from buy a new tablet.
-
Stupid Question of the Week.
Ok, I hesitate to ask this, but for the sake of efficiency (not wanting to peruse the manual at this time).... here goes... I want to change the density, and/or color balance, (or whatever) on 100 images simultaneously.... is there a method of doing
-
Change Adobe Camera Raw background color
Anybody know how to change the background color in Adobe Camera Raw from grey to white?