Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Please correct me in reading application server file with '~' delimiter

Former Member
0 Kudos

I have an application server file.

I need to read the file and keep the data into internal table.

I have the below data in application server file.

2009010000000112300012030850000114792110~ 43958.780.000USD ~

2009010000000112100012241060000114792110~ 136402.290.000USD ~

2009010000004077000040010240000114792110~ -132632.930.000USD ~

2009010000000112000012010100000114792110~ 715218.250.000USD ~

I have declared my internal table as....

*-Type for input file internal table.

TYPES : BEGIN OF tp_input_trans_file_data,

posting_period TYPE char07, " Posting period

grp_account TYPE char10, " Group Account Number

account TYPE char10, " G/L account number

cost_center TYPE char10, " Cost Center

currency_type TYPE char3, " 3-Byte field

document_type TYPE char_02, " Document type

amount_balance TYPE p DECIMALS 2," 17 2 Total of transactions of the period in group currency

quantity_balance TYPE p DECIMALS 3," MENGE_D, " Total of the transactions of period in units of measure

currency_code TYPE waers_curc, " Currency Key

unit_of_meas TYPE lagme, " Base Unit of Measure

END OF tp_input_trans_file_data.

Reading input file in below routine...

Form read_input_file.

DATA : wa_ip_fline TYPE string.

DATA : h_offset TYPE i VALUE '0',

lv_amt_bal TYPE char17,

lv_qty_bal TYPE char17.

  • The file mentioned in the server file path is created.

OPEN DATASET p_ifname FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

CLEAR : wa_ip_fline, h_offset.

READ DATASET p_ifname INTO wa_ip_fline.

IF sy-subrc NE 0.

EXIT.

ELSE.

*put corresponsing values of file into workarea

SPLIT wa_ip_fline AT '~'

INTO wa_trans_file_data-posting_period

wa_trans_file_data-grp_account

wa_trans_file_data-account

wa_trans_file_data-cost_center

wa_trans_file_data-currency_type

wa_trans_file_data-document_type

lv_amt_bal

lv_qty_bal

wa_trans_file_data-currency_code

wa_trans_file_data-unit_of_meas.

wa_trans_file_data-amount_balance = lv_amt_bal .

wa_trans_file_data-quantity_balance = lv_qty_bal.

APPEND wa_trans_file_data TO p_itab_trans_file_data.

CLEAR : wa_trans_file_data.

ENDIF.

ENDDO.

CLOSE DATASET p_ifname.

Please validate above idea is correct or not ?

However, say for even first record

2009010000000112300012030850000114792110~ 43958.780.000USD ~

'~' value is sitting in last field which is not correct and hwo to avoid this ?

POSTING_PERIOD = 2009010

GRP_ACCOUNT = 0000001120

ACCOUNT = 0001201010

COST_CENTER = 0000114792

CURRENCY_TYPE = 110

DOCUMENT_TYPE =

AMOUNT_BALANCE = 715218.25

QUANTITY_BALANCE = 0.000

CURRENCY_CODE = USD

UNIT_OF_MEAS = ~

YOUR HELP IS HIGHLY APPRECIATED. THANKS IN ADVANCE.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Sorry , I did not get what do you mean by

Check whether the last field UNIT_OF_MEAS is empty or not .

How to do this?

The second point you said is that

I need to count all of the characters in workarea and

offset last three charactes and

check whether that is equal to '~ ~' ? is it ?

4 REPLIES 4

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Check whether the last field UNIT_OF_MEAS is empty or not .

or if you have two ~ consecutively you may ignore it .

Former Member
0 Kudos

Sorry , I did not get what do you mean by

Check whether the last field UNIT_OF_MEAS is empty or not .

How to do this?

The second point you said is that

I need to count all of the characters in workarea and

offset last three charactes and

check whether that is equal to '~ ~' ? is it ?

0 Kudos

Hi Sam

There are 10 delimiter characters (~) in each line of your file which suggests that there are 11 fields. As you have only put 10 fields in your SPLIT statement, the last field will contain everything after the 9th delimiter - that is, a space character plus the 10th delimiter.

Assuming there's no valuable data after the last delimiter, simply add an 11th field to your SPLIT statement (eg. lv_remainder) and your UOM field should then contain just a space.

Kind Regards

Glen

Former Member
0 Kudos

THANK YOU VERY VERY MUCH! Glen Simpson