Вы находитесь на странице: 1из 14

Welcome, Guest

Login
Register
Getting Started
Newsletters
Store
Solutions
SAP Services & Support
About SCN
Downloads
Industries
Training & Education
Partnership
Code Exchange
Lines of Business
University Alliances
Events & Webinars
Idea Place
Browse
My Home >
Code Gallery >
ALV Grid Display with chec box to process selected records at runtime
Tools
ALV Grid Display with chec box to process selected records at runtime
Attachments:3
Added by Tarun Gambhir, last edited by Kuaising Lin on Mar 06, 2009 (view c
hange)
*&---------------------------------------------------------------------*
*& Report ZPM_WO
*&---------------------------------------------------------------------*
*& Author
: Tarun Gambhir
*& Description : To generate an ALV report display to trac
*&
damage-type wor orders and pending completion status
*&
whose order status is PM01 or PM02 in order to ensure
*&
timely completions.
*&---------------------------------------------------------------------*
*& Display records in first screen in ALV Grid Display with chec boxes
*& appended with each record and perform an user action to display the
*& selected records into another ALV Gird
*& or user can use their own code as per their requirements
*&---------------------------------------------------------------------*
REPORT zpm_wo NO STANDARD PAGE HEADING MESSAGE-ID zmsg_wo.
*&---------------------------------------------------------------------*
*
TYPE POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS : slis. " used for ALV output
*&---------------------------------------------------------------------*
*
TYPE DECLARATION
*&---------------------------------------------------------------------*

TYPES :
* for table auf (wor order details)
BEGIN OF t_auf ,
aufnr TYPE auf -aufnr, " order number
text TYPE auf - text, " description
objnr TYPE auf -objnr, " object number
END OF t_auf ,
* for table jest (object status details)
BEGIN OF t_jest,
objnr TYPE jest-objnr, " object number
END OF t_jest,
* for table af o (basic finish date details)
BEGIN OF t_af o,
aufnr TYPE af o-aufnr, " order number
gltrp TYPE af o-gltrp, "basic finish date
END OF t_af o,
* for table qmel (notification number details)
BEGIN OF t_qmel,
aufnr TYPE qmel-aufnr, " order number
qmnum TYPE qmel-qmnum, " notification number
END OF t_qmel,
* final table from which the records need to be displayed
BEGIN OF t_final,
aufnr TYPE auf -aufnr, " order number
text TYPE auf - text, " description
qmnum TYPE qmel-qmnum, " notification number
flag(1), " for selection of records
END OF t_final,
* table which contains the selected records to be processed
BEGIN OF t_process,
aufnr TYPE auf -aufnr, " order number
text TYPE auf - text, " description
qmnum TYPE qmel-qmnum, " notification number
END OF t_process,
* table for messages
BEGIN OF t_message,
aufnr TYPE auf -aufnr, "order number
msg(200), "message text
END OF t_message.
*&---------------------------------------------------------------------*
*
CONTANTS DECLARATION
*&---------------------------------------------------------------------*
CONSTANTS : c_chec (1) VALUE 'X',
" value used to set X for a field
c_langu(1) VALUE 'E',
" language used
c_ustat(4) VALUE 'TECO'. " object status description
*&---------------------------------------------------------------------*
*
RANGES DECLARATION
*&---------------------------------------------------------------------*
*
RANGE VALUE TO BE USED FOR THE ORDER TYPE
*&---------------------------------------------------------------------*
RANGES : r_auart FOR auf -auart. "for order type

*&---------------------------------------------------------------------*
*
PARAMETERS FOR SELECTION-SCREEN
*&---------------------------------------------------------------------*
*
SELECTION SCREEN BLOCK FOR THE VARIANT NAME
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_var TYPE disvariant-variant. " variant parameter
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*
VARIABLE DECLARATIONS
*&---------------------------------------------------------------------*
DATA : v_rep_id TYPE sy-repid, " report id
v_istat TYPE tj02t-istat, " order status
v_cdate TYPE sy-datum,
" current system date
v_line_count TYPE i,
" number of lines in final internal table
v_filename TYPE string. " path for download error log
*&---------------------------------------------------------------------*
*
INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* TYPE OF T_AUFK
* internal table to select records for damaged order types
DATA : it_auf TYPE STANDARD TABLE OF t_auf ,
* wor area for damaged order types
wa_auf TYPE t_auf .
* TYPE OF T_JEST
* internal table to select object number based upon user status
DATA : it_jest TYPE STANDARD TABLE OF t_jest,
* wor area to select object number based upon user status
wa_jest TYPE t_jest.
* TYPE OF T_AFKO
* internal table to select the basic finish date corresopnding to wor order
DATA : it_af o TYPE STANDARD TABLE OF t_af o,
* wor area to select the basic finish date corresopnding to wor order
wa_af o TYPE t_af o.
* TYPE OF T_QMEL
* internal table to select the notification number corresopnding to object numbe
r
DATA : it_qmel TYPE STANDARD TABLE OF t_qmel,
* wor area to select the notification number corresopnding to object number
wa_qmel TYPE t_qmel.
* TYPE OF T_FINAL
* final internal table to select final records to be displayed
DATA : it_final TYPE STANDARD TABLE OF t_final,
* final wor area to select final records to be displayed
wa_final TYPE t_final.
* TYPE OF T_PROCESS
* final internal table to select final records to be displayed
DATA : it_process TYPE STANDARD TABLE OF t_process,
* final wor area to select final records to be displayed
wa_process TYPE t_process.
* FOR VARIANT
DATA : wa_variant TYPE disvariant.

* FOR VARIANT IMPORT


DATA : wa_i_variant TYPE disvariant.
*&---------------------------------------------------------------------*
*
ALV INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field TYPE slis_fieldcat_alv. "wor area for field catalog
* SORTING INFO
DATA : it_sort TYPE slis_t_sortinfo_alv, "internal table for sorting field
wa_sort TYPE slis_sortinfo_alv. "wor area for sorting field
* FOR LAYOUT OF ALV GRID
DATA : wa_layout TYPE slis_layout_alv. "wor area for layout design
*&---------------------------------------------------------------------*
*
ALV INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field1 TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field1 TYPE slis_fieldcat_alv. "wor area for field catalog
* SORTING INFO
DATA : it_sort1 TYPE slis_t_sortinfo_alv, "internal table for sorting field
wa_sort1 TYPE slis_sortinfo_alv. "wor area for sorting field
* FOR LAYOUT OF ALV GRID
DATA : wa_layout1 TYPE slis_layout_alv. "wor area for layout design
*&---------------------------------------------------------------------*
*
INITIALIZATION
*&---------------------------------------------------------------------*
*
TO INITIALIZE ALL THE VARIABLES TO BE USED
*
IN THE PROGRAM
*&---------------------------------------------------------------------*
INITIALIZATION.
v_rep_id = sy-repid.
" report id
r_auart-sign = 'I'.
" for inclusive
r_auart-option = 'BT'.
" for between operator
r_auart-low = 'PM01'.
" order type(low value)
r_auart-high = 'PM02'.
" order type(high value)
APPEND r_auart.
" append values for range
v_cdate = sy-datum - 7.
" ta e date 7 days before current date
wa_variant-report = v_rep_id. " report for using variants
*&---------------------------------------------------------------------*
*
AT SELECTION-SCREEN OUTPUT
*&---------------------------------------------------------------------*
*
TO CLEAR THE VALUE OF THE VARIANT PARAMETER WHEN USER
*
RETURNS FROM THE OUTPUT SCREEN TO THE SELECTION SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
CLEAR p_var. "clear variant value
*&---------------------------------------------------------------------*
*
AT-SELECTION SCREEN ON VALUE REQUEST
*&---------------------------------------------------------------------*
*
TO GET THE F4 HELP FOR EXISTING VARIANTS

*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
PERFORM f4_variant_help USING p_var.
*&---------------------------------------------------------------------*
*
AT-SELECTION SCREEN
*&---------------------------------------------------------------------*
*
TO PASS THE DEFAULT VALUE OF THE VARIANT IF THE PARAMETER
*
FOR VARIANT IS LEFT AS BLANK
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*&---------------------------------------------------------------------*
*
IF THE USER DOESN'T ENTERS ANY VALUE FOR VARIANT
*
THEN THE DEFAULT VARIANT SHOULD BE USED TO DISPLAY
*&---------------------------------------------------------------------*
IF p_var EQ ' '.
PERFORM get_default_variant USING p_var.
*&---------------------------------------------------------------------*
*
IF THE USER ENTERS SOME VARIANT NAME FOR THE SELECTION
*
SCREEN WHICH NEED TO BE VALIDATED AGAINST THE EXISTING
*
VARIANTS
*&---------------------------------------------------------------------*
ELSE.
PERFORM chec _variant_existence USING p_var.
ENDIF.
*&---------------------------------------------------------------------*
*
START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*
CLEAR ALL THE CONTENTS OF ALL INTERBAL TABLES
*&---------------------------------------------------------------------*
REFRESH it_jest.
REFRESH it_auf .
REFRESH it_af o.
REFRESH it_qmel.
REFRESH it_final.
*&---------------------------------------------------------------------*
*
select user status from TJ02T for TXT04(status of an object)
*
into variable V_ISTAT
*&---------------------------------------------------------------------*
SELECT SINGLE
istat
FROM tj02t
INTO (v_istat)
WHERE
txt04 EQ c_ustat AND
spras EQ c_langu.
*&---------------------------------------------------------------------*
*
select object number based upon the user status selected
*&---------------------------------------------------------------------*
SELECT
objnr
FROM jest
INTO TABLE it_jest

WHERE
stat EQ v_istat.
IF sy-subrc <> 0.
MESSAGE e003.
ELSE.
*&---------------------------------------------------------------------*
*
select into it_auf table: object number, description and
*
object number based on object number selected and order type
*
in PM01 and PM02
*&---------------------------------------------------------------------*
SELECT
aufnr
text
objnr
FROM auf
INTO TABLE it_auf
FOR ALL ENTRIES IN it_jest
WHERE
objnr EQ it_jest-objnr AND
auart IN r_auart.
IF sy-subrc <> 0.
MESSAGE e002.
ELSE.
*&---------------------------------------------------------------------*
*
select into it_af o table: order number and basic finish date
*
based upon order number selected and basic finish date as
*
v_cdate variable
*&---------------------------------------------------------------------*
SELECT
aufnr
gltrp
FROM af o
INTO TABLE it_af o
FOR ALL ENTRIES IN it_auf
WHERE
aufnr EQ it_auf -aufnr AND
gltrp LE v_cdate.
*&---------------------------------------------------------------------*
*
select into it_qmel table: order number and notification
*
number based on the order number selected
*&---------------------------------------------------------------------*
SELECT
aufnr
qmnum
FROM qmel
INTO TABLE it_qmel
FOR ALL ENTRIES IN it_auf
WHERE
aufnr EQ it_auf -aufnr.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*
READ THE RECORDS FOMR THE ABOVE POPULATED INTERNAL TABLE
*
INTO WORK AREA AND THEN POPULATE THE FINAL INTERNAL
*
TABLE
*&---------------------------------------------------------------------*
* read internal table it_jest into wor area wa_jest
LOOP AT it_jest INTO wa_jest.

* read it_auf based on object number from wa_jest


READ TABLE it_auf INTO wa_auf WITH KEY objnr = wa_jest-objnr.
* if records found
IF sy-subrc EQ 0.
* read it_af o for order number and description based on order number
READ TABLE it_af o INTO wa_af o WITH KEY aufnr = wa_auf -aufnr.
* if records found
IF sy-subrc EQ 0.
wa_final-aufnr = wa_af o-aufnr. "move order number to it_final
wa_final- text = wa_auf - text. "move description to it_final
ELSE.
* if no record found then move to next loop pass
CONTINUE.
ENDIF.
ELSE.
* if no record found then move to next loop pass
CONTINUE.
ENDIF.
* read it_qmel for description based on the order number selected above
READ TABLE it_qmel INTO wa_qmel WITH KEY aufnr = wa_final-aufnr.
* if records found
IF sy-subrc EQ 0.
wa_final-qmnum = wa_qmel-qmnum. "move notification number to it_final
ENDIF.
* finally append the records into the final internal table
APPEND wa_final TO it_final. "append wa_final into it_final
CLEAR wa_final. "clear wor area
CLEAR wa_auf . "clear wor area
CLEAR wa_qmel. "clear wor area
ENDLOOP.
*&---------------------------------------------------------------------*
*
TO COUNT THE NUMBER OF RECORDS IN THE FINAL INTERNAL
*
TABLE AND RETURN TO SELECTION SCREEN
*
IF NO RECORDS EXISTS THEN AN INFORMATION MESSGE IS DISPLAYED
*&---------------------------------------------------------------------*
DESCRIBE TABLE it_final
LINES v_line_count.
IF ( v_line_count EQ 0 ).
MESSAGE i002. "error message
EXIT.
ENDIF.
*&---------------------------------------------------------------------*
*
END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*
FIELD CATALOG FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM field_catalog.
*&---------------------------------------------------------------------*
*
SORT W.R.T. WORK ORDER NUMBER FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM sort_field.

*&---------------------------------------------------------------------*
*
FOR LAYOUT FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM set_layout.
*&---------------------------------------------------------------------*
*
DISPLAY RECORDS IN ALV GRID FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM alv_display.
*&---------------------------------------------------------------------*
*&
SUBROUTINE DEFINITIONS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FIELD_CATALOG
*&---------------------------------------------------------------------*
*
SUB-ROUTINE FIELD_CATALOG USED TO SET THE COLUMNS FOR
*
THE ALV GRID (OUTPUT FORMAT)
*
SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog .
wa_field-fieldname = 'FLAG'.
wa_field-tabname = 'IT_FINAL'.
wa_field-outputlen = 2.
wa_field-chec box = c_chec .
wa_field-edit = c_chec .
wa_field-seltext_l = ' '.
APPEND wa_field TO it_field.
CLEAR wa_field.

"
"
"
"
"
"
"
"

name of field from internal table


internal table name
output length on screen
print as chec box
ma e field open for input
header information
append field catalog internal table
clear field catalog wor area

wa_field-fieldname
wa_field-tabname =
wa_field-outputlen
wa_field-seltext_l
APPEND wa_field TO
CLEAR wa_field.

= 'AUFNR'.
'IT_FINAL'.
= 20.
= text-003.
it_field.

"
"
"
"
"
"

name of field from internal table


internal table name
output length on screen
header information
append field catalog internal table
clear field catalog wor area

wa_field-fieldname
wa_field-tabname =
wa_field-outputlen
wa_field-seltext_l
APPEND wa_field TO
CLEAR wa_field.

= 'KTEXT'.
'IT_FINAL'.
= 45.
= text-004.
it_field.

"
"
"
"
"
"

name of field from internal table


internal table name
output length on screen
header information
append field catalog internal table
clear field catalog wor area

wa_field-fieldname
wa_field-tabname =
wa_field-outputlen
wa_field-seltext_l
APPEND wa_field TO
CLEAR wa_field.

= 'QMNUM'.
'IT_FINAL'.
= 22.
= text-005.
it_field.

"
"
"
"
"
"

name of field from internal table


internal table name
output length on screen
header information
append field catalog internal table
clear field catalog wor area

ENDFORM.
" FIELD_CATALOG
*&---------------------------------------------------------------------*
*&
Form SORT_FIELD
*&---------------------------------------------------------------------*
*
SUB-ROUTINE SORT_FIELD IS USED TO SORT THE RECORDS IN THE
*
INTERNAL TABLE BASED ON THE GIVEN FIELD AND NATURE OF

*
SORTING TO BE DONE (ASCENDING OR DESCENDING)
*----------------------------------------------------------------------*
FORM sort_field .
wa_sort-spos = 1.
wa_sort-fieldname = 'AUFNR'.
wa_sort-tabname = 'IT_FINAL'.
wa_sort-up = c_chec .
APPEND wa_sort TO it_sort.
CLEAR wa_sort.

"
"
"
"
"
"

sort priority
field on which records sorted
internal table name
sort ascending
append sort info internal table
clear sort info wor area

ENDFORM.
" SORT_FIELD
*&---------------------------------------------------------------------*
*&
Form SET_LAYOUT
*&---------------------------------------------------------------------*
*
SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
*
ALV GRID LINES IN ALTERNATIVE COLOURS
*----------------------------------------------------------------------*
FORM set_layout .
wa_layout-zebra = c_chec .
ENDFORM.

" so set colors of line alternatively

" SET_LAYOUT

*&---------------------------------------------------------------------*
*&
Form ALV_DISPLAY
*&---------------------------------------------------------------------*
*
SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
*
FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
*
AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
*
DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display .

*
*
*

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_INTERFACE_CHECK
= ' '
I_BYPASSING_BUFFER
= ' '
I_BUFFER_ACTIVE
= ' '
i_callbac _program
= v_rep_id
i_callbac _pf_status_set
= 'PF'
i_callbac _user_command
= 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE
= ' '
I_CALLBACK_HTML_TOP_OF_PAGE
= ' '
I_CALLBACK_HTML_END_OF_LIST
= ' '
I_STRUCTURE_NAME
=
I_BACKGROUND_ID
= ' '
I_GRID_TITLE
=
I_GRID_SETTINGS
=
is_layout
= wa_layout
it_fieldcat
= it_field
IT_EXCLUDING
=
IT_SPECIAL_GROUPS
=
it_sort
= it_sort
IT_FILTER
=
IS_SEL_HIDE
=
I_DEFAULT
= 'X'
i_save
= 'A'
is_variant
= wa_variant
IT_EVENTS
=

" report id
" for PF-STATUS
" for User-Command

" for layout


" field catalog
" sort info

" variant name

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

IT_EVENT_EXIT
IS_PRINT
IS_REPREP_ID
I_SCREEN_START_COLUMN
I_SCREEN_START_LINE
I_SCREEN_END_COLUMN
I_SCREEN_END_LINE
I_HTML_HEIGHT_TOP
I_HTML_HEIGHT_END
IT_ALV_GRAPHICS
IT_HYPERLINK
IT_ADD_FIELDCAT
IT_EXCEPT_QINFO
IR_SALV_FULLSCREEN_ADAPTER
IMPORTING
E_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER
TABLES
t_outtab
EXCEPTIONS
program_error
OTHERS

=
=
=
=
=
=
=
=
=
=
=
=
=
=

0
0
0
0
0
0

=
=
= it_final

" internal table

= 1
= 2.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.

" ALV_DISPLAY

*&---------------------------------------------------------------------*
*&
Form pf
*&---------------------------------------------------------------------*
*
SUB-ROUTINE PF IS USED TO SET THE PF-STATUS OF THE SCREEN
*
ON WHICH THE ALV GRID IS DISPLAYED
*----------------------------------------------------------------------*
*
-->RT_EXTAB
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZTG_STAT'.
ENDFORM.
"pf
*&---------------------------------------------------------------------*
*&
Form USER_COMMAND
*&---------------------------------------------------------------------*
*
SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
*
AND EXECUTE THE APPROPIATE CODE
*----------------------------------------------------------------------*
*
-->LV_OKCODE used to capture the function code
*
of the user-defined push-buttons
*
-->L_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING lv_o code LIKE sy-ucomm l_selfield TYPE slis_selfield.
* assign the function code to variable v_o code
lv_o code = sy-ucomm.
* handle the code execution based on the function code encountered
CASE lv_o code.

* when the function code is EXECUTE then process the selected records
WHEN 'EXECUTE'.
* refresh it_process when user processes selected records
REFRESH it_process.
* to reflect the data changed into internal table
DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->chec _changed_data.
ENDIF.
*----------------------------------------------------------------------*
* sort the internal table by flag descending so that the selected
* records are appended at the beginning of internal table
*----------------------------------------------------------------------*
SORT it_final BY flag DESCENDING.
*----------------------------------------------------------------------*
* move the selected records from final internal table into another
* internal table so that they can be processed
*----------------------------------------------------------------------*
LOOP AT it_final INTO wa_final WHERE flag = 'X'.
wa_process-aufnr = wa_final-aufnr.
wa_process- text = wa_final- text.
wa_process-qmnum = wa_final-qmnum.
APPEND wa_process TO it_process.
ENDLOOP.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_chec .
* now all the selected records by the user at run-time are appended into
* into a new internal table which can now be used to processed as per the
* user requirements
DATA : line_count1 TYPE i.
DESCRIBE TABLE it_process
LINES line_count1.
IF line_count1 GE 1.
PERFORM user_action.
ELSE.
MESSAGE e002.
ENDIF.
WHEN 'SEL_ALL'.
* to select all the records displayed in ALV Grid
LOOP AT it_final INTO wa_final.
wa_final-flag = 'X'.
MODIFY it_final FROM wa_final.
ENDLOOP.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_chec .

WHEN 'DESEL_ALL'.
* to deselect all the records displayed in ALV Grid
LOOP AT it_final INTO wa_final.
wa_final-flag = ' '.
MODIFY it_final FROM wa_final.
ENDLOOP.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_chec .
ENDCASE.
ENDFORM.
"USER_COMMAND
*&---------------------------------------------------------------------*
*&
Form F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*
SUB-ROUTINE f4_variant_help TO GET A F4 HELP FOR VARIANT
*
SELECTION AND DISPLAY DATA ACCORDINGLY
*----------------------------------------------------------------------*
*
<--P_P_VAR text
*----------------------------------------------------------------------*
FORM f4_variant_help USING p_p_var.

*
*
*

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'


EXPORTING
is_variant
= wa_variant " export variant
I_TABNAME_HEADER
=
I_TABNAME_ITEM
=
IT_DEFAULT_FIELDCAT
=
i_save
= 'A'
" layout for all users
i_display_via_grid
= 'X'
" grid view of variants
IMPORTING
E_EXIT
=
es_variant
= wa_i_variant " import variant
EXCEPTIONS
not_found
= 1
program_error
= 2
OTHERS
= 3.
IF sy-subrc = 0.
PASS THE SELECTED VARIANT TO THE SELECTION SCREEN FIELD
p_p_var = wa_i_variant-variant.
ELSEIF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM.
" F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*&
Form GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*
SUB-ROUTINE GET_DEFAULT_VARIANT TO PASS THE DEFAULT VARIANT
*
IF USER DOESN'T ENTERS ANY VALUE FOR THE VARIANT
*----------------------------------------------------------------------*
*
<--P_P_VAR variant name
*----------------------------------------------------------------------*
FORM get_default_variant USING l_p_var.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save
= 'A'

CHANGING
cs_variant
= wa_variant "variant name
EXCEPTIONS
wrong_input = 1
not_found
= 2
program_error = 3
OTHERS
= 4.
* IF DEFAULT VARIANT FOUND
IF sy-subrc = 0.
* PASS THE DEFAULT VARIANT TO THE SELECTION SCREEN FIELD
l_p_var = wa_variant-variant.
ELSEIF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
" GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*&
Form CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
*
SUB-ROUTINE CHECK_VARIANT_EXISTENCE TO VALIDATE THE VARIANT
*
NAME ENTERED BY THE USER
*
IF VARIANT FOUND THEN EXECUTE
*
ELSE DISPLAY ERROR MESSAGE
*----------------------------------------------------------------------*
*
<--P_P_VAR variant name
*----------------------------------------------------------------------*
FORM chec _variant_existence USING l_p_var.
*&---------------------------------------------------------------------*
*
ASSIGN THE VALUE OF THE VARIANT ENTERED BY USER TO THE
*
WORK AREA FIELD AND CHECK FOR ITS EXISTENCE
*&---------------------------------------------------------------------*
wa_variant-variant = l_p_var.
*&---------------------------------------------------------------------*
*
TO CHECK THE EXISTENCE FOR VARIANT CORRESPONDING TO
*
EXISTING VARIANT IF THE USER ENTERS SOME VALUE FOR
*
THE PARAMETER
*&---------------------------------------------------------------------*
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save
= 'A'
CHANGING
cs_variant
= wa_variant " variant name
EXCEPTIONS
wrong_input = 1
not_found
= 2
program_error = 3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE e001.
ENDIF.
ENDFORM.
" CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
*&
Form USER_ACTION
*&---------------------------------------------------------------------*
*
SUB-ROUTINE USER_ACTION CAN BE USED AS PER THE USER REQUIREMENT
*
TO PROCESS THE SELECTED RECORDS IN ALV GRID DISPLAY
*----------------------------------------------------------------------*

FORM user_action.
*
user code to process selected records in internal table
*
it_process
*&---------------------------------------------------------------------*
*
FIELD CATALOG FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM field_catalog1.
*&---------------------------------------------------------------------*
*
SORT W.R.T. WORK ORDER NUMBER FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM sort_field1.
*&---------------------------------------------------------------------*
*
FOR LAYOUT FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM set_layout1.
*&---------------------------------------------------------------------*
*
DISPLAY RECORDS IN ALV GRID FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM alv_display1.
ENDFORM.
" F4_FILE_REQUEST
*&---------------------------------------------------------------------*
*&
Form FIELD_CATALOG1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
*
SUB-ROUTINE FIELD_CATALOG USED TO SET THE COLUMNS FOR
*
THE ALV GRID (OUTPUT FORMAT)
*
SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog1 .
REFRESH it_field1.
CLEAR wa_field1.
wa_field1-fieldname
wa_field1-tabname =
wa_field1-outputlen
wa_field1-seltext_l
APPEND wa_field1 {
Comments (2)
Show Comments
Follow SCN
Contact Us
SAP Help Portal
Privacy
Terms of Use
Legal Disclosure
Copyright

= 'AUFNR'.
'IT_PROCESS'.
= 20.
= text-003.

"
"
"
"

name of field from internal table


internal table name
output length on screen
header information