‎2009 Jan 26 9:17 PM
Hi,
My program produces an internal table with one row containing about 100 fields. Before I merge the contents of these fields, I would like to "loop" horizontall through the row to find negative values.
1. How can I loop horizontally trhough fields in a row.
2. How do I reposition the "-" (minus) sign so that it comes before the number before I merge the data to a word document. When I use "replace" and "concatenate" to change the position of the minus sign, the values are not merged properly to word. They appear in brackets.
Thanks in advance for your help.
‎2009 Jan 26 9:28 PM
Try this for question # 1
data : i_details type abap_compdescr_tab.
data : i_ref_descr type ref to cl_abap_structdescr.
i_ref_descr ?= cl_abap_typedescr=>describe_by_data( i_temp ).
" Here i_temp is your internal table to verify horizontally
i_details[] = i_ref_descr->components[].
" Here you will get i_details with (ie it contains all fields information)
data : v_value(100) type c.
loop at i_temp.
loop at i_details.
concatenate 'I_TEMP-' i_details-name into v_field.
condense v_field no-gaps.
write : ( v_field ) to v_value.
" Here search for v_value in it have minus sign or not.
endloop.
endloop.
a®s
Edited by: a®s on Jan 26, 2009 4:41 PM
‎2009 Jan 26 9:29 PM
Hi,
for your first question, you can use
DO .. ENDO with VARYING addion.
Loop .. Endloop will iterate vertically where as DO .. ENDO iterates horizontally.
I did not understand your second question, can you clear a bit.
Mubeen
‎2009 Jan 26 9:51 PM
Thanks for your concise anwser. Unfortunately I am not connected to my ABAP compture but will try that tomorrow.
For my second question, in SAP the negative amounts are stored with the minus sign after the number for example, 3456.78-, 12345.90- ,...instead of -3456.78, -12345.90,... I would like to have the negative sign before the number and not after.
I have used "REPLACE" to replace the sign after the number with a blank and then "CONCATENATE" to combine "-" and the number. The resulting number does not appear correctly in my word document. It is enclosed in brackets.
‎2009 Jan 26 10:06 PM
Try like this,
Let us assume num1 = 7890.98-
if num1 ca '-'.
REPLACE '-' with space here and lets say num2 is the new variable without -sign
concatenate '-' num2
into num1.
endif.
Otherwise you can check syntax of WRITE statement with FORMAT addition.
Mubeen
‎2009 Jan 26 10:10 PM
I did try the REPLACE/CONCATENATE algorithm but my numbers appear in brackets in he resulting Word document. I did llok at WRITE but it seems it is only useful if one is writing to a screen and not to a table to be used in a WORD mail merge.
‎2009 Jan 26 10:16 PM
Hello TJ,
WRITE statement is used to display on screen as well as to move data from variable to other.
WRITE source TO destination.
It has some additions like FORMAT.
I don't have access to SAP now, please check the syntax.
Mubeen
‎2009 Jan 26 10:21 PM
Thanks Mubeen,
I will try that first thing tomorrow morning. I do not have access to SAP now either.
‎2009 Jan 26 9:32 PM
Try this way:
<fs_itab> type itab. "your table...
field-symbols: <fs_comp> TYPE ANY.
loop at itab assigning <fs_itab>.
do.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_itab> TO <fs_comp>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
check if <fs_comp> LE 0.
enddo.
endloop.