2005 Jul 27 8:08 PM
Hi,
I am working on an ALV program which should show the no. of days as negative...if the due date is past the current date.
For instance if the due date is 07/26/2005, it should show 1-.
I have declared the data as:
no_of_days_1 type I.
no_of_days_1_d(10) type C.
In my code:
disc_d_date: gets calculated at run time.
no_of_days_1 = sy-datum - disc_d_date.
if no_of_days_1 < 0 .
concatenate
no_of_days_1_d '-' into
no_of_days_1_d.
condense no_of_days_1_d NO-GAPS.
shift no_of_days_1_d RIGHT
DELETING TRAILING space.
else.
no_of_days_1_d = no_of_days_1.
endif.
The problem it appears, no_of_days_1_d being declared as I(integer), cannot store negative nos. A possible solution would be to create a data element with the sign checkbox ticked.
Would appreciate if anybody has a better solution.
Rajib
2005 Jul 27 8:46 PM
Rick,
The problem is based on the date difference, the column has to show 1 or 1-(negative).
Wouldn't it be better if I can define a data element as negative, something like AFRV-HRBET.
Rajib
Hi,
I am working on an ALV program which should show the no. of days as negative...if the due date is past the current date.
For instance if the due date is 07/26/2005, it should show 1-.
I have declared the data as:
no_of_days_1 type I.
no_of_days_1_d(10) type C.
In my code:
disc_d_date: gets calculated at run time.
no_of_days_1 = sy-datum - disc_d_date.
if no_of_days_1 < 0 .
concatenate
no_of_days_1_d '-' into
no_of_days_1_d.
condense no_of_days_1_d NO-GAPS.
shift no_of_days_1_d RIGHT
DELETING TRAILING space.
else.
no_of_days_1_d = no_of_days_1.
endif.
The problem it appears, no_of_days_1_d being declared as I(integer), cannot store negative nos. A possible solution would be to create a data element with the sign checkbox ticked.
Would appreciate if anybody has a better solution.
Rajib
2005 Jul 27 8:38 PM
Yes, integers can have a negative value.
Check out the sample program, pay attention to the IMARA-TESTF field. This is all you need to do to show negative in your ALV grid.
report zrich_0004
no standard page heading.
type-pools slis.
data: fieldcat type slis_t_fieldcat_alv.
data: sort type slis_t_sortinfo_alv.
data: begin of imara occurs 0,
matnr type mara-matnr,
matkl type mara-matkl,
labor type mara-labor,
brgew type mara-brgew,
maktx type makt-maktx,
<b> testf type i,</b>
end of imara.
* Selection Screen
selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for imara-matnr .
selection-screen end of block b1.
start-of-selection.
perform get_data.
perform write_report.
************************************************************************
* Get_Data
************************************************************************
form get_data.
select mara~matnr mara~matkl mara~labor mara~brgew makt~maktx
into corresponding fields of table imara
from mara
inner join makt
on mara~matnr = makt~matnr
where mara~matnr in s_matnr
and makt~spras = sy-langu.
<b> loop at imara.
imara-testf = sy-tabix * -1.
modify imara.
endloop.</b>
endform.
************************************************************************
* WRITE_REPORT
************************************************************************
form write_report.
perform build_field_catalog.
* CALL ABAP LIST VIEWER (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_sort = sort
it_fieldcat = fieldcat
tables
t_outtab = imara.
endform.
************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
data: fc_tmp type slis_t_fieldcat_alv with header line.
clear: fieldcat. refresh: fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Number'.
fc_tmp-fieldname = 'MATNR'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '18'.
fc_tmp-col_pos = 2.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Description'.
fc_tmp-fieldname = 'MAKTX'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '40'.
fc_tmp-col_pos = 5.
append fc_tmp to fieldcat.
<b> clear: fc_tmp.
fc_tmp-reptext_ddic = 'Test Field'.
fc_tmp-fieldname = 'TESTF'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '12'.
fc_tmp-do_sum = 'X'.
fc_tmp-col_pos = 4.
append fc_tmp to fieldcat.</b>
endform.
Regards,
Rich Heilman
2005 Jul 27 8:42 PM
2005 Jul 27 8:46 PM
Rick,
The problem is based on the date difference, the column has to show 1 or 1-(negative).
Wouldn't it be better if I can define a data element as negative, something like AFRV-HRBET.
Rajib
2005 Jul 27 9:01 PM
2005 Jul 27 10:57 PM
what abt nos that are positive....for e.g if the due date is 07/28 and the current system date is 07/27...it should show 1 and if the due date is 07/26, it should show 1-.
i will try you suggestion tommorrow.
thanks again,
Rajib
2005 Jul 28 1:32 AM
value = sy-datum - due_date.where due_date is 07/28/2005, value will be -1
where due_date is 07/26/2005, value will be 1.
If you need the sign(-) the other way around, just multiple by -1.
value = ( sy-datum - due_date ) * -1.or you can swich the fields around.
value = due_date - sy-datum .It really depends on what you want to see.
Regards,
Rich Heilman
2005 Jul 28 12:48 PM
Rick,
I tried "value = due_date - sy-datum ." and it solved my problem.
Got pretty confused yesterday.....when I got a positive diffference between the current date and an earlier date.
Have a great day.
Rajib
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |