Professional Documents
Culture Documents
Sales document, SAP provides means to add our own data into Qutation
document and so user is able to display and maintain through standard
maintenance transaction (e.g. VA21, VA22, and VA23). The fields normally
placed under tab Additional Data B at header level. Following is one of
the ways adding custom fields into the screen.
When click on SPAR field and press enter then following report is calling
with option box using alv opps .
*&---------------------------------------------------------------------*
ZSD_QUATION_SPAR.
ZFOCUS_PROG,VBAK.
*
CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
** Toolbar handler.
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
* button press
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
"lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
** append a separator to normal toolbar
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
** append an icon for your function
** Select All Rows
CLEAR ls_toolbar.
MOVE 'SELE' TO ls_toolbar-function.
MOVE icon_select_all TO ls_toolbar-icon.
MOVE 'Select all checkbox' TO ls_toolbar-quickinfo.
MOVE '' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
"#EC NOTEXT
CLEAR ls_toolbar.
** Deselect all Rows.
MOVE 'DSEL' TO ls_toolbar-function.
MOVE icon_deselect_all TO ls_toolbar-icon.
MOVE 'Deselect all checkbox' TO ls_toolbar-quickinfo.
MOVE '' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
"handle_toolbar
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'SELE'.
PERFORM select_all_rows.
WHEN 'DSEL'.
PERFORM deselect_all_rows.
WHEN OTHERS.
"#EC NOTEXT
ENDCASE.
ENDMETHOD.
"handle_user_command
ENDCLASS.
"lcl_event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
*&
Form SELECT_ALL_ROWS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM select_all_rows .
FIELD-SYMBOLS <fs_stock1> TYPE ty_zst_stock_partS.
LOOP AT itab ASSIGNING <fs_stock1>.
<fs_stock1>-check_b = zcl_ecc_globalobject=>gv_x.
ENDLOOP.
CALL METHOD o_grid->check_changed_data.
CALL METHOD o_grid->refresh_table_display.
ENDFORM.
" SELECT_ALL_ROWS
*&---------------------------------------------------------------------*
*&
Form DESELECT_ALL_ROWS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM deselect_all_rows .
FIELD-SYMBOLS <fs_stock1> TYPE ty_zst_stock_parts.
LOOP AT itab ASSIGNING <fs_stock1>.
<fs_stock1>-check_b = ''.
ENDLOOP.
CALL METHOD o_grid->check_changed_data.
CALL METHOD o_grid->refresh_table_display.
ENDFORM.
" DESELECT_ALL_ROWS
Form
GET_SELECTED_ROWS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_selected_rows .
DATA : l_count TYPE I.
FIELD-SYMBOLS : <fs_stock1> TYPE ty_zst_stock_parts.
CALL METHOD o_grid->check_changed_data.
IMPORT vbak-vbeln FROM MEMORY id 'ZVBELN'.
LOOP AT itab ASSIGNING <fs_stock1>.
IF <fs_stock1>-check_b = zcl_ecc_globalobject=>gv_x AND <fs_stock1>pid IS NOT INITIAL.
**
IF SPAR NE '003'.
**
l_count = l_count + 1.
**
CLEAR WA.
**
IF l_count GE 2.
**
MESSAGE 'PLEASE SELECT ONE ROW ONLY' TYPE 'E'.
**
else.
wa1-zfocus = <fs_stock1>-zfocus.
wa1-pg_type = <fs_stock1>-pG_type.
WA1-PG_YEAR = <fs_stock1>-PG_YEAR.
wa1-pid = <fs_stock1>-pid.
wa1-CR_TYP = <fs_stock1>-CR_TYP.
WA1-VBELN = VBAK-VBELN.
APPEND wa1 TO itab1.
CLEAR wa1.
*
endif.
*
ENDIF.
ENDIF.
ENDLOOP.
IF itAB1 IS NOT INITIAL.
EXPORT itAB1 TO MEMORY ID 'PART'.
ENDIF.
ENDFORM.
" GET_SELECTED_ROWS
** START-OF-SELECTION.
*&---------------------------------------------------------------------*
*&
Form GET_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form GET_DATA .
IMPORT IT_QT FROM MEMORY ID 'PART_C'.
* IMPORT ITab FROM MEMORY ID 'PART_C'.
SELECT * FROM zfocus_prog INto CORRESPONDING FIELDS OF TABLE itab_FOC
WHERE piD = spar.
LOOP AT itab_FOC INTO WA_FOC.
*
*
*
*
*
*
i_appl_events
= space
i_parentdbg
=
i_applogparent
=
i_graphicsparent =
i_name
=
i_fcat_complete
= space
EXCEPTIONS
error_cntl_create = 1
error_cntl_init
= 2
error_cntl_link
= 3
error_dp_create
= 4
OTHERS
= 5
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
f_conatiner = 'X'.
endform.
" BUILD_CONATINER
*&---------------------------------------------------------------------*
*&
Form BUILD_CATALOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM build_catalog .
DEFINE fieldcat.
wa_fcat-col_pos = &1.
wa_fcat-fieldname = &2.
wa_fcat-tabname = &3.
wa_fcat-scrtext_l = &4.
wa_fcat-checkbox = &5.
wa_fcat-edit = &6.
append wa_fcat to it_fcat.
clear wa_fcat.
END-OF-DEFINITION.
*
IF c_box = zcl_ecc_globalobject=>gv_x.
**********change**********
fieldcat
fieldcat
fieldcat
fieldcat
fieldcat
fieldcat
fieldcat
'1'
'2'
'3'
'4'
'5'
'6'
'7'
wa_layout-zebra = zcl_ecc_globalobject=>gv_x.
wa_layout-cwidth_opt = zcl_ecc_globalobject=>gv_x.
*
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Module EXIT INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module EXIT input.
CASE sy-ucomm.
WHEN 'CANCEL'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
endmodule.
" EXIT INPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module STATUS_0200 output.
SET PF-STATUS 'PF_200'.
* SET TITLEBAR 'xxx'.
IF f_conatiner IS INITIAL .
PERFORM build_conatiner.
PERFORM build_catalog.
PERFORM display_output.
ENDIF.
endmodule.
" STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
Form DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form DISPLAY_OUTPUT .
* IF c_box = zcl_ecc_globalobject=>gv_x.
SET HANDLER l_obj->handle_toolbar FOR o_grid.
SET HANDLER l_obj->handle_user_command FOR o_grid.
CALL METHOD o_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
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.
*
ENDIF.
w_variant-report = sy-repid.
*
*
*
*
*
*
*
*
*
*
*
*
i_consistency_check
=
i_structure_name
=
is_variant
= w_variant
i_save
= 'X'
I_DEFAULT
= 'X'
is_layout
= wa_layout
is_print
=
it_special_groups
=
it_toolbar_excluding
=
it_hyperlink
=
it_alv_graphics
=
it_except_qinfo
=
ir_salv_adapter
=
CHANGING
it_outtab
= itAB
it_fieldcatalog
= it_fcat
it_sort
=
it_filter
=
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 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.
ENDIF.
"change
endform.
" DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module USER_COMMAND_0200 input.
DATA: l_count TYPE i.
PERFORM get_selected_data.
PERFORM user_action_button.
endmodule.
" USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*&
Form GET_SELECTED_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form GET_SELECTED_DATA .
CALL METHOD o_grid->get_selected_rows
IMPORTING
et_index_rows = it_index
*
et_row_no
=
.
LOOP AT it_index INTO wa_index.
READ TABLE itAB INTO wa INDEX wa_index-index.
ENDLOOP.
IF SPAR NE '3'.
l_count = 0.
Save to database
In the event custom field is appended directly in table VBAK and VBAP table
no additional logic is required as SAP will automatically populate the
custom values to database.
We can put saving logic under user exit USEREXIT_SAVE_DOCUMENT in include
MV45AFZZ.
At this point VBAK and XVBAP is visible and VBAK-VBELN contains new document
number in case of document creation.