How to write data to CSV file in ABL coding - csv

I populated a temp from a query, and the temp table looks like,
ttcomp.inum
ttcomp.iname
ttcomp.iadd
There are 5000 records in this temp table and now i wanted to write in a CSV file. I think it could be done with output stream but i don't know how to implement this. Please someone help me in getting this.

Export does the trick:
/* Define a stream */
DEFINE STREAM str.
/* Define the temp-table. I did some guessing according datatypes... */
DEFINE TEMP-TABLE ttcomp
FIELD inum AS INTEGER
FIELD iname AS CHARACTER
FIELD iadd AS INTEGER.
/* Fake logic that populates your temp-table is here */
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO 5000:
CREATE ttComp.
ASSIGN
ttComp.inum = i
ttComp.iname = "ABC123"
ttComp.iadd = 3.
END.
/* Fake logic done... */
/* Output the temp-table */
OUTPUT STREAM str TO VALUE("c:\temp\file.csv").
FOR EACH ttComp NO-LOCK:
/* Delimiter can be set to anything you like, comma, semi-colon etc */
EXPORT STREAM str DELIMITER "," ttComp.
END.
OUTPUT STREAM str CLOSE.
/* Done */

Here is an alternative without stream.
/* Using the temp-table. of Jensd*/
DEFINE TEMP-TABLE ttcomp
FIELD inum AS INTEGER
FIELD iname AS CHARACTER
FIELD iadd AS INTEGER.
OUTPUT TO somefile.csv APPEND.
FOR EACH ttcomp:
DISPLAY
ttcomp.inum + ",":U
ttcomp.iname + ",":U
ttcomp..iadd SKIP.
END.
OUTPUT CLOSE.

There is alternative way also. EXPORT is good in case format doesn't matter because EXPORT ignores format. For example you don't want format for date to be mm/dd/yy. In this case it is better to use PUT STREAM and specify format explicitly.
FOR EACH ttComp NO-LOCK:
PUT STREAM str UNFORMATTED SUBSTITUTE("&1;&2;&3 \n", ttComp.inum, ttcomp.iname, ttcomp.iadd).
END.

Related

Convert semicolon-separated string into table structure?

I need some help for converting a string into in ITAB.
LOOP AT LT_0111_FILE INTO LV_STRING.
SPLIT LV_STRING AT ';' INTO TABLE LT_0111.
DO GV_COMP TIMES.
READ TABLE LT_0111 ASSIGNING <LV> INDEX SY-INDEX.
IF <LV> IS NOT INITIAL.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <STRUCT> TO <LV_COMP>.
IF <LV_COMP> IS ASSIGNED.
<LV_COMP> = <LV>.
ENDIF.
ENDIF.
ENDDO.
INSERT <STRUCT> INTO TABLE <TABLE>.
ENDLOOP.
In LT_0111_FILE is the table PA0111 as a string with separator ";".
Now I need to assign every field of this stringtable into the fields of the structure from PA0111.
I don´t want to do this for every field separatly because the fields will be created dynamically.
This code works for character fields but not for numbers. In the txt-file there will be numbers like 0,00 and to move them to the fields of the structure will give an error because the number have to be 0.00.
Thanks for the help
When you have an unknown structure and want to know what fields it has and what properties those fields have, then you can use the runtime type information classes.
First, get a type description of your target structure.
DATA lo_struct_description TYPE REF TO cl_abap_structdescr.
lo_struct_description ?= cl_abap_typedescr=>describe_by_data( <struct> ).
The casting-operator ?= is required here, because the return value of describe_by_data is a generic cl_abap_typedescr. You know that it got to be a structure, but the class does not know that. It could just as well be a table, simple type or a reference to an object. But if you can guarantee that it got to be a structure, you can up-cast it to a cl_abap_structdescr.
Now you can get a table describing all the fields of the structure with:
DATA lt_components TYPE abap_component_tab.
lt_components = lo_struct_description->get_components( ).
This table contains the names and the types of those components. So instead of using a DO-loop and using ASSIGN COMPONENT by index, you can LOOP AT the component table and use ASSIGN COMPONENT by name. And then you can handle each field according to its type:
LOOP AT lt_components INTO ls_component.
READ TABLE lt_0111 ASSIGNING <lv_in> INDEX sy-tabix.
IF sy-subrc = 0.
ASSIGN COMPONENT ls_component-name OF STRUCTURE <struct> TO <lv_out>.
IF sy-subrc = 0.
CASE ls_component-type->type_kind.
WHEN cl_abap_datadescr=>typekind_date.
" Special handling for dates
WHEN cl_abap_datadescr=>typekind_packed.
" Special handling for decimal numbers
" Check the other constants cl_abap_datadescr=>typekind_* for all the other types
" you might encounter in your use-case and which might require special treatment.
WHEN OTHERS.
" Probably just copyable. If not, you will get a runtime error here and need
" to implement special handling for this particular type_kind.
<lv_out> = <lv_in>.
ENDCASE.
ENDIF.
ENDIF.
ENDLOOP.
Actually I like Philips solution more, it is more error-proof and comprehensive in terms of type-handling, but just for the sake of diversity I will add this fast&dirty solution.
You can use methods methods of cl_rsda_csv_converter auxiliary class:
DATA: input TYPE TABLE OF string.
TYPES t_itab TYPE TABLE OF pa0009 WITH EMPTY KEY.
DATA(dref) = NEW t_itab( ).
APPEND ` 800;90051099;0;;;99991231;20080501;000;20100312;HORVATLU;;;;;;;;;;;;;;;46456.89;HUF;0.00;;0;;;;;HU;;;;;;;;;;;;;;;;00;;;;00000000;;;;; ` TO input.
APPEND ` 800;99000005;0;;;99991231;20170101;000;20170220;GUNASHMA;;;;;;;;;;;;;;;5564665.00;EUR;0.00;;0;;;;;DE;28511111;123;;;;;;;;;;;;;;00;;;;00000000;;;;; ` TO input.
DATA: ls_line TYPE LINE OF t_itab.
LOOP AT input ASSIGNING FIELD-SYMBOL(<fs_s>).
* creating converter
DATA(lo_csv) = cl_rsda_csv_converter=>create( i_separator = ';' ).
* Process records
lo_csv->csv_to_structure( EXPORTING i_data = <fs_s> IMPORTING e_s_data = ls_line ).
* inserting into itab
INSERT ls_line INTO TABLE dref->*.
ENDLOOP.

MySQL Trigger Replace Accented/Unwanted Variables using an Array of Values

I am trying to create a MySQL trigger to change a string into a proper filename. I would like to replace accented/strange variables with the equivalent counterparts (Québec -> Quebec)
I have an array (I found) with all the characters with the equivalent letter that I would like to replace with:
{"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","Ǩ":"K","Ķ":"K","Ⱪ":"K","Ꝃ":"K","Ḳ":"K","Ƙ":"K","Ḵ":"K","Ꝁ":"K","Ꝅ":"K","Ĺ":"L","Ƚ":"L","Ľ":"L","Ļ":"L","Ḽ":"L","Ḷ":"L","Ḹ":"L","Ⱡ":"L","Ꝉ":"L","Ḻ":"L","Ŀ":"L","Ɫ":"L","Lj":"L","Ł":"L","LJ":"LJ","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ń":"N","Ň":"N","Ņ":"N","Ṋ":"N","Ṅ":"N","Ṇ":"N","Ǹ":"N","Ɲ":"N","Ṉ":"N","Ƞ":"N","Nj":"N","Ñ":"N","NJ":"NJ","Ó":"O","Ŏ":"O","Ǒ":"O","Ô":"O","Ố":"O","Ộ":"O","Ồ":"O","Ổ":"O","Ỗ":"O","Ö":"O","Ȫ":"O","Ȯ":"O","Ȱ":"O","Ọ":"O","Ő":"O","Ȍ":"O","Ò":"O","Ỏ":"O","Ơ":"O","Ớ":"O","Ợ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ȏ":"O","Ꝋ":"O","Ꝍ":"O","Ō":"O","Ṓ":"O","Ṑ":"O","Ɵ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Õ":"O","Ṍ":"O","Ṏ":"O","Ȭ":"O","Ƣ":"OI","Ꝏ":"OO","Ɛ":"E","Ɔ":"O","Ȣ":"OU","Ṕ":"P","Ṗ":"P","Ꝓ":"P","Ƥ":"P","Ꝕ":"P","Ᵽ":"P","Ꝑ":"P","Ꝙ":"Q","Ꝗ":"Q","Ŕ":"R","Ř":"R","Ŗ":"R","Ṙ":"R","Ṛ":"R","Ṝ":"R","Ȑ":"R","Ȓ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꜿ":"C","Ǝ":"E","Ś":"S","Ṥ":"S","Š":"S","Ṧ":"S","Ş":"S","Ŝ":"S","Ș":"S","Ṡ":"S","Ṣ":"S","Ṩ":"S","Ť":"T","Ţ":"T","Ṱ":"T","Ț":"T","Ⱦ":"T","Ṫ":"T","Ṭ":"T","Ƭ":"T","Ṯ":"T","Ʈ":"T","Ŧ":"T","Ɐ":"A","Ꞁ":"L","Ɯ":"M","Ʌ":"V","Ꜩ":"TZ","Ú":"U","Ŭ":"U","Ǔ":"U","Û":"U","Ṷ":"U","Ü":"U","Ǘ":"U","Ǚ":"U","Ǜ":"U","Ǖ":"U","Ṳ":"U","Ụ":"U","Ű":"U","Ȕ":"U","Ù":"U","Ủ":"U","Ư":"U","Ứ":"U","Ự":"U","Ừ":"U","Ử":"U","Ữ":"U","Ȗ":"U","Ū":"U","Ṻ":"U","Ų":"U","Ů":"U","Ũ":"U","Ṹ":"U","Ṵ":"U","Ꝟ":"V","Ṿ":"V","Ʋ":"V","Ṽ":"V","Ꝡ":"VY","Ẃ":"W","Ŵ":"W","Ẅ":"W","Ẇ":"W","Ẉ":"W","Ẁ":"W","Ⱳ":"W","Ẍ":"X","Ẋ":"X","Ý":"Y","Ŷ":"Y","Ÿ":"Y","Ẏ":"Y","Ỵ":"Y","Ỳ":"Y","Ƴ":"Y","Ỷ":"Y","Ỿ":"Y","Ȳ":"Y","Ɏ":"Y","Ỹ":"Y","Ź":"Z","Ž":"Z","Ẑ":"Z","Ⱬ":"Z","Ż":"Z","Ẓ":"Z","Ȥ":"Z","Ẕ":"Z","Ƶ":"Z","IJ":"IJ","Œ":"OE","ᴀ":"A","ᴁ":"AE","ʙ":"B","ᴃ":"B","ᴄ":"C","ᴅ":"D","ᴇ":"E","ꜰ":"F","ɢ":"G","ʛ":"G","ʜ":"H","ɪ":"I","ʁ":"R","ᴊ":"J","ᴋ":"K","ʟ":"L","ᴌ":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
Is there a way to quickly and efficiently do this replace in my MySQL Trigger?
SET #STRING = "Québec";
FOR EACH ITEM IN ARRAY AS KEY/VALUE
SET #STRING=REPLACE(#STRING,KEY,VALUE);
END;
Or is there a better way to do this? I've tried to change my Encoding/Collation for my column without success.
You can't use arrays directly. But you can work with strings. Change array into string delimited by "," for each key/value pair and further delimited by ":". Then run through string in a while loop.
CREATE FUNCTION `sanitize_string`(STRING varchar(255)) RETURNS varchar(255)
begin
/* set as array as string delimited by a "," for each key/value pair and delimited again by a ":" for each key/value */
/* key is the unwanted character, value is the wanted character */
set #chars="Á:A,Ă:A,Ắ:A,Ặ:A,Ằ:A,Ẳ:A,Ẵ:A,Ǎ:A,Â:A,Ấ:A,Ậ:A,Ầ:A,Ẩ:A,Ẫ:A,Ä:A,Ǟ:A,Ȧ:A,Ǡ:A,Ạ:A,Ȁ:A,À:A,Ả:A,Ȃ:A,Ā:A,Ą:A,Å:A,Ǻ:A,Ḁ:A,Ⱥ:A,Ã:A,Ꜳ:AA,Æ:AE,Ǽ:AE,Ǣ:AE,Ꜵ:AO,Ꜷ:AU,Ꜹ:AV,Ꜻ:AV,Ꜽ:AY,Ḃ:B,Ḅ:B,Ɓ:B,Ḇ:B,Ƀ:B,Ƃ:B,Ć:C,Č:C,Ç:C,Ḉ:C,Ĉ:C,Ċ:C,Ƈ:C,Ȼ:C,Ď:D,Ḑ:D,Ḓ:D,Ḋ:D,Ḍ:D,Ɗ:D,Ḏ:D,Dz:D,Dž:D,Đ:D,Ƌ:D,DZ:DZ,DŽ:DZ,É:E,Ĕ:E,Ě:E,Ȩ:E,Ḝ:E,Ê:E,Ế:E,Ệ:E,Ề:E,Ể:E,Ễ:E,Ḙ:E,Ë:E,Ė:E,Ẹ:E,Ȅ:E,È:E,Ẻ:E,Ȇ:E,Ē:E,Ḗ:E,Ḕ:E,Ę:E,Ɇ:E,Ẽ:E,Ḛ:E,Ꝫ:ET,Ḟ:F,Ƒ:F,Ǵ:G,Ğ:G,Ǧ:G,Ģ:G,Ĝ:G,Ġ:G,Ɠ:G,Ḡ:G,Ǥ:G,Ḫ:H,Ȟ:H,Ḩ:H,Ĥ:H,Ⱨ:H,Ḧ:H,Ḣ:H,Ḥ:H,Ħ:H,Í:I,Ĭ:I,Ǐ:I,Î:I,Ï:I,Ḯ:I,İ:I,Ị:I,Ȉ:I,Ì:I,Ỉ:I,Ȋ:I,Ī:I,Į:I,Ɨ:I,Ĩ:I,Ḭ:I,Ꝺ:D,Ꝼ:F,Ᵹ:G,Ꞃ:R,Ꞅ:S,Ꞇ:T,Ꝭ:IS,Ĵ:J,Ɉ:J,Ḱ:K,Ǩ:K,Ķ:K,Ⱪ:K,Ꝃ:K,Ḳ:K,Ƙ:K,Ḵ:K,Ꝁ:K,Ꝅ:K,Ĺ:L,Ƚ:L,Ľ:L,Ļ:L,Ḽ:L,Ḷ:L,Ḹ:L,Ⱡ:L,Ꝉ:L,Ḻ:L,Ŀ:L,Ɫ:L,Lj:L,Ł:L,LJ:LJ,Ḿ:M,Ṁ:M,Ṃ:M,Ɱ:M,Ń:N,Ň:N,Ņ:N,Ṋ:N,Ṅ:N,Ṇ:N,Ǹ:N,Ɲ:N,Ṉ:N,Ƞ:N,Nj:N,Ñ:N,NJ:NJ,Ó:O,Ŏ:O,Ǒ:O,Ô:O,Ố:O,Ộ:O,Ồ:O,Ổ:O,Ỗ:O,Ö:O,Ȫ:O,Ȯ:O,Ȱ:O,Ọ:O,Ő:O,Ȍ:O,Ò:O,Ỏ:O,Ơ:O,Ớ:O,Ợ:O,Ờ:O,Ở:O,Ỡ:O,Ȏ:O,Ꝋ:O,Ꝍ:O,Ō:O,Ṓ:O,Ṑ:O,Ɵ:O,Ǫ:O,Ǭ:O,Ø:O,Ǿ:O,Õ:O,Ṍ:O,Ṏ:O,Ȭ:O,Ƣ:OI,Ꝏ:OO,Ɛ:E,Ɔ:O,Ȣ:OU,Ṕ:P,Ṗ:P,Ꝓ:P,Ƥ:P,Ꝕ:P,Ᵽ:P,Ꝑ:P,Ꝙ:Q,Ꝗ:Q,Ŕ:R,Ř:R,Ŗ:R,Ṙ:R,Ṛ:R,Ṝ:R,Ȑ:R,Ȓ:R,Ṟ:R,Ɍ:R,Ɽ:R,Ꜿ:C,Ǝ:E,Ś:S,Ṥ:S,Š:S,Ṧ:S,Ş:S,Ŝ:S,Ș:S,Ṡ:S,Ṣ:S,Ṩ:S,Ť:T,Ţ:T,Ṱ:T,Ț:T,Ⱦ:T,Ṫ:T,Ṭ:T,Ƭ:T,Ṯ:T,Ʈ:T,Ŧ:T,Ɐ:A,Ꞁ:L,Ɯ:M,Ʌ:V,Ꜩ:TZ,Ú:U,Ŭ:U,Ǔ:U,Û:U,Ṷ:U,Ü:U,Ǘ:U,Ǚ:U,Ǜ:U,Ǖ:U,Ṳ:U,Ụ:U,Ű:U,Ȕ:U,Ù:U,Ủ:U,Ư:U,Ứ:U,Ự:U,Ừ:U,Ử:U,Ữ:U,Ȗ:U,Ū:U,Ṻ:U,Ų:U,Ů:U,Ũ:U,Ṹ:U,Ṵ:U,Ꝟ:V,Ṿ:V,Ʋ:V,Ṽ:V,Ꝡ:VY,Ẃ:W,Ŵ:W,Ẅ:W,Ẇ:W,Ẉ:W,Ẁ:W,Ⱳ:W,Ẍ:X,Ẋ:X,Ý:Y,Ŷ:Y,Ÿ:Y,Ẏ:Y,Ỵ:Y,Ỳ:Y,Ƴ:Y,Ỷ:Y,Ỿ:Y,Ȳ:Y,Ɏ:Y,Ỹ:Y,Ź:Z,Ž:Z,Ẑ:Z,Ⱬ:Z,Ż:Z,Ẓ:Z,Ȥ:Z,Ẕ:Z,Ƶ:Z,IJ:IJ,Œ:OE,ᴀ:A,ᴁ:AE,ʙ:B,ᴃ:B,ᴄ:C,ᴅ:D,ᴇ:E,ꜰ:F,ɢ:G,ʛ:G,ʜ:H,ɪ:I,ʁ:R,ᴊ:J,ᴋ:K,ʟ:L,ᴌ:L,ᴍ:M,ɴ:N,ᴏ:O,ɶ:OE,ᴐ:O,ᴕ:OU,ᴘ:P,ʀ:R,ᴎ:N,ᴙ:R,ꜱ:S,ᴛ:T,ⱻ:E,ᴚ:R,ᴜ:U,ᴠ:V,ᴡ:W,ʏ:Y,ᴢ:Z,á:a,ă:a,ắ:a,ặ:a,ằ:a,ẳ:a,ẵ:a,ǎ:a,â:a,ấ:a,ậ:a,ầ:a,ẩ:a,ẫ:a,ä:a,ǟ:a,ȧ:a,ǡ:a,ạ:a,ȁ:a,à:a,ả:a,ȃ:a,ā:a,ą:a,ᶏ:a,ẚ:a,å:a,ǻ:a,ḁ:a,ⱥ:a,ã:a,ꜳ:aa,æ:ae,ǽ:ae,ǣ:ae,ꜵ:ao,ꜷ:au,ꜹ:av,ꜻ:av,ꜽ:ay,ḃ:b,ḅ:b,ɓ:b,ḇ:b,ᵬ:b,ᶀ:b,ƀ:b,ƃ:b,ɵ:o,ć:c,č:c,ç:c,ḉ:c,ĉ:c,ɕ:c,ċ:c,ƈ:c,ȼ:c,ď:d,ḑ:d,ḓ:d,ȡ:d,ḋ:d,ḍ:d,ɗ:d,ᶑ:d,ḏ:d,ᵭ:d,ᶁ:d,đ:d,ɖ:d,ƌ:d,ı:i,ȷ:j,ɟ:j,ʄ:j,dz:dz,dž:dz,é:e,ĕ:e,ě:e,ȩ:e,ḝ:e,ê:e,ế:e,ệ:e,ề:e,ể:e,ễ:e,ḙ:e,ë:e,ė:e,ẹ:e,ȅ:e,è:e,ẻ:e,ȇ:e,ē:e,ḗ:e,ḕ:e,ⱸ:e,ę:e,ᶒ:e,ɇ:e,ẽ:e,ḛ:e,ꝫ:et,ḟ:f,ƒ:f,ᵮ:f,ᶂ:f,ǵ:g,ğ:g,ǧ:g,ģ:g,ĝ:g,ġ:g,ɠ:g,ḡ:g,ᶃ:g,ǥ:g,ḫ:h,ȟ:h,ḩ:h,ĥ:h,ⱨ:h,ḧ:h,ḣ:h,ḥ:h,ɦ:h,ẖ:h,ħ:h,ƕ:hv,í:i,ĭ:i,ǐ:i,î:i,ï:i,ḯ:i,ị:i,ȉ:i,ì:i,ỉ:i,ȋ:i,ī:i,į:i,ᶖ:i,ɨ:i,ĩ:i,ḭ:i,ꝺ:d,ꝼ:f,ᵹ:g,ꞃ:r,ꞅ:s,ꞇ:t,ꝭ:is,ǰ:j,ĵ:j,ʝ:j,ɉ:j,ḱ:k,ǩ:k,ķ:k,ⱪ:k,ꝃ:k,ḳ:k,ƙ:k,ḵ:k,ᶄ:k,ꝁ:k,ꝅ:k,ĺ:l,ƚ:l,ɬ:l,ľ:l,ļ:l,ḽ:l,ȴ:l,ḷ:l,ḹ:l,ⱡ:l,ꝉ:l,ḻ:l,ŀ:l,ɫ:l,ᶅ:l,ɭ:l,ł:l,lj:lj,ſ:s,ẜ:s,ẛ:s,ẝ:s,ḿ:m,ṁ:m,ṃ:m,ɱ:m,ᵯ:m,ᶆ:m,ń:n,ň:n,ņ:n,ṋ:n,ȵ:n,ṅ:n,ṇ:n,ǹ:n,ɲ:n,ṉ:n,ƞ:n,ᵰ:n,ᶇ:n,ɳ:n,ñ:n,nj:nj,ó:o,ŏ:o,ǒ:o,ô:o,ố:o,ộ:o,ồ:o,ổ:o,ỗ:o,ö:o,ȫ:o,ȯ:o,ȱ:o,ọ:o,ő:o,ȍ:o,ò:o,ỏ:o,ơ:o,ớ:o,ợ:o,ờ:o,ở:o,ỡ:o,ȏ:o,ꝋ:o,ꝍ:o,ⱺ:o,ō:o,ṓ:o,ṑ:o,ǫ:o,ǭ:o,ø:o,ǿ:o,õ:o,ṍ:o,ṏ:o,ȭ:o,ƣ:oi,ꝏ:oo,ɛ:e,ᶓ:e,ɔ:o,ᶗ:o,ȣ:ou,ṕ:p,ṗ:p,ꝓ:p,ƥ:p,ᵱ:p,ᶈ:p,ꝕ:p,ᵽ:p,ꝑ:p,ꝙ:q,ʠ:q,ɋ:q,ꝗ:q,ŕ:r,ř:r,ŗ:r,ṙ:r,ṛ:r,ṝ:r,ȑ:r,ɾ:r,ᵳ:r,ȓ:r,ṟ:r,ɼ:r,ᵲ:r,ᶉ:r,ɍ:r,ɽ:r,ↄ:c,ꜿ:c,ɘ:e,ɿ:r,ś:s,ṥ:s,š:s,ṧ:s,ş:s,ŝ:s,ș:s,ṡ:s,ṣ:s,ṩ:s,ʂ:s,ᵴ:s,ᶊ:s,ȿ:s,ɡ:g,ᴑ:o,ᴓ:o,ᴝ:u,ť:t,ţ:t,ṱ:t,ț:t,ȶ:t,ẗ:t,ⱦ:t,ṫ:t,ṭ:t,ƭ:t,ṯ:t,ᵵ:t,ƫ:t,ʈ:t,ŧ:t,ᵺ:th,ɐ:a,ᴂ:ae,ǝ:e,ᵷ:g,ɥ:h,ʮ:h,ʯ:h,ᴉ:i,ʞ:k,ꞁ:l,ɯ:m,ɰ:m,ᴔ:oe,ɹ:r,ɻ:r,ɺ:r,ⱹ:r,ʇ:t,ʌ:v,ʍ:w,ʎ:y,ꜩ:tz,ú:u,ŭ:u,ǔ:u,û:u,ṷ:u,ü:u,ǘ:u,ǚ:u,ǜ:u,ǖ:u,ṳ:u,ụ:u,ű:u,ȕ:u,ù:u,ủ:u,ư:u,ứ:u,ự:u,ừ:u,ử:u,ữ:u,ȗ:u,ū:u,ṻ:u,ų:u,ᶙ:u,ů:u,ũ:u,ṹ:u,ṵ:u,ᵫ:ue,ꝸ:um,ⱴ:v,ꝟ:v,ṿ:v,ʋ:v,ᶌ:v,ⱱ:v,ṽ:v,ꝡ:vy,ẃ:w,ŵ:w,ẅ:w,ẇ:w,ẉ:w,ẁ:w,ⱳ:w,ẘ:w,ẍ:x,ẋ:x,ᶍ:x,ý:y,ŷ:y,ÿ:y,ẏ:y,ỵ:y,ỳ:y,ƴ:y,ỷ:y,ỿ:y,ȳ:y,ẙ:y,ɏ:y,ỹ:y,ź:z,ž:z,ẑ:z,ʑ:z,ⱬ:z,ż:z,ẓ:z,ȥ:z,ẕ:z,ᵶ:z,ᶎ:z,ʐ:z,ƶ:z,ɀ:z,ff:ff,ffi:ffi,ffl:ffl,fi:fi,fl:fl,ij:ij,œ:oe,st:st,ₐ:a,ₑ:e,ᵢ:i,ⱼ:j,ₒ:o,ᵣ:r,ᵤ:u,ᵥ:v,ₓ:x";
/* while string contains a ",", keep looping */
while(locate(',',#chars)>0)
do
/* get first key/value pair */
set #pair=substring_index(#chars,',',1);
/* get the key */
set #key=substring_index(#pair,':',1);
/* get the value */
set #value=replace(#pair,#key+':','');
/* cut the key/value pair out of the array string for next loop */
set #chars=substring(#chars,locate(',',#chars)+1);
/* if key exists, replace with value */
set STRING=replace(STRING,#key,#value);
end while;
return STRING;
end;
Where:
return sanitize_string("Québec");
/* returns "Quebec" */

GAMS csv read issue

I'm trying to read a .csv file with the following format using MAC:
;lon;lat
0;55,245594;25,066697
1;55,135613;25,070419
2;55,275683;25,203425
What I am doing so far is:
$call csv2gdx coords.csv id=d index=1 values=2..lastCol useHeader=y
sets
i
c /x,y/
;
parameters
dloc(i,c) 'locations'
;
$gdxin clients_csv.gdx
$load ___ ?
What I want to do is read the lat,lon coordinates in the parameter dloc so as for each i to have a pair of coords c, i.e. lat, lon.
Example output:
x y
i1 17.175 84.327
Running your code produces an error from csv2gdx:
*** ErrNr = 15 Msg = Values(s) column number exceeds column count; Index = 2, ColCnt = 1
Per default, csv2gdx expects the entries separated by commas, which you do not have in your data. You could also define semicolon or tab as separator by means of an option, but if the data has really the format you posted, you do not need to call csv2gdx at all. You could just include the data directly like this:
Sets
i
c
;
Table dloc(i<,c<) 'locations'
$include coords.csv
;
Display dloc;
EDIT after change of input data format:
The error message is still the same. And also the reason is the same: You use a different field separator than the default one. If you switch that using the option fieldSep=semiColon, you will realize that also your decimal separator is non-default for csv2gdx. But this can be changed as well. Here is the whole code (with adjusted csv2gdx call and adjustments for data loading). Note that sets i and c get implicitly defined when loading dloc with the < syntax in the declaration of dloc.
$call csv2gdx coords.csv id=d index=1 values=2..lastCol useHeader=y fieldSep=semiColon decimalSep=comma
Sets
i
c
;
parameters
dloc(i<,c<) 'locations'
;
$gdxin coords.gdx
$load dloc=d
Display dloc;
$exit\

Progress ABL format decimal number without leading characters

I just want to format a decimal number for output to a simple CSV formatted file.
I feel like I'm stupid, but I can't find a way to do it without leading zeroes or spaces, of course I can simply trim the leading spaces, but there has to be a proper way to just format like I that, isn't there?
Example
define variable test as decimal.
define variable testString as character.
test = 12.3456.
testString = string(test, '>>>>>9.99').
message '"' + testString + '"' view-as alert-box. /* " 12.35" */
I tried using >>>>>9.99 and zzzzz9.99 for the number format, but both format the string with leading spaces. I actually have no idea what the difference is between using > and z.
The SUBSTITUTE() function will do what you describe wanting:
define variable c as character no-undo.
c = substitute( "&1", 1.23 ).
display "[" + c + "]".
(Toss in a TRUNCATE( 1.2345, 2 ) if you really only want 2 decimal places.)
Actually, this also works:
string( truncate( 1.2345, 2 )).
If you are creating a CSV file you might want to think about using EXPORT. EXPORT format removes leading spaces and omits decorations like ",". The SUBSTITUTE() function basically uses EXPORT format to make its substitutions. The STRING() function uses EXPORT format when no other format is specified.
The EXPORT statement will format your data for you. Here is an example:
DEFINE VARIABLE test AS DECIMAL NO-UNDO.
DEFINE VARIABLE testRound AS DECIMAL NO-UNDO.
DEFINE VARIABLE testString AS CHARACTER NO-UNDO.
test = 12.3456.
testRound = ROUND(test, 2).
testString = STRING(test).
OUTPUT TO VALUE("test.csv").
EXPORT DELIMITER "," test testRound testString.
OUTPUT CLOSE.
Here is the output:
12.3456,12.35,"12.3456"
The EXPORT statement's default delimiter is a space so you have to specify a comma for your CSV file. Since the test and testRound variables are decimals, they are not in quotes in the output. testString is character so it is in quotes.

How to convert jsonAST.Jint to int

I am attempting to learn Scala, and I'm trying to parse a JSON file. I have two lines of code:
var jVal:JValue = parse(json);
val totalCount:Int = (jVal \\ "totalCount").asInstanceOf[Int];
However, (jVal \\ "totalCount") returns a JInt instead of an int. If I print it as a string, it looks like "JInt(38)".
How on earth do I convert this to a regular int? My current code throws an exception saying that
net.liftweb.json.JsonAST$JInt cannot be cast to java.lang.Integer
I've scoured the internet, but I can't find any answers. I would really prefer not to manually parse and remove the "JInt()" part of the string just to get it as an integer.
Surely I am missing a simple way to do this?
Since JInt is a case class, a convenient way to extract the value is using an extractor expression, either in a match:
myJValue match {
case JInt(x) => /* do something with x */
case JString(s) => /* do something with s */
/* etc. */
}
or just an assignment statement, when you know what type to expect:
val JInt(totalCount) = (jVal \\ "totalCount")
This will define totalCount to be the value of "totalCount" in your JSON. Note that it will be of type BigInt. If you want to, you can convert your BigInt to an Int with the toInt method. But if your number is too big for an Int, this method will give you a different number instead of an error. So if huge numbers are at all a possibility, you'll want to check first with isValidInt.
You can also get the value using the num field or values method, but in your code that's harder to work with. To use num, you'd have to do a cast of your JValue to JInt. And if you don't cast to JInt, you won't know the type of the result of values.