Skip to Content
author's profile photo Former Member
Former Member

displaying negative nos.

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2005 at 07: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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 27, 2005 at 07: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.