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: 

'GUI_UPLOAD': uploading of only numbers

Former Member
0 Kudos

Dear Experts,

I use 'GUI_UPLOAD' for uploading of the CSV-File into my ALV and I need that whatever information this list contains, only numbers (well no letters)

will be uploaded into the grid.

My current code for uploading looks following:

CALL FUNCTION 'GUI_UPLOAD'

     EXPORTING

       filename = v_filename

       filetype = 'ASC'

     TABLES

       data_tab = ta_csv_data.

   LOOP AT ta_csv_data INTO v_string.

     IF sy-tabix = 1.

       CONTINUE.

     ENDIF.

     SPLIT v_string AT ';'

     INTO

     wa_csv-vkorg

     wa_csv-matnr

     wa_csv-preis.

     APPEND wa_csv TO ta_csv.

     CLEAR wa_csv.


Is this somehow possible?


Thank you in advance


BR, Denis

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Thank Simone, Klaus for your feedbacks,

but I don't understand how declaring of the field WA_CSV-PREIS as a character, will help me to avoid the uploadning of the letters?

BR

Denis

19 REPLIES 19

former_member195402
Active Contributor
0 Kudos

Hi,

either your field catalog has wrong definitions, or your wa_csv fields are defined numeric instead of alpha.

Regards,

Klaus

SimoneMilesi
Active Contributor
0 Kudos

Hello Denis,

how  ta_csv_data and TA_CSV are declared?

0 Kudos

Hi Simone.

ta_csv_data      TYPE STANDARD TABLE OF zst_preisupload

ta_csv      TYPE STANDARD TABLE OF zst_preisupload

Structure zst_preisupload:

UPDATE: actually I need the number only for Prices, but the Datatyp is already CURR...

0 Kudos

First of all (not related to your issue, but maybe....): why you split at ';' if you are uploading data into an internal table with the correct structure?

WA_CSV how it's declared?

My suggestion

DATA: ta_csv_data type table of string,

                  wa_csv should be a full char structure

                         vkorg type vkorg,

                          matnr type matnr,

                         preis (10)

->upload ta_csv_data as now

loop at ta_csv_data into lv_string

split as now into wa_csv

move-corresponding wa_csv to TA_CSV

append ta_csv.

endloop

0 Kudos

Hi,

how are the WA_CSV fields defined?

WA_CSV-PREIS must be a character type for upload. After upload you may convert it to currency type.

Regards,

Klaus

0 Kudos

Thank you for fast feedbac, Simone,

well without spliting the information will be written just as a string.

I have declared WA_CSV following:

wa_csv           LIKE LINE OF ta_csv


.

0 Kudos

As stated also by Klaus, if you use split, you have to declare DESTINATION FIELDS type char.

IF you have separators, then TA_CSV_TAB should not be declare like your structure: look at it, the Zstructure got no separator!

Former Member
0 Kudos

Thank Simone, Klaus for your feedbacks,

but I don't understand how declaring of the field WA_CSV-PREIS as a character, will help me to avoid the uploadning of the letters?

BR

Denis

0 Kudos

Sorry, i completly misunderstood the request.

You got your data correctly uploaded then and want to remove all non numeric characters?

0 Kudos

No problem, may be I should describe it more clear.

Yes, the data are uploaded and look good and yes I want to remove all non numeric characters

0 Kudos

From here

DATA lv_text TYPE string VALUE 'ab000cdeSDFf34534gh1ASDF234ijk5abc0'.
 WRITE : /,'Before Replace :',lv_text. REPLACE ALL OCCURRENCES OF REGEX '[[:alpha:]]' IN lv_text WITH ''. 
WRITE : /,'After Replace :',lv_text.  
Output: Before Replace : ab000cdeSDFf34534gh1ASDF234ijk5abc0  7
After Replace : 00034534123450

[[:alpha:]]

specifies any alphabet in lower or upper case.

Remember that there is no space between the single quotes in the WITH clause.

Or here

You have to do it for your char fields

0 Kudos

There can be other non-numeric characters like special character, which will not be removed when you remove all alphabets. Instead, you should replace all occurrences of regex '\D' which means anything which is not '\d', which means non-numeric characters.

0 Kudos

Thank you for the advise, Manish. I already was thoinking how to solve it in term also to avoid special characters, but when I use

REPLACE ALL OCCURRENCES OF REGEX '\D' IN v_string WITH ''


for some reason happening following:


Excel: ALV:


is there may be some possibility to replace ALL but not REGEX [digit] ?

0 Kudos

Hi, Denis!

Have you tried to shorten the file for uploading and debugging thorougthly what's happening there?

is there may be some possibility to replace ALL but not REGEX [digit] ?

It seems to me that "\D" regex should do exactly that trick.

You can check the document for description of some more regular expressions.

0 Kudos

Your delimiter is also getting deleted when \D (non-numeric) is used. So instead of deleting all '\D', you can apply negation and delete all '[^\d;]' , assuming semicolon ; is your field separator. I haven't tested it but I think it will work fine.

In case it doesn't work, post the non-working code here.

0 Kudos

Now I kow what the problem is about.

in my string I do split by ';' and it also will be replaced by " "...

Could it be possible to make exaption for ";" somehow?

0 Kudos

Thank you Manish!

Small question: and what, when I'd like to do 2 exaptions: for ; and for , ?

It's possible?

0 Kudos

Yes, it is possible. Big brackets [ ] define a set. [abc] means it would match either a or b or c.

[^abc] would match anything other than a or b or c as negation operator ^ is used.

In your case, \d is digit and semicolon is also part of negation set. To add comma to it, use '[^\d;,]'

0 Kudos

Thank you once again!