Today one of the member of our telegram group aked how to display the negative sign of a value at the beginning instead of at the end and keeping the possibility to make get total and subtotal of the column. I never had such kind of request, so I needed to investigate on how to solve this quest.
Request for the test:
Find a way to display the negative sign in front of the value
Make sure that decimal notation of the user will still work
Question and decision how to implement:
Can it be solved using standard functions?
No, neather fieldcatalog nor ALV layout can handle this request.
Must be developed here?
Yes, we need a conversion routine. This means we have to create a functiongroup and two functionmodules
Implementation steps
Info: I haven’t included popup with warning and package assignment. I ignored all warnings that happened in this sample and I assigned all objects to the local package $TMP.
Thinking about the requirement and the difficulties while implementing.
When implementing a conversion routine we have to think about on how to keep the number notation that the user have in the settings (TAC:SU01/SU3). This means that we have to create flexible EDIT MASKS in the output conversion routine
Creating a conversion routine.
A conversion routine is identified by its five-place name (custom conversion routine should start with Y or Z) and is stored as a group of two function modules. The function modules have a fixed naming convention. The following function modules are assigned to conversion routine xxxxx:
CONVERSION_EXIT_xxxxx_INPUT
CONVERSION_EXIT_xxxxx_OUTPUT
Creating functiongroup
Naviagte to the topinclude of the functiongroup and paste the code:
" Get the Decimal Format from the user settings (SU01/SU3)
" Dezimaldarstellung aus den Benutzereinstellungen holen (SU01/SU3)
IFgv_decimal_signIS INITIAL.CALL FUNCTION'CLSE_SELECT_USR01'EXPORTINGusername=sy-unameiv_delete_buffer=abap_trueIMPORTINGdecimal_sign=gv_decimal_signseparator=gv_separator.ENDIF.DATA(lv_input)=CONVstring(input).DATA(lv_negativ_number)=boolc(lv_inputCS'-').REPLACE ALLOCCURRENCESOF'-'INlv_inputWITH''.SPLITlv_inputAT'.'INTODATA(lv_number)DATA(lv_decimals).REPLACE ALLOCCURRENCESOF'.'INlv_inputWITH''.DOstrlen(lv_number)TIMES.IFsy-indexEQ1.DATA(lv_mask)=|_|.CONTINUE.ENDIF.lv_mask=|_{COND#(WHENsy-indexMOD3EQ1THENgv_separator)}{lv_mask}|.ENDDO.DOstrlen(lv_decimals)TIMES.IFsy-indexEQ1.lv_mask=|{lv_mask}{gv_decimal_sign}_|.CONTINUE.ENDIF.lv_mask=|{lv_mask}_|.ENDDO.lv_mask=|{COND#(WHENlv_negativ_numberEQabap_trueTHEN|-|)}{lv_mask}|.WRITElv_inputTOoutputUSINGEDITMASKlv_mask.
" Get the Decimal Format from the user settings (SU01/SU3)
" Dezimaldarstellung aus den Benutzereinstellungen holen (SU01/SU3)
IFgv_decimal_signIS INITIAL.CALL FUNCTION'CLSE_SELECT_USR01'EXPORTINGusername=sy-unameiv_delete_buffer=abap_trueIMPORTINGdecimal_sign=gv_decimal_signseparator=gv_separator.ENDIF.DATA(lv_input)=CONVstring(input).REPLACE ALL OCCURRENCES OF gv_separatorINlv_inputWITH''.REPLACE gv_decimal_signINlv_inputWITH'.'.CONDENSElv_inputNO-GAPS.TRY.output=lv_input.CATCHcx_sy_conversion_no_number." Clear message fields of sy structure, so that 'Conversion error' will be raised
" Alle Message Felder der sy Struktur löschen, damit 'Fehler bei der Konvertierung.' geworfen wird
CLEAR:sy-msgty,sy-msgno,sy-msgv1,sy-msgv2,sy-msgv3,sy-msgv4.RAISEerror_message.ENDTRY.
Activating new functiongroup and functionmodules
Implementing the conversion routine
Implementing conversion routine to domain
Implementing at runtime to ALV
In the demo report you can find how you can implement the conversion routine at runtine to ALV.
Demo report
Here is a small demo report on how you can use it.