Hi,
This is a Simple ALV report which contains most of the options that can be done in ALV.
Data:v_vbeln type vbrk-vbeln.
TYPE-POOLS:slis.
select-options:s_vbeln for v_vbeln.
PARAMETERS:p_varnt TYPE slis_vari. "ALV variant
TYPES:BEGIN OF ty_vbrp,
vbeln TYPE vbeln_vf,
posnr TYPE posnr_vf,
matnr TYPE matnr,
fkimg TYPE fkimg,
vrkme TYPE vrkme,
END OF ty_vbrp.
DATA:l_wa_vbrp TYPE ty_vbrp.
TYPES:BEGIN OF ty_final,
box TYPE char1,
vbeln TYPE vbeln_vf,
posnr TYPE posnr_vf,
matnr TYPE matnr,
fkimg TYPE fkimg,
vrkme TYPE vrkme,
END OF ty_final.
DATA:i_final TYPE STANDARD TABLE OF ty_final,
l_wa_final TYPE ty_final.
DATA:i_vbrp TYPE STANDARD TABLE OF ty_vbrp.
* Variables used for variant declaration
DATA: v_variant TYPE disvariant, "Variant
v_variant_value TYPE disvariant, "Variant
v_save(1) TYPE c VALUE 'A'. " For Storing VALUE 'A'
CONSTANTS: c_a TYPE char1 VALUE 'A', "Value 'A'
c_form_top TYPE slis_formname VALUE 'TOP_OF_PAGE'.
INITIALIZATION.
* Sends variant to ALV
PERFORM f_layout_variant.
AT SELECTION-SCREEN.
*Checks whether user defined variant already exists
PERFORM f_check_variant.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varnt.
* Help request for variant value
* To get variant defined for selection
PERFORM f4_for_variant.
START-OF-SELECTION.
SELECT vbeln posnr matnr fkimg vrkme
FROM vbrp INTO TABLE i_vbrp
WHERE vbeln in s_vbeln.
LOOP AT i_vbrp INTO l_wa_vbrp.
l_wa_final-vbeln = l_wa_vbrp-vbeln.
l_wa_final-posnr = l_wa_vbrp-posnr.
l_wa_final-matnr = l_wa_vbrp-matnr.
l_wa_final-fkimg = l_wa_vbrp-fkimg.
l_wa_final-vrkme = l_wa_vbrp-vrkme.
APPEND l_wa_final TO i_final.
ENDLOOP.
DATA:fp_i_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv.
CONSTANTS:c_outputlen15 TYPE dd03p-outputlen VALUE '15'.
END-OF-SELECTION.
wa_fcat-col_pos = '1'.
wa_fcat-fieldname = 'BOX'.
wa_fcat-tabname = 'I_FINAL'.
wa_fcat-checkbox = 'X'.
*wa_fcat-input = 'X'.
wa_fcat-edit = 'X'.
wa_fcat-fix_column = 'X'.
wa_fcat-outputlen = '1'.
APPEND wa_fcat TO fp_i_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = '2'.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-tabname = 'I_FINAL'.
wa_fcat-outputlen = c_outputlen15.
wa_fcat-seltext_l = 'Sales doc'.
APPEND wa_fcat TO fp_i_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = '3'.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-tabname = 'I_FINAL'.
wa_fcat-outputlen = c_outputlen15.
wa_fcat-seltext_l = 'Item No'.
APPEND wa_fcat TO fp_i_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = '4'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-tabname = 'I_FINAL'.
wa_fcat-outputlen = c_outputlen15.
wa_fcat-seltext_l = 'Material'.
APPEND wa_fcat TO fp_i_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = '5'.
wa_fcat-fieldname = 'FKIMG'.
wa_fcat-tabname = 'I_FINAL'.
wa_fcat-outputlen = c_outputlen15.
wa_fcat-seltext_l = 'Quantity'.
*the option do_sum is needed if we want to find the subtotal
*After filling this we have to pass the option subtot in it_sort.
wa_fcat-do_sum = 'X'. " ='C' to calculate the avg
APPEND wa_fcat TO fp_i_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = '6'.
wa_fcat-fieldname = 'VRKME'.
wa_fcat-tabname = 'I_FINAL'.
wa_fcat-outputlen = c_outputlen15.
wa_fcat-seltext_l = 'Unit'.
APPEND wa_fcat TO fp_i_fcat.
CLEAR wa_fcat.
CONSTANTS:c_ucomm TYPE slis_formname VALUE 'USER_COMM',
c_sub_pf_set TYPE slis_formname VALUE 'SUB_PF_SET'.
DATA:v_repid TYPE repid,
l_wa_set TYPE lvc_s_glay. "Grid setting for check
*CALL BACK PROGRAM IS MUST IF WE WANT TO SET OUR OWN PF STATUS
v_repid = sy-repid.
* Set the grid setting for editable ALV
*this is must if the check box ticked on the selection screen needs to be updated in the
*internal table I_FINAL
l_wa_set-edt_cll_cb = 'X'.
*to facilitate the sorting of the internal table.
DATA: wa_sort TYPE slis_sortinfo_alv,
i_sort TYPE slis_t_sortinfo_alv.
*wa_sort-spos = '01'. "Works only if box is not there
wa_sort-fieldname = 'POSNR'.
wa_sort-tabname = 'I_FINAL'.
* wa_sort-up = 'X'.
wa_sort-down = 'X'.
* wa_sort-subtot = 'X'.
* Append work area
APPEND wa_sort TO i_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = v_repid
i_callback_pf_status_set = c_sub_pf_set
i_callback_user_command = c_ucomm
i_callback_top_of_page = c_form_top
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
i_grid_settings = l_wa_set
* IS_LAYOUT =
it_fieldcat = fp_i_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = i_sort
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
i_save = c_a "Needs to be passed to save the variant in the alv output
is_variant = v_variant_value "to send the variant value from selection screen
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_final
EXCEPTIONS
program_error = 1
OTHERS = 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.
*&---------------------------------------------------------------------*
*& Form user_comm
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FP_UCOMM text
* -->FP_SELFIELD text
*----------------------------------------------------------------------*
FORM user_comm USING fp_ucomm TYPE syucomm
fp_selfield TYPE slis_selfield.
CASE fp_ucomm.
WHEN 'SASI1'.
DELETE i_final INDEX fp_selfield-tabindex.
*to refresh the screen.
fp_selfield-refresh = 'X'.
ENDCASE.
ENDFORM. "USER_COMM
*---------------------------------------------------------------------*
* FORM sub_pf_set *
*---------------------------------------------------------------------*
* PF status routine
*---------------------------------------------------------------------*
FORM sub_pf_set USING fp_rt_extab TYPE slis_t_extab.
*To set the standard PF status.
*Transaction SE41
*SAPLSLVC program- status STANDARD
SET PF-STATUS 'SASI1'.
ENDFORM. "sub_pf_set
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* Top of Page routine
*---------------------------------------------------------------------*
FORM top_of_page.
DATA:i_list_top_of_page TYPE slis_t_listheader,
rec_head TYPE slis_listheader.
CLEAR rec_head.
rec_head-typ = 'S'.
rec_head-key = 'SASI'.
rec_head-info = 'To display the header in the AlV output'.
APPEND rec_head TO i_list_top_of_page.
CLEAR rec_head.
* Write the top of page of the ALV using function module
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_list_top_of_page.
ENDFORM. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form f_layout_variant
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_layout_variant .
CLEAR v_variant_value.
v_variant_value-report = sy-repid.
PERFORM f_get_default_variant.
ENDFORM. " f_layout_variant
*&---------------------------------------------------------------------*
*& Form f_get_default_variant
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_get_default_variant .
v_variant = v_variant_value.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = c_a
CHANGING
cs_variant = v_variant
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
p_varnt = v_variant-variant.
ENDIF.
ENDFORM. " f_get_default_variant
*&---------------------------------------------------------------------*
*& Form f_check_variant
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_check_variant .
IF NOT p_varnt IS INITIAL.
MOVE v_variant_value TO v_variant.
MOVE p_varnt TO v_variant-variant.
*Check whether the user entered variant exists
*through function module,REUSE_ALV_VARIANT_EXISTENCE.
*If the variant does not exist issue appropriate
*error message.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = c_a
CHANGING
cs_variant = v_variant
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE e501. "Variant does not exist.
ENDIF.
v_variant_value = v_variant.
ELSE.
CLEAR v_variant_value.
v_variant_value-report = sy-repid.
ENDIF.
ENDFORM. " f_check_variant
*&---------------------------------------------------------------------*
*& Form f4_for_variant
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f4_for_variant .
DATA: l_exit(1) TYPE c. " For storing exit value
v_variant = v_variant_value.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = v_variant_value
i_save = v_save
IMPORTING
e_exit = l_exit
es_variant = v_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc EQ 0 AND l_exit = space.
p_varnt = v_variant-variant.
ENDIF.
ENDFORM. " f4_for_variant
No comments:
Post a Comment