Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

displaying negative nos.

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

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

0 Kudos

So in your case,



report zrich_0004.


data:

     no_of_days_1 type i,
     disc_d_date type sy-datum value '20051231'.


no_of_days_1 = sy-datum - disc_d_date.


write:/ no_of_days_1.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Former Member
0 Kudos

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

0 Kudos

I'm not sure what the problem is, in the above examples, the integar field WILL show a negative sign.

Am I missing something?

Regards,

Rich Heilman

0 Kudos

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

0 Kudos
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

0 Kudos

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