I work as an ABAP programmer at one very large industrial enterprise. I am mainly engaged in support and maintenance, because in work there are often lulls. I decided to write an article about ABAP.
When I got a job in R / 3, I already saw and could do something. ABAP / 4 we studied at the institute. They showed the basic syntax, and a couple of programs wrote simple ones.
The first week at work, I read a book on ABAP and missed frankly. After some time, I was finally given the assignment.
')
Who are interested in welcome.
As it turned out, the task was aimed at solving a fairly common problem. Namely, the download rates in the system from the site of the central bank.
In our company there is a person who is engaged in the introduction of these courses.
How it worked before my intervention. The user went to the site of the centro-bank, copied the plate with the courses, then the script written in python, the case was brought into the desired form, and then the user started the transaction in R / 3 and fed the program the resulting text file. Extremely tricky operation.
I started to work.
At first, I looked at the central bank website and found out that it is possible to pick up exchange rates as an XML file from the site. I decided not to eat the brain for myself and write to start a program that will eat this file and shove it into the inner table.
R / 3 knows how to eat XML files, but I didn’t manage to figure out how to use the Function Module for working with XML and decided to write my bicycle, it was young. By the method of not frail instillation into the Internet, a help and a smart book, I found a FM that reads a file into an internal table. The result is such a form:
* . form get_file tables table_name using file_name like rlgrap-filename. call function 'WS_UPLOAD' exporting CODEPAGE = ' ' FILENAME = FILE_NAME FILETYPE = 'ASC' tables DATA_TAB = TABLE_NAME exceptions CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TYPE = 4 NO_BATCH = 5 OTHERS = 6. * . case sy-subrc. when 1. write ' .'. exit. when 2. write ' .'. exit. when 3. write ' .'. exit. when 4. write ' .'. exit. when 5. write 'Front-End Function Cannot Be Executed in Backgrnd.'. exit. when 6. write ' .'. exit. endcase. endform.
FM issues a TABLE_NAME sign in which each line is a line of the downloaded file. There was a question as from lines of a type:
<Valute ID="R01010"> <NumCode>036</NumCode> <CharCode>AUD</CharCode> <Nominal>1</Nominal> <Name> </Name> <Value>27,0138</Value> </Valute>
Get the currency code, denomination and the actual rate. At the previous work I was engaged in web development, I didn’t achieve much success in this field, but I got some useful knowledge. In general, during the next immersion in the help, I found out that in the ABAP language I can work with regular expressions. Without hesitation, I built a structure of the type:
* . read table valuta into valuta index 2. RE-PLACE REGEX '(\W\w+\W\w+\W+)(\d+)(\D)(\d+)(\D)(\d+)(\W+\w+\W+\w+.\w+)' IN valuta WITH `$2.$4.$6`. if sy-subrc = 0. date = valuta. endif. * . loop at l_val into l_val. clear val. if l_val-waers <> 'UE'. * XML . concatenate '<CharCode>' l_val-waers '</CharCode>' into s_val. find s_val in table valuta match line index. if sy-subrc = 0. val-kodv = l_val-waers. val-datan = date. add 1 to index. read table valuta into valuta index index. * . REPLACE REGEX '(\W+\w+\W)(\d+)(\W+\w+\W)' IN valuta WITH '$2'. nom = valuta. add 2 to index. read table valuta into valuta index index. * . RE-PLACE REGEX '(\W+\w+\W)(\d+)(\D)(\d+)(\W+\w+\W)' IN valuta WITH '$2.$4'. if sy-subrc = 0. tmp = valuta / nom. val-kyrsp = tmp. replace all occurrences of '.' in val-kyrsp with ','. * . append val. endif. else. s_val = text-wv1. replace '&1' in s_val with l_val-waers. message s_val type 'I'. endif. endif. endloop.
Sloppy, but then I was proud of myself, when the whole thing worked.
By this time, I was given a login and password to access the Internet. And the chief offered to look towards the HTTP_GET function module. But unfortunately there was no documentation on this module in our system, I had to guess by touch how to work with this miracle.
I tried to feed the URL password and login to the proxy, but there was no result. After several experiments, I determined that the proxy server does not allow access to the outside world.
I had to dig into Google again and forums. On one of the forums I found a solution. It turns out that HTTP_GET is crookedly communicating with proxies and offering a solution.
The proxy data must be entered in the THTTP table, the function module 'HTTP_PROXY_CONFIG' must be entered in the EXITFUNC field of this table (it determines if a proxy is required to connect to the URL, if yes, then the data from the table string is transmitted).
Well, the function module call itself looks like this for me:
call function 'HTTP_GET' exporting absolute_uri = url blankstocrlf = 'x' timeout = 500 rfc_destination = 'SAPHTTP' tables response_entity_body = file_table response_headers = file_headers exceptions connect_failed = 1 timeout = 2 internal_error = 3 tcpip_error = 4 data_error = 5 system_failure = 6 communication_failure = 7.
After all the manipulations and dances with the R / 3 tambourine, I began to break into the site and collect the necessary data in the internal table. The program took data from the site, then from the resulting label, codes and exchange rates are pulled out using regular expressions, and then all this is entered into the system by batch input.