Excel Upload...
*-----------------------------------------------------------------------
*
* Company XXX Company Limited
*
* ProgrameName: ZZW_EXCEL_UPLOAD
*
* Author: Wei_Zhu
*
* Date: 07/31/2007
*
* Description: Study SAP In Program How To Upload Excel File To SAP
* Table.
*
*
*-----------------------------------------------------------------------
REPORT ZZW_EXCEL_UPLOAD MESSAGE-ID 00.
Tables: ZTBTEST.
*Data: I_Tab_1 like standard table of alsmex_tabline with header line,
* I_Tab_2 like alsmex_tabline.
*----------Excel Paraters Setting-----------
*Data: Begin_Col Type i value 1,
* Begin_Row Type i value 1,
* End_Col Type i value 128,
* End_Row Type i value 65535.
Data: Begin Of I_tab_1 Occurs 0.
INCLUDE Structure alsmex_tabline.
Data: End Of I_tab_1.
Data: Begin Of I_tab_2 Occurs 0.
INCLUDE Structure alsmex_tabline.
Data: End Of I_tab_2.
Data: Begin Of T_Col Occurs 0,
Col Like alsmex_tabline-col,
Size Type i,
End Of T_Col.
Data: Zwlen Type i,
Zwlines Type i.
DATA: tind(4) TYPE n.
DATA: zwfeld(19).
* No of columns
DATA: BEGIN OF data_tab OCCURS 0,
value_0001(50),
value_0002(50),
value_0003(50),
value_0004(50),
value_0005(50),
value_0006(50),
value_0007(50),
value_0008(50),
value_0009(50),
value_0010(50),
value_0011(50),
value_0012(50),
value_0013(50),
value_0014(50),
value_0015(50),
value_0016(50),
value_0017(50),
value_0018(50),
value_0019(50),
value_0020(50),
value_0021(50),
value_0022(50),
value_0023(50),
value_0024(50),
value_0025(50),
value_0026(50),
value_0027(50),
value_0028(50),
value_0029(50),
value_0030(50),
value_0031(50),
value_0032(50),
value_0033(50),
value_0034(50),
value_0035(50),
value_0036(50),
value_0037(50),
value_0038(50),
value_0039(50),
value_0040(50),
value_0041(50),
value_0042(50),
value_0043(50),
value_0044(50),
value_0045(50),
value_0046(50),
value_0047(50),
value_0048(50),
value_0049(50),
value_0050(50),
value_0051(50),
value_0052(50),
value_0053(50),
value_0054(50),
value_0055(50),
value_0056(50),
value_0057(50),
value_0058(50),
value_0059(50),
value_0060(50),
value_0061(50),
value_0062(50),
value_0063(50),
value_0064(50),
value_0065(50),
value_0066(50),
value_0067(50),
value_0068(50),
value_0069(50),
value_0070(50),
value_0071(50),
value_0072(50),
value_0073(50),
value_0074(50),
value_0075(50),
value_0076(50),
value_0077(50),
value_0078(50),
value_0079(50),
value_0080(50),
value_0081(50),
value_0082(50),
value_0083(50),
value_0084(50),
value_0085(50),
value_0086(50),
value_0087(50),
value_0088(50),
value_0089(50),
value_0090(50),
value_0091(50),
value_0092(50),
value_0093(50),
value_0094(50),
value_0095(50),
value_0096(50),
value_0097(50),
value_0098(50),
value_0099(50),
value_0100(50).
DATA: END OF data_tab.
Data: Begin Of FieldNames Occurs 3,
Title(60),
Table(6),
Field(10),
KZ(1),
End Of FieldNames.
Data: Begin OF Itab Occurs 0,
ID Like ZTBTEST-Z_USER_ID,
Name Like ZTBTEST-Z_USER_NAME,
Text Like ZTBTEST-Z_TEXT,
End Of Itab.
*-----------------------------------------------------------------------
* Screen
*-----------------------------------------------------------------------
Selection-Screen Begin Of Block B1 With Frame Title Text-001.
Parameters: P_fname like rlgrap-filename modif ID m3.
Selection-Screen End Of Block B1.
Selection-Screen Begin Of Block B2 With Frame Title Text-002.
Parameters: Kzheader as CheckBox. " Tick Don't Append Header
Selection-Screen End Of Block B2.
Selection-Screen Begin Of Block B3 With Frame Title Text-003.
Parameters: B_Col Type I,
B_Row Type I,
E_Col Type I,
E_Row Type I.
Selection-Screen End Of Block B3.
*-----------------------------------------------------------------------
*Initialization
*-----------------------------------------------------------------------
Initialization.
*----------------------------------------------------------------------
* Process Control
*----------------------------------------------------------------------
At Selection-Screen On Value-Request For P_fname.
Perform Fname_Value_F4.
At Selection-Screen.
If B_Col is initial.
Message e888(sabapdocu)
With '[ Begin Column ] Must Be Input Parameter!'.
EndIf.
If B_ROW Is Initial.
Message e888(sabapdocu)
With '[ Begin Row ] Must Be Input Parameter!'.
EndIf.
If E_Col is Initial.
Message e888(sabapdocu)
With '[ End Column ] Must Be Input Parameter!'.
EndIf.
If E_Row is Initial.
Message e888(sabapdocu)
With '[ End Row ] Must Be Input Parameter!'.
EndIf.
*----------------------------------------------------------------------
* Statr-Of-Selection
*----------------------------------------------------------------------
Start-Of-Selection.
Perform Get_Excel_Data.
*&---------------------------------------------------------------------
*
*& Form Fname_Value_F4
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
form Fname_Value_F4 .
Call Function 'KD_GET_FILENAME_ON_F4'
Exporting
Mask = ',Microsoft Excel Files,*.xls'
Static = 'X'
Changing
File_Name = P_fname.
endform. " Fname_Value_F4
*&---------------------------------------------------------------------*
*& Form Get_Excel_Data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form Get_Excel_Data .
Call Function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
Exporting
filename = p_fname
i_begin_col = B_Col
i_begin_row = B_Row
i_end_col = E_Col
i_end_row = E_Row
Tables
intern = i_tab_1
Exceptions
inconsistent = 1
upload_old = 2
others = 3.
If Sy-subrc <> 0.
Write: / 'Upload Error', Sy-subrc.
* Message e888(sabapdocu) with 'xxxxx'.
EndIf.
Loop at i_tab_1.
i_tab_2 = i_tab_1.
Clear i_tab_2-row.
Append i_tab_2.
EndLoop.
Sort i_tab_2 by col.
Loop At i_tab_2.
At new Col.
T_Col-Col = i_tab_2-col.
Append t_col.
EndAt.
Zwlen = Strlen( I_tab_2-Value ).
Read Table T_Col With Key Col = I_tab_2-Col.
If Sy-SubRc EQ 0.
If Zwlen > T_Col-Size.
T_Col-Size = Zwlen.
Modify T_Col Index Sy-tabix.
EndIF.
EndIF.
EndLoop.
Describe Table T_Col Lines Zwlines.
Sort I_Tab_1 By Row Col.
IF KZheader = 'X'.
Loop at I_Tab_1.
FieldNames-Title = I_tab_1-Value.
Append FieldNames.
At End Of Row.
Exit.
EndAT.
EndLoop.
Else.
Do Zwlines Times.
Write Sy-Index to FieldNames-Title.
Append Fieldnames.
EndDo.
EndIF.
Field-Symbols <fs>.
Sort I_Tab_1 BY Row Col.
Loop At I_tab_1.
If Kzheader = 'X'
And I_tab_1-Row = 1.
Continue.
EndIf.
Tind = I_tab_1-Col.
Concatenate 'Data_Tab-Value_' Tind Into zwfeld.
Assign (zwfeld) To <fs>.
<fs> = I_tab_1-Value.
At End Of Row.
Append data_tab.
Clear Data_tab.
EndAT.
EndLoop.
Call Function 'DISPLAY_BASIC_LIST'
Exporting
File_Name = p_fname
Tables
Data_tab = Data_tab
FieldName_Tab = FieldNames.
* Loop at Data_tab.
* If Sy-tabix EQ 1.
** Skip.
* Continue.
* Else.
* Itab-ID = Data_Tab-Value_0001(10).
* Itab-Name = Data_Tab-Value_0002(10).
* Itab-Text = Data_Tab-Value_0003(10).
* Append Itab.
* EndIF.
*
* EndLoop.
*
* Modify ZTBTEST From Table Itab.
endform. " Get_Excel_Data