SAP ABAP Programs
Wednesday, February 18, 2009
Thursday, February 12, 2009
Commands & Useful Tips
-------------------------------------------------
READ TABLE p_t_wiqmfe INTO p_wa_wiqmfe INDEX 1.
-------------------------------------------------
DESCRIBE TABLE gt_vpind LINES lv_lines.
-------------------------------------------------
REPLACE ' ' WITH '0' INTO l_kd_rk.
REPLACE ALL OCCURRENCES OF '"' IN v_char WITH space.
CONDENSE v_char.
-------------------------------------------------
set pf-status 'STANDRAD' excluding rt_extab.
-------------------------------------------------
DATA text TYPE string VALUE `I know you know`.
SHIFT text RIGHT DELETING TRAILING 'know'.
output: I know you
------------------------------------------------
modify t2 index idx from st_r
transporting a b c .
FOR EXCLUDING STANDARD BUTTON FROM ALV TOOLBAR
DATA : it_exclude TYPE slis_t_extab,
wa_exclude TYPE slis_extab.
*&---------------------------------------------------------------------*
* FOR EXCLUDING STANDARD BUTTONS FROM ALV TOOLBAR
*&---------------------------------------------------------------------*
wa_exclude-fcode = '&OUP'.
APPEND wa_exclude TO it_exclude.
CLEAR wa_exclude.
wa_exclude-fcode = '&ODN'.
APPEND wa_exclude TO it_exclude.
CLEAR wa_exclude.
wa_exclude-fcode = '&OAD'.
APPEND wa_exclude TO it_exclude.
CLEAR wa_exclude.
wa_exclude-fcode = '&INFO'.
APPEND wa_exclude TO it_exclude.
CLEAR wa_exclude.
*--similarly append other function codes of the buttons that you want to exclude
*--and pass this internal table to FM REUSE_ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
* DISPLAY RECORDS IN ALV GRID
*&---------------------------------------------------------------------*
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = rep_id
* i_callback_pf_status_set = 'PF'
i_callback_user_command = 'COMMAND'
i_callback_top_of_page = 'TOP'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
i_grid_title = wa_title
* I_GRID_SETTINGS =
is_layout = wa_layout
it_fieldcat = it_field
it_excluding = it_exclude "excule buttons
* IT_SPECIAL_GROUPS =
--------------------------------------------------------------------------------------------
DATA : tab TYPE rstabfield.
ranges : r_vbeln for vbap-vbeln.
tab-tablename = 'VBAP'.
tab-fieldname = 'VBELN'.
CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
EXPORTING
title = text-002
text = ' '
signed = 'X'
lower_case = 'X'
no_interval_check = 'X'
* just_display = 'X'
* just_incl = 'X'
* excluded_options = 'X'
* description =
* help_field =
* search_help =
tab_and_field = tab
TABLES
range = r_vbeln
EXCEPTIONS
no_range_tab = 1
cancelled = 2
internal_error = 3
invalid_fieldname = 4
OTHERS = 5.
IF sy-subrc EQ 2.
MESSAGE s899 WITH text-003. "no value selected
ELSEIF sy-subrc = 0 AND sy-subrc = 2.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
read a file from directory using cl_gui_frontend_services
DATA: lt_filetab TYPE filetable.
DATA: ls_filetab LIKE LINE OF lt_filetab.
PARAMETERS: p_file TYPE localfile.
AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = lt_filetab
rc = v_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
READ TABLE lt_filetab INTO ls_filetab INDEX 1.
IF sy-subrc = 0.
p_file = ls_filetab-filename.
ENDIF.
Monday, November 24, 2008
Auto-Refreshed ALV Report
REPORT z_alv_auto_refresh.
*---------------------------------------------------------------------*
* This report displays User's info (SM04) using the FM : *
* REUSE_ALV_LIST_DISPLAY *
* The list is auto-refreshed (refresh time : 5 seconds) *
*---------------------------------------------------------------------*
TYPE-POOLS: slis. " ALV Global Types
DATA : gt_user LIKE uinfo OCCURS 0 WITH HEADER LINE. " User info in SM04
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form F_LIRE_DATA
*---------------------------------------------------------------------*
FORM f_read_data.
REFRESH gt_user.
* Get User's info
CALL FUNCTION 'THUSRINFO'
TABLES
usr_tabl = gt_user.
* Wait in a task
PERFORM f_call_rfc_wait.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form F_DISPLAY_DATA
*---------------------------------------------------------------------*
FORM f_display_data.
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DEFINE m_event_exit.
clear ls_event_exit.
ls_event_exit-ucomm = &1.
ls_event_exit-after = 'X'.
append ls_event_exit to lt_event_exit.
END-OF-DEFINITION.
DATA :
ls_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit.
* Build Sort Table
m_sort 'ZEIT'.
* Build Event Exit Table
m_event_exit '&NTE'. " Refresh
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
is_layout = ls_layout
i_structure_name = 'UINFO'
it_sort = lt_sort
it_event_exit = lt_event_exit
TABLES
t_outtab = gt_user.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING i_ucomm TYPE syucomm
is_selfield TYPE slis_selfield. "#EC CALLED
CASE i_ucomm.
WHEN '&NTE'.
PERFORM f_read_data.
is_selfield-refresh = 'X'.
SET USER-COMMAND '&OPT'. " Optimize columns width
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form F_CALL_RFC_WAIT
*---------------------------------------------------------------------*
FORM f_call_rfc_wait.
DATA lv_mssg(80). "#EC NEEDED
* Wait in a task
CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
PERFORMING f_task_end ON END OF TASK
EXPORTING
seconds = 5 " Refresh time
busy_waiting = space
EXCEPTIONS
RESOURCE_FAILURE = 1
communication_failure = 2 MESSAGE lv_mssg
system_failure = 3 MESSAGE lv_mssg
OTHERS = 4.
ENDFORM. " F_CALL_RFC_WAIT
*---------------------------------------------------------------------*
* Form F_TASK_END
*---------------------------------------------------------------------*
FORM f_task_end USING u_taskname.
DATA lv_mssg(80). "#EC NEEDED
* Receiving task results
RECEIVE RESULTS FROM FUNCTION 'RFC_PING_AND_WAIT'
EXCEPTIONS
RESOURCE_FAILURE = 1
communication_failure = 2 MESSAGE lv_mssg
system_failure = 3 MESSAGE lv_mssg
OTHERS = 4.
CHECK sy-subrc EQ 0.
SET USER-COMMAND '&NTE'. " Refresh
ENDFORM. " F_TASK_END
Thursday, September 18, 2008
ALV Grid in 3 Steps without Screen Painter
lt_sflight TYPE TABLE OF sflight.
SELECTION-SCREEN BEGIN OF SCREEN 1001 .
SELECTION-SCREEN END OF SCREEN 1001.
SELECT * FROM sflight INTO TABLE lt_sflight.
* Creation of the ALV object, when we use cl_gui_container=>screen0 as
*parent, the ALVGrid control will
* automatically use the full screen to display the grid, NO CONTAINER
*DEFINITION IS REQUIRED !
CREATE OBJECT l_alv EXPORTING i_parent = cl_gui_container=>screen0.
* calling the display of the grid, the system will automatically create
*the fieldcatalog based
* on the table name you pass in parameter
CALL METHOD l_alv->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
CHANGING it_outtab = lt_sflight.
DATA p_text(5) TYPE c." LENGTH 5.
DO 2 TIMES.
WAIT UP TO '0.5' SECONDS.
p_text(3) = sy-index.
p_text+3 = '%'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = sy-index
text = p_text.
ENDDO.
CALL SELECTION-SCREEN 1001." STARTING AT 8 8 ENDING AT 85 22.
Showing a progress bar in ABAP(Timer Clock)
DATA p_text(5) TYPE c." LENGTH 5.
DO 3 TIMES.
WAIT UP TO '0.5' SECONDS.
p_text(3) = sy-index.
p_text+3 = '%'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = sy-index
text = p_text.
ENDDO.