2017-07-18 4 views
-2
TABLES: mara, marc. 
    "marc is N 181 
    "mara is 1 157 
    DATA: lt_mara TYPE TABLE OF mara, 
      ls_mara TYPE mara, 
      lt_marc TYPE TABLE OF marc, 
      ls_marc TYPE marc, 
      BEGIN OF ls_out OCCURS 0, 
      mtart LIKE mara-mtart, 
      matnr LIKE marc-matnr, 
      werks LIKE marc-werks, 
      ntgew LIKE mara-ntgew, 
      brgew LIKE mara-brgew, 
      sum LIKE mara-brgew, 
      color(4). 
    DATA: END OF ls_out. 
    DATA: lt_out LIKE TABLE OF ls_out, 
      fcat TYPE slis_t_fieldcat_alv, 
      ls_fcat LIKE LINE OF fcat, 
      layout TYPE slis_layout_alv. 
    FIELD-SYMBOLS: <fsym> LIKE LINE OF fcat. 
    PARAMETERS: p_mtart TYPE mara-mtart. 
    SELECT-OPTIONS: so_werks FOR marc-werks. 
    SELECT * FROM mara INTO TABLE lt_mara 
     WHERE mtart = p_mtart. 
    IF sy-subrc = 0. 
     SELECT * FROM marc INTO TABLE lt_marc 
     FOR ALL ENTRIES IN lt_mara 
     WHERE matnr = lt_mara-matnr 
     AND werks IN so_werks. 
     LOOP AT lt_marc INTO ls_marc. 
     READ TABLE lt_mara INTO ls_mara 
     WITH KEY matnr = ls_marc-matnr. 
     ls_out-sum = ls_mara-brgew + ls_mara-ntgew . 
     MOVE-CORRESPONDING ls_marc TO ls_out. 
     MOVE-CORRESPONDING ls_mara TO ls_out. 
     APPEND ls_out TO lt_out. 
     CLEAR ls_out. 
     ENDLOOP. 
    ELSE. 
     MESSAGE TEXT-e02 TYPE 'E' . 
    ENDIF. 
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' 
     EXPORTING 
     i_program_name   = sy-repid "e merr auto 
     i_internal_tabname  = 'LS_OUT' 
     i_client_never_display = 'X' 
     i_inclname    = sy-repid 
     CHANGING 
     ct_fieldcat   = fcat[] 
     EXCEPTIONS 
     inconsistent_interface = 1 
     program_error   = 2 
     OTHERS     = 3. 
    READ TABLE fcat INDEX 6 ASSIGNING <fsym>. 
    <fsym>-outputlen = 15. 

    *-conditionally populate the color 
    LOOP AT LS_OUT. 
     IF LS_OUT-sum eq 21. 
     LS_OUT-color = 'C311'. 
     ENDIF. 
     MODIFY LS_OUT. 
    ENDLOOP. 
    layout-info_fieldname = 'COLOR'. 
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
     EXPORTING 
     i_callback_program = sy-repid 
     i_structure_name = 'LS_OUT' 
     it_fieldcat  = fcat[] 
     TABLES 
     t_outtab   = lt_out 
     EXCEPTIONS 
     program_error  = 1 
     OTHERS    = 2. 

Comment puis-je afficher la ligne où la somme de ls_out est 1900? Quelqu'un peut-il me dire ce qu'il faut ajouter à mon code? Cela fonctionne j'ai juste besoin de colorier. Toutes les variables semblent être déclarées. Remplissez le code avec ces P_MATARTFERTso_werks1000 à 1998.Couleur abap alv row

+2

On ne sait pas très bien ce que vous demandez. Voulez-vous que tous les autres rangs soient colorés? Voulez-vous que des valeurs spécifiques d'un champ soient colorées? Veuillez clarifier votre question, en la rendant aussi succincte que possible. – gkubed

+0

@gkubed J'ai, je demande à colorier les lignes où la somme est LT 5000 – user3026665

Répondre

0
LOOP AT Lt_OUT. 
     IF Lt_OUT-SUM LT 50000. 
    Lt_OUT-color = 'C311'. 
     ENDIF. 
     MODIFY Lt_OUT. 
    ENDLOOP. 
    layout-info_fieldname = 'COLOR". 
1

Ajout du paramètre suivant à votre appel à REUSE_ALV_GRID_DISPLAY devrait résoudre votre problème

is_layout = layout

+0

Désolé, ce n'est pas! même si je fais le ls_out-SUM ou une autre colonne LT 5000 il ne jaunit aucun – user3026665

+0

Maintenant votre programme colore avec la condition SI LS_OUT-sum eq 21, changez cela à la condition appropriée. Désactivez également la valeur si la condition échoue, c'est-à-dire ajoutez une clause ELSE. –

0

Si vous voulez gérer les /! \ Mise en forme d'une cellule particulière dans ALV, ici est la manière .

FORM update_style using 
    x type lvc_fname " x is 'MATNR', 'VBELN', 'BELNR'.... whatever in your fieldcatalog 
    y type int4 " y = 1,2,3..... 
    update_mask type xstring 
    update_style type xstring. 

READ table gt_alv into gs_alv index y. 
tabstyle = gs_alv-tabstyle. 
READ table tabstyle into s_style with key fieldname = x. 

" check if fieldname already exists in gs_alv-tabstyle (insert or update) 

s_style-style = s_style-style BIT-AND update_mask. 
s_style-style = s_style-style BIT-OR update_style. 

" Update or insert gs_alv-tabstyle from s_style 
" update gt_alv from gs_alv 

ENDFORM. 

Comment attribuer une couleur à une ligne dans ALV (Mais vous ne pouvez pas avoir fond de la cellule et la couleur de police en même temps!)

perform update_style USING x y 'FFFFFFE0' update_style. 

update_style can be : 

'00000000'. " Disable any color 
'00000011'. " White Font 
'00000017'. " Red fond 
'00000013'. " gray font 
'00000014'. " Yellow font 
'00000015'. " blue font 
'00000016'. " green font 
'00000018'. " orange font 
'00000011'. " black font 

'0000000D'. " background dark blue 
'0000000A'. " background fluo blue 
'00000005'. " background blue 
'00000003'. " background light blue 
'00000000'. " background gray 
'00000001'. " background light gray 
'00000004'. " backgorund yellow 
'0000000C'. " background dark yellow 
'00000006'. " background green 
'0000000E'. " background dark green 
'00000010'. " background dark orange 
'0000000F'. " background red 
'00000007'. " background pink 
'00000008'. " background orange 
'00000001'. " background standard 

Si vous voulez gérer éditable, gras, italique, souligné ... propriétés

perform update_style USING x y 'FFFFFF9F' '00000020'. " set bold 
perform update_style USING x y 'FFFFFF9F' '00000040'. " unset bold property 

perform update_style USING x y 'FFFFF9FF' '00000200'. " Underline 
perform update_style USING x y 'FFFFF9FF' '00000400'. " stop underlying 

perform update_style USING x y 'FFFFF57F' '00000080' " italic 

perform update_style USING x y 'FF9FFFFF' '00200000' " hotspot 
perform update_style USING x y 'FF9FFFFF' '00400000' " no hotspot 

perform update_style USING x y 'F9E7FFFF' '00080000' " Editable 
perform update_style USING x y 'F9E7FFFF' '00100000' " Non Editable 

Pour les alignements, update_mask est 'DFFFF57F' Et update_style peut être:

DATA alv_style_align_left_top(4) TYPE x VALUE '00000800'. 
    DATA alv_style_align_center_top(4) TYPE x VALUE '00001000'. 
    DATA alv_style_align_right_top(4) TYPE x VALUE '00001800'. 
    DATA alv_style_align_left_center(4) TYPE x VALUE '00002000'. 
    DATA alv_style_align_center_center(4) TYPE x VALUE '00002800'. 
    DATA alv_style_align_right_center(4) TYPE x VALUE '00003000'. 
    DATA alv_style_align_left_bottom(4) TYPE x VALUE '00003800'. 
    DATA alv_style_align_center_bottom(4) TYPE x VALUE '00004000'. 
    DATA alv_style_align_right_bottom(4) TYPE x VALUE '00004800'. 

Si vous voulez gérer les frontières, vous devez modifier s_style-style2 avec:

'FFFBFFFF' '00040000' " Remove top border 
'FFF7FFFF' '00080000' " Remove bottom border 
'FFFEFFFF' '00010000' " Remove left border 
'FFFDFFFF' '00020000' " Remove right border 

Et après tout cela (même après set_table_for_first_display) vous avez juste besoin d'appeler une forme ou une méthode appelée REFRESH Depuis que j'ai écrit un implentation de CL_GUI_ALV_GRID de classe I ne utilise pas, mais les méthodes: les formulaires FORM

METHOD REFRESH. 
    DATA ls_stable TYPE lvc_s_stbl. 
    ls_stable-row = 'X'. 
    ls_stable-col = 'X'. 

    CALL METHOD me->refresh_table_display 
    EXPORTING 
    is_stable = ls_stable 
    EXCEPTIONS 
    finished = 1 
    OTHERS = 2. 
ENDMETHOD. 

x et y ne sont pas les champs obligatoires, donc je boucle sur toutes les lignes peuvent à définir une propriété à une colonne (y est unset)

ASSIGN mt_outtab->* TO <tab>. 
    CHECK <tab> IS ASSIGNED. 
    LOOP AT <tab> ASSIGNING <line>. 
     update_style(x sy-tabix update_mask update_style) 

ou boucle sur mon fieldcatalog pour définir une propriété à une ligne (x est unset)

LOOP at me->get_frontend_fieldcatalog() in ls_fcat 
     update_style(ls_fcat-fieldname y update_mask update_style) 

Pour plus de possibilités, consultez lien

ABAP Alv_grid Merge cells and style formating of cells