1 在内表中加入颜色字段
.............................
color(4) type c,
................................
2 在内表添加记录是通过条件设置颜色字段值
wa_customerinfo-color = 'C110'.
3 设置颜色控制内表 slis_layout_alv 的颜色字段为内表增加的颜色字段
data g_slis_layo type slis_layout_alv. "定义Grid输出颜色控制内表
g_slis_layo-info_fieldname = 'COLOR'.
4 输出记录
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
is_layout = g_slis_layo
it_fieldcat = g_field[]
it_sort = g_sort[]
it_events = event_top_of_page[]
tables
t_outtab = i_customerinfo.
以下为显示表头的代码
data event_top_of_page type slis_alv_event occurs 0 with header line.
perform event_top_of_page tables event_top_of_page.
form event_top_of_page tables rt_event type slis_t_event.
refresh rt_event.
clear rt_event.
rt_event-name = slis_ev_top_of_page.
rt_event-form = 'WRITE_TOP_OF_PAGE'.
append rt_event.
endform. "event_top_of_page
form write_top_of_page.
data: hline type slis_listheader,
text(60) type c,
text10(10) type c,
text5(5) type c,
percent type p decimals 2.
refresh head.
clear head.
clear: hline, text.
hline-typ = 'S'.
write: '时间:', g_curdate to text.
hline-info = text.
append hline to head.
write: '客户状态:绿色-老呆死客户,红色-新呆死客户,兰色-超信用额度客户'
to text.
hline-info = text.
write: g_countkunnr to text5.
append hline to head.
concatenate '往来单位:' text5 '个.' into text.
hline-info = text.
append hline to head.
write: g_oldbad_count to text5.
concatenate '老呆死帐单位:' text5 '个,占' into text.
percent = g_oldbad_count * 100 / g_countkunnr.
write: percent to text5.
concatenate text5 '%' into text+23.
write: g_newbad_count to text5.
concatenate '新呆死单位:' text5 '个,占' into text+30.
percent = g_newbad_count * 100 / g_countkunnr.
write: percent to text5.
concatenate text5 '%' into text+53.
* CONDENSE text.
hline-info = text.
append hline to head.
clear text.
percent = g_ccdebit_count / 10000.
write: percent to text10.
concatenate '应收帐款:' text10 '万元' into text.
percent = g_webtr_count / 10000.
write: percent to text10.
concatenate '认可呆死帐:' text10 '万元.' into text+30.
hline-info = text.
append hline to head.
percent = g_oldbad_money / 10000.
write: percent to text10.
concatenate '老呆死帐款:' text10 '万元,' into text.
percent = g_oldbad_money * 100 / g_ccdebit_count.
write: percent to text5.
concatenate '占' text5 '%' into text+30.
hline-info = text.
append hline to head.
percent = g_newbad_money / 10000.
write: percent to text10.
concatenate '新呆死帐款:' text10 '万元,' into text.
percent = g_newbad_money * 100 / g_ccdebit_count.
write: percent to text5.
concatenate '占' text5 '%' into text+30.
hline-info = text.
append hline to head.
write: g_over_count to text5.
concatenate '超安全额度单位:' text5 '个,' into text.
percent = g_over_count * 100 / g_countkunnr.
write: percent to text5.
concatenate '占' text5 '%' into text+24.
percent = g_over_money / 10000.
write: percent to text10.
concatenate '超安全额度:' text10 '万元.' into text+30.
hline-info = text.
append hline to head.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = head.
endform. "write_top_of_page
A.主菜单
WEDI Main menu for EDI−related activities
BALE Main menu for ALE−related activities
SWLD Main menu for workflow−related activities
SALE Main area for ALE configuration
NACE Main menu for Message control configuration
.
B.IDoc监视/检查
WE02 IDoc display
WE05 IDoc list
WE07 IDoc statistics
.
C.测试
WE19 Test tool for IDocs
WE12 Convert an outbound IDoc to an inbound IDoc
WE16 Process an incoming IDoc file
WE17 Process an incoming status file
.
D.IDocs再处理
BD87 Manual processing of IDocs
Content Author: Jayanta Narayan Choudhuri
Author Email: sss@cal.vsnl.net.in
Author Website: http://www.geocities.com/ojnc
Objective: SAP On-Line HELP has a section - "Controls and Control Framework (BC-CI)".
Under this refer "Desktop Office Integration (BC-CI)"
In that section read "The Spreadsheet Interface" thoroughly.
The ides is that once a programmer gets hold of a SpreadSheetInterface Object he/she can use the powerful methods to populate Excel in any way setting sheets, ranges, colours, fonts and ofcourse content.
Create a Function Group ZUTIL
Paste TOP Level code into LZUTILTOP
Create 4 Functionn Modules
ZJNC_START_EXCEL.
ZJNC_ADD_SHEET.
ZJNC_ADD_RANGE.
ZJNC_ADD_TABLE.
ZJNC_START_EXCEL - uses the "secret" screen 2307 which a user does not even see to get hold of a Spreadsheet Interface handle. With this alone a user has virtually unlimited power as he she can call all the methods.
But to make life easier I created 4 simple functions:
ZJNC_ADD_SHEET adds a sheet to a work book
ZJNC_ADD_RANGE adds a range to a sheet
ZJNC_ADD_TABLE adds a internal table to a range with specification of all properties like font colour size bold italic etc. In ABAP Objects, you can only declare tables without headers. Hence TABLE[] syntax ensures Header is Stripped.
It is best to have full geometry in mind and fill in the following sequence
For each SHEET Create 1 RANGE & Populate Data immediately
For each SHEET Reapeat for all Ranges
Before creating a range you will need to consider size based on table.
The no. of Rows & Columns will decide size.
The cumulative rows will gixe the corner co-ordinates.
------------------------------------------------------------------------------------------
Attached Files:
ZJNCEXCEL_Test.ab4 is the Test Program
ZJNCEXCEL_FUNC.ab4 is the Function Group
ZEXCEL_WRITEUP.txt is this write-up
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*------------------------------------------------------------------------------------------
* Screen 2307 has only 1 Custom Control MYCONTROL
* Screen 2307 Flow Logic
PROCESS BEFORE OUTPUT.
MODULE ZJNCPBO.
*
PROCESS AFTER INPUT.
* MODULE ZJNCPAI.
1 Custom Control MYCONTROL
OK ZJNC_OK_CODE
*------------------------------------------------------------------------------------------
FUNCTION ZJNC_START_EXCEL.
*"----------------------------------------------------------------------
*"*"Local interface:
*" EXPORTING
*" REFERENCE(SPREADSHEETINTF) TYPE REF TO I_OI_SPREADSHEET
*"----------------------------------------------------------------------
Move SY-REPID to ZJNC_REPID.
CALL SCREEN 2307.
spreadsheetintf = zjncspreadsheet.
ENDFUNCTION.
FUNCTION ZJNC_ADD_SHEET.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(PSHEET) TYPE C
*" REFERENCE(SPREADSHEETINTF) TYPE REF TO I_OI_SPREADSHEET
*"----------------------------------------------------------------------
Move SY-REPID to ZJNC_REPID.
CALL METHOD SPREADSHEETINTF->add_sheet
EXPORTING name = psheet
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
ENDFUNCTION.
FUNCTION ZJNC_ADD_RANGE.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(PRANGE) TYPE C
*" REFERENCE(STARTROW) TYPE I
*" REFERENCE(STARTCOL) TYPE I
*" REFERENCE(NUMROWS) TYPE I
*" REFERENCE(NUMCOLS) TYPE I
*" REFERENCE(PSHEET) TYPE C
*" REFERENCE(SPREADSHEETINTF) TYPE REF TO I_OI_SPREADSHEET
*"----------------------------------------------------------------------
Move SY-REPID to zjnc_repid.
CALL METHOD SPREADSHEETINTF->select_sheet
EXPORTING name = psheet
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
CALL METHOD SPREADSHEETINTF->set_selection
EXPORTING top = StartRow
left = StartCol
rows = 1
columns = 1
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
CALL METHOD SPREADSHEETINTF->insert_range
EXPORTING name = prange
rows = numRows
columns = numCols
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
ENDFUNCTION.
FUNCTION ZJNC_ADD_TABLE.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(PTABLE) TYPE TABLE
*" REFERENCE(PRANGE) TYPE C
*" REFERENCE(PSIZE) TYPE I DEFAULT -1
*" REFERENCE(PBOLD) TYPE I DEFAULT -1
*" REFERENCE(PITALIC) TYPE I DEFAULT -1
*" REFERENCE(PALIGN) TYPE I DEFAULT -1
*" REFERENCE(PFRONT) TYPE I DEFAULT -1
*" REFERENCE(PBACK) TYPE I DEFAULT -1
*" REFERENCE(PFORMAT) TYPE C DEFAULT 'NA'
*" REFERENCE(SPREADSHEETINTF) TYPE REF TO I_OI_SPREADSHEET
*"----------------------------------------------------------------------
** TYPES: SOI_zjnc_fields_table TYPE STANDARD TABLE OF RFC_FIELDS.
DATA: zjnc_fields_table Type TABLE OF rfc_fields.
DATA: zjncwa_zjnc_fields_table TYPE rfc_fields.
Move SY-REPID to zjnc_repid.
CALL FUNCTION 'DP_GET_FIELDS_FROM_TABLE'
TABLES
data = ptable
fields = zjnc_fields_table.
CALL METHOD SPREADSHEETINTF->insert_one_table
EXPORTING
* ddic_name = ddic_name
data_table = ptable
fields_table = zjnc_fields_table
rangename = prange
wholetable = 'X'
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
CALL METHOD SPREADSHEETINTF->set_font
EXPORTING rangename = prange
family = 'Arial'
size = psize
bold = pbold
italic = pitalic
align = palign
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
CALL METHOD SPREADSHEETINTF->set_color
EXPORTING rangename = prange
front = pfront
back = pback
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
If pFormat <> 'NA'.
CALL METHOD SPREADSHEETINTF->set_format_string
EXPORTING rangename = prange
formatstring = pformat
no_flush = ' '
IMPORTING error = zjncerror
retcode = zjncretcode.
EndIf.
ENDFUNCTION.
*------------------------------------------------------------------------------------------
* TOP level Include of Function Group ZUTIL
FUNCTION-POOL ZUTIL. "MESSAGE-ID ..
* Global ZUTIL Data for ZJNCEXCEL
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.
************************************************************************
* P B O
************************************************************************
MODULE zjncpbo OUTPUT.
* SET PF-STATUS 'ZJNCSTATUS'.
* SET TITLEBAR 'ZJNCTITLE'.
IF zjncdocument IS NOT INITIAL.
RETURN.
EndIf.
Perform ZJNC_INIT_EXCEL.
Leave to Screen 0.
ENDMODULE. " PBO
*&---------------------------------------------------------------------*
*& 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.
CREATE OBJECT zjnccontainer
EXPORTING
CONTAINER_NAME = 'MYCONTROL'
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
IF sy-subrc NE 0.
* add your handling
ENDIF.
CALL METHOD zjnccontrol->init_control
EXPORTING r3_application_name = 'R/3 Basis' "#EC NOTEXT
inplace_enabled = 'X'
inplace_scroll_documents = 'X'
parent = zjnccontainer
register_on_close_event = 'X'
register_on_custom_event = 'X'
no_flush = 'X'
IMPORTING error = zjncerror.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = zjnc_repid
txt2 = 'INIT OLE zjnccontrol Failed'
txt1 = 'to init Excel zjnccontrol'.
Leave Program.
ENDIF.
CALL METHOD zjnccontrol->get_document_proxy
EXPORTING document_type = zjncexcelsheet
* document_format = document_format
* register_container = register_container
no_flush = ' '
IMPORTING document_proxy = zjncdocument
retcode = zjncretcode
error = zjncerror.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = zjnc_repid
txt2 = 'Create zjncdocument PROXY Failed'
txt1 = 'to make Excel zjncdocument'.
Leave Program.
ENDIF.
CALL METHOD zjncdocument->create_document
EXPORTING open_inplace = ' '
* create_view_data = create_view_data
* onsave_macro = onsave_macro
* startup_macro = startup_macro
document_title = 'JNC'
no_flush = ' '
IMPORTING error = zjncerror
* retcode = retcode
.
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.
CALL METHOD zjncdocument->get_spreadsheet_interface
EXPORTING no_flush = ' '
IMPORTING sheet_interface = zjncspreadsheet
error = zjncerror
retcode = zjncretcode.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = zjnc_repid
txt2 = 'Create zjncspreadsheet INTERFACE Failed'
txt1 = 'to make Excel zjncspreadsheet'.
Leave Program.
ENDIF.
ENDFORM. " ZJNC_INIT_EXCEL
Report ZExcelTest.
DATA spreadsheetintf TYPE REF TO i_oi_spreadsheet.
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.
CLEAR: head_table.
Head_Table-hd_region = 'Region'.
Head_Table-hd_sales = 'Sales'.
Head_Table-hd_date = 'Date'.
Head_Table-hd_time = 'Time'.
Head_Table-hd_weight = 'Weight in MT'.
Head_Table-hd_amount = 'Value in Rupees'.
Head_Table-hd_id = 'Sytem ID'.
Append Head_Table.
CALL FUNCTION 'ZJNC_START_EXCEL'
IMPORTING
SPREADSHEETINTF = SPREADSHEETINTF.
CALL FUNCTION 'ZJNC_ADD_SHEET'
EXPORTING
PSHEET = 'Sheet ONE'
SPREADSHEETINTF = spreadsheetintf.
maxRows = 1.
CALL FUNCTION 'ZJNC_ADD_RANGE'
EXPORTING
PRANGE = 'HeadRange1'
STARTROW = maxRows
STARTCOL = 1
NUMROWS = 1
NUMCOLS = 7
PSHEET = 'Sheet ONE'
SPREADSHEETINTF = spreadsheetintf.
* In ABAP Objects, you can only declare tables without headers.
* Hence sales_table[] ensures Header is Stripped
CALL FUNCTION 'ZJNC_ADD_TABLE'
EXPORTING
PTABLE = head_table[]
PRANGE = 'HeadRange1'
* PSIZE = -1
PBOLD = 1
* PITALIC = -1
* PALIGN = -1
* PFRONT = -1
* PBACK = -1
* PFORMAT = 'NA'
SPREADSHEETINTF = spreadsheetintf.
Add 1 to maxrows.
CLEAR: sales_table.
sales_table-region = 'USA'(usa).
sales_table-sales = usa_sales.
APPEND sales_table.
sales_table-region = 'Europe'(eur).
sales_table-sales = europe_sales.
APPEND sales_table.
sales_table-region = 'Japan'(jap).
sales_table-sales = japan_sales.
APPEND sales_table.
sales_table-region = 'Asia'(asi).
sales_table-sales = asia_sales.
APPEND sales_table.
LOOP AT sales_table.
ind = sy-tabix.
sales_table-date = sy-datum + ind.
sales_table-time = sy-uzeit + ind.
sales_table-weight = 100000 * ind.
sales_table-amount = 11111 * ind.
sales_table-id = ind.
MODIFY sales_table.
ENDLOOP.
Describe Table sales_table Lines numRows.
CALL FUNCTION 'ZJNC_ADD_RANGE'
EXPORTING
PRANGE = 'DataRange1'
STARTROW = maxRows
STARTCOL = 1
NUMROWS = numRows
NUMCOLS = 7
PSHEET = 'Sheet ONE'
SPREADSHEETINTF = spreadsheetintf.
CALL FUNCTION 'ZJNC_ADD_TABLE'
EXPORTING
PTABLE = sales_table[]
PRANGE = 'DataRange1'
* PSIZE = -1
PBOLD = 0
* PITALIC = -1
* PALIGN = -1
PFRONT = 3
* PBACK = -1
* PFORMAT = 'NA'
SPREADSHEETINTF = spreadsheetintf.
* Start NewSheet on TOP
Move 1 to maxRows.
CALL FUNCTION 'ZJNC_ADD_SHEET'
EXPORTING
PSHEET = 'Sheet TWO'
SPREADSHEETINTF = spreadsheetintf.
CALL FUNCTION 'ZJNC_ADD_RANGE'
EXPORTING
PRANGE = 'HeadRange2'
STARTROW = maxRows
STARTCOL = 1
NUMROWS = 1
NUMCOLS = 7
PSHEET = 'Sheet TWO'
SPREADSHEETINTF = spreadsheetintf.
* In ABAP Objects, you can only declare tables without headers.
* Hence sales_table[] ensures Header is Stripped
CALL FUNCTION 'ZJNC_ADD_TABLE'
EXPORTING
PTABLE = head_table[]
PRANGE = 'HeadRange2'
* PSIZE = -1
PBOLD = 1
* PITALIC = -1
* PALIGN = -1
* PFRONT = -1
* PBACK = -1
* PFORMAT = 'NA'
SPREADSHEETINTF = spreadsheetintf.
Add 1 to maxrows.
CLEAR: sales_table.
sales_table-region = 'America'(ame).
sales_table-sales = america_sales.
APPEND sales_table.
sales_table-region = 'Africa'(afr).
sales_table-sales = africa_sales.
APPEND sales_table.
LOOP AT sales_table.
ind = sy-tabix.
sales_table-date = sy-datum + ind.
sales_table-time = sy-uzeit + ind.
sales_table-weight = 700000 * ind.
sales_table-amount = 123456 * ind.
sales_table-id = ind.
MODIFY sales_table.
ENDLOOP.
Describe Table sales_table Lines numRows.
CALL FUNCTION 'ZJNC_ADD_RANGE'
EXPORTING
PRANGE = 'DataRange2'
STARTROW = maxRows
STARTCOL = 1
NUMROWS = numRows
NUMCOLS = 7
PSHEET = 'Sheet TWO'
SPREADSHEETINTF = spreadsheetintf.
CALL FUNCTION 'ZJNC_ADD_TABLE'
EXPORTING
PTABLE = sales_table[]
PRANGE = 'DataRange2'
* PSIZE = -1
PBOLD = 0
* PITALIC = -1
* PALIGN = -1
PFRONT = 55
PBACK = 6
* PFORMAT = 'NA'
SPREADSHEETINTF = spreadsheetintf.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = sy-repid
txt2 = 'See EXCEL & SAVE if Needed'
txt1 = 'Jai Hind ....'.
With good tips from top SDN contributor
Thomas Jung
I made 2 function modules to suit my whims.
SAP being a serious Businesss Software you cannot have too many
JPGs floating around! One or two is fun.
In Function group uou need two screens 0806 & 2009 which are
essentially blank.
I put 2 title Bars - 0806 "SAP - JOB in Progress"; 2009 - "SAP - JOB
OVER!!"
Code listing for function: ZJNC_START_SPLASH
Description: Show Splash at Start
--------------------------------------------------------------------------------
FUNCTION zjnc_start_splash.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IMAGEFILE) TYPE C DEFAULT 'THANKS.JPG'
*" REFERENCE(WIDTH) TYPE I DEFAULT 415
*" REFERENCE(HEIGHT) TYPE I DEFAULT 274
*" REFERENCE(TIMEOUT) TYPE I DEFAULT 3
*" REFERENCE(CALLBACK) TYPE C
*"----------------------------------------------------------------------
* Global data declarations
MOVE imagefile TO g_name.
MOVE width TO picwidth.
MOVE height TO picheight.
MOVE timeout TO pictimeout.
MOVE callback TO piccallback.
TRANSLATE piccallback TO UPPER CASE.
PERFORM getpicurl.
CALL SCREEN 0806.
ENDFUNCTION.
Code listing for function: ZJNC_END_SPLASH
Description: Show Splash at End
--------------------------------------------------------------------------------
FUNCTION ZJNC_END_SPLASH.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IMAGEFILE) TYPE C DEFAULT 'THANKS.JPG'
*" REFERENCE(WIDTH) TYPE I DEFAULT 415
*" REFERENCE(HEIGHT) TYPE I DEFAULT 274
*" REFERENCE(TIMEOUT) TYPE I DEFAULT 3
*"----------------------------------------------------------------------
* Global data declarations
MOVE imagefile TO g_name.
MOVE width TO picwidth.
MOVE height TO picheight.
MOVE timeout TO pictimeout.
PERFORM getpicurl.
CALL SCREEN 2009.
ENDFUNCTION.
Code listing for: LZUTILTOP
* TOP level Include of Function Group ZUTIL
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
FUNCTION-POOL zutil. "MESSAGE-ID ..
TYPE-POOLS: abap.
DATA: graphic_url(255),
g_result TYPE i,
g_linesz TYPE i,
g_filesz TYPE i,
g_name(100).
TYPES: t_graphic_line(256) TYPE x.
DATA: graphic_line TYPE t_graphic_line,
graphic_table TYPE TABLE OF t_graphic_line.
DATA: picwidth TYPE i,
picheight TYPE i,
pictimeout TYPE i,
piccallback(60) TYPE c,
first TYPE boolean.
*---------------------------------------------------------------------*
* CLASS ZCL_ES_SPLASH_SCREEN DEFINITION
*---------------------------------------------------------------------*
CLASS zcl_es_splash_screen DEFINITION.
PUBLIC SECTION.
EVENTS on_close.
METHODS constructor
IMPORTING
!i_num_secs TYPE i DEFAULT 5
!i_url TYPE c
!i_width TYPE i
!i_height TYPE i.
PROTECTED SECTION.
METHODS handle_end_of_timer
FOR EVENT finished OF cl_gui_timer.
PRIVATE SECTION.
DATA container TYPE REF TO cl_gui_dialogbox_container.
DATA image TYPE REF TO cl_gui_picture.
DATA timer TYPE REF TO cl_gui_timer.
ENDCLASS. "ZCL_ES_SPLASH_SCREEN DEFINITION
*---------------------------------------------------------------------*
* CLASS ZCL_ES_SPLASH_SCREEN IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS zcl_es_splash_screen IMPLEMENTATION.
METHOD constructor.
DATA: image_width TYPE i,
image_height TYPE i.
COMPUTE image_width = i_width + 30.
COMPUTE image_height = i_height + 50.
CREATE OBJECT container
EXPORTING
width = 10
height = 10
top = 10
left = 10
name = 'DialogSplash'.
CALL METHOD container->set_caption
EXPORTING
caption = g_name.
CREATE OBJECT image
EXPORTING
parent = container.
CALL METHOD image->load_picture_from_url
EXPORTING
url = i_url.
image->set_display_mode( image->display_mode_normal_center ).
cl_gui_cfw=>flush( ).
container->set_metric( EXPORTING metric = image->metric_pixel ).
DATA: myleft TYPE i,
mytop TYPE i.
COMPUTE myleft = ( 800 - image_width ) / 2.
COMPUTE mytop = ( 600 - image_height ) / 2.
IF myleft < 0.
MOVE 0 TO myleft.
ENDIF.
IF mytop < 0.
MOVE 0 TO mytop.
ENDIF.
container->set_position(
EXPORTING
height = image_height
left = myleft
top = mytop
width = image_width ).
cl_gui_cfw=>update_view( ).
CREATE OBJECT timer.
timer->interval = i_num_secs.
SET HANDLER me->handle_end_of_timer FOR timer.
timer->run( ).
cl_gui_cfw=>flush( ).
ENDMETHOD. "constructor
METHOD handle_end_of_timer.
* I wanted NAMASTE to remain until JOB was complete.
* IF container IS NOT INITIAL.
* container->free( ).
* CLEAR container.
* FREE container.
* ENDIF.
*
* IF timer IS NOT INITIAL.
* timer->free( ).
* CLEAR timer.
* FREE timer.
* ENDIF.
*
* cl_gui_cfw=>flush( ).
RAISE EVENT on_close.
ENDMETHOD. "handle_end_of_timer
ENDCLASS. "ZCL_ES_SPLASH_SCREEN IMPLEMENTATION
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: on_close FOR EVENT on_close OF zcl_es_splash_screen.
ENDCLASS. "lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_close.
IF sy-dynnr = 2009.
LEAVE PROGRAM.
ELSE.
MOVE abap_false TO first.
PERFORM (piccallback) IN PROGRAM (sy-cprog).
ENDIF.
ENDMETHOD. "on_close
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA: splash TYPE REF TO zcl_es_splash_screen.
*&---------------------------------------------------------------------*
*& Module STATUS_0806 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0806 OUTPUT.
IF first IS INITIAL.
first = abap_true.
SET TITLEBAR 'TITLE0806'.
CREATE OBJECT splash
EXPORTING
i_num_secs = pictimeout
i_url = graphic_url
i_width = picwidth
i_height = picheight.
SET HANDLER lcl_event_handler=>on_close FOR splash.
ENDIF.
ENDMODULE. " STATUS_0806 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_2009 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2009 OUTPUT.
IF first IS INITIAL.
first = abap_true.
SET TITLEBAR 'TITLE2009'.
CREATE OBJECT splash
EXPORTING
i_num_secs = pictimeout
i_url = graphic_url
i_width = picwidth
i_height = picheight.
SET HANDLER lcl_event_handler=>on_close FOR splash.
ENDIF.
ENDMODULE. " STATUS_2009 OUTPUT
*&---------------------------------------------------------------------*
*& Form getpicurl
*&---------------------------------------------------------------------*
FORM getpicurl.
OPEN DATASET g_name FOR INPUT IN BINARY MODE.
REFRESH graphic_table.
CLEAR g_filesz.
DO.
CLEAR graphic_line.
READ DATASET g_name INTO graphic_line ACTUAL LENGTH g_linesz.
ADD g_linesz TO g_filesz.
APPEND graphic_line TO graphic_table.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET g_name.
CLEAR graphic_url.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE'
subtype = 'GIF'
TABLES
data = graphic_table
CHANGING
url = graphic_url
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_put_table = 2
dp_error_general = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
ENDFORM. "getpicurl
Report Z_CTRY.
* A Shape Interface "Like a shape" "Behaves like a Shape"
Adverb/Adjective
Interface IShape.
Methods: getArea Returning Value(area) Type F,
getCircumference Returning Value(circumference) Type F.
Endinterface.
* A Circle Class that behaves like a Shape
Class CCircle Definition.
Public Section.
Interfaces IShape.
Aliases: getArea For IShape~getArea,
getCircumference For IShape~getCircumference.
Methods: Constructor Importing pRadius Type F,
setRadius Importing pRadius Type F,
getRadius Returning Value(pRadius) Type F.
Private Section.
Data radius Type F.
Constants PI Type F Value '3.141592365359'.
EndClass.
Class CCircle Implementation.
Method Constructor.
radius = pRadius.
EndMethod.
Method setRadius.
radius = pRadius.
EndMethod.
Method getRadius.
pRadius = radius.
EndMethod.
Method IShape~getArea.
Compute area = 2 * PI * radius.
EndMethod.
Method IShape~getCircumference.
Compute circumference = PI * radius * radius.
EndMethod.
EndClass.
* A Square Class
Class CSquare Definition.
Public Section.
Interfaces IShape.
Aliases: getArea For IShape~getArea,
getCircumference For IShape~getCircumference.
Methods: Constructor Importing pSide Type F.
Private Section.
Data side Type F.
EndClass.
Class CSquare Implementation.
Method Constructor.
side = pSide.
EndMethod.
Method IShape~getArea.
Compute area = side * side.
EndMethod.
Method IShape~getCircumference.
Compute circumference = 4 * side.
EndMethod.
EndClass.
* A Rectangle Class
Class CRectangle Definition.
Public Section.
Interfaces IShape.
Aliases: getArea For IShape~getArea,
getCircumference For IShape~getCircumference.
Methods: Constructor Importing pHeight Type F
pLength Type F.
Private Section.
Data: height Type F,
length Type F.
EndClass.
Class CRectangle Implementation.
Method Constructor.
height = pHeight.
length = pLength.
EndMethod.
Method IShape~getArea.
Compute area = height * length.
EndMethod.
Method IShape~getCircumference.
Compute circumference = 2 * ( height + length ).
EndMethod.
EndClass.
* START of PROGRAM
* Array of Shapes
Data: OneShape Type Ref To IShape, " One Object with
Shape Behaviour
ShapeTable Type Table Of Ref To IShape. " Array of Objects
with Shape Behaviour
* Concrete Objects with IShape Behaviour!
Data: C1 Type Ref To CCircle,
S1 Type Ref To CSquare,
R1 Type Ref To CRectangle,
C2 Type Ref To CCircle,
S2 Type Ref To CSquare,
R2 Type Ref To CRectangle.
Data: descr_ref TYPE ref to CL_ABAP_TYPEDESCR,
ClassName Type String,
Serial Type I.
Data: myArea Type F,
myCircumference Type F.
START-OF-SELECTION.
Create Object C1 Exporting pRadius = '2.5'.
Create Object C2 Exporting pRadius = '5.0'.
Create Object S1 Exporting pSide = '3.5'.
Create Object S2 Exporting pSide = '6.0'.
Create Object R1 Exporting pHeight = '2.8' pLength = '3.4'.
Create Object R2 Exporting pHeight = '1.7' pLength = '6.3'.
* Append in any order!
Append S1 to ShapeTable.
Append R2 to ShapeTable.
Append R1 to ShapeTable.
Append C2 to ShapeTable.
Append C1 to ShapeTable.
Append S2 to ShapeTable.
Serial = 0.
Loop At ShapeTable into OneShape.
Call Method OneShape->getArea
Receiving area = myArea.
Call Method OneShape->getCircumference
Receiving circumference = myCircumference.
descr_ref = CL_ABAP_TYPEDESCR=>Describe_By_Object_Ref( OneShape
).
Call Method descr_ref->get_relative_name
Receiving P_RELATIVE_NAME = ClassName.
Add 1 to Serial.
Write: / Serial, ClassName.
Write: / 'Area ', myArea Decimals 4 Exponent
0.
Write: / 'Circumference ', myCircumference Decimals 4 Exponent
0.
Write: /.
EndLoop.
** Results
* 1 CSQUARE
* Area 12.2500
* Circumference 14.0000
*
* 2 CRECTANGLE
* Area 10.7100
* Circumference 16.0000
*
* 3 CRECTANGLE
* Area 9.5200
* Circumference 12.4000
*
* 4 CCIRCLE
* Area 31.4159
* Circumference 78.5398
*
* 5 CCIRCLE
* Area 15.7080
* Circumference 19.6350
*
* 6 CSQUARE
* Area 36.0000
* Circumference 24.0000
Many times I've looked at transaction SWO1 for a business object and seen how it displays all sorts of useful functions (e.g Line Item Texts etc. etc.). Many of these attributes can only be got at in normal programming via convoluted abap tinkering. -- How many times for example do you want to get texts to include on a smartform etc.
However it's really easy to get the attribute from the BOR itself using very simple coding.
Most people shy away from this since a BOR is usually used in SAP workflow and most abap developers haven't had a lot of exposure to OO programming or SAP workflow.
Anyway here's sample code to return an Attribute of a BOR.
program zzreadbor.* The above example will return an 'X' if the customer is an IS Media customer or blank otherwise.
* Get an attribute of a business object.
parameters: p_busobj(10) type c default 'BUSISM007', "IS Media
customer
p_key(70) type c,
p_attr(32) type c default 'Xmediacustomer'.
data:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid,
i_element TYPE swo_verb.
DATA object TYPE swo_objhnd.
DATA verb TYPE swo_verb.
DATA return TYPE swotreturn.
DATA lt_container TYPE STANDARD TABLE OF swcont.
data line type swcont.
i_objtype = p_busobj.
i_element = p_attr.
i_objkey = p_key.
* instantiate the business object. I.e give it a key and create it.
CALL FUNCTION 'SWO_CREATE'
EXPORTING
objtype = i_objtype
objkey = i_objkey
IMPORTING
object = object.
* return attribute.
CALL FUNCTION 'SWO_INVOKE'
EXPORTING
access = 'G'
object = object
verb = i_element
IMPORTING
return = return
verb = verb
TABLES
container = lt_container.
* the attribute value is returned in field line-value.
IF return-code = 0.
loop at lt_container into line.
write: / line-value.
endloop.
endif.
Other good business objects to use are sales docs (header / line items), invoices, Info types etc etc.
You can also call methods this way as well -- change the access to 'C' in the SWO_INVOKE and pass the parameters to the method. Method name is in VERB. A bit more complex as in the case of Supertypes you need to find the program -- will post an example later --however to start with even the attributes are useful since on "Instantiation" of the BOR you have access to ALL the attribites of that BOR.
1990年1月15日 2007年1月14日 2007年1月15日 2007年1月16日 2007年1月17日 2007年1月18日 2007年1月19日 2007年1月20日 2007年1月22日 2007年1月23日 2007年1月24日 2007年1月25日 2007年1月26日 2007年1月27日 2007年1月29日 2007年1月30日 2007年1月31日 2007年2月1日 2007年2月2日 2007年2月3日 2007年3月13日 2007年5月15日 2007年5月16日 2007年6月2日