Vous êtes sur la page 1sur 10

HOW TO INSERT A FIELD AT QUTATION:

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.

Append the custom field to database table


We need to prepare containers to store the custom data into the database. We can create new custom
transparent tables containing all the custom fields along with key fields to link with sales document
tables or the easiest way we can append the field to the sales document tables, i.e. in this example we
will use VBAK tables. The later approach is easier and simpler because we dont need to develop our
own logic to retrieve and save our custom data from/to database.
We can use Append Structure functionality through transaction SE11 to add our field into the tables.
Because our custom field will appear as a list-box, we can create a new domain where the possible
values are set and a new data element that will make use of the new domain. The custom field should
then make use of the new data element we created as its data type.
In this example we will name the new field as SPAR so that we will have VBAK-SPAR and VBAP-SPAR.

Paint the custom fields


Open transaction SE80, program SAPMV45A, screen 8309 (header level screen) and screen 8459 (item
level screen).
Go to the screen layout and appends our field there and paint the layout at header level.
If the custom field is slotted in VBAK , It is better to name the dynpro-field the same as the field name in
database, for example VBAK-SPAR, because then SAP will be able to determine the corresponding
fields of database table VBAK or VBAP where the value should be referring to.

When click on SPAR field and press enter then following report is calling
with option box using alv opps .

*&---------------------------------------------------------------------*

*& Report ZSD_QUATION_SPAR


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT
TABLES :

ZSD_QUATION_SPAR.
ZFOCUS_PROG,VBAK.

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


PARAMETERS : SPAR TYPE ZFOCUS_PROG-pid.
SELECT-OPTIONS : VBELN FOR VBAK-VBELN NO INTERVALS NO-EXTENSION..
SELECTION-SCREEN END OF BLOCK B1.
DATA : wa_layout
TYPE
lvc_s_layo.
TYPES : BEGIN OF ty_zst_stock_parts,
check_b TYPE c,
pg_type TYPE zfocus_prog-pg_type,
zfocus TYPE zfocus_prog-zfocus,
porg_name TYPE zfocus_prog-porg_name,
pg_year TYPE zfocus_prog-pg_year,
cr_typ TYPE zfocus_prog-cr_typ,
eff_dt TYPE zfocus_prog-eff_dt,
pid TYPE zfocus_prog-pid,
END OF ty_zst_stock_parts.
DATA : itab TYPE TABLE OF ty_zst_stock_parts,
wa TYPE ty_zst_stock_parts.
DATA: wa_index
TYPE lvc_s_row,
it_index
TYPE lvc_t_row.
DATA : ITAB_FOC TYPE TABLE OF zfocus_prog,
WA_FOC TYPE zfocus_prog.
TYPES : BEGIN OF tab,
pg_type TYPE zfocus_prog-pg_type,
pid TYPE zfocus_prog-pid,
zfocus TYPE zfocus_prog-zfocus,
PG_YEAR TYPE zfocus_prog-PG_YEAR,
CR_TYP TYPE ZFOCUS_PROG-CR_TYP,
VBELN TYPE VBAK-VBELN,
END OF tab.
DATA : IT_QT TYPE TABLE OF tab,
WA_QT TYPE tab..
DATA: o_docking
TYPE REF TO
cl_gui_docking_container,
o_grid
TYPE REF TO
cl_gui_alv_grid.
DATA: it_fcat
TYPE STANDARD TABLE OF lvc_s_fcat,
WA_FCAT TYPE lvc_s_fcat.
DATA : itab1 TYPE TABLE OF tab,
wa1 TYPE tab.
DATA :f_conatiner
TYPE c,
g_alt
TYPE c,
w_variant TYPE disvariant..
FIELD-SYMBOLS : <fs_field> TYPE any.
*************Change***********************************
****************Class Definition & Implementation*****
*----------------------------------------------------------------------*

*
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

DATA : l_obj TYPE REF TO lcl_event_handler,


grid1 TYPE REF TO cl_gui_alv_grid.
START-OF-SELECTION.
CREATE OBJECT l_obj.
PERFORM get_data.
CALL SCREEN 200.
*&---------------------------------------------------------------------*
*&

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.

READ TABLE it_qt INTO wa_qt WITH key zfocus = wa_foc-zfocus


pg_year = wa_foc-pg_yeAr pg_type = wa_foc-pg_type.
if sy-subrc = 0.
wa-check_B = 'X'.
MOVE-CORRESPONDING WA_FOC TO WA.
APPEND WA TO ITAB.
CLEAR : wa_foc,wa.
ELSE.
MOVE-CORRESPONDING WA_FOC TO WA.
APPEND WA TO ITAB.
CLEAR :wa.
ENDIF.
ENDLOOP.
endform.
" GET_DATA
*&---------------------------------------------------------------------*
*&
Form BUILD_CONATINER
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form BUILD_CONATINER .
CREATE OBJECT o_docking
EXPORTING
*
parent
=
*
repid
=
*
dynnr
=
side
= ctld_dock_at_bottom
" extension
=
*
style
=
*
lifetime
= cntl_lifetime_default
*
caption
=
*
metric
= 0
ratio
= '85'
*
no_autodef_progid_dynnr
=
" name
= 'DOCK'
EXCEPTIONS
cntl_error
= 1
cntl_system_error
= 2
create_error
= 3
lifetime_error
= 4
lifetime_dynpro_dynpro_link = 5
OTHERS
= 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF sy-subrc EQ 0 .
CREATE OBJECT o_grid
EXPORTING
*
i_shellstyle
= 0
*
i_lifetime
=
i_parent
= o_docking

*
*
*
*
*
*

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'

'CHECK_B' 'ITAB' 'Select' 'X' 'X'.


"#EC NOTEXT
'PORG_NAME' 'ITAB' 'Program Name' '' ''.
'ZFOCUS' 'ITAB' 'Program ID' '' ''.
'PG_TYPE' 'ITAB' 'Program Type' ' ' ' '.
"#EC NOTEXT
'PG_YEAR' 'ITAB' 'YEAR' '' ''.
'CR_TYP' 'ITAB' 'Credit Type' '' ''.
'EFF_DT' 'ITAB' 'Effective Dates' '' ''.

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.

CALL METHOD o_grid->set_table_for_first_display


EXPORTING
*
i_buffer_active
=
*
i_bypassing_buffer
=

*
*
*
*
*
*
*
*
*
*

*
*

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.

LOOP AT itAB INTO WA WHERE check_b = 'X'.


l_count = l_count + 1.
CLEAR WA.
IF l_count GE 2.
MESSAGE 'PLEASE SELECT ONE ROW ONLY' TYPE 'E'.
ENDIF.
ENDLOOP.
ENDIF .
CLEAR :
l_count.
endform.
" GET_SELECTED_DATA
*&---------------------------------------------------------------------*
*&
Form USER_ACTION_BUTTON
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form USER_ACTION_BUTTON .
CASE sy-ucomm.
WHEN 'BACK'.
BREAK sarmip.
PERFORM get_selected_rows.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
PERFORM get_selected_rows.
ENDCASE.
endform.
" USER_ACTION_BUTTON
*IMPORT itAB FROM MEMORY ID 'PART'.
*
* CALL SCREEN '8000' STARTING AT 20 3.

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.

Vous aimerez peut-être aussi