SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Utility di cancellazione eventi del dipendente



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> HR
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Fri May 22, 2009 3:01 pm    Post subject: Utility di cancellazione eventi del dipendente Reply with quote

Code:
************************************************************************
*                                                                      *
*                                  H R                                 *
*                                                                      *
************************************************************************
*   Sviluppatore    : L. Cantaro                                       *
*   Analista        : S. Quartili                                      *
*   Creato il       : 25/09/2002                                       *
*   Ultima modifica : 26/09/2002                                       *
*   Stato           : D              (S)viluppo, (T)est, (D)efinitivo  *
*                                                                      *
************************************************************************
*   Descrizione : Utility di cancellazione eventi del dipendente       *
*                                                                      *
************************************************************************

REPORT  zhrbidelaction               .

INCLUDE <icon>.
       

TABLES: pa0000, t529a, t588c, t588d.


DATA: BEGIN OF it_pernr OCCURS 0,
      pernr LIKE pa0000-pernr,
      massn LIKE pa0000-massn,
      begda LIKE pa0000-begda,
      nachn LIKE pa0002-nachn,
      vorna LIKE pa0002-vorna,
      flag(1),
      linea LIKE sy-linno,
      END OF it_pernr.

DATA: it_errori LIKE it_pernr OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF inftab OCCURS 30,
        infty LIKE prel-infty,
      END OF inftab.

DATA: BEGIN OF it_singolo OCCURS 0,
      infty(4),
      begda LIKE pa0000-begda,
      endda LIKE pa0000-endda,
      END OF it_singolo.

DATA: BEGIN OF it_riapertura OCCURS 0,
      pernr LIKE pa0000-pernr,
      infty(4),
      endda LIKE pa0000-endda,
      END OF it_riapertura.

DATA: it_appo LIKE pa0000 OCCURS 0 WITH HEADER LINE.

DATA: it_testata LIKE hrfieldnam OCCURS 0 WITH HEADER LINE.

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: v_pernr LIKE pa0000-pernr,
      userg LIKE t588b-userg.                               "K11K093265

DATA: v_endda LIKE sy-datum.

data: v_group(12) value 'DEL'.

*MACRO FILL$BDCDATA
DEFINE fill$bdcdata.
  clear bdcdata.
  if &1 = 'X'.
    bdcdata-program = &2.
    bdcdata-dynpro = &3.
    bdcdata-dynbegin = &1.
  else.
    bdcdata-fnam = &2.
    bdcdata-fval = &3.
  endif.
  append bdcdata.
END-OF-DEFINITION.


*screen
SELECTION-SCREEN BEGIN OF BLOCK bl_1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS: so_pernr FOR pa0000-pernr MATCHCODE OBJECT prem
OBLIGATORY.
PARAMETERS: p_begda LIKE sy-datum OBLIGATORY,
            p_event LIKE pa0000-massn MATCHCODE OBJECT h_t529a
OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl_1.

SELECTION-SCREEN BEGIN OF BLOCK bl_2 WITH FRAME TITLE text-002.
PARAMETERS: p_test AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK bl_2.




START-OF-SELECTION.

  DATA: actio(4).

  SET PF-STATUS 'CUSTOM'.

*per l'evento indicato viene letta la sequenza di infotype
  PERFORM carica_infty_evento.

*lettura pa0000 e visualizzazione anteprima eventi da cancellare
  PERFORM preparazione_cid.
  PERFORM visualizza_anteprima.


END-OF-SELECTION.

AT LINE-SELECTION.
*lettura degli infotype che verrebbero cancellati, dettaglio per cid
  PERFORM visualizza_singolo_evento.


AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'BACK'.
*      CALL SELECTION-SCREEN 1000.
      CALL TRANSACTION 'ZHRDELEVENTO'.
    WHEN 'DELE'.
*creazione della sessione e lancio
      IF actio <> 'DELE'.
        PERFORM cancellazione_evento.
        PERFORM log_esecuzione.
        MOVE sy-ucomm TO actio.
      ELSE.
        MESSAGE i000(db) WITH 'Rilanciare il report'.
        CALL TRANSACTION 'ZHRDELEVENTO'.
      ENDIF.
    WHEN 'ALLX'.
      LOOP AT it_pernr.
        READ LINE it_pernr-linea OF CURRENT PAGE.
        IF sy-lisel+1(1) <> 'X'.
          MOVE 'X' TO sy-lisel+1(1).
          MODIFY CURRENT LINE.
        ENDIF.
      ENDLOOP.
    when 'ALLB'.
      LOOP AT it_pernr.
        READ LINE it_pernr-linea OF CURRENT PAGE.
        IF sy-lisel+1(1) = 'X'.
          MOVE ' ' TO sy-lisel+1(1).
          MODIFY CURRENT LINE.
        ENDIF.
      ENDLOOP.
  ENDCASE.

*
*routines

*
*&---------------------------------------------------------------------*
*&      Form  PREPARAZIONE_CID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM preparazione_cid.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE it_pernr FROM pa0000
         WHERE pernr IN so_pernr
           AND begda = p_begda
           AND massn = p_event.

  IF NOT it_pernr[] IS INITIAL.
    SORT it_pernr BY pernr.
    DELETE ADJACENT DUPLICATES FROM it_pernr.
  ELSE.
    MESSAGE i000(db) WITH 'Non esistono eventi per le matricole'.
    CALL SELECTION-SCREEN 1000.
  ENDIF.


ENDFORM.                    " PREPARAZIONE_CID


*
*&---------------------------------------------------------------------*
*&      Form  VISUALIZZA_ANTEPRIMA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM visualizza_anteprima.

  SKIP.
  FORMAT COLOR 1 INTENSIFIED OFF.
  WRITE: icon_delete AS ICON,
         AT 4 'CID',
         AT 13 'Data',
         AT 24 'Evento',
         AT 38 'Cognome',
         AT 58 'Nome                '.
  FORMAT COLOR OFF INTENSIFIED ON.
  SKIP.

  LOOP AT it_pernr.
    WRITE AT 2 it_pernr-flag AS CHECKBOX.
    SELECT SINGLE nachn vorna INTO (it_pernr-nachn,it_pernr-vorna)
      FROM pa0002 WHERE pernr = it_pernr-pernr.
    FORMAT HOTSPOT ON COLOR 2.
    WRITE AT 4 it_pernr-pernr.
    FORMAT HOTSPOT OFF COLOR OFF.
    WRITE: AT 13 it_pernr-begda,
           AT 24 it_pernr-massn,
           AT 38 it_pernr-nachn,
           AT 58 it_pernr-vorna.
    MOVE sy-linno TO it_pernr-linea.
    MODIFY it_pernr.
    SKIP.
  ENDLOOP.

ENDFORM.                    " VISUALIZZA_ANTEPRIMA

*
*&---------------------------------------------------------------------*
*&      Form  VISUALIZZA_SINGOLO_EVENTO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM visualizza_singolo_evento.

  TABLES: t529t.

  DATA: pa(6),
        txt_matricola(40),
        txt_evento(40).

  MOVE sy-lisel+3(8) TO v_pernr.
  READ TABLE it_pernr WITH KEY pernr = v_pernr.

  IF sy-subrc = 0.
    CLEAR: it_singolo[],
           it_testata[],
           it_singolo,
           it_testata.

    LOOP AT inftab.
      CONCATENATE 'PA' inftab-infty INTO pa.
     SELECT SINGLE begda endda INTO (it_singolo-begda,it_singolo-endda)
                                 FROM (pa) WHERE pernr = v_pernr
                                             AND begda = p_begda.
      IF sy-subrc = 0.
        MOVE inftab-infty TO it_singolo-infty.
        APPEND it_singolo.
        CLEAR  it_singolo.
      ENDIF.
    ENDLOOP.


    IF NOT it_singolo[] IS INITIAL.

      it_testata-field  = 'Infotype'. APPEND it_testata.
      it_testata-field  = 'Inizio val.'. APPEND it_testata.
      it_testata-field  = 'Fine val.'. APPEND it_testata.
      CLEAR it_testata.

      CONCATENATE 'Matricola n. :  ' v_pernr INTO txt_matricola.
      SELECT SINGLE mntxt INTO txt_evento FROM t529t
             WHERE sprsl = 'IT'
               AND massn = p_event.
      CONCATENATE 'per evento :' txt_evento INTO txt_evento.

      CALL FUNCTION 'DISPLAY_BASIC_LIST'
           EXPORTING
              basic_list_title = icon_terminated_position
              file_name        = 'evento'
           head_line1       = 'I seguenti infotype verranno cancellati'
              head_line2       = txt_evento
              head_line3       = txt_matricola
              lay_out          = 1
           TABLES
              data_tab         = it_singolo
              fieldname_tab    = it_testata.
    ELSE.
      MESSAGE i000(db) WITH 'Nessuna sequenza per evento'.
    ENDIF.

  ELSE.

    IF sy-lisel+1(2) = '1V'.
      SET PARAMETER ID 'MPN' FIELD v_group.
      CALL TRANSACTION 'SM35' AND SKIP FIRST SCREEN.
    ENDIF.

  ENDIF.

ENDFORM.                    " VISUALIZZA_SINGOLO_EVENTO

*
*&---------------------------------------------------------------------*
*&      Form  CARICA_INFTY_EVENTO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM carica_infty_evento.

  SELECT SINGLE * FROM t529a
         WHERE massn = p_event.
  IF sy-subrc NE 0.
    WRITE: / 'Non ci sono entrate in Tab. T529A'(002), p_event.
    STOP.
  ENDIF.
  SELECT SINGLE * FROM t588c
         WHERE mntyp EQ 'G'
           AND menue EQ t529a-itygr.
  IF sy-subrc EQ 0.
    IF t588c-mnbgr NE space.
      IF userg EQ '00'.
        MOVE t588c-refbg TO userg.
      ELSE.
        MOVE t588c-refbg TO userg.
      ENDIF.
    ELSE.
      MOVE t588c-refbg TO userg.
    ENDIF.
  ELSE.
    CLEAR userg.
  ENDIF.
  MOVE '0000' TO inftab.
  APPEND inftab.
  SELECT * FROM t588d
           WHERE itygr EQ t529a-itygr
             AND userg EQ userg.
    MOVE t588d-infty TO inftab.
    APPEND inftab.
  ENDSELECT.
  IF sy-subrc NE 0.
    WRITE: / 'Nessun Infotype per l''Infogroup'(003), t529a-itygr,
             ', Gruppo utenti '(004), userg,
             ', esistente.'(005).
    STOP.
  ELSE.
    SORT inftab BY infty ASCENDING.
  ENDIF.

ENDFORM.                    " CARICA_INFTY_EVENTO

*
*&---------------------------------------------------------------------*
*&      Form  CANCELLAZIONE_EVENTO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM cancellazione_evento.

  LOOP AT it_pernr.
    READ LINE it_pernr-linea OF CURRENT PAGE.
    IF sy-lisel+1(1) <> 'X'.
      DELETE it_pernr.
    ENDIF.
  ENDLOOP.

  IF it_pernr[] IS INITIAL.
    MESSAGE i000(db) WITH 'Nessun cid selezionato!'.
  ELSE.
    IF p_test IS INITIAL.
*richiesta della conferma da parte dell'utente
      PERFORM richiedi_conferma USING reply.
    ELSE.
      reply = '1'.
    ENDIF.
    IF reply = '1'.
      PERFORM delete_for_all_employees.
    ELSE.
      CHECK p_test IS INITIAL.
      MESSAGE e000(db) WITH 'Transazione interrotta dall"utente'.
    ENDIF.

  ENDIF.

ENDFORM.                    " CANCELLAZIONE_EVENTO

*
*&---------------------------------------------------------------------*
*&      Form  DELETE_FOR_ALL_EMPLOYEES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM delete_for_all_employees.

  DATA: pa(6),
        v_date(10),
        v_program(8).

  PERFORM open_session.

  v_endda = p_begda - 1.
  SKIP.
  LOOP AT it_pernr.

    CLEAR it_riapertura[].
    CLEAR it_riapertura.


    LOOP AT inftab.


      CONCATENATE 'PA' inftab-infty INTO pa.
      SELECT SINGLE * FROM (pa) INTO CORRESPONDING FIELDS OF it_appo
             WHERE pernr = it_pernr-pernr
               AND begda = it_pernr-begda.
      IF sy-subrc = 0.

        SELECT SINGLE * FROM (pa) INTO CORRESPONDING FIELDS OF it_appo
               WHERE pernr = it_pernr-pernr
                 AND begda > it_appo-endda.
        IF sy-subrc <> 0.
*cancellazione record relativo all'evento
          IF p_test = 'X'.
            WRITE:/ 'canc..', it_pernr-pernr,
                    inftab-infty, it_pernr-begda.
          ELSE.

*dati per batch input
            fill$bdcdata 'X' 'SAPMP50A' '1000'.
            fill$bdcdata ' ' 'RP50G-PERNR' it_pernr-pernr.
            fill$bdcdata ' ' 'RP50G-CHOIC' inftab-infty.
            IF inftab-infty = '0000'.
              fill$bdcdata ' ' 'RP50G-SUBTY' p_event.
            ENDIF.
            CONCATENATE it_pernr-begda+6(2)
                  '.'
                  it_pernr-begda+4(2)
                  '.'
                  it_pernr-begda+0(4) INTO v_date.
            fill$bdcdata ' ' 'RP50G-BEGDA' v_date.
            fill$bdcdata ' ' 'BDC_OKCODE' '=DEL'.
            SELECT SINGLE repid INTO v_program FROM t777d
                   WHERE infty = inftab-infty.
*            CONCATENATE 'MP' inftab-infty '00' INTO v_program.
            fill$bdcdata 'X' v_program '2000'.
            fill$bdcdata ' ' 'BDC_OKCODE' '=UPDL'.


            PERFORM insert_session.

          ENDIF.
        ELSE.
   MESSAGE i000(db) WITH 'Esistono record successivi' pa it_pernr-pernr.
          APPEND it_pernr TO it_errori.
          DELETE it_pernr.
          EXIT.
        ENDIF.
      ENDIF.
    ENDLOOP.


**riapertura record vecchi
*    LOOP AT it_riapertura.
*      CONCATENATE 'PA' it_riapertura-infty INTO pa.
*      SELECT SINGLE * FROM (pa) INTO CORRESPONDING FIELDS OF it_appo
*             WHERE pernr = it_riapertura-pernr
*               AND endda = v_endda.
*      IF sy-subrc = 0.
*        IF p_test = 'X'.
*          WRITE:/ 'prolung..', it_riapertura-pernr,
*                  it_riapertura-infty, it_riapertura-endda.
*        ELSE.
** SELECT SINGLE * FROM (pa) INTO CORRESPONDING FIELDS OF it_appo
**                   WHERE pernr = it_riapertura-pernr
**                     AND endda = v_endda.
**          MOVE it_riapertura-endda TO it_appo-endda.
**          UPDATE (pa) FROM it_riapertura.
**          COMMIT WORK AND WAIT.
*        ENDIF.
*      ENDIF.
*    ENDLOOP.

  ENDLOOP.

  PERFORM close_session.


ENDFORM.                    " DELETE_FOR_ALL_EMPLOYEES


*
*&---------------------------------------------------------------------*
*&      Form  OPEN_SESSION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM open_session.


  IF p_test <> 'X'.

    CONCATENATE v_group '_' p_begda
       INTO v_group.
    REFRESH bdcdata.

    CALL FUNCTION 'BDC_OPEN_GROUP'
         EXPORTING
              client = sy-mandt
              group  = v_group
              keep   = 'X'
              user   = sy-uname.
    IF sy-subrc = 0.
    ENDIF.

  ENDIF.

ENDFORM.                    " OPEN_SESSION


*
*&---------------------------------------------------------------------*
*&      Form  INSERT_SESSION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM insert_session.

  IF p_test <> 'X'.

    CALL FUNCTION 'BDC_INSERT'
         EXPORTING
              tcode     = 'PA30'
         TABLES
              dynprotab = bdcdata.

    IF sy-subrc <> 0.
    ENDIF.

  ENDIF.

  REFRESH bdcdata.

ENDFORM.                    " INSERT_SESSION


*
*&---------------------------------------------------------------------*
*&      Form  CLOSE_SESSION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM close_session.

  IF p_test <> 'X'.
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    IF sy-subrc = 0.
      PERFORM execute_session.
    ELSE.
      MESSAGE i000(db) WITH 'Sessione ' v_group ' non eseguibile'.
    ENDIF.
  ENDIF.

ENDFORM.                    " CLOSE_SESSION

*&---------------------------------------------------------------------*
*&      Form  LOG_ESECUZIONE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM log_esecuzione.

  IF NOT it_pernr[] IS INITIAL.
    SKIP.
    FORMAT COLOR 5 INTENSIFIED OFF.
    WRITE:/ 'Matricole elaborate con successo:'.
    FORMAT COLOR OFF INTENSIFIED ON.
    SKIP.
    IF p_test <> 'X'.
      FORMAT HOTSPOT ON.
      WRITE: AT 2 icon_alarm AS ICON.
      FORMAT HOTSPOT OFF.
      WRITE: AT 7 'log del batch input per la sessione: ', v_group.
      SKIP.
      FORMAT COLOR 5 INTENSIFIED OFF.
      WRITE 'Contenuto della sessione: '.
      FORMAT COLOR OFF INTENSIFIED ON.
    ENDIF.
    LOOP AT it_pernr.
      WRITE:/ it_pernr-pernr.
    ENDLOOP.
    SKIP.
    IF NOT it_errori[] IS INITIAL.
      SKIP.
      FORMAT COLOR 6 INTENSIFIED OFF.
      WRITE:/ 'Matricole scartate per presenza di eventi successivi'.
      FORMAT COLOR OFF INTENSIFIED ON.
      SKIP.
      LOOP AT it_errori.
        WRITE:/ it_errori-pernr.
      ENDLOOP.
    ENDIF.
  ELSE.
    IF NOT it_errori[] IS INITIAL.
      SKIP.
      FORMAT COLOR 6 INTENSIFIED OFF.
      WRITE:/ 'Matricole scartate per presenza di eventi successivi'.
      FORMAT COLOR OFF INTENSIFIED ON.
      SKIP.
      LOOP AT it_errori.
        WRITE:/ it_errori-pernr.
      ENDLOOP.
    ENDIF.
  ENDIF.

ENDFORM.                    " LOG_ESECUZIONE

*


*&---------------------------------------------------------------------*
*&      Form  EXECUTE_SESSION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM execute_session.

  SUBMIT rsbdcsub
     WITH mappe = v_group
     WITH von   = sy-datum
     WITH bis   = sy-datum
     WITH z_verarb = 'X'
     WITH z_fehler = ' '
     WITH bathsys  = 'X'
     WITH log      = 'X'
  AND RETURN EXPORTING LIST TO MEMORY.
*    AND RETURN.


ENDFORM.                    " EXECUTE_SESSION


*
*&---------------------------------------------------------------------*
*&      Form  RICHIEDI_CONFERMA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_REPLY  text
*----------------------------------------------------------------------*
FORM richiedi_conferma USING    reply.


  CALL FUNCTION 'TR_POPUP_TO_CONFIRM'
       EXPORTING
          iv_titlebar           = 'Arinso'
          iv_text_question      = 'Cancellazione effettiva dal database'
          iv_text_button1       = 'Vai tranquillo...' "(d01)
          iv_text_button2       = 'Ma che sei matto?' "(d02)
          iv_icon_button1       = '@15@'
          iv_icon_button2       = '@8N@'
          iv_with_cancel_button = ' '
      IMPORTING
           ev_answer             = reply
            .



ENDFORM.                    " RICHIEDI_CONFERMA

*
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> HR All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.