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: 

Negative Sign missing in File downloaded from ALV grid using SALV* classes

Former Member
0 Kudos

Hello Experts,

I created a very simple ALV grid having a column MSEG-MENGE (defined as type mseg-menge in itab). I created manual fieldcatalog and don't pass any other field in the fcatalog table for this field other than COLTEXT. Some menge values in itab are negative.

When used REUSE_ALV_GRID_DISPLAY :

In output ALV grid, signs and values are displayed correctly. If I download in a file using Export>Local File>Unconverted, the signs and values in the file are correct.

When used cl_salv_table=>factory (nothing done for columns explicitly):

In output ALV grid, signs and values are displayed correctly. If I download in a file using Export>Local File>Unconverted, the negative signs are NOT COMING with the values, all the values are positive. Why ??

Hope my problem is clear. I guess it is something to do with the data type of this field but how different behaviour using 2 separate functions.

Regards,

Diwakar

Edited by: Diwakar Aggarwal on Nov 1, 2011 5:58 PM

1 ACCEPTED SOLUTION

Former Member

Hello Diwakar,

Are you using the SET_SIGN method as below to set your column to allow negatives within the fieldcatalog?


  TRY. 
      lo_column ?= lo_columns->get_column(
                  columnname = 'MENGE' ).
      lo_column->set_sign( abap_true ).                        
    CATCH cx_salv_not_found.
  ENDTRY.

Also, when you download the file using Export>Local File>Unconverted, make sure to use the default format which is .txt

Hope this helps.

Cheers,

Sougata.

Also, another method lo_column->set_quantity_column might be required for your column to set it as qty column.

Edited by: Sougata Chatterjee on Nov 2, 2011 6:43 AM

8 REPLIES 8

Former Member
0 Kudos

Did you notice that MSEG has field SHKZG, the positive/negative indicator? This would indicate to me that MSEG currency values would always be shown as positive and that to get the "correct" value, I'd have to multiply the value by '-1' when the SHKZG indicator is 'H'. Check to see if that is the cause of your positive numbers only.

0 Kudos

Davel,

Yes, I know the field SHKZG and based on that I am changing the value of MENGE in my internal table. But, after all the values are modified with whatever logic, the values in ITAB should be correctly displayed in ALV. This is happening correctly, but why signs are missing in the download file using SALV class.

The contents in the download file should be same as ALV, which is not the case here and is my problem.

Regards,

Diwakar

Former Member

Hello Diwakar,

Are you using the SET_SIGN method as below to set your column to allow negatives within the fieldcatalog?


  TRY. 
      lo_column ?= lo_columns->get_column(
                  columnname = 'MENGE' ).
      lo_column->set_sign( abap_true ).                        
    CATCH cx_salv_not_found.
  ENDTRY.

Also, when you download the file using Export>Local File>Unconverted, make sure to use the default format which is .txt

Hope this helps.

Cheers,

Sougata.

Also, another method lo_column->set_quantity_column might be required for your column to set it as qty column.

Edited by: Sougata Chatterjee on Nov 2, 2011 6:43 AM

0 Kudos

Sougata,

Welcome to SCN !!

lo_column->set_sign( abap_true ) is helping and I am able to download that column with SIGNS in my text file.

But the issue is not yet clear that WHY this behaviour, do you have any idea ?

If I have 5 QTY fields, I have to mark this method for every field. Also, since the SIGN is appearing correctly in ALV grid, why this method is REQUIRED to get correct signs in download File. I believe there should not be any special need as the field seems to be able to handle signs in the ALV grid without any extra method call.

It raises more concerns about the SALV* approach in my mind.

Anyways, Thanks for the valuable suggestion.

Regards,

Diwakar

0 Kudos

Experts,

Any helpful comments for my problem ??

0 Kudos

Well, if you think about it logically SAP actually makes a lot of sense in regards to the SALV object model.

First of all, you are trying to force a negative value to a Quantity field i.e. whose data type is QUAN; as per SAP data type doco it is a "Quantity field which points to a unit field with format UNIT".

To me it does not make any sense at all to use type QUAN for a negative value - it's like saying to a customer "At the moment we have minus 500 laptops 5 cartons each containing 500 boxes of chocolates in our stock!!" You see my point? If you really need to show negative values for a column then don't use type QUAN in the fieldcatalog instead use type CURR (if your column is amount related) or type INT4 if its not related to any amount/currency.

And that is precisely why SAP displays and transfers the absolute value from the SLV grid (for Type CURR, INT4 columns e.g. WRBTR) to a file unless you specifically set the column sign to be negative within the fieldcatalog by calling the method SET_SIGN.

So in summary (assuming values are already negative in ITAB that is passed to the SALV object instance) :

1. For Currency(CURR) or Integer(INT4) Type columns (e.g. WRBTR, S_SEATSMAX)

- calling SET_SIGN will display in the SLV grid and download to file the actual values that are in the ITAB

- not calling SET_SIGN will display in the SLV grid and download to file the absolute values that are in the ITAB

2. For other data Types (where you are technically able to convert values as negatives in the ITAB (e.g. QUAN)

- calling the SET_SIGN will display in the SLV grid and download to file the actual values that are in the ITAB

- not calling SET_SIGN will display in the SLV grid with actual values in the ITAB but will download to the file with absolute values simply because the column using the associated data Type was never designed to be used for a negative number value unless specified explicitly in the application.

I hope this made sense and you are now a little less concerned with the SALV object model

Cheers,

Sougata.

Edited by: Sougata Chatterjee on Nov 3, 2011 6:35 AM

0 Kudos

Sougata,

Thanks for your time to discuss on this.

You are correct that it doesn't make sense to have negative Quantities, but we are just marking them negative for identification purpose to differentiate ISSUE and RECEIPT (based on debit/credit flag). I believe SAP is also doing similar thing in MB51, MB58.

W.r.t. your summarised analysis, I have some comments (in red) :


1. For Currency(CURR) or Integer(INT4) Type columns (e.g. WRBTR, S_SEATSMAX)
- calling SET_SIGN will display in the SLV grid and download to file the actual values that are in the ITAB
- not calling SET_SIGN will display in the SLV grid and download to file the absolute values that are in the ITAB
          "not calling SET_SIGN is also resulting in ACTUAL values for me (and not the absolute values), so what is the actual importance of this field for types allowing negative values...

2. For other data Types (where you are technically able to convert values as negatives in the ITAB (e.g. QUAN)
- calling the SET_SIGN will display in the SLV grid and download to file the actual values that are in the ITAB
- not calling SET_SIGN will display in the SLV grid with actual values in the ITAB but will download to the file with absolute values simply because the column using the associated data Type was never designed to be used for a negative number value unless specified explicitly in the application.
          "Correctly stated that data type is never designed to be used as a Negative value, but then Isn't it Strange that without calling SET_SIGN, WHY it is allowed to display the negative sign in the grid. It should be same behavior in Grid & File.

As per docum of SET_SIGN method,


Positive numbers are displayed in the output table without a sign, while negative numbers are displayed by default with the minus sign ('-').

You use the SET_SIGN method to set whether the sign is displayed for negative numbers or not.

Note:
Regardless of whether you display the sign or not: For calculations, of course, the actual value is used.

So, it actually is designed to work for DISPLAY ALV itself(and not the File download).

I guess, since this data type (QUAN) is not designed for negative signs, behavior is not so convincing and moreover confusing me now because there was no such issue with REUSE*.

Diwakar

Former Member
0 Kudos

Dear Diwakar,

After experiencing this behavior first hand, I have made a post to raise this again for discussion and review and referenced your discussion here. If you have any further insight into the matter, please feel free to check out the post and comment.

Kind Regards,

James