Excel data transfer into SAP internal table with GUI_UPLOAD
hi all,
i m using SRM4 system and i wanted to develop one report which will upload data from excel and convert it into IT.
i know that many threads are posted on this topic.
but my requirement is slight different. in the system only one function module is available that is "GUI_UPLOAD" and we want that user shd not save file as tab delimited before calling this fm. instead, program shd take care of all these things...
please suggest something asap..
helpful ans will be rewarded..
thanks,
jigs.
Dear Jigs,
Please go though the following lines of code:
D A T A D E C L A R A T I O N *
TABLES: ANEP,
BKPF.
TYPES: BEGIN OF TY_TABDATA,
MANDT LIKE SY-MANDT, " Client
ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number
ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred
ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year
ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period
ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1
ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2
ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3
END OF TY_TABDATA.
Declaration of the Internal Table with Header Line comprising of the uploaded data.
DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
DATA: END OF IT_FILE_UPLOAD.
S E L E C T I O N - S C R E E N *
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,
BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK B2,
END OF BLOCK B1.
E V E N T : AT S E L E C T I O N - S C R E E N *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = 'X'
MASK = '.'
CHANGING
FILE_NAME = P_FNAME
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.
E V E N T : S T A R T - O F - S E L E C T I O N *
START-OF-SELECTION.
Upload Excel file into Internal Table.
PERFORM UPLOAD_EXCEL_FILE.
Organize the uploaded data into another Internal Table.
PERFORM ORGANIZE_UPLOADED_DATA.
E V E N T : E N D - O F - S E L E C T I O N *
END-OF-SELECTION.
*& Form UPLOAD_EXCEL_FILE
text
--> p1 text
<-- p2 text
FORM UPLOAD_EXCEL_FILE .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FNAME
I_BEGIN_COL = 1
I_BEGIN_ROW = 3
I_END_COL = 7
I_END_ROW = 32000
TABLES
INTERN = IT_FILE_UPLOAD
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.
ENDFORM. " UPLOAD_EXCEL_FILE
*& Form ORGANIZE_UPLOADED_DATA
text
--> p1 text
<-- p2 text
FORM ORGANIZE_UPLOADED_DATA .
SORT IT_FILE_UPLOAD BY ROW
COL.
LOOP AT IT_FILE_UPLOAD.
CASE IT_FILE_UPLOAD-COL.
WHEN 1.
WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.
WHEN 2.
WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.
WHEN 3.
WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.
WHEN 4.
WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.
WHEN 5.
WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.
WHEN 6.
WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.
WHEN 7.
WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.
ENDCASE.
AT END OF ROW.
WA_TABDATA-MANDT = SY-MANDT.
APPEND WA_TABDATA TO IT_TABDATA.
CLEAR: WA_TABDATA.
ENDAT.
ENDLOOP.
ENDFORM. " ORGANIZE_UPLOADED_DATA
In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.
Regards,
Abir
Don't forget to award points *
Similar Messages
-
Mass data load into SAP R/3 - with XI?
Hi guys!
I have an issue - mass data migration into SAP R/3. Is XI a good solution? It will be about 60GB of data. Or is there a better way of this data load?
Thanx a lot!
Olianhi,
SAP doesn't recomment using XI for mass data migration
and 60 Gb is certainly too much
use LSMW for that purpose
Regards,
michal -
Selecting into an internal table with deep structure
Hi,
I am working in ECC 6.0 now and it is giving me a syntax error for the following code.
types: tt_bdc type standard table of bdcmsgcoll
with default key.
data: begin of t_test occurs 0,
vbeln like vbak-vbeln,
tab type tt_bdc,
end of t_test.
select vbeln from vbak into table t_test
where aedat > '20081101'.
The error is:
+The work area (or internal table) "T_TEST" is not flat, or contains
reference or internal tables as components . components. components.
components. components.+
I've done this in countless other programs in the past. How can I use a deep structure this way? What am I missing?
Thanks very much!Will this solve ur requirement -
types: tt_bdc type standard table of bdcmsgcoll
with default key.
data: begin of t_test occurs 0,
vbeln like vbak-vbeln,
tab type tt_bdc,
end of t_test.
select vbeln from vbak into
CORRESPONDING FIELDS OF TABLE t_test
where aedat > '20081101'. -
I want to convert XML file into SAP Internal table
Hi Frndz,
My xml file is:
<?xml version="1.0" ?>
- <!-- Comments: START DATE :1/11/2002 11:26:14 PM
-->
- <!-- Comments: RFID Tags read by Mercury4 Copyright Praff@Anantara Solutions
-->
<RFIDs><ID>0x303030303030303035050000B5EC</ID><ID>0x300833B2DDD901403505000042E7</ID></RFIDs>
i want to take those 2 ID's in a internal table that id field is of 28 character type....
very urgent.
Thanks,
Arunprasad.Pclass cl_ixml definition load.
type-pools: ixml.
types: begin of t_xml_line,
data(256) type x,
end of t_xml_line,
begin of tsfixml,
data(1024) type c,
end of tsfixml.
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:\WINDOWS\Desktop\RFIDTags.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 FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = l_filename
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = l_xml_table_size
HEADER =
TABLES
DATA_TAB = l_xml_table
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.
data: name2 type string,
name_root type string,
node_parent type ref to if_ixml_node,
node_root type ref to if_ixml_node,
num_children 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.
num_children = node->num_children( ).
case node->get_type( ).
when if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
node_root = node->get_root( ).
name_root = node_root->get_name( ).
write: / 'ELEMENT :'.
write: at indent name color col_positive inverse.
write: 'NUM_CHILDREN:', num_children.
write: 'ROOT:', name_root.
node_parent = node->get_parent( ).
name2 = node_parent->get_name( ).
write: 'NAME2: ' , name2.
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 :'.
node_parent = node->get_parent( ).
write: at indent value color col_group inverse.
name2 = node_parent->get_name( ).
write: 'NAME2: ' , name2.
endcase.
*advance to next node
node = iterator->get_next( ).
endwhile.
endform. "process_dom
Thanks,
Arunprasad.P -
Data Transfer between two internal tables
Hi SDN,
If I have two internal tables itab_a and Itab_b and I want to copy a subset of itab_a to itab_b using a conditional statement, is it possible and how?
Second, what if I want to append the smaller internal table itab_b to itab_a, how would you do that.
My task is to take some of the rows from a into b, change one field and append back to a. So if a had 100 rows, now it would have 110.
Please help.
Thanks.
Saf.If I have two internal tables itab_a and Itab_b and I want to copy a subset of itab_a to itab_b using a conditional statement, is it possible and how?
LOOP AT ITAB_A.
IF ITAB_A-SOME_FIELD = SOME_VALUE.
MOVE-CORRESPONDING ITAB_A TO ITAB_B.
APPEND ITAB_B.
ENDIF.
ENDLOOP. -
Data transfer to sap R/3 with no standard IDoc
Hi all,
I have a situation where i need to transfer data to and fro between SAP R/3 system and an Oracle database.
The data getting transfered is HR data.
For this transfer there is no suitable standard IDOC which can be used.
In this situation what should be our approach?
Pls guide as soon as possible, since its a bit urgent.
Thanks in advance.
Regards
NeetuHi Neetu,
If sap WAB AS is >= 6.20 then u can use Abap Proxies(SPROXY) in SAP instead of calling IDOC...
Check this link
D:\helpdata\EN\86\58cd3b11571962e10000000a11402f\content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/ab/585f3c482a7331e10000000a114084/content.htm
and weblog..
/people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies
Regards,
Sridhar
Message was edited by: sridhar reddy kondam -
Access db upload to SAP internal table table
Dear friends.
i am supposed to develop a program that upload the MS-Access DB table to SAP internal table. I have received the code wich is ok...but i am failed to provide it porper input as i am not receiving n e values in internall tables. please help me to understand this program i am providing you its source code which i received from this forum only...apart from it, is there n e other alternative to upload the data from MS access to SAP . I have Ms Access Data base db2.mdb as per the prgram and db2.mdb has tab (table). please see the code and help me in this regards..thanking you,,,
REPORT ZYSH01.
INCLUDE ole2incl.
DATA: con TYPE ole2_object,
rec TYPE ole2_object.
DATA SQL(1023).
DATA: BEGIN OF SPL OCCURS 0,
VAL(1023),
END OF SPL.
DATA: BEGIN OF I1 OCCURS 0,
F1(10) ,
F2 TYPE I,
END OF I1.
IF con-header IS INITIAL OR con-handle = -1.
CREATE OBJECT con 'ADODB.Connection'.
IF NOT sy-subrc = 0.
EXIT.
ENDIF.
CREATE OBJECT REC 'ADODB.Recordset'.
IF NOT sy-subrc = 0.
EXIT.
ENDIF.
ENDIF.
MDB connetion infomations ....
CONCATENATE 'Provider=' '''Microsoft.Jet.OLEDB.4.0''' ';'
INTO SQL.
CONCATENATE SQL 'Password=' '''''' ';'
INTO SQL.
CONCATENATE SQL 'User ID=' '''Admin''' ';'
INTO SQL.
CONCATENATE SQL 'Data Source=' '''C:\db2.mdb''' ';'
INTO SQL.
CONCATENATE SQL 'Mode=' '''Share Deny None'''
INTO SQL.
MDB connection ...
CALL METHOD OF CON 'Open'
EXPORTING #1 = SQL.
Query (insert) statement ...
SQL = 'insert into [test] values('.
CONCATENATE SQL '''A''' ',' '''1''' ')' INTO SQL.
Query run ...
CALL METHOD OF REC 'Open'
EXPORTING #1 = SQL
#2 = CON
#3 = '1'.
Query (select) statement ...
SQL = 'select * from[test]'.
Query run ...
CALL METHOD OF REC 'Open'
EXPORTING #1 = SQL
#2 = CON
#3 = '1'.
Selecting MDB record into SAP internal table ...
DO.
CALL METHOD OF REC 'getstring' = SQL
EXPORTING #1 = '2' "Do not modify!
#2 = 1 "Do not modify!
#3 = '|' "Do not modify!
#4 = '|'. "Do not modify!
IF SUBRC EQ 0.
REFRESH SPL. CLEAR SPL.
SPLIT SQL AT '|' INTO TABLE SPL.
LOOP AT SPL.
CASE SY-TABIX.
WHEN 1.
I1-F1 = SPL-VAL.
WHEN OTHERS.
I1-F2 = SPL-VAL.
ENDCASE.
ENDLOOP.
APPEND I1. CLEAR I1.
ELSE.
EXIT.
ENDIF.
ENDDO.
Result writing ...
LOOP AT I1.
WRITE: AT /1(10) I1-F1,
AT (10) I1-F2.
ENDLOOP.
connetion close & destroy
FREE OBJECT con.
FREE OBJECT rec.Hi,
Make one proves, but:
CALL METHOD OF CON 'Open'
EXPORTING #1 = SQL.
return -> <b>sy-subrc = 2.</b>
Please, helpme.
Thank you.
Arecio -
How to fetch the data from query to internal table ?
Dear all ,
I would like to fetch the query data(sq01) into my internal table ? is it possible to do that ?
Best Regards,
CarlosHi
Try this <b>RRW3_GET_QUERY_VIEW_DATA</b>
Also, you can have a look at this...
<a href="/people/durairaj.athavanraja/blog/2005/04/03/execute-bw-query-using-abap-part-ii Query results into Internal table</a>
Regards
Raj -
Data transfer from sap r/3 into excel sheet for mi01
hi gurus,
as i am a xi consultant i got requirement to write a program for data transfer from sap r/3 into excel sheet for MI01.can any body help me by giving sample code or example for this requirement.please help me.Hi Rohit,
This is an upload program and it has used both function modules to upload from an excel to R3 and to download from R3 onto excel.
GUI_UPLOAD
GUI_DOWNLOAD
are the function modules used.
Hope this helps,
*Output: Downloads error records onto presentation server,
* Displays report with number of success and error records
REPORT ZMCG047CONTR NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID ZM.
*& Table declarations
TABLES : T001W, "Plants/Branches
T024E, "Purchasing Organizations
T001. "Company Codes
* TYPE-POOLS DECLARATION
TYPE-POOLS : SLIS.
* Types Declaration *
TYPES: BEGIN OF T_RECORD, "record storing contract info
LIFNR(010), "Vendor Number
EVART(004), "Agreement Type
EKORG(004), "Purchasing Organization
EKGRP(003), "Purchasing Group
WERKS(004), "Plant
LGORT(004), "Storage Location
KDATB(010), "Valid start Date
KDATE(010), "Valid End Date
ZTERM(004), "Payment Terms
KTWRT(020), "Target Value
EPSTP(001), "Item Category
EMATN(018), "Material Number
KTMNG(017), "Target Quantity
NETPR(014), "Net Price
PEINH(006), "Net Price Unit
BPRME(003), "Net Price Order Price Unit
IDNLF(035), "Vendor Material number
WEBRE(001), "GR Based-IV
MEPRF(001), "Pricing Date Category
LTEX1(040), "Info Text
DATAB(010), "Valid From
DATBI(010), "Valid To
KSCHL(004), "Condition Type
KBETR(016), "Condition Rate if scale is not given
KONWA(005), "Currency
KPEIN(005), "Condition Pricing Unit
KMEIN(003), "Condition Unit of Measure
KSTBM(019), "Scale
KBETR_01(016), "Scale Rate
DEL_FLAG, "Delete Flag Indicator
ERR_MSG(100), "Error Message
END OF T_RECORD,
BEGIN OF T_ERR_RECORD, "to have error records stored
LIFNR(010), "Vendor Number
EVART(004), "Agreement Type
EKORG(004), "Purchasing Organization
EKGRP(003), "Purchasing Group
WERKS(004), "Plant
LGORT(004), "Storage Location
KDATB(010), "Valid start Date
KDATE(010), "Valid End Date
ZTERM(004), "Payment Terms
KTWRT(020), "Target Value
EPSTP(001), "Item Category
EMATN(018), "Material Number
KTMNG(017), "Target Quantity
NETPR(014), "Net Price
PEINH(006), "Net Price Unit
BPRME(003), "Net Price Order Price Unit
IDNLF(035), "Vendor Material number
WEBRE(001), "GR Based-IV
MEPRF(001), "Pricing Date Category
LTEX1(040), "Info Text
DATAB(010), "Valid From
DATBI(010), "Valid To
KSCHL(004), "Condition Type
KBETR(016), "Condition Rate if scale is not given
KONWA(005), "Currency
KPEIN(005), "Condition Pricing Unit
KMEIN(003), "Condition Unit of Measure
KSTBM(019), "Scale
KBETR_01(016), "Scale Rate
DEL_FLAG, "Delete Flag Indicator
ERR_MSG(100), "Error Message
END OF T_ERR_RECORD,
BEGIN OF T_LOEKZ, "To have deletion indicators for materials
LOEKZ(001), "Deletion indicator in purchasing document
EMATN(018), "Material Number
WERKS(004), "Plant
LGORT(004), "Storage Location
BSTYP(001), "Purchasing document category
END OF T_LOEKZ,
BEGIN OF T_MATNR, " Type definition to store details of materials
MATNR(018), "Material Number
END OF T_MATNR,
BEGIN OF T_T001, " Type definition for company codes
BUKRS(004), " Company Code
END OF T_T001,
BEGIN OF T_ZMVXREF, "Cross-Reference table type
D_ALTKN(10), "Legacy Vendor Number
D_BUKRS(4), "Legacy Company Code
M_ALTKN(10), "SAP Company Code
END OF T_ZMVXREF,
BEGIN OF T_LFA1, "Master data of vendors
LIFNR(10), "Vendor Number
END OF T_LFA1,
* Type Declaration for T024E (Company Codes)
BEGIN OF T_T024E,
EKORG LIKE T024E-EKORG, "Purchasing organization
BUKRS LIKE T024E-BUKRS, "Company Code
END OF T_T024E,
* Type Declaration for t001w (Plant)
BEGIN OF T_T001W,
WERKS LIKE T001W-WERKS, "Plant
END OF T_T001W,
* Type Declatation for String Line
BEGIN OF T_STR1, "#EC NEEDED
SLINE(6000) TYPE C,
END OF T_STR1.
TYPES: BEGIN OF T_BDCDATA. "BDC Data
INCLUDE STRUCTURE BDCDATA.
TYPES: END OF T_BDCDATA.
* Internal Tables Declaration *
DATA:
* Internal table to store input file data
I_RECORD TYPE STANDARD TABLE OF T_RECORD INITIAL SIZE 0,
* Internal table to capture errors
I_ERR_REC TYPE STANDARD TABLE OF T_ERR_RECORD INITIAL SIZE 0,
* Internal table to check for deletion indicators
I_LOEKZ TYPE STANDARD TABLE OF T_LOEKZ INITIAL SIZE 0,
* Internal table to check for material numbers
I_MATNR TYPE STANDARD TABLE OF T_MATNR INITIAL SIZE 0,
* Internal table used for storing Cross-Reference data of Vendor
I_ZMVXREF TYPE STANDARD TABLE OF T_ZMVXREF INITIAL SIZE 0,
* Internal table for holding Vendor Numbers from Master table
I_LFA1 TYPE STANDARD TABLE OF T_LFA1 INITIAL SIZE 0,
* Internal table for holding Purchase Org and Company Codes
I_T024E TYPE STANDARD TABLE OF T_T024E INITIAL SIZE 0,
* Internal table for holding Plants
I_T001W TYPE STANDARD TABLE OF T_T001W INITIAL SIZE 0,
* Internal table for storing a list of Company Codes
I_T001 TYPE STANDARD TABLE OF T_T001 INITIAL SIZE 0,
* Internal table used for ALV Reporting
I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
* Internal table used for holding List Header
I_LISTHEADER TYPE SLIS_T_LISTHEADER, "EC NEEDED
* Internal table to hold ALV Event
I_ALV_EVENT TYPE SLIS_T_EVENT,
* Internal table to hold Sort Info for ALV Report
I_SORT TYPE SLIS_T_SORTINFO_ALV,
* Internal table for BDC Data
I_BDCDATA TYPE STANDARD TABLE OF T_BDCDATA INITIAL SIZE 0,
* Internal table for messages
I_MESSTAB TYPE TABLE OF BDCMSGCOLL,
* Internal table for String line
I_STR1 TYPE STANDARD TABLE OF T_STR1 INITIAL SIZE 0.
* Work Area Declaration *
DATA:
* Work Area to hold data for the Open Contract
WA_RECORD TYPE T_RECORD,
* Work Area to hold previous record data
WA_RECORDPREV TYPE T_RECORD,
* Work Area to hold errors
WA_ERR_REC TYPE T_ERR_RECORD,
* Work Area to hold the Deletion Indicator of materials
WA_LOEKZ TYPE T_LOEKZ,
* Work Area to hold Material numbers of required materials
WA_MATNR TYPE T_MATNR, "EC NEEDED
* Work Area to hold errors occured while performing BDC
WA_MESSTAB TYPE BDCMSGCOLL,
* Work Area to hold field catalog for ALV Reports
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
* Work Area to hold list header data for ALV reports
WA_LISTHEADER TYPE SLIS_LISTHEADER,
* Work Area to hold ALV Event
WA_ALV_EVENT LIKE LINE OF I_ALV_EVENT, "EC NEEDED
* Work Area to hold Layout of ALV Report
WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
* Work Area to hold Cross-Reference data of Vendor
WA_ZMVXREF TYPE T_ZMVXREF,
* Work Area to hold Vendor Numbers from Master table
WA_LFA1 TYPE T_LFA1, "EC NEEDED
* Work Area to hold Purchase Org and Company Codes
WA_T024E TYPE T_T024E,
* Work Area to hold Company Codes
WA_T001 TYPE T_T001,
* Work Area to hold Plants
WA_T001W TYPE T_T001W,
* Work Area to hold Sort Info for ALV Report
WA_SORT TYPE SLIS_SORTINFO_ALV,
* Work Area to hold BDC Data
WA_BDCDATA TYPE T_BDCDATA,
* Work Area for String line
WA_STR1 TYPE T_STR1.
* Variables Declaration *
DATA: V_ERRMSG(500), "To temporarily store the error message
V_CONV_DATE(10) TYPE C, "To capture the converted date format
V_DATE LIKE SY-DATUM,
V_REPID LIKE SY-REPID, "holds report id
V_CROSS_REFERENCE_ERROR TYPE I, " cross-reference error
V_INPUTERROR_FLAG VALUE '', " input error status
V_FILENAME TYPE STRING, " File Name
VEN_FLAG(1), " at new status
MAT_FLAG(1), " at new status
V_IND(2) TYPE N, " index of table control
V_IND2(2) TYPE N, " index of table control
V_IND3(2) TYPE N, " index of table control
V_EVRTP1(20),
V_EPSTP1(20),
V_EMATN1(20),
V_KTMNG1(20),
V_NETPR1(20),
V_PEINH1(20),
V_BPRME1(20),
V_TCSELFLAG1(20),
V_KSCHL2(20),
V_KBETR2(20),
V_KONWA2(20),
V_KPEIN2(20),
V_KMEIN2(20),
V_SELKZ2(20),
V_KBETR3(20),
V_KSTBM3(20),
V_LINE TYPE I,
V_STR TYPE X VALUE '09',
V_EXIST TYPE C,
V_EXIST1 TYPE C,
V_ISDIR TYPE C,
V_ISDIR1 TYPE C.
* Constants Declaration *
CONSTANTS: C_TCODE(5) VALUE 'ME31K', "Trx code - Open Contract Creation
C_TRUE VALUE 'X', " Del_Flag indicator
C_LOEKZ_MARKED VALUE 'X', "Deletion indicator for material
C_INPUTERROR_FLAG_YES VALUE 'X', "Input File Indicator
C_VEN_ERR1 VALUE 1, "Error Indicator
C_16(2) VALUE '16',
C_VEN_ERR2 VALUE 2, "Error Indicator
C_VEN_ERR3 VALUE 3, "Error Indicator
C_VEN_SUCS VALUE 0, "Success Indicator
C_SUCCESS LIKE SY-SUBRC VALUE '0',
C_STRUE VALUE 'S', "Del_flag for SAP Errors
C_YTRUE VALUE 'Y', "Del_flag for Success Records
C_MSGTYP_E VALUE 'E', "holds error message type
C_MSGTYP_S VALUE 'S', "holds success message type
C_BSTYP VALUE 'K', "Purchasing Document type is Contract
C_BACKGROUND VALUE 'N', "Background mode
C_FOREGROUND VALUE 'A', "All Screen mode
C_ERRORS VALUE 'E', "Error screen mode
C_WK(2) VALUE 'WK'. "Value Contract
* Selection Screen *
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-033.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS:
* Plant
S_WERKS FOR T001W-WERKS OBLIGATORY,
* Purchase Organization
S_EKORG FOR T024E-EKORG OBLIGATORY.
* Company Code
PARAMETER P_BUKRS LIKE T001-BUKRS OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 3.
PARAMETER RB_SERVE RADIOBUTTON GROUP RBX DEFAULT 'X' USER-COMMAND U1.
SELECTION-SCREEN COMMENT 6(19) TEXT-036.
SELECTION-SCREEN POSITION 37.
PARAMETER RB_LOCAL RADIOBUTTON GROUP RBX.
SELECTION-SCREEN COMMENT 40(13) TEXT-035.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
PARAMETERS:
* Parameter holding Input File name
P_FILE LIKE RLGRAP-FILENAME
OBLIGATORY
LOWER CASE
DEFAULT 'C:\'
MODIF ID G1,
P_FILE1 LIKE RLGRAP-FILENAME
OBLIGATORY
LOWER CASE
DEFAULT '/celestica/interface/corp/in/work/'
MODIF ID G2,
* Parameter specifying Mode of calling the Transaction.
P_MODE DEFAULT 'N' OBLIGATORY,
* Check box used to test the input file.
P_TEST AS CHECKBOX DEFAULT 'X',
* Parameter holding Filename for holding Input File Errors
P_IPERR LIKE RLGRAP-FILENAME
OBLIGATORY
LOWER CASE
DEFAULT 'C:\'
MODIF ID G1,
P_IPERR1 LIKE RLGRAP-FILENAME
OBLIGATORY
LOWER CASE
DEFAULT '/celestica/interface/corp/in/work/047_Err.txt'
MODIF ID G2.
SELECTION-SCREEN END OF BLOCK B2.
* AT Selection Screen Events *
* Loop the screen to activate relative paths
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF RB_SERVE = C_TRUE AND SCREEN-GROUP1 = 'G1'.
SCREEN-OUTPUT = 0.
SCREEN-ACTIVE = 0.
SCREEN-INPUT = 0.
ELSEIF RB_LOCAL = C_TRUE AND SCREEN-GROUP1 = 'G2'.
SCREEN-OUTPUT = 0.
SCREEN-ACTIVE = 0.
SCREEN-INPUT = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
AT SELECTION-SCREEN ON BLOCK B2.
* Checking Access Authorization for the user
CALL FUNCTION 'ZU_DATA_ACCESS_AUTH_CHECK'
EXPORTING
ACTVT = C_16
P_BUKRS = P_BUKRS
TABLES
S_WERKS = S_WERKS
S_EKORG = S_EKORG
EXCEPTIONS
BUKRS_FAILED = 1
VKORG_FAILED = 2
VTWEG_FAILED = 3
EKORG_FAILED = 4
WERKS_FAILED = 5
LGNUM_FAILED = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
AT SELECTION-SCREEN ON P_BUKRS.
IF NOT P_BUKRS IS INITIAL.
SELECT SINGLE BUKRS INTO T001
FROM T001
WHERE BUKRS EQ P_BUKRS.
IF SY-SUBRC NE 0.
MESSAGE I000 WITH TEXT-089.
STOP.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
* Search Help to select Input File path.
PERFORM GET_FILE_NAME USING P_FILE.
* Check for the existence of the file.
IF RB_LOCAL EQ C_TRUE.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
FNAME = P_FILE
IMPORTING
EXIST = V_EXIST
ISDIR = V_ISDIR
EXCEPTIONS
FILEINFO_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.
IF V_ISDIR IS INITIAL.
IF V_EXIST IS INITIAL.
MESSAGE I000 WITH TEXT-018.
STOP.
ENDIF.
ELSEIF V_ISDIR EQ C_TRUE.
MESSAGE I000 WITH TEXT-068.
STOP.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IPERR.
* Search Help to select Input Error File path.
PERFORM GET_FILE_NAME USING P_IPERR.
AT SELECTION-SCREEN.
* Validate Transaction Mode
IF P_MODE <> C_BACKGROUND AND
P_MODE <> C_FOREGROUND AND
P_MODE <> C_ERRORS.
MESSAGE I000 WITH TEXT-034.
STOP.
ENDIF.
START-OF-SELECTION.
* Get the Input File Data
V_FILENAME = P_FILE.
PERFORM UPLOAD_FLATFILE_DATA TABLES I_RECORD
USING V_FILENAME.
* Sorting the data by all fields
SORT I_RECORD.
* Ensuring the padding of the empty spaces before the vendor No
CLEAR WA_RECORD.
LOOP AT I_RECORD INTO WA_RECORD.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_RECORD-LIFNR
IMPORTING
OUTPUT = WA_RECORD-LIFNR.
MODIFY I_RECORD FROM WA_RECORD
INDEX SY-TABIX
TRANSPORTING LIFNR.
CLEAR WA_RECORD.
ENDLOOP.
* Input file validation
PERFORM VALIDATE_FLATFILE_DATA.
IF P_TEST = C_TRUE.
IF I_ERR_REC[] IS INITIAL.
MESSAGE I000 WITH TEXT-032.
STOP.
ELSE.
* Display all the error records at the input level.
PERFORM DISPLAY_INPERR_RECORDS.
* Download Error File
PERFORM DOWNLOAD_ERROR_FILE.
ENDIF.
ELSE.
* Build BDC Data
PERFORM BUILD_BDC_DATA.
* Download Error File
PERFORM DOWNLOAD_ERROR_FILE.
* Display the status report.
PERFORM DISPLAY_PROCESSED_RECORDS.
ENDIF.
END-OF-SELECTION.
REFRESH: I_RECORD,
I_ERR_REC,
I_LOEKZ,
I_MATNR,
I_ZMVXREF,
I_LFA1,
I_T024E,
I_FIELDCAT,
I_LISTHEADER,
I_ALV_EVENT,
I_SORT,
I_BDCDATA,
I_MESSTAB,
I_STR1.
FREE: I_RECORD,
I_ERR_REC,
I_LOEKZ,
I_MATNR,
I_ZMVXREF,
I_LFA1,
I_T024E,
I_FIELDCAT,
I_LISTHEADER,
I_ALV_EVENT,
I_SORT,
I_BDCDATA,
I_MESSTAB,
I_STR1.
*& Form GET_file_name
* Fetches the file and path from the presentation system
* --> p1 Path along with the file name
FORM GET_FILE_NAME USING L_FILE LIKE RLGRAP-FILENAME.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',*.TXT,*.txt.'
MODE = 'O'
TITLE = TEXT-011
IMPORTING
FILENAME = L_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
CASE SY-SUBRC.
WHEN 1.
MESSAGE I000 WITH TEXT-084.
STOP.
WHEN 2.
MESSAGE I000 WITH TEXT-085.
STOP.
WHEN 3.
MESSAGE I000 WITH TEXT-086.
STOP.
WHEN 4.
MESSAGE I000 WITH TEXT-087.
STOP.
ENDCASE.
ENDFORM. " GET_file_name
*& Form upload_flatfile_data
* Uploading data from Flat File
FORM UPLOAD_FLATFILE_DATA
TABLES I_L_RECORD STRUCTURE WA_RECORD
USING L_FILENAME TYPE STRING.
DATA WA_L_RECORD TYPE T_RECORD.
* Upload the Flat file data
IF RB_LOCAL EQ C_TRUE. "File is on the Local System
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_L_RECORD
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.
CASE SY-SUBRC.
WHEN 0.
DESCRIBE TABLE I_L_RECORD LINES V_LINE.
IF V_LINE EQ 0.
MESSAGE I000 WITH TEXT-065.
STOP.
ENDIF.
WHEN 1.
MESSAGE I000 WITH TEXT-068.
STOP.
WHEN 2.
MESSAGE I000 WITH TEXT-069.
STOP.
WHEN 3.
MESSAGE I000 WITH TEXT-070.
STOP.
WHEN 4.
MESSAGE I000 WITH TEXT-071.
STOP.
WHEN 5.
MESSAGE I000 WITH TEXT-072.
STOP.
WHEN 6.
MESSAGE I000 WITH TEXT-073.
STOP.
WHEN 7.
MESSAGE I000 WITH TEXT-074.
STOP.
WHEN 8.
MESSAGE I000 WITH TEXT-075.
STOP.
WHEN 9.
MESSAGE I000 WITH TEXT-076.
STOP.
WHEN 10.
MESSAGE I000 WITH TEXT-077.
STOP.
WHEN 11.
MESSAGE I000 WITH TEXT-078.
STOP.
WHEN 12.
MESSAGE I000 WITH TEXT-079.
STOP.
WHEN 13.
MESSAGE I000 WITH TEXT-080.
STOP.
WHEN 14.
MESSAGE I000 WITH TEXT-081.
STOP.
WHEN 15.
MESSAGE I000 WITH TEXT-082.
STOP.
WHEN 16.
MESSAGE I000 WITH TEXT-083.
STOP.
ENDCASE.
CLEAR V_LINE.
ELSEIF RB_SERVE EQ C_TRUE. "File is on the Application Server
P_MODE = C_BACKGROUND.
OPEN DATASET P_FILE1 FOR INPUT IN TEXT MODE.
CHECK SY-SUBRC EQ C_SUCCESS.
CLEAR WA_STR1.
DO.
READ DATASET P_FILE1 INTO WA_STR1.
IF SY-SUBRC <> 0. " NE SUCCESS.
EXIT.
ELSEIF SY-SUBRC EQ C_SUCCESS.
APPEND WA_STR1 TO I_STR1.
CLEAR WA_STR1.
ENDIF. " ENDIF on SY-SUBRC 0 Check.
ENDDO. " ENDDO
DELETE I_STR1 WHERE SLINE EQ ' '.
DESCRIBE TABLE I_STR1 LINES V_LINE.
IF V_LINE EQ 0.
MESSAGE S000 WITH TEXT-065.
STOP.
ENDIF.
LOOP AT I_STR1 INTO WA_STR1.
CLEAR: WA_L_RECORD.
SPLIT WA_STR1-SLINE AT V_STR
INTO WA_L_RECORD-LIFNR
WA_L_RECORD-EVART
WA_L_RECORD-EKORG
WA_L_RECORD-EKGRP
WA_L_RECORD-WERKS
WA_L_RECORD-LGORT
WA_L_RECORD-KDATB
WA_L_RECORD-KDATE
WA_L_RECORD-ZTERM
WA_L_RECORD-KTWRT
WA_L_RECORD-EPSTP
WA_L_RECORD-EMATN
WA_L_RECORD-KTMNG
WA_L_RECORD-NETPR
WA_L_RECORD-PEINH
WA_L_RECORD-BPRME
WA_L_RECORD-IDNLF
WA_L_RECORD-WEBRE
WA_L_RECORD-MEPRF
WA_L_RECORD-LTEX1
WA_L_RECORD-DATAB
WA_L_RECORD-DATBI
WA_L_RECORD-KSCHL
WA_L_RECORD-KBETR
WA_L_RECORD-KONWA
WA_L_RECORD-KPEIN
WA_L_RECORD-KMEIN
WA_L_RECORD-KSTBM
WA_L_RECORD-KBETR_01
WA_L_RECORD-DEL_FLAG
WA_L_RECORD-ERR_MSG.
APPEND WA_L_RECORD TO I_L_RECORD.
CLEAR: WA_L_RECORD,
WA_STR1.
ENDLOOP.
REFRESH I_STR1.
CLOSE DATASET P_FILE1.
ENDIF.
ENDFORM.
*& Form BDC_DYNPRO
* Data populated into i_bdcdata table for program
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM.
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = C_TRUE.
APPEND WA_BDCDATA TO I_BDCDATA.
ENDFORM.
*& Form BDC_FIELD
* Data populated into i_bdcdata table for fields
FORM BDC_FIELD USING FNAM FVAL.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO I_BDCDATA.
ENDFORM.
*& Form convert_date
* Converting the data from the file format to mm/dd/yyyy format
* <--P_wa_record_kdatb Source Date
* <--p_l_conv_date Target Date
FORM CONVERT_DATE USING L_DATE
L_TAR_DATE.
CONCATENATE L_DATE+0(2)
L_DATE+3(2)
L_DATE+6(4)
INTO L_TAR_DATE.
ENDFORM. " convert_date
*& Form validate_flatfile_data
* Validating the input file
FORM VALIDATE_FLATFILE_DATA.
DATA: L_TODAY LIKE SY-DATUM,
L_STARTDATE_C LIKE SY-DATUM,
L_ENDDATE_C LIKE SY-DATUM,
L_ENDDATE_C1 LIKE SY-DATUM,
L_STARTDATE_C1 LIKE SY-DATUM,
L_STARTDATE(8),
L_ENDDATE(8).
* Fetch indicator for all records on the material, plant & storage
* location combination.
IF NOT I_RECORD[] IS INITIAL.
REFRESH I_LOEKZ.
SELECT EMATN " Material Number
WERKS " Plant
LGORT " Storage Location
BSTYP " Purchasing Document Category
LOEKZ " Deletion indicator
INTO TABLE I_LOEKZ
FROM EKPO
FOR ALL ENTRIES IN I_RECORD
WHERE EMATN = I_RECORD-EMATN
AND WERKS = I_RECORD-WERKS
AND LGORT = I_RECORD-LGORT
AND BSTYP = C_BSTYP
AND LOEKZ = C_LOEKZ_MARKED.
IF SY-SUBRC EQ 0.
SORT I_LOEKZ BY EMATN WERKS LGORT BSTYP LOEKZ.
ENDIF.
* Fetching Plants for all entries in the selection screen
REFRESH I_T001W.
SELECT WERKS "Plant
INTO TABLE I_T001W
FROM T001W
WHERE WERKS IN S_WERKS.
IF SY-SUBRC EQ 0.
SORT I_T001W BY WERKS.
ENDIF.
* Fetching materials for the plants listed in flat file
REFRESH I_MATNR.
SELECT MATNR " Material Number
INTO TABLE I_MATNR
FROM MARC
FOR ALL ENTRIES IN I_RECORD
WHERE WERKS = I_RECORD-WERKS.
IF SY-SUBRC EQ 0.
SORT I_MATNR BY MATNR.
ENDIF.
* Fetching Company Codes for repective Purchase Organizations
REFRESH I_T024E.
SELECT EKORG " Purchase Organization
BUKRS " Company Code
INTO TABLE I_T024E
FROM T024E
WHERE EKORG IN S_EKORG.
IF SY-SUBRC EQ 0.
SORT I_T024E BY EKORG.
ENDIF.
* Fetching SAP Data using Legacy Data.
REFRESH I_ZMVXREF.
SELECT D_ALTKN
D_BUKRS
M_ALTKN
INTO TABLE I_ZMVXREF
FROM ZMVXREF
FOR ALL ENTRIES IN I_RECORD
WHERE D_ALTKN = I_RECORD-LIFNR.
IF SY-SUBRC EQ 0.
SORT I_ZMVXREF BY D_ALTKN D_BUKRS.
ENDIF.
* Fetching Vendors from LFA1
IF NOT I_ZMVXREF[] IS INITIAL.
REFRESH I_LFA1.
SELECT LIFNR
INTO TABLE I_LFA1
FROM LFA1
FOR ALL ENTRIES IN I_ZMVXREF
WHERE LIFNR = I_ZMVXREF-M_ALTKN.
IF SY-SUBRC EQ 0.
SORT I_LFA1 BY LIFNR.
ENDIF.
ENDIF.
* Start Validating the flat file
CLEAR: WA_RECORD,
WA_T024E,
WA_ZMVXREF,
WA_LFA1,
WA_LOEKZ,
WA_MATNR.
LOOP AT I_RECORD INTO WA_RECORD.
L_TODAY = SY-DATUM.
L_STARTDATE = WA_RECORD-KDATB.
L_ENDDATE = WA_RECORD-KDATE.
IF WA_RECORD-DEL_FLAG IS INITIAL.
READ TABLE I_T001W INTO WA_T001W
WITH KEY WERKS = WA_RECORD-WERKS
BINARY SEARCH.
IF SY-SUBRC EQ 0.
* Cross-Reference check performed for the given Vendors
READ TABLE I_T024E INTO WA_T024E
WITH KEY EKORG = WA_RECORD-EKORG
BINARY SEARCH.
IF SY-SUBRC NE 0.
V_CROSS_REFERENCE_ERROR = C_VEN_ERR3.
ELSE.
READ TABLE I_ZMVXREF INTO WA_ZMVXREF
WITH KEY D_ALTKN = WA_RECORD-LIFNR
D_BUKRS = P_BUKRS
BINARY SEARCH.
IF SY-SUBRC EQ 0.
READ TABLE I_LFA1 INTO WA_LFA1
WITH KEY LIFNR = WA_ZMVXREF-M_ALTKN
BINARY SEARCH.
IF SY-SUBRC EQ 0.
V_CROSS_REFERENCE_ERROR = C_VEN_SUCS.
ELSE.
V_CROSS_REFERENCE_ERROR = C_VEN_ERR2.
ENDIF.
ELSE.
V_CROSS_REFERENCE_ERROR = C_VEN_ERR1.
ENDIF.
ENDIF.
* Legacy Vendor could not be mapped
IF V_CROSS_REFERENCE_ERROR EQ C_VEN_ERR1.
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES. "Inp.file err. occurd
WA_RECORD-DEL_FLAG = C_TRUE.
WA_RECORD-ERR_MSG = TEXT-007.
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR.
* Legacy Vendor is mapped but the obtained SAP vendor doesn't exist.
ELSEIF V_CROSS_REFERENCE_ERROR EQ C_VEN_ERR2.
* Inp.file err. occurd
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-DEL_FLAG = C_TRUE.
WA_RECORD-ERR_MSG = TEXT-008.
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR.
* Purchase Organization doesn't exist in T024E.
ELSEIF V_CROSS_REFERENCE_ERROR EQ C_VEN_ERR3.
* Inp.file err. occurd
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-DEL_FLAG = C_TRUE.
WA_RECORD-ERR_MSG = TEXT-014.
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE EKORG = WA_RECORD-EKORG.
* Vendor is mapped and validated successfully
ELSEIF V_CROSS_REFERENCE_ERROR EQ C_VEN_SUCS.
* Checking for the deletion indicator for that record
CONCATENATE WA_RECORD-KDATB+6(4)
WA_RECORD-KDATB+3(2)
WA_RECORD-KDATB+0(2)
INTO
L_STARTDATE.
MOVE L_STARTDATE TO L_STARTDATE_C.
CONCATENATE WA_RECORD-KDATB+6(4)
WA_RECORD-KDATB+0(2)
WA_RECORD-KDATB+3(2)
INTO
L_STARTDATE_C1.
CONCATENATE WA_RECORD-KDATE+6(4)
WA_RECORD-KDATE+3(2)
WA_RECORD-KDATE+0(2)
INTO
L_ENDDATE.
MOVE L_ENDDATE TO L_ENDDATE_C.
CONCATENATE WA_RECORD-KDATE+6(4)
WA_RECORD-KDATE+0(2)
WA_RECORD-KDATE+3(2)
INTO
L_ENDDATE_C1.
READ TABLE I_LOEKZ INTO WA_LOEKZ WITH KEY
EMATN = WA_RECORD-EMATN
WERKS = WA_RECORD-WERKS
LGORT = WA_RECORD-LGORT
BINARY SEARCH.
IF SY-SUBRC EQ 0.
* Inpfle err.occured
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-ERR_MSG = TEXT-003.
WA_RECORD-DEL_FLAG = C_TRUE. "marking the record
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR
AND EVART = WA_RECORD-EVART
AND EKORG = WA_RECORD-EKORG
AND EKGRP = WA_RECORD-EKGRP
AND WERKS = WA_RECORD-WERKS
AND LGORT = WA_RECORD-LGORT
AND KDATB = WA_RECORD-KDATB
AND KDATE = WA_RECORD-KDATE
AND ZTERM = WA_RECORD-ZTERM
AND KTWRT = WA_RECORD-KTWRT
AND EPSTP = WA_RECORD-EPSTP
AND EMATN = WA_RECORD-EMATN.
* Validating the Purchasing Organization for Blank/Null
ELSEIF WA_RECORD-EKORG IS INITIAL.
* Inpfle err.occured
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-ERR_MSG = TEXT-010.
WA_RECORD-DEL_FLAG = C_TRUE.
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR
AND EVART = WA_RECORD-EVART
AND EKORG = WA_RECORD-EKORG
AND EKGRP = WA_RECORD-EKGRP
AND WERKS = WA_RECORD-WERKS
AND LGORT = WA_RECORD-LGORT
AND KDATB = WA_RECORD-KDATB
AND KDATE = WA_RECORD-KDATE
AND ZTERM = WA_RECORD-ZTERM
AND KTWRT = WA_RECORD-KTWRT
AND EPSTP = WA_RECORD-EPSTP
AND EMATN = WA_RECORD-EMATN.
* Validating the Plant for Blank/Null
ELSEIF WA_RECORD-WERKS IS INITIAL.
* Inpfle err.occured
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-ERR_MSG = TEXT-039.
WA_RECORD-DEL_FLAG = C_TRUE.
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR
AND EVART = WA_RECORD-EVART
AND EKORG = WA_RECORD-EKORG
AND EKGRP = WA_RECORD-EKGRP
AND WERKS = WA_RECORD-WERKS
AND LGORT = WA_RECORD-LGORT
AND KDATB = WA_RECORD-KDATB
AND KDATE = WA_RECORD-KDATE
AND ZTERM = WA_RECORD-ZTERM
AND KTWRT = WA_RECORD-KTWRT
AND EPSTP = WA_RECORD-EPSTP
AND EMATN = WA_RECORD-EMATN.
* Validating the Contract Validity Start Date
ELSEIF L_STARTDATE_C1 GT L_TODAY. "#EC PORTABLE
* Inpfle err.occured
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-ERR_MSG = TEXT-004.
WA_RECORD-DEL_FLAG = C_TRUE. "marking the record
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR
AND EVART = WA_RECORD-EVART
AND EKORG = WA_RECORD-EKORG
AND EKGRP = WA_RECORD-EKGRP
AND WERKS = WA_RECORD-WERKS
AND LGORT = WA_RECORD-LGORT
AND KDATB = WA_RECORD-KDATB.
* Validating the Contract Validity End Date
ELSEIF L_ENDDATE_C1 LE L_TODAY. "#EC PORTABLE
* Inpfle err.ocrd
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
WA_RECORD-ERR_MSG = TEXT-005.
WA_RECORD-DEL_FLAG = C_TRUE. "marking the record
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR
AND EVART = WA_RECORD-EVART
AND EKORG = WA_RECORD-EKORG
AND EKGRP = WA_RECORD-EKGRP
AND WERKS = WA_RECORD-WERKS
AND LGORT = WA_RECORD-LGORT
AND KDATB = WA_RECORD-KDATB
AND KDATE = WA_RECORD-KDATE.
* Checking for Material under the Plant for Agreement Type 'WK'
ELSEIF WA_RECORD-EVART = C_WK.
READ TABLE I_MATNR INTO WA_MATNR
WITH KEY MATNR = WA_RECORD-EMATN
BINARY SEARCH.
IF SY-SUBRC NE 0.
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES. "Inpfle err.ocrd
WA_RECORD-ERR_MSG = TEXT-006.
WA_RECORD-DEL_FLAG = C_TRUE. "marking the record
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE LIFNR = WA_RECORD-LIFNR
AND EVART = WA_RECORD-EVART
AND EKORG = WA_RECORD-EKORG
AND EKGRP = WA_RECORD-EKGRP
AND WERKS = WA_RECORD-WERKS
AND LGORT = WA_RECORD-LGORT
AND KDATB = WA_RECORD-KDATB
AND KDATE = WA_RECORD-KDATE
AND ZTERM = WA_RECORD-ZTERM
AND KTWRT = WA_RECORD-KTWRT
AND EPSTP = WA_RECORD-EPSTP
AND EMATN = WA_RECORD-EMATN.
ENDIF.
ENDIF. " checking of deletion indicator
ENDIF. " checking for success of vendor cross reference
ELSE.
V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES. "Inpfle err.ocrd
WA_RECORD-ERR_MSG = TEXT-041.
WA_RECORD-DEL_FLAG = C_TRUE. "marking the record
MODIFY I_RECORD FROM WA_RECORD
TRANSPORTING DEL_FLAG
ERR_MSG
WHERE WERKS = WA_RECORD-WERKS.
ENDIF. " Plant checked to selection screen
ENDIF. " the records for which del_flag is initial
CLEAR: WA_RECORD,
WA_T024E,
WA_ZMVXREF,
WA_LFA1,
WA_LOEKZ,
WA_MATNR,
L_TODAY,
L_STARTDATE_C,
L_ENDDATE_C,
L_STARTDATE,
L_ENDDATE.
ENDLOOP.
LOOP AT I_RECORD INTO WA_RECORD.
IF WA_RECORD-DEL_FLAG = C_TRUE.
APPEND WA_RECORD TO I_ERR_REC.
CLEAR WA_RECORD.
ENDIF.
ENDLOOP.
ELSE.
MESSAGE E000 WITH TEXT-013. " no records in the flat file
STOP.
ENDIF.
ENDFORM. " validate_flatfile_data
*& Form DOWNLOAD_ERROR_FILE
* Downloads all records along with the records encountering the
* input file validation error
FORM DOWNLOAD_ERROR_FILE.
DATA L_ISDIR TYPE C.
IF V_INPUTERROR_FLAG = C_INPUTERROR_FLAG_YES.
V_FILENAME = P_IPERR.
* Check for the existence of the file.
IF RB_LOCAL EQ C_TRUE.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
FNAME = P_IPERR
IMPORTING
ISDIR = L_ISDIR
EXCEPTIONS
FILEINFO_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.
IF L_ISDIR EQ C_TRUE.
MESSAGE I000 WITH TEXT-088.
STOP.
ENDIF.
ENDIF.
IF RB_LOCAL EQ C_TRUE.
* Download the Input Error File.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = V_FILENAME
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = '#'
TABLES
DATA_TAB = I_ERR_REC
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.
ELSEIF RB_SERVE EQ C_TRUE.
OPEN DATASET P_IPERR1 FOR OUTPUT IN TEXT MODE.
CHECK SY-SUBRC EQ 0.
CLEAR WA_ERR_REC.
LOOP AT I_ERR_REC INTO WA_ERR_REC.
IF WA_ERR_REC-DEL_FLAG = C_TRUE.
TRANSFER WA_ERR_REC TO P_IPERR1.
ENDIF.
CLEAR WA_ERR_REC.
ENDLOOP.
CLOSE DATASET P_IPERR1.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_ERROR_FILE
*& Form BUILD_BDC_DATA
* Populates BDC for all the fields neccessary for Open Contract Creation
FORM BUILD_BDC_DATA.
DATA: L_MAT_INDEX TYPE I,
L_CON_INDEX TYPE I,
L_SCA_INDEX TYPE I.
CLEAR WA_BDCDATA.
REFRESH: I_BDCDATA,
I_MESSTAB.
* Processing the bdc
CLEAR: WA_RECORD,
WA_RECORDPREV,
VEN_FLAG,
MAT_FLAG.
LOOP AT I_RECORD INTO WA_RECORD.
* Checks for the del_flag of the record.
IF WA_RECORD-DEL_FLAG EQ C_TRUE
OR WA_RECORD-DEL_FLAG EQ C_STRUE.
CLEAR WA_RECORD.
CONTINUE.
ELSE.
IF WA_RECORDPREV-LIFNR NE WA_RECORD-LIFNR
OR WA_RECORDPREV-EVART NE WA_RECORD-EVART
OR WA_RECORDPREV-EKORG NE WA_RECORD-EKORG
OR WA_RECORDPREV-EKGRP NE WA_RECORD-EKGRP
OR WA_RECORDPREV-WERKS NE WA_RECORD-WERKS
OR WA_RECORDPREV-LGORT NE WA_RECORD-LGORT
OR WA_RECORDPREV-KDATB NE WA_RECORD-KDATB
OR WA_RECORDPREV-KDATE NE WA_RECORD-KDATE
OR WA_RECORDPREV-ZTERM NE WA_RECORD-ZTERM
OR WA_RECORDPREV-KTWRT NE WA_RECORD-KTWRT.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0200'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RM06E-LGORT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
* Cross-Reference check performed for the given Vendors
CLEAR WA_T024E.
READ TABLE I_T024E INTO WA_T024E
WITH KEY EKORG = WA_RECORD-EKORG
BINARY SEARCH.
IF SY-SUBRC EQ 0.
CLEAR WA_ZMVXREF.
READ TABLE I_ZMVXREF INTO WA_ZMVXREF
WITH KEY D_ALTKN = WA_RECORD-LIFNR
D_BUKRS = P_BUKRS
BINARY SEARCH.
IF SY-SUBRC EQ 0.
PERFORM BDC_FIELD USING 'EKKO-LIFNR'
WA_ZMVXREF-M_ALTKN.
ENDIF.
CLEAR WA_ZMVXREF.
ENDIF.
CLEAR WA_T024E.
PERFORM BDC_FIELD USING 'RM06E-EVART'
WA_RECORD-EVART.
PERFORM BDC_FIELD USING 'EKKO-EKORG'
WA_RECORD-EKORG.
PERFORM BDC_FIELD USING 'EKKO-EKGRP'
WA_RECORD-EKGRP.
PERFORM BDC_FIELD USING 'RM06E-WERKS'
WA_RECORD-WERKS.
PERFORM BDC_FIELD USING 'RM06E-LGORT'
WA_RECORD-LGORT.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0201'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'EKKO-KTWRT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=AB'.
PERFORM CONVERT_DATE USING WA_RECORD-KDATB V_CONV_DATE.
PERFORM BDC_FIELD USING 'EKKO-KDATB'
V_CONV_DATE.
PERFORM CONVERT_DATE USING WA_RECORD-KDATE V_CONV_DATE.
PERFORM BDC_FIELD USING 'EKKO-KDATE'
V_CONV_DATE.
PERFORM BDC_FIELD USING 'EKKO-ZTERM'
WA_RECORD-ZTERM.
PERFORM BDC_FIELD USING 'EKKO-KTWRT'
WA_RECORD-KTWRT.
VEN_FLAG = 1.
L_MAT_INDEX = 1. "index for table-control of material
ENDIF.
* "first check for itemline
IF WA_RECORDPREV-EPSTP NE WA_RECORD-EPSTP
OR WA_RECORDPREV-EMATN NE WA_RECORD-EMATN
OR WA_RECORDPREV-KTMNG NE WA_RECORD-KTMNG
OR WA_RECORDPREV-NETPR NE WA_RECORD-NETPR
OR WA_RECORDPREV-PEINH NE WA_RECORD-PEINH
OR WA_RECORDPREV-BPRME NE WA_RECORD-BPRME
OR WA_RECORDPREV-IDNLF NE WA_RECORD-IDNLF
OR WA_RECORDPREV-WEBRE NE WA_RECORD-WEBRE
OR WA_RECORDPREV-MEPRF NE WA_RECORD-MEPRF
OR WA_RECORDPREV-LTEX1 NE WA_RECORD-LTEX1
OR VEN_FLAG EQ 1.
V_IND = L_MAT_INDEX.
IF V_IND GT 1.
V_IND = 2.
ENDIF.
CONCATENATE 'RM06E-EVRTP(' V_IND ')' INTO V_EVRTP1.
CONCATENATE 'RM06E-EPSTP(' V_IND ')' INTO V_EPSTP1.
CONCATENATE 'EKPO-EMATN(' V_IND ')' INTO V_EMATN1.
CONCATENATE 'EKPO-KTMNG(' V_IND ')' INTO V_KTMNG1.
CONCATENATE 'EKPO-NETPR(' V_IND ')' INTO V_NETPR1.
CONCATENATE 'EKPO-PEINH(' V_IND ')' INTO V_PEINH1.
CONCATENATE 'EKPO-BPRME(' V_IND ')' INTO V_BPRME1.
CONCATENATE 'RM06E-TCSELFLAG(' V_IND ')' INTO V_TCSELFLAG1.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0220'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=NP'.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0220'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
V_EVRTP1.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=DETA'.
PERFORM BDC_FIELD USING V_EPSTP1
WA_RECORD-EPSTP.
PERFORM BDC_FIELD USING V_EMATN1
WA_RECORD-EMATN.
PERFORM BDC_FIELD USING V_KTMNG1
WA_RECORD-KTMNG.
PERFORM BDC_FIELD USING V_NETPR1
WA_RECORD-NETPR.
PERFORM BDC_FIELD USING V_PEINH1
WA_RECORD-PEINH.
PERFORM BDC_FIELD USING V_BPRME1
WA_RECORD-BPRME.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0211'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'EKPO-WEBRE'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=DETZ'.
PERFORM BDC_FIELD USING 'EKPO-IDNLF'
WA_RECORD-IDNLF.
TRANSLATE WA_RECORD-EVART TO UPPER CASE.
IF WA_RECORD-EVART EQ C_WK.
PERFORM BDC_FIELD USING 'EKPO-WEBRE' 'X'.
ENDIF.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0212'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'EKPO-MEPRF'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=TXP'.
PERFORM BDC_FIELD USING 'EKPO-MEPRF'
WA_RECORD-MEPRF.
IF NOT WA_RECORD-LTEX1 IS INITIAL. "NE space.
PERFORM BDC_DYNPRO USING 'SAPMM06E' '0106'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RM06E-SELKZ(02)'.
PERFORM BDC_FIELD -
Uploading excel file into internal table with field length more than 255
I am trying to upload the data from an excel file through function module 'TEXT_CONVERT_XLS_TO_SAP'.
I have tested by changing the field type from string, and char2000.
But it is accepting only 255 chars from the cell content.
How to get the total content of the field if it is more than 255 char.hi,
you can use any of the following procedures:
For uploading data from excel to internal table refer standard report RC1TCG3Z in se38 :
or
You can use the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' itself. Please check if you have done it this way . But, this FM can be a little time consuming if the excel has large data, so you can use the FM u2018GUI_UPLOADu2019.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file1
i_begin_col = l_b1
i_begin_row = l_c1
i_end_col = l_b2
i_end_row = l_c2
TABLES
intern = lt_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e018 DISPLAY LIKE 'i'.
ENDIF.
*---Removing the first heading fields from the file.
IF NOT lt_data[] IS INITIAL.
LOOP AT lt_data INTO lwa_data WHERE row = '0001'.
DELETE lt_data.
CLEAR lwa_data.
ENDLOOP.
*---Inserting the data from file the internal table
LOOP AT lt_data INTO lwa_data.
CASE lwa_data-col.
WHEN 1.
wa_file_wicopa-serial = lwa_data-value.
WHEN 2.
wa_file_wicopa-blart = lwa_data-value.
WHEN 3.
wa_file_wicopa-bldat = lwa_data-value.
WHEN 4.
wa_file_wicopa-budat = lwa_data-value.
ENDCASE.
AT END OF row.
APPEND wa_file_wicopa TO gt_file_wicopa.
CLEAR wa_file_wicopa.
ENDAT.
CLEAR lwa_data.
ENDLOOP.
ENDIF.
ENDIF.
or
DATA: it_test TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE.
DATA :v_start_col TYPE i VALUE '1',
v_start_row TYPE i VALUE '1',
v_end_col TYPE i VALUE '256',
v_end_row TYPE i VALUE '65536',
v_text TYPE repti.
* Funtion Module to upload values from excel to the Internal table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = v_start_col
i_begin_row = v_start_row
i_end_col = v_end_col
i_end_row = v_end_row
TABLES
intern = it_test
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.
Or
You can use FM u201CTEXT_CONVERT_XLS_TO_SAPu201D.
DATA : i_raw TYPE truxs_t_text_data.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_tab_raw_data = i_raw
i_filename = p_path
TABLES
i_tab_converted_data = itab
EXCEPTIONS
conversion_failed = 1
OTHERS = 2
hope it will help u
regards
rahul -
How to read data in correct format from EXCEL file into an internal table??
Hi Experts,
My requirement is to upload data from an excel file on presentation server into an internal table on <b>SRM</b> server.
I used 'GUI_UPLOAD' function module to achieve the same but all the the data is getting uploaded in # only.I had set in the 'HAS_FIELD_SEPARATOR' to 'X' to overcome this problem.
But all the efforts are in vain. The function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' doesn't exist on SRM Server and I am not getting any other function module having similar functionality available on SRM server.
I have written the following code:-
TYPES: BEGIN OF ty_addr_loc,
userid TYPE xubname, "User Id
addr_code TYPE char4, "3 Digit Site Location Code/4 Digit
"Alternate Address
loc_id TYPE bbp_location, "Indicator: Address is standard address
END OF ty_addr_loc.
*Retrieving file name
parameters: p_file type rlgrap-filename.
DATA:
Local variable holding file name
l_file TYPE string,
Local Variable holding the file type,
l_type TYPE filetype VALUE 'ASC',
Local Variable holding the field separator
l_sep TYPE char01,
i_tab type standard table of ty_addr_loc.
Clearing local variables
CLEAR:
l_file,
l_sep.
Initializing the local variables
MOVE p_file TO l_file.
l_sep = 'X'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = l_type
has_field_separator = l_sep
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 = i_tab
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.
Throwing an information message
MESSAGE i003. "Data Upload Failed
LEAVE LIST-PROCESSING.
ENDIF.
Please tell me a way out. I have to make a delivery urgently.
Thanks in advance,
Swati GuptaHi
Try the FM <b>KCD_EXCEL_OLE_TO_INT_CONVERT</b>
Sample:
call function 'KCD_EXCEL_OLE_TO_INT_CONVERT'
exporting
filename = i_filename
i_begin_col = l_begin_col
i_begin_row = l_begin_row
i_end_col = l_end_col
i_end_row = l_end_row
tables
intern = xt_intern
exceptions
INCONSISTENT_PARAMETERS = 201
UPLOAD_OLE = 201.
if sy-subrc <> 0.
e_subrc = sy-subrc.
exit.
endif.
<b>reward if Helpful.</b> -
How to read a table and transfer the data into an internal table?
Hello,
I try to read all the data from a table (all attribute values from a node) and to write these data into an internal table. Any idea how to do this?
Thanks for any help.Hi,
Check this code.
Here i creates context one node i.e flights and attributes are from SFLIGHT table.
DATA: lo_nd_flights TYPE REF TO if_wd_context_node,
lo_el_flights TYPE REF TO if_wd_context_element,
ls_flights TYPE if_main=>element_flights,
it_flights type if_main=>elements_flights.
navigate from <CONTEXT> to <FLIGHTS> via lead selection
lo_nd_flights = wd_context->get_child_node( 'FLIGHTS' ).
CALL METHOD LO_ND_FLIGHTS->GET_STATIC_ATTRIBUTES_TABLE
IMPORTING
TABLE = it_flights.
now the table data will be in internal table it_flights. -
Read file from ftp SERVER(NON SAP) into an internal table
Hi all,
I need to read the data from an excel file which was uploaded from ftp (i.e different server) into an SAP internal table by using FTP connections.
Actually i am already getting text file data successfully.
But only when reading in excel file that is presented in JDA server.
Facing problem to read excel file data from JDA server.
Pls help me.
How can we go ahead ?
Kindly suggest with the help of some code.Hi Lokesh,
Currently I need to interface JDA and SAP.
Can you kindly recommend how to handle this? -
Download the KTOPL field data and GLT0 table data into one Internal table
Hi,
I have downloaded GLT0 table fields data to PC file . But i need to download KTOPL(Chart Of Accounts) data also. in GLT0 table there is no KTOPL field.
But in SKA1 table have KTOPL field. Then what is the issue is GLT0 data & KTOPL field data needs to download into one Internal Table.
anybody could you please solve this problem. immediately need to solve this.
Below is the code.
REPORT ZFXXEABL_1 NO STANDARD PAGE HEADING
LINE-SIZE 200.
Tables Declaration
TABLES : GLT0.
Data Declaration
DATA : FP(8) TYPE C,
YEAR LIKE GLT0-RYEAR,
PERIOD(3) TYPE C,
DBALANCE LIKE VBAP-NETWR VALUE 0 ,
CBALANCE LIKE VBAP-NETWR VALUE 0.
*Internal table for for final data..
DATA : BEGIN OF REC1 OCCURS 0,
BAL LIKE GLT0-TSLVT value 0,
COAREA LIKE GLT0-RBUSA,
CA(4) TYPE C,
KTOPL LIKE ska1-ktopl,
CCODE LIKE GLT0-BUKRS,
CREDIT LIKE VBAP-NETWR,
CURRENCY LIKE GLT0-RTCUR,
CURTYPE(2) TYPE N,
DEBIT LIKE VBAP-NETWR,
YEAR(8) TYPE C,
FY(2) TYPE C,
ACCOUNT LIKE GLT0-RACCT,
VER LIKE GLT0-RVERS,
VTYPE(2) TYPE N,
CLNT LIKE SY-MANDT,
S_SYS(3) TYPE C,
INDICATOR LIKE GLT0-DRCRK,
END OF REC1.
DATA : C(2) TYPE N,
D(2) TYPE N.
DATA REC1_H LIKE REC1.
Variable declarations
DATA :
W_FILES(4) TYPE N,
W_DEBIT LIKE GLT0-TSLVT,
W_CREDIT LIKE GLT0-TSLVT,
W_PCFILE LIKE RLGRAP-FILENAME ,
W_UNIXFILE LIKE RLGRAP-FILENAME,
W_PCFILE1 LIKE RLGRAP-FILENAME,
W_UNIXFIL1 LIKE RLGRAP-FILENAME,
W_EXT(3) TYPE C,
W_UEXT(3) TYPE C,
W_PATH LIKE RLGRAP-FILENAME,
W_UPATH LIKE RLGRAP-FILENAME,
W_FIRST(1) TYPE C VALUE 'Y',
W_CFIRST(1) TYPE C VALUE 'Y',
W_PCFIL LIKE RLGRAP-FILENAME.
DATA: "REC LIKE GLT0 OCCURS 0 WITH HEADER LINE,
T_TEMP LIKE GLT0 OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF REC3 OCCURS 0.
INCLUDE STRUCTURE GLT0.
DATA: KTOPL LIKE SKA1-KTOPL,
END OF REC3.
DATA: BEGIN OF T_KTOPL OCCURS 0,
KTOPL LIKE SKA1-KTOPL,
SAKNR LIKE SKA1-SAKNR,
END OF T_KTOPL.
Download data.
DATA: BEGIN OF I_REC2 OCCURS 0,
BAL(17), " like GLT0-TSLVT value 0,
COAREA(4), " like glt0-rbusa,
CA(4), " chart of accounts
CCODE(4), " like glt0-bukrs,
CREDIT(17), " like vbap-netwr,
CURRENCY(5), " like glt0-rtcur,
CURTYPE(2), " type n,
DEBIT(17), " like vbap-netwr,
YEAR(8), " type c,
FY(2), " type c, fiscal yr variant
ACCOUNT(10), " like glt0-racct,
VER(3), " like glt0-rvers,
VTYPE(3), " type n,
CLNT(3), "like sy-mandt,
S_SYS(3), "like sy-sysid,
INDICATOR(1), " like glt0-drcrk,
END OF I_REC2.
Selection screen. *
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1.
SELECT-OPTIONS : COMPCODE FOR GLT0-BUKRS,
GLACC FOR GLT0-RACCT,
FISYEAR FOR GLT0-RYEAR,
no intervals no-extension, "- BG6661-070212
FISCPER FOR GLT0-RPMAX,
busarea for glt0-rbusa,
CURRENCY FOR GLT0-RTCUR.
SELECTION-SCREEN END OF BLOCK BL1.
SELECTION-SCREEN BEGIN OF BLOCK BL2 WITH FRAME TITLE TEXT-BL2.
PARAMETERS:
P_UNIX AS CHECKBOX, "Check box for Unix Option
P_UNFIL LIKE RLGRAP-FILENAME, " Unix file Dnload file name
default '/var/opt/arch/extract/GLT0.ASC', "- BG6661-070212
P_PCFILE AS CHECKBOX, "Check box for Local PC download.
P_PCFIL LIKE RLGRAP-FILENAME " PC file Dnload file name
default 'C:\GLT0.ASC'. "- BG6661-070212
DEFAULT 'C:\glt0_gl_balance_all.asc'. "+ BG6661-070212
SELECTION-SCREEN END OF BLOCK BL2.
*eject
Initialization. *
INITIALIZATION.
Try to default download filename
p_pcfil = c_pcfile.
p_unfil = c_unixfile.
if sy-sysid eq c_n01.
p_unfil = c_unixfile.
endif.
if sy-sysid eq c_g21.
p_unfil = c_g21_unixfile.
endif.
if sy-sysid eq c_g9d.
p_unfil = c_g9d_unixfile.
endif.
Default for download filename
*{ Begin of BG6661-070212
CONCATENATE C_UNIXFILE
SY-SYSID C_FSLASH C_CHRON C_FILENAME INTO P_UNFIL.
*} End of BG6661-070212
AT SELECTION-SCREEN OUTPUT.
loop at screen.
if screen-name = 'P_PCFIL'. "PC FILE
screen-input = '0'.
modify screen.
endif.
if screen-name = 'P_UNFIL'. "UN FILE
screen-input = '0'.
modify screen.
endif.
endloop.
if w_first = 'Y'.
perform path_file.
w_first = 'N'.
endif.
if w_cfirst = 'Y'.
perform cpath_file.
w_cfirst = 'N'.
endif.
Start-of-Selection. *
START-OF-SELECTION.
*COLLECT DATA
PERFORM COLLECT_DATA.
*BUILD FILENAMES
PERFORM BUILD_FILES.
*LOCAL
IF P_PCFILE = C_YES.
PERFORM LOCAL_DOWNLOAD.
ENDIF.
*UNIX
IF P_UNIX = C_YES.
PERFORM UNIX_DOWNLOAD.
ENDIF.
IF P_PCFILE IS INITIAL AND P_UNIX IS INITIAL.
MESSAGE I000(ZL) WITH 'Down load flags both are unchecked'.
ENDIF.
END-OF-SELECTION.
IF P_PCFILE = C_YES.
WRITE :/ 'PC File' , C_UNDER, P_PCFIL.
ENDIF.
*& Form DOWNLOAD
Download *
FORM DOWNLOAD.
P_PCFIL = W_PATH.
DATA LIN TYPE I.
DESCRIBE TABLE I_REC2 LINES LIN.
WRITE:/ 'No of Records downloaded = ',LIN.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = P_PCFIL
FILETYPE = C_ASC "c_dat "dat
TABLES
DATA_TAB = I_REC2 " t_str
fieldnames = t_strhd
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC EQ 0.
ENDIF.
ENDFORM.
*& Form WRITE_TO_SERVER
text *
--> p1 text
<-- p2 text
FORM WRITE_TO_SERVER.
DATA : L_MSG(100) TYPE C,
L_LINE(5000) TYPE C.
P_UNFIL = W_UPATH.
DATA LIN TYPE I.
DESCRIBE TABLE I_REC2 LINES LIN.
WRITE:/ 'No of Records downloaded = ',LIN.
OPEN DATASET P_UNFIL FOR OUTPUT IN TEXT MODE. " message l_msg.
IF SY-SUBRC <> 0.
WRITE: / L_MSG.
ENDIF.
perform header_text1.
LOOP AT I_REC2.
TRANSFER I_REC2 TO P_UNFIL.
ENDLOOP.
CLOSE DATASET P_UNFIL.
WRITE : / C_TEXT , W_UPATH.
SPLIT W_UNIXFILE AT C_DOT INTO W_UNIXFIL1 W_UEXT.
CLEAR W_UPATH.
IF NOT W_UEXT IS INITIAL.
CONCATENATE W_UNIXFIL1 C_DOT W_UEXT INTO W_UPATH.
ELSE.
W_UEXT = C_ASC. " c_csv.
CONCATENATE W_UNIXFIL1 C_DOT W_UEXT INTO W_UPATH.
ENDIF.
ENDFORM. " WRITE_TO_SERVER
*& Form BUILD_FILES
FORM BUILD_FILES.
IF P_PCFILE = C_YES.
W_PCFILE = P_PCFIL.
***Split path at dot**
SPLIT W_PCFILE AT C_DOT INTO W_PCFILE1 W_EXT.
IF NOT W_EXT IS INITIAL.
CONCATENATE W_PCFILE1 C_DOT W_EXT INTO W_PATH.
ELSE.
W_PATH = W_PCFILE1.
ENDIF.
ENDIF.
IF P_UNIX = C_YES.
W_UNIXFILE = P_UNFIL.
SPLIT W_UNIXFILE AT C_DOT INTO W_UNIXFIL1 W_UEXT.
IF NOT W_UEXT IS INITIAL.
CONCATENATE W_UNIXFIL1 C_DOT W_UEXT INTO W_UPATH.
ELSE.
W_UPATH = W_UNIXFIL1.
ENDIF.
ENDIF.
ENDFORM.
FORM CPATH_FILE.
CLEAR P_PCFIL.
CONCATENATE C_PCFILE
C_COMFILE SY-SYSID C_UNDER SY-DATUM SY-UZEIT
C_DOT C_ASC INTO P_PCFIL.
ENDFORM. " CPATH_FILE
FORM PATH_FILE.
CLEAR P_UNFIL.
if sy-sysid eq c_n01.
CONCATENATE C_UNIXFILE
C_COMFILE SY-SYSID C_UNDER SY-DATUM SY-UZEIT
C_DOT C_ASC INTO P_UNFIL.
endif.
if sy-sysid eq c_g21.
concatenate c_g21_unixfile
c_comfile sy-sysid c_under sy-datum sy-uzeit
c_dot c_asc into p_unfil.
endif.
if sy-sysid eq c_g9d.
concatenate c_g9d_unixfile
c_comfile sy-sysid c_under sy-datum sy-uzeit
c_dot c_asc into p_unfil.
endif.
ENDFORM. " PATH_FILE
Local_Download *
Local *
FORM LOCAL_DOWNLOAD.
perform header_text.
LOOP AT REC1.
REC1-CLNT = SY-MANDT.
REC1-S_SYS = SY-SYSID.
MOVE: REC1-BAL TO I_REC2-BAL,
REC1-COAREA TO I_REC2-COAREA,
REC1-CA TO I_REC2-CA,
REC1-KTOPL TO I_REC2-CA,
REC1-CCODE TO I_REC2-CCODE,
REC1-CREDIT TO I_REC2-CREDIT,
REC1-CURRENCY TO I_REC2-CURRENCY,
REC1-CURTYPE TO I_REC2-CURTYPE,
REC1-DEBIT TO I_REC2-DEBIT,
REC1-YEAR TO I_REC2-YEAR,
REC1-FY TO I_REC2-FY,
REC1-ACCOUNT TO I_REC2-ACCOUNT,
REC1-VER TO I_REC2-VER,
REC1-VTYPE TO I_REC2-VTYPE,
REC1-CLNT TO I_REC2-CLNT,
REC1-S_SYS TO I_REC2-S_SYS,
REC1-INDICATOR TO I_REC2-INDICATOR.
APPEND I_REC2.
CLEAR I_REC2.
ENDLOOP.
IF NOT I_REC2[] IS INITIAL.
PERFORM DOWNLOAD .
CLEAR I_REC2.
REFRESH I_REC2.
ELSE.
WRITE : / ' no record exist due to unavailability of data'.
ENDIF.
ENDFORM. " LOCAL_DOWNLOAD
*& Form UNIX_DOWNLOAD
FORM UNIX_DOWNLOAD.
LOOP AT REC1.
REC1-CLNT = SY-MANDT.
REC1-S_SYS = SY-SYSID.
MOVE: REC1-BAL TO I_REC2-BAL,
REC1-COAREA TO I_REC2-COAREA,
REC1-CA TO I_REC2-CA,
REC1-KTOPL TO I_REC2-CA,
REC1-CCODE TO I_REC2-CCODE,
REC1-CREDIT TO I_REC2-CREDIT,
REC1-CURRENCY TO I_REC2-CURRENCY,
REC1-CURTYPE TO I_REC2-CURTYPE,
REC1-DEBIT TO I_REC2-DEBIT,
REC1-YEAR TO I_REC2-YEAR,
REC1-FY TO I_REC2-FY,
REC1-ACCOUNT TO I_REC2-ACCOUNT,
REC1-VER TO I_REC2-VER,
REC1-VTYPE TO I_REC2-VTYPE,
SY-MANDT TO I_REC2-CLNT,
SY-SYSID TO I_REC2-S_SYS,
REC1-INDICATOR TO I_REC2-INDICATOR.
APPEND I_REC2.
CLEAR I_REC2.
ENDLOOP.
IF NOT I_REC2[] IS INITIAL.
PERFORM WRITE_TO_SERVER.
CLEAR I_REC2.
REFRESH I_REC2.
ELSE.
WRITE : / ' no record exist due to unavailability of data'.
ENDIF.
ENDFORM. " UNIX_DOWNLOAD
*& Form HEADER_TEXT
text *
--> p1 text
<-- p2 text
*form header_text.
concatenate c_bal c_ba c_ca c_cc c_credit c_currency c_curtype
c_debit c_fisyear c_fisvar c_acct c_ver c_vtype c_indicator
into t_strhd
separated by c_comma.
append t_strhd.
*endform. " HEADER_TEXT
*& Form HEADER_TEXT1
text *
*form header_text1.
concatenate c_bal c_ba c_ca c_cc c_credit c_currency c_curtype
c_debit c_fisyear c_fisvar c_acct c_ver c_vtype c_indicator
into t_strhd1
separated by c_comma.
append t_strhd1.
transfer t_strhd1 to p_unfil.
*endform. " HEADER_TEXT1
*& Form COLLECT_DATA
Collect Data *
FORM COLLECT_DATA.
SELECT * FROM GLT0 INTO TABLE REC3
WHERE BUKRS IN COMPCODE
AND RYEAR IN FISYEAR
AND RPMAX IN FISCPER
AND RACCT IN GLACC
AND RTCUR IN CURRENCY.
SELECT KTOPL FROM SKA1
INTO TABLE T_KTOPL
FOR ALL ENTRIES IN REC3
WHERE SAKNR = REC3-RACCT.
LOOP AT REC3 .
select *
from glt0
into table t_temp
where rldnr = rec-rldnr
and rrcty = rec-rrcty
and rvers = rec-rvers
and bukrs = rec-bukrs
and ryear = rec-ryear
and racct = rec-racct
and rbusa = rec-rbusa
and rtcur <> 'ZAR'
and rpmax = rec-rpmax.
if sy-subrc = 0.
rec1-bal = '0.00'.
else.
rec1-bal = rec-hslvt.
endif.
*READ TABLE T_KTOPL WITH KEY SAKNR = REC-RACCT BINARY SEARCH.
MOVE T_KTOPL-KTOPL TO REC3-KTOPL.
CLEAR: CBALANCE, DBALANCE.
REC1-BAL = REC3-HSLVT.
IF REC3-DRCRK = 'S'.
IF REC3-HSLVT NE C_ZERO.
YEAR = REC-RYEAR.
PERIOD = '000'.
CONCATENATE PERIOD C_DOT YEAR INTO FP.
REC1-INDICATOR = REC-DRCRK.
REC1-DEBIT = C_ZERO.
REC1-CREDIT = C_ZERO.
REC1-CCODE = REC-BUKRS.
REC1-YEAR = FP.
REC1-CURRENCY = REC-RTCUR.
REC1-ACCOUNT = REC-RACCT.
rec1-bal = rec-hslvt.
dbalance = rec1-bal.
REC1-CURTYPE = C_CTYPE.
REC1-FY = C_FY.
REC1-COAREA = REC-RBUSA.
REC1-VER = REC-RVERS.
REC1-VTYPE = C_CTYPE.
REC1-CA = C_CHART.
APPEND REC1.
C = 0.
PERFORM D.
ENDIF.
IF REC3-HSL01 NE C_ZERO.
YEAR = REC3-RYEAR.
PERIOD = '001'.
CONCATENATE PERIOD C_DOT YEAR INTO FP.
REC1-INDICATOR = REC3-DRCRK.
REC1-DEBIT = REC3-HSL01 .
REC1-CCODE = REC3-BUKRS.
REC1-YEAR = FP.
REC1-CURRENCY = REC3-RTCUR.
REC1-ACCOUNT = REC3-RACCT.
rec1-bal = REC3-hsl01 + dbalance.
dbalance = rec1-bal.
REC1-CURTYPE = C_CTYPE.
REC1-FY = C_FY.
REC1-COAREA = REC3-RBUSA.
REC1-VER = REC3-RVERS.
REC1-VTYPE = C_CTYPE.
REC1-CA = C_CHART.
REC1-KTOPL = REC3-KTOPL.
APPEND REC1.
C = 1.
PERFORM D.
ENDIF.
IF REC3-HSL02 NE C_ZERO.
REC1-DEBIT = REC3-HSL02.
YEAR = REC3-RYEAR.
PERIOD = '002'.
CONCATENATE PERIOD C_DOT YEAR INTO FP.
REC1-INDICATOR = REC3-DRCRK.
REC1-DEBIT = REC3-HSL02.
REC1-CCODE = REC3-BUKRS.
REC1-YEAR = FP.
REC1-CURRENCY = REC3-RTCUR.
REC1-ACCOUNT = REC3-RACCT.
rec1-bal = REC3-hsl02 + dbalance.
dbalance = rec1-bal.
REC1-CURTYPE = C_CTYPE.
REC1-FY = C_FY.
REC1-COAREA = REC3-RBUSA.
REC1-VER = REC3-RVERS.
REC1-VTYPE = C_CTYPE.
REC1-CA = C_CHART. "-BF7957-070503
REC1-KTOPL = REC3-KTOPL. "+BF7957-070503
APPEND REC1.
C = 2.
PERFORM D.
ENDIF.
IF REC3-HSL03 NE C_ZERO.
YEAR = REC3-RYEAR.
PERIOD = '003'.
CONCATENATE PERIOD C_DOT YEAR INTO FP.
REC1-INDICATOR = REC3-DRCRK.
REC1-DEBIT = REC3-HSL03.
REC1-CCODE = REC3-BUKRS.
REC1-YEAR = FP.
REC1-CURRENCY = REC3-RTCUR.
REC1-ACCOUNT = REC3-RACCT.
rec1-bal = REC3-hsl03 + dbalance .
dbalance = rec1-bal.
REC1-CURTYPE = C_CTYPE.
REC1-FY = C_FY.
REC1-COAREA = REC3-RBUSA.
REC1-VER = REC3-RVERS.
REC1-VTYPE = C_CTYPE.
REC1-CA = C_CHART. "-BF7957-070503
REC1-KTOPL = REC3-KTOPL. "+BF7957-070503
APPEND REC1.
C = 3.
PERFORM D.
ENDIF.
IF REC3-HSL04 NE C_ZERO.
REC1-DEBIT = REC3-HSL04.
YEAR = REC3-RYEAR.
PERIOD = '004'.
CONCATENATE PERIOD C_DOT YEAR INTO FP.
REC1-INDICATOR = REC3-DRCRK.
REC1-DEBIT = REC3-HSL04.
REC1-CCODE = REC3-BUKRS.
REC1-YEAR = FP.
REC1-CURRENCY = REC3-RTCUR.
REC1-ACCOUNT = REC3-RACCT.
rec1-bal = REC3-hsl04 + dbalance .
REC1-CURTYPE = C_CTYPE.
REC1-FY = C_FY.
REC1-COAREA = REC3-RBUSA.
REC1-VER = REC3-RVERS.
REC1-VTYPE = C_CTYPE.
REC1-CA = C_CHART. "-BF7957-070503
REC1-KTOPL = REC3-KTOPL. "+BF7957-070503
APPEND REC1.
dbalance = rec1-bal.
C = 4.
PERFORM D.
ENDIF.
Thanks and Regards,
Ramuse logical database SDF, nodes ska1 and skc1c
A. -
Collect data from a dynamic XML file into multiple internal tables
I need to convert the XML file into multiple internal tables. I tried many links and posts in SDN but still was facing difficulty in achieving this. Can some one tell me where I am going wrong.
My XML file is of the following type.It is very complex and the dynamice.
The following tags occur more than once in the XML file. The "I" and "L" tags and its child tags can occur ones or more than once for each XML file and it is not constant. i.e in one file they can occur 1 time and in another they can occur 100 times.
"I" and "L" are child tags of <C>
<I>
<J>10</J>
<K>EN</K>
</I>
<L>
<J>20</J>
<N>BB</N>
</L>
Tags <C> and <F> occur only ones for each XML file. <C> is the child tag of "A" and "F" is the child tag of <C>.
I need to collect <D>, <E> in one internal table ITAB.
I need to collect <G>, <H> in one internal table JTAB.
I need to collect <J>, <K> in one internal table KTAB.
I need to collect <J>, <N> in one internal table PTAB.
Below is the complete XML file.
?xml version="1.0" encoding="iso-8859-1" ?>
<A>
<B/>
<C>
<D>RED</D>
<E>999</E>
<F>
<G>TRACK</G>
<H>PACK</H>
</F>
<I>
<J>10</J>
<K>EN</K>
</I>
<I>
<J>20</J>
<K>TN</K>
</I>
<I>
<J>30</J>
<K>KN</K>
</I>
<L>
<J>10</J>
<N>AA</N>
</L>
<L>
<J>20</J>
<N>BB</N>
</L>
<L>
<J>30</J>
<N>CC</N>
</L>
</C>
</A>
With the help of SDN I am able to gather the values of <D> <E> in one internal table.
Now if I need to gather
<G>, <H> in one internal table JTAB.
<J>, <K> in one internal table KTAB.
<J>, <N> in one internal table PTAB.
I am unable to do. I am following XSLT transformation method. If some one has some suggestions. Please help.
Here is my ABAP program
TYPE-POOLS abap.
CONSTANTS gs_file TYPE string VALUE 'C:\TEMP\ABCD.xml'.
* This is the structure for the data from the XML file
TYPES: BEGIN OF ITAB,
D(10) TYPE C,
E(10) TYPE C,
END OF ITAB.
* 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_ITAB TYPE STANDARD TABLE OF ts_ITAB,
gs_ITAB TYPE ts_ITAB.
* 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_itab1
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
* "IITAB".
GET REFERENCE OF gt_shipment INTO gs_result_xml-value.
gs_result_xml-name = 'IITAB'.
APPEND gs_result_xml TO gt_result_xml.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION zxslt
SOURCE XML gt_itab1
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.
* Now let's see what we got from the file
LOOP AT gt_ITAB INTO gs_ITAB.
WRITE: / 'D:', gs_ITAB-D.
WRITE: / 'E :', gs_ITAB-E.
ENDLOOP.
Transformation
<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>
<IITAB>
<xsl:apply-templates select="//C"/>
</IITAB>
</asx:values>
</asx:abap>
</xsl:template>
<item>
<D>
<xsl:value-of select="D"/>
</D>
<E>
<xsl:value-of select="E"/>
</E>
</item>
</xsl:template>
</xsl:transform>
Now the above pgm and transformation work well and I am able to extract data into the ITAB. Now what changes should I make in transformation and in pgm to collect
<G>, <H> in one internal table JTAB.
<J>, <K> in one internal table KTAB.
<J>, <N> in one internal table PTAB.
Please help..i am really tring hard to figure this out. I am found lot of threads addressing this issue but not my problem.
Kindly help.
Regards,
VSHi Rammohan,
Thanks for the effort!
But I don't need to use GUI upload because my functionality does not require to fetch data from presentation server.
Moreover, the split command advised by you contains separate fields...f1, f2, f3... and I cannot use it because I have 164 fields. I will have to split into 164 fields and assign the values back to 164 fields in the work area/header line.
Moreover I have about 10 such work areas. so the effort would be ten times the above effort! I want to avoid this! Please help!
I would be very grateful if you could provide an alternative solution.
Thanks once again,
Best Regards,
Vinod.V
Maybe you are looking for
-
I am having problems plugging in my MBpro to my LCD tv. My display is working with the hdmi hook up but i cant figure how to get the audio working when i connect the optical audio to the macbook.
-
whereare my pics in icloud--ho can I view them
-
Hi All, Can some one help me find out whats the error in my code?? what/where is wrong in my casting?? import java.lang.* ; class base { public void display() System.out.println( " i am in base "); class derv extends base{ public void show() System.o
-
Cursor for loop gives less number of records for certain condition
Hi i am getting very weired behaviour of cursor for loop. i have one query below which returns 128 records. select su.item_id from suv_tmp su inner join review_items ri on su.ITEM_ID = RI.ITEM_ID inner join sources s on s.source_id=ri.source_id and s
-
Kicking off workflow from webdynpro using events?
I have abap experience but no workflow. Any advice will be appreciated. I have to kick off a workflow from webdynpro. I assume that I have to set up a business object (eg. ZOBJECT), create an event therein (eg. ZEVENT). Then when webdynpro runs I use