Skip to Content
0
Former Member
Jan 19, 2012 at 08:27 AM

IF_EX_ME_PROCESS_PO_CUST~CHECK -> Multiple message errors

2034 Views

Hello, I'm new in ABAP development

I must add a control to prohibit save of purchase order in creation (ME21N) or modification (ME22N) if some accounting controls are not OK

i've found on this forum an answer : implementing the metho chec on BADI IF_EX_ME_PROCESS_PO_CUST in class see the following code

TYPES : BEGIN of Data_Err,
          Num_Poste type STRING,
          Lib_Err type STRING,
        END OF Data_Err.

DATA: lt_Champs_POSTES_CDE      TYPE  PURCHASE_ORDER_ITEMS,
      lo_Champs_POSTES_CDE      LIKE  LINE OF lt_Champs_POSTES_CDE,
      lo_Entete_CDE             TYPE  MEPOHEADER,
      lo_Poste_CDE              TYPE  MEPOITEM,
      lt_Champs_IMP_CDE         TYPE  PURCHASE_ORDER_ACCOUNTINGS,
      lo_Champs_IMP_CDE         LIKE  LINE OF lt_Champs_IMP_CDE,
      lo_Imp_Poste_CDE          TYPE  MEPOACCOUNTING,
      lt_Erreurs                TYPE  STANDARD TABLE OF Data_Err,
      ls_Ligne_Erreur           TYPE  Data_Err,
      ls_Msg_Ctrl               TYPE  STRING,
      ls_Tag_Deb                TYPE  STRING,
      ls_Msg_ERR_1              TYPE  STRING,
      ls_Msg_ERR_2              TYPE  STRING.

"---  Init
ls_Msg_ERR_1 = 'Ordre invest. obligatoire pour Cpte Gene = 923100'(001).
ls_Msg_ERR_2 = 'Cpte Gene début. par 6 incompa. avec ordre invest.'(002)
.
ls_Tag_Deb = 'POSTE'(003).

"--- récupération de l'entete de la commande en cours
lo_Entete_CDE = im_header->get_data( ).
IF lo_Entete_CDE-BSART = 'NB'.
  "--- on est sur une commande de type normal
  "--- récupération des postes de la commande en cours
  lt_Champs_POSTES_CDE = im_header->get_items( ).

  "--- boucle sur les postes de la commande en cours
  LOOP AT lt_Champs_POSTES_CDE INTO lo_Champs_POSTES_CDE.
    "--- on recupere les données du poste en cours
    lo_Poste_CDE = lo_Champs_POSTES_CDE-item->get_data( ).
    IF lo_Poste_CDE-KNTTP = 'F'.
      "--- recuperation des informations d'imputation
      lt_Champs_IMP_CDE = lo_Champs_POSTES_CDE-item->GET_ACCOUNTINGS( ).
      "--- boucle sur les imputations du poste
      LOOP AT lt_Champs_IMP_CDE INTO lo_Champs_IMP_CDE.
        "--- on recupere les données d'imputation du poste en cours
        lo_Imp_Poste_CDE  = lo_Champs_IMP_CDE-accounting->get_data( ).
        "--- investissement obligatoire sur compte général 923100
        IF lo_Imp_Poste_CDE-SAKTO = '0000923100' and
lo_Imp_Poste_CDE-AUFNR(2) NE 'IN'.
           "--- Trace erreur blocante
           ls_Ligne_Erreur-Num_Poste = lo_Poste_CDE-EBELP.
           ls_Ligne_Erreur-Lib_Err = ls_Msg_ERR_1.
           APPEND ls_Ligne_Erreur TO lt_Erreurs.
        ENDIF.

        "--- pas d'investissement sur compte général debute par 6
        IF lo_Imp_Poste_CDE-SAKTO(5) = '00006' and
lo_Imp_Poste_CDE-AUFNR(2)
 = 'IN'.
           "--- Trace erreur blocante
           ls_Ligne_Erreur-Num_Poste = lo_Poste_CDE-EBELP.
           ls_Ligne_Erreur-Lib_Err = ls_Msg_ERR_1.
           APPEND ls_Ligne_Erreur TO lt_Erreurs.
         ENDIF.

      ENDLOOP.
    ENDIF.
  ENDLOOP.
ENDIF.

* Affichage Erreurs
ls_Msg_Ctrl = ''.
IF lt_Erreurs[] IS NOT INITIAL.
  LOOP AT lt_Erreurs INTO ls_Ligne_Erreur.
    CONCATENATE ls_Tag_Deb ls_Ligne_Erreur-Num_Poste INTO ls_Msg_Ctrl
SEPARATED BY ' '.
    CONCATENATE ls_Msg_Ctrl ls_Ligne_Erreur-Lib_Err INTO ls_Msg_Ctrl
SEPARATED BY ' - '.
    MESSAGE ls_Msg_Ctrl TYPE 'E'.
  ENDLOOP.
  " blocage sauvegarde
  CH_FAILED = 'X'.

ENDIF.

all is ok, and system check my data

my probleme is on the displaying errors : only the first item on error is displayed

i wish to have in the error dialog box all of my items in error (so all the contain of my error table lt_Erreurs)

is it possible in this method?

is it the correct method to do that ?

all ideas are welcomed

thanks in advance

Edited by: kishan P on Jan 19, 2012 3:26 PM