MUNDOSAP

Regresar   MUNDOSAP > DESARROLLO > Programación ABAP IV
Nombre de Usuario
Contraseña
Home Descargas Registrar FAQ Miembros Calendario Buscar Temas de Hoy Marcar Foros Como Leídos




 
Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Viejo 08/03/08, 18:36:59
Jarpi Jarpi is offline
Senior Member
 
Fecha de Ingreso: abr 2007
Localización: Argentina
Mensajes: 453
Función DAYS_BETWEEN_TWO_DATES

Buenas tardes para todos,

Estoy haciendo un programa en el cual me solicitan que traiga en una columna la diferencia entre dos fechas.

Para ello estoy intentando utilizar la función DAYS_BETWEEN_TWO_DATES pero sinceramente no se que parámetros debo darle y tampoco como hacer para que se me agregue una columna que no estoy declarando en la estructura.

No soy programador, soy funcional, pero estoy incursionando en esto ya que me gusta mucho.

Les pongo el programa que tengo hasta ahora, quizás alguno pueda ayudarme.

*&---------------------------------------------------------------------*
*& Report Z_LISTMEDICION
*&
*&---------------------------------------------------------------------*

*===================================================================*
REPORT Z_LISTMEDICION.
*========================== Global definitions ====================*

**
* Data Types
**

type-pools: slis.

types: begin of tp_data,
lifnr like ekko-lifnr,
aedat like ekko-aedat,
matnr like ekpo-matnr,
txz01 like ekpo-txz01,
ebeln like ekpo-ebeln,
banfn like eban-banfn,
bnfpo like eban-bnfpo,
badat like eban-badat,
lfdat like eban-lfdat,
frgdt like eban-frgdt,
belnr like ekbe-belnr,
budat like ekbe-budat,
fecha type d,
Sel,

end of tp_data,
tp_tbl_data type standard table of tp_data.


**
* Data objects
**
data: s_budat like ekbe-budat.

data: d_lfdat like eban-lfdat.

* Report data to be shown.
data: it_data type standard table of tp_data.

* Heading of the report.
data: t_heading type slis_t_listheader.

*======================= Selection Screen ==========================*

selection-screen: begin of block b1 with frame title text-t01.
DATA: w_aux_banfn like eban-banfn.
SELECT-OPTIONS s_banfn for w_aux_banfn.
PARAMETER p_werks like eban-werks OBLIGATORY.
DATA: w_aux_badat like eban-badat,
w_aux_lfdat like eban-lfdat.
SELECT-OPTIONS: s_badat for w_aux_badat,
s_lfdat for w_aux_lfdat.
PARAMETER p_bewtp like ekbe-bewtp OBLIGATORY.
selection-screen: end of block b1.

INITIALIZATION.

p_bewtp = 'E'.


*======================== Event Blocks =============================*
at selection-screen.

start-of-selection.
perform get_data using it_data.

end-of-selection.
perform build_alv using it_data t_heading.

*======================== Subroutines ==============================*


* Se calcula la diferencia entre la fecha estimada de entrega contra
* la fecha de entrega real.

*CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
* EXPORTING
* I_DATUM_BIS =
* I_DATUM_VON =
* I_KZ_EXCL_VON = '0'
* I_KZ_INCL_BIS = '0'
* I_KZ_ULT_BIS = ' '
* I_KZ_ULT_VON = ' '
* I_STGMETH = '0'
* I_SZBMETH = '1'
* IMPORTING
* E_TAGE = tp_data-fecha
* EXCEPTIONS
* DAYS_METHOD_NOT_DEFINED = 1
* OTHERS = 2
.
*IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.






*&------------------------------------------------------------------*
*& Form get_data
*&------------------------------------------------------------------*
* Gets the information to be shown in the report.
*-------------------------------------------------------------------*
form get_data using t_data type tp_tbl_data.

SELECT b~banfn
e~lifnr
b~bnfpo
k~matnr
k~txz01
b~badat
b~lfdat
b~frgdt
k~ebeln
e~aedat
e1~belnr
e1~budat
INTO CORRESPONDING FIELDS OF TABLE t_data
FROM ekko as e
inner join ekpo as k on e~ebeln = k~ebeln
inner join eban as b on k~banfn = b~banfn
AND k~bnfpo = b~bnfpo
inner join ekbe as e1 on k~ebeln = e1~ebeln AND k~ebelp = e1~ebelp
WHERE b~banfn IN s_banfn
AND b~werks = p_werks
AND b~badat IN s_badat
AND e1~bewtp = p_bewtp
AND b~lfdat IN s_lfdat.

endform. " get_data

*&------------------------------------------------------------------*
*& Form build_alv
*&------------------------------------------------------------------*
* Builds and display the ALV Grid.
*-------------------------------------------------------------------*
form build_alv using t_data type tp_tbl_data
t_heading type slis_t_listheader.

* ALV required data objects.
data: w_title type lvc_title,
w_repid type syrepid,
w_comm type slis_formname,
w_status type slis_formname,
x_layout type slis_layout_alv,
t_event type slis_t_event,
t_fieldcat type slis_t_fieldcat_alv,
t_sort type slis_t_sortinfo_alv.



refresh t_fieldcat.
refresh t_event.
refresh t_sort.
clear x_layout.
clear w_title.

* Field Catalog
perform set_fieldcat2 using:
1 'SEL.' 'XFELD' space space space 'Select' 'Select this row' 'Sel'
'Select this row' space space space 'X' 'X' space t_fieldcat,
2 'BANFN' 'BANFN' 'EBAN' space space space space 'Nº SolPed' space
space 'X' space space space space t_fieldcat ,
3 'LIFNR' 'LIFNR' 'EKKO' space space space space 'Nº Prov.' space
space space space space space space t_fieldcat ,
4 'BNFPO' 'BNFPO' 'EBAN' space space space space space 'Pos.' space
space space space space space t_fieldcat ,
5 'MATNR' 'MATNR' 'EKPO' space space space space 'Nº Material' space
space space space space space space t_fieldcat ,
6 'TXZ01' 'TXZ01' 'EKPO' space space space 'Descripción Material'
space space space space space space space space t_fieldcat ,
7 'BADAT' 'BADAT' 'EBAN' space space space space 'Fec. SolPed' space
space space space space space space t_fieldcat ,
8 'LFDAT' 'LFDAT' 'EBAN' space space space space 'Fec. Entrega'
space space space space space space space t_fieldcat ,
9 'FRGDT' 'FRGDT' 'EBAN' space space space space 'Fec. Liberac.'
space space space space space space space t_fieldcat ,
10 'EBELN' 'EBELN' 'EKPO' space space 'Nro. Orden Compra' space space
space space space space space space space t_fieldcat ,
11 'AEDAT' 'AEDAT' 'EKKO' space space space space 'Fecha OC' space
space space space space space space t_fieldcat ,
12 'BELNR' 'BELNR' 'EKBE' space space 'Doc. Entr. Merc.' space space
space space space space space space space t_fieldcat ,
13 'BUDAT' 'BUDAT' 'EKBE' space space space space 'Fec. Cont.' space
space space space space space space t_fieldcat .


* Layout
x_layout-zebra = 'X'.

* Top of page heading
perform set_top_page_heading using t_heading t_event.

* Events
perform set_events using t_event.

* GUI Status
w_status = ''.
w_repid = sy-repid.

* User commands
w_comm = 'USER_COMMAND'.

* Displays the ALV grid
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
it_fieldcat = t_fieldcat
is_layout = x_layout
it_sort = t_sort
i_callback_pf_status_set = w_status
i_callback_user_command = w_comm
i_save = 'X'
it_events = t_event
i_grid_title = w_title
tables
t_outtab = t_data
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

endform. " build_alv.


*&------------------------------------------------------------------*
*& Form set_top_page_heading
*&------------------------------------------------------------------*
* Creates the report headings.
*-------------------------------------------------------------------*
form set_top_page_heading using t_heading type slis_t_listheader
t_events type slis_t_event.

data: x_heading type slis_listheader,
x_event type line of slis_t_event.

* Report title
* clear t_heading[].
* clear x_heading.
* x_heading-typ = 'H'.
* x_heading-info = ''(001).
* append x_heading to t_heading.

* Program name
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Programa: '.
x_heading-info = 'Reporte Medición'.
append x_heading to t_heading.

* User who is running the report
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Usuario: '.
x_heading-info = sy-uname.
append x_heading to t_heading.

* Date of execution
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Día: '.
write sy-datum to x_heading-info.
append x_heading to t_heading.

* Time of execution
clear x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Hora: '.
write sy-uzeit to x_heading-info.
append x_heading to t_heading.

* Top of page event
x_event-name = slis_ev_top_of_page.
x_event-form = 'TOP_OF_PAGE'.
append x_event to t_events.

endform.

*&------------------------------------------------------------------*
*& Form set_events
*&------------------------------------------------------------------*
* Sets the events for ALV.
* The TOP_OF_PAGE event is alredy being registered in
* the set_top_page_heading subroutine.
*-------------------------------------------------------------------*
form set_events using t_events type slis_t_event.

data: x_event type line of slis_t_event.

**
* Example
* -------
* clear x_event.
* x_event-name = .
* x_event-form = .
* append x_event to t_event.
**

endform.

*&------------------------------------------------------------------*
*& Form set_order
*&------------------------------------------------------------------*
* Adds an entry to the order table.
*-------------------------------------------------------------------*
FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot
t_sort TYPE slis_t_sortinfo_alv.

DATA: x_sort TYPE slis_sortinfo_alv.

CLEAR x_sort.
x_sort-fieldname = p_fieldname.
x_sort-tabname = p_tabname.
x_sort-up = p_up.
x_sort-down = p_down.
x_sort-subtot = p_subtot.
APPEND x_sort TO t_sort.


ENDFORM. "set_order

FORM set_fieldcat2 USING
p_colpos p_fieldname p_ref_fieldname p_ref_tabname
p_outputlen p_noout
p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
p_hotspot p_showasicon p_checkbox p_edit
p_dosum
t_fieldcat TYPE slis_t_fieldcat_alv.

DATA: wa_fieldcat TYPE slis_fieldcat_alv.

CLEAR wa_fieldcat.

* General settings
wa_fieldcat-fieldname = p_fieldname.
wa_fieldcat-col_pos = p_colpos.
wa_fieldcat-no_out = p_noout.
wa_fieldcat-hotspot = p_hotspot.
wa_fieldcat-checkbox = p_checkbox.
wa_fieldcat-icon = p_showasicon.
wa_fieldcat-do_sum = p_dosum.

* Set reference fieldname, tablenam and rollname.
* If p_ref_tabname is not given, the ref_fieldname given
* is a data element.
* If p_ref_tabname is given, the ref_fieldname given is a
* field of a table.
* In case ref_fieldname is not given,
* it is copied from the fieldname.
IF p_ref_tabname IS INITIAL.
wa_fieldcat-rollname = p_ref_fieldname.
ELSE.
wa_fieldcat-ref_tabname = p_ref_tabname.
IF p_ref_fieldname EQ space.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
ELSE.
wa_fieldcat-ref_fieldname = p_ref_fieldname.
ENDIF.
ENDIF.

* Set output length.
IF NOT p_outputlen IS INITIAL.
wa_fieldcat-outputlen = p_outputlen.
ENDIF.

* Set text headers.
IF NOT p_seltext_m IS INITIAL.
wa_fieldcat-seltext_m = p_seltext_m.
ENDIF.

IF NOT p_seltext_l IS INITIAL.
wa_fieldcat-seltext_l = p_seltext_l.
ENDIF.

IF NOT p_seltext_s IS INITIAL.
wa_fieldcat-seltext_s = p_seltext_s.
ENDIF.

IF NOT p_reptext_ddic IS INITIAL.
wa_fieldcat-reptext_ddic = p_reptext_ddic.
ENDIF.

IF NOT p_ddictxt IS INITIAL.
wa_fieldcat-ddictxt = p_ddictxt.
ENDIF.

* Set as editable or not.
IF NOT p_edit IS INITIAL.
wa_fieldcat-input = 'X'.
wa_fieldcat-edit = 'X'.
ENDIF.

APPEND wa_fieldcat TO t_fieldcat.

ENDFORM. "set_fieldcat2

*======================== Subroutines called by ALV ================*

*&------------------------------------------------------------------*
*& Form top_of_page

form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
* i_logo = <<If you want to set a logo, please,
* uncomment and edit this line>>
it_list_commentary = t_heading.
endform. " alv_top_of_page

*&------------------------------------------------------------------*
*& Form user_command
*&------------------------------------------------------------------*
* Called on user_command ALV event.
* Executes custom commands.
*-------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.


endform. "user_command

Desde ya muchas gracias,
Saludos.
Responder Con Cita
  #2  
Viejo 09/03/08, 19:38:01
ic_man_777 ic_man_777 is offline
Member
 
Fecha de Ingreso: oct 2007
Localización: Mexico
Mensajes: 97
No miré el codigo, pero...
Si los 2 campos son de tipo Date, puedes hacer una resta normal... XD

Y te da el numero de dias entre dos fechas
Responder Con Cita
  #3  
Viejo 09/03/08, 22:26:30
Jarpi Jarpi is offline
Senior Member
 
Fecha de Ingreso: abr 2007
Localización: Argentina
Mensajes: 453
Muchas gracias ic_man_777!

Ahora, te pregunto, como hago para insertar una columna? La declaro en la estructura con que parámetros?

Gracias nuevamente,
Saludos.
Responder Con Cita
  #4  
Viejo 10/03/08, 03:38:10
cubanito cubanito is offline
Junior Member
 
Fecha de Ingreso: nov 2006
Mensajes: 13
Smile

Si... tu estructura de salida es "t_data". Ahí debes agregar el campo de dicha diferencia. Como supongo que son "número de días transcurridos" entre una fecha y otra, el campo puede ser de tipo I, N, o C (para estos últimos deberías saber qué tan grande podría llegar a ser esa diferencia para "dimensionar" la variable)...
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Reglas de Mensajes
no puedes crear nuevos temas
no puedes responder temas
no puedes adjuntar archivos
no puedes editar tus mensajes

El código vB está On
Las caritas están On
Código [IMG] está On
Código HTML está Off
Saltar a Foro


Husos Horarios son GMT. La hora en este momento es 16:37:58.


www.mundosap.com 2006 - Spain
software crm, crm on demand, software call center, crm act, crm solutions, crm gratis, crm web