IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SAP Discussion :

[ ALV orienté object ] click


Sujet :

SAP

  1. #1
    Nouveau membre du Club Avatar de roxanne
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    50
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 50
    Points : 25
    Points
    25
    Par défaut [ ALV orienté object ] click
    Bonjour tou le monde,
    j'utilise un ALV orienté objet et je veux gerer l'evenment d'un simple click ou double click sur une ligne de l'ALV.
    quand je click sur une ligne je veux appler une transaction par exemple.
    Merci.

  2. #2
    Rédacteur
    Avatar de cladsam
    Profil pro
    Inscrit en
    Août 2003
    Messages
    1 785
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Août 2003
    Messages : 1 785
    Points : 2 436
    Points
    2 436
    Par défaut
    Merci de mettre un morceau de code pour voir la façon dont tu gères ton ALV ( par exemple, si tu passes bien par les classes CL_SALV_TABLE ou CL_SALV_TREE etc .)

    Ensuite, si tel est le cas, tu peux regarder le programme SAP de demo prévu à cet effet ( SALV_LEARN_MAP_TABLE_4 ). Et s'il y a quelque chose que tu ne comprends pas/ n'arrive pas à reproduire dans ce programme, merci de mettre un morceau de code avec une question plus précise sur ce qui te pose problème

  3. #3
    Nouveau membre du Club Avatar de roxanne
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    50
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 50
    Points : 25
    Points
    25
    Par défaut
    Bonjour,
    Voila les Methodes qui me petmettent d'afficher mon ALV dans un conteneur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    CALL METHOD alv_grid->set_table_for_first_display
           EXPORTING
             i_default                     = c_X
             is_layout                     = it_layout
           CHANGING
             it_outtab                     = t_table[]
             it_fieldcatalog               = t_fieldcat[]
           .
    
      IF alv_container IS INITIAL.
        CREATE OBJECT alv_container
          EXPORTING
             container_name              =  mycontainer  
          .
    
        CREATE OBJECT alv_grid
          EXPORTING
             i_parent          = alv_container
          .
    j'ai deux questions :
    1- apres avoir fait un doucle click sur une ligne, comment je peux recuperer les valeurs et pouvoir faire un autre traitement avec les valeurs recuperées.

    2-dans le cas oú je veux selectionner plusieurs lignes de mon ALV en me servant de la barre de selection se trouvant a l'extrimité gauche de l'ALV, comment je fais pour pouvoir récuperer les valeurs des lignes selectionnées.

    Merci.

  4. #4
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Août 2009
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Exemple de code ALV
    *&---------------------------------------------------------------------*
    *& PROGRAM ZUT_ALV_OBI_SALDO.
    *&
    *& Sample program for table edit through ALV
    *& with check against duplicate keys, protocol and delta update
    *&---------------------------------------------------------------------*

    * Steps to create this program in your system:
    *
    * 1. SE38: create executable program (type 1)
    *
    * 2. SE80: create screen 0100
    *
    * 3. Screen Painter: on the screen 0100 create 'Custom control'
    * CONT1_0100
    *
    * 4. SE80: for screen 0100 set the variable OK_CODE for the element OK
    *
    * 5. SE80: create calls to PBO and PAI in the flow logic of screen 0100:
    *
    * PROCESS BEFORE OUTPUT.
    * MODULE pbo_0100.
    * PROCESS AFTER INPUT.
    * MODULE pai_0100.
    *
    * 6. SE80: create GUI Status STAT_0100, assign functions EXIT and SAVE
    * to standard icons, eventually create your own toolbar button

    PROGRAM zfx_obi_saldo_alv.

    *Include for ALV styles
    INCLUDE <cl_alv_control>.

    TYPES: BEGIN OF ts_data.
    INCLUDE STRUCTURE zfx_obi_saldo.
    TYPES: mod_type TYPE string. " type of modification (for protocol)
    TYPES: verified TYPE c. " flag for verification
    TYPES: celltab TYPE lvc_t_styl.
    TYPES: rowcolor(4) TYPE c.
    TYPES: color TYPE lvc_t_scol. "Cell coloring

    TYPES: END OF ts_data.

    TYPES:
    tt_data TYPE STANDARD TABLE OF ts_data WITH NON-UNIQUE DEFAULT KEY.

    CLASS cl_event_handler DEFINITION DEFERRED.

    * ALV Layout (colors)
    DATA:
    * v_alv_layout TYPE lvc_s_layo,
    i_alv_color TYPE lvc_t_scol,
    v_alv_color TYPE lvc_s_scol,
    v_alv_color_cell TYPE lvc_s_colo.

    DATA:
    ls_layout TYPE lvc_s_layo.

    DATA:
    gt_data TYPE tt_data,
    go_grid TYPE REF TO cl_gui_alv_grid,
    go_cont TYPE REF TO cl_gui_custom_container,
    gt_fcat TYPE lvc_t_fcat,
    ok_code LIKE sy-ucomm,
    go_event_handler TYPE REF TO cl_event_handler.

    DATA: w_cwidth_opt TYPE c.
    *----------------------------------------------------------------------*
    * CLASS cl_event_handler DEFINITION
    *----------------------------------------------------------------------*
    CLASS cl_event_handler DEFINITION.

    PUBLIC SECTION.

    CLASS-DATA:
    data_changed_error TYPE i, " error flag
    protocol_tab TYPE tt_data. " protocol of changes since last save

    METHODS handle_toolbar
    FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING
    e_object
    e_interactive.

    METHODS handle_user_command
    FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING
    e_ucomm.

    METHODS handle_data_changed
    FOR EVENT data_changed OF cl_gui_alv_grid
    IMPORTING
    er_data_changed.

    METHODS protocol_add
    IMPORTING
    pi_tabix TYPE i
    er_data_changed TYPE REF TO cl_alv_changed_data_protocol.

    ENDCLASS. "cl_event_handler DEFINITION

    *----------------------------------------------------------------------*
    * CLASS cl_event_handler IMPLEMENTATION
    *----------------------------------------------------------------------*
    CLASS cl_event_handler IMPLEMENTATION.

    *&---------------------------------------------------------------------*
    *& METHOD handle_toolbar
    *&---------------------------------------------------------------------*
    METHOD handle_toolbar.

    FIELD-SYMBOLS:
    <fs_button> TYPE stb_button.

    * replace the standard function 'check' with own one
    READ TABLE e_object->mt_toolbar ASSIGNING <fs_button>
    WITH KEY function = cl_gui_alv_grid=>mc_fc_check. " '&CHECK'.
    <fs_button>-function = 'CHECK'.

    ** deactivate the 'copy row' function
    ** (not necessary in the logic of this program)
    *
    * READ TABLE e_object->mt_toolbar ASSIGNING <fs_button>
    * WITH KEY function = cl_gui_alv_grid=>mc_fc_loc_copy_row. " '&LOCAL&COPY_ROW'.
    * <fs_button>-disabled = 'X'.
    ENDMETHOD. "handle_toolbar

    *&---------------------------------------------------------------------*
    *& METHOD handle_user_command
    *&---------------------------------------------------------------------*
    METHOD handle_user_command.

    * force PAI processing with user function as ok_code
    cl_gui_cfw=>set_new_ok_code( e_ucomm ).

    ENDMETHOD. "handle_user_command

    *&---------------------------------------------------------------------*
    *& METHOD handle_data_changed
    *&---------------------------------------------------------------------*
    *& validate changes against duplicate keys and collect the protocol
    *& of the changes for further db update or transport of changes
    *&---------------------------------------------------------------------*
    METHOD handle_data_changed.

    DATA:
    ls_row TYPE lvc_s_moce,
    lt_data TYPE tt_data,
    ls_data TYPE ts_data,
    ls_data2 TYPE ts_data,
    lv_tabix TYPE i,
    lv_tabix2 TYPE i,
    lv_new TYPE i.

    FIELD-SYMBOLS:
    <ft_data> TYPE tt_data.

    ASSIGN er_data_changed->mp_mod_rows->* TO <ft_data>.

    data_changed_error = 0.

    * 1. collect the deleted rows (no checks needed)
    LOOP AT er_data_changed->mt_deleted_rows INTO ls_row.

    READ TABLE gt_data INTO ls_data INDEX ls_row-row_id.
    ls_data-mod_type = 'DELETE'.
    APPEND ls_data TO protocol_tab.
    ENDLOOP.

    * 2. collect the 'old' changed rows (no changes on key fields)
    LOOP AT <ft_data> INTO ls_data
    WHERE verified = 'X'.

    ls_data-mod_type = 'UPDATE'.
    APPEND ls_data TO protocol_tab.
    ENDLOOP.

    * 3. check the new rows against the old, verified rows
    LOOP AT <ft_data> INTO ls_data
    WHERE verified = ''.

    lv_tabix = sy-tabix.
    ADD 1 TO lv_new.

    READ TABLE gt_data TRANSPORTING NO FIELDS
    WITH KEY mandt = ls_data-mandt
    bukrs = ls_data-bukrs
    hkont = ls_data-hkont
    gjahr = ls_data-gjahr
    mwskz = ls_data-mwskz
    prctr = ls_data-prctr.

    CHECK sy-subrc = 0.

    data_changed_error = 1.

    CALL METHOD protocol_add
    EXPORTING
    pi_tabix = lv_tabix
    er_data_changed = er_data_changed.

    ENDLOOP.

    * 4. check the new rows among themselves
    IF lv_new > 1.
    LOOP AT <ft_data> INTO ls_data
    WHERE verified = ''.

    lv_tabix = sy-tabix.

    LOOP AT <ft_data> INTO ls_data2
    WHERE verified = ''.

    lv_tabix2 = sy-tabix.
    CHECK lv_tabix2 <> lv_tabix.

    * CHECK ls_data2-carrid = ls_data-carrid
    * AND ls_data2-connid = ls_data-connid.

    CHECK ls_data2-mandt = ls_data-mandt
    AND ls_data2-bukrs = ls_data-bukrs
    AND ls_data2-hkont = ls_data-hkont
    AND ls_data2-gjahr = ls_data-gjahr
    AND ls_data2-mwskz = ls_data-mwskz
    AND ls_data2-prctr = ls_data-prctr.

    data_changed_error = 1.

    CALL METHOD protocol_add
    EXPORTING
    pi_tabix = lv_tabix
    er_data_changed = er_data_changed.

    CALL METHOD protocol_add
    EXPORTING
    pi_tabix = lv_tabix2
    er_data_changed = er_data_changed.

    ENDLOOP.
    ENDLOOP.
    ENDIF.

    * 5. collect new rows if check against duplicate key was ok
    IF data_changed_error = 0.

    LOOP AT <ft_data> INTO ls_data
    WHERE verified = ''.

    ls_data-mod_type = 'INSERT'.
    APPEND ls_data TO protocol_tab.
    ENDLOOP.
    ENDIF.

    ** 6. activate the copied rows
    ** (not necessary in the logic of this program)
    *
    * DATA:
    * ls_cell TYPE lvc_s_modi.
    *
    * LOOP AT er_data_changed->mt_inserted_rows INTO ls_row.
    *
    * LOOP AT er_data_changed->mt_mod_cells INTO ls_cell
    * WHERE row_id = ls_row-row_id.
    *
    * CALL METHOD er_data_changed->modify_style
    * EXPORTING
    * i_row_id = ls_cell-row_id
    * i_fieldname = ls_cell-fieldname
    * i_style = cl_gui_alv_grid=>mc_style_enabled.
    * ENDLOOP.
    * ENDLOOP.
    ENDMETHOD. "handle_data_changed

    *&---------------------------------------------------------------------*
    *& METHOD protocol_add
    *&---------------------------------------------------------------------*
    METHOD protocol_add.

    DATA:
    ls_cell TYPE lvc_s_modi,
    ls_fcat TYPE lvc_s_fcat,
    lv_string TYPE string,
    lv_msgv1 TYPE symsgv,
    lv_msgv2 TYPE symsgv,
    ls_roid_front TYPE lvc_s_roid,
    lv_row_id TYPE i.

    LOOP AT er_data_changed->mt_mod_cells INTO ls_cell
    WHERE tabix = pi_tabix.

    * report only key fields
    READ TABLE gt_fcat INTO ls_fcat WITH KEY fieldname = ls_cell-fieldname.
    CHECK ls_fcat-key = 'X'.

    * report only once
    READ TABLE er_data_changed->mt_protocol TRANSPORTING NO FIELDS
    WITH KEY fieldname = ls_cell-fieldname
    row_id = ls_cell-row_id.

    CHECK sy-subrc <> 0.

    * map the row id between frontend and internal tables for the message
    READ TABLE er_data_changed->mt_roid_front INTO ls_roid_front
    WITH KEY row_id = ls_cell-row_id.

    lv_row_id = sy-tabix.

    lv_msgv1 = 'Row &1:'.
    lv_string = lv_row_id.
    REPLACE SUBSTRING '&1' IN lv_msgv1 WITH lv_string.

    lv_msgv2 = 'Duplicate key with value ''&1'''.
    lv_string = ls_cell-value.
    REPLACE SUBSTRING '&1' IN lv_msgv2 WITH lv_string.

    CALL METHOD er_data_changed->add_protocol_entry
    EXPORTING
    i_msgid = '0K'
    i_msgno = '000'
    i_msgty = 'E'
    i_msgv1 = lv_msgv1
    i_msgv2 = lv_msgv2
    i_fieldname = ls_cell-fieldname
    i_row_id = ls_cell-row_id. " pass the row id without mapping here
    ENDLOOP.
    ENDMETHOD. "protocol_add
    ENDCLASS. "cl_event_handler IMPLEMENTATION

    *&---------------------------------------------------------------------*
    *& START-OF-SELECTION
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.

    PERFORM data_load CHANGING gt_data.

    * initially check all rows as verified
    PERFORM data_verified_set CHANGING gt_data.

    PERFORM fieldcat_create CHANGING gt_fcat.

    PERFORM data_key_readonly_set USING gt_fcat CHANGING gt_data.

    CALL SCREEN 0100.

    *&---------------------------------------------------------------------*
    *& Form data_load
    *&---------------------------------------------------------------------*
    FORM data_load CHANGING pt_data TYPE tt_data.

    SELECT *
    INTO CORRESPONDING FIELDS OF TABLE pt_data
    FROM zfx_obi_saldo.

    ENDFORM. "data_load

    *&---------------------------------------------------------------------*
    *& Form fieldcat_create
    *&---------------------------------------------------------------------*
    FORM fieldcat_create CHANGING pt_fcat TYPE lvc_t_fcat.

    FIELD-SYMBOLS:
    <fs_fcat> TYPE lvc_s_fcat.

    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
    i_structure_name = 'ZFX_OBI_SALDO'
    CHANGING
    ct_fieldcat = gt_fcat.

    LOOP AT gt_fcat ASSIGNING <fs_fcat>.
    <fs_fcat>-edit = 'X'.

    * key fields
    IF <fs_fcat>-fieldname = 'MANDT'
    OR <fs_fcat>-fieldname = 'BUKRS'
    OR <fs_fcat>-fieldname = 'HKONT'
    OR <fs_fcat>-fieldname = 'GJAHR'
    OR <fs_fcat>-fieldname = 'MWSKZ'
    OR <fs_fcat>-fieldname = 'PRCTR'.

    <fs_fcat>-key = 'X'.
    <fs_fcat>-edit = space.
    ELSE.
    <fs_fcat>-key = ''.
    ENDIF.

    * for each and every line of the fieldcat
    CASE sy-tabix.

    *Color Styles
    *Background/Font/Group/positive/negative
    ** WHEN '1'.
    ** <fs_fcat>-style = alv_style_color_inv_positive.
    ** WHEN '2'.
    ** <fs_fcat>-style = alv_style_color_int_negative.
    ** WHEN '3'.
    ** <fs_fcat>-style = alv_style_color_inv_negative.
    ** WHEN '4'.
    ** <fs_fcat>-style = alv_style_color_int_positive.
    ** WHEN '5'.
    ** <fs_fcat>-style = alv_style_color_background.
    ** <fs_fcat>-style = alv_style_color_inv_background.
    ** WHEN '6'.
    ** <fs_fcat>-style = alv_style_color_background.
    * WHEN '7'.
    * <fs_fcat>-style = alv_style_color_group.
    * WHEN '8'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '9'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '10'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '11'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '12'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '13'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '14'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '15'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '16'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '17'.
    * <fs_fcat>-style = alv_style_color_group.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '18'.
    * <fs_fcat>-style = alv_style_color_int_background.
    * WHEN '19'.
    * <fs_fcat>-style = alv_style_color_int_background.
    *
    ***Style for F4
    ** WHEN '7'.
    ** <fs_fcat>-style = alv_style_f4.
    **
    ***Style for Alignment(others are also possible)
    ** WHEN '8'.
    ** <fs_fcat>-style = alv_style_align_left_bottom.
    **
    ***Style for Font Underlined/Bold and Italic are possible
    ** WHEN '9'.
    ** <fs_fcat>-style = alv_style_font_underlined.
    **
    ***Style for button type
    ** WHEN '10'.
    ** <fs_fcat>-style = alv_style_button.
    **
    ***Style for Font Symbol
    ** WHEN '11'.
    ** <fs_fcat>-style = alv_style_font_symbol.
    **
    ***Style for Radiobutton
    ** WHEN '12'.
    ** <fs_fcat>-style = alv_style_radio_checked.
    **
    ***Style for checkbox
    ** WHEN '13'.
    ** <fs_fcat>-style = alv_style_checkbox_checked.
    **
    ***Style for column style characteristics(highlighting the col)
    ** WHEN '14'.
    ** <fs_fcat>-style = alv_col_style_characteristic.
    **
    ***Styles for Enabling the column
    ** WHEN '15'.
    ** <fs_fcat>-style = alv_style_enabled.

    ENDCASE.
    ENDLOOP.
    ENDFORM. "fieldcat_create

    *&---------------------------------------------------------------------*
    *& Form data_key_readonly_set
    *&---------------------------------------------------------------------*
    FORM data_key_readonly_set USING pt_fcat TYPE lvc_t_fcat
    CHANGING pt_data TYPE tt_data.

    DATA:
    lt_style TYPE lvc_t_styl,
    ls_style TYPE lvc_s_styl,
    ls_fcat TYPE lvc_s_fcat.

    FIELD-SYMBOLS:
    <fs_data> TYPE ts_data.

    * the following construct works well for function 'copy row' (MC_FC_LOC_COPY_ROW)
    * (the style of the whole row is not copied and the key fields are open for change)

    * first deactivate complete row for edit
    ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
    INSERT ls_style INTO TABLE lt_style.

    LOOP AT pt_fcat INTO ls_fcat
    WHERE NOT key = 'X'.

    * then activate non-key fields
    ls_style-fieldname = ls_fcat-fieldname.
    ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
    INSERT ls_style INTO TABLE lt_style.
    ENDLOOP.

    LOOP AT pt_data ASSIGNING <fs_data>.
    <fs_data>-celltab = lt_style.
    ENDLOOP.
    ENDFORM. "data_key_readonly_set

    *&---------------------------------------------------------------------*
    *& Form data_verified_set
    *&---------------------------------------------------------------------*
    FORM data_verified_set CHANGING pt_data TYPE tt_data.

    FIELD-SYMBOLS:
    <fs_data> TYPE ts_data.

    LOOP AT pt_data ASSIGNING <fs_data>
    WHERE verified = ''.

    <fs_data>-verified = 'X'.

    ENDLOOP.
    ENDFORM. "data_verified_set

    *&---------------------------------------------------------------------*
    *& Form data_change_post_processing
    *&---------------------------------------------------------------------*
    FORM data_change_post_processing CHANGING pt_data TYPE tt_data.

    * check all rows as verified
    PERFORM data_verified_set CHANGING pt_data.

    * deactivate edit mode of key fields
    PERFORM data_key_readonly_set USING gt_fcat
    CHANGING pt_data.

    * refresh ALV grid from internal table
    CALL METHOD go_grid->refresh_table_display.

    ENDFORM. "data_change_post_processing

    *&---------------------------------------------------------------------*
    *& Form data_save
    *&---------------------------------------------------------------------*
    FORM data_save.

    DATA:
    ls_data TYPE ts_data,
    ls_db_data TYPE zfx_obi_saldo.

    LOOP AT cl_event_handler=>protocol_tab INTO ls_data.

    MOVE-CORRESPONDING ls_data TO ls_db_data.

    IF ls_db_data-mwskz = space.
    ls_db_data-mwskz = '--'.
    ENDIF.

    CASE ls_data-mod_type.

    WHEN 'INSERT'.
    INSERT zfx_obi_saldo FROM ls_db_data.

    WHEN 'UPDATE'.
    UPDATE zfx_obi_saldo FROM ls_db_data.

    WHEN 'DELETE'.
    DELETE zfx_obi_saldo FROM ls_db_data.
    ENDCASE.
    ENDLOOP.

    COMMIT WORK.

    MESSAGE s999(b1) WITH 'Daten gesichert'.
    ENDFORM. "data_save

    *&---------------------------------------------------------------------*
    *& Form alv_init
    *&---------------------------------------------------------------------*
    FORM alv_init.


    IF go_cont IS INITIAL.

    SET PF-STATUS 'STAT_0100'.

    CREATE OBJECT go_cont
    EXPORTING
    container_name = 'CONT1_0100'.

    CREATE OBJECT go_grid
    EXPORTING
    i_parent = go_cont.

    CREATE OBJECT go_event_handler.
    SET HANDLER go_event_handler->handle_toolbar FOR go_grid.
    SET HANDLER go_event_handler->handle_user_command FOR go_grid.
    SET HANDLER go_event_handler->handle_data_changed FOR go_grid.

    ls_layout-stylefname = 'CELLTAB'.
    ls_layout-info_fname = 'ROWCOLOR'.

    ls_layout-grid_title = 'GMBS: OBI ZFX_OBI_SALDO Tabelle mutieren'.

    ls_layout-cwidth_opt = 'X'.
    ls_layout-zebra = 'X'.
    ls_layout-col_opt = 'X'.

    * Color the cells
    PERFORM color_cells.

    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
    is_layout = ls_layout
    CHANGING
    it_fieldcatalog = gt_fcat
    it_outtab = gt_data.

    ** if you need event DATA_CHANGED after function 'copy row'
    ** (not necessary in the logic of this program)
    *
    * CALL METHOD go_grid->register_edit_event
    * EXPORTING
    * i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    ENDIF.
    ENDFORM. "alv_init

    *&---------------------------------------------------------------------*
    *& Form user_command
    *&---------------------------------------------------------------------*
    FORM user_command.

    CALL METHOD cl_gui_cfw=>dispatch.

    CASE ok_code.

    WHEN 'EXIT'.
    LEAVE PROGRAM.

    * WHEN 'MIN'.
    * ls_layout-cwidth_opt = 'X'.
    ** refresh ALV grid from internal table
    * CALL METHOD go_grid->refresh_table_display.
    *
    * WHEN 'MAX'.
    * ls_layout-cwidth_opt = space.
    ** refresh ALV grid from internal table
    * CALL METHOD go_grid->refresh_table_display.

    WHEN 'CHECK'.
    * 1. synchronize the internal table and check against duplicate keys
    CALL METHOD go_grid->check_changed_data.

    * 2. if there are no duplicated keys
    CHECK cl_event_handler=>data_changed_error = 0.
    * post processing after successful synchronization
    PERFORM data_change_post_processing CHANGING gt_data.

    WHEN 'SAVE'.
    * 1. synchronize the internal table
    CALL METHOD go_grid->check_changed_data.

    * 2. if there are no duplicated keys
    CHECK cl_event_handler=>data_changed_error = 0.
    * post processing after successful synchronization
    PERFORM data_change_post_processing CHANGING gt_data.

    * 3. if the data was changed
    CHECK NOT cl_event_handler=>protocol_tab IS INITIAL.
    * save the delta changes in database
    PERFORM data_save.
    * clear the protocol
    CLEAR cl_event_handler=>protocol_tab.
    ENDCASE.

    CLEAR ok_code.
    ENDFORM. "user_command

    *----------------------------------------------------------------------*
    * MODULE pbo_0100 OUTPUT
    *----------------------------------------------------------------------*
    MODULE pbo_0100 OUTPUT.

    PERFORM alv_init.

    ENDMODULE. "pbo_0100 OUTPUT

    *----------------------------------------------------------------------*
    * MODULE pai_0100 INPUT
    *----------------------------------------------------------------------*
    MODULE pai_0100 INPUT.

    PERFORM user_command.

    ENDMODULE. "pai_0100 INPUT

    *---------------------------------------------------------------------*
    * FORM color_cells
    *---------------------------------------------------------------------*
    * [+] Loop through the data and apply coloring
    *---------------------------------------------------------------------*
    FORM color_cells.

    DATA:
    ls_row TYPE lvc_s_moce,
    lt_data TYPE tt_data,
    ls_data TYPE ts_data.

    * tell the ALV grid what field in v_alv_data contains color information
    ls_layout-ctab_fname = 'COLOR'.

    * loop through each row of the table
    LOOP AT gt_data INTO ls_data.

    * clear the variables
    CLEAR:
    v_alv_color,
    v_alv_color_cell,
    i_alv_color.

    REFRESH:
    i_alv_color.

    * apply the colors
    * IF ls_data-mwskz <> '--'.
    * PERFORM color_cell USING 'MWSKZ' 5. "positive
    * ENDIF.

    PERFORM color_cell USING 'MANDT' 5. "Total
    PERFORM color_cell USING 'BUKRS' 5. "Total
    PERFORM color_cell USING 'HKONT' 5. "Total
    PERFORM color_cell USING 'GJAHR' 5. "Total
    PERFORM color_cell USING 'MWSKZ' 5. "Total
    PERFORM color_cell USING 'PRCTR' 5. "Total


    PERFORM color_cell USING 'HSLVT' 3. "Total
    PERFORM color_cell USING 'HSL01' 3. "Total
    PERFORM color_cell USING 'HSL02' 3. "Total
    PERFORM color_cell USING 'HSL03' 3. "Total
    PERFORM color_cell USING 'HSL04' 3. "Total
    PERFORM color_cell USING 'HSL05' 3. "Total
    PERFORM color_cell USING 'HSL06' 3. "Total
    PERFORM color_cell USING 'HSL07' 3. "Total
    PERFORM color_cell USING 'HSL08' 3. "Total
    PERFORM color_cell USING 'HSL09' 3. "Total
    PERFORM color_cell USING 'HSL10' 3. "Total
    PERFORM color_cell USING 'HSL11' 3. "Total
    PERFORM color_cell USING 'HSL12' 3. "Total

    * set the color data for this table row
    ls_data-color = i_alv_color.
    MODIFY gt_data FROM ls_data.

    ENDLOOP.

    ENDFORM. "color_cells

    *---------------------------------------------------------------------*
    * FORM color_cell
    *---------------------------------------------------------------------*
    * [+] Colors a cell in the ALV grid
    *---------------------------------------------------------------------*
    FORM color_cell
    USING
    p_cellname TYPE c
    p_color TYPE i.

    CLEAR:
    v_alv_color_cell,
    v_alv_color.

    * set the color for the cell
    IF p_color = 0.
    v_alv_color_cell-col = cl_gui_resources=>list_col_background.
    ELSEIF p_color = 1.
    v_alv_color_cell-col = cl_gui_resources=>list_col_heading.
    ELSEIF p_color = 2.
    v_alv_color_cell-col = cl_gui_resources=>list_col_normal.
    ELSEIF p_color = 3.
    v_alv_color_cell-col = cl_gui_resources=>list_col_total.
    ELSEIF p_color = 4.
    v_alv_color_cell-col = cl_gui_resources=>list_col_key.
    ELSEIF p_color = 5.
    v_alv_color_cell-col = cl_gui_resources=>list_col_positive.
    ELSEIF p_color = 6.
    v_alv_color_cell-col = cl_gui_resources=>list_col_negative.
    ELSEIF p_color = 7.
    v_alv_color_cell-col = cl_gui_resources=>list_col_group.
    ENDIF.

    v_alv_color-nokeycol = 'X'.
    v_alv_color-fname = p_cellname.
    v_alv_color-color = v_alv_color_cell.
    APPEND v_alv_color TO i_alv_color.

    ENDFORM. "color_cell

Discussions similaires

  1. question sur date sous oracle oriente object
    Par PHPkoala dans le forum SQL
    Réponses: 4
    Dernier message: 22/01/2008, 23h48
  2. Orienté object : dérivation ou pas ?
    Par casafa dans le forum C++
    Réponses: 2
    Dernier message: 25/09/2007, 18h00
  3. debutant oriente object
    Par taurus-le-bien-aime dans le forum Général Python
    Réponses: 3
    Dernier message: 18/07/2007, 21h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo