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.
Les pongo el programa que tengo hasta ahora, quizás alguno pueda ayudarme.
**
* 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.
* 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
*&------------------------------------------------------------------*
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
*-------------------------------------------------------------------*
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
*-------------------------------------------------------------------*
*&------------------------------------------------------------------*
*& 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 using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
endform. "user_command
Desde ya muchas gracias,
Saludos.
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.
Les pongo el programa que tengo hasta ahora, quizás alguno pueda ayudarme.
**
* 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.
* 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
*&------------------------------------------------------------------*
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
*-------------------------------------------------------------------*
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
*-------------------------------------------------------------------*
*&------------------------------------------------------------------*
*& 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 using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
endform. "user_command
Desde ya muchas gracias,
Saludos.
Comentario