Escolar Documentos
Profissional Documentos
Cultura Documentos
VERSION 3.1
ALV
PAGE 1 / 94
VERSION 3.1
SOMMAIRE :
A Introduction :Comment devenir super fort pour faire des listes .......................................................................5 A.I Introduction...................................................................................................................................................5 A.II Fondements thoriques...............................................................................................................................5 B Ralisation technique ALV STANDARD:...........................................................................................................6 B.I Prsentation Gnrale :................................................................................................................................6 B.I.1 Schma gnral........................................................................................................................................6 B.I.2 Dfinition des diffrentes lments:.........................................................................................................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 vnements :....................................................................................................................7 B.I.2.e Catalogue : ........................................................................................................................................7 B.II Lcran le screen painter.........................................................................................................................8 B.III Le catalogue..............................................................................................................................................10 B.III.1 Dfinition.............................................................................................................................................10 B.III.2 Mthode automatique :........................................................................................................................10 B.III.3 Mthode manuelle...............................................................................................................................10 B.III.3.a Processus :.....................................................................................................................................10 B.III.3.b Exemple de cration du catalogue................................................................................................11 B.III.4 Mthode 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 quantits : (Voir doc SAP)........................................................................................13 B.IV Le container..............................................................................................................................................14 B.IV.1 Paramtres :.........................................................................................................................................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 zbr des lignes.............................................................................................................16 B.VI Gestion variantes......................................................................................................................................17 B.VII Les vnements.......................................................................................................................................19 B.VII.1 Dfinition :.........................................................................................................................................19 B.VII.2 Implmentation :................................................................................................................................20 B.VII.3 Utilisation :.........................................................................................................................................21 B.VIII La grille ou composant ALV................................................................................................................23 B.VIII.1 Dfinition :........................................................................................................................................23 B.VIII.2 Cration de lobjet :..........................................................................................................................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
VERSION 3.1
C Utilisation des fonctions ALV dfinies pas SAP...............................................................................................47 C.I Fonction Standart SAP pour une ALV rapide.........................................................................................47 C.I.1 Affichage dun ALV simple...................................................................................................................47 C.I.1.a Appel de base de la fonction REUSE_ALV_LIST_DISPLAY .....................................................47 C.I.1.b Dfinition de la fonction.................................................................................................................47 C.II Liste hirarchique ....................................................................................................................................49 C.II.1 Introduction : ........................................................................................................................................49 C.II.2 Cl de correpondance............................................................................................................................49 C.II.3 Layout...................................................................................................................................................49 C.II.3.a Gestion de lexpansion...................................................................................................................50 C.II.3.b Gestion des LED............................................................................................................................50 C.II.3.c Gestion des checkbox.....................................................................................................................50 C.II.3.d Affichage du dtail ........................................................................................................................50 C.II.3.e Autres possibilits..........................................................................................................................51 C.III Liste sous forme de grille........................................................................................................................52 C.IV Le catalogue..............................................................................................................................................53 C.IV.1 Dfinition du catalogue.......................................................................................................................53 C.IV.2 Dclaration :........................................................................................................................................53 C.IV.3 Zone en entre.....................................................................................................................................54 C.IV.4 EXAMPLE dimplmentation 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 Dfinition.............................................................................................................................................58 C.VI.2 Implmentation....................................................................................................................................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 vrifier)......................................................................58 C.VI.3.c Rcupration de la variante par dfaut.........................................................................................59 C.VII Table contenant les donnes..................................................................................................................60 C.VIII Les vnements......................................................................................................................................61 C.IX Commentaires : Entte de page..............................................................................................................63 C.X Gestion de plusieurs ALV sur un seul cran ..........................................................................................64 C.X.1 Initialisation..........................................................................................................................................64 C.X.2 Dfinition des blocs..............................................................................................................................65 C.X.2.a ALV classique :..............................................................................................................................65 C.X.2.b Alv Hirarchique :.........................................................................................................................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 lextrait............................................................................................................68 C.X.4.e Chargement de lextrait..................................................................................................................68 C.X.4.f Exemple..........................................................................................................................................68 D ANNEXES :........................................................................................................................................................71 D.I Utilisation de classe sous SAP....................................................................................................................72 D.I.1 Dclaration dune classe........................................................................................................................72 D.I.2 Exemple de dfinition de classe.............................................................................................................72 D.I.3 Implmentation dune classe..................................................................................................................73 E Annexe sur ALV standard..................................................................................................................................74 E.I Gestion des groupes de colonnes pour les variantes :..............................................................................74 E.II Ajout dun menu........................................................................................................................................75
PAGE 3 / 94
VERSION 3.1
E.III Output Options of Columns....................................................................................................................79 E.IV Formatting Column Contents ................................................................................................................81 E.V Properties of the Grid Control ................................................................................................................83 E.VI Events of Class CL_GUI_ALV_GRID ..................................................................................................85 E.VII Dcoupage de lcran afin dafficher plusieurs ALV..........................................................................87 E.VII.1 Dfinition de lcran de slection.......................................................................................................87 E.VIII Affichage dun objet ALV sans utiliser de screen Painter ...............................................................89 E.IX Dfinir un menu contextuel : Bouton droit de la souris.......................................................................90 TO DO :................................................................................................................................................................94
PAGE 4 / 94
VERSION 3.1
A.I Introduction Afin de gnrer des listes qui soient enfin attractives, interactives et amusantes, SAP a dvelopp un outil efficace : lAbap List Viewer. Il sagit, en vrit, dun objet de R/3 version.4.6, exploitable dans les dveloppements spcifiques, pour qui veut bien sarrimer aux exemples abscons dlivrs par la maison mre. Pour les profanes, lintgration de la programmation objet dans SAP, peut savrer fastidieuse. En effet, la gestion de mthodes, class, et autres public section, demande une tude approfondie et une implication coteuse en temps. Aussi, il convient de prsenter le rsultat de ces investigations en sorientant principalement vers loprationnel. Les esthtes de la programmation objet voudront bien pardonner au nophyte, les approximations et contre sens qui ne sauront manquer dmailler la prsentation.
A.II
Fondements thoriques.
Laffichage dune liste par ALV, se base sur lutilisation dun objet le CL_GUI_ALV_GRID. Il faut dfinir un catalogue qui rfrence et spcifie les caractristiques des cellules daffichage. Il sagit donc dune table interne de 60 champs, qui chacun dcrit un attribut de la cellule. Parmi ceux-ci, on trouvera le champ fieldname qui reprend le nom du champ de la table interne souhait dans la cellule. Les autres font varier des caractristiques daffichage tel que la position de la colonne, sa taille, la gestion en checkbox, etc.Cette table interne doit reprendre strictement le format de la table interne afficher, cela signifie que chaque champ doit tre retrouver en tant que valeur dans le champ fieldname de la table catalogue. Une table de lay-out, permettra de grer un certain nombre de caractristiques graphiques sur la structure dentte de colonne, comme empcher deffectuer des totaux sur la colonne (par rapport au fieldname), affichage de len-tte de colonne en hot-spot.. En ltat, il est ds lors possible dafficher la table souhaite lcran. pour peu que les rcepteurs adquats aient t installs dans lcran appel. En effet, un objet de type custom control devra avoir t install comme rceptacle de la liste dans lcran appel. Les fonctions standards de lALV telles que le tri, le filtre, lexport sous Excel, les Totaux, les Sous totaux, etc.. seront alors automatiquement gres. Dautres fonctionnalits peuvent alors tre implantes, dans un menu spcifique afin de grer une interaction. La mise en place de cette technique semble ncessiter des connaissances particulirement pousses de la programmation objet. Il nen est rien. Vaguement imprgn de ce qui prcde, il est possible deffectuer exactement le mme travail en utilisant astucieusement et uniquement des call function adquats.
PAGE 5 / 94
VERSION 3.1
B.I.1 Schma gnral La ralisation dun programme sous sap utilisant lALV comme outil de report est relativement simple, cependant un certain nombre dtapes sont indispensable. (Il existe au sein de SAP des fonctions standards permettant de raliser en trs peu dtape laffichage dune liste, cependant les possibilits de personnalisation (en particulier pour les vnements) sont alors plus rduites. Une de ces fonctions est dcrite en annexe.) Le schma suivant prsente limplmentation basique dun report sous ALV.
CONTAINER DE RECEPTION
Paramtre Paramtres :
GRILLE ALV
Objet attach :
EVENEMENT
B.I.2 Dfinition des diffrentes lments: B.I.2.A ECRAN SCREEN PAINTER Laffichage dun composant ALV demande en premier lieu, quun cran soit dfinit par lintermdiaire du screen painter (transaction se51). Au sein de ce dernier on insrera un objet custom contrle , lequel recevra par la suite la grille ALV et limitera la taille afficher. (Une mthode est prsente en annexe permettant dutiliser une grille ALV sans utiliser le SCREEN PAINTER) B.I.2.B CONTAINER Ce dernier est utilis pour accueillir le composant ALV, il doit faire rfrence un custom contrle dfinit dans un cran (Voir screen painter).
PAGE 6 / 94
VERSION 3.1
B.I.2.C GRILLE ALV Ce composant correspond la grille que lon souhaite afficher, il existe un nombre important de paramtres disponibles afin de modifier son comportement. Les trois principaux paramtres fournir sont : 1. Variante. 2. Layout. 3. Catalogue B.I.2.D CLASSE DES VNEMENTS : Celle-ci contient lensemble des fonctions dfinis par lutilisateur et le comportement associ : double clic, bouton, slection
B.I.2.E CATALOGUE : Ce dernier correspond une table interne et dfinit entirement les informations relatives laffichage des champs dans lALV.
PAGE 7 / 94
VERSION 3.1
B.II
Afin de crer un cran contenant un objet custom contrle , il faut appeler la transaction
SE51.
Au sein de cette dernire on dfinit le nom du programme gnrant les donnes ainsi que le numro de lcran qui sera appel. Et ensuite appuyer sur le bouton CREER.
Une fois lcran crer, il faut alors le modifier selon notre objectif :
PAGE 8 / 94
VERSION 3.1
Slection le bouton (custom controle) puis le placer sur la partie de gauche tout en le dimensionnant enfin il faut lui dfinir un nom.
Custom contrle
Nom de lobjet
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 . Afin de pouvoir utiliser un ok_code, il est indispensable de le dfinir dans la liste des lments : (variable de type OK) et dans le programme appelant lALV avec le mme nom. IL suffit alors dactiver.
PAGE 9 / 94
VERSION 3.1
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.III.1 Dfinition
Lors de la cration du composant ALV, un ensemble de paramtres sont fournit tels le catalogue. Celui-ci est une table de type LVC_T_FCAT qui contient toutes les informations sur les champs afficher :
B.III.3.A PROCESSUS :
1. Dclaration de la table interne : Data : GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE.
2. Ajout des champs 1 1. Lors de lajout dun champ dans le catalogue, on peut soit, lorsque cela est possible faire rfrence un champ dune table du dictionnaire soit dfinir entirement les caractristiques du champ.
Rfrence :
REF_FIELD REF_TABLE Correspond au nom du champ de rfrence. Ex NAME1 Correspond la table de rfrence. Ex KNA1
PAGE 10 / 94
VERSION 3.1
Spcifique:
TEXTE Dfinition du champ : DATATYPE ou INTTYPE COLTEXT TOOLTIP SELTEXT DATATYPE INTTYPE OUTPUTLEN Intitul de la colonne Intitul de la bulle daide Intitul du texte Type de donne : DEC, CHAR Type de donne lmentaire C, I Largeur de la colonne
Il peut tre utile dans le cas de champs spcifique dutiliser des routines de conversion dentresortie. On utilise alors le champ
EDIT_MASK
If you set a conversion exit (for example, conv = ' ==ALPHA ' for function module CONVERSION_EXIT_ALPHA_OUTPUT ), you enforce output conversion for the associated output field. (See also F1 help for WRITE edit option USING EDIT MASK) .
Commun :
Nom du champ
FIELDNAME KEY COL_POS
Dsignation
Rfrence la table interne contenant les donnes Cl (si la valeur X est fourni alors la colonne sera affiche gauche de lALV et sera fige par rapport aux dplacements horizontaux) Position de la colonne.
PAGE 11 / 94
VERSION 3.1
Si on gnre le catalogue de faon semi-automatique, on peut utiliser des champs issus du dictionnaire mais aussi spcifiques. Il est alors aussi possible de modifier ou dajouter des champs. Par exemple si on souhaite afficher une structure du dictionnaire sans pour autant afficher toutes les colonnes, on peut alors soit utiliser le champ NO_OUT dans la structure du catalogue, soit effacer lenregistrement. (voir LVC_T_FCAT)
B.III.4.A PROCESSUS :
1. 2. Dclarer une table interne du type LVC_T_FCAT . Data : GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE. Appeler la fonction LVC_FIELDCATALOG_MERGE et donner en argument la structure de la table contenant les donnes afficher la table interne correspondant au catalogue
Exemple de valeur
= = = = = 'ECART'. '12'. 'ECART.'(100). 'ECART.'(101). 'ECART.'(102).
Dsignation Nom du champ Position de la colonne dans lALV Intitul de la colonne Intitul de la Bulle daide Intitul de la colonne lors dun passage de la souris Type de donne (Pour les donnes de base on utilise le champ INTTYPE) Taille de la colonne en sortie
= 'DEC'.
= 13.
4. Il est alors possible de lire la table et de modifier les diffrents paramtres. Il nest par contre pas possible de modifier les intituls des colonnes gnres automatiquement partir du dictionnaire.
B.III.5 Exemple
* On initialise le catalogue. clear gt_fieldcat. refresh gt_fieldcat. * Appel de la fonction afin de gnrer un catalogue * a partir de la table ZINV dfinit dans le dictionnaire CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'ZINV' CHANGING CT_FIELDCAT = gt_fieldcat[]. * Exemple de suppression delete gt_fieldcat where fieldname = 'UZEIT'. * Exemple de modification
PAGE 12 / 94
VERSION 3.1
B.III.6 Catalogue Quantit et currency B.III.6.A GESTION DES DEVISES : (VOIR DOC SAP)
Dans le cas, o lon affiche des valeurs ncessitant un formatage selon une devise, on peut : o o Soit utiliser le champ CURRENCY pour une devise fixe pour toute la colonne. Soit CFIELDNAME faisant rfrence un autre champ (de type devise telles que DEM ou USD) du Catalogue.
PAGE 13 / 94
VERSION 3.1
B.IV
Le container
Le container est lobjet qui doit contenir le composant ALV. Celui-ci fait appel un container cre au pralable dans un screen. La dclaration du container se fait de prfrence au dbut du programme.
Dans notre exemple BCALVC_TOOLBAR_D100_C1 correspond au nom de lobjet custom controle dans lcran de slection.
B.IV.1 Paramtres :
cont_on_main doit contenir le nom du custom contrle * Dclaration du container DATA custom_container1 TYPE REF TO cl_gui_custom_container, * Nom du Container de rfrence = 'BCALVC_TOOLBAR_D100_C1' cont_on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C1'
.
*Dans le PBO !
PAGE 14 / 94
VERSION 3.1
B.V
Gestion du layout
La structure du layout contient un ensemble de champs permettant de configurer les proprits graphiques de la grille ALV. Cette structure est de type : LVC_S_LAYO.
Dsignation Dfini le titre Slection de multi-ligne Ajuste la taille des colonnes selon le contenu. Permet de ne pas afficher la barre des boutons
If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If the character field begins with 'C' (color code), 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, see the F1 help on the FORMAT statement.
PAGE 15 / 94
VERSION 3.1
La table de type LVC_T_SCOL des couleurs contient 3 champs FNAME COLOR NOKEYCOL Contrle ALV : nom de zone de table interne Contrle arbre ALV : codage couleur Contrle 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 dfinit dans lALV (Voir le catalogue). Si on veut colorer la ligne, il suffit de dfinir la couleur souhaite dans le champ COLOR et ne pas affecter le champs FNAME. Si on veut affecter plusieurs cellule il faut mettre le nom de la colonne dans le champs FNAME. Si on souhaite colorer plusieurs cellule, 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.2.D AFFICHAGE ZBR DES LIGNES
Dans la structure layout : ZEBRA If this field is set, the list shows a striped pattern in the print preview and when it is printed. SPACE, 'X'
PAGE 16 / 94
VERSION 3.1
B.VI
Gestion variantes
LALV offre la possibilit de grer lutilisation de variantes dfinissant les colonnes affiches et autres aspects graphiques. Cependant il incombe au dveloppeur de grer les proprits que peuvent prendre les variantes. Pour ce faire, ce dernier dispose de 3 paramtres :
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. I_SAVE = SPACE. (default setting)
The ALV grid control displays only the variant icon ( ) but no menu in the toolbar. By clicking this icon, users can change the current display variant (basically, they can modify the selection and the order of the columns displayed). The ALV grid control displays both the variant icon and a menu in the toolbar. The menu contains only functions for selecting and changing display variants.
IS_VARIANT = <variant structure> I_SAVE = SPACE . (or IS_VARIANT is SPACE and I_SAVE is not SPACE ) IS_VARIANT = <variant structure> I_SAVE = <'X', 'U' or 'A'> See also: Saving Display Variants
The ALV grid control displays both the variant icon and a menu in the toolbar. By clicking this icon, users can select an existing display variant. The menu provides functions for selecting, changing, saving and managing display variants.
Par dfaut lutilisateur peut saisir des variantes, ces dernires ne sont pas rappeles lors des utilisations futures. Par contre, si lutilisateur ne doit pas avoir accs lutilisation de variantes, il suffit de dfinir la valeur SPACE pour I_DEFAULT . Les possibilits offertes pour la gestion des variantes sont importantes et sont dfinis par lintermdiaire de paramtres. Le premier paramtre utiliser est de type DISVARIANT. Data :GS_VARIANT TYPE DISVARIANT. ce dernier doit contenir au minimum lID du programme dans le champ REPORT: G_REPID = SY-REPID. GS_VARIANT-REPORT = G_REPID.
PAGE 17 / 94
VERSION 3.1
* 'gs_variant' must at least contain the report-id to allow * saving a variant. g_repid = sy-repid. * 2.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid.
NOTA : Afin de grer les variantes selon les dynpros, il est utile de dfinir le champ HANDLE STRUCTURE DISVARIANT REPORT HANDLE LOG_GROUP USERNAME VARIANT TEXT DEPENDVARS Nom du programme ABAP ID de gestion pour appel rpt depuis le mme programme Cl de groupe logique Nom utilisateur pour mmorisation personnalise Variante d'affichage Dsignation variante affichage Vecteur entres de var. dpendantes
PAGE 18 / 94
VERSION 3.1
B.VII
Les vnements
Outres la simplification de la gestion de laffichage, lutilisation de LALV offre aussi la possibilit de grer un ensemble dvnements.
B.VII.1
Dfinition :
La premire tape consiste crer une classe permettant de dfinir ses propres fonctions (METHOD) : NOTA : Si la classe nest pas dfinit au tout dbut du programme, toute rfrence la classe ne pourra tre faites quaprs. Pour palier ce problme 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. CLASS lcl_event_receiver DEFINITION DEFERRED.
Exemple de dfinition :
**************************************************************** * LOCAL CLASSES: Definition **************************************************************** *====================================================== ========= * class lcl_event_receiver: local class to * define and handle own functions. * * Definition: * ~~~~~~~~~~~ class lcl_event_receiver definition. public section. methods: handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive , handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm, handle_double_click for event double_click of cl_gui_alv_grid importing e_row e_column. data : poste type c value 'P'. private section. endclass. * * lcl_event_receiver (Definition) *====================================================== =========
-> nom de la fonction -> Nom de lvnement (voir annexe) -> Paramtres rcuprs (voir dfinition de lvnement)
PAGE 19 / 94
VERSION 3.1
B.VII.2 Implmentation : Une fois les fonctions dfinis, il convient alors de procder leur implmentation (juste en dessous de la dfinition) :
**************************************************************** * LOCAL CLASSES: Implementation **************************************************************** *====================================================== ========= * class lcl_event_receiver (Implementation) * * class lcl_event_receiver implementation. method handle_toolbar. * 2.In event handler method for event TOOLBAR: Append own functions * by using event parameter E_OBJECT. data: ls_toolbar type stb_button. *.................................................................... * E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET. * This class has got one attribute, namly MT_TOOLBAR, which * is a table of type TTB_BUTTON. One line of this table is * defined by the Structure STB_BUTTON (see data deklaration above). * * A remark to the flag E_INTERACTIVE: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 'e_interactive' is set, if this event is raised due to * the call of 'set_toolbar_interactive' by the user. * You can distinguish this way if the event was raised * by yourself or by ALV * (e.g. in method 'refresh_table_display'). * An application of this feature is still unknown... :-) * append a separator to normal toolbar clear ls_toolbar. move 3 to ls_toolbar-butn_type. append ls_toolbar to e_object->mt_toolbar. * append an icon to show post table clear ls_toolbar. move 'POSTES' to ls_toolbar-function. * MOVE icon_employee TO ls_toolbar-icon. move icon_detail to ls_toolbar-icon. move ' Voir les postes'(111) to ls_toolbar-quickinfo. move ' Vue poste'(112) to ls_toolbar-text. move ' ' to ls_toolbar-disabled. append ls_toolbar to e_object->mt_toolbar. endmethod. *------------------------------------------------------------------method handle_double_click. data: ls_poste like line of t_poste, ls_entete like line of t_entete, p_vbeln like vbrp-vbeln. * 4.The event DOUBLE_CLICK provides parameters for row and column * of the click. Use row parameter to select a line of the * corresponding internal table. if poste eq 'P'. * read selected row from internal table gt_sflight read table t_poste index e_row-index into ls_poste. p_vbeln = ls_poste-vbeln. else.
PAGE 20 / 94
VERSION 3.1
*------------------------------------------------------------------method handle_user_command. * 3.In event handler method for event USER_COMMAND: Query your * function codes defined in step 2 and react accordingly. data: lt_rows type lvc_t_row. case e_ucomm. when 'POSTES'. call method grid1->get_selected_rows importing et_index_rows = lt_rows. call method cl_gui_cfw=>flush. if sy-subrc ne 0. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). else. perform show_poste_table tables lt_rows. endif. when 'FACTURE'. leave to screen 0. endcase. endmethod. "handle_user_command *----------------------------------------------------------------endclass. * * lcl_event_receiver (Implementation) *====================================================== =============
B.VII.3
Utilisation :
Enfin, lorsque la classe dfinissant les vnements est dfinie et implmente, alors il faut crer une instance de lobjet et connecter nos propres au composant ALV.
Data : event_receiver type ref to lcl_event_receiver, * * * * * ->Create Object to receive events and link them to handler methods. When the ALV Control raises the event for the specified instance the corresponding method is automatically called. Cration de linstance create object event_receiver.
PAGE 21 / 94
VERSION 3.1
->
nom de la fonction
for
objet ALV
PAGE 22 / 94
VERSION 3.1
B.VIII
Le composant ALV est celui qui permet laffichage de la grille, cest ce dernier qui utilisera lensemble des objets prcdemment dfinis. Nous ne prsenterons pas par la suite lensemble des fonctions et proprits disponibles (voir annexe).
B.VIII.1
B.VIII.2
Cration de lobjet :
Ltape suivante consiste crer une instance de lobjet grid1. La fonction Create objet prend pour argument Le nom de lobjet (le composant ALV prcdemment dclar) Et le nom du container devant rceptionner 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.VIII.3
PAGE 23 / 94
VERSION 3.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 appele. 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. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be ATTACHED'(510). endif.
= = = = = = = = = = = =
< < < < < < < < < < < <
string of type DD02L-TABNAME> structure of type DISVARIANT> var. of type CHAR01> var. 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
VERSION 3.1
Type CATALOGUE
VARIANTE
I_DEFAULT IT_SPECIAL_GROUPS
Dsignation Nom de la structure du catalogue si elle appartient au dictionnaire ex : SFLIGHT Nom de la variante Autres paramtres propre la gestion des variantes Autes paramtres propre la gestion des variantes Permet de dfinir des groupes de colonnes (voir annexe) Nom du layout Structure dfinissant les paramtres dimpression de lALV. Nom de la table interne Nom du catalogue si spcifique Table interne contenant les informations de tri Table interne contenant les informations de filtres.
LAYOUT IMPRESSION
CHANGING
IT_FILTER
IS_PRINT reoit une structure de type LVC_S_PRN Champs PRINT Type CHAR Dsignation Contrle ALV : dition par impression Contrle ALV : nbre de lignes rserves pour END_OF_PAGE Ctrl ALV : format changement grpe dfinissable par utilis. Contrle ALV : ne pas activer les informations de liste Contrle ALV : ne pas activer informations de slection
PAGE 25 / 94
VERSION 3.1
LVC_T_SORT.
Type NUMC 2
CHAR 30 Contrle ALV : nom de zone de table interne CHAR 1 CHAR 1 CHAR 2 CHAR 1 CHAR 1 CHAR 1 Code 1 caractre Code 1 caractre Chgmt gpe : insrer chgmt page et traits soulignement Editer total intermdiaire Code 1 caractre Code 1 caractre
PAGE 26 / 94
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
Dsignation Cntrl ALV : nom table de rfrence pour zone table interne
30 Cntrl ALV : nom table de rfrence pour zone table interne 30 Ctrl ALV : nom zone de rfrence pour zone table interne 30 Cntrl ALV : nom table de rfrence pour zone table interne 30 Contrle ALV : nom de zone de table interne 30 Nom de table LVC 5 1 Table R/2 Code 1 caractre
40 Contrle ALV : identificateur de colonne pour fct. 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 caractre Composante du n de version Domaine dfini imprcisment, Code 1 caractre Contrle ALV : longueur d'dition en nbre de caractres Nombre de dcimales
PAGE 27 / 94
VERSION 3.1
60 Contrle ALV : EditMask pour dition 1 1 4 1 1 1 2 Minuscules autorises/non autorises Type donnes ABAP (C,D,N,...) Type de donnes dans dictionnaire ABAP Code 1 caractre Contrle ALV : occulter les signes +/- lors dition Code 1 caractre Squence
*** DEFINITION de la grille ALV appele. 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. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be ATTACHED'(510). endif.
B.VIII.4
La fonction refresh_table_display
call method grid1->refresh_table_display.
B.VIII.5
La fonction set_focus
Cette mthode permet de slectionner lobjet actif dans lcran, dans lexemple qui suit on choisit grid1.
PAGE 28 / 94
VERSION 3.1
call method cl_gui_control=>set_focus exporting control = grid1. if sy-subrc ne 0. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be in focus'(510). endif.
B.VIII.6
Exemple :
INCLUDE <icon>. TYPE-POOLS: SLIS. DATA: ok_code LIKE sy-ucomm, g_repid LIKE sy-repid, gs_layout TYPE lvc_s_layo, * Nom du contenair principal cont_on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C1' * Utilisation de Variantes. gs_variant TYPE disvariant, "for parameter IS_VARIANT x_save value 'A', grid1 TYPE REF TO cl_gui_alv_grid, custom_container1 TYPE REF TO cl_gui_custom_container, event_receiver TYPE REF TO lcl_event_receiver, * Definition des catalogues utiliss. GT_FIELD_CAT_ENTETE type LVC_T_FCAT with header line. ... ... ... IF custom_container1 is initial. * Dfinition du catalogue ***************************************************************** DATA: POS TYPE I VALUE 1. clear GT_field_cat_entete. GT_field_cat_entete-COL_POS = POS. GT_field_cat_entete-FIELDNAME = 'KUNAG'. GT_field_cat_entete-tabname = 't_entete'. GT_field_cat_entete-ref_field = 'KUNAG'. GT_field_cat_entete-REF_TABLE = 'VBRK'. GT_field_cat_entete-KEY = 'X'. append GT_field_cat_entete. * Fin de la definition du catalogue. ***************************************************************** CLEAR gs_variant. * 'gs_variant' must at least contain the report-id to allow * saving a variant. g_repid = sy-repid. * 2.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid.
PAGE 29 / 94
VERSION 3.1
CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid1. IF sy-subrc ne 0. * add your handling, for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be in focus'(510). ENDIF.
PAGE 30 / 94
VERSION 3.1
B.IX
Afin de pouvoir grer des ALV avec diffrents niveaux, il est prfrable dutiliser plusieurs cran, gnrer partir du screen painter et de crer dans chacun un CUSTOM CONTROLE. La cration et laffichage des objets ALV sont alors grs au sein des PBO et PAI. (Voir exemple fournit la fin) Il est aussi possible de dutiliser dautres containers, lesquelles permettent de grer plusieurs composants ALV..
PAGE 31 / 94
VERSION 3.1
B.X
Voici un schma global fournit par SAP reprenant lensemble des tapes et composants :
NOTA : Nous invitons le lecteur consulter les programmes de la classe de dveloppement SLIS.
B.X.2 EXEMPLES
Exemple de programme simple avec un seul ALV :
program bcalvc_variants_exe. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&& * Purpose: * ~~~~~~~~
PAGE 32 / 94
VERSION 3.1
* This example illustrates how a variant can be chosen before * the generation of the list. * * Relevant function modules are: * - LVC_VARIANT_DEFAULT_GET * -> Get the default variant * - LVC_VARIANT_EXISTENCE_CHECK * -> Test if a variant exist. Useful at event AT SELECTION-SCREEN * - LVC_VARIANT_F4 * -> F4 help pops up to select a variant * - 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. * Chose one as a default variant and return to the selection screen. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&& data: ok_code like sy-ucomm, gt_sflight type table of sflight, g_repid like sy-repid, mycontainer type scrfname value 'BCALV_VARIANTS_0100_C1', * reference to custom container: neccessary to bind ALV Control custom_container type ref to cl_gui_custom_container, grid1 type ref to cl_gui_alv_grid. *......................................................... * '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. * When provided as parameter for 'set_grid_for_first_display', * it must contain at least the report-id. * data: x_save, "for parameter I_SAVE: modus for saving variants default, "has to be set if the chosen variant is a default variant x_variant type disvariant, g_exit type c. "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. * 'gs_variant' finally holds the chosen variant. data: def_variant type disvariant, "default variant spec_variant type disvariant, "specific variant gs_variant type disvariant. "finally chosen variant *DATA: got_default. "marks that the default variant has been loaded *........................................................... ****************************************************** * Define a selection screen * to choose an already saved variant ****************************************************** selection-screen begin of block vari with frame title text-002. parameters: p_no_v radiobutton group exec default 'X', p_def_v radiobutton group exec, p_spec_v radiobutton group exec, p_vari like disvariant-variant. selection-screen end of block vari. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ initialization. g_repid = sy-repid. x_save = 'A'. "The user may save all types of variants
PAGE 33 / 94
VERSION 3.1
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ at selection-screen output. * The default variant is fetched the first time the PBO of the * selection screen is called. * If a default variant exist, its identification * is saved in 'def_variant'. * if default = ' '. clear def_variant. move g_repid to def_variant-report. call function 'LVC_VARIANT_DEFAULT_GET' exporting i_save = x_save changing cs_variant = def_variant exceptions not_found = 2. if sy-subrc = 2. p_no_v = 'X'. p_def_v = ' '. p_spec_v = ' '. perform deactivate_def_v. exit. else. * set name of variant on selection screen p_vari = def_variant-variant. default = 'X'. endif. endif. "default IS INITIAL *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ at selection-screen on value-request for p_vari. * popup F4 help to select a variant clear x_variant. move g_repid to x_variant-report. 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. if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. else. if g_exit ne 'X'. * set name of variant on selection screen p_vari = spec_variant-variant. endif. endif. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ at selection-screen. * test if specified variant exist if p_spec_v = 'X'. clear spec_variant. move p_vari to spec_variant-variant. move g_repid to spec_variant-report.
PAGE 34 / 94
VERSION 3.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. if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. endif. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ start-of-selection. select * from sflight into table gt_sflight. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ end-of-selection. * set gs_variant according to the selection made clear gs_variant. * execute without variant if p_no_v = 'X'. gs_variant-report = g_repid. * execute with default variant elseif p_def_v = 'X'. move-corresponding def_variant to gs_variant. * execute with specified variant elseif p_spec_v = 'X'. move-corresponding spec_variant to gs_variant. else. call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = space txt1 = 'Fatal error: No radio button active!'(550). leave program. endif. call screen 100. *---------------------------------------------------------------------* * MODULE PBO OUTPUT * *---------------------------------------------------------------------* module pbo output. set pf-status 'MAIN100'. if custom_container is initial. * 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
VERSION 3.1
Exemple de programme avec deux ALV : LE programme qui suit est prsent juste comme illustration, la majeure partie du code non relatif limplmentation de lALV a t supprime.
PAGE 36 / 94
VERSION 3.1
report zrsd0007 message-id zs no standard page heading line-size 132 line-count 65. ***ALV*** include <icon>. type-pools: slis. *----------------------------------------------------------------------* * TABLES * *----------------------------------------------------------------------* tables " Base clients (partie gnrale) . . . *----------------------------------------------------------------------* * TABLES INTERNES * *----------------------------------------------------------------------* ** Tables contenants tous les entetes (vbrk) types : begin of ty_entete , zzhiez(10) type c , kunag like vbrk-kunag, name1 like kna1-name1, vbeln like vbrk-vbeln, fkart like vbrk-fkart, konda like vbrk-konda, netwr like vbrk-netwr, fkdat like vbrk-fkdat, buchk like vbuk-buchk, zztext(20) type c, zztext5(30) type c, vkorg like vbrk-vkorg, vtweg like vbrk-vtweg, spart like vbrk-spart, end of ty_entete. * Definition de structure data : st_entete type ty_entete , st_poste type ty_poste . ************** ** ENTETE data : begin of t_entete occurs 0. include structure st_entete. data : end of t_entete. *************** ********ALV * Predefine a local class for event handling to allow the * declaration of a reference variable before the class is defined. class lcl_event_receiver definition deferred. * ********* data: ok_code like sy-ucomm, g_repid like sy-repid, gs_layout type lvc_s_layo, : kna1,
PAGE 37 / 94
VERSION 3.1
**************************************************************** * LOCAL CLASSES: Definition **************************************************************** *====================================================== ========= * class lcl_event_receiver: local class to * define and handle own functions. * * Definition: * ~~~~~~~~~~~ class lcl_event_receiver definition. public section. methods: handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive , handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm, handle_double_click for event double_click of cl_gui_alv_grid importing e_row e_column. private section. endclass. * * lcl_event_receiver (Definition) *====================================================== ========= **************************************************************** * LOCAL CLASSES: Implementation **************************************************************** *====================================================== ========= * class lcl_event_receiver (Implementation) *
PAGE 38 / 94
VERSION 3.1
*------------------------------------------------------------------method handle_user_command. * 3.In event handler method for event USER_COMMAND: Query your * function codes defined in step 2 and react accordingly. data: lt_rows type lvc_t_row.
PAGE 39 / 94
VERSION 3.1
case e_ucomm. when 'POSTES'. call method grid1->get_selected_rows importing et_index_rows = lt_rows. call method cl_gui_cfw=>flush. if sy-subrc ne 0. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). else. perform show_poste_table tables lt_rows. endif. when 'FACTURE'. leave to screen 0. endcase. endmethod. "handle_user_command *----------------------------------------------------------------endclass. * * lcl_event_receiver (Implementation) *====================================================== ============= *----------------------------------------------------------------------* * ECRAN DE SELECTION *----------------------------------------------------------------------* *----------------------------------------------------------------------* * INITIALIZATION * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * AT SELECTION-SCREEN *----------------------------------------------------------------------* *----------------------------------------------------------------------* * START OF SELECTION *----------------------------------------------------------------------* start-of-selection. ** Controle sur les slections faites ** Recupration des donnes perform f_facture. end-of-selection. *---------------------------------------------------------------------* * CREATION ALV * *---------------------------------------------------------------------* perform init_catalogue. call screen '100'. ********************************************************* * f_facture * t_entete ******************************************************** *
PAGE 40 / 94
VERSION 3.1
PAGE 41 / 94
VERSION 3.1
PAGE 42 / 94
VERSION 3.1
*&---------------------------------------------------------------------* *& Module PBO_0101 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module pbo_0101 output. set pf-status 'MAIN101'. if custom_container2 is initial. * 'gs_variant' must at least contain the report-id to allow * saving a variant. g_repid = sy-repid. * 2.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid. gs_variant-handle = '0101'. * (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. if sy-subrc ne 0. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(510). endif. * create an instance of alv control create object grid2
PAGE 43 / 94
VERSION 3.1
*&---------------------------------------------------------------------* *& Module PAI_0101 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module pai_0101 input.
PAGE 44 / 94
VERSION 3.1
*---------------------------------------------------------------------* * FORM init_catalogue * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* form init_catalogue. data: pos type i value 1. * DATA: LS_FIELDCAT type LVC_S_FCAT. * Dfinition du catalogue pour les entetes. * On affiche la hirarchie que dans le cas ou on l'utilise.
PAGE 45 / 94
VERSION 3.1
clear gt_field_cat_entete. gt_field_cat_entete-col_pos = pos. gt_field_cat_entete-fieldname = 'KUNAG'. gt_field_cat_entete-tabname = 't_entete'. gt_field_cat_entete-ref_field = 'KUNAG'. gt_field_cat_entete-ref_table = 'VBRK'. gt_field_cat_entete-key = 'X'. append gt_field_cat_entete. clear gt_field_cat_entete. pos = pos + 1. gt_field_cat_entete-col_pos = pos. gt_field_cat_entete-fieldname = 'ZZTEXT5'. gt_field_cat_entete-tabname = 't_entete'. gt_field_cat_entete-inttype = 'C'. gt_field_cat_entete-outputlen = '30'. gt_field_cat_entete-coltext = 'Motif de non comptabilisation'. gt_field_cat_entete-seltext = 'Motif de non comptabilisation'. append gt_field_cat_entete. clear gt_field_cat_entete. pos = pos + 1. gt_field_cat_poste-col_pos = pos. gt_field_cat_poste-fieldname = 'Z_FKIMG'. gt_field_cat_poste-tabname = 't_poste'. gt_field_cat_poste-coltext = 'QTE en UR'. gt_field_cat_poste-seltext = 'Quantit factur en unit de rfrence'. gt_field_cat_poste-datatype = 'QUAN'. append gt_field_cat_poste. clear gt_field_cat_poste. endform.
PAGE 46 / 94
VERSION 3.1
Sap met la disposition du dveloppeur un ensemble de fonction permettant laffichage dun ALV de faon trs rapide. Ces fonctions sont trs pratiques mais ne couvrent pas ltendue des possibilits offertes par une implmentations manuelles des composants ALV. NOTE : Dautres fonctions existe et peuvent tre trouv au sein du groupe de fonction SLIS (Transaction SE80)
PAGE 47 / 94
VERSION 3.1
PAGE 48 / 94
VERSION 3.1
C.II
Liste hirarchique
C.II.1 Introduction :
Laffichage de liste hirarchique est une opration qui peut savrer utile pour certains reports, en effet laffichage est alors beaucoup plus mallable et permet une meilleur gestion de linformation. Afin dafficher correctement les informations il est indispensable de comprendre la mthode de gestion entre les enttes et les items.
C.II.2 Cl de correpondance
Afin de pouvoir afficher les informations correctement on utilise une structure permettant de mettre en relation jusqu 6 cls deux tables.
Data gs_keyinfo type slis_keyinfo_alv.
Lexemple suivant fait le lien entre la table des enttes dfinis par les compagnies arienes (SPFLI) et la table des vols (SCARR) :
* define keyinfo clear gs_keyinfo. gs_keyinfo-header01 = 'CARRID'. gs_keyinfo-item01 = 'CARRID'. gs_keyinfo-header02 = space. gs_keyinfo-item02 = 'CONNID'.
C.II.3 Layout
Le layout est la structure par laquelle on dfinit les proprits graphiques de laffichage.
Data gs_layout type slis_layout_alv.
PAGE 49 / 94
VERSION 3.1
* Nom du champ dans la table des enttes * ce champs contient soit X soit space. e05_ls_layout-expand_fieldname = 'EXPAND'.
PAGE 50 / 94
VERSION 3.1
PAGE 51 / 94
VERSION 3.1
C.III
Le programme BCALV_FULLSCREEN_DEMO Cette fonction permet dafficher une liste sous la forme dune grille ALV.
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.
PAGE 52 / 94
VERSION 3.1
C.IV
Le catalogue
C.IV.2 Dclaration :
data: ls_fieldcat type slis_fieldcat_alv.
Le tableau ci-dessous reprend la liste des champs disponible dans la structure SLIS_T_FIELDCAT_ALV Ces derniers sont relativement similaires de ceux utiliss avec les composants ALV. On peut alors soit implmenter le catalogue de faon manuelle, ou utiliser des fonctions spcifiques :
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[].
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
Dfinition 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
Field with currency unit and table Field with quantity unit and table
" decimals in write statement exponent for floats column with key-color As icon As symbol As checkbox (R)ight (L)eft (C)ent. leading zero Write no-sign Write no-zero
PAGE 53 / 94
VERSION 3.1
Field not obligatory Do not sum up Group specification selection for rep/rep Input Hotspot
. . .
form fieldcat_init using rt_fieldcat type slis_t_fieldcat_alv. data: ls_fieldcat type slis_fieldcat_alv. data: pos type i value 1. clear ls_fieldcat. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'VBELN'. ls_fieldcat-ref_fieldname = 'VBELN'. ls_fieldcat-ref_tabname = 'VBAK'. ls_fieldcat-key = 'X'. append ls_fieldcat to rt_fieldcat. clear ls_fieldcat.
PAGE 54 / 94
VERSION 3.1
PAGE 55 / 94
VERSION 3.1
C.V
Le menu utilisateur est dfinit laide de la transaction SE41, on peut retrouver ci-dessous un exemple de fonctions standards implmentes. Il est important de dfinir manuellement chacune des options.
Ensuite, il faut alors dfinir au sein du programme le menu utilisateur choisit avant lappel de la fonction ALV.
set pf-status 'STANDARD001'.
Enfin, il suffit alors de renseigner le paramtre adquate de la fonction, savoir I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET' La valeur du texte (PF_STATUS_SET) ne semble pas avoir de relle valeur. Dans le cas ou aucun menu ne serait fournit alors cest le menu par dfaut qui est repris :
PAGE 56 / 94
VERSION 3.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'. case if_fcode. when 'WAHL'. "menubutton read table gt_outtab index cs_selfield-tabindex. "cursorposit. set parameter id 'CAR' field gt_outtab-carrid. set parameter id 'CON' field gt_outtab-connid. call transaction l_ta and skip first screen. "# EC* clear r_ucomm. when '&IC1'. "dobbleclick read table gt_outtab into gt_outtab index rs_selfield-tabindex. set parameter id 'CAR' field gt_outtab-carrid. set parameter id 'CON' field gt_outtab-connid. call transaction l_ta and skip first screen. "# EC* clear r_ucomm. endcase. endform
Exemple issu dun dboguage de la transaction VL10D sur la fonction FCODE_BEARBEITEN. 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
VERSION 3.1
C.VI
C.VI.1 Dfinition
* Dclaration data : gs_variant type disvariant, "for parameter IS_VARIANT
C.VI.2 Implmentation
* Implmentation clear gs_variant. * 'gs_variant' must at least contain the report-id to allow * saving a variant. data: g_repid like sy-repid. g_repid = sy-repid. * 2.At least field REPORT of this structure has to be filled! gs_variant-report = g_repid.
PAGE 58 / 94
VERSION 3.1
PAGE 59 / 94
VERSION 3.1
C.VII
La table contenant les donnes doit tre une table interne. Voici un exemple de dfinition dune table affiche par la suite :
*- table de chargement data : begin of t_charge occurs 0 , vbeln like vbak-vbeln " n cde , kunnr like vbak-kunnr " donneur d'ordre , name1 like kna1-name1 " nom , posnr like vbap-posnr " n poste , matnr like vbap-matnr " code article , arktx like vbap-arktx " dsignation article , kschl like zsd02-kschl " type condition , vtext like zsd02-vtext " libell , kwert like konv-kwert " valeur condition , waerk like vbak-waerk " devise , z_kbetr(11) type p decimals 2 " montant , koein like konv-waers " valeur = devise ou % , kpein like konv-kpein " unit de prix , kmein like konv-kmein " unit qtit , erdat like vbak-erdat " date cde , ernam like vbak-ernam " auteur de la saisie , end of t_charge.
PAGE 60 / 94
VERSION 3.1
C.VIII
Les vnements
Data gt_events type slis_t_event.
REUSE_ALV_EVENT_GET afin de rcuprer lensemble des fonctions disponibles dans une table interne.
call function 'REUSE_ALV_EVENTS_GET' exporting i_list_type = 0 importing et_events = e03_lt_events.
Il est alors trs simple dassocier une fonciton au moins un des vnements disponibles.(La gestion du click passe par lutilisation du f2code). Liste des vnements : 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
VERSION 3.1
'ITEM_DATA_EXPAND', 'REPREP_SEL_MODIFY', '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', 'SUBTOTAL_TEXT'.
read table e03_lt_events with key name = slis_ev_top_of_page into ls_event. if sy-subrc = 0. move gc_formname_top_of_page to ls_event-form. append ls_event to e03_lt_events. endif.
PAGE 62 / 94
VERSION 3.1
C.IX
On peut utiliser la fonction REUSE_ALV_COMMENTARY_WRITE. La table utilise 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,
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. * * Listenberschrift: 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
VERSION 3.1
C.X
(programme BALVBT01) La gestion de plusieurs ALV sur un seul cran est possible laide des fonctions standards sans avoir recours un container spcifique. Nous nous efforcerons de prsenter les fonctions permettant cette souplesse : Exemple dcran gnr :
C.X.1 Initialisation
La premire fonction a appell a pour objectif dintialiser 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 appele trait les commandes utilisateurs. i_callback_user_command = 'USER_COMMAND' * Dfinit que le menu est propre lutilisateur i_callback_pf_status_set = PF_STATUS_SET * IT_EXCLUDING = .
PAGE 64 / 94
VERSION 3.1
Il est alors possible dafficher autant de blocs que lon souhaite soit de type classique ou hirarchique. On utilise alors les fonctions suivantes : Ces fonctions sont relativement proche des fonctions classique auquelles elles font rfrence, le dveloppeur est donc invit sy reporter.
PAGE 65 / 94
VERSION 3.1
PAGE 66 / 94
VERSION 3.1
C.X.4.A INITIALISATION
Il est conseill de placer cette fonction le plus tt possible, cela est particulirement important si on souhaite grer la notion daide sur un cran de slection. Dans notre exemple nous lavons plac au sein de linitialisation.
data: gs_extract1 like disextract. data: gs_extract2 like disextract. *---------------------------------------------------------------------* * initialization. call function 'REUSE_ALV_EXTRACT_AT_INIT' changing cs_extract1 = gs_extract1 cs_extract2 = gs_extract2.
C.X.4.B
La fonction suivante permet de mettre jour les structures GS_EXTRACT1 et 2. GS_EXTRACT1 correspond la structure pour lenregistrement des donnes. GS_EXTRACT2 correspond la structure pour le chargement des donnes. P_SAVE et P_LOAD dfinissent 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 dsignation. CS_EXTRACT1 et CS_EXTRACT2 sont les structures reprenant toutes les informations.
AT SELECTION-SCREEN. 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
VERSION 3.1
C.X.4.C AIDE F4
On utilise pour cela les fonctions suivantes, la premire concerne le champs pour lenregistrement dextrait alors que la seconde concerne le chargement. Ces fonctions peuvent tre places 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. 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.
* *
* *
C.X.4.F EXEMPLE
REPORT BALVEX01 NO STANDARD PAGE HEADING. * DB-Table TABLES SFLIGHT. * Type-pool of ALV TYPE-POOLS: SLIS. * Report Selections SELECT-OPTIONS CARRID FOR SFLIGHT-CARRID. SELECT-OPTIONS CONNID FOR SFLIGHT-CONNID. SELECT-OPTIONS FLDATE FOR SFLIGHT-FLDATE. SELECTION-SCREEN SKIP 1. selection-screen begin of block extract with frame title text-ext. * selection-screen begin of line. parameters: p_noex radiobutton group extr. selection-screen comment 3(50) text-ex1 for field p_noex. selection-screen end of line. selection-screen begin of line.
PAGE 68 / 94
VERSION 3.1
* Data to be displayed DATA: GT_SFLIGHT LIKE SFLIGHT OCCURS 0. DATA: GS_EXTRACT1 LIKE DISEXTRACT. DATA: GS_EXTRACT2 LIKE DISEXTRACT. *---------------------------------------------------------------------* * INITIALIZATION. CALL FUNCTION 'REUSE_ALV_EXTRACT_AT_INIT' CHANGING CS_EXTRACT1 = GS_EXTRACT1 CS_EXTRACT2 = GS_EXTRACT2. AT SELECTION-SCREEN. 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. break-point. * Process on value request AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_EX1. * * 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.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_EX2. * * 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
VERSION 3.1
PAGE 70 / 94
VERSION 3.1
D ANNEXES :
PAGE 71 / 94
VERSION 3.1
D.I
NOTA : Cette partie est donne titre informatif et ne peut en aucuns cas se substituer laide fournit par SAP : SAP Library Basis components Abap Programming and Runtime Environment BC-Abap Programming Abap Objects
Chacune dentre elle peut contenir des donnes des mthodes Des vnements.
CLASS C_LIST DEFINITION. PUBLIC SECTION. METHODS: FCODE_HANDLER FOR EVENT BUTTON_CLICKED OF STATUS IMPORTING FCODE, LIST_CHANGE FOR EVENT SPEED_CHANGE OF I_VEHICLE IMPORTING NEW_SPEED, LIST_OUTPUT. PRIVATE SECTION. DATA: ID TYPE I, REF_SHIP TYPE REF TO C_SHIP, REF_TRUCK TYPE REF TO C_TRUCK, BEGIN OF LINE, ID TYPE I, FLAG, IREF TYPE REF TO I_VEHICLE, SPEED TYPE I, END OF LINE, LIST LIKE SORTED TABLE OF LINE WITH UNIQUE KEY ID.
PAGE 72 / 94
VERSION 3.1
ENDCLASS.
PAGE 73 / 94
VERSION 3.1
PAGE 74 / 94
VERSION 3.1
E.II
Il faut commencer par dfinir un statut associ au programme en utilisant la transaction SE41. Cette transaction permet daffecter des codes transactions aux diffrents boutons, ainsi que de crer son menu. Les codes fonctions seront alors rcuprs au sein de lOK_CODE dans le PAI de lcran (dans le cas dun Ecran) ou dans la fonction AT SELECTION-SCREEN. Enfin, au sein du programme on utilise linstruction suivante, dans le PBO, pour insrer le menu : * MAIN100 est le nom du statues SET PF-STATUS MAIN100
PAGE 75 / 94
VERSION 3.1
La premire tape consiste crer un catalogue. Puis on fait appel la fonction standard 'REUSE_ALV_LIST_DISPLAY
Exemple
* Global data declaration include vsd03top. * Initialization fieldcatalog initialization. g_repid = sy-repid. perform fieldcat_init using gt_fieldcat[]. * Data selection start-of-selection. perform select_data tables gt_outtab. * Display list end-of-selection. ******************************************************************************
call function 'REUSE_ALV_LIST_DISPLAY' exporting i_callback_program = g_repid it_fieldcat = gt_fieldcat[] tables t_outtab = gt_outtab.
****************************************************************************** *----------------------------------------------------------------------* Forms *----------------------------------------------------------------------* Initialization fieldcatalog form fieldcat_init using rt_fieldcat type slis_t_fieldcat_alv. data: ls_fieldcat type slis_fieldcat_alv. data: pos type i value 1. clear ls_fieldcat. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SCARR-CARRID'. ls_fieldcat-ref_fieldname = 'CARRID'. ls_fieldcat-ref_tabname = 'SCARR'. ls_fieldcat-key = 'X'. append ls_fieldcat to rt_fieldcat. clear ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SCARR-CARRNAME'. ls_fieldcat-ref_fieldname = 'CARRNAME'. ls_fieldcat-ref_tabname = 'SCARR'. append ls_fieldcat to rt_fieldcat. clear ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SPFLI-CONNID'. ls_fieldcat-ref_fieldname = 'CONNID'.
PAGE 76 / 94
VERSION 3.1
PAGE 77 / 94
VERSION 3.1
PAGE 78 / 94
VERSION 3.1
E.III
Field name
CHECKBOX
LVC_CHECKB
CHAR(1)
SPACE, 'X'
Outputting a checkbox. The checkbox cannot be modified by the user. Parameter sel_mode of the layout structure allows the user to select multiple rows in the grid control (see also: get_selected_rows). 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 parameter determines the relative column position of the field for list output. The user can interactively modify the order of the columns. If this parameter is initial for each field catalog entry, the order of the columns corresponds to the sequence of fields in the field catalog. DO_SUM LVC_DOSUM Char(1) SPACE, 'X'
If this field is set, the ALV uses this field to calculate the total (this corresponds to the generic totals function in the toolbar.) EMPHASIZE LVC_EMPHSZ Char(4) SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If the character field begins with 'C' (color code), 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, see the F1 help on the FORMAT statement. LVC_HOTSPT Char(1) SPACE, 'X' If this field is set, all cells of this column are hotspot-sensitive. LVC_KEY Char(1) SPACE, 'X' If this field is set, the ALV grid control color-codes the column as a key field and fixes this column during horizontal scrolling. The order of the key columns in the ALV grid control can be modified interactively. In contrast to the ABAP List Viewer, the ALV grid control allows you to directly hide key columns with NO_OUT (field KEY_SEL is not used). LOWERCASE Char(1) SPACE, 'X' If this field is set, the ALV grid control recognizes upper/lower case in the output table. This affects the sorting of fields, for example. LVC_NOOUT Char(1) SPACE, 'X' If you set this field, you hide the relevant column in the list. Nevertheless, the column is available in the field selection and can be interactively selected by the user as a display field. The ALV displays the contents of hidden fields on the detail screen for a row in the grid control. LVC_NOSIGN Char(1) SPACE, 'X' If you set this field, you lock totals calculation for the relevant field. LVC_OUTLEN Numc(6) 0 (default setting), n
PAGE 79 / 94
VERSION 3.1
If the field has a reference to the Data Dictionary, you can leave the field set to its initial value. In this case, the ALV adopts the output length of the relevant domain. For fields without reference to the DDIC, you must specify the desired field output length.
TECH
LVC_TECH Char(1) SPACE, 'X' If this field is set, the relevant field is not displayed on the list and cannot be shown interactively. The field is only known in the field catalog. (For example, it must not be specified as a sorting criterion).
PAGE 80 / 94
VERSION 3.1
E.IV
Field name
Comp. type
Dtype(length) Use
Value range
DECIMALS_O
LVC_DECMLS
Char(6)
Relevant only if no currency field is assigned to the field and if CURRENCY has a value. The value in this field determines the number of digits to be displayed after the comma. DECMFIELD LVC_DFNAME Char(30) SPACE, field name of output table
Defining the digits after the comma on a row-by-row basis. 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. EDIT_MASK LVC_EDTMSK Char(60) SPACE, conv (conversion exit)
If you set a conversion exit (for example, conv = ' ==ALPHA ' for function module CONVERSION_EXIT_ALPHA_OUTPUT ), you enforce output conversion for the associated output field. (See also F1 help for WRITE edit option USING EDIT MASK) . See also: Using the Conversion Exit EXPONENT LVC_EXPONT Char(3) initial, integer
Determines a fixed exponent for the field. The field must be of internal type F. (See also F1 help for WRITE edit option EXPONENT ). ICON LVC_ICON Char(1) SPACE, 'X'
If this field is set, the column contents of the output table are output as an icon. The column contents must consist of valid icon strings ( @xx@ or @xx\Q <Quickinfo> @ ). You should consider the problem of printing icons. JUST LVC_JUST Char(1) SPACE, 'R', 'L','C'
Relevant only to fields of data type CHAR or NUMC . Justifications: 'R': right justified 'L': left justified 'C': centered
LZERO
How the column header is justified, depends on how the column contents are justified. You cannot justify the column header separately. LVC_LZERO Char(1) SPACE, 'X' Relevant only to fields of data type NUMC . In the default setting, the ALV control displays these fields right justified without leading zeros. If you set LZERO , leading
PAGE 81 / 94
VERSION 3.1
NO_SIGN
NO_ZERO
ROUND
ROUNDFIELD
SYMBOL
zeros are displayed. LVC_NOSIGN Char(1) SPACE, 'X' Relevant only to value fields. If you set NO-SIGN , values are displayed without signs (see also F1 help for the WRITE edit options). LVC_NOZERO Char(1) SPACE, 'X' If NO_ZERO is set, no zeros are displayed for initial value fields. The cell remains empty. LVC_ROUND Char(10) initial, natural number Displaying a value of type P scaled by the power of ten. For positive ROUND values, the ALV grid control moves the comma to the left; otherwise, it moves the comma to the right. (See also F1 help for the WRITE edit options) LVC_RNDFN Char(30) Defining scaled output on a row-by-row-basis. You can use an additional field in the output table to determine how the relevant field is scaled in each row. LVC_SYMBOL Char(1) SPACE, 'X' If this field is set, the column contents are displayed as a symbol. The column contents of the internal table must consist of valid symbol signs. The caller should consider the problem of printing symbols. (It is usually possible to print symbols, but they may not be output correctly depending on the printer configuration).
PAGE 82 / 94
VERSION 3.1
E.V
General display options Field name CWIDTH_OPT Description If this field is set, the ALV grid control optimizes the column width. You can then see the column header and the contents of the cells of this column. If this field is set, the title size in the grid control is set to the font size of the column header. Value range SPACE, 'X'
SMALLTITLE
SPACE, '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, column headers are hidden. If this field is set, columns are displayed without horizontal grid lines. If this field is set, cells are not merged when a column is sorted. 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' ). If this field is set, the toolbar is hidden. If this field is set, columns are displayed without vertical grid lines. Set the selection mode (see table below). Value range Character string of 70 characters at most SPACE, 'X' SPACE, 'X' SPACE, 'X' SPACE, 'X'
Selection modes for SEL_MODE Value SPACE 'A' Mode same as 'B' Column and row selection (see graphic) 'B' Simple selection, list box Possible selections see 'B' 'C' Multiple selection, 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.
PAGE 83 / 94
VERSION 3.1
The user selects the rows through pushbuttons at the left border of the grid control.
PAGE 84 / 94
VERSION 3.1
E.VI
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
PAGE 85 / 94
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
VERSION 3.1
E.VII
E.VII.1
Afin de pouvoir afficher plusieurs objets ALV au sein dun mme cran, on peut procder selon deux mthodes : Crer deux CUSTOM CONTROL . Utiliser un contnaire divisant en cellules le custom control originel. Chaque cellule est alors identifiable par un numro de ligne et de colonne. Seule la seconde mthode est dtaill par la suite. Processus : 1 2 3 On utilise toujours un objet de type custom_container rattach au cutom_control de lcran. On crer alors un objet de type splitter_custom rattacher au custom_container dfinit prcdemment. On peut alors soit dfinir des contnaires 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 dfinit dans lcran. data : cont_on_main type scrfname value 'ALV_1', * Dfinition du contnaire principal rattach au custom control custom_container_parent type ref to cl_gui_custom_container, * Dfinition du contenair divis en cellule custom_splitter type ref to cl_gui_splitter_container, * Dfinition des contenairs acceuillant les objets ALV.
PAGE 87 / 94
VERSION 3.1
* Mthode 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.
* Mthode 2
PAGE 88 / 94
Documentation sur LABAP List Viewer E.VIII Affichage dun objet ALV sans utiliser de screen Painter
VERSION 3.1
Pour se faire on utilise un container particulier qui permet de dfinir sa taille et ses caractristiques daffichage.
* Dclaration Data : dock_container type ref to cl_gui_docking_container. Data: l_repid like sy-repid, l_dynnr like sy-dynnr. * Affectation de valeur g_repid = sy-repid. l_dynnr = sy-dynnr. * Ce code peut tre mis dans un PBO. *create docking container create object dock_container exporting repid = l_repid dynnr = l_dynnr * Dfinit le placement du container (droite, gauche, bas , 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. *set height and width call method dock_container->set_position exporting height = 150 width = 100 exceptions cntl_error =1 cntl_system_error = 2.
Une fois que le contenair est cre, on peut alors soit lutiliser pour afficher nos composant, soit utiliser une autre contenair tel que le splitter_container. Il suffit alors de dfinir le dock_container comme tant le parent . Le placement du container par rapport lcran est dfinit par le paramtre SIDE NOTA : Ce container offre la possibilit de pouvoir redimensionner laide de la souris le container. 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
VERSION 3.1
E.IX
Lobjet ALV permet de dfinir un menu appeler par le bouton droit de la souris ou (SHIFT + F10). 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. Parameter context_menu Meaning Instance of the class CL_CTMENU for constructing and displaying a context menu ( see also: Context Menu).
Fonction dfinis relative au menu contextuel. Method Description LOAD_GUI_STATUS Charge un menu dfini dans le menu painter SE41
constants: c_pname type program value 'CTMENU_BUILD', c_status_context type cua_status value 'CT_STATIC'.
call method cl_ctmenu=>load_gui_status exporting program = c_pname status = c_status_context menu
= p_menu.
ADD_FUNCTION
CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING FCODE = 'AA' code fonction TEXT = TEXT-150. "American Airlines
Adds a function :
ADD_MENU ADD_SUBMENU
Data l_submenu type ref to cl_ctmenu. * Add new submenu create object l_submenu. * Add functions call method l_submenu->add_function exporting fcode = c_fcode1 text = text-001. * Add separator call method l_submenu->add_separator. * Add functions call method l_submenu->add_function exporting fcode = c_fcode3 text = text-003. * Dans la fonction handler p_menu = e_object call method p_menu->add_submenu exporting menu = l_submenu text = text-m01.
call method p_menu->add_separator.
Adds a menu that you defined in the Menu Painter Adds a menu that you defined in the Menu Painter as a submenu
Adds a separator
PAGE 90 / 94
VERSION 3.1
APPEND CL_GUI_ALV_GRID=>MC_FC_DELETE_FILTER TO LT_STD_FCODES. * Fonction perso. APPEND 'AA' TO LT_STD_FCODES. CALL METHOD E_OBJECT->HIDE_FUNCTIONS EXPORTING FCODES = LT_STD_FCODES.
SHOW_FUNCTIONS
DATA: LT_STD_FCODES TYPE UI_FUNCTIONS. * Fonction standard ALV APPEND CL_GUI_ALV_GRID=>MC_FC_DELETE_FILTER TO LT_STD_FCODES. * Fonction perso. APPEND 'AA' TO LT_STD_FCODES. CALL METHOD E_OBJECT->SHOW_FUNCTIONS EXPORTING FCODES = LT_STD_FCODES.
Shows a function
DISABLE_FUNCTIONS ENABLE_FUNCTIONS
Tout comme pour les autres vnements, on utilise une classe locale, celle-ci peut aussi contenir dautres mthodes. Dfinition :
INCLUDE <ICON>. ********* * Predefine a local class for event handling to allow the * declaration of a reference variable before the class is defined. CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED. DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
Dfinition de la classe
**************************************************************** * LOCAL CLASSES: Definition **************************************************************** *====================================================== ========= * class lcl_event_receiver: local class to * define and handle own functions. * * Definition: * ~~~~~~~~~~~ CLASS LCL_EVENT_RECEIVER DEFINITION. PUBLIC SECTION. METHODS : HANDLE_USER_COMMAND FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID IMPORTING E_UCOMM, HANDLE_CONTEXT_MENU FOR EVENT CONTEXT_MENU_REQUEST OF CL_GUI_ALV_GRID IMPORTING E_OBJECT. PRIVATE SECTION. * Les LT_STD_FCODES et LT_OWN_FCODES permettent de regrouper * par groupes les fonctions (Voir implmentation). DATA: LT_STD_FCODES TYPE UI_FUNCTIONS,
PAGE 91 / 94
VERSION 3.1
* Chargement dun menu dfinit dans le menu painter call method cl_ctmenu=>load_gui_status exporting program = c_pname status = c_status_context
menu = p_menu.
* 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. CL_GUI_ALV_GRID=>MC_FC_HELP TO LT_STD_FCODES. CL_GUI_ALV_GRID=>MC_FC_COL_INVISIBLE TO LT_STD_FCODES. CL_GUI_ALV_GRID=>MC_FC_DELETE_FILTER TO LT_STD_FCODES.
PAGE 92 / 94
VERSION 3.1
* On ajoute nos lignes de menus et les codes fonctions associs. * Celle-ci seront rcupres dans le E_UCOMM dans lvnement user_command CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING * Code rcupr dans le E_UCOMM FCODE = 'AA' TEXT = TEXT-150. "American Airlines CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING FCODE = 'LH' TEXT = TEXT-151. "Lufthansa CALL METHOD E_OBJECT->ADD_FUNCTION EXPORTING FCODE = 'UA' TEXT = TEXT-152. "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. * La fonction SHOW permet dafficher le groupe LT_OWN_FCODES CALL METHOD E_OBJECT->SHOW_FUNCTIONS EXPORTING FCODES = LT_OWN_FCODES. ENDMETHOD. ENDCLASS. * * lcl_event_receiver (Implementation) *====================================================== =============
Enfin il suffit alors de crer une instance de lobjet et de le rattacher lobjet ALV.
******** * ->Create Object to receive events and link them to handler methods. * When the ALV Control raises the event for the specified instance * the corresponding method is automatically called. * * GRID est le nom de notre composant ALV. CREATE OBJECT EVENT_RECEIVER. SET HANDLER EVENT_RECEIVER->HANDLE_USER_COMMAND FOR GRID1. SET HANDLER EVENT_RECEIVER->HANDLE_CONTEXT_MENU FOR GRID1. * ********
PAGE 93 / 94
VERSION 3.1
TO DO :
1 2 3 Gestion du drag and Drop Listes hirarchiques
PAGE 94 / 94