Vous êtes sur la page 1sur 8

PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS

TP4 4ème Année Management N. ZIDANE

5 L’ACCÈS AUX TABLES DE LA BASE DE DONNÉES : SQL SOUS SAP


Objectifs
À la fin de cet atelier, vous serez à même d'effectuer les tâches suivantes :
Extraction des données d’une base
Filtrage
Tri
Durée approximative de cet atelier : 3 heures
Il faut créer aux préalables la table ZNOTES contenant les champs num, nom ,prenom et note (
voir tp n°3).
5.1 EXERCICE1 : lecture du 1ier enregistrement
REPORT ZLECTURE1.
tables ZNOTES .
select * from ZNOTES .
write: / ZNOTES -NOM, ZNOTES -PRENOM, ZNOTES -NOTE.
endselect.
DISQUE DUR MEMOIRE RAM ECRAN

WRITE: / ZNOTES -NOM,


ALAMI ALI 16
BASE DE select * ZNOTES -PRENOM,

DONNEES from ZNOTES


RAM ZNOTES -NOTE ALAOUI AHMED 12

SAP ZNOTES

5.2 EXERCICE2 :lecture de tous les enregistrements


REPORT ZLECTURE2.
tables ZNOTES .
data etudiants like ZNOTES occurs 100 with header line.
select * from ZNOTES into table etudiants.
loop at etudiants.
write:/ etudiants-NOM, etudiants-PRENOM, etudiants-NOTE.
endloop.

DISQUE DUR MEMOIRE RAM ECRAN


LOOP AT ETUDIANTS.

RAM
WRITE : / ZNOTES -NOM,
ZNOTES -PRENOM,
BASE DE data etudiants like ZNOTES -NOTE. ALAMI ALI 16
DONNEES ZNOTES occurs 100 ETUDIANTS ALAOUI AHMED 12
ENDLOOP.
SAP with header line
Identique à
ZNOTES
ZNOTES

select *
from ZNOTES INTO TABLE ETUDIANTS

1
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

5.3 EXERCICE3 : Recherche d’un enregistrement


REPORT ZLECTURE3.
tables ZNOTES .
data etudiants like ZNOTES occurs 100 with header line.
select * from ZNOTES into table etudiants where PRENOM = 'ALI'.
loop at etudiants.
write:/ etudiants-NOM,etudiants-PRENOM, etudiants-note.
endloop.

5.4 EXERCICE4 :Tri
*---------------------------------------------------------------------*
* programme de tri de la table *
*---------------------------------------------------------------------*
REPORT ZLECTURE4.
data etudiants like ZNOTES occurs 100 with header line.
select * from ZNOTES into table etudiants order by nom DESCENDING.
loop at etudiants. " boucle sur tous les enregistrements
write:/ etudiants-NOM,etudiants-PRENOM.
endloop.

5.5 EXERCICE5 : Recherche version 2


REPORT ZLECTURE5.
tables ZNOTES .
data etudiantslike ZNOTES occurs 100 with header line.
select * from ZNOTES into table etudiants where PRENOM = 'ALI'.
if sy-subrc = 0.
write: / 'trouvé'.
loop at etudiants.
write:/ etudiants-NOM,etudiants-PRENOM.
endloop.
write: / 'nombre enregistrements:',sy-dbcnt.
else.
write : / 'aucun enregistrement trouvé'.
endif.

5.6 Exercice 6 : Calcul de la moyenne


Faites un programme ABAP pour calculer la moyenne de la classe

2
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

Début 1

Znotes 2

Etudiant Znotes 3

moyenne 0 4

7 Fin de la table
OUI Etudiant
EOF ?

8
NON
Moyenne moyenne / sy-dbcnt. 5
6

moyenne 9 moyenne moyenne + note

Fin

 ,1 Report zmoyenne .

 2 Tables znotes .

 3 Data etudiant like znotes occurs 100 with header line.


Select * from znotes into table etudiant.

 4 DATA moyenne TYPE P.


MOVE 0 To moyenne.

 5 Loop at etudiant.

3
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

 moyenne = Moyenne + etudiant–note.

 7 ENDLOOP.

 8 moyenne = Moyenne / SY-DBCNT.



 9 Write : /  la moyenne de la classe :  , moyenne.

5.7 Exercice7 : Mise à jour des données


Créez la table ZPRODUITSgf suivante :

Saisissez des données dans cette table.

REPORT ZMAJPRODUITS .
Tables zproduitsmc .
data produits like zproduitsmc occurs 100 with header line.
parameters p_code(10).
parameters p_pu(10).
UPDATE zproduitsmc SET pu = p_pu WHERE code_p = p_code.
select * from zproduitsmc into table produits.
if sy-subrc = 0.
write: / 'trouvé'.
LOOP at produits.
WRITE:/ produits-code_p, produits-designation.
WRITE:/10(15) produits-q, produits-pu COLOR COL_TOTAL.
ENDLOOP.

4
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

WRITE: / 'nombre enregistrements:',sy-dbcnt.


ELSE.
WRITE : / 'aucun enr'.
ENDIF.

5.8 Exercice 8 :Suppression des données


REPORT ZSUPPRIME .
tables znotesgf .
data etudiant like znotesmc occurs 100 with header line.
parameters nom(30).
delete from znotesmc WHERE NOM = nom.
select * from znotesmc into table etudiant.
if sy-subrc = 0.
write: / 'trouvé'.
loop at etudiant.
WRITE:/10(15) etudiant-num,etudiant-NOM,etudiant-PRENOM,
etudiant-note COLOR COL_TOTAL.
endloop.
write: / 'nombreenregistrements:',sy-dbcnt.
else.
write : / 'aucunenr'.
endif.

5.9 Exercice9 : Commande et facturation


Faites un programme ABAP qui permet de lire et faire la mise à jour de la table
ZPRODUITS9GF ayant la structure suivante :

Saisissez des données dans cette table.

5
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

Programme de lecture:
REPORT ZLECTURE9 .
tables zproduits9.
select * from zproduits9.
write:/ zproduit-refproduit ,zproduits9-nomproduit,
zproduits9-prixunitaire.
endselect.
----------------------------------------------------------------------------------
*Programme de lecture et de mise à jour:
REPORT ZPRODUITSMAJ9 .
tables ZPRODUITS9.
data produit like ZPRODUITS9 occurs 100 with header line.
parametersp_nom(30).
parametersp_prix(10).
UPDATE ZPRODUITS9 SET prixunitaire = p_prix WHERE NOMproduit = p_nom.
select * from ZPRODUITS9 into table produit.
if sy-subrc = 0.
write: / 'trouvé'.
loop at produit.
write:/ produit-refproduit,produit-NOMproduit.
WRITE:/10(15) produit-prixunitaire.
endloop.
write: / 'nombre enregistrements:',sy-dbcnt.
else.
write : / 'aucunenr'.
endif.
----------------------------------------------------------------------------------

Faites un programme ABAP qui permet d’afficher la facture de la table Zcommande ayant la
structure suivante :

6
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

Saisissez des données dans cette table.

Créez le programme suivant:


REPORT ZFACTURE.
tables zcommande.
data commande like zcommande occurs 100 with header line.
select * from zcommande into table commande.
dataprix_ht type p.
dataprix_ttc type p.
data total_ttc type p.

WRITE: /5(15) 'REF' COLOR 1,21(10) 'intitulé' COLOR 1 ,33(10) 'quantite' COLOR
1,44(10) 'prix ht' COLOR 1,55(10) 'prix ttc' COLOR 1.
loop at commande.
prix_ht = commande-quantite * commande-prix_achat * commande-coef.
prix_ttc = prix_ht * 120 / 100.
prix_ttc = prix_ttc * ( 1 - commande-remise / 100 ).
WRITE: /5(15) commande-ref,21(10) commande-intitule,
33(10) commande-quantite,44(10) prix_ht,
55(10) prix_ttc COLOR COL_TOTAL.

7
PROGICIELS APPLIQUÉS A LA GESTION DES OPÉRATIONS
TP4 4ème Année Management N. ZIDANE

total_ttc = total_ttc + prix_ttc.


endloop.
WRITE: /44(10) ’Total ttc=’, 55(10) total_ttc.

Modifiez le programme pour avoir la facture au format suivant:

Vous aimerez peut-être aussi