Mostrando entradas con la etiqueta ABAP. Mostrar todas las entradas
Mostrando entradas con la etiqueta ABAP. Mostrar todas las entradas

miércoles, 15 de mayo de 2013

0HR_PA_1: BEGDAT-1 para salidas, status empleado ='0'


Un empleado cesado el  1.4.2011 en la  PA20,  va a tener en el extractor una fecha de inicio para la salida de la empresa de 31.03.2011:

 En la página Help de SAP se indica: “A special date calculation takes place for leaving actions. Actions are only identified as leaving actions if the employment status of the action is changed to the value withdrawn (STAT2 = o). For these actions, one day is subtracted from the start date of the action” http://help.sap.com/saphelp_nw04/helpdata/en/29/02b43947f80c74e10000000a114084/content.htm

Notas: Note 381239 - HR BW: Counting leavings using actions

Si queremos que en el BW sea de 1.4.2011 tenemos que Incluir este código en la transformación:


Para dia:
* ABB 15.05.2013
* 0HR_PA_1 extractor returns in BW day -1 compared with that of
* ECC whenever the Employee Status change on incative (=0)  and the
* action type ( "10") .
* To avoid this in BW you may insert in the trasformation sample code:
* Note 381239 - HR BW: Counting leavings using actions
    if SOURCE_FIELDS-STAT2 = '0' and SOURCE_FIELDS-MASSN = '10'.
      RESULT = SOURCE_FIELDS-CALDAY + 1.
else.
      RESULT = SOURCE_FIELDS-CALDAY.
    endif.

* ABB 15.05.2013
Para mes:
    data: aux_day TYPE D.
    clear aux_day.
    if SOURCE_FIELDS-STAT2 = '0' and SOURCE_FIELDS-MASSN = '10'.
      aux_day = SOURCE_FIELDS-CALDAY + 1.
      RESULT = aux_day(6).
    else.
      RESULT = SOURCE_FIELDS-CALDAY(6).
    endif.

jueves, 9 de mayo de 2013

R3: EXIT_SAPLRSAP_004: Modify DataSource 0GLACCEXT_T011_HIER, 0PROFIT_CTR_0106_HIER, 0ACCOUNT_0109_HIER


CASE i_datasource.
  WHEN '0GLACCEXT_T011_HIER'.
    PERFORM jerarquia_balance TABLES c_t_hienode  c_t_hienode3.
    PERFORM jerarquia_carpetas TABLES C_T_FOLDERT.

  WHEN '0PROFIT_CTR_0106_HIER'.
      PERFORM profit_carpetas TABLES C_T_FOLDERT.

  WHEN '0ACCOUNT_0109_HIER'.
    PERFORM cuenta_carpetas TABLES C_T_FOLDERT.

ENDCASE.


*****************************


*&---------------------------------------------------------------------*
*&      Form  jerarquia_balance
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_T_DATA  text
*----------------------------------------------------------------------*

TYPE-POOLS: rsap.

TYPES: BEGIN OF s_reorg,
   nodo TYPE rshienodid,
   nodo_n TYPE rshienodid,
  END OF s_reorg.

TYPES t_reorg TYPE TABLE OF s_reorg.

TYPES: BEGIN OF s_node3,
  nodeid(8) TYPE n,
  iobjnm(30) TYPE c,
  nodename(32) TYPE c,
  tlevel(2) TYPE n,
  link TYPE c,
  parentid(8) TYPE n,
  childid(8) TYPE n,
  nextid(8) TYPE n,
  datefrom TYPE d,
  dateto TYPE d,
  intervl TYPE c,
  fieldnm(30) TYPE c,
  glaccext(18) TYPE c,
  rsign TYPE c,
  plumi TYPE c,
END OF s_node3.


*&---------------------------------------------------------------------*
*&      Form  jerarquia_balance
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_T_DATA   text
*----------------------------------------------------------------------*
FORM jerarquia_balance  TABLES i_t_data TYPE rsap_t_hienode
                               i_t_data3.

  DATA it_nodos TYPE rsap_t_hienode.
  DATA wa_nodos TYPE rsap_s_hienode.

  DATA wa_nodos_companyb33 TYPE rsap_s_hienode.
  DATA wa_nodos_companyb195 TYPE rsap_s_hienode.
  DATA lineas TYPE i.
  DATA nod_piv TYPE rshienodid.
  DATA ztab LIKE sy-tabix.
  DATA ztab_companyb33 LIKE sy-tabix.
  DATA ztab_companyb195 LIKE sy-tabix.

  DATA nodo_companyb126 TYPE rshienodid.
  DATA nodo_companyb138 TYPE rshienodid.
  DATA nodo_companybobsnotes TYPE rshienodid.
*  DATA nodo_companyb2 TYPE rshienodid.
  DATA nodo_companyb26 TYPE rshienodid.
*

*
  READ TABLE i_t_data INTO wa_nodos
    WITH KEY nodename = 'companyB126'.

  IF sy-subrc EQ 0.
    nodo_companyb126 = wa_nodos-nodeid.
  ENDIF.

  READ TABLE i_t_data INTO wa_nodos
  WITH KEY nodename = 'companyB138'.

  IF sy-subrc EQ 0.
    nodo_companyb138 = wa_nodos-nodeid.
  ENDIF.

  READ TABLE i_t_data INTO wa_nodos
  WITH KEY nodename = 'companyB26'.

  IF sy-subrc EQ 0.
    nodo_companyb26 = wa_nodos-nodeid.
  ENDIF.

  READ TABLE i_t_data INTO wa_nodos
  WITH KEY nodename = 'companyB0BSNOTES'.

  IF sy-subrc EQ 0.
    nodo_companybobsnotes = wa_nodos-nodeid.
  ENDIF.

*  READ TABLE i_t_data INTO wa_nodos
*  WITH KEY nodename = 'companyB2'.
*
*  IF sy-subrc EQ 0.
*    nodo_companyb2 = wa_nodos-nodeid.
*  ENDIF.



* En esta extraccion tenemos que colocar
* el nodo companyB138-Resultado del ejercicio 
* entre los nodos companyB33 y companyB195
* Así el nodo companyB138 tiene que ser nodo HIJO del nodo companyB26


  DATA it_reorg TYPE t_reorg.
  DATA wa_reorg TYPE s_reorg.

  DESCRIBE TABLE i_t_data LINES lineas.

  READ TABLE i_t_data INTO wa_nodos INDEX lineas.

  IF sy-subrc EQ 0.
    nod_piv = wa_nodos-nodeid.
  ENDIF.


  LOOP AT i_t_data INTO wa_nodos.
    IF wa_nodos-nodeid > nodo_companyb126.                      "1277
      EXIT.
    ENDIF.
    IF wa_nodos-nodeid >= nodo_companyb138. "875
      DELETE i_t_data INDEX sy-tabix.

      ADD 1 TO nod_piv.
      wa_reorg-nodo = wa_nodos-nodeid.
      wa_reorg-nodo_n = nod_piv.

      APPEND wa_reorg TO it_reorg.
      ADD 2 TO wa_nodos-tlevel.
      APPEND wa_nodos TO it_nodos.
    ENDIF.
  ENDLOOP.

  LOOP AT it_nodos INTO wa_nodos.

    IF wa_nodos-nodeid <> nodo_companyb138. "875
      ztab = sy-tabix.


      PERFORM dame_nuevo_nodo
                  TABLES
                     it_reorg
                  USING
                     wa_nodos-nodeid.

      PERFORM dame_nuevo_nodo
                  TABLES
                     it_reorg
                  USING
                     wa_nodos-parentid.

      PERFORM dame_nuevo_nodo
                  TABLES
                     it_reorg
                  USING
                     wa_nodos-childid.

      PERFORM dame_nuevo_nodo
                  TABLES
                     it_reorg
                  USING
                     wa_nodos-nextid.

      MODIFY it_nodos FROM wa_nodos INDEX ztab.
    ENDIF.

  ENDLOOP.


*------------------------------

  LOOP AT it_nodos INTO wa_nodos WHERE nodeid = nodo_companyb138. "875
    ztab = sy-tabix.

    PERFORM dame_nuevo_nodo
                TABLES
                   it_reorg
                USING
                   wa_nodos-nodeid.
    PERFORM dame_nuevo_nodo
                TABLES
                   it_reorg
                USING
                   wa_nodos-childid.

    READ TABLE i_t_data INTO wa_nodos_companyb33
    WITH KEY nodename = 'companyB33'.

    IF sy-subrc EQ 0.
      ztab_companyb33 = sy-tabix.
      wa_nodos_companyb33-nextid = wa_nodos-nodeid.
      MODIFY i_t_data FROM wa_nodos_companyb33 INDEX ztab_companyb33.
    ENDIF.


    READ TABLE i_t_data INTO wa_nodos_companyb195
    WITH KEY nodename = 'companyB195'.

    IF sy-subrc EQ 0.
      ztab_companyb195 = sy-tabix.
      wa_nodos-nextid = wa_nodos_companyb195-nodeid.
    ENDIF.

    MODIFY it_nodos FROM wa_nodos INDEX ztab.

  ENDLOOP.

*****************

*  DATA ztab_companyb180 LIKE sy-tabix.
*  DATA wa_nodos_companyb180 TYPE rsap_s_hienode.
*
*
*
*  READ TABLE i_t_data INTO wa_nodos_companyb180
*  WITH KEY nodename = 'companyB180'.
*
*  IF sy-subrc EQ 0.
*    ztab_companyb180 = sy-tabix.
*    wa_nodos_companyb180-nextid = nodo_companybobsnotes. "1278
*    MODIFY i_t_data FROM wa_nodos_companyb180 INDEX ztab_companyb180.
*  ENDIF.

**********************************************
  DATA ztab_companyb0bsnotes LIKE sy-tabix.
  DATA wa_nodos_companyb0bsnotes TYPE rsap_s_hienode.


  READ TABLE i_t_data INTO wa_nodos_companyb0bsnotes
  WITH KEY nodename = 'companyB0BSNOTES'.

  IF sy-subrc EQ 0.
    ztab_companyb0bsnotes = sy-tabix.
    CLEAR wa_nodos_companyb0bsnotes-childid.
    MODIFY i_t_data
    FROM wa_nodos_companyb0bsnotes INDEX ztab_companyb0bsnotes.
  ENDIF.

*******************************
  DATA ztab_companyb138 LIKE sy-tabix.
  DATA wa_nodos_companyb138 TYPE rsap_s_hienode.



  READ TABLE it_nodos INTO wa_nodos_companyb138
  WITH KEY nodename = 'companyB138'.

  IF sy-subrc EQ 0.
    ztab_companyb138 = sy-tabix.
    wa_nodos_companyb138-parentid = nodo_companyb26. "483
    wa_nodos_companyb138-tlevel = 5.
    MODIFY it_nodos FROM wa_nodos_companyb138 INDEX ztab_companyb138.
  ENDIF.

********************************************
  DATA ztab_companyb125 LIKE sy-tabix.
  DATA wa_nodos_companyb125 TYPE rsap_s_hienode.



  READ TABLE it_nodos INTO wa_nodos_companyb125
  WITH KEY nodename = 'companyB125'.

  IF sy-subrc EQ 0.
    ztab_companyb125 = sy-tabix.
    wa_nodos_companyb125-tlevel = 6.
    MODIFY it_nodos FROM wa_nodos_companyb125 INDEX ztab_companyb125.
  ENDIF.

********************************************
  DATA ztab_companyb126 LIKE sy-tabix.
  DATA wa_nodos_companyb126 TYPE rsap_s_hienode.



  READ TABLE it_nodos INTO wa_nodos_companyb126
  WITH KEY nodename = 'companyB126'.

  IF sy-subrc EQ 0.
    ztab_companyb126 = sy-tabix.
    wa_nodos_companyb126-tlevel = 6.
    MODIFY it_nodos FROM wa_nodos_companyb126 INDEX ztab_companyb126.
  ENDIF.


*******************************
  APPEND LINES OF it_nodos TO i_t_data.



* sincroniza

  i_t_data3[] = i_t_data[].

  FIELD-SYMBOLS TYPE s_node3.
  DATA long TYPE i.

  LOOP AT i_t_data3 ASSIGNING .

    IF -iobjnm = '0HIER_NODE'.
      -fieldnm = 'NODNAME'.
    ENDIF.

    IF -iobjnm = '0GLACCEXT'.
      -fieldnm = 'GLACCEXT'.
      -glaccext = -nodename.
      long = STRLEN( -nodename ).
      long = long - 2.
      IF -nodename+long = '1A'.
        -plumi = 1.
      ENDIF.
      IF -nodename+long = '2A'.
        -plumi = 1.
      ENDIF.

    ENDIF.

  ENDLOOP.







ENDFORM.                    " jerarquia_balance

*&---------------------------------------------------------------------*
*&      Form  dame_nuevo_nodo
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_REORG    text
*      -->NODO       text
*----------------------------------------------------------------------*
FORM dame_nuevo_nodo TABLES it_reorg TYPE t_reorg
                     USING nodo TYPE rshienodid.

  DATA wa_reorg TYPE s_reorg.

  IF NOT nodo IS INITIAL.

    READ TABLE it_reorg INTO wa_reorg
     WITH KEY nodo = nodo.

    IF sy-subrc EQ 0.
      nodo = wa_reorg-nodo_n.
    ELSE.
      BREAK-POINT.
    ENDIF.

  ENDIF.

ENDFORM.                    "dame_nuevo_nodo

*----------------------------------------------------------------------*
FORM jerarquia_carpetas TABLES C_T_FOLDERT TYPE RSAP_T_FOLDERT.
*  LOOP at C_T_FOLDERT..
*    C_T_FOLDERT-LANGU = 'EN'.
*    MODIFY C_T_FOLDERT.
*  ENDLOOP.


ENDFORM.                    "jerarquia_carpetas
*----------------------------------------------------------------------*
FORM profit_carpetas TABLES C_T_FOLDERT  TYPE RSAP_T_FOLDERT.

  LOOP at C_T_FOLDERT..

    IF C_T_FOLDERT-LANGU = 'E'.
      select single DESCRIPT into C_T_FOLDERT-TXTLG
      from SETHEADERT where
       LANGU   = 'S' and
       SUBCLASS = C_T_FOLDERT-NODENAME(4) and
       SETCLASS = '0106' and
       SETNAME = C_T_FOLDERT-NODENAME+4(24).

      C_T_FOLDERT-TXTSH = C_T_FOLDERT-TXTLG.
      C_T_FOLDERT-TXTMD = C_T_FOLDERT-TXTLG.
    ENDIF.


    MODIFY C_T_FOLDERT.
  ENDLOOP..
ENDFORM.                    "profit_carpetas
*----------------------------------------------------------------------*
FORM cuenta_carpetas TABLES C_T_FOLDERT  TYPE RSAP_T_FOLDERT.
  LOOP at C_T_FOLDERT..

    IF C_T_FOLDERT-LANGU = 'E'.
      select single DESCRIPT into C_T_FOLDERT-TXTLG
      from SETHEADERT where
       LANGU   = 'S' and
       SUBCLASS = C_T_FOLDERT-NODENAME(4) and
*       SETCLASS = '0106' and
       SETNAME = C_T_FOLDERT-NODENAME+4(10).

      C_T_FOLDERT-TXTSH = C_T_FOLDERT-TXTLG.
      C_T_FOLDERT-TXTMD = C_T_FOLDERT-TXTLG.
    ENDIF.


    MODIFY C_T_FOLDERT.
  ENDLOOP..
ENDFORM.                    "cuenta_carpetas

viernes, 26 de abril de 2013

R3: EXIT_SAPLRSAP_004: 4R_SAKNR_0000_HIER


* In this example, Sets are extracted for DataSource 4R_SAKNR_0000_HIER
* they are compounded by a value of 'TEST' (for compound 0CHRT_ACCTS)
* The exit is called for any hierarchy extracted from OLTP to BW,
* therefore we have to make sure only desired FI-SL-Sets are modified.
* This information is available in I_DATASOURCE and I_S_HIEBAS.
*
IF I_DATASOURCE = '4R_SAKNR_0000_HIER'   "<--- datasource="" o:p="" your="">
   AND I_S_HIEBAS-HCLASS = '0000'.       "Hierarchy class of FI-SL-Sets

* Add compound value to hierarchy leaves
  LOOP AT C_T_HIENODE WHERE IOBJNM <> '0HIER_NODE'.
*   Shift nodename right to get space for compound characteristic
    SHIFT C_T_HIENODE-NODENAME RIGHT BY 4 PLACES.
*   Put chart of accounts into first 4 places
    C_T_HIENODE-NODENAME(4) = 'TEST'.      "<-- compound="" o:p="" value="" your="">
    MODIFY C_T_HIENODE.
  ENDLOOP.

* Add compound value to intervals in the same fashion
  LOOP AT C_T_HIEINTV.
    SHIFT C_T_HIEINTV-LEAFFROM RIGHT BY 4 PLACES.
    C_T_HIEINTV-LEAFFROM(4) = 'TEST'.      "<-- compound="" o:p="" value="" your="">
    SHIFT C_T_HIEINTV-LEAFTO RIGHT BY 4 PLACES.
    C_T_HIEINTV-LEAFTO(4) = 'TEST'.        "<-- compound="" o:p="" value="" your="">
    MODIFY C_T_HIEINTV.
  ENDLOOP.

ENDIF.

Carga en masa de fotos


REPORT ZHR_BDC_UPLOADPIC

     NO STANDARD PAGE HEADING LINE-SIZE 255.



INCLUDE
INCLUDE BDCRECX1.

I N T E R N A L T A B L E S
DATA : BEGIN OF IT_DATA OCCURS 0,

        RP50G-PERNR(8), " LIKE RP50G-PERNR,
        RLGRAP-FILENAME(128),
     END OF IT_DATA.
S T A R T - O F - S E L E C T I O N
START-OF-SELECTION.

PERFORM OPEN_GROUP.
CALL FUNCTION 'UPLOAD'
     EXPORTING
          FILENAME                = 'C:\PICTURE.TXT'
          FILETYPE                = 'DAT'
     TABLES
          DATA_TAB                = IT_DATA
     EXCEPTIONS
          CONVERSION_ERROR        = 1
          INVALID_TABLE_WIDTH     = 2
          INVALID_TYPE            = 3
          NO_BATCH                = 4
          UNKNOWN_ERROR           = 5
          GUI_REFUSE_FILETRANSFER = 6
          OTHERS                  = 7.
IF SY-SUBRC NE 0.
  WRITE : / 'Unable to upload data'.
  STOP.
ENDIF.
LOOP AT IT_DATA.
  PERFORM BDC_DYNPRO      USING 'OANEWCON' '0100'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'TOAOM-AR_OBJECT'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=NEW'.
  PERFORM BDC_FIELD       USING 'TOAOM-SAP_OBJECT'
                                'PREL'.
  PERFORM BDC_FIELD       USING 'TOAOM-AR_OBJECT'
                                'HRICOLFOTO'.
  PERFORM BDC_DYNPRO      USING 'SAPLSJ01' '0200'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'FIELD_VALUES-INPUT(02)'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=OK'.
  PERFORM BDC_FIELD       USING 'FIELD_VALUES-INPUT(01)'
                            IT_DATA-RP50G-PERNR.       "'10002'.
  PERFORM BDC_FIELD       USING 'FIELD_VALUES-INPUT(02)'
                                '0002'.
  PERFORM BDC_DYNPRO      USING 'SAPLOPTM' '0105'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'SAPB-SAPPOOLINF'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=OKAY'.
  PERFORM BDC_FIELD       USING 'SAPB-SAPPOOLINF'
                            IT_DATA-RLGRAP-FILENAME.      "JPG'.
  PERFORM BDC_TRANSACTION USING 'OAOH'.
  clear IT_DATA-RLGRAP-FILENAME.
  ENDLOOP.
  PERFORM CLOSE_GROUP.

Infopaquete ABAP ejemplos


**********30 dias hacia atras**************************************+
program conversion_routine.
* Type pools used by conversion program
type-pools: rsarc, rsarr, rssm.
tables: rssdlrange.
* Global code used by conversion rules
*$*$ begin of global - insert your declaration only below this line  *-*
* TABLES: ...
* DATA:   ...
*$*$ end of global - insert your declaration only before this line   *-*
* -------------------------------------------------------------------
*     InfoObject      = Z_BUDAT
*     Fieldname       = BUDAT
*     data type       = DATS
*     length          = 000008
*     convexit        =
* -------------------------------------------------------------------
form compute_BUDAT
  tables l_t_range structure rssdlrange
  changing p_subrc like sy-subrc.
*       Insert source code to current selection field
*$*$ begin of routine - insert your code only below this line        *-*
data: l_idx like sy-tabix, l_budat_low like sy-datum.

  read table l_t_range with key fieldname = 'BUDAT'.
  l_idx = sy-tabix.

* Se calcula la fecha de dos día hacia atras
*  clear l_budat_low.
  l_budat_low = sy-datum.
  l_budat_low = (  l_budat_low - 29 ).

* Se pone la fecha de dos días hacia atras como límite inferior del
* rango de fechas, el límite superior la fecha que venía y el
* signo de igual se pasa a between.
*  clear l_t_range-high.
  l_t_range-high   = sy-datum.
  l_t_range-low    = l_budat_low.
  l_t_range-option = 'BT'.
  l_t_range-sign   = 'I'.
  modify l_t_range index l_idx.

  p_subrc = 0.

*$*$ end of routine - insert your code only before this line         *-*
endform.

*****************************************************************+
*********ultimo dia del mes******************************************
data: l_idx like sy-tabix.
read table l_t_range with key
     fieldname = 'STIDA'.
l_idx = sy-tabix.
*....
data: u_fecha like sy-datum.
* Se calcula la fecha
  u_fecha = sy-datum.
* Ultimo dia do mes
      CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
        EXPORTING
          DAY_IN            = u_fecha
        IMPORTING
          LAST_DAY_OF_MONTH = u_fecha
        EXCEPTIONS
          DAY_IN_NOT_VALID  = 1
          OTHERS            = 2.
* rango de fechas
  l_t_range-high   = u_fecha.
  l_t_range-low    = u_fecha.
  l_t_range-option = 'BT'.
  l_t_range-sign   = 'I'.
  modify l_t_range index l_idx.

TEVEN: infotipo IT2011


Detallo un poco mas como tratar el Infotipo 2011.

Los registros del IT2011 no se almacenan en una tabla tipo PANNNN, con NNNN = Nº Infotipo, sino en la tabla TEVEN, por lo que funciones como HR_READ_INFOTYPE, no sirven para leer los datos del IT2011, entonces un ejemplo de lectura del IT2011 es como el siguiente:


Código:
     SELECT * FROM teven APPENDING TABLE it_teven
             WHERE pernr EQ gt_pernr-pernr
               AND ldate EQ gf_fecha
               AND stokz EQ space.


A su vez, para borrar un registro es aconsejable hacerlo de la siguiente manera:


Código:
   IF teven-stokz EQ space.
     teven-stokz = 'X'.
     teven-uname = sy-uname.
     teven-aedtm = sy-datum.
     UPDATE teven.
   ENDIF.


BAPI_CC1_UPLOAD_TIMEEVENT.

Code para transacción para lanzar cadenas


&---------------------------------------------------------------------*
*& Report  ZBWPR00
*&
*

REPORT  ZBWPR00.

************************************************************************
* VARIABLES
************************************************************************
CONSTANTS:  c_co(13) TYPE C VALUE 'ZPC_IG_TRAN03', "Comercial
            c_lo(13) TYPE C VALUE 'ZPC_IG_TRAN04', "Logística
            c_cg(13) TYPE C VALUE 'ZPC_IG_TRAN05', "Control de Gestión
            c_pr(13) TYPE C VALUE 'ZPC_IG_TRAN02', "Producción
            c_ca(13) TYPE C VALUE 'ZPC_IG_TRAN06', "Calidad
            c_fi(13) TYPE C VALUE 'ZPC_IG_TRAN07', "Finanzas
            c_rh(13) TYPE C VALUE 'ZPC_IG_TRAN01'. "Recursos Humanos

DATA: V_CHAIN TYPE RSPC_CHAIN. "Cadena de proceso


************************************************************************
* PANTALLA SELECCIÓN
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

PARAMETERS:
            cb_co   AS CHECKBOX, "Comercial
            cb_lo   AS CHECKBOX, "Logística
            cb_cg   AS CHECKBOX, "Control de Gestión
            cb_pr   AS CHECKBOX, "Producción
            cb_ca   AS CHECKBOX, "Calidad
            cb_fi   AS CHECKBOX, "Finanzas
            cb_rh   AS CHECKBOX. "Recursos Humanos

SELECTION-SCREEN END OF BLOCK b1.

************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION.


   MESSAGE I000(zbw).

   IF cb_co IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_co.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.

   IF cb_lo IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_lo.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.

   IF cb_cg IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_cg.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.

   IF cb_pr IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_pr.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.


   IF cb_ca IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_ca.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.


   IF cb_fi IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_fi.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.

   IF cb_rh IS NOT INITIAL.

         CLEAR V_CHAIN.
         V_CHAIN = c_rh.
         PERFORM F_CHAIN_START USING V_CHAIN.

   ENDIF.



*****************************************************************
* RUTINAS
*****************************************************************

*&---------------------------------------------------------------------*
*&      Form  F_CHAIN_START
*&---------------------------------------------------------------------*
*    Ejecutar cadena de procesos
*----------------------------------------------------------------------*
*      -->Pe_CHAIN  text
*----------------------------------------------------------------------*
FORM F_CHAIN_START  USING  Pe_CHAIN.

  CALL FUNCTION 'RSPC_CHAIN_START' IN BACKGROUND TASK
*                     [AS SEPARATE UNIT]
*                     [DESTINATION dest]
     EXPORTING
          i_chain             = Pe_CHAIN
          i_synchronous       = 'X'.
.
COMMIT WORK.


*   CALL FUNCTION 'RSPC_CHAIN_START'
*     EXPORTING
*          i_chain             = Pe_CHAIN
*          i_synchronous       = 'X'.

ENDFORM.                    " F_CHAIN_START

Coger el ultimo valor de un CHAR


opción 1

data: str_aux type string.
str_aux =
data: length type i.
length = strlen( str_aux ).
if not length is initial.
= str_aux+
perdon
length = lenght - 1.
= str_aux+length(1).
endif.


opcion 2
data: str_aux type string.
str_aux = .
shift str_aux by 1 places RIGHT CIRCULAR.
if not str_aux is initial.
= str_aux(1).
endif.

borrado con patron


  DELETE DATA_PACKAGE WHERE  COMP_CODE = 'YYYY'
  AND ( MATERIAL NP 'K*'
       AND MATERIAL NP 'W*'
       AND MATERIAL NP 'H*'
       AND MATERIAL NP 'L*').

Rutina: Año Bisiesto // Fisper-->Calmonth


data: year type /BI0/OICALYEAR,
      tri  type /BI0/OICALQUART1,
      dia  type c LENGTH 2,
      mes  type /BI0/OICALMONTH2,
      yearmes  type /BI0/OICALMONTH.

INCLUDE rs_bct_hr_update_rules_general.



***********
  clear: mes, year, dia, yearmes.
  year = COMM_STRUCTURE-CALMONTH(4).
  year = year + 1.
  mes  = COMM_STRUCTURE-CALMONTH+4(2).
  dia  = COMM_STRUCTURE-CALDAY+6(2).

  if mes eq '02'.
    concatenate year mes into yearmes.
    PERFORM CALCULATE_ULTIMO
        USING yearmes
               RECORD_NO
               RECORD_ALL
               SOURCE_SYSTEM
        CHANGING RESULT
                 RETURNCODE.
 else.
  concatenate year mes dia into RESULT.
endif.




************************************************************+
************************************************************

data: year type /BI0/OICALYEAR,
      tri  type /BI0/OICALQUART1,
      dia  type c LENGTH 2,
      mes  type /BI0/OICALMONTH2.

clear: mes, year.
  year = COMM_STRUCTURE-CALMONTH(4).
  year = year + 1.
  mes  = COMM_STRUCTURE-CALMONTH+4(2).
  dia  = COMM_STRUCTURE-CALDAY+6(2).
  if dia eq '29'.
    dia = '28'.
  endif.
  concatenate year mes dia into RESULT.


*************************************************************
*************************************************************

data: mes type /BI0/OICALMONTH2,
      year type /BI0/OICALYEAR.

clear: mes, year.

year = TRAN_STRUCTURE-FISCPER(4) .
mes = TRAN_STRUCTURE-FISCPER+5(2) .

if mes > 12.
mes = 12.
endif.

if mes = 00.
mes = 01.
endif.

concatenate year mes into RESULT.

martes, 5 de febrero de 2013

2 last characters of a string

DATA: int TYPE I, PEP TYPE C,
AUX_PEP TYPE /BI0/OIWBS_ELEMT.



CLEAR: INT, AUX_PEP.
PEP = COMM_STRUCTURE-WBS_ELEMT.
DESCRIBE FIELD PEp LENGTH INT IN CHARACTER MODE.
INT = INT - 2.
* result value of the routine
AUX_PEP = COMM_STRUCTURE-WBS_ELEMT+INT(2).
IF AUX_PEP ca SY-ABCDE.
RESULT = AUX_PEP.
ELSE.
RESULT = 99.
ENDIF.

lunes, 4 de febrero de 2013

ABAP HR


Edad


PERFORM CALCULATE_ULTIMO " last day of month

using SOURCE_FIELDS-CALMONTH

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

CHANGING ULTIMO

RETURNCODE.



CLEAR: EMPLOYEE_MD, PERSON_MD.

CLEAR: EMPLOYEE_WA, PERSON_WA.



PERFORM READ_MD_PERSON

using SOURCE_FIELDS-employee

SOURCE_FIELDS-calmonth

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

CHANGING EMPLOYEE_WA

PERSON_WA

RETURNCODE.

EMPLOYEE_MD = EMPLOYEE_WA.

PERSON_MD = PERSON_WA.



IF NOT PERSON_MD-DATEBIRTH IS INITIAL.

RESULT = ULTIMO+0(4) - PERSON_MD-DATEBIRTH+0(4).

IF ULTIMO+4(4) LT PERSON_MD-DATEBIRTH+4(4).

RESULT = RESULT - 1.

ENDIF.

ENDIF.







%% Ocupação

if g_RECORD_NO <> RECORD_NO.

g_RECORD_NO = RECORD_NO.

clear: employee_md, person_md.

clear: employee_wa, person_wa.

endif.



perform read_md_employee

using SOURCE_FIELDS-employee

SOURCE_FIELDS-calmonth

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

changing employee_wa

RETURNCODE.

employee_md = employee_wa.

RESULT = EMPLOYEE_MD-PAYPCT.







if g_RECORD_NO <> RECORD_NO.

g_RECORD_NO = RECORD_NO.

clear: employee_md, person_md.

clear: employee_wa, person_wa.

endif.



perform read_md_employee

using SOURCE_FIELDS-employee

SOURCE_FIELDS-calmonth

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

changing employee_wa

RETURNCODE.

employee_md = employee_wa.

* fill the internal table "MONITOR", to make monitor entries



* result value of the routine

RESULT = EMPLOYEE_MD-PAYPCT / 100.







data: ultimo like sy-datum.



if g_RECORD_NO <> RECORD_NO.

g_RECORD_NO = RECORD_NO.

clear: employee_md, person_md.

clear: employee_wa, person_wa.

endif.



perform read_md_employee

using SOURCE_FIELDS-employee

SOURCE_FIELDS-calmonth

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

changing employee_wa

RETURNCODE.

employee_md = employee_wa.



perform calculate_ultimo

using SOURCE_FIELDS-calmonth

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

changing ultimo

RETURNCODE.



IF NOT EMPLOYEE_WA-ENTRYDATE IS INITIAL.

RESULT = ULTIMO+0(4) - EMPLOYEE_WA-ENTRYDATE+0(4).

IF ULTIMO+4(4) LT EMPLOYEE_WA-ENTRYDATE+4(4).

RESULT = RESULT - 1.

endif.

ENDIF.







DATA: TMP_PAYPCT TYPE I.

if g_RECORD_NO <> RECORD_NO.

g_RECORD_NO = RECORD_NO.

clear: employee_md, person_md.

clear: employee_wa, person_wa.

endif.



perform read_md_employee

using SOURCE_FIELDS-employee

SOURCE_FIELDS-calmonth

RECORD_NO

RECORD_ALL

SOURCE_SYSTEM

changing employee_wa

RETURNCODE.

employee_md = employee_wa.

* fill the internal table "MONITOR", to make monitor entries



* result value of the routine

* rounded

TMP_PAYPCT = EMPLOYEE_MD-PAYPCT.

RESULT = TMP_PAYPCT.

lunes, 13 de febrero de 2012

Edad con dos decimales, como texto

DATA: aux_date type sy-datum,
aux_year type numc4,
aux_age(200) type c.
DATA: aux_age_num type p DECIMALS 2.
Data: valor type numc5.

clear: aux_year, aux_date, aux_age, aux_age_num ,valor.
aux_year = sy-datum(4).
CONCATENATE aux_year '05' '30' into aux_date.

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = TRAN_STRUCTURE-GBDAT
I_DATUM_VON = aux_date
IMPORTING
E_TAGE = aux_age.
CALL FUNCTION 'CHAR_NUMC_CONVERSION'
EXPORTING
INPUT = aux_age
IMPORTING
NUMCSTR = aux_age_num.
valor = 100 * ( aux_age_num ) / ( 365 + ( 25 / 100 ) ) .
*RESULT = valor.

CONCATENATE valor+1(2) ',' valor+3(2) into RESULT .

miércoles, 2 de febrero de 2011

Ejemplo Rutina INIT

"loop at source_package assigning .

IF NOT ( -PO_STATUS NE 'K'
** PO is not a replication from SRM System (in case of Extended Scenario
** PO is created in SRM and a copy of the PO is created in ERP with
** PO_STATUS = K)
*
AND ( -PROCESSKEY = '001' OR "Normal purchasing order
-PROCESSKEY = '011' OR "Stock transport order
-PROCESSKEY = '021' OR "Cross company order
** Only Purchase Orders
*
-PROCESSKEY = '004' OR "Normal scheduling agreement
-PROCESSKEY = '014' OR "Stock transport agreement
-PROCESSKEY = '024') "Cross company agreement -
** or Call Offs from schedule agreements
*
AND -BWAPPLNM EQ 'MM' ).
DELETE source_package.
ENDIF.
ENDLOOP."




**************************
********************

  delete DATA_PACKAGE where ( CUST_MKT ne '009'    and
                             CUST_MKT ne '020' )   and
                           ( DOC_TYPE ne 'ZA11'    and
                             DOC_TYPE ne 'ZD11'    and
                             DOC_TYPE ne 'ZD21'    and
                             DOC_TYPE ne 'ZD31'    and
                             DOC_TYPE ne 'ZR11'    and
                             DOC_TYPE ne   'KE'  ) and
                           ( MATL_TYPE eq 'ZPPT'   or
                             MATERIAL  eq '000000000001200002' ).

martes, 18 de enero de 2011

Intervalo de edad

DATA: years type numc2,
months type numc2,
days type numc2.

CALL FUNCTION 'ZHRCM_TIME_PERIOD_CALCULATE'
EXPORTING
begda = TRAN_STRUCTURE-GBDAT
endda = sy-datum
IMPORTING
noyrs = years
nomns = months
nodys = days
EXCEPTIONS
invalid_dates = 1
overflow = 2
OTHERS = 3.

IF years < 20.
RESULT = 1.
ELSEIF years >= 20 AND years <= 29.
RESULT = 2.
ELSEIF years >= 30 AND years <= 39.
RESULT = 3.
ELSEIF years >= 40 AND years <= 49.
RESULT = 4.
ELSEIF years >= 50 AND years <= 59.
RESULT = 5.
ELSEIF years >= 60 AND years <= 69.
RESULT = 6.
ELSEIF years >= 70.
RESULT = 7.
Else. RESULT =

miércoles, 29 de diciembre de 2010

Transformation routines

1.- El clásico delete DELETE DATA_PACKAGE es ahora

DATA: l_tabix TYPE sy-tabix,
wa_source_package TYPE _ty_s_sc_1.

LOOP AT source_package
INTO wa_source_package.
l_tabix = sy-tabix.

IF ( wa_source_package-processkey NE '001' AND
wa_source_package-processkey NE '011' AND
wa_source_package-processkey NE '021' AND
wa_source_package-processkey NE '002' AND
wa_source_package-processkey NE '012' AND
wa_source_package-processkey NE '022' ) OR
wa_source_package-CPQUAOU EQ 0 OR
wa_source_package-numerator EQ 0 OR
wa_source_package-denomintr EQ 0.
DELETE
source_package
INDEX
l_tabix.

ENDIF.

ENDLOOP.
Ex: completar un dato en las subida
clear result.
select single /BIC/Z_GROUP
into result
from /BI0/PPROD_HIER
where PROD_HIER = SOURCE_FIELDS-PRDHA
and OBJVERS eq 'A'.




Ex.: 0COSTCENTER-->Cost center hierarchy

select single * from rshiedir into hier_wa where
objvers eq 'A' and
hietype eq '1' and
hienm eq hier_name and
dateto ge sy-datum .
if sy-subrc ne 0 .
raise invalid_hierarchy .
endif .

clear hier_detail .
move: hier_wa-hieid to hier_detail-hieid ,
hier_wa-objvers to hier_detail-objvers .


call function 'RSSH_HIERARCHY_READ'
exporting
i_rshiedirkey = hier_detail
* I_RSHIEDIRLOG =
i_date = sy-datum
importing
e_rshiedir = e_rshiedir
e_t_rsnodes = e_t_rsnodes
e_th_rsinterval = e_th_rsinterval
e_duplicate_leafs = e_duplicate_leafs
e_t_rsnodes_lnk = e_t_rsnodes_lnk
exceptions
invalid_hierarchy = 1
name_error = 2
iobj_not_found = 3
others = 4 .
case sy-subrc .