ALV (Fiche Technique)



Comments



Description

Documentation sur L’ABAP List ViewerVERSION 3.1 ALV PAGE 1 / 94 Documentation sur L’ABAP List Viewer VERSION 3.1 SOMMAIRE : A Introduction :Comment devenir super fort pour faire des listes .......................................................................5 A.I Introduction...................................................................................................................................................5 A.II Fondements théoriques...............................................................................................................................5 B Réalisation technique ALV STANDARD:...........................................................................................................6 B.I Présentation Générale :................................................................................................................................6 B.I.1 Schéma général........................................................................................................................................6 B.I.2 Définition des différentes éléments:.........................................................................................................6 B.I.2.a Ecran – Screen painter.......................................................................................................................6 B.I.2.b Container...........................................................................................................................................6 B.I.2.c Grille ALV.........................................................................................................................................7 B.I.2.d Classe des évènements :....................................................................................................................7 B.I.2.e Catalogue : ........................................................................................................................................7 B.II L’écran – le screen painter.........................................................................................................................8 B.III Le catalogue..............................................................................................................................................10 B.III.1 Définition.............................................................................................................................................10 B.III.2 Méthode automatique :........................................................................................................................10 B.III.3 Méthode manuelle...............................................................................................................................10 B.III.3.a Processus :.....................................................................................................................................10 B.III.3.b Exemple de création du catalogue................................................................................................11 B.III.4 Méthode semi-automatique.................................................................................................................12 B.III.4.a Processus :.....................................................................................................................................12 B.III.5 Exemple...............................................................................................................................................12 B.III.6 Catalogue – Quantité et currency........................................................................................................13 B.III.6.a Gestion des devises : (voir doc SAP)............................................................................................13 B.III.6.b Gestion des quantités : (Voir doc SAP)........................................................................................13 B.IV Le container..............................................................................................................................................14 B.IV.1 Paramètres :.........................................................................................................................................14 B.V Gestion du layout ......................................................................................................................................15 B.V.1 Options principales...............................................................................................................................15 B.V.2 Gestion des couleurs ............................................................................................................................15 B.V.2.a Gestion de colonne en couleur.......................................................................................................15 B.V.2.b Gestion de la couleur pour les lignes.............................................................................................15 B.V.2.c Gestion de la couleur pour des cellules..........................................................................................16 B.V.2.d Affichage zébré des lignes.............................................................................................................16 B.VI Gestion variantes......................................................................................................................................17 B.VII Les évènements.......................................................................................................................................19 B.VII.1 Définition :.........................................................................................................................................19 B.VII.2 Implémentation :................................................................................................................................20 B.VII.3 Utilisation :.........................................................................................................................................21 B.VIII La grille ou composant ALV................................................................................................................23 B.VIII.1 Définition :........................................................................................................................................23 B.VIII.2 Création de l’objet :..........................................................................................................................23 B.VIII.3 La fonction set_table_for_first_display............................................................................................23 B.VIII.4 La fonction refresh_table_display....................................................................................................28 B.VIII.5 La fonction set_focus........................................................................................................................28 B.VIII.6 Exemple :..........................................................................................................................................29 B.IX Gestion avec plusieurs ALV....................................................................................................................31 B.X REALISATION PRATIQUE : Exemple.................................................................................................32 B.X.1 MISE EN ŒUVRE...............................................................................................................................32 B.X.2 EXEMPLES..........................................................................................................................................32 PAGE 2 / 94 Documentation sur L’ABAP List Viewer VERSION 3.1 C Utilisation des fonctions ALV définies pas SAP...............................................................................................47 C.I Fonction Standart SAP pour une ALV rapide.........................................................................................47 C.I.1 Affichage d’un ALV simple...................................................................................................................47 C.I.1.a Appel de base de la fonction REUSE_ALV_LIST_DISPLAY .....................................................47 C.I.1.b Définition de la fonction.................................................................................................................47 C.II Liste hiérarchique ....................................................................................................................................49 C.II.1 Introduction : ........................................................................................................................................49 C.II.2 Clé de correpondance............................................................................................................................49 C.II.3 Layout...................................................................................................................................................49 C.II.3.a Gestion de l’expansion...................................................................................................................50 C.II.3.b Gestion des LED............................................................................................................................50 C.II.3.c Gestion des checkbox.....................................................................................................................50 C.II.3.d Affichage du détail ........................................................................................................................50 C.II.3.e Autres possibilités..........................................................................................................................51 C.III Liste sous forme de grille........................................................................................................................52 C.IV Le catalogue..............................................................................................................................................53 C.IV.1 Définition du catalogue.......................................................................................................................53 C.IV.2 Déclaration :........................................................................................................................................53 C.IV.3 Zone en entrée.....................................................................................................................................54 C.IV.4 EXAMPLE d’implémentation manuelle.............................................................................................54 C.V Gestion du menu et de la barre des boutons...........................................................................................56 C.V.1.a Gestion des codes Transactions et clik de la souris.......................................................................56 C.VI Gestion des variantes...............................................................................................................................58 C.VI.1 Définition.............................................................................................................................................58 C.VI.2 Implémentation....................................................................................................................................58 C.VI.3 Fonction utiles.....................................................................................................................................58 C.VI.3.a Gestion du F4................................................................................................................................58 C.VI.3.b Sauvegarde de la variante dans le PAI (A vérifier)......................................................................58 C.VI.3.c Récupération de la variante par défaut.........................................................................................59 C.VII Table contenant les données..................................................................................................................60 C.VIII Les événements......................................................................................................................................61 C.IX Commentaires : Entête de page..............................................................................................................63 C.X Gestion de plusieurs ALV sur un seul écran ..........................................................................................64 C.X.1 Initialisation..........................................................................................................................................64 C.X.2 Définition des blocs..............................................................................................................................65 C.X.2.a ALV classique :..............................................................................................................................65 C.X.2.b Alv Hiérarchique :.........................................................................................................................65 C.X.3 Affichage des blocs...............................................................................................................................65 C.X.4 Gestion des extraits – sauvegarde de table interne...............................................................................67 C.X.4.a Initialisation...................................................................................................................................67 C.X.4.c Aide F4...........................................................................................................................................68 C.X.4.d Enregistrement de l’extrait............................................................................................................68 C.X.4.e Chargement de l’extrait..................................................................................................................68 C.X.4.f Exemple..........................................................................................................................................68 D ANNEXES :........................................................................................................................................................71 D.I Utilisation de classe sous SAP....................................................................................................................72 D.I.1 Déclaration d’une classe........................................................................................................................72 D.I.2 Exemple de définition de classe.............................................................................................................72 D.I.3 Implémentation d’une classe..................................................................................................................73 E Annexe sur ALV standard..................................................................................................................................74 E.I Gestion des groupes de colonnes pour les variantes :..............................................................................74 E.II Ajout d’un menu........................................................................................................................................75 PAGE 3 / 94 ..................................................................................1 E...............................................85 E.................79 E................87 E.........................................................................................................................III Output Options of Columns...87 E....................VI Events of Class CL_GUI_ALV_GRID ..................................................................................................................................83 E..................VII............................IX Définir un menu contextuel : Bouton droit de la souris...................................................................................81 E...Documentation sur L’ABAP List Viewer VERSION 3...................................................................................V Properties of the Grid Control ....................VII Découpage de l’écran afin d’afficher plusieurs ALV...........VIII Affichage d’un objet ALV sans utiliser de screen Painter ...................................94 PAGE 4 / 94 .......................................................................................................................................90 TO DO :..........89 E...IV Formatting Column Contents ......................................1 Définition de l’écran de sélection................. En effet. Il n’en est rien. Les autres font varier des caractéristiques d’affichage tel que la position de la colonne. L’affichage d’une liste par ALV. le filtre. comme empêcher d’effectuer des totaux sur la colonne (par rapport au fieldname). il est dès lors possible d’afficher la table souhaitée à l’écran…. etc. interactives et amusantes. la gestion de méthodes. La mise en place de cette technique semble nécessiter des connaissances particulièrement poussées de la programmation objet. pour qui veut bien s’arrimer aux exemples abscons délivrés par la maison mère. PAGE 5 / 94 . on trouvera le champ fieldname qui reprend le nom du champ de la table interne souhaité dans la cellule.Documentation sur L’ABAP List Viewer VERSION 3. permettra de gérer un certain nombre de caractéristiques graphiques sur la structure d’entête de colonne. peut s’avérer fastidieuse. Une table de lay-out.1 A Introduction :Comment devenir super fort pour faire des listes NOTA : Cette documentation présente l’implémentation d’une ALV dans un programme en utilisant les fonctions de base fournis par SAP. qui chacun décrit un attribut de la cellule. ‘class’.I Introduction Afin de générer des listes qui soient enfin attractives. seront alors automatiquement gérées. Les esthètes de la programmation objet voudront bien pardonner au néophyte. Pour les profanes. l’export sous Excel. exploitable dans les développements spécifiques. En effet. les approximations et contre sens qui ne sauront manquer d’émailler la présentation. Il faut définir un catalogue qui référence et spécifie les caractéristiques des cellules d’affichage. la gestion en checkbox.. se base sur l’utilisation d’un objet le CL_GUI_ALV_GRID.6.II Fondements théoriques. demande une étude approfondie et une implication coûteuse en temps. cela signifie que chaque champ doit être retrouver en tant que valeur dans le champ ‘fieldname’ de la table catalogue. Aussi.. l’intégration de la programmation objet dans SAP. Parmi ceux-ci. Les fonctions standards de l’ALV telles que le tri. il convient de présenter le résultat de ces investigations en s’orientant principalement vers l’opérationnel.4. affichage de l’en-tête de colonne en hot-spot. Il s’agit donc d’une table interne de 60 champs. Vaguement imprégné de ce qui précède. D’autres fonctionnalités peuvent alors être implantées. dans un menu spécifique afin de gérer une interaction. en vérité. sa taille. d’un objet de R/3 version.…Cette table interne doit reprendre strictement le format de la table interne à afficher. Il s’agit. il est possible d’effectuer exactement le même travail en utilisant astucieusement et uniquement des ‘call function’ adéquats. les Sous totaux. (voir annexe) A. un objet de type ‘custom control’ devra avoir été installé comme réceptacle de la liste dans l’écran appelé. les Totaux. SAP a développé un outil efficace : l’Abap List Viewer. A. et autres ‘public section’. pour peu que les récepteurs adéquats aient été installés dans l’écran appelé. En l’état. etc. dans de nombreux cas simple on peut utiliser certaines fonctions standard fournit par SAP. A ECRAN – SCREEN PAINTER L’affichage d’un composant ALV demande en premier lieu. Une de ces fonctions est décrite en annexe.I. (Une méthode est présentée en annexe permettant d’utiliser une grille ALV sans utiliser le SCREEN PAINTER) B. PAGE 6 / 94 .I. qu’un écran soit définit par l’intermédiaire du screen painter (transaction se51).I Présentation Générale : B.2 Définition des différentes éléments: B. il doit faire référence à un custom contrôle définit dans un écran (Voir screen painter).2.I.Documentation sur L’ABAP List Viewer VERSION 3. (Il existe au sein de SAP des fonctions standards permettant de réaliser en très peu d’étape l’affichage d’une liste.I.B CONTAINER Ce dernier est utilisé pour accueillir le composant ALV.1 Schéma général La réalisation d’un programme sous sap utilisant l’ALV comme outil de report est relativement simple.2.) Le schéma suivant présente l’implémentation basique d’un report sous ALV. cependant un certain nombre d’étapes sont indispensable. Au sein de ce dernier on insérera un objet « custom contrôle ». cependant les possibilités de personnalisation (en particulier pour les évènements) sont alors plus réduites. CONTAINER DE RECEPTION LAYOUT VARIANTE CATALOGUE Paramètre Paramètres : GRILLE ALV Objet attaché : EVENEMENT B.1 B Réalisation technique ALV STANDARD: B. lequel recevra par la suite la grille ALV et limitera la taille à afficher. Variante. sélection… B.E CATALOGUE : Ce dernier correspond à une table interne et définit entièrement les informations relatives à l’affichage des champs dans l’ALV.2. PAGE 7 / 94 . Les trois principaux paramètres à fournir sont : 1.Documentation sur L’ABAP List Viewer VERSION 3.I.1 B. Layout.D CLASSE DES ÉVÈNEMENTS : Celle-ci contient l’ensemble des fonctions définis par l’utilisateur et le comportement associé : double clic. Catalogue B.C GRILLE ALV Ce composant correspond à la grille que l’on souhaite afficher.I. il existe un nombre important de paramètres disponibles afin de modifier son comportement.2.2. 2.I. 3. bouton. Et ensuite appuyer sur le bouton CREER. mais n’est pas obligatoire. Au sein de cette dernière on définit le nom du programme générant les données ainsi que le numéro de l’écran qui sera appelé. Il est possible d’utiliser des containers totalement autonome : voir annexe. il faut appeler la transaction SE51. Remplir les paramètres de l’écran suivant : Une fois l’écran créer. il faut alors le modifier selon notre objectif : PAGE 8 / 94 . Afin de créer un écran contenant un objet « custom contrôle ».1 B.II L’écran – le screen painter NOTA : Cette opération est très simple.Documentation sur L’ABAP List Viewer VERSION 3. Documentation sur L’ABAP List Viewer VERSION 3. IL suffit alors d’activer. Afin de pouvoir utiliser un ok_code.1 Sélection le bouton (custom controle) puis le placer sur la partie de gauche tout en le dimensionnant enfin il faut lui définir un nom. il est indispensable de le définir dans la liste des éléments : (variable de type OK) et dans le programme appelant l’ALV avec le même nom. PAGE 9 / 94 . Custom contrôle Nom de l’objet Nota : Une bonne taille pour un affichage classique semble être :  140 pour la longueur visible  40 pour la hauteur  1 pour les minimums des lignes et colonnes redimensionnables OK_CODE . Déclaration de la table interne : Data : GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE. Ex ‘NAME1’ Correspond à la table de référence.2 Méthode automatique : Si la structure de la table contenant les données est issue du dictionnaire. Voir section sur le composant ALV.A PROCESSUS : 1.3. Référence : REF_FIELD REF_TABLE Correspond au nom du champ de référence.1 B.III.III. Ex ‘KNA1’ PAGE 10 / 94 . B.III Le catalogue Aide SAP : SAP Library  Basis components Basis services / communication interface (BC-SRV) Abap list viewer (BC-SRV-ARL) BC-ALV Grid Control B. B.III. Ajout des champs 1 à 1. Lors de l’ajout d’un champ dans le catalogue. 2. Celui-ci est une table de type LVC_T_FCAT qui contient toutes les informations sur les champs à afficher :      Intitulé de colonne Tooltips Taille Position Autres Il existe plusieurs moyens de générer ce catalogue:    Automatique Manuel Semi-automatique La méthode manuelle permet de définir à la main la totalité des champs nécessaire. on peut soit. un ensemble de paramètres sont fournit tels le catalogue. Tous les champs de la structure sont alors affichés. la définition du catalogue est alors automatiquement faite lors de la création de l’ALV. CHAR…) ou une référence à un champ d’une table du dictionnaire.Documentation sur L’ABAP List Viewer VERSION 3. L’objectif est alors de créer une table interne de type LVC_T_FCAT. lorsque cela est possible faire référence à un champ d’une table du dictionnaire soit définir entièrement les caractéristiques du champ.III.3 Méthode manuelle Tous les champs à afficher dans l’ALV peuvent être définit manuellement en utilisant un type (DEC. B.1 Définition Lors de la création du composant ALV. CLEAR : POS . GT_FIELD_CAT_POSTE-tabname = 't_poste'. GT_FIELD_CAT_poste-coltext = 'QTE en UR'. B. conv = ' ==ALPHA ' for function module CONVERSION_EXIT_ALPHA_OUTPUT ).1 Spécifique: TEXTE Définition du champ : DATATYPE ou INTTYPE COLTEXT TOOLTIP SELTEXT DATATYPE INTTYPE OUTPUTLEN Intitulé de la colonne Intitulé de la bulle d’aide Intitulé du texte Type de donnée : DEC. APPEND GT_FIELD_CAT_POSTE. GT_FIELD_CAT_POSTE-COL_POS = POS. On utilise alors le champ EDIT_MASK If you set a conversion exit (for example. I Largeur de la colonne Il peut être utile dans le cas de champs spécifique d’utiliser des routines de conversion d’entréesortie. CLEAR GT_FIELD_CAT_POSTE. APPEND GT_FIELD_CAT_POSTE. GT_FIELD_CAT_POSTE-tabname = 't_poste'.Documentation sur L’ABAP List Viewer Les intitulés sont alors directement récupérés et ne peuvent pas être modifiés. GT_FIELD_CAT_POSTE-FIELDNAME = 'Z_FKIMG'. GT_FIELD_CAT_POSTE-DATATYPE = 'QUAN'. GT_FIELD_CAT_POSTE-KEY = 'X'. GT_FIELD_CAT_POSTE-FIELDNAME = 'VRKME'. GT_FIELD_CAT_POSTE-OUTPUTLEN = '3'. GT_FIELD_CAT_POSTE-REF_TABLE = 'VBRP'. PAGE 11 / 94 . VERSION 3.B EXEMPLE DE CRÉATION DU CATALOGUE DATA : GT_FIELD_CAT_POSTE type LVC_T_FCAT with header line.3. CHAR Type de donnée élémentaire C.III. Commun : Nom du champ FIELDNAME KEY COL_POS Désignation Référence à la table interne contenant les données Clé (si la valeur ‘X’ est fourni alors la colonne sera affichée à gauche de l’ALV et sera figée par rapport aux déplacements horizontaux) Position de la colonne. GT_FIELD_CAT_POSTE-ref_field = 'VRKME'. (See also F1 help for WRITE edit option USING EDIT MASK) . GT_FIELD_CAT_POSTE-COL_POS = POS. GT_FIELD_CAT_poste-seltext = 'Quantité facturé en unité de référence'. you enforce output conversion for the associated output field. POS = POS + 1. POS TYPE I VALUE 1. GT_FIELD_CAT_POSTE. 4. 'ECART. GT_FIELDCAT-OUTPUTLEN APPEND GT_FIELDCAT. on peut alors soit utiliser le champ ‘NO_OUT’ dans la structure du catalogue.A PROCESSUS : 1. 2.'(100). on peut utiliser des champs issus du dictionnaire mais aussi spécifiques. '12'.1 Si on génère le catalogue de façon semi-automatique.'(102). * Appel de la fonction afin de générer un catalogue * a partir de la table ZINV définit dans le dictionnaire CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'ZINV' CHANGING CT_FIELDCAT = gt_fieldcat[]. Il est alors possible de lire la table et de modifier les différents paramètres. clear gt_fieldcat. Déclarer une table interne du type LVC_T_FCAT . Appeler la fonction LVC_FIELDCATALOG_MERGE et donner en argument   la structure de la table contenant les données à afficher la table interne correspondant au catalogue 3. Data : GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE. Il n’est par contre pas possible de modifier les intitulés des colonnes générées automatiquement à partir du dictionnaire. Désignation Nom du champ Position de la colonne dans l’ALV Intitulé de la colonne Intitulé de la Bulle d’aide Intitulé de la colonne lors d’un passage de la souris Type de donnée (Pour les données de base on utilise le champ INTTYPE) Taille de la colonne en sortie = 'DEC'. * Exemple de suppression delete gt_fieldcat where fieldname = 'UZEIT'. * Exemple de modification PAGE 12 / 94 . (voir LVC_T_FCAT) B. = 13.4. refresh gt_fieldcat. Par exemple si on souhaite afficher une structure du dictionnaire sans pour autant afficher toutes les colonnes. Ajout de champs spécifiques se fait alors manuellement : Nom du champ CLEAR GT_FIELDCAT. Il est alors aussi possible de modifier ou d’ajouter des champs.5 Exemple * On initialise le catalogue. soit effacer l’enregistrement. GT_FIELDCAT-FIELDNAME GT_FIELDCAT-COL_POS GT_FIELDCAT-COLTEXT GT_FIELDCAT-TOOLTIP GT_FIELDCAT-SELTEXT GT_FIELDCAT-DATATYPE Exemple de valeur = = = = = 'ECART'.III.4 Méthode semi-automatique VERSION 3. B.III. 'ECART.III.'(101).Documentation sur L’ABAP List Viewer B. 'ECART. 6 Catalogue – Quantité et currency B.1 B.A GESTION DES DEVISES : (VOIR DOC SAP) Dans le cas. GT_FIELDCAT-OUTPUTLEN = 13.6. on peut : o o Soit utiliser le champ QUANTITY pour une devise fixe pour toute la colonne. GT_FIELDCAT-FIELDNAME = 'QSTSA'.III. GT_FIELDCAT-TOOLTIP = 'STOCK SAP'(101). Soit QFIELDNAME faisant référence à un autre champ (de type unit tel que KG) du Catalogue. ENDIF. PAGE 13 / 94 .III. VERSION 3.III. * Exemple d’ajout de champ spécifique CLEAR GT_FIELDCAT. où l’on affiche des valeurs nécessitant un formatage selon une devise. B. Soit CFIELDNAME faisant référence à un autre champ (de type devise telles que DEM ou USD) du Catalogue. GT_FIELDCAT-COL_POS = '8'.Documentation sur L’ABAP List Viewer READ TABLE GT_FIELDCAT WITH KEY FIELDNAME = 'WERKS'. GT_FIELDCAT-COL_POS = '1'.6. APPEND GT_FIELDCAT. GT_FIELDCAT-SELTEXT = 'STOCK SAP'(102). GT_FIELDCAT-DATATYPE = 'DEC'. on peut : o o Soit utiliser le champ CURRENCY pour une devise fixe pour toute la colonne. MODIFY GT_FIELDCAT INDEX SY-TABIX. GT_FIELDCAT-COLTEXT = 'STOCK SAP'(100). * GT_FIELDCAT-SYMBOL = 'X'.B GESTION DES QUANTITÉS : (VOIR DOC SAP) Dans le cas. où l’on affiche des valeurs nécessitant un formatage selon une quantité. IF SY-SUBRC = 0. B. La déclaration du container se fait de préférence au début du programme. Celui-ci fait appel à un container crée au préalable dans un screen. *Dans le PBO ! * Création de l’objet container * create a custom container control for our ALV Control IF custom_container1 is initial. CREATE OBJECT custom_container1 EXPORTING container_name = cont_on_main “ Nom du Container de référence EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5.1 Paramètres : cont_on_main doit contenir le nom du « custom contrôle» * Déclaration du container DATA custom_container1 TYPE REF TO cl_gui_custom_container.1 B. PAGE 14 / 94 .Documentation sur L’ABAP List Viewer VERSION 3. ENDIF. CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(510).IV. IF sy-subrc ne 0. Endif. * Nom du Container de référence = 'BCALVC_TOOLBAR_D100_C1' cont_on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C1' . Dans notre exemple “BCALVC_TOOLBAR_D100_C1” correspond au nom de l’objet ‘custom controle’ dans l’écran de sélection.IV Le container Le container est l’objet qui doit contenir le composant ALV. y. see the F1 help on the FORMAT statement.2.1 B. * Titre gs_layout-grid_title = 'Listes des factures'(100).2.z: '0'=off '1'=on) If the field is set to 'X'. * Ajuste la taille des colonnes gs_layout-cwidth_opt = 'X'.B GESTION DE LA COULEUR POUR LES LIGNES.V. the remaining numbers have the following meaning: • • • x: color number y: intensified display on/off y: inverse display on/off For more information on color coding. DATA: linecolor(4) type c. the ALV uses a pre-defined color for highlighting the column. Désignation Défini le titre Sélection de multi-ligne Ajuste la taille des colonnes selon le contenu. PAGE 15 / 94 . 1 Il faut ajouter un champ caractère de taille 4 à la table contenant les données.Documentation sur L’ABAP List Viewer VERSION 3.2 Gestion des couleurs B. If the character field begins with 'C' (color code). Permet de ne pas afficher la barre des boutons B.V. Cette structure est de type : LVC_S_LAYO.A GESTION DE COLONNE EN COULEUR Dans le catalogue EMPHASIZE LVC_EMPHSZ Char(4) SPACE. B.V Gestion du layout La structure du layout contient un ensemble de champs permettant de configurer les propriétés graphiques de la grille ALV.V.V. "Color for corresponding line DATA: END OF GT_OUTTAB. DATA: BEGIN OF GT_OUTTAB OCCURS 0. INCLUDE STRUCTURE <DDIC-Struktur>.1 Options principales Nom du champ Grid_title Sel_mode CWIDTH_OPT NO_TOOLBAR Exemple : *Déclaration Data : gs_layout TYPE lvc_s_layo. B. 'X' or 'Cxyz' (x:'1'-'9'. * allow to select multiple lines gs_layout-sel_mode = 'A'. et lui affecter la couleur à afficher. SPACE. GT_CATALOG-INFO_NAME = linecolor. B. the list shows a striped pattern in the print preview and when it is printed.1 2 Renseigner le champ INFO_NAME de la structure. INCLUDE STRUCTURE SFLIGHT. Si on veut affecter plusieurs cellule il faut mettre le nom de la colonne dans le champs FNAME. "Table for colors DATA: END OF GT_OUTTAB. 'X' PAGE 16 / 94 . il suffit de définir la couleur souhaitée dans le champ COLOR et ne pas affecter le champs FNAME. DATA: CT TYPE LVC_T_SCOL.2. Si on veut colorer la ligne.D AFFICHAGE ZÉBRÉ DES LIGNES Dans la structure layout : ZEBRA If this field is set. il faut alors ajouter plusieurs lignes dans la table. Enfin il faut assigner le nom de la table interne (pour notre exemple CT) dans le champ CTAB_FNAME de la structure layout. B.V.C GESTION DE LA COULEUR POUR DES CELLULES Ajouter une table des couleurs du type LVC_T_SCOL à la table contenant les données à afficher : DATA: BEGIN OF GT_OUTTAB OCCURS 0. Si on souhaite colorer plusieurs cellule.V. La table de type LVC_T_SCOL des couleurs contient 3 champs FNAME COLOR NOKEYCOL Contrôle ALV : nom de zone de table interne Contrôle arbre ALV : codage couleur Contrôle ALV : substituer la couleur de la clé Si le champs NOKEYCOL est égal à ‘X’ alors il est possible de changer la couleur des champs clé définit dans l’ALV (Voir le catalogue).Documentation sur L’ABAP List Viewer VERSION 3.2. I_SAVE = SPACE. ce dernier doit contenir au minimum l’ID du programme dans le champ REPORT: G_REPID = SY-REPID. they can modify the selection and the order of the columns displayed). (default setting) Changing the current display variant only The ALV grid control displays only the variant icon ( ) but no menu in the toolbar. ce dernier dispose de 3 paramètres :  I_SAVE   Mode IS_VARIANT I_DEFAULT Result Values of I_SAVE and IS_VARIANT when set_table_for_first_display is called IS_VARIANT = SPACE. ces dernières ne sont pas rappelées lors des utilisations futures. Le premier paramètre à utiliser est de type DISVARIANT.VI Gestion variantes L’ALV offre la possibilité de gérer l’utilisation de variantes définissant les colonnes affichées et autres aspects graphiques. Data :GS_VARIANT TYPE DISVARIANT. 'U' or 'A'> See also: Saving Display Variants Loading and saving display variants The ALV grid control displays both the variant icon and a menu in the toolbar. Par défaut l’utilisateur peut saisir des variantes. il suffit de définir la valeur ‘SPACE’ pour I_DEFAULT . By clicking this icon. users can change the current display variant (basically.Documentation sur L’ABAP List Viewer VERSION 3. si l’utilisateur ne doit pas avoir accès à l’utilisation de variantes. Les possibilités offertes pour la gestion des variantes sont importantes et sont définis par l’intermédiaire de paramètres. The menu contains only functions for selecting and changing display variants. The ALV grid control displays both the variant icon and a menu in the toolbar.1 B. Pour ce faire. saving and managing display variants. (or IS_VARIANT is SPACE and I_SAVE is not SPACE ) IS_VARIANT = <variant structure> I_SAVE = <'X'. GS_VARIANT-REPORT = G_REPID. changing. Loading delivered display variants only IS_VARIANT = <variant structure> I_SAVE = SPACE . Cependant il incombe au développeur de gérer les propriétés que peuvent prendre les variantes. The menu provides functions for selecting. Par contre. By clicking this icon. PAGE 17 / 94 . users can select an existing display variant. X_SAVE = SPACE X_SAVE = 'U' X_SAVE = 'X' X_SAVE = 'A' Example: * Déclaration Data : gs_variant TYPE disvariant.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid.Documentation sur L’ABAP List Viewer Un second paramètre permet de déterminer les options de sauvegarde : DATA : X_SAVE type c. Only global variants can be saved. il est utile de définir le champ HANDLE STRUCTURE DISVARIANT REPORT HANDLE LOG_GROUP USERNAME VARIANT TEXT DEPENDVARS Nom du programme ABAP ID de gestion pour appel répété depuis le même programme Clé de groupe logique Nom utilisateur pour mémorisation personnalisée Variante d'affichage Désignation variante affichage Vecteur entrées de var.1 * 'gs_variant' must at least contain the report-id to allow * saving a variant. NOTA : Afin de gérer les variantes selon les dynpros. Variants cannot be saved. dépendantes PAGE 18 / 94 . x_save value 'A'. Only user-defined variants can be saved. * § 2. g_repid like sy-repid. clear gs_variant. Both user-defined and global variants can be saved. VERSION 3. g_repid = sy-repid. Documentation sur L’ABAP List Viewer VERSION 3.VII.1 Définition : La première étape consiste à créer une classe permettant de définir ses propres fonctions (METHOD) : NOTA : Si la classe n’est pas définit au tout début du programme. public section. methods: handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive . private section. Pour palier à ce problème on inclut la ligne de code suivante : * Predefine a local class for event handling to allow the * declaration of a reference variable before the class is defined. l’utilisation de L’ALV offre aussi la possibilité de gérer un ensemble d’évènements. toute référence à la classe ne pourra être faites qu’après.1 B. Exemple de définition : **************************************************************** * LOCAL CLASSES: Definition **************************************************************** *====================================================== ========= * class lcl_event_receiver: local class to * define and handle own functions. B.VII Les évènements Outres la simplification de la gestion de l’affichage. handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm. * * Definition: * ~~~~~~~~~~~ class lcl_event_receiver definition. handle_double_click for event double_click of cl_gui_alv_grid importing e_row e_column. * * lcl_event_receiver (Definition) *====================================================== ========= La définition d’une fonction rattachée à un événement est très simple :    handle_toolbar double_click e_row e_column -> nom de la fonction -> Nom de l’évènement (voir annexe) -> Paramètres récupérés (voir définition de l’évènement) PAGE 19 / 94 . data : poste type c value 'P'. endclass. CLASS lcl_event_receiver DEFINITION DEFERRED. ... * § 2... endmethod. method handle_toolbar.. *------------------------------------------------------------------method handle_double_click.... Use row parameter to select a line of the * corresponding internal table... if this event is raised due to * the call of 'set_toolbar_interactive' by the user. * E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET. il convient alors de procéder à leur implémentation (juste en dessous de la définition) : **************************************************************** * LOCAL CLASSES: Implementation **************************************************************** *====================================================== ========= * class lcl_event_receiver (Implementation) * * class lcl_event_receiver implementation. One line of this table is * defined by the Structure STB_BUTTON (see data deklaration above).. ls_entete like line of t_entete. move ' Voir les postes'(111) to ls_toolbar-quickinfo. append ls_toolbar to e_object->mt_toolbar.Documentation sur L’ABAP List Viewer VERSION 3.... in method 'refresh_table_display').. * § 4.1 B......g.... * An application of this feature is still unknown.... * append an icon to show post table clear ls_toolbar. p_vbeln like vbrp-vbeln. data: ls_poste like line of t_poste...... * * A remark to the flag E_INTERACTIVE: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 'e_interactive' is set... move 'POSTES' to ls_toolbar-function.. move ' ' to ls_toolbar-disabled. * You can distinguish this way if the event was raised * by yourself or by ALV * (e. else.. if poste eq 'P'.. p_vbeln = ls_poste-vbeln. PAGE 20 / 94 . which * is a table of type TTB_BUTTON... * read selected row from internal table gt_sflight read table t_poste index e_row-index into ls_poste..... move 3 to ls_toolbar-butn_type........ *. namly MT_TOOLBAR. move ' Vue poste'(112) to ls_toolbar-text. * MOVE icon_employee TO ls_toolbar-icon. :-) * append a separator to normal toolbar clear ls_toolbar.. * This class has got one attribute..In event handler method for event TOOLBAR: Append own functions * by using event parameter E_OBJECT.... data: ls_toolbar type stb_button......... append ls_toolbar to e_object->mt_toolbar...VII...The event DOUBLE_CLICK provides parameters for row and column * of the click... move icon_detail to ls_toolbar-icon.2 Implémentation : Une fois les fonctions définis. 3 Utilisation : Enfin.In event handler method for event USER_COMMAND: Query your * function codes defined in step 2 and react accordingly. "handle_user_command *----------------------------------------------------------------endclass. Création de l’instance create object event_receiver. * * lcl_event_receiver (Implementation) *====================================================== ============= B.1 *------------------------------------------------------------------method handle_user_command. when 'FACTURE'. "handle_double_click VERSION 3. call method cl_gui_cfw=>flush. * § 3. if sy-subrc ne 0. case e_ucomm. leave to screen 0. endif.VII. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). * Connection des Méthodes aux évènements. * add your handling. p_vbeln = ls_entete-vbeln. * On appel la transaction VF03 pour afficher la Facture. data: lt_rows type lvc_t_row. set parameter id 'VF' field p_vbeln. lorsque la classe définissant les évènements est définie et implémentée. When the ALV Control raises the event for the specified instance the corresponding method is automatically called. endif. alors il faut créer une instance de l’objet et connecter nos propres au composant ALV. call transaction 'VF03' and skip first screen.Documentation sur L’ABAP List Viewer * read selected row from internal table gt_sflight read table t_entete index e_row-index into ls_entete. Data : event_receiver type ref to lcl_event_receiver. endmethod. call method grid1->get_selected_rows importing et_index_rows = lt_rows. endmethod. * * * * * ->Create Object to receive events and link them to handler methods. when 'POSTES'. endcase. PAGE 21 / 94 . else. perform show_poste_table tables lt_rows. call method grid2->set_toolbar_interactive.Call method 'set_toolbar_interactive' to raise event TOOLBAR. set handler event_receiver->handle_toolbar for grid1. VERSION 3. set handler event_receiver->handle_double_click for grid1.1 La fonction se définit comme suit : Set handler “nom de l’objet » -> « nom de la fonction » for « objet ALV » PAGE 22 / 94 . * § 4.Documentation sur L’ABAP List Viewer set handler event_receiver->handle_user_command for grid1. Documentation sur L’ABAP List Viewer VERSION 3.VIII La grille ou composant ALV Le composant ALV est celui qui permet l’affichage de la grille.VIII. set_table_for_first_display. c’est ce dernier qui utilisera l’ensemble des objets précédemment définis. il suffit alors d’appeler la fonction PAGE 23 / 94 . La fonction « Create objet » prend pour argument  Le nom de l’objet (le composant ALV précédemment déclaré)  Et le nom du container devant réceptionner la grille * create an instance of alv control ******************************************* * Composant alv  grid1 * Nom du container  custom_container1 ******************************************* create object grid1 exporting i_parent = custom_container1. B. Nous ne présenterons pas par la suite l’ensemble des fonctions et propriétés disponibles (voir annexe).2 Création de l’objet : L’étape suivante consiste à créer une instance de l’objet grid1.1 Définition : Le composant ALV est de type cl_gui_alv_grid. Une fois l’objet crée. et se déclare ainsi : Data grid1 type ref to cl_gui_alv_grid. B. B.3 La fonction set_table_for_first_display.VIII.VIII.1 B. * add your handling.Documentation sur L’ABAP List Viewer Cette dernière utilise plusieurs paramètres: VERSION 3. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be ATTACHED'(510). of type CHAR01> var.1 CALL METHOD grid1->set_table_for_first_display EXPORTING I_STRUCTURE_NAME IS_VARIANT I_SAVE I_DEFAULT IS_LAYOUT IS_PRINT IT_SPECIAL_GROUPS IT_TOOLBAR_EXCLUDING CHANGING IT_OUTTAB IT_FIELDCATALOG IT_SORT IT_FILTER Exemple : *** DEFINITION de la grille ALV appelée. of type CHAR01> structure of type LVC_S_LAYO> structure of type LVC_S_PRNT> internal table of type LVC_T_SGRP> internal table of type UI_FUNCTIONS> internal table> internal table of type LVC_T_FCAT> internal table of type LVC_T_SORT> internal table of type LVC_T_FILT> PAGE 24 / 94 . call method grid1->set_table_for_first_display exporting is_layout = gs_layout is_variant = gs_variant "&see below i_save = x_save "&see below changing it_outtab = t_entete[] it_fieldcatalog = gt_field_cat_entete[] . if sy-subrc ne 0. endif. = = = = = = = = = = = = < < < < < < < < < < < < string of type DD02L-TABNAME> structure of type DISVARIANT> var. Documentation sur L’ABAP List Viewer EXPORTING VERSION 3. LAYOUT IMPRESSION CHANGING IS_LAYOUT IS_PRINT IT_OUTTAB IT_FIELDCATALOG IT_SORT TABLE DONNEES CATALOGUE TRI FILTRE IT_FILTER IS_PRINT reçoit une structure de type LVC_S_PRN Champs PRINT Type CHAR Désignation Contrôle ALV : édition par impression Contrôle ALV : nbre de lignes réservées pour END_OF_PAGE Ctrl ALV : format changement grpe définissable par utilis.1 Type CATALOGUE Nom du paramètre I_STRUCTURE_NAME IS_VARIANT I_SAVE VARIANTE I_DEFAULT IT_SPECIAL_GROUPS Désignation Nom de la structure du catalogue si elle appartient au dictionnaire ex : SFLIGHT Nom de la variante Autres paramètres propre à la gestion des variantes Autes paramètres propre à la gestion des variantes Permet de définir des groupes de colonnes (voir annexe) Nom du layout Structure définissant les paramètres d’impression de l’ALV. Nom de la table interne Nom du catalogue si spécifique Table interne contenant les informations de tri Table interne contenant les informations de filtres. Contrôle ALV : ne pas activer les informations de liste Contrôle ALV : ne pas activer informations de sélection RESERVELNS INT4 GRPCHGEDIT CHAR PRNTLSTINF CHAR PRNTSELINF CHAR PAGE 25 / 94 . 1 LVC_T_SORT. lt_sort_alv-spos = 1. append lt_sort_alv.Documentation sur L’ABAP List Viewer IT_SORT Table interne de type internal table of type Déclaration : data: lt_sort_alv type lvc_t_sort with header line. VERSION 3. lt_sort_alv-fieldname = 'SESSNO'. lt_sort_alv-up = 'X'. CLEAR lt_sort_alv. Champs SPOS FIELDNAME UP DOWN GROUP SUBTOT COMP EXPA SELTEXT Type NUMC 2 Désignation Séquence de tri CHAR 30 Contrôle ALV : nom de zone de table interne CHAR 1 CHAR 1 CHAR 2 CHAR 1 CHAR 1 CHAR 1 Code à 1 caractère Code à 1 caractère Chgmt gpe : insérer chgmt page et traits soulignement Editer total intermédiaire Code à 1 caractère Code à 1 caractère CHAR 40 Critère de tri Code à 1 caractère OBLIGATORY CHAR 1 LEVEL NO_OUT INT4 10 Nombre naturel CHAR 1 Code à 1 caractère PAGE 26 / 94 . Documentation sur L’ABAP List Viewer IT_FILTER Table interne de type VERSION 3.1 LVC_T_FILT Champs FIELDNAME TABNAME REF_FIELD REF_TABLE C_FIELD C_TAB C_VALUE FLG_CQ SELTEXT VALUF VALUT LOW HIGH SIGN OPTION SIGN_ICON STYPE DD_OUTLEN DECIMAL Type CHAR 30 CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR NUMC NUMC Désignation Cntrl ALV : nom table de référence pour zone table interne 30 Cntrl ALV : nom table de référence pour zone table interne 30 Ctrl ALV : nom zone de référence pour zone table interne 30 Cntrl ALV : nom table de référence pour zone table interne 30 Contrôle ALV : nom de zone de table interne 30 Nom de table LVC 5 1 Table R/2 Code à 1 caractère 40 Contrôle ALV : identificateur de colonne pour fct. Code à 1 caractère Contrôle ALV : longueur d'édition en nbre de caractères Nombre de décimales PAGE 27 / 94 . dialogue 80 Texte de longueur 80 80 Texte de longueur 80 80 Texte de longueur 80 80 Texte de longueur 80 1 2 4 1 6 6 Code à 1 caractère Composante du n° de version Domaine défini imprécisément. ) Type de données dans dictionnaire ABAP Code à 1 caractère Contrôle ALV : occulter les signes +/. Cette fonction permet de réinitialiser l’objet ALV.D.lors édition Code à 1 caractère Séquence *** DEFINITION de la grille ALV appelée.1 60 Contrôle ALV : EditMask pour édition 1 1 4 1 1 1 2 Minuscules autorisées/non autorisées Type données ABAP (C..VIII.Documentation sur L’ABAP List Viewer INTLEN CONVEXIT EDIT_MASK LOWERCASE INTTYPE DATATYPE EXCEPTION NO_SIGN OR ORDER NUMC CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR NUMC 6 5 Longueur interne en octets Routine de conversion VERSION 3.5 La fonction set_focus Cette méthode permet de sélectionner l’objet actif dans l’écran. endif. call method grid1->set_table_for_first_display exporting is_layout = gs_layout is_variant = gs_variant "&see below i_save = x_save "&see below changing it_outtab = t_entete[] it_fieldcatalog = gt_field_cat_entete[] .N.4 La fonction refresh_table_display call method grid1->refresh_table_display. B.. PAGE 28 / 94 .VIII. * add your handling. B.. if sy-subrc ne 0. dans l’exemple qui suit on choisit grid1. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be ATTACHED'(510). VIII. * Definition des catalogues utilisés. . GT_FIELD_CAT_ENTETE type LVC_T_FCAT with header line. GT_field_cat_entete-REF_TABLE = 'VBRK'. gs_variant TYPE disvariant. endif. . * Fin de la definition du catalogue. event_receiver TYPE REF TO lcl_event_receiver. TYPE-POOLS: SLIS. IF custom_container1 is initial. g_repid LIKE sy-repid. B.. * Nom du contenair principal cont_on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C1' * Utilisation de Variantes.1 call method cl_gui_control=>set_focus exporting control = grid1.. GT_field_cat_entete-KEY = 'X'. clear GT_field_cat_entete. GT_field_cat_entete-ref_field = 'KUNAG'.. * Définition du catalogue ***************************************************************** DATA: POS TYPE I VALUE 1. append GT_field_cat_entete. GT_field_cat_entete-COL_POS = POS. . GT_field_cat_entete-FIELDNAME = 'KUNAG'. * add your handling.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid. g_repid = sy-repid. PAGE 29 / 94 . gs_layout TYPE lvc_s_layo. if sy-subrc ne 0. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be in focus'(510)..6 Exemple : INCLUDE <icon>. grid1 TYPE REF TO cl_gui_alv_grid. DATA: ok_code LIKE sy-ucomm. custom_container1 TYPE REF TO cl_gui_custom_container..Documentation sur L’ABAP List Viewer VERSION 3. GT_field_cat_entete-tabname = 't_entete'. "for parameter IS_VARIANT x_save value 'A'.. * § 2. * 'gs_variant' must at least contain the report-id to allow * saving a variant. ***************************************************************** CLEAR gs_variant. * add your handling. ENDIF. IF sy-subrc ne 0. for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be ATTACHED'(510). IF sy-subrc ne 0. ENDIF.Documentation sur L’ABAP List Viewer * create a custom container control for our ALV Control CREATE OBJECT custom_container1 EXPORTING container_name = cont_on_main EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be in focus'(510). ENDIF. * create an instance of alv control CREATE OBJECT grid1 EXPORTING i_parent = custom_container1. for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(510). "IF grid1 IS INITIAL VERSION 3. ENDIF. CALL METHOD grid1->set_table_for_first_display EXPORTING is_layout = gs_layout is_variant = gs_variant "&see below i_save = x_save "&see below CHANGING it_outtab = t_entete[] IT_FIELDCATALOG = GT_FIELD_CAT_ENTETE[] . CALL METHOD grid1->set_toolbar_interactive.1 CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid1. gs_layout-CWIDTH_OPT = 'X'. * allow to select multiple lines gs_layout-sel_mode = 'A'. * § 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR. * add your handling. *** DEFINITION de la grille ALV appelée. * add your handling. * * Set a titlebar for the grid control * gs_layout-grid_title = 'Listes des factures'(100). PAGE 30 / 94 . IF sy-subrc ne 0. . La création et l’affichage des objets ALV sont alors gérés au sein des PBO et PAI. il est préférable d’utiliser plusieurs écran.1 B. générer à partir du screen painter et de créer dans chacun un CUSTOM CONTROLE. lesquelles permettent de gérer plusieurs composants ALV. " PBO_100 OUTPUT VERSION 3.IX Gestion avec plusieurs ALV. Afin de pouvoir gérer des ALV avec différents niveaux. PAGE 31 / 94 .Documentation sur L’ABAP List Viewer ENDMODULE. (Voir exemple fournit à la fin) Il est aussi possible de d’utiliser d’autres containers. B. variante.X REALISATION PRATIQUE : Exemple Voici un schéma global fournit par SAP reprenant l’ensemble des étapes et composants : NOTA : Nous invitons le lecteur à consulter les programmes de la classe de développement SLIS. B.1 B. (affichage.1 MISE EN ŒUVRE  Création de l’écran et insertion de l’objet.X.Documentation sur L’ABAP List Viewer VERSION 3. classe d’objet. NOTA : l’instanciation correspond à la création de l’objet.2 EXEMPLES Exemple de programme simple avec un seul ALV : program bcalvc_variants_exe. paramétrages…)  Instanciation et rattachement de la classe évènements. layout. container. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&& * Purpose: * ~~~~~~~~ PAGE 32 / 94 .  Création du catalogue  Définition du layout  Définition des paramètres propres aux variantes.  Définition de la grille.  Instanciation du container..X. à l’aide par exemple de la fonction « CREATE OBJET ». (création)  Instanciation de la grille(création).  Définition et implémentation des classes locales : évènements et autres.  Déclaration des différents éléments dans le programme : catalogue. p_def_v radiobutton group exec......... * When provided as parameter for 'set_grid_for_first_display'.. "for parameter I_SAVE: modus for saving variants default.. gt_sflight type table of sflight..... "finally chosen variant *DATA: got_default..... g_repid like sy-repid... selection-screen end of block vari........ "specific variant gs_variant type disvariant. g_exit type c....... *. p_spec_v radiobutton group exec..LVC_VARIANT_SELECT (not used in this example!) * -> select a variant by name *----------------------------------------------------------------* To check program behavior * ~~~~~~~~~~~~~~~~~~~~~~~~~ * Create your own variants using the variant menu of ALV Control.. "default variant spec_variant type disvariant.... * Chose one as a default variant and return to the selection screen. g_repid = sy-repid. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&& data: ok_code like sy-ucomm......... "has to be set if the chosen variant is a default variant x_variant type disvariant. data: def_variant type disvariant....LVC_VARIANT_EXISTENCE_CHECK * -> Test if a variant exist. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ initialization... * reference to custom container: neccessary to bind ALV Control custom_container type ref to cl_gui_custom_container.... "marks that the default variant has been loaded *.LVC_VARIANT_F4 * -> F4 help pops up to select a variant * . * it must contain at least the report-id. * data: x_save.......... x_save = 'A'... "The user may save all types of variants PAGE 33 / 94 . mycontainer type scrfname value 'BCALV_VARIANTS_0100_C1'..... ****************************************************** * Define a selection screen * to choose an already saved variant ****************************************************** selection-screen begin of block vari with frame title text-002. * 'gs_variant' finally holds the chosen variant.. grid1 type ref to cl_gui_alv_grid..... parameters: p_no_v radiobutton group exec default 'X'.. Useful at event AT SELECTION-SCREEN * ... p_vari like disvariant-variant..... "is set if the user has aborted a variant popup * The variables 'def_variant' and 'spec_variant' are set during * interactions on the selection screen.....1 * This example illustrates how a variant can be chosen before * the generation of the list.....LVC_VARIANT_DEFAULT_GET * -> Get the default variant * .Documentation sur L’ABAP List Viewer VERSION 3.......... * * Relevant function modules are: * ............. * 'x_save' contains a flag to control which kind of variants the user * can save (in this example it is set to 'A' for all variant types). * * Variables of type DISVARIANT identify a variant..... move g_repid to def_variant-report. p_spec_v = ' '. * popup F4 help to select a variant clear x_variant.Documentation sur L’ABAP List Viewer VERSION 3. call function 'LVC_VARIANT_F4' exporting is_variant = x_variant i_save = x_save importing e_exit = g_exit es_variant = spec_variant exceptions not_found =1 others = 2. PAGE 34 / 94 . message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. if sy-subrc = 2. exit. * set name of variant on selection screen p_vari = spec_variant-variant. clear def_variant. move g_repid to x_variant-report. * If a default variant exist. p_no_v = 'X'. endif. * set name of variant on selection screen p_vari = def_variant-variant. if sy-subrc ne 0. * if default = ' '. else. * The default variant is fetched the first time the PBO of the * selection screen is called. else. call function 'LVC_VARIANT_DEFAULT_GET' exporting i_save = x_save changing cs_variant = def_variant exceptions not_found = 2. endif. move g_repid to spec_variant-report.1 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ at selection-screen output. if g_exit ne 'X'. endif. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ at selection-screen. endif. clear spec_variant. "default IS INITIAL *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ at selection-screen on value-request for p_vari. move p_vari to spec_variant-variant. its identification * is saved in 'def_variant'. default = 'X'. perform deactivate_def_v. * test if specified variant exist if p_spec_v = 'X'. p_def_v = ' '. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. * execute with default variant elseif p_def_v = 'X'. else. call screen 100. select * from sflight into table gt_sflight. * execute with specified variant elseif p_spec_v = 'X'. if sy-subrc <> 0. gs_variant-report = g_repid.1 call function 'LVC_VARIANT_EXISTENCE_CHECK' exporting i_save = x_save changing cs_variant = spec_variant exceptions wrong_input = 1 not_found =2 program_error = 3 others = 4. * set gs_variant according to the selection made clear gs_variant. leave program.Documentation sur L’ABAP List Viewer VERSION 3. endif. if custom_container is initial. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ start-of-selection. call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = space txt1 = 'Fatal error: No radio button active!'(550). endif. * execute without variant if p_no_v = 'X'. move-corresponding spec_variant to gs_variant. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ end-of-selection. *---------------------------------------------------------------------* * MODULE PBO OUTPUT * *---------------------------------------------------------------------* module pbo output. * create a custom container control for our ALV Control create object custom_container exporting container_name = mycontainer exceptions cntl_error = 1 cntl_system_error = 2 PAGE 35 / 94 . set pf-status 'MAIN100'. move-corresponding def_variant to gs_variant. Documentation sur L’ABAP List Viewer create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. la majeure partie du code non relatif à l’implémentation de l’ALV a été supprimée. *&---------------------------------------------------------------------* *& Form DEACTIVATE_DEF_V *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. clear ok_code. endform. call method grid1->set_table_for_first_display exporting i_structure_name = 'SFLIGHT' * gs_variant-report must not be initial! is_variant = gs_variant i_save = x_save changing it_outtab = gt_sflight. endmodule. case ok_code.p2 text *----------------------------------------------------------------------* form deactivate_def_v. when 'EXIT'. * deactivate radio button for default variant loop at screen. screen-input = 0. leave to screen 0. endcase. endloop. if sy-subrc ne 0. endform. endif. modify screen. endmodule. PAGE 36 / 94 . * add your handling. endif. endif. *---------------------------------------------------------------------* * FORM EXIT_PROGRAM *---------------------------------------------------------------------* form exit_program. *---------------------------------------------------------------------* * MODULE PAI INPUT * *---------------------------------------------------------------------* module pai input. if screen-name = 'P_DEF_V'. create object grid1 exporting i_parent = custom_container.1 * Exemple de programme avec deux ALV : LE programme qui suit est présenté juste comme illustration. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(510). " DEACTIVATE_DEF_V VERSION 3. call method custom_container->free. perform exit_program. kunag like vbrk-kunag. type-pools: slis. . . fkdat like vbrk-fkdat. name1 like kna1-name1. : kna1. gs_layout type lvc_s_layo. include structure st_entete. PAGE 37 / 94 . *----------------------------------------------------------------------* * TABLES INTERNES * *----------------------------------------------------------------------* ** Tables contenants tous les entetes (vbrk) types : begin of ty_entete . * Definition de structure data : st_entete type ty_entete . fkart like vbrk-fkart. end of ty_entete. konda like vbrk-konda. vkorg like vbrk-vkorg. data : end of t_entete. ************** ** ENTETE data : begin of t_entete occurs 0. * ********* data: ok_code like sy-ucomm. zztext(20) type c. netwr like vbrk-netwr.Documentation sur L’ABAP List Viewer VERSION 3. *************** ********ALV * Predefine a local class for event handling to allow the * declaration of a reference variable before the class is defined. vbeln like vbrk-vbeln. zztext5(30) type c. spart like vbrk-spart. buchk like vbuk-buchk. class lcl_event_receiver definition deferred. g_repid like sy-repid. st_poste type ty_poste . ***ALV*** include <icon>. zzhiez(10) type c . *----------------------------------------------------------------------* * TABLES * *----------------------------------------------------------------------* tables " Base clients (partie générale) .1 report zrsd0007 message-id zs no standard page heading line-size 132 line-count 65. vtweg like vbrk-vtweg. methods: handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive .Documentation sur L’ABAP List Viewer * Nom du contenair principal cont_on_main type scrfname value 'BCALVC_TOOLBAR_D100_C1' *'ZZ_controle_100' . gt_field_cat_entete type lvc_t_fcat with header line.1 **************************************************************** * LOCAL CLASSES: Definition **************************************************************** *====================================================== ========= * class lcl_event_receiver: local class to * define and handle own functions. handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm. gs_variant type disvariant. custom_container2 type ref to cl_gui_custom_container. grid1 type ref to cl_gui_alv_grid. endclass. * * lcl_event_receiver (Definition) *====================================================== ========= **************************************************************** * LOCAL CLASSES: Implementation **************************************************************** *====================================================== ========= * class lcl_event_receiver (Implementation) * PAGE 38 / 94 . custom_container1 type ref to cl_gui_custom_container. handle_double_click for event double_click of cl_gui_alv_grid importing e_row e_column. * Utilisation de Variantes. event_receiver type ref to lcl_event_receiver. gt_field_cat_poste type lvc_t_fcat with header line. * Definition des catalogues utilisés. event_receiver2 type ref to lcl_event_receiver. "for parameter IS_VARIANT x_save value 'A'. public section. * * Definition: * ~~~~~~~~~~~ class lcl_event_receiver definition. private section. grid2 type ref to cl_gui_alv_grid. VERSION 3. * Nom du contenair secondaire cont_on_dialog type scrfname value 'BCALVC_TOOLBAR_D101_C1'. . data: ls_poste like line of t_poste... * An application of this feature is still unknown.... which * is a table of type TTB_BUTTON. *... * append an icon to show post table clear ls_toolbar... in method 'refresh_table_display'). PAGE 39 / 94 .. move ' Vue poste'(112) to ls_toolbar-text.. * MOVE icon_employee TO ls_toolbar-icon. Use row parameter to select a line of the corresponding internal table....g. * * * * § 4...... append ls_toolbar to e_object->mt_toolbar. p_vbeln = ls_entete-vbeln. data: ls_toolbar type stb_button..... namly MT_TOOLBAR..... * § 3....1 *------------------------------------------------------------------method handle_user_command. read selected row from internal table t_entete read table t_entete index e_row-index into ls_entete.In event handler method for event USER_COMMAND: Query your * function codes defined in step 2 and react accordingly. * * A remark to the flag E_INTERACTIVE: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 'e_interactive' is set..In event handler method for event TOOLBAR: Append own functions * by using event parameter E_OBJECT. *------------------------------------------------------------------method handle_double_click. "handle_double_click VERSION 3.. move 3 to ls_toolbar-butn_type... endmethod..Documentation sur L’ABAP List Viewer * class lcl_event_receiver implementation...... :-) * append a separator to normal toolbar clear ls_toolbar.... move 'POSTES' to ls_toolbar-function.... method handle_toolbar........ One line of this table is * defined by the Structure STB_BUTTON (see data deklaration above). move ' Voir les postes'(111) to ls_toolbar-quickinfo... move ' ' to ls_toolbar-disabled. call transaction 'VF03' and skip first screen.. ls_entete like line of t_entete.. * This class has got one attribute.... move icon_detail to ls_toolbar-icon. append ls_toolbar to e_object->mt_toolbar.. endmethod. * E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET..... set parameter id 'VF' field p_vbeln. * On appel la transaction VF03 pour afficher la Facture.The event DOUBLE_CLICK provides parameters for row and column of the click. data: lt_rows type lvc_t_row.. * You can distinguish this way if the event was raised * by yourself or by ALV * (e.. * § 2. p_vbeln like vbrp-vbeln. if this event is raised due to * the call of 'set_toolbar_interactive' by the user.. if sy-subrc ne 0. call method grid1->get_selected_rows importing et_index_rows = lt_rows. * add your handling. end-of-selection. ********************************************************* * f_facture *  t_entete ******************************************************** * * * PAGE 40 / 94 . for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). perform show_poste_table tables lt_rows. * * lcl_event_receiver (Implementation) *====================================================== ============= *----------------------------------------------------------------------* * ECRAN DE SELECTION *----------------------------------------------------------------------* *----------------------------------------------------------------------* * INITIALIZATION * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * AT SELECTION-SCREEN *----------------------------------------------------------------------* *----------------------------------------------------------------------* * START OF SELECTION *----------------------------------------------------------------------* start-of-selection. endmethod.Documentation sur L’ABAP List Viewer VERSION 3. when 'FACTURE'. when 'POSTES'. call screen '100'. else. endcase. leave to screen 0. endif. *---------------------------------------------------------------------* * CREATION ALV * *---------------------------------------------------------------------* perform init_catalogue. call method cl_gui_cfw=>flush. "handle_user_command *----------------------------------------------------------------endclass. ** Controle sur les sélections faites ** Recupération des données perform f_facture.1 case e_ucomm. if sy-subrc ne 0. endif. set pf-status 'MAIN100'. leave program. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). * call method custom_container1->free. * 'gs_variant' must at least contain the report-id to allow * saving a variant.Documentation sur L’ABAP List Viewer form f_facture . * no matter how many times the second window is called). endform. *&---------------------------------------------------------------------* *& Module PBO_100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module pbo_100 output. endform. if custom_container1 is initial. * (It is created only once during the first selection of SBOOK. call method cl_gui_cfw=>flush. gs_variant-handle = '0100'. endform. * The instance grid2 is freed not until the program exits from the * main screen. *********************************************************************** *---------------------------------------------------------------------* * FORM EXIT_PROGRAM * *---------------------------------------------------------------------* form exit_program. if not custom_container2 is initial.1 PAGE 41 / 94 . **&--------------------------------------------------------------------* **& Form select_table_poste **&--------------------------------------------------------------------* ** text **---------------------------------------------------------------------* ** -->P_LS_entete text **---------------------------------------------------------------------* form select_table_poste using p_ls_entete like line of t_entete . endif. * create a custom container control for our ALV Control create object custom_container1 exporting VERSION 3.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid. call method custom_container2->free. * § 2. clear gs_variant. g_repid = sy-repid. * add your handling. endif. * create an instance of alv control create object grid1 exporting i_parent = custom_container1. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be ATTACHED'(510). set handler event_receiver->handle_toolbar for grid1.1 PAGE 42 / 94 . * add your handling. * ******** * § 4.Documentation sur L’ABAP List Viewer container_name = cont_on_main exceptions cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. call method grid1->set_toolbar_interactive. VERSION 3. gs_layout-cwidth_opt = 'X'. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(510).Call method 'set_toolbar_interactive' to raise event TOOLBAR. endif. set handler event_receiver->handle_user_command for grid1. * allow to select multiple lines gs_layout-sel_mode = 'A'. if sy-subrc ne 0. *********************************************************************** ******** * ->Create Object to receive events and link them to handler methods. call method grid1->set_table_for_first_display exporting is_layout = gs_layout is_variant = gs_variant "&see below i_save = x_save "&see below changing it_outtab = t_entete[] it_fieldcatalog = gt_field_cat_entete[] . * * Set a titlebar for the grid control * gs_layout-grid_title = 'Listes des factures'(100). * When the ALV Control raises the event for the specified instance * the corresponding method is automatically called. * add your handling. if sy-subrc ne 0. * create object event_receiver. set handler event_receiver->handle_double_click for grid1. *** DEFINITION de la grille ALV appelée. * add your handling.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid. gs_variant-handle = '0101'. endcase. if sy-subrc ne 0. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be in focus'(510). " PBO_100 OUTPUT *&---------------------------------------------------------------------* *& Module PAI_100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module pai_100 input. * (the data from sbook is already selected) * create a custom container control for our ALV Control create object custom_container2 exporting container_name = cont_on_dialog exceptions cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. endif.Documentation sur L’ABAP List Viewer endif. when 'EXIT'. case ok_code.1 " PAI_100 INPUT *&---------------------------------------------------------------------* *& Module PBO_0101 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module pbo_0101 output. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(510). * add your handling. endmodule. g_repid = sy-repid. VERSION 3. * 'gs_variant' must at least contain the report-id to allow * saving a variant. perform exit_program. endif. endmodule. if sy-subrc ne 0. "IF grid1 IS INITIAL call method cl_gui_control=>set_focus exporting control = grid1. if custom_container2 is initial. clear ok_code. * § 2. * create an instance of alv control create object grid2 PAGE 43 / 94 . set pf-status 'MAIN101'. for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be in focus'(510). set handler event_receiver2->handle_user_command for grid2. endmodule. endif. call method grid2->set_table_for_first_display exporting is_layout = gs_layout is_variant = gs_variant "&see below i_save = x_save "&see below changing it_outtab = t_poste[] it_fieldcatalog = gt_field_cat_poste[].1 *&---------------------------------------------------------------------* *& Module PAI_0101 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module pai_0101 input. set handler event_receiver2->handle_double_click for grid2. * Cas des autres appels else. ************DEFINITION**** ******** * ->Create Object to receive events and link them to handler methods.Call method 'set_toolbar_interactive' to raise event TOOLBAR. * * change title * gs_layout-grid_title = 'Liste des postes'(101). * On reaffiche. gs_layout-cwidth_opt = 'X'. PAGE 44 / 94 . endif. call method grid2->refresh_table_display. call method grid2->set_toolbar_interactive. *On efface.Documentation sur L’ABAP List Viewer exporting i_parent = custom_container2. * add your handling. call method grid2->set_table_for_first_display exporting is_layout = gs_layout changing it_outtab = t_poste[] it_fieldcatalog = gt_field_cat_poste[]. ********* * § 4. * When the ALV Control raises the event for the specified instance * the corresponding method is automatically called. gs_layout-sel_mode = ' '. "IF custom_container2 IS INITIAL. * create object event_receiver2. if sy-subrc ne 0. *********************************************************************** call method cl_gui_control=>set_focus exporting control = grid2. " PBO_0101 OUTPUT VERSION 3. * call dialog screen and display new alv control data : n type i. PAGE 45 / 94 . * read selected row from internal table gt_sflight read table t_entete index lf_row_index into ls_entete.. loop at p_et_index_rows into ls_selected_line.Documentation sur L’ABAP List Viewer case ok_code. endloop. call screen 101 . if n ne 0.. * DATA: LS_FIELDCAT type LVC_S_FCAT. lf_row_index type lvc_index.. describe table t_poste lines n. endform.. clear ok_code. data: ls_selected_line like lvc_s_row. call function 'POPUP_TO_INFORM' exporting titel = g_repid txt1 = text-201 txt2 = text-200. * Définition du catalogue pour les entetes. " PAI_0101 INPUT *&--------------------------------------------------------------------*& Form show_poste_table *&--------------------------------------------------------------------* text *---------------------------------------------------------------------* -->P_ET_INDEX_ROWS text *---------------------------------------------------------------------form show_poste_table tables p_et_index_rows structure lvc_s_row. endcase. data: pos type i value 1.. endmodule. leave to screen 0. else. when 'RETURN'. lf_row_index = ls_selected_line-index.. * select corresponding lines of table sbook * and append new lines to global table perform select_table_poste using ls_entete. ls_entete like line of t_entete.. * *---------------------------------------------------------------------* form init_catalogue. when 'FACTURE'. " show_booking_table VERSION 3. * On affiche la hiérarchie que dans le cas ou on l'utilise.1 *---------------------------------------------------------------------* * FORM init_catalogue * *---------------------------------------------------------------------* * . leave to screen 0. endif. clear t_poste[]. " STARTING AT 10 5. gt_field_cat_entete-coltext = 'Motif de non comptabilisation'. endform. clear gt_field_cat_entete. gt_field_cat_entete-col_pos = pos. gt_field_cat_entete-fieldname = 'ZZTEXT5'. gt_field_cat_entete-outputlen = '30'.Documentation sur L’ABAP List Viewer VERSION 3. PAGE 46 / 94 . gt_field_cat_entete-ref_table = 'VBRK'. gt_field_cat_entete-col_pos = pos. gt_field_cat_entete-seltext = 'Motif de non comptabilisation'. clear gt_field_cat_entete. gt_field_cat_poste-seltext = 'Quantité facturé en unité de référence'. clear gt_field_cat_poste. pos = pos + 1. gt_field_cat_poste-tabname = 't_poste'. gt_field_cat_poste-datatype = 'QUAN'. gt_field_cat_entete-ref_field = 'KUNAG'. gt_field_cat_entete-inttype = 'C'. gt_field_cat_entete-tabname = 't_entete'. gt_field_cat_poste-coltext = 'QTE en UR'. append gt_field_cat_poste. gt_field_cat_entete-key = 'X'. gt_field_cat_entete-tabname = 't_entete'.1 clear gt_field_cat_entete. append gt_field_cat_entete. gt_field_cat_poste-fieldname = 'Z_FKIMG'. pos = pos + 1. gt_field_cat_poste-col_pos = pos. append gt_field_cat_entete. gt_field_cat_entete-fieldname = 'KUNAG'. B DÉFINITION DE LA FONCTION function reuse_alv_list_display. Ces fonctions sont très pratiques mais ne couvrent pas l’étendue des possibilités offertes par une implémentations manuelles des composants ALV.I.Documentation sur L’ABAP List Viewer VERSION 3. *" IMPORTING *" VALUE(I_INTERFACE_CHECK) DEFAULT SPACE *" VALUE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE *" VALUE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME DEFAULT *" SPACE *" VALUE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME DEFAULT SPACE *" VALUE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL *" VALUE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL *" VALUE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL *" VALUE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL *" VALUE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL *" VALUE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL PAGE 47 / 94 . C.I. NOTE : D’autres fonctions existe et peuvent être trouvé au sein du groupe de fonction SLIS (Transaction SE80) C.1.I Fonction Standart SAP pour une ALV rapide Sap met à la disposition du développeur un ensemble de fonction permettant l’affichage d’un ALV de façon très rapide.1.1 Affichage d’un ALV simple C.1 C Utilisation des fonctions ALV définies pas SAP C.A APPEL DE BASE DE LA FONCTION REUSE_ALV_LIST_DISPLAY call function 'REUSE_ALV_LIST_DISPLAY' exporting i_callback_program = g_repid it_fieldcat = gt_fieldcat[] i_save = x_save is_variant = gs_variant tables t_outtab = t_charge.I. Documentation sur L’ABAP List Viewer *" VALUE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL *" VALUE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL *" VALUE(I_DEFAULT) DEFAULT 'X' *" VALUE(I_SAVE) DEFAULT SPACE *" VALUE(IS_VARIANT) LIKE DISVARIANT STRUCTURE DISVARIANT DEFAULT *" SPACE *" VALUE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL *" VALUE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL *" VALUE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL *" VALUE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL *" VALUE(I_SCREEN_START_COLUMN) DEFAULT 0 *" VALUE(I_SCREEN_START_LINE) DEFAULT 0 *" VALUE(I_SCREEN_END_COLUMN) DEFAULT 0 *" VALUE(I_SCREEN_END_LINE) DEFAULT 0 *" VALUE(I_BUFFER_ACTIVE) OPTIONAL *" EXPORTING *" VALUE(E_EXIT_CAUSED_BY_CALLER) *" VALUE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER *" TABLES *" T_OUTTAB *" EXCEPTIONS *" PROGRAM_ERROR VERSION 3.1 PAGE 48 / 94 . C.2 Clé de correpondance Afin de pouvoir afficher les informations correctement on utilise une structure permettant de mettre en relation jusqu’à 6 clés deux tables. gs_keyinfo-item02 = 'CONNID'.1 C.II.II. Data gs_keyinfo type slis_keyinfo_alv. en effet l’affichage est alors beaucoup plus malléable et permet une meilleur gestion de l’information. Afin d’afficher correctement les informations il est indispensable de comprendre la méthode de gestion entre les entêtes et les items. gs_keyinfo-header01 = 'CARRID'.II. PAGE 49 / 94 .3 Layout Le layout est la structure par laquelle on définit les propriétés graphiques de l’affichage. C.II Liste hiérarchique C. Data gs_layout type slis_layout_alv. L’exemple suivant fait le lien entre la table des entêtes définis par les compagnies aérienes (SPFLI) et la table des vols (SCARR) : * define keyinfo clear gs_keyinfo.1 Introduction : L’affichage de liste hiérarchique est une opération qui peut s’avérer utile pour certains reports. gs_keyinfo-header02 = space. gs_keyinfo-item01 = 'CARRID'.Documentation sur L’ABAP List Viewer VERSION 3. * Nom du champ dans la table des entêtes * ce champs contient soit X soit space. C. e05_ls_layout-expand_fieldname = 'EXPAND'.II.3. C. leur utilisation est elle-même très simple * définit le champ utilisé e05_ls_layout-lights_fieldname = ‘light’ * Nom de la table interne auquels est ratachée la led e05_ls_layout-lights_tabname = g_tabname_item.D AFFICHAGE DU DÉTAIL * Detailed screen e05_ls_layout-detail_popup= ‘X’.II. " Titlebar for detail PAGE 50 / 94 .3.3.3. e05_ls_layout-box_fieldname = ‘BOX’ . " show detail in popup e05_ls_layout-detail_initial_lines = ‘X’ .II. " show also initial lines e05_ls_layout-detail_titlebar = ‘TEST’.B GESTION DES LED Souvent utilisé dans SAP les leds sont de bon indicateurs visuels.II.1 exemple : * e05_ls_layout-expand_all = 'X'. C. * Je ne sais pas e05_ls_layout-lights_condense = p_lightc.A GESTION DE L’EXPANSION VERSION 3.Documentation sur L’ABAP List Viewer C. * Table interne e05_ls_layout-box_tabname = g_tabname_header.C GESTION DES CHECKBOX * Nom du champ dans la table interne. E AUTRES POSSIBILITÉS Key_hotspot permet de modifier la forme du curseur lorsque celui-ci est présent sur une clé.1 C.II.Documentation sur L’ABAP List Viewer VERSION 3.3. PAGE 51 / 94 . Zebra change la couleur d’une ligne à l ‘autre. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_BACKGROUND_ID = 'ALV_BACKGROUND' "QBJ50 I_CALLBACK_PROGRAM = G_REPID I_STRUCTURE_NAME = 'SFLIGHT' IS_LAYOUT = GS_LAYOUT I_SAVE = G_SAVE IS_VARIANT = GS_VARIANT IT_EVENTS = GT_EVENTS[] * I_SCREEN_START_COLUMN = 0 "Use coordinates for * I_SCREEN_START_LINE =0 "display as dialog box * I_SCREEN_END_COLUMN =0 * I_SCREEN_END_LINE =0 IMPORTING E_EXIT_CAUSED_BY_CALLER = G_EXIT_CAUSED_BY_CALLER ES_EXIT_CAUSED_BY_USER = GS_EXIT_CAUSED_BY_USER TABLES T_OUTTAB = GT_OUTTAB EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2.1 C.III Liste sous forme de grille Le programme BCALV_FULLSCREEN_DEMO Cette fonction permet d’afficher une liste sous la forme d’une grille ALV. PAGE 52 / 94 .Documentation sur L’ABAP List Viewer VERSION 3. ou utiliser des fonctions spécifiques : call function 'REUSE_ALV_FIELDCATALOG_MERGE' exporting * Table interne contenant les champs i_internal_tabname = g_tabname_header * Nom de la structure i_structure_name = 'SCARR' changing * Table contenant le catalogue ct_fieldcat = e01_lt_fieldcat[].Documentation sur L’ABAP List Viewer VERSION 3. leading zero Write no-sign Write no-zero PAGE 53 / 94 .1 Définition du catalogue Le catalogue est basé sur une table de type SLIS_T_FIELDCAT_ALV. C.IV.2 Déclaration : data: ls_fieldcat type slis_fieldcat_alv.1 C. On peut alors soit implémenter le catalogue de façon manuelle.IV Le catalogue C. Le tableau ci-dessous reprend la liste des champs disponible dans la structure SLIS_T_FIELDCAT_ALV Ces derniers sont relativement similaires de ceux utilisés avec les composants ALV.IV. Nom du champ row_pos col_pos fieldname tabname ref_fieldname ref_tabname currency(5) cfieldname ctabname quantity(3) qfieldname qtabname roundfieldname roundtabname round decimalsfieldname decimalstabname decimals_out(6) text_fieldname exponent(3) key(1) icon(1) Symbol(1) checkbox(1) just(1) lzero(1) no_sign(1) no_zero(1) edit_mask Définition like sy-curow like sy-cucol type slis_fieldname type slis_tabname like dd03p-fieldname like dd03p-tabname type c type slis_fieldname type slis_tabname type c type slis_fieldname type slis_tabname type slis_fieldname type slis_tabname type i type slis_fieldname type slis_tabname type c type slis_fieldname type c type c type c type c type c type c type c type c type c type slis_edit_mask Désignation output in row position of the column Field with currency unit and table Field with quantity unit and table Round in write statement " decimals in write statement exponent for floats column with key-color As icon As symbol As checkbox (R)ight (L)eft (C)ent. la table interne est alors automatiquement mise à jour. perform fieldcat_init using gt_fieldcat[]. append ls_fieldcat to rt_fieldcat. clear ls_fieldcat.(X)no out technical field Offset long key word middle key word Short key word heading (ddic) (S)hort (M)iddle (L)ong VERSION 3. ls_fieldcat-col_pos = pos. Lorsqu’une zone est modifiée.Documentation sur L’ABAP List Viewer emphasize(4) fix_column(1) do_sum(1) no_out(1) tech(1) outputlen Offset seltext_l seltext_m seltext_s reptext_ddic ddictxt(1) rollname datatype inttype ddic_outputlen Intlen lowercase key_sel(1) no_sum(1) sp_group(4) Reprep(1) input(1) hotspot(1) type c type c type c type c type c like dd03p-outputlen type dd03p-intlen like dd03p-scrtext_l like dd03p-scrtext_m like dd03p-scrtext_s like dd03p-reptext type c like dd03p-rollname like dd03p-datatype like dd03p-inttype like dd03p-outputlen like dd03p-intlen like dd03p-lowercase type c type c type c type c type c type c Emphasize Spalte fixieren sum up (O)blig. ls_fieldcat-ref_tabname = 'VBAK'. ls_fieldcat-fieldname = 'VBELN'.3 Zone en entrée Il est possible de définir au sein de l’affichage de l’ALV des zones accessibles en écriture de façon très simple.IV. . data: ls_fieldcat type slis_fieldcat_alv.4 EXAMPLE d’implémentation manuelle data: gt_fieldcat type slis_t_fieldcat_alv. form fieldcat_init using rt_fieldcat type slis_t_fieldcat_alv. .IV. data: pos type i value 1. C. PAGE 54 / 94 . . en effet il suffit de mettre la valeur ‘X’ dans le champs input du catalogue. ls_fieldcat-ref_fieldname = 'VBELN'. clear ls_fieldcat. ls_fieldcat-key = 'X'.1 Field not obligatory Do not sum up Group specification selection for rep/rep Input Hotspot C. ls_fieldcat-col_pos = pos. ls_fieldcat-ref_fieldname = 'WAERK'. ls_fieldcat-fieldname = 'WAERK'. clear ls_fieldcat. * LS_FIELDCAT-KEY = 'X'. clear ls_fieldcat. clear ls_fieldcat. ls_fieldcat-col_pos = pos. pos = pos + 1. pos = pos + 1. Endform. ls_fieldcat-ref_tabname = 'VBAK'. VERSION 3. ls_fieldcat-ref_fieldname = 'KWERT'. ls_fieldcat-ref_tabname = 'VBAP'. clear ls_fieldcat. ls_fieldcat-col_pos = pos. ls_fieldcat-ref_tabname = 'VBAK'. * LS_FIELDCAT-KEY = 'X'. * LS_FIELDCAT-KEY = 'X'. ls_fieldcat-fieldname = 'KWERT'. ls_fieldcat-key = 'X'. ls_fieldcat-ref_tabname = 'KONV'. ls_fieldcat-fieldname = 'NAME1'. ls_fieldcat-ref_fieldname = 'POSNR'. ls_fieldcat-ref_fieldname = 'KUNNR'. ls_fieldcat-cfieldname = 'WAERK'. pos = pos + 1. ls_fieldcat-ref_tabname = 'KNA1'. pos = pos + 1. ls_fieldcat-fieldname = 'KUNNR'. append ls_fieldcat to rt_fieldcat. append ls_fieldcat to rt_fieldcat. ls_fieldcat-fieldname = 'POSNR'. ls_fieldcat-ref_fieldname = 'NAME1'. ls_fieldcat-col_pos = pos. append ls_fieldcat to rt_fieldcat. append ls_fieldcat to rt_fieldcat. append ls_fieldcat to rt_fieldcat. ls_fieldcat-col_pos = pos. * LS_FIELDCAT-KEY = 'X'.1 PAGE 55 / 94 .Documentation sur L’ABAP List Viewer pos = pos + 1. Par contre si le développeur souhaite utiliser plusieurs code fonction spécifique au sein de son programme.1. Dans le cas ou aucun menu ne serait fournit alors c’est le menu par défaut qui est repris : C. il lui suffit d’affecter le nom d’un sous programme au niveau du paramètre ‘I_CALLBACK_USER_COMMAND’ si le code fonction est spécifique alors la fonction est automatiquement appelée.A GESTION DES CODES TRANSACTIONS ET CLIK DE LA SOURIS. PAGE 56 / 94 . set pf-status 'STANDARD001'. il faut alors définir au sein du programme le menu utilisateur choisit avant l’appel de la fonction ALV. Il est important de définir manuellement chacune des options. Ensuite. on utilisera le code ‘&ETA’. La zone F2CODE dans la structure du layout permet d’associer une transaction au double click.1 C. il suffit alors de renseigner le paramètre adéquate de la fonction.V Gestion du menu et de la barre des boutons Le menu utilisateur est définit à l’aide de la transaction SE41. à savoir I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET' La valeur du texte (‘PF_STATUS_SET’) ne semble pas avoir de réelle valeur. Ainsi si on souhaite utiliser la notion de détail suite au double click sur une ligne.Documentation sur L’ABAP List Viewer VERSION 3.V. on peut retrouver ci-dessous un exemple de fonctions standards implémentées. Enfin. Si le champ F2CODE n’est pas renseigné alors le code fonction généré suite à un double click est : ‘&IC1’. set parameter id 'CAR' field gt_outtab-carrid.1 * if _code contient le code de la transaction * cs_selfield contient toutes les informations relatives à la selection faites : data: l_ta(4) type c value 'TCH1'. "cursorposit.Documentation sur L’ABAP List Viewer form fcode_bearbeiten using if_fcode like sy-ucomm cs_selfield type slis_selfield. when '&IC1'. call transaction l_ta and skip first screen. VERSION 3. set parameter id 'CON' field gt_outtab-connid. "# EC* clear r_ucomm. "menubutton read table gt_outtab index cs_selfield-tabindex. endform Exemple issu d’un déboguage de la transaction VL10D sur la fonction FCODE_BEARBEITEN. set parameter id 'CAR' field gt_outtab-carrid. case if_fcode. TABNAME TABINDEX SUMINDEX ENDSUM SEL_TAB_FIELD VALUE BEFORE_ACTION AFTER_ACTION REFRESH IGNORE_MULTI COL_STABLE ROW_STABLE EXIT FIELDNAME GROUPLEVEL COLLECT_FROM COLLECT_TO C I I C C C C C C C C C C C I I I 30 4 4 1 60 60 1 1 1 1 1 1 1 30 4 40 4 CT_ITEM 1 0 CT_ITEM-MATNR 65 MATNR 0 0 PAGE 57 / 94 . "dobbleclick read table gt_outtab into gt_outtab index rs_selfield-tabindex. "# EC* clear r_ucomm. endcase. set parameter id 'CON' field gt_outtab-connid. call transaction l_ta and skip first screen. when 'WAHL'. "for parameter IS_VARIANT g_save value 'A'. move p_vari to gx_variant-variant.1 C. on peut utiliser la fonction suivante : REUSE_ELV_VARIANT_F4.VI.1 Définition * Déclaration data : gs_variant type disvariant.VI.3.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid.Documentation sur L’ABAP List Viewer VERSION 3. C. call function 'REUSE_ALV_VARIANT_F4' exporting is_variant = g_variant i_save = g_save i_tabname_header = g_tabname_header i_tabname_item = g_tabname_item * it_default_fieldcat = importing e_exit = g_exit es_variant = gx_variant exceptions not_found = 2. PAGE 58 / 94 .B SAUVEGARDE DE LA VARIANTE DANS LE PAI (A VÉRIFIER) On peut utiliser la fonction REUSE_ALV_VARIANT_EXISTENCE if not p_vari is initial. call function 'REUSE_ALV_VARIANT_EXISTENCE' exporting i_save = g_save changing cs_variant = gx_variant.VI. move g_variant to gx_variant.VI Gestion des variantes C. else.VI. perform variant_init. g_repid = sy-repid. g_variant = gx_variant.A GESTION DU F4 Afin de gérer le ‘F4’ dans un selection-screen.3. C.2 Implémentation * Implémentation clear gs_variant. * § 2.VI.3 Fonction utiles C. data: g_repid like sy-repid. C. * 'gs_variant' must at least contain the report-id to allow * saving a variant. VI. PAGE 59 / 94 .3. call function 'REUSE_ALV_VARIANT_DEFAULT_GET' exporting i_save = g_save changing cs_variant = gx_variant exceptions not_found = 2.C RÉCUPÉRATION DE LA VARIANTE PAR DÉFAUT Pour la récupération de la variante par défaut on peut utiliser la fonction : REUSE_ALV_VARIANT_DEFAULT_GET.Documentation sur L’ABAP List Viewer endif. VERSION 3.1 C. ernam like vbak-ernam " auteur de la saisie . z_kbetr(11) type p decimals 2 " montant . waerk like vbak-waerk " devise . koein like konv-waers " valeur = devise ou % .VII Table contenant les données La table contenant les données doit être une table interne.1 C. kunnr like vbak-kunnr " donneur d'ordre .table de chargement data : begin of t_charge occurs 0 . kwert like konv-kwert " valeur condition . arktx like vbap-arktx " désignation article . kschl like zsd02-kschl " type condition . name1 like kna1-name1 " nom . vbeln like vbak-vbeln " n° cde . vtext like zsd02-vtext " libellé . matnr like vbap-matnr " code article . kpein like konv-kpein " unité de prix .Documentation sur L’ABAP List Viewer VERSION 3. erdat like vbak-erdat " date cde . Voici un exemple de définition d’une table affichée par la suite : *. end of t_charge. posnr like vbap-posnr " n° poste . PAGE 60 / 94 . kmein like konv-kmein " unité qtité . VIII Les événements Data gt_events type slis_t_event. La structure utilisé est la suivante : Les évènements disponibles doivent être définit dans une table interne du type ci-dessus.Documentation sur L’ABAP List Viewer VERSION 3. Il est alors très simple d’associer une fonciton à au moins un des évènements disponibles.1 C.(La gestion du click passe par l’utilisation du f2code). Name  nom de l’évènement Form  Nom de la fonction associé On peut utiliser la fonction suivante REUSE_ALV_EVENT_GET afin de récupérer l’ensemble des fonctions disponibles dans une table interne. le premier correspond à l’événement disponible alors que le second correspond à la fonction associée. call function 'REUSE_ALV_EVENTS_GET' exporting i_list_type = 0 importing et_events = e03_lt_events. Liste des évènements : • • • • • • • • • • • • • • • • CALLER_EXIT USER_COMMAND TOP_OF_PAGE TOP_OF_COVERPAGE END_OF_COVERPAGE FOREIGN_TOP_OF_PAGE FOREIGN_END_OF_PAGE PF_STATUS_SET LIST_MODIFY TOP_OF_LIST END_OF_PAGE END_OF_LIST AFTER_LINE_OUTPUT BEFORE_LINE_OUTPUT REPREP_SEL_MODIFY SUBTOTAL_TEXT PAGE 61 / 94 . La table interne contient alors 2 champs. 'PF_STATUS_SET'. 'BEFORE_LINE_OUTPUT'. 'CALLER_EXIT'. 'TOP_OF_PAGE'. 'FOREIGN_END_OF_PAGE'.1 'ITEM_DATA_EXPAND'. 'REPREP_SEL_MODIFY'. 'FOREIGN_TOP_OF_PAGE'. if sy-subrc = 0. 'END_OF_LIST'. 'AFTER_LINE_OUTPUT'.Documentation sur L’ABAP List Viewer Définition des constantes utilisées dans le type-spool SLIS : * Events slis_ev_item_data_expand slis_ev_reprep_sel_modify slis_ev_caller_exit_at_start slis_ev_user_command slis_ev_top_of_page slis_ev_top_of_coverpage slis_ev_end_of_coverpage slis_ev_foreign_top_of_page slis_ev_foreign_end_of_page slis_ev_pf_status_set slis_ev_list_modify slis_ev_top_of_list slis_ev_end_of_page slis_ev_end_of_list slis_ev_after_line_output slis_ev_before_line_output slis_ev_subtotal_text type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value type slis_formname value VERSION 3. 'SUBTOTAL_TEXT'. 'LIST_MODIFY'. move gc_formname_top_of_page to ls_event-form. endif. read table e03_lt_events with key name = slis_ev_top_of_page into ls_event. append ls_event to e03_lt_events. 'USER_COMMAND'. 'TOP_OF_COVERPAGE'. PAGE 62 / 94 . 'END_OF_COVERPAGE'. 'TOP_OF_LIST'. 'END_OF_PAGE'. Documentation sur L’ABAP List Viewer VERSION 3.1 C.IX Commentaires : Entête de page On peut utiliser la fonction REUSE_ALV_COMMENTARY_WRITE. La table utilisée afin de stocké les informations est de type : slis_t_listheader typ(1) type c, " H = Header, S = Selection, A = Action key(20) type c, info type slis_entry, exemple de sortie générée à l’écran : constants: gc_formname_top_of_page type slis_formname value 'TOP_OF_PAGE'. data: gt_list_top_of_page type slis_t_listheader. perform e04_comment_build using gt_list_top_of_page[]. call function 'REUSE_ALV_COMMENTARY_WRITE' exporting it_list_commentary = gt_list_top_of_page. form e04_comment_build using e04_lt_top_of_page type slis_t_listheader. data: ls_line type slis_listheader. * * Listenüberschrift: Typ H clear ls_line. ls_line-typ = 'H'. * LS_LINE-KEY: not used for this type ls_line-info = ‘intitulé de liste’. append ls_line to e04_lt_top_of_page. * Kopfinfo: Typ S clear ls_line. ls_line-typ = 'S'. ls_line-key = ‘Clé 1’. ls_line-info = ‘Texte d information’. append ls_line to e04_lt_top_of_page. ls_line-key = ‘Clé 2’. append ls_line to e04_lt_top_of_page. * Aktionsinfo: Typ A clear ls_line. ls_line-typ = 'A'. * LS_LINE-KEY: not used for this type ls_line-info = ‘Statut liste’. append ls_line to e04_lt_top_of_page. endform. PAGE 63 / 94 Documentation sur L’ABAP List Viewer VERSION 3.1 C.X Gestion de plusieurs ALV sur un seul écran (programme BALVBT01) La gestion de plusieurs ALV sur un seul écran est possible à l’aide des fonctions standards sans avoir recours à un container spécifique. Nous nous efforcerons de présenter les fonctions permettant cette souplesse : Exemple d’écran généré : C.X.1 Initialisation La première fonction a appellé a pour objectif d’intialiser les blocs : Data repid like sy-repid. Repid = sy-repid. call function 'REUSE_ALV_BLOCK_LIST_INIT' exporting * nom du programme i_callback_program = repid * Nom de la fonction appelée traité les commandes utilisateurs. i_callback_user_command = 'USER_COMMAND' * Définit que le menu est propre à l’utilisateur i_callback_pf_status_set = ‘PF_STATUS_SET’ * IT_EXCLUDING = . Le menu utilisateur sera à définir dans le programme, voir autre section. PAGE 64 / 94 Documentation sur L’ABAP List Viewer C.X.2 Définition des blocs VERSION 3.1 Il est alors possible d’afficher autant de blocs que l’on souhaite soit de type classique ou hiérarchique. On utilise alors les fonctions suivantes : Ces fonctions sont relativement proche des fonctions classique auquelles elles font référence, le développeur est donc invité à s’y reporter. C.X.2.A ALV CLASSIQUE : call function 'REUSE_ALV_BLOCK_LIST_APPEND' exporting * CATALOGUE it_fieldcat * LAYOUT is_layout * TABLE INTERNE i_tabname *EVENEMENT it_events i_text tables t_outtab = xfield = x_layout = 'XDATA' = gt_xevents = ‘first block’ = xdata. C.X.2.B ALV HIÉRARCHIQUE : call function 'REUSE_ALV_BLOCK_LIST_HS_APPEND' exporting is_layout = h_layout it_fieldcat = hfield is_keyinfo = gs_keyinfo i_header_tabname = 'HDATA' i_item_tabname = 'IDATA' it_events = gt_hevents i_text = text-0b2 tables t_outtab_header = hdata t_outtab_item = idata. C.X.3 Affichage des blocs Enfin, afin de pouvoir afficher tout les blocs à l’écran il suffit alors d’appeler la fonction suivante : PAGE 65 / 94 Documentation sur L’ABAP List Viewer CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY' * EXPORTING * I_INTERFACE_CHECK ='' * IS_PRINT = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE =0 * I_SCREEN_END_COLUMN =0 * I_SCREEN_END_LINE =0 * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = * EXCEPTIONS * PROGRAM_ERROR =1 * OTHERS =2 . VERSION 3.1 PAGE 66 / 94 . Documentation sur L’ABAP List Viewer VERSION 3. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_REPORT) LIKE SY-REPID OPTIONAL *" VALUE(I_HANDLE) LIKE DISEXTRACT-HANDLE OPTIONAL *" VALUE(I_LOG_GROUP) LIKE DISEXTRACT-LOG_GROUP OPTIONAL *" VALUE(I_USERNAME) LIKE DISEXTRACT-USERNAME OPTIONAL *" CHANGING *" VALUE(CS_EXTRACT1) LIKE DISEXTRACT *" STRUCTURE DISEXTRACT *" VALUE(CS_EXTRACT2) LIKE DISEXTRACT *" STRUCTURE DISEXTRACT *"---------------------------------------------------------------------- C.1 C.4. GS_EXTRACT2 correspond à la structure pour le chargement des données. function reuse_alv_extract_at_init. call function 'REUSE_ALV_EXTRACT_AT_INIT' changing cs_extract1 = gs_extract1 cs_extract2 = gs_extract2. cela est particulièrement important si on souhaite gérer la notion d’aide sur un écran de sélection.X. CS_EXTRACT1 et CS_EXTRACT2 sont les structures reprenant toutes les informations. P_SAVE et P_LOAD définissent le mode (SAVE or LOAD) P_EX1 et P_EX2 correspondent aux nom des extraits C_P_EX1 et C_P_EX2 sont les textes de désignation. CALL FUNCTION 'REUSE_ALV_EXTRACT_AT_SELSCREEN' EXPORTING I_P_SAVE = P_SAVE I_P_LOAD = P_LOAD CHANGING C_P_EX1 = P_EX1 C_P_EX2 = P_EX2 C_P_EXT1 = P_EXT1 C_P_EXT2 = P_EXT2 PAGE 67 / 94 . Dans notre exemple nous l’avons placé au sein de l’initialisation.A INITIALISATION Il est conseillé de placer cette fonction le plus tôt possible.4 Gestion des extraits – sauvegarde de table interne (Programme BALVEX01) La gestion des extraits consiste à sauvegarder des informations contenus dans une table interne.4. C. La fonction se contente de retourner des informations sur l’environnement en cours. *---------------------------------------------------------------------* * initialization. Une fois enregistrée les informations sont alors consultables dans le temps même si les données de bases ont été modifiées.X. GS_EXTRACT1 correspond à la structure pour l’enregistrement des données.X. AT SELECTION-SCREEN.B La fonction suivante permet de mettre à jour les structures GS_EXTRACT1 et 2. data: gs_extract2 like disextract. data: gs_extract1 like disextract. Cette fonctionnalité offerte par SAP est particulièrement intéressante. 4. selection-screen comment 3(50) text-ex1 for field p_noex. call function 'REUSE_ALV_EXTRACT_AT_F4_P_EX2' EXPORTING I_PARNAME_P_EXT2 = 'P_EXT2' changing c_p_ex2 = p_ex2 c_p_ext2 = p_ext2 cs_extract2 = gs_extract2. parameters: p_noex radiobutton group extr.1 C. PAGE 68 / 94 . selection-screen end of line. VERSION 3.Documentation sur L’ABAP List Viewer CS_EXTRACT1 = GS_EXTRACT1 CS_EXTRACT2 = GS_EXTRACT2. * Type-pool of ALV TYPE-POOLS: SLIS.X. selection-screen begin of block extract with frame title text-ext. C. * Report Selections SELECT-OPTIONS CARRID FOR SFLIGHT-CARRID. C.4.X. * * * * C.E CHARGEMENT DE L’EXTRAIT call function 'REUSE_ALV_EXTRACT_LOAD' exporting is_extract = gs_extract2 tables et_exp01 = gt_sflight.X. selection-screen begin of line. * selection-screen begin of line. la première concerne le champs pour l’enregistrement d’extrait alors que la seconde concerne le chargement. SELECT-OPTIONS FLDATE FOR SFLIGHT-FLDATE. SELECTION-SCREEN SKIP 1. * DB-Table TABLES SFLIGHT.X.4.F EXEMPLE REPORT BALVEX01 NO STANDARD PAGE HEADING.4. Ces fonctions peuvent être placées au sein de call function 'REUSE_ALV_EXTRACT_AT_F4_P_EX1' EXPORTING I_PARNAME_P_EXT1 = 'P_EXT1' changing c_p_ex1 = p_ex1 c_p_ext1 = p_ext1 cs_extract1 = gs_extract1.C AIDE F4 On utilise pour cela les fonctions suivantes.D ENREGISTREMENT DE L’EXTRAIT call function 'REUSE_ALV_EXTRACT_SAVE' exporting is_extract = gs_extract1 i_get_selinfos = 'X' tables it_exp01 = gt_sflight. SELECT-OPTIONS CONNID FOR SFLIGHT-CONNID. selection-screen begin of line. selection-screen end of line. selection-screen end of line. break-point. parameters: p_ex2 like ltex-exname. VERSION 3. selection-screen comment 3(29) text-ex2 for field p_ex2. selection-screen comment 3(29) text-ex2 for field p_ex1. selection-screen begin of line. *---------------------------------------------------------------------* * INITIALIZATION. selection-screen comment 47(40) p_ext2 for field p_ex2. * Process on value request AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_EX1. parameters: p_load radiobutton group extr. selection-screen end of line. selection-screen comment 3(50) text-ex4 for field p_load. selection-screen begin of line. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_EX2. selection-screen comment 3(50) text-ex3 for field p_save. CALL FUNCTION 'REUSE_ALV_EXTRACT_AT_SELSCREEN' EXPORTING I_P_SAVE = P_SAVE I_P_LOAD = P_LOAD CHANGING C_P_EX1 = P_EX1 C_P_EX2 = P_EX2 C_P_EXT1 = P_EXT1 C_P_EXT2 = P_EXT2 CS_EXTRACT1 = GS_EXTRACT1 CS_EXTRACT2 = GS_EXTRACT2. CALL FUNCTION 'REUSE_ALV_EXTRACT_AT_INIT' CHANGING CS_EXTRACT1 = GS_EXTRACT1 CS_EXTRACT2 = GS_EXTRACT2. selection-screen comment 3(29) text-ex5 for field p_ext1. DATA: GS_EXTRACT1 LIKE DISEXTRACT. * * CALL FUNCTION 'REUSE_ALV_EXTRACT_AT_F4_P_EX1' EXPORTING I_PARNAME_P_EXT1 = 'P_EXT1' CHANGING C_P_EX1 = P_EX1 C_P_EXT1 = P_EXT1 CS_EXTRACT1 = GS_EXTRACT1.1 * Data to be displayed DATA: GT_SFLIGHT LIKE SFLIGHT OCCURS 0. selection-screen end of line. selection-screen begin of line. DATA: GS_EXTRACT2 LIKE DISEXTRACT.Documentation sur L’ABAP List Viewer parameters: p_save radiobutton group extr. AT SELECTION-SCREEN. parameters: p_ex1 like ltex-exname. selection-screen end of block extract. selection-screen end of line. * * CALL FUNCTION 'REUSE_ALV_EXTRACT_AT_F4_P_EX2' EXPORTING I_PARNAME_P_EXT2 = 'P_EXT2' CHANGING C_P_EX2 = P_EX2 PAGE 69 / 94 . parameters: p_ext1 like ltex-text. START-OF-SELECTION. IF P_LOAD = 'X'. ENDIF. VERSION 3. ENDIF.Documentation sur L’ABAP List Viewer C_P_EXT2 = P_EXT2 CS_EXTRACT2 = GS_EXTRACT2. SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT WHERE CARRID IN CARRID AND CONNID IN CONNID AND FLDATE IN FLDATE. CALL FUNCTION 'REUSE_ALV_EXTRACT_SAVE' EXPORTING IS_EXTRACT = GS_EXTRACT1 I_GET_SELINFOS = 'X' TABLES IT_EXP01 = GT_SFLIGHT. IF P_SAVE = 'X'.1 PAGE 70 / 94 . ENDIF. * EXIT. CALL FUNCTION 'REUSE_ALV_EXTRACT_LOAD' EXPORTING IS_EXTRACT = GS_EXTRACT2 TABLES ET_EXP01 = GT_SFLIGHT. * Call ABAP/4 List Viewer CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = GS_EXTRACT1-REPORT I_STRUCTURE_NAME = 'SFLIGHT' I_SAVE = 'A' TABLES T_OUTTAB = GT_SFLIGHT. * Selection IF P_LOAD IS INITIAL. Documentation sur L’ABAP List Viewer VERSION 3.1 D ANNEXES : PAGE 71 / 94 . METHODS: FCODE_HANDLER FOR EVENT BUTTON_CLICKED OF STATUS IMPORTING FCODE. IREF TYPE REF TO I_VEHICLE.2 Exemple de définition de classe. ID TYPE I. LIST_CHANGE FOR EVENT SPEED_CHANGE OF I_VEHICLE IMPORTING NEW_SPEED. **************************************************************** * LOCAL CLASSES: Definition **************************************************************** *=========================================================== ==== CLASS C_LIST DEFINITION.I. FLAG.1 D. PUBLIC SECTION. PRIVATE SECTION. END OF LINE. REF_SHIP TYPE REF TO C_SHIP. LIST LIKE SORTED TABLE OF LINE WITH UNIQUE KEY ID. BEGIN OF LINE. LIST_OUTPUT. SPEED TYPE I.Documentation sur L’ABAP List Viewer VERSION 3.I.1 Déclaration d’une classe Les classes sous SAP se décomposent en trois parties : • • • Public : Privé : Protected : accessible par tous accessible uniquement par les objets de la classe même attribut que pour la partie privée mais accessible aussi par les classes déclarées « ami » Chacune d’entre elle peut contenir • des données • des méthodes • Des événements. PAGE 72 / 94 . REF_TRUCK TYPE REF TO C_TRUCK.I Utilisation de classe sous SAP. NOTA : Cette partie est donnée à titre informatif et ne peut en aucuns cas se substituer à l’aide fournit par SAP : SAP Library  Basis components  Abap Programming and Runtime Environment  BC-Abap Programming Abap Objects D. D. DATA: ID TYPE I. METHOD LIST_CHANGE . *CODE ENDMETHOD. METHOD FCODE_HANDLER . *CODE ENDMETHOD. *CODE ENDMETHOD. VERSION 3. PAGE 73 / 94 . ENDCLASS.Documentation sur L’ABAP List Viewer ENDCLASS.3 Implémentation d’une classe CLASS C_LIST IMPLEMENTATION.I.1 D. METHOD LIST_OUTPUT. Ensuite. la marche à suivre est aussi très simple.Documentation sur L’ABAP List Viewer VERSION 3. CLEAR T_GROUPE.1 E Annexe sur ALV standard E. APPEND T_GROUPE. Enfin il suffit d’ajouter ces informations dans la table « t_groupe ». La première étape consiste à déclarer la table de type : LVC_T_SGRP. T_GROUPE-TEXT = ‘Groupe A’. il suffit d’affecter au champ SP_GROUP du catalogue une clé de 4 chiffres (digits) correspondant à un groupe. T_GROUPE-SP_GROUPE = ‘1001’.I Gestion des groupes de colonnes pour les variantes : La gestion de groupe de colonnes prédéfinies pour les variantes peut s’avérer des plus intéressante. PAGE 74 / 94 . DATA : t_groupe type LVC_T_SGRP. II Ajout d’un menu.Documentation sur L’ABAP List Viewer VERSION 3. Il faut commencer par définir un statut associé au programme en utilisant la transaction SE41. au sein du programme on utilise l’instruction suivante. Enfin. Cette transaction permet d’affecter des codes transactions aux différents boutons. pour insérer le menu : * MAIN100 est le nom du statues SET PF-STATUS ‘MAIN100’ PAGE 75 / 94 . dans le PBO. Les codes fonctions seront alors récupérés au sein de l’OK_CODE dans le PAI de l’écran (dans le cas d’un Ecran) ou dans la fonction AT SELECTION-SCREEN. ainsi que de créer son menu.1 E. clear ls_fieldcat. ls_fieldcat-ref_tabname = 'SCARR'. * Initialization fieldcatalog initialization. ls_fieldcat-fieldname = 'SPFLI-CONNID'. ls_fieldcat-col_pos = pos. clear ls_fieldcat. perform fieldcat_init using gt_fieldcat[].Documentation sur L’ABAP List Viewer Création d’un ALV à l’aide d’une fonction standard SAP. g_repid = sy-repid. ls_fieldcat-ref_fieldname = 'CARRID'. Puis on fait appel à la fonction standard «'REUSE_ALV_LIST_DISPLAY” Exemple * Global data declaration include vsd03top. pos = pos + 1. data: pos type i value 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SCARR-CARRNAME'. append ls_fieldcat to rt_fieldcat. ****************************************************************************** *----------------------------------------------------------------------* Forms *----------------------------------------------------------------------* Initialization fieldcatalog form fieldcat_init using rt_fieldcat type slis_t_fieldcat_alv. * Display list end-of-selection.   VERSION 3. perform select_data tables gt_outtab. ls_fieldcat-key = 'X'. append ls_fieldcat to rt_fieldcat. * Data selection start-of-selection. ls_fieldcat-fieldname = 'SCARR-CARRID'. data: ls_fieldcat type slis_fieldcat_alv. ls_fieldcat-ref_fieldname = 'CARRNAME'. ls_fieldcat-col_pos = pos. pos = pos + 1. PAGE 76 / 94 . ls_fieldcat-ref_tabname = 'SCARR'.1 La première étape consiste à créer un catalogue. ****************************************************************************** call function 'REUSE_ALV_LIST_DISPLAY' exporting i_callback_program = g_repid it_fieldcat = gt_fieldcat[] tables t_outtab = gt_outtab. ls_fieldcat-ref_fieldname = 'CONNID'. clear ls_fieldcat. clear ls_fieldcat. ls_fieldcat-col_pos = pos. ls_fieldcat-col_pos = pos. pos = pos + 1. ls_fieldcat-fieldname = 'SPFLI-AIRPTO'.1 PAGE 77 / 94 . clear ls_fieldcat. ls_fieldcat-fieldname = 'SPFLI-DEPTIME'. append ls_fieldcat to rt_fieldcat. ls_fieldcat-no_out = 'X'. ls_fieldcat-ref_fieldname = 'DISTID'.Documentation sur L’ABAP List Viewer ls_fieldcat-ref_tabname = 'SPFLI'. pos = pos + 1. clear ls_fieldcat. ls_fieldcat-col_pos = pos. ls_fieldcat-ref_tabname = 'SPFLI'. append ls_fieldcat to rt_fieldcat. pos = pos + 1. pos = pos + 1. clear ls_fieldcat. ls_fieldcat-ref_fieldname = 'ARRTIME'. append ls_fieldcat to rt_fieldcat. pos = pos + 1. ls_fieldcat-fieldname = 'SPFLI-ARRTIME'. ls_fieldcat-fieldname = 'SPFLI-CITYTO'. ls_fieldcat-ref_tabname = 'SPFLI'. append ls_fieldcat to rt_fieldcat. append ls_fieldcat to rt_fieldcat. pos = pos + 1. ls_fieldcat-no_out = 'X'. ls_fieldcat-col_pos = pos. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SPFLI-DISTANCE'. ls_fieldcat-ref_tabname = 'SPFLI'. ls_fieldcat-fieldname = 'SPFLI-CITYFROM'. append ls_fieldcat to rt_fieldcat. pos = pos + 1. clear ls_fieldcat. ls_fieldcat-fieldname = 'SPFLI-AIRPFROM'. clear ls_fieldcat. ls_fieldcat-ref_fieldname = 'CITYTO'. ls_fieldcat-col_pos = pos. ls_fieldcat-ref_fieldname = 'CITYFROM'. ls_fieldcat-ref_fieldname = 'AIRPTO'. pos = pos + 1. "fieldcat_init * Data selection VERSION 3. ls_fieldcat-ref_fieldname = 'AIRPFROM'. ls_fieldcat-no_out = 'X'. ls_fieldcat-col_pos = pos. ls_fieldcat-no_out = 'X'. clear ls_fieldcat. ls_fieldcat-ref_tabname = 'SPFLI'. ls_fieldcat-ref_fieldname = 'DISTANCE'. append ls_fieldcat to rt_fieldcat. ls_fieldcat-ref_tabname = 'SPFLI'. ls_fieldcat-ref_tabname = 'SPFLI'. clear ls_fieldcat. append ls_fieldcat to rt_fieldcat. endform. ls_fieldcat-ref_tabname = 'SPFLI'. ls_fieldcat-fieldname = 'SPFLI-DISTID'. ls_fieldcat-ref_tabname = 'SPFLI'. ls_fieldcat-ref_fieldname = 'DEPTIME'. ls_fieldcat-col_pos = pos. append ls_fieldcat to rt_fieldcat. rt_outtab-spfli-airpfrom. " select_data VERSION 3.1 PAGE 78 / 94 . rt_outtab-spfli-deptime. rt_outtab-spfli-distance. endselect. rt_outtab-spfli-cityfrom. rt_outtab-spfli-arrtime. rt_outtab-scarr-carrname. rt_outtab-spfli-airpto. append rt_outtab. rt_outtab-spfli-connid.Documentation sur L’ABAP List Viewer form select_data tables rt_outtab like gt_outtab[]. endform. select distinct scarr~carrid scarr~carrname spfli~connid spfli~cityfrom spfli~airpfrom spfli~cityto spfli~airpto spfli~deptime spfli~arrtime spfli~distance spfli~distid into (rt_outtab-scarr-carrid. rt_outtab-spfli-cityto. rt_outtab-spfli-distid) from scarr inner join spfli on scarr~carrid = spfli~carrid where scarr~carrid between 'AA' and 'LH'. you lock totals calculation for the relevant field. y. the ALV grid control color-codes the column as a key field and fixes this column during horizontal scrolling. If the character field begins with 'C' (color code). see the F1 help on the FORMAT statement. DO_SUM LVC_DOSUM Char(1) SPACE. the ALV grid control allows you to directly hide key columns with NO_OUT (field KEY_SEL is not used). the ALV uses this field to calculate the total (this corresponds to the generic totals function in the toolbar. LVC_KEY Char(1) SPACE. the ALV grid control recognizes upper/lower case in the output table. for example.III Field name Output Options of Columns Comp. n PAGE 79 / 94 . 'X' or 'Cxyz' (x:'1'-'9'. Parameter sel_mode of the layout structure allows the user to select multiple rows in the grid control (see also: get_selected_rows). If this parameter is initial for each field catalog entry. the ALV uses a pre-defined color for highlighting the column.1 E. 'X' If this field is set. LVC_NOOUT Char(1) SPACE. The parameter determines the relative column position of the field for list output. 'X' If this field is set. The ALV displays the contents of hidden fields on the detail screen for a row in the grid control. the remaining numbers have the following meaning: • • • HOTSPOT KEY x: color number y: intensified display on/off y: inverse display on/off LOWERCASE NO_OUT NO_SUM OUTPUTLEN For more information on color coding. LVC_NOSIGN Char(1) SPACE. This affects the sorting of fields. The user can interactively modify the order of the columns. 'X' If this field is set. you hide the relevant column in the list. Nevertheless. LVC_HOTSPT Char(1) SPACE. LOWERCASE Char(1) SPACE. the column is available in the field selection and can be interactively selected by the user as a display field.) EMPHASIZE LVC_EMPHSZ Char(4) SPACE. 'X' If you set this field. 'X' If you set this field. LVC_OUTLEN Numc(6) 0 (default setting). The checkbox cannot be modified by the user. type Dtype(length) Use Value range CHECKBOX LVC_CHECKB CHAR(1) SPACE. the order of the columns corresponds to the sequence of fields in the field catalog. 'X' If this field is set. all cells of this column are hotspot-sensitive. In contrast to the ABAP List Viewer.Documentation sur L’ABAP List Viewer VERSION 3. 'X' Outputting a checkbox. COL_POS LVC_COLPOS INT4(10) natural number Relevant only if the relative column positions should not be identical to the sequence of fields in the field catalog when the list is displayed for the first time. The order of the key columns in the ALV grid control can be modified interactively.z: '0'=off '1'=on) If the field is set to 'X'. For fields without reference to the DDIC. the relevant field is not displayed on the list and cannot be shown interactively. PAGE 80 / 94 .1 If the field has a reference to the Data Dictionary.Documentation sur L’ABAP List Viewer Determines the column width of the field: • VERSION 3. it must not be specified as a sorting criterion). (For example. the ALV adopts the output length of the relevant domain. 'X' If this field is set. The field is only known in the field catalog. In this case. you must specify the desired field output length. you can leave the field set to its initial value. • TECH LVC_TECH Char(1) SPACE. type Dtype(length) Use Value range DECIMALS_O LVC_DECMLS Char(6) initial. natural number Relevant only if no currency field is assigned to the field and if CURRENCY has a value. conv (conversion exit) If you set a conversion exit (for example. integer Determines a fixed exponent for the field. See also: Using the Conversion Exit EXPONENT LVC_EXPONT Char(3) initial. USING EDIT MASK . Field name Comp. EDIT_MASK LVC_EDTMSK Char(60) SPACE. 'L'. You can use an additional field in the output table to determine how many digits are to be displayed after the comma in each row. The column contents must consist of valid icon strings ( @xx@ or @xx\Q <Quickinfo> @ ). NO_SIGN and ROUND correspond to WRITE additions DECIMALS . JUST LVC_JUST Char(1) SPACE. conv = ' ==ALPHA ' for function module CONVERSION_EXIT_ALPHA_OUTPUT ). EDIT_MASK . the ALV control displays these fields right justified without leading zeros. EXPONENT . you enforce output conversion for the associated output field. For information on combining these fields with fields CURRENCY and QUANTITY (for WRITE: UNIT ). 'R'. If you set LZERO . The field must be of internal type F. leading PAGE 81 / 94 . 'X' Relevant only to fields of data type NUMC . the column contents of the output table are output as an icon. EXPONENT .1 E. field name of output table Defining the digits after the comma on a row-by-row basis.IV Formatting Column Contents Fields DECIMALS_O . LVC_LZERO Char(1) SPACE. Justifications: • • • 'R': right justified 'L': left justified 'C': centered LZERO How the column header is justified. see the F1 help for the WRITE edit option. (See also F1 help for WRITE edit option EXPONENT ). You should consider the problem of printing icons.Documentation sur L’ABAP List Viewer VERSION 3.'C' Relevant only to fields of data type CHAR or NUMC . NO-SIGN and ROUND . You cannot justify the column header separately. The value in this field determines the number of digits to be displayed after the comma. 'X' If this field is set. depends on how the column contents are justified. ICON LVC_ICON Char(1) SPACE. In the default setting. DECMFIELD LVC_DFNAME Char(30) SPACE. (See also F1 help for WRITE edit option USING EDIT MASK) . The cell remains empty. no zeros are displayed for initial value fields.Documentation sur L’ABAP List Viewer VERSION 3. LVC_NOSIGN Char(1) SPACE. (It is usually possible to print symbols. the ALV grid control moves the comma to the left. 'X' If NO_ZERO is set. The column contents of the internal table must consist of valid symbol signs. The caller should consider the problem of printing symbols. PAGE 82 / 94 . If you set NO-SIGN . LVC_ROUND Char(10) initial. LVC_SYMBOL Char(1) SPACE. but they may not be output correctly depending on the printer configuration). For positive ROUND values. You can use an additional field in the output table to determine how the relevant field is scaled in each row. 'X' Relevant only to value fields. it moves the comma to the right. 'X' If this field is set.1 NO_SIGN NO_ZERO ROUND ROUNDFIELD SYMBOL zeros are displayed. the column contents are displayed as a symbol. values are displayed without signs (see also F1 help for the WRITE edit options). natural number Displaying a value of type P scaled by the power of ten. otherwise. (See also F1 help for the WRITE edit options) LVC_RNDFN Char(30) Defining scaled output on a row-by-row-basis. LVC_NOZERO Char(1) SPACE. PAGE 83 / 94 . If this field is set. the toolbar is hidden. Value range Character string of 70 characters at most SPACE. 'D' Selection modes for SEL_MODE Value SPACE 'A' Mode same as 'B' Column and row selection (see graphic) 'B' Simple selection. the ALV grid control optimizes the column width. If this field is set. You can then see the column header and the contents of the cells of this column. 'X' SPACE. If this field is set. 'X' NO_TOOLBAR NO_VGRIDLN SEL_MODE SPACE. columns are displayed without horizontal grid lines. columns are displayed without vertical grid lines. Set the selection mode (see table below). 'C'. If this field is set. list • Multiple columns Multiple rows Multiple columns Multiple rows Multiple Comment Default setting The user selects the rows through pushbuttons at the left border of the grid control. column headers are hidden. 'B'.V Properties of the Grid Control General display options Field name CWIDTH_OPT Description If this field is set. cells are not merged when a column is sorted. 'A'. If this field is set. 'X' Grid customizing Field name GRID_TITLE NO_HEADERS NO_HGRIDLN NO_MERGING NO_ROWMARK Description Title between grid control and toolbar If this field is set. 'X' SPACE. 'X' SPACE. 'X' SMALLTITLE SPACE. Value range SPACE. list box Possible selections see 'B' • • • • 'C' Multiple selection. If this field is set. the button at the beginning of a row is hidden in selection modes cell selection ( SEL_MODE = 'D' ) and column/row selection ( SEL_MODE = 'A' ).1 E. the title size in the grid control is set to the font size of the column header.Documentation sur L’ABAP List Viewer VERSION 3. 'X' SPACE. 'X' SPACE. Documentation sur L’ABAP List Viewer box • 'D' Cell selection • • • columns Multiple rows Multiple columns Multiple rows Any cells VERSION 3. ALV grid control with column and row selection PAGE 84 / 94 .1 The user selects the rows through pushbuttons at the left border of the grid control. 1 E.Documentation sur L’ABAP List Viewer VERSION 3.VI Events of Class CL_GUI_ALV_GRID The section Working With the ALV Grid Control describes the special points and issues you must consider when you handle events of the ALV grid control. User-defined Text Output Event print_end_of_list print_top_of_list print_end_of_page print_top_of_page subtotal_text Application Define output text to be printed at the end of the entire list Define output text to be printed at the beginning of the entire list Define output text to be printed at the end of each page Define output text to be printed at the beginning of each page Define self-defined subtotals texts Mouse-controlled Actions in the Grid Control Event double_click hotspot_click onDrag onDrop onDropComplete onDropGetFlavor Application Query a double-click on a cell of the grid control Query a hotspot click on columns defined for this purpose in advance Collect information when elements of the ALV grid control are dragged Process information when elements of the ALV grid control are dropped Perform final actions after successful Drag&Drop Distinguish between options for Drag&Drop behavior Processing of Self-defined and Standard Functions Event before_user_command user_command after_user_command Application Query self-defined and standard function codes Query self-defined function codes Query self-defined and standard function codes Definition of Self-defined Functions PAGE 85 / 94 . Documentation sur L’ABAP List Viewer Event toolbar menu_button context_menu_request Application VERSION 3.1 Change, delete or add GUI elements in the toolbar Define menus for menu buttons in the toolbar Change context menu PAGE 86 / 94 Documentation sur L’ABAP List Viewer VERSION 3.1 E.VII Découpage de l’écran afin d’afficher plusieurs ALV. E.VII.1 Définition de l’écran de sélection Afin de pouvoir afficher plusieurs objets ALV au sein d’un même écran, on peut procéder selon deux méthodes :  Créer deux « CUSTOM CONTROL ».  Utiliser un conténaire divisant en cellules le custom control originel. Chaque cellule est alors identifiable par un numéro de ligne et de colonne. Seule la seconde méthode est détaillé par la suite. Processus : 1 2 3 On utilise toujours un objet de type « custom_container » rattaché au « cutom_control » de l’écran. On créer alors un objet de type « splitter_custom » rattacher au « custom_container » définit précédemment. On peut alors soit définir des conténaires et y attacher les objets ALV, soit rattacher directement les objets ALV(Le parent étant alors le splitter_continer) Etape 1 : * Nom du custom control définit dans l’écran. data : cont_on_main type scrfname value 'ALV_1', * Définition du conténaire principal rattaché au custom control custom_container_parent type ref to cl_gui_custom_container, * Définition du contenair divisé en cellule custom_splitter type ref to cl_gui_splitter_container, * Définition des contenairs acceuillant les objets ALV. PAGE 87 / 94 Documentation sur L’ABAP List Viewer custom_container1 type ref to cl_gui_container, * Définition des objets ALV. grid1 type ref to cl_gui_alv_grid, grid2 type ref to cl_gui_alv_grid. Etape 2 : Cette partie du code peut être placé au sein du code PBO : If custom_container_parent is initial. * Création du contenair principal en relation avec le custom control * de l’écran. create object custom_container_parent exporting container_name = cont_on_main exceptions cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. * Premier container create object custom_splitter exporting * Nombre de lignes rows = 1 * Nombre de colones columns = 2 * Le parent est le contenair définit précedement parent = custom_container_parent . * Permet de rendre la barre de separation mobile. call method custom_splitter->set_border exporting border = gfw_false. VERSION 3.1 * Méthode 1 * Affectation du contenair 1 affecté à la grille 1. call method custom_splitter->get_container exporting row = 1 column = 1 receiving container = custom_container1. * create an instance of alv control create object grid1 exporting i_parent = custom_container1. * Méthode 2 create object grid2 exporting i_parent = custom_splitter. call method custom_splitter->add_control exporting row = 1 column = 2 control = grid2 . PAGE 88 / 94 Une fois que le contenair est crée.VIII Affichage d’un objet ALV sans utiliser de screen Painter VERSION 3.1 Pour se faire on utilise un container particulier qui permet de définir sa taille et ses caractéristiques d’affichage. *create docking container create object dock_container exporting repid = l_repid dynnr = l_dynnr * Définit le placement du container (droite. Le placement du container par rapport à l’écran est définit par le paramètre SIDE NOTA : Ce container offre la possibilité de pouvoir redimensionner à l’aide de la souris le container. * Déclaration Data : dock_container type ref to cl_gui_docking_container. Il suffit alors de définir le dock_container comme étant le « parent ». gauche. l_dynnr = sy-dynnr. haut etc…) side = cl_gui_docking_container=>dock_at_left exceptions cntl_error =1 cntl_system_error =2 create_error =3 lifetime_error =4 lifetime_dynpro_dynpro_link = 5. * Affectation de valeur g_repid = sy-repid. soit utiliser une autre contenair tel que le splitter_container. *set height and width call method dock_container->set_position exporting height = 150 width = 100 exceptions cntl_error =1 cntl_system_error = 2. l_dynnr like sy-dynnr.Documentation sur L’ABAP List Viewer E. * Ce code peut être mis dans un PBO. Data: l_repid like sy-repid. bas . Static Constant dock_at_left dock_at_top dock_at_bottom dock_at_right property_docking property_floating Type / Value Type I Value 1 Type I Value 2 Type I Value 4 Type I Value 8 Type I Value 470 Type I Value 480 Description / Use Left-hand edge of the screen Top edge of the screen Bottom edge of the screen Right-hand edge of the screen Docking property Floating property PAGE 89 / 94 . on peut alors soit l’utiliser pour afficher nos composant. Method Description LOAD_GUI_STATUS Charge un menu défini dans le menu painter SE41 constants: c_pname type program value 'CTMENU_BUILD'. call method p_menu->add_separator. ADD_FUNCTION CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING FCODE = 'AA' “code fonction TEXT = TEXT-150. * Dans la fonction handler p_menu = e_object call method p_menu->add_submenu exporting menu = l_submenu text = text-m01. Le menu contextuel est automatiquement appelé sauf dans les cas suivants : • SAP Picture Control • SAP Toolbar Control Où il faudra utiliser la fonction : CALL METHOD picture->display_context_menu exporting context_menu = context_menu exceptions error = 1. * Add functions call method l_submenu->add_function exporting fcode = c_fcode1 text = text-001.Documentation sur L’ABAP List Viewer VERSION 3. * Add new submenu create object l_submenu. Parameter context_menu Meaning Instance of the class CL_CTMENU for constructing and displaying a context menu ( see also: Context Menu). * Add separator call method l_submenu->add_separator. c_status_context type cua_status value 'CT_STATIC'. Adds a menu that you defined in the Menu Painter Adds a menu that you defined in the Menu Painter as a submenu ADD_SEPARATOR RESET HIDE FUNCTIONS Adds a separator DATA: LT_STD_FCODES TYPE UI_FUNCTIONS. * Add functions call method l_submenu->add_function exporting fcode = c_fcode3 text = text-003. * Fonction standard ALV Reset to initial value Hides a function PAGE 90 / 94 .IX Définir un menu contextuel : Bouton droit de la souris. L’objet ALV permet de définir un menu appeler par le bouton droit de la souris ou (SHIFT + F10). call method cl_ctmenu=>load_gui_status exporting program = c_pname status = c_status_context menu = p_menu. "American Airlines Adds a function : ADD_MENU ADD_SUBMENU Data l_submenu type ref to cl_ctmenu. Fonction définis relative au menu contextuel.1 E. HANDLE_CONTEXT_MENU FOR EVENT CONTEXT_MENU_REQUEST OF CL_GUI_ALV_GRID IMPORTING E_OBJECT. * Fonction standard ALV APPEND CL_GUI_ALV_GRID=>MC_FC_DELETE_FILTER TO LT_STD_FCODES. APPEND 'AA' TO LT_STD_FCODES. Shows a function DISABLE_FUNCTIONS ENABLE_FUNCTIONS Inactivates a function Activates a function Tout comme pour les autres événements. CALL METHOD E_OBJECT->SHOW_FUNCTIONS EXPORTING FCODES = LT_STD_FCODES.Documentation sur L’ABAP List Viewer VERSION 3. PRIVATE SECTION. PUBLIC SECTION. * Fonction perso. CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED. DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER. DATA: LT_STD_FCODES TYPE UI_FUNCTIONS. ********* * Predefine a local class for event handling to allow the * declaration of a reference variable before the class is defined. APPEND 'AA' TO LT_STD_FCODES. PAGE 91 / 94 . * Les LT_STD_FCODES et LT_OWN_FCODES permettent de regrouper * par groupes les fonctions (Voir implémentation). CALL METHOD E_OBJECT->HIDE_FUNCTIONS EXPORTING FCODES = LT_STD_FCODES. * Fonction perso. SHOW_FUNCTIONS DATA: LT_STD_FCODES TYPE UI_FUNCTIONS. * * Definition: * ~~~~~~~~~~~ CLASS LCL_EVENT_RECEIVER DEFINITION. Définition : INCLUDE <ICON>. Définition de la classe **************************************************************** * LOCAL CLASSES: Definition **************************************************************** *====================================================== ========= * class lcl_event_receiver: local class to * define and handle own functions. METHODS : HANDLE_USER_COMMAND FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID IMPORTING E_UCOMM. celle-ci peut aussi contenir d’autres méthodes.1 APPEND CL_GUI_ALV_GRID=>MC_FC_DELETE_FILTER TO LT_STD_FCODES. on utilise une classe locale. Documentation sur L’ABAP List Viewer LT_OWN_FCODES TYPE UI_FUNCTIONS. WHEN 'LH'.1 ENDCLASS. VERSION 3. PERFORM SELECT_TABLE_SFLIGHT USING 'UA' CHANGING GT_SFLIGHT. "handle_user_command *----------------------------------------------------------------* * § 2. CL_GUI_ALV_GRID=>MC_FC_COL_INVISIBLE TO LT_STD_FCODES. METHOD HANDLE_USER_COMMAND. * handle user commands of context menu WHEN 'AA'. PERFORM SELECT_TABLE_SFLIGHT USING 'AA' CHANGING GT_SFLIGHT. WHEN 'UA'. c_status_context type * Chargement d’un menu définit dans le menu painter call method cl_ctmenu=>load_gui_status exporting program = c_pname status = c_status_context menu = p_menu. ENDMETHOD. METHOD HANDLE_CONTEXT_MENU. APPEND 'AA' TO LT_OWN_FCODES. CALL METHOD GRID1->REFRESH_TABLE_DISPLAY. PAGE 92 / 94 . ENDCASE. constants: c_pname type program cua_status value 'CT_STATIC'.Use event handler method for event CONTEXT_MENU_REQUEST to define * your own context menu. * * lcl_event_receiver (Definition) *====================================================== ========= Implémentation : (Voir le programme BCALV_GRID_06) **************************************************************** * LOCAL CLASSES: Implementation **************************************************************** *====================================================== ========= * class lcl_event_receiver (Implementation) * CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. * On ajoute nos propres fonctions au groupe LT_OWN_FCODES. * § 5. CASE E_UCOMM.Implement event handler method for event USER_COMMAND: * Query the function code defined in event handler method for * event CONTEXT_MENU_REQUEST. CALL METHOD GRID1->REFRESH_TABLE_DISPLAY. DATA: LT_ROWS TYPE LVC_T_ROW. value 'CTMENU_BUILD'. * On ajoute les fonctions standards le groupe LT_STD_FCODES APPEND APPEND APPEND APPEND CL_GUI_ALV_GRID=>MC_FC_COL_OPTIMIZE TO LT_STD_FCODES. CALL METHOD GRID1->REFRESH_TABLE_DISPLAY. CL_GUI_ALV_GRID=>MC_FC_DELETE_FILTER TO LT_STD_FCODES. PERFORM SELECT_TABLE_SFLIGHT USING 'LH' CHANGING GT_SFLIGHT. CL_GUI_ALV_GRID=>MC_FC_HELP TO LT_STD_FCODES. 1 * On ajoute nos lignes de menus et les codes fonctions associés. * * lcl_event_receiver (Implementation) *====================================================== ============= Enfin il suffit alors de créer une instance de l’objet et de le rattacher à l’objet ALV. * * GRID est le nom de notre composant ALV. "Lufthansa CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING FCODE = 'UA' TEXT = TEXT-152. * La fonction SHOW permet d’afficher le groupe LT_OWN_FCODES CALL METHOD E_OBJECT->SHOW_FUNCTIONS EXPORTING FCODES = LT_OWN_FCODES. SET HANDLER EVENT_RECEIVER->HANDLE_USER_COMMAND FOR GRID1. "United Airlines * La fonction HIDE permet de ne pas afficher le groupe LT_STD_FCODES CALL METHOD E_OBJECT->HIDE_FUNCTIONS EXPORTING FCODES = LT_STD_FCODES. VERSION 3. ******** * ->Create Object to receive events and link them to handler methods. ENDCLASS. "American Airlines CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING FCODE = 'LH' TEXT = TEXT-151. * ******** PAGE 93 / 94 . ENDMETHOD. CREATE OBJECT EVENT_RECEIVER. * When the ALV Control raises the event for the specified instance * the corresponding method is automatically called. APPEND 'UA' TO LT_OWN_FCODES. SET HANDLER EVENT_RECEIVER->HANDLE_CONTEXT_MENU FOR GRID1. * Celle-ci seront récupérées dans le E_UCOMM dans l’événement user_command CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING * Code récupéré dans le E_UCOMM FCODE = 'AA' TEXT = TEXT-150.Documentation sur L’ABAP List Viewer APPEND 'LH' TO LT_OWN_FCODES. 1 TO DO : 1 2 3 Gestion du drag and Drop Listes hiérarchiques PAGE 94 / 94 .Documentation sur L’ABAP List Viewer VERSION 3.
Copyright © 2024 DOKUMEN.SITE Inc.