‎2006 Dec 27 1:54 PM
Hi Experts,
I am writing a FM to read the input (file) that contains some set of strings. MY FM should read the invoices,amounts in a given string as follows:
SWF OF 06/12/07 INV03467225-$2137.27 INV03467224 $ 56743.69 INV03404808
INVOICE,-03464401USD35065.53 INVOICE-03464400-USD300472.16
In th above string i can identify the invoice no by searching for INV* followed by 8 chars/numbers .
But how can i read the amount which is can be of 4 digits(2137.27) or 5 digits( 56743.69 ) ..etc varies and which also contains varying .decimals. The amounts are preceded by $ or USD.
Please help me. Points will be rewarded.
thanks
‎2006 Dec 27 4:07 PM
[code]Hi Dan,
Execute the program and chekout , looks confusing but may solve ur problem
REPORT ychatest LINE-SIZE 350.
DATA : v_invoice TYPE string,
v_invoice1 TYPE string,
v_invoice2 TYPE string,
v_int1 TYPE i,
v_lines type i.
DATA : BEGIN OF itab OCCURS 0,
field1(100),
END OF itab.
DATA : BEGIN OF itab1 OCCURS 0,
field2(100),
END OF itab1.
DATA : BEGIN OF it_final OCCURS 0,
amount(100),
END OF it_final.
v_invoice1 = 'SWF OF 06/12/07 INV03467225-$2137.27 INV03467224 $ 56743.69 INV03404808'.
v_invoice2 = 'INVOICE,-03464401USD35065.53 INVOICE-03464400-USD300472.16'.
CONCATENATE v_invoice1 v_invoice2 INTO v_invoice.
REFRESH: itab , itab1 , it_final.
SPLIT v_invoice AT '$' INTO TABLE itab.
READ TABLE itab INDEX 1.
SEARCH itab-field1 FOR 'USD'.
IF sy-subrc EQ 0.
SPLIT itab-field1 AT 'USD' INTO TABLE itab1.
delete itab1 index 1.
clear itab1.
describe table itab1 lines v_lines.
LOOP AT itab1.
CONDENSE itab1-field2.
if sy-tabix eq v_lines.
it_final-amount = itab1-field2.
APPEND it_final.
clear it_final.
else.
SEARCH itab1-field2 FOR 'INV'.
IF sy-subrc EQ 0.
v_int1 = sy-fdpos - 1.
it_final-amount = itab1-field2+0(v_int1).
APPEND it_final.
CLEAR: it_final , v_int1 , v_lines..
ENDIF.
endif.
ENDLOOP.
ENDIF.
DELETE itab INDEX 1.
CLEAR :itab , itab1,it_final.
LOOP AT itab.
CONDENSE itab-field1.
SEARCH itab-field1 FOR 'INV'.
IF sy-subrc EQ 0.
v_int1 = sy-fdpos - 1.
it_final-amount = itab-field1+0(v_int1).
APPEND it_final.
CLEAR : it_final , v_int1.
ENDIF.
SEARCH itab-field1 FOR 'USD'.
IF sy-subrc EQ 0.
refresh itab1.
SPLIT itab-field1 AT 'USD' INTO TABLE itab1.
delete itab1 index 1.
clear : itab1 , v_lines.
describe table itab1 lines v_lines.
LOOP AT itab1.
CONDENSE itab1-field2.
if sy-tabix eq v_lines.
it_final-amount = itab1-field2.
APPEND it_final.
clear it_final.
else.
SEARCH itab1-field2 FOR 'INV'.
IF sy-subrc EQ 0.
v_int1 = sy-fdpos - 1.
it_final-amount = itab1-field2+0(v_int1).
APPEND it_final.
CLEAR: it_final , v_int1.
ENDIF.
endif.
ENDLOOP.
ENDIF.
ENDLOOP.
LOOP AT it_final.
WRITE : / it_final-amount.
ENDLOOP.[/code]
‎2006 Dec 27 2:02 PM
There doesn't seem to be an structure to the data here, for example.
There is not space in between the values.
INV03467225-$2137.27
There is space between.
INV03467224 $ 56743.69
So which is it? Or can it be both? Seems like bad design to me. Anyway that the data can be comma delimited? It would make it real easy.
Regards,
Rich Heilman
‎2006 Dec 27 2:06 PM
Hi Rich,
It can be both ( a bad design )
Well, assuming that there is no space could you pls help me how to proceed further?
thanks
‎2006 Dec 27 2:07 PM
SPLIT I_STRING AT '$' INTO A_AMOUNT.
SPLIT I_STRING AT 'USD' INTO A_AMOUNT.
SPLIT I_STRING AT ' ' INTO A_AMOUNT.
"this will split the text at the $ or USD and at the space after the amount into new_amount. The number 8 im assuming to be the longest possible entry, you can increase this.
NEW_AMOUNT = I_STRING(8).
hope this helps.
Warren
‎2006 Dec 27 2:09 PM
sorry, let me make a correction to my logic.....
SPLIT I_STRING AT '$' INTO A_AMOUNT.
SPLIT A_AMOUNT AT 'USD' INTO B_AMOUNT.
SPLIT B_AMOUNT AT ' ' INTO A_AMOUNT.
"this will split the text at the $ or USD and at the space after the amount into new_amount. The number 8 im assuming to be the longest possible entry, you can increase this.
NEW_AMOUNT = A_AMOUNT(8).
‎2006 Dec 27 2:43 PM
Hi Warren,
Thanks for the reply. I specified that the amount can vary.
What if the string contains amount of only two digits below or space :
INV03467225-$37.27SWF
INV03467225-$37.27
After split, the variable A_AMOUNT(8) contains 37.27SWF which is invalid.
May i know if there is better solution?
Thanks
‎2006 Dec 27 3:26 PM
Dan,
It is very difficult to retreive this amount because there seems to be no standard formatting. If there is always a $ or USD before the amount, then we easily clear all to the left of the $ including the $. In the example above, there is a space proceeding the amount. Is there always a space after the amount? If not, does SWF always proceed in place of the space?
Warren
‎2006 Dec 27 4:07 PM
[code]Hi Dan,
Execute the program and chekout , looks confusing but may solve ur problem
REPORT ychatest LINE-SIZE 350.
DATA : v_invoice TYPE string,
v_invoice1 TYPE string,
v_invoice2 TYPE string,
v_int1 TYPE i,
v_lines type i.
DATA : BEGIN OF itab OCCURS 0,
field1(100),
END OF itab.
DATA : BEGIN OF itab1 OCCURS 0,
field2(100),
END OF itab1.
DATA : BEGIN OF it_final OCCURS 0,
amount(100),
END OF it_final.
v_invoice1 = 'SWF OF 06/12/07 INV03467225-$2137.27 INV03467224 $ 56743.69 INV03404808'.
v_invoice2 = 'INVOICE,-03464401USD35065.53 INVOICE-03464400-USD300472.16'.
CONCATENATE v_invoice1 v_invoice2 INTO v_invoice.
REFRESH: itab , itab1 , it_final.
SPLIT v_invoice AT '$' INTO TABLE itab.
READ TABLE itab INDEX 1.
SEARCH itab-field1 FOR 'USD'.
IF sy-subrc EQ 0.
SPLIT itab-field1 AT 'USD' INTO TABLE itab1.
delete itab1 index 1.
clear itab1.
describe table itab1 lines v_lines.
LOOP AT itab1.
CONDENSE itab1-field2.
if sy-tabix eq v_lines.
it_final-amount = itab1-field2.
APPEND it_final.
clear it_final.
else.
SEARCH itab1-field2 FOR 'INV'.
IF sy-subrc EQ 0.
v_int1 = sy-fdpos - 1.
it_final-amount = itab1-field2+0(v_int1).
APPEND it_final.
CLEAR: it_final , v_int1 , v_lines..
ENDIF.
endif.
ENDLOOP.
ENDIF.
DELETE itab INDEX 1.
CLEAR :itab , itab1,it_final.
LOOP AT itab.
CONDENSE itab-field1.
SEARCH itab-field1 FOR 'INV'.
IF sy-subrc EQ 0.
v_int1 = sy-fdpos - 1.
it_final-amount = itab-field1+0(v_int1).
APPEND it_final.
CLEAR : it_final , v_int1.
ENDIF.
SEARCH itab-field1 FOR 'USD'.
IF sy-subrc EQ 0.
refresh itab1.
SPLIT itab-field1 AT 'USD' INTO TABLE itab1.
delete itab1 index 1.
clear : itab1 , v_lines.
describe table itab1 lines v_lines.
LOOP AT itab1.
CONDENSE itab1-field2.
if sy-tabix eq v_lines.
it_final-amount = itab1-field2.
APPEND it_final.
clear it_final.
else.
SEARCH itab1-field2 FOR 'INV'.
IF sy-subrc EQ 0.
v_int1 = sy-fdpos - 1.
it_final-amount = itab1-field2+0(v_int1).
APPEND it_final.
CLEAR: it_final , v_int1.
ENDIF.
endif.
ENDLOOP.
ENDIF.
ENDLOOP.
LOOP AT it_final.
WRITE : / it_final-amount.
ENDLOOP.[/code]
‎2006 Dec 27 5:43 PM
Is the amount always preceded by either "USD" or "$" (no spaces), or can there be others?
Rob
‎2006 Dec 27 6:40 PM
Hi Rob,
The amount is always preceded by $, or USD or spaces and not b others.
thanks