Monday, December 6, 2010

Send PDF to SPOOL

*&---------------------------------------------------------------------*
*& Report ZPDF_TO_SPOOL.
*&
*&---------------------------------------------------------------------*
report ZPDF_TO_SPOOL.

*&---------------------------------------------------------------------*
*& Declarations
*&---------------------------------------------------------------------*

data : w_options like itcpo ,
it_otfdata type standard table of itcoo ,
it_tlines type standard table of tline ,
bin_filesize type i ,
bin_file type xstring ,
printer like tsp01-rqdest value 'LP01',
append type c value 'X',
doctype type adsdoctype value 'ADSP' ,
adstype type string,
l_strlen type i,
l_strlen1 type i,
nopdf type c value '',
globaldir(100),
pathname(256),
myfile type string,
handle like sy-tabix,
spoolid like tsp01-rqident,
partname type adspart,
filename type file_name,
pages type i,
size type i.

data: begin of datatab occurs 100,
line(80) type x,
end of datatab.

*&---------------------------------------------------------------------*
*& Start of selection
*&---------------------------------------------------------------------*

start-of-selection.

w_options-tdgetotf = 'X'.
w_options-tddest = 'LP01'.

*--Call the Script

call function 'OPEN_FORM'
exporting
device = 'PRINTER'
dialog = ' '
form = 'ZTEST'
language = sy-langu
options = w_options.


call function 'WRITE_FORM'
exporting
* element = '520'
function = 'SET'
type = 'BODY'
window = 'MAIN'.


call function 'CLOSE_FORM'
tables
otfdata = it_otfdata.


*--Convert from OTF to PDF format
* bin_file needs to be XSTRING format.
call function 'CONVERT_OTF'
exporting
format = 'PDF'
max_linewidth = 255
importing
bin_filesize = bin_filesize
bin_file = bin_file
tables
otf = it_otfdata
lines = it_tlines.

call function 'ADS_SR_OPEN'
exporting
dest = printer
append = append
doctype = doctype
importing
handle = handle
spoolid = spoolid
partname = partname
exceptions
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
others = 5.

* l_strlen = STRLEN( bin_file ).
* l_strlen1 = STRLEN( bin_file ).

l_strlen = bin_filesize .
l_strlen1 = bin_filesize .

do.

if l_strlen gt 80.
move bin_file+0(80) to datatab-line.
append datatab.
l_strlen = l_strlen - 80.
bin_file = bin_file+80.
else.
move bin_file+0(l_strlen) to datatab-line.
append datatab.
exit.
endif.

enddo.

* Filename from partname
concatenate partname '.pdf' into filename.

* Get path of global directory
call 'C_SAPGPARAM'
id 'NAME' field 'DIR_GLOBAL'
id 'VALUE' field globaldir.

* Create fully qualified path
concatenate globaldir '/' filename into pathname.

myfile = pathname.

open dataset myfile for output in binary mode.

if sy-subrc = 0.

loop at datatab.
transfer datatab to myfile.
endloop.

close dataset myfile.
endif.

size = l_strlen1.
pages = 1.

call function 'ADS_SR_CONFIRM'
exporting
handle = handle
partname = partname
size = size
pages = pages
no_pdf = nopdf
exceptions
handle_not_valid = 1
operation_failed = 2
others = 3.

call function 'ADS_SR_CLOSE'
exporting
handle = handle
exceptions
handle_not_valid = 1
operation_failed = 2
others = 3.

end-of-selection.

Friday, December 3, 2010

Split Container to display multiple ALV's

*&---------------------------------------------------------------------*
*& Report Z_SPLIT_CONTAINER_ALV
*&
*&---------------------------------------------------------------------*

REPORT Z_SPLIT_CONTAINER_ALV.

DATA : lcl_custom TYPE REF TO cl_gui_custom_container.
DATA : lcl_split TYPE REF TO cl_gui_splitter_container.
DATA : lcl_con1 TYPE REF TO cl_gui_container.
DATA : lcl_con2 TYPE REF TO cl_gui_container.
DATA : lcl_con3 TYPE REF TO cl_gui_container.
DATA : lcl_con4 TYPE REF TO cl_gui_container.
DATA : gcl_dd_doc TYPE REF TO cl_dd_document.
DATA : gr_functions TYPE REF TO cl_salv_functions.

DATA : gr_salv TYPE REF TO cl_salv_table,
gr_salv2 TYPE REF TO cl_salv_table,
gr_salv3 TYPE REF TO cl_salv_table,
gr_salv4 TYPE REF TO cl_salv_table,
lr_exp TYPE REF TO cx_root,
lv_text TYPE string.

TYPES:BEGIN OF ty_table3,
g_belnr TYPE bkpf-belnr, "pra
g_bukrs TYPE bkpf-bukrs,"pra
sbelnr TYPE bkpf-belnr,"pra
rbukrs TYPE bkpf-bukrs,"pra
rbelnr TYPE bkpf-belnr,"pra
rstblg TYPE bkpf-stblg,"pra
pernr TYPE pa0001-pernr,
name(30) TYPE c,
begda TYPE dats,
endda TYPE dats,
END OF ty_table3.

DATA : BEGIN OF ty_alv3.
INCLUDE TYPE ty_table3.
DATA : END OF ty_alv3.

DATA : gt_display3 LIKE TABLE OF ty_alv3,
gs_display3 LIKE ty_alv3.

TYPES:BEGIN OF ty_table2,
pernr TYPE pa0002-pernr,
nachn TYPE pa0002-nachn,
vorna type pa0002-vorna,
GESCH type pa0002-GESCH,
GBDAT type pa0002-GBDAT,
begda TYPE dats,
endda TYPE dats,
END OF ty_table2.

DATA : BEGIN OF ty_alv2.
INCLUDE TYPE ty_table2.
DATA : END OF ty_alv2.

DATA : gt_display2 LIKE TABLE OF ty_alv2,
gs_display2 LIKE ty_alv2.

DATA : gt_display4 LIKE TABLE OF bseg,
gs_display4 LIKE bseg.

START-OF-SELECTION.

PERFORM fill_internal_tables.

CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZSTAT'.
SET TITLEBAR 'ZTITLE'.

CREATE OBJECT lcl_custom
EXPORTING
* parent = parent
container_name = 'SPLIT'
* style = style
* lifetime = lifetime_default
* repid = repid
* dynnr = dynnr
* no_autodef_progid_dynnr = no_autodef_progid_dynnr
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6
.

*Split the container into 4
CREATE OBJECT lcl_split
EXPORTING
parent = lcl_custom
rows = 4
columns = 1
* no_autodef_progid_dynnr = no_autodef_progid_dynnr
* name = name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3
.

*1st window
CALL METHOD lcl_split->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = lcl_con1.

CALL METHOD lcl_split->set_row_height
EXPORTING
id = 1
height = 3.

IF gcl_dd_doc IS INITIAL.
CREATE OBJECT gcl_dd_doc.
ENDIF.
PERFORM built_header CHANGING gcl_dd_doc.
CALL METHOD gcl_dd_doc->merge_document.

CALL METHOD gcl_dd_doc->display_document
EXPORTING
parent = lcl_con1
EXCEPTIONS
html_display_error = 1.

*2nd window
CALL METHOD lcl_split->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = lcl_con4.

CALL METHOD lcl_split->set_row_height
EXPORTING
id = 2
height = 3.
TRY.
"Factory Method for display the ALV
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = lcl_con4
IMPORTING
r_salv_table = gr_salv4
CHANGING
t_table = gt_display3.

CATCH cx_salv_msg INTO lr_exp.
lv_text = lr_exp->get_text( ).

ENDTRY.

gr_salv4->display( ).

*3rd window
CALL METHOD lcl_split->get_container
EXPORTING
row = 3
column = 1
RECEIVING
container = lcl_con2.

CALL METHOD lcl_split->set_row_height
EXPORTING
id = 3
height = 22.

TRY.
"Factory Method for display the ALV
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = lcl_con2
IMPORTING
r_salv_table = gr_salv2
CHANGING
t_table = gt_display2.

gr_functions = gr_salv2->get_functions( ).
gr_functions->set_all( abap_true ).

CATCH cx_salv_msg INTO lr_exp.
lv_text = lr_exp->get_text( ).

ENDTRY.
gr_salv2->display( ).

*4th window
CALL METHOD lcl_split->get_container
EXPORTING
row = 4
column = 1
RECEIVING
container = lcl_con3.

CALL METHOD lcl_split->set_row_height
EXPORTING
id = 4
height = 21.

TRY.
"Factory Method for display the ALV
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = lcl_con3
IMPORTING
r_salv_table = gr_salv3
CHANGING
t_table = gt_display4.

gr_functions = gr_salv3->get_functions( ).
gr_functions->set_all( abap_true ).

CATCH cx_salv_msg INTO lr_exp.
lv_text = lr_exp->get_text( ).

ENDTRY.
gr_salv3->display( ).

ENDMODULE. " STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*
*& Form built_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM built_header CHANGING ps_cl_dd_doc TYPE REF TO cl_dd_document.

DATA : lcl_ta TYPE REF TO cl_dd_table_element,
lcl_col1 TYPE REF TO cl_dd_area,
lcl_col2 TYPE REF TO cl_dd_area,
lcl_col3 TYPE REF TO cl_dd_area,
lv_text TYPE sdydo_text_element,
lcl_form TYPE REF TO cl_dd_form_area.

CALL METHOD ps_cl_dd_doc->add_table
EXPORTING
no_of_columns = 3
width = '100%'
cell_background_transparent = space
IMPORTING
table = lcl_ta.

*Set the columns
CALL METHOD lcl_ta->add_column
EXPORTING
width = '30%'
IMPORTING
column = lcl_col1.

CALL METHOD lcl_ta->add_column
EXPORTING
width = '30%'
IMPORTING
column = lcl_col2.

CALL METHOD lcl_ta->add_column
EXPORTING
width = '40%'
IMPORTING
column = lcl_col3.

lv_text = 'First Field'.

CALL METHOD lcl_col1->add_text
EXPORTING
text = lv_text
sap_emphasis = cl_dd_area=>table_heading."strong.

lv_text = 'Second Field'.

CALL METHOD lcl_col2->add_text
EXPORTING
text = lv_text
sap_emphasis = cl_dd_area=>table_heading.

lv_text = 'Third Field'.

CALL METHOD lcl_col3->add_text
EXPORTING
text = lv_text
sap_emphasis = cl_dd_area=>table_heading.

CLEAR:lv_text.

CALL METHOD ps_cl_dd_doc->add_table
EXPORTING
no_of_columns = 3
width = '100%'
cell_background_transparent = space
IMPORTING
table = lcl_ta.

ENDFORM. " built_header

*&---------------------------------------------------------------------*
*& Form fill_internal_tables
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_internal_tables .

SELECT pernr nachn vorna GESCH gbdat begda endda FROM pa0002
INTO TABLE gt_display2
UP TO 20 ROWS.

gs_display4-bukrs = '0112'.
gs_display4-belnr = '1090807060'.
gs_display4-gjahr = '2010'.

DO 20 TIMES.
APPEND gs_display4 TO gt_display4.
ENDDO.

ENDFORM. " fill_internal_tables

Convert ABAP Spool to word document

*&---------------------------------------------------------------------*
*& Report Z_SPOOL_2_WORD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_SPOOL_2_WORD.

INCLUDE ole2incl.

DATA i_buffer(132) OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.

PARAMETERS: p_spool LIKE tsp01-rqident OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE text-002.

PARAMETERS: p_word AS CHECKBOX DEFAULT 'X'.
PARAMETERS: p_fwor LIKE rlgrap-filename obligatory.

SELECTION-SCREEN END OF BLOCK B2.

*----------------------------------------------------------------------*
* START-OF-SELECTION.
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM read_spool.

IF NOT p_word IS INITIAL.
PERFORM write_word.
ENDIF.

*&---------------------------------------------------------------------*
*& Form read_spool
*&---------------------------------------------------------------------*
* Read spool data
*----------------------------------------------------------------------*
FORM read_spool.

CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
EXPORTING
rqident = p_spool
first_line = 1
last_line = 9999999
TABLES
buffer = i_buffer
EXCEPTIONS
no_such_job = 1
not_abap_list = 2
job_contains_no_data = 3
selection_empty = 4
no_permission = 5
can_not_access = 6
read_error = 7
OTHERS = 8.

IF sy-subrc NE 0.
MESSAGE e398(00) WITH 'Spool' p_spool 'not found'.
ENDIF.

ENDFORM. " read_spool

*&---------------------------------------------------------------------*
*& Form write_word
*&---------------------------------------------------------------------*
* Write to word.
*----------------------------------------------------------------------*
FORM write_word.

DATA: wordapp TYPE ole2_object,
document TYPE ole2_object,
selection TYPE ole2_object.

CALL FUNCTION 'CLPB_EXPORT'
TABLES
data_tab = i_buffer
EXCEPTIONS
clpb_error = 1
OTHERS = 2.

* Word CREATE
CREATE OBJECT wordapp 'word.application'.

IF sy-subrc NE 0.
MESSAGE e398(00) WITH 'Word cannot be created'.
ENDIF.

* Set visible
SET PROPERTY OF wordapp 'Visible' = 1.

CALL METHOD OF wordapp 'Documents' = document.

CALL METHOD OF document 'Add'.

CALL METHOD OF wordapp 'Selection' = selection.

CALL METHOD OF selection 'Paste'.

IF sy-subrc NE 0.
MESSAGE e398(00) WITH 'Error at writing to the document'.
ENDIF.

CALL METHOD OF wordapp 'ActiveDocument' = document.

CALL METHOD OF document 'SaveAs'
EXPORTING #1 = p_fwor.

IF sy-subrc NE 0.
MESSAGE e398(00) WITH 'Error saving the document'.
ENDIF.

* Close Word application

CALL METHOD OF WORDAPP 'Quit'.

IF sy-subrc NE 0.
MESSAGE e398(00) WITH 'Error closing Word'.
ENDIF.

ENDFORM. "write_word

Thursday, December 2, 2010

Email Excel Sheet as an Attachment

*&---------------------------------------------------------------------*
*& Report Z_EXCEL_MAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_EXCEL_MAIL.

DATA: BEGIN OF it_kna1 OCCURS 0,
kunnr TYPE kunnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
END OF it_kna1.

START-OF-SELECTION.

SELECT kunnr land1 name1 FROM kna1
INTO TABLE it_kna1 UP TO 10 ROWS
WHERE land1 = 'US'.

*-- Sending mail with Excel

TYPES: BEGIN OF t_solisti1,
line TYPE string,
END OF t_solisti1.

DATA : docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin_tmp TYPE STANDARD TABLE OF solix ,
objbin_final TYPE STANDARD TABLE OF solix ,
objhead TYPE TABLE OF solisti1,
objbin1 TYPE t_solisti1 OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
wa_objhead LIKE LINE OF objhead,
tab_lines TYPE sy-tabix.

DATA:gv_tab_lines TYPE c.

CONSTANTS : lk_tab_char TYPE c VALUE
cl_abap_char_utilities=>horizontal_tab,
lk_cr_char TYPE c VALUE cl_abap_char_utilities=>cr_lf,
lk_xls_extension TYPE so_obj_tp VALUE 'XLS',
lk_filename(255) TYPE c VALUE 'Customer Details.XLS'.

DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ) .

*-- Mail Subject
CONCATENATE 'Customer details as on'
sy-datum+4(2)
sy-datum+6(2)
sy-datum+0(4)
INTO docdata-obj_descr.

CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = gv_tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.

*-- Mail Subject
CLEAR : objhead,
wa_objhead.
REFRESH objhead.

wa_objhead-line = lk_filename.
APPEND wa_objhead TO objhead.

reclist-receiver = 'mailid@igroup.com'.
reclist-express = 'X'.
reclist-rec_type = 'U'. "Internet Mail Address
APPEND reclist.

reclist-receiver = 'mailid@igroup.com'.
reclist-copy = 'X'.
reclist-express = 'X'.
reclist-rec_type = 'U'. "Internet Mail Address
APPEND reclist.

*-- Creation of the document attachment
CONCATENATE 'Customer'
'Country'
'Name'
INTO objbin1-line
SEPARATED BY lk_tab_char.
CONCATENATE objbin1-line lk_cr_char
INTO objbin1-line.
CONDENSE objbin1-line.
APPEND objbin1.

APPEND: INITIAL LINE TO objbin1.

*-- Creation of the document body
LOOP AT it_kna1.
DATA:lv_tot_approval(20) TYPE c,
lv_sno(3) TYPE c.
lv_sno = lv_sno + 1.

CONCATENATE it_kna1-kunnr
it_kna1-land1
it_kna1-name1
INTO objbin1-line
SEPARATED BY lk_tab_char.
CONCATENATE objbin1-line lk_cr_char
INTO objbin1-line.
CONDENSE objbin1-line.
APPEND objbin1.
CLEAR : objbin1.
ENDLOOP.

DESCRIBE TABLE objbin1 LINES tab_lines.
tab_lines = tab_lines + 50.
objpack-doc_size = tab_lines * 255 .
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = lk_xls_extension.
objpack-obj_name = lk_filename.
objpack-obj_descr = lk_filename.

APPEND objpack.

*-- To avoid Junk Characters
LOOP AT objbin1.
DATA:lv_buffer TYPE xstring.

CLEAR lv_buffer.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = objbin1-line
IMPORTING
buffer = lv_buffer
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc = 0.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_buffer
TABLES
binary_tab = objbin_tmp.
APPEND LINES OF objbin_tmp TO objbin_final.
ENDIF.

ENDLOOP.

*-- FM to send mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
commit_work = 'X'
TABLES
packing_list = objpack
object_header = objhead
contents_txt = objtxt
contents_hex = objbin_final
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE 'Mail was sent successfully' TYPE 'I'.
ELSE.
MESSAGE 'Mail sent successfully' TYPE 'I'.
ENDIF.

ALV List with Subtotal and Page no's

*&---------------------------------------------------------------------*
*& Report ZALV_SUBTOTAL_PAGENOS *
*&---------------------------------------------------------------------*
report ZALV_SUBTOTAL_PAGENOS.

*-- Type pools
type-pools: slis.

*--------------------------------------------------------------------
* G L O B A L I N T E R N A L T A B L E S
*--------------------------------------------------------------------
data: gt_fieldcat type slis_t_fieldcat_alv,
gs_layout type slis_layout_alv,
gt_events type slis_t_event.
data: it_sort type slis_t_sortinfo_alv ,
wa_sort type slis_sortinfo_alv .
data: gs_print type slis_print_alv.

data: begin of it_sflight occurs 0,
carrid like sflight-carrid,
connid like sflight-connid,
fldate like sflight-fldate,
price like sflight-price,
planetype like sflight-planetype,
seatsmax like sflight-seatsmax,
seatsocc like sflight-seatsocc,
paymentsum like sflight-paymentsum,
end of it_sflight.

data: g_repid like sy-repid.
data: gt_list_top_of_page type slis_t_listheader.
data: v_total(5).

start-of-selection.
g_repid = sy-repid.

perform init_fieldcat using gt_fieldcat[].
perform build_eventtab using gt_events[].
perform build_comment using gt_list_top_of_page[].
perform get_data.
perform set_layout using gs_layout.

*-- SORT
clear wa_sort.
wa_sort-fieldname = 'CARRID'.
wa_sort-up = 'X'.
wa_sort-group = '*'.
wa_sort-subtot = 'X'.
append wa_sort to it_sort.

clear wa_sort.
wa_sort-fieldname = 'CONNID'.
wa_sort-up = 'X'.
wa_sort-group = 'UL'.
wa_sort-subtot = 'X'.
append wa_sort to it_sort.

*-- DISPLAY LIST
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_interface_check = ' '
i_callback_program = g_repid
i_callback_user_command = 'USER_COMMAND'
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
it_sort = it_sort[]
it_events = gt_events
is_print = gs_print
tables
t_outtab = it_sflight
exceptions
program_error = 1
others = 2.

*&---------------------------------------------------------------------*
*& Form INIT_FIELDCAT
*&---------------------------------------------------------------------*
form init_fieldcat using p_gt_fieldcat type slis_t_fieldcat_alv.

data: ls_fieldcat type slis_fieldcat_alv,
l_index type sy-tabix.

data :rep like sy-repid.
rep = sy-repid.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = rep
i_internal_tabname = 'IT_SFLIGHT'
i_inclname = rep
changing
ct_fieldcat = gt_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.
endif.

sort gt_fieldcat by col_pos.

loop at gt_fieldcat into ls_fieldcat.
l_index = sy-tabix.
if ls_fieldcat-fieldname = 'PRICE'.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-sp_group = 'X'.
modify gt_fieldcat from ls_fieldcat index l_index .
endif.
endloop.

endform. " INIT_FIELDCAT

*&---------------------------------------------------------------------*
*& Form BUILD_EVENTTAB
*&---------------------------------------------------------------------*
form build_eventtab using p_gt_events type slis_t_event.

data: ls_event type slis_alv_event.

clear ls_event.
ls_event-name = slis_ev_top_of_page.
ls_event-form = 'XTOP_OF_PAGE'.
append ls_event to p_gt_events.
clear ls_event.
ls_event-name = slis_ev_top_of_list.
ls_event-form = 'XTOP_OF_LIST'.
append ls_event to p_gt_events.
clear ls_event.
clear ls_event.
ls_event-name = slis_ev_end_of_page.
ls_event-form = 'XEND_OF_PAGE'.
append ls_event to p_gt_events.
ls_event-name = slis_ev_end_of_list.
ls_event-form = 'XEND_OF_LIST'.
append ls_event to p_gt_events.
clear ls_event.

endform. " BUILD_EVENTTAB

*&---------------------------------------------------------------------*
*& Form BUILD_COMMENT
*&---------------------------------------------------------------------*
form build_comment using p_gt_list_top_of_page type slis_t_listheader.
data: ls_line type slis_listheader.
ls_line-typ = 'H'." = Header, S = Selection, A = Action
ls_line-key = 'KEY'.
ls_line-info = 'INFO'.
append ls_line to p_gt_list_top_of_page.

endform. " BUILD_COMMENT

*&---------------------------------------------------------------------*
*& Form SELECTION
*&---------------------------------------------------------------------*
form get_data..
data: l_rows type i value 3.
* Read data from table SFLIGHT
select carrid
connid
fldate
price
planetype
seatsmax
seatsocc
paymentsum
from sflight
into table it_sflight.
** up to l_rows rows.
sort it_sflight.
endform. " SELECTION

*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
form set_layout using p_gs_layout type slis_layout_alv.

p_gs_layout-zebra = 'X'.
p_gs_layout-colwidth_optimize = 'X'.
p_gs_layout-no_input = 'X'.
p_gs_layout-no_colhead = space.
p_gs_layout-totals_text = 'Total Price'.
p_gs_layout-subtotals_text = 'Sub Total'.
p_gs_layout-totals_only = 'X'.
p_gs_layout-key_hotspot = 'X'.
p_gs_layout-detail_popup = 'X'.
p_gs_layout-no_subtotals = space.
p_gs_layout-expand_all = 'X'.
p_gs_layout-group_buttons = 'X'."space.
endform. " SET_LAYOUT

*---------------------------------------------------------------------*
* FORM XTOP_OF_PAGE *
*---------------------------------------------------------------------*
form xtop_of_page.

data : lv_page(5),
lv_text(20).
MOVE SY-PAGNO TO LV_PAGE.
write:/ 'X_TOP_OF_PAGE'.
.
endform. "xtop_of_page
*---------------------------------------------------------------------*
* FORM XTOP_OF_LIST *
*---------------------------------------------------------------------*
form xtop_of_list.
write:/ 'X_TOP_OF_LIST'.
endform. "xtop_of_list

*---------------------------------------------------------------------*
* FORM XEND_OF_PAGE *
*---------------------------------------------------------------------*
form xend_of_page.
write:/ 'X_END_OF_PAGE'.
endform. "xend_of_page

*---------------------------------------------------------------------*
* FORM XEND_OF_LIST *
*---------------------------------------------------------------------*
form xend_of_list.
write:/ 'X_END_OF_LIST'.
data : lv_page(5),
lv_text(20).
data : l_lines type i,
l_line type i.

clear v_total.

write sy-pagno to v_total left-justified.
do sy-pagno times.
lv_page = sy-index.
concatenate 'Page' lv_page 'of' v_total
into lv_text separated by space.
if sy-index = 1.
read line 2 of page sy-index.
else.
read line 1 of page sy-index.

endif.
sy-lisel+60(20) = lv_text.
modify current line .
enddo.

endform. "xend_of_list

*---------------------------------------------------------------------*
* USER_COMMAND *
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.

case r_ucomm.
when 'EXIT'.
leave to screen 0.
when '&IC1'.
data: text(256),text1(6),text2(5).
move rs_selfield-tabindex to text1.
move rs_selfield-sumindex to text2.
concatenate 'Double clicked on (field:'
rs_selfield-fieldname
'Value:'
rs_selfield-value
','
text1
','
text2
' ) '
into text
separated by space.

call function 'POPUP_TO_DISPLAY_TEXT'
exporting
textline1 = text.

endcase.
endform. "user_command

Debug a popup screen

Type the below in a note pad , save it to the desktop , drag and drop onto the popup screen.

[FUNCTION]
Command=/H
Title=Debugger
Type=SystemCommand

Thursday, November 25, 2010

Other useful sites

www.sdn.sap.com
www.saptechnical.com

Get sample program list

Enter ABAPDOCU in Command prompt and enter
You'll find some basic ABAP Examples
BIBS - Contains Examples of user Interface design