How to make a currency amount field with blank value instead of 0.00 - abap

I want to put currency amount field blank instead of 0.00.

ALV: NO_ZERO = abap_true in fieldcatalog structure LVC_S_FCAT
SALV: call method SET_ZERO of class CL_SALV_COLUMN (you need to get the columns reference, google code examples)
Sapscript/Smartforms: use flag I (suppress initial value output) as in &ZAMOUNT(I)&
WRITE statement: Add NO-ZERO before the .
String templates: lv_string = |{ lv_amnt ZERO = NO }|.

Related

Is there an equivalent of an f-string in Google Sheets?

I am making a portfolio tracker in Google Sheets and wanted to know if there is a way to link the "TICKER" column with the code in the "PRICE" column that is used to pull JSON data from Coin Gecko. I was wondering if there was an f-string like there is in Python where you can insert a variable into the string itself. Ergo, every time the Ticker column is updated the coin id will be updated within the API request string. Essentially, string interpolation
For example:
TICKER PRICE
BTC =importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids={BTC}","0.current_price")
You could use CONCATENATE for this:
https://support.google.com/docs/answer/3094123?hl=en
CONCATENATE function
Appends strings to one another.
Sample Usage
CONCATENATE("Welcome", " ", "to", " ", "Sheets!")
CONCATENATE(A1,A2,A3)
CONCATENATE(A2:B7)
Syntax
CONCATENATE(string1, [string2, ...])
string1 - The initial string.
string2 ... - [ OPTIONAL ] - Additional strings to append in sequence.
Notes
When a range with both width and height greater than 1 is specified, cell values are appended across rows rather than down columns. That is, CONCATENATE(A2:B7) is equivalent to CONCATENATE(A2,B2,A3,B3, ... , A7,B7).
See Also
SPLIT: Divides text around a specified character or string, and puts each fragment into a separate cell in the row.
JOIN: Concatenates the elements of one or more one-dimensional arrays using a specified delimiter.

How do I get the Index of an UltraComboEditor ValueList Item?

I have an UltraComboEditor named ddltype
I set the values with an Enumeration:
ddlType.Items.Add(SalesPaymentType.CashPayment.Value, SalesPaymentType.CashPayment.DisplayName)
ddlType.Items.Add(SalesPaymentType.CheckPayment.Value, SalesPaymentType.CheckPayment.DisplayName)
ddlType.Items.Add(SalesPaymentType.CreditCardPayment.Value, SalesPaymentType.CreditCardPayment.DisplayName)
When I try to set the SelectedIndex with
ddlType.SelectedIndex = ddlType.Items.ValueList.FindString(SalesPaymentType.CashPayment.DisplayName)
It returns 0 not found. It is not finding my entry.
Any enumerated values can be added to the UltraComboEditor control as below:
ultraComboEditor1.Items.Add(new ValueListItem(value, value.ToString))
One of the ValueListItem() constructors gets data value and display text.
To find item by string:
ultraComboEditor1.SelectedIndex = ultraComboEditor1.FindString(SalesPaymentType.CashPayment.ToString)
But more reasonable to use the FindByDataValue():
ultraComboEditor1.SelectedItem = ultraComboEditor1.ValueList.FindByDataValue(SalesPaymentType.CashPayment)
Pay attention, the FindByDataValue() requires a value, but not a text.

Cleaning empty cells in internal table

I'm trying to clean the following empty cells marked in red from this internal table before I display it in an ALV.
If a cell is found to be blank, look for any cells underneath that have value and move up.
I am struggling to figure out what is the best way in code to perform this.
Any help would be great.
It is undoubtedly that something is wrong with your merging logic, however your task is quite interesting and this is one of the possible ways it can be solved.
I took your structure and made an assumption that none of the rows in your table is fully filled, i.e. either first three columns are filled (struct_left) or last three (struct_right). This is how I feel it from your screenshots.
REPORT z_sections.
TYPES:
BEGIN OF struct_left, " left structure
LEFTDAMAGED TYPE c LENGTH 1,
LEFTDAMAGEDDESC TYPE c LENGTH 3,
LEFTDAMAGEDDESCT TYPE c LENGTH 30,
END OF struct_left,
BEGIN OF struct_right, " right structure
RIGHTDAMAGED TYPE c LENGTH 1,
RIGHTDAMAGEDDESC TYPE c LENGTH 3,
RIGHTDAMAGEDDESCT TYPE c LENGTH 30,
END OF STRUCT_right.
TYPES BEGIN OF ty_table.
INCLUDE TYPE struct_left.
INCLUDE TYPE struct_right.
TYPES END OF ty_table.
DATA: lt_current_table TYPE TABLE OF ty_table INITIAL SIZE 100,
ls_current_table LIKE LINE OF lt_current_table,
i TYPE i.
FIELD-SYMBOLS: <fld> TYPE clike.
DATA: r_random TYPE REF TO cl_abap_random_packed,
seed TYPE i.
seed = cl_abap_random=>seed( ).
CALL METHOD cl_abap_random_packed=>create
EXPORTING
seed = seed
min = -999999999999999
max = 999999999999999
RECEIVING
prng = r_random.
DEFINE randomize. " filling row with random data
ASSIGN COMPONENT &1 OF STRUCTURE &2 TO <fld>.
<fld> = r_random->get_next( ).
&1 = &1 + 1.
ASSIGN COMPONENT &1 OF STRUCTURE &2 TO <fld>.
<fld> = r_random->get_next( ).
&1 = &1 + 1.
ASSIGN COMPONENT &1 OF STRUCTURE &2 TO <fld>.
<fld> = r_random->get_next( ).
END-OF-DEFINITION.
START-OF-SELECTION.
* filling table with random stuff
DO 100 TIMES.
CLEAR ls_current_table.
IF sy-index MOD 3 = 0.
i = 1.
randomize i ls_current_table.
ELSE.
i = 4.
randomize i ls_current_table.
ENDIF.
APPEND ls_current_table TO lt_current_table.
ENDDO.
DATA: ls_left TYPE struct_left,
ls_right TYPE struct_right.
DATA lt_new LIKE lt_current_table.
* collapsing table
LOOP AT lt_current_table ASSIGNING FIELD-SYMBOL(<fs_current>) WHERE leftdamaged IS NOT INITIAL.
DELETE lt_current_table WHERE leftdamaged IS INITIAL AND leftdamageddesc IS INITIAL AND leftdamageddesct IS INITIAL AND
rightdamaged IS INITIAL AND rightdamageddesc IS INITIAL AND rightdamageddesct IS INITIAL. " remove empty lines
MOVE-CORRESPONDING <fs_current> TO ls_left.
READ TABLE lt_current_table ASSIGNING FIELD-SYMBOL(<fs_right>) WITH KEY leftdamaged = ''.
IF <fs_right> IS ASSIGNED.
MOVE-CORRESPONDING <fs_right> TO ls_right.
CLEAR: <fs_right>.
ENDIF.
CLEAR: <fs_current>.
IF ls_left IS NOT INITIAL AND ls_right IS NOT INITIAL.
CLEAR: ls_current_table.
MOVE-CORRESPONDING ls_left TO ls_current_table.
MOVE-CORRESPONDING ls_right TO ls_current_table.
APPEND ls_current_table TO lt_new.
CLEAR: ls_left, ls_right.
ENDIF.
ENDLOOP.
You can sort the internal table and store it in a temp internal table, and swap them. For instance:
data: lt_itab_temp like table of lt_itab.
move lt_itab[] to lt_itab_temp[].
clear:lt_itab[],lt_itab.
sort lt_itab_temp descending by rightdamagedesc rightdamagedesct.
move lt_itab_temp[] to lt_itab[].
OR, you can loop through the fieldcatalog, set "no_display" or "no_out" field to 'X'.

How to split a series of number and compare it with another set of digit?

Say I have a no. 20101105, I need to compare it with a series of other nos. say 20110105 , 20090105 and find the nearest no. of it.
I don't want to compare it on the whole, I need to compare it each digit wise by parsing thru it and then see which is the closest.
Can someone suggest on how to do this in ABAP language?
In general You should mention some more information. For example, are the numbers really integers ? Then You can put them into an internal table and sorting all of them is the easiest solution to find any "nearest" number relating to an actual scanned. This is just like integers work in sort, they are sorted like numbers, my friend. But If You want it character-wise ( what really makes no sense, if the numbers are integers ) i give You some help with this character-comparison in a do-loop, taking smaller string-length as iterator-counter. I omitted the else, that's Your "homework". :-D
DATA:
lv_length1 TYPE i,
lv_length2 TYPE i,
lv_cnt TYPE i,
lv_teststr1 TYPE string VALUE '123456',
lv_teststr2 TYPE string VALUE '1235'.
lv_length1 = strlen( lv_teststr1 ).
lv_length2 = strlen( lv_teststr2 ).
IF lv_length1 GE lv_length2.
DO lv_length2 TIMES.
IF lv_teststr2+lv_cnt(1) NE lv_teststr1+lv_cnt(1).
BREAK-POINT.
ENDIF.
ADD 1 TO lv_cnt.
ENDDO.
ENDIF.
The counter variable is also the index of, in this case, the first not matching character. This gets the job done.
Coded and tested by me just right now.
I don't know if I understood but maybe this helps.
report znearest.
data lv_value(8) type n.
parameters p_value(8) type n. " ---------> The value
select-options s_values for lv_value. " -> The list
start-of-selection.
data: wa like line of s_values,
lv_dif(8) type n,
lv_nearest(8) type n,
lv_nearest_dif(8) type n,
lv_first type c.
loop at s_values into wa.
lv_dif = abs( p_value - wa-low ). " Calculate the difference
if lv_first is initial.
lv_nearest_dif = lv_dif.
lv_first = 'X'.
endif.
if lv_dif le lv_nearest_dif. " Compare the differences
lv_nearest = wa-low.
lv_nearest_dif = lv_dif.
endif.
endloop.
write: 'The nearest from', p_value, 'is', lv_nearest.
Hope it helps.

How to write number with sign on the left and thousands separator point

I am holding the number in character format in abap. Because I have to take the minus from right to left. So I have to put the number to character and shift or using function 'CLOI_PUT_SIGN_IN_FRONT' I'm moving minus character to left.
But after assigning number to character it doesn't hold the points. I mean my number is;
1.432- (as integer)
-1432 (as character)
I want;
-1.432 (as character)
is there a shortcut for this or should I append some string operations.
Edit:
Here is what I'm doing now.
data: mustbak_t(10) TYPE c,
mustbak like zsomething-menge.
select single menge from zsomething into mustbak where something eq something.
mustbak_t = mustbak.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
VALUE = mustbak_t.
write: mustbak_t.
If you're on a recent release, you could use string templates - you'll have to add some black magic to use a country that confoirms to your decimal settings, though:
DATA: l_country TYPE t005x-land,
l_text TYPE c LENGTH 15,
l_num TYPE p LENGTH 6.
SELECT SINGLE land
INTO l_country
FROM t005x
WHERE xdezp = space.
l_num = '-123456'.
l_text = |{ l_num COUNTRY = l_country }|.
WRITE: / l_text.
In this case, you need a country code to pass to the COUNTRY parameter as described in the format options. The values of the individual fields, namely T005X-XDEZP are described in detail in the country-specific formats.
tl;dr = Find any country where they use "." as a thousands separator and "," as a decimal separator and use that country settings to format the number.
You could also use classic formatting templates, but they are hard to handle unless you have a fixed-length output value:
DATA: l_text TYPE c LENGTH 15,
l_num TYPE p LENGTH 6 DECIMALS 2.
l_num = '-1234.56'.
WRITE l_num TO l_text USING EDIT MASK 'RRV________.__'.
CONDENSE l_text NO-GAPS.
WRITE: / l_text.
Here's another way, which i finally got working:
DATA: characters(18) TYPE c,
ints TYPE i VALUE -222333444.
WRITE ints TO characters. "This is it... nothing more to say.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
value = characters.
WRITE characters.
Since integers are automatically printed with the thousands separator, you can simply output them to a char data object directly using WRITE TO with no aditions..... lol
DATA: currency TYPE cdcurr,
characters(18) TYPE c,
ints TYPE i VALUE -200000.
currency = ints.
WRITE currency TO characters CURRENCY 'USD' DECIMALS 0.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
value = characters.
.
WRITE: / 'example',characters.
This prints your integer as specified. Must be apparently converted to a currency during the process.