2009 Aug 31 7:22 PM
Hi,
Is it possible to modify the split command to include a conversion of one of the fields from string to currency?
I have these data structures:
Types: Begin of ttab,
rec(1000) type c,
end of ttab.
data: itab type table of ttab with header line.
data: Begin of itab2 OCCURS 0,
sir_id like zfmusfga-gl_sirid,
refdocnr like zfmusfga-refdocnr,
budat like zfmusfga-budat,
racct like zfmusfga-racct,
usnam like zfmusfga-usnam,
ryear like zfmusfga-ryear,
poper like zfmusfga-poper,
rfistl like zfmusfga-rfistl,
rfund like zfmusfga-rfund,
belnr like zfmusfga-belnr,
hsl like zfmusfga-hsl,
end of itab2.
And I have this code:
Loop at itab.
split itab-rec at '|' into itab2-sir_id
itab2-refdocnr
itab2-budat
itab2-racct
itab2-usnam
itab2-ryear
itab2-poper
itab2-rfistl
itab2-rfund
itab2-belnr
itab2-hsl.
append itab2.
endloop.
It doesn't work because zfmusfga-hsl is a currency type, not a string. Is there an easy way to convert itab2-hsl into currency within the split command?
Thanks,
Kevin
2009 Aug 31 7:59 PM
The answer to your question is definitely NO. If you want to know how to convert it if you don't know, please tell us what is the expected format of "HSL" in the file, and then we can give you a precise answer. For example, does it contain thousands separator (is it comma or something else), where is the sign, does it have fixed decimals without decimal separator, etc.
The answer to your question is definitely NO. If you want to know how to convert it if you don't know, please tell us what is the expected format of "HSL" in the file, and then we can give you a precise answer. For example, does it contain thousands separator (is it comma or something else), where is the sign, does it have fixed decimals without decimal separator, etc.
2009 Aug 31 7:29 PM
Hi,
Not sure if thats not possible. but there is no harm in declaring the internal table field hsl as type char in internal table. the same would work in select statements also
Types: Begin of ttab,
rec(1000) type c,
end of ttab.
data: itab type table of ttab with header line.
data: Begin of itab2 OCCURS 0,
sir_id like zfmusfga-gl_sirid,
refdocnr like zfmusfga-refdocnr,
budat like zfmusfga-budat,
racct like zfmusfga-racct,
usnam like zfmusfga-usnam,
ryear like zfmusfga-ryear,
poper like zfmusfga-poper,
rfistl like zfmusfga-rfistl,
rfund like zfmusfga-rfund,
belnr like zfmusfga-belnr,
hsl(10) type c,
end of itab2.
Loop at itab.
split itab-rec at '|' into itab2-sir_id
itab2-refdocnr
itab2-budat
itab2-racct
itab2-usnam
itab2-ryear
itab2-poper
itab2-rfistl
itab2-rfund
itab2-belnr
itab2-hsl.
append itab2.
endloop.
Regards,
Vikranth
2009 Aug 31 7:32 PM
Hi,
Try this Function module
'HRCM_STRING_TO_AMOUNT_CONVERT'
Regards
Krishna
2009 Aug 31 7:59 PM
The answer to your question is definitely NO. If you want to know how to convert it if you don't know, please tell us what is the expected format of "HSL" in the file, and then we can give you a precise answer. For example, does it contain thousands separator (is it comma or something else), where is the sign, does it have fixed decimals without decimal separator, etc.
2009 Aug 31 8:08 PM
The format is as follows:
16,919.51-
50.00
Always 2 decimals separated by period. Comma separates thousands with trailing minus sign. It is CURR data type, length 17 with decimal 2.
I guess I will have to import it as HSL(20) type C and then somehow convert the internal table field into another field of type currency and delete the character field from the internal table. It just seems like a cumbersome solution to a simple problem.
2009 Aug 31 8:21 PM
while spliting just keep every thing as it is and remove that itab2-hsl and put gv_hsl which should be of type string.
and then convert this gv_string to currency and pass it to itab2-hsl.
append itab2.
2009 Aug 31 9:52 PM
I made the following changes, but I get a convert error:
data: gv_hsl type string.
Loop at itab.
split itab-rec at '|' into itab2-sir_id
itab2-refdocnr
itab2-budat
itab2-racct
itab2-usnam
itab2-ryear
itab2-poper
itab2-rfistl
itab2-rfund
itab2-belnr
gv_hsl.
CALL FUNCTION 'HRCM_STRING_TO_AMOUNT_CONVERT'
EXPORTING
string = gv_hsl
decimal_separator = '.'
thousands_separator = ','
IMPORTING
betrg = itab2-hsl.
IF sy-subrc <> 0.
ENDIF.
append itab2.
endloop.
Any ideas? Please give me actual code-- I am very new to ABAP. Thanks!
2009 Aug 31 9:55 PM
welcome to sap world, sometimes we think we are in the prehistoric era
To convert, just remove the commas (REPLACE ALL OCCURRENCES OF ',' IN l_hsl_char WITH '') then call BAPI_CURRENCY_CONV_TO_INTERNAL to copy l_hsl_char into your l_hsl packed variable, pass also the currency code to which l_hsl corresponds.
Note: instead of calling the BAPI, you might prefer to code l_hsl = l_hsl_char, but I don't advise it as it would not be multi-currency compatible (even if the local currency will never change).
2009 Aug 31 10:34 PM
That is helpful. I guess my main problem is the types in SAP. I'm pretty new to SAP so please forgive me.
I have created a table that I want to update with data from an external '|' delimited text file.
It all will work fine, except the SAP table I created has an element zfmusfga-hsl that is of type data element VLCUR9 which appears to be a currency data type of length 17.
The BAPI returns data type bapicurr-bapicurr. I have to define in the internal table itab2 the hsl element as bapicurr-bapicurr or the bapi function module will not work. If I do that, the following code does not update the custom table that I created correctly:
INSERT ZFMUSFGA FROM TABLE itab2.
COMMIT WORK AND WAIT.
MESSAGE i899 WITH sy-dbcnt 'Records Written to ZFMUSFGA'.
In a nutshell, I have a bapicurr data type in an internal table and I'm trying to update a VLCUR9 data element in a table I created. It does not seem to want to allow that.
2009 Aug 31 11:08 PM
sorry, I forgot to say that you have to declare a separate l_bapicurr variable (type bapicurr-bapicurr) to be used with the BAPI, and after the call you do : l_hsl = l_bapicurr
that's all
2009 Sep 01 12:58 PM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |