Posted: Tue Oct 09, 2007 1:00 pm Post subject: Integration OLE через EXCEL
Code:
Report ZExcelTest Message-id ym.
DATA zjnccontainer TYPE REF TO cl_gui_custom_container.
DATA zjnccontrol TYPE REF TO i_oi_container_control.
DATA zjncdocument TYPE REF TO i_oi_document_proxy.
DATA zjncspreadsheet TYPE REF TO i_oi_spreadsheet.
DATA zjncerror TYPE REF TO i_oi_error.
DATA zjncretcode TYPE SOI_RET_STRING.
DATA zjncexcelsheet TYPE soi_document_type VALUE
SOI_DOCTYPE_EXCEL_SHEET.
DATA: zjnc_ok_code LIKE sy-ucomm," return code from screen
zjnc_repid LIKE sy-repid.
DATA spreadsheetintf TYPE REF TO i_oi_spreadsheet.
DATA documentintf TYPE REF TO i_oi_document_proxy.
DATA pivotintf TYPE REF TO i_oi_pivot.
DATA: numRows type I,
maxRows type I.
DATA: usa_sales TYPE i VALUE 1000,
europe_sales TYPE i VALUE 2000,
japan_sales TYPE i VALUE 1000,
asia_sales TYPE i VALUE 100,
america_sales TYPE i VALUE 100,
africa_sales TYPE i VALUE 100.
DATA: BEGIN OF head_table Occurs 0,
hd_region(10),
hd_sales(10),
hd_date(10),
hd_time(10),
hd_weight(10),
hd_amount(10),
hd_id(10),
END OF head_table.
DATA: BEGIN OF sales_table Occurs 0,
region(60),
sales TYPE i,
date TYPE d,
time TYPE t,
weight TYPE f,
amount TYPE p DECIMALS 3,
id(10) TYPE n,
END OF sales_table.
DATA: ind TYPE i.
Data: Begin of WA_PIVOT,
region(60),
date TYPE d,
amount TYPE p DECIMALS 3,
End of WA_PIVOT.
* Qty Internal Table for Date-wise Plant-Wise
Data: IT_PIVOT Like Sorted Table Of WA_PIVOT With Header Line
With Unique Key region date.
Data: DT_PIVOT Like Table Of WA_PIVOT With Header Line.
Data: IT_ITEMS type SOI_NAMETYPE_TABLE.
Data: WA_ITEMS like line of IT_ITEMS.
DATA: WA_NAMECOL TYPE SOI_NAMECOL_ITEM.
DATA: NAMECOL TYPE SOI_NAMECOL_TABLE.
DATA: WA_FIELD LIKE RFC_FIELDS.
DATA: FIELDS_TABLE TYPE TABLE OF RFC_FIELDS.
DATA: OFFSET LIKE RFC_FIELDS-OFFSET VALUE 0.
DATA: N TYPE I.
DATA: POS TYPE I VALUE 1.
DATA: ALIGNMENT TYPE I.
LOOP AT sales_table.
Move sales_table-region to WA_PIVOT-region.
Move sales_table-date to WA_PIVOT-date.
Move sales_table-amount to WA_PIVOT-amount.
Collect WA_PIVOT Into IT_PIVOT.
ENDLOOP.
* If zjncretcode <> c_oi_errors=>ret_ok.
* CALL METHOD c_oi_errors=>raise_message
* EXPORTING type = 'E'.
* EndIf.
If pivotintf Is Initial.
message e999 with 'NULL pivot interface'.
EndIf.
* PERFORM DYN_ANALYSE_SINGLE TABLES FIELDS_TABLE
* USING DT_PIVOT
* CHANGING POS N OFFSET ALIGNMENT.
WA_NAMECOL-NAME = 'REGION'.
WA_NAMECOL-COLUMN = '1'.
APPEND WA_NAMECOL TO NAMECOL.
WA_NAMECOL-NAME = 'DATE'.
WA_NAMECOL-COLUMN = '2'.
APPEND WA_NAMECOL TO NAMECOL.
WA_NAMECOL-NAME = 'AMOUNT'.
WA_NAMECOL-COLUMN = '3'.
APPEND WA_NAMECOL TO NAMECOL.
LOOP AT NAMECOL INTO WA_NAMECOL.
READ TABLE FIELDS_TABLE INTO WA_FIELD INDEX WA_NAMECOL-COLUMN.
IF SY-SUBRC EQ 0.
WA_FIELD-FIELDNAME = WA_NAMECOL-NAME.
MODIFY FIELDS_TABLE INDEX WA_NAMECOL-COLUMN FROM WA_FIELD.
ENDIF.
ENDLOOP.
Move 'REGION' to WA_ITEMS-name.
Move i_oi_pivot=>rowfield to WA_ITEMS-type.
Append WA_ITEMS to IT_ITEMS.
Move 'DATE' to WA_ITEMS-name.
Move i_oi_pivot=>columnfield to WA_ITEMS-type.
Append WA_ITEMS to IT_ITEMS.
Move 'AMOUNT' to WA_ITEMS-name.
Move i_oi_pivot=>datafield to WA_ITEMS-type.
Append WA_ITEMS to IT_ITEMS.
* CALL FUNCTION 'POPUP_TO_INFORM'
* EXPORTING
* titel = sy-repid
* txt2 = 'See EXCEL & SAVE if Needed'
* txt1 = 'Jai Hind ....'.
*&---------------------------------------------------------------------*
*& Form GET_ALIGNMENT
*&---------------------------------------------------------------------*
FORM GET_ALIGNMENT USING P_TYP
CHANGING ALIGNBASE.
ALIGNBASE = 1.
CASE P_TYP.
*FLOAT VALUE NEEDS 8 BYTE ALIGNMENT
WHEN 'F'.
ALIGNBASE = 8.
*SHORT INTEGER NEEDS 2 BYTE ALIGNMENT
WHEN 's'.
ALIGNBASE = 2.
*LONG INTEGER NEEDS 4 BYTE ALIGNMENT
WHEN 'I'.
ALIGNBASE = 4.
*ALL OTHER TYPES ARE BYTE ALIGNED
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form OFFSET_CORRECTION
*&---------------------------------------------------------------------*
FORM OFFSET_CORRECTION USING P_TYP ALIGNBASE
CHANGING P_FIELDS_OFFSET.
DATA : MODRESULT TYPE I.
DATA : ADDOFFSET TYPE I.
DATA : THISALIGNBASE TYPE I.
IF P_TYP NE ' '.
PERFORM GET_ALIGNMENT USING P_TYP CHANGING THISALIGNBASE.
ELSE.
THISALIGNBASE = ALIGNBASE.
ENDIF.
IF THISALIGNBASE NE 1.
* If the reminder of mod operation is not equal 0 we have to adjust
* the offset
MODRESULT = P_FIELDS_OFFSET MOD THISALIGNBASE.
IF MODRESULT NE 0.
ADDOFFSET = THISALIGNBASE - MODRESULT.
P_FIELDS_OFFSET = P_FIELDS_OFFSET + ADDOFFSET.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_0100 output.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
*
* IF zjncdocument IS NOT INITIAL.
* RETURN.
* EndIf.
Perform ZJNC_INIT_EXCEL.
Leave to Screen 0.
endmodule." STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form ZJNC_INIT_EXCEL
*&---------------------------------------------------------------------*
Form ZJNC_INIT_EXCEL.
CALL METHOD c_oi_container_control_creator=>get_container_control
IMPORTING control = zjnccontrol
error = zjncerror.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = zjnc_repid
txt2 = 'Create OLE zjnccontrol Failed'
txt1 = 'to make Excel zjnccontrol'.
Leave Program.
ENDIF.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = zjnc_repid
txt2 = 'Create zjncdocument Failed'
txt1 = 'to make Excel zjncdocument'.
Leave Program.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.