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: 

String operations

Former Member
0 Kudos
329

Hi Friends,

I have a requirement where i need to upload a text file in a note pad containing PO, PO-line item and item text. The problem is item text is more than 255 chars and i am using the GUI_UPLOAD FM but i am getting the value in my internal table as "4550610#010#0001#text sample to upload in the file for the PO'S ETC".

Could you please suggest me how to segregate only the text part i.e (text sample to upload in the file for the PO'S ETC".) from the

Others the problem is text char is more than 255 char long and i am unable to get the value in an variable. I tried using split command but of no luck.

Please suggest.Thanks for your help.

Best Regards.

Meenakshi

1 ACCEPTED SOLUTION

Former Member
0 Kudos
171

Hi,

It seems that you are uploading a .txt file from your local drive to the SAP and your file is TAB delimited. If your file is TAB delimited then it will appear as '#' in place of separators in your internal table. In this case you can try and follow 2 different approaches,

This code is commomn for both the approaches.

TYPES: BEGIN OF TY_PO,
     PO_NO TYPE EBELN,
     ITM_NO TYPE EBELP,
     ITM_TXT(400) TYPE c,
  END OF TY_PO,

BEGIN OF TY_DATA,
  DATA(500) TYPE c,
END OF TY_DATA.
DATA: IT_DATA TYPE STANDARD TABLE OF TY_DATA,
           WA_DATA TYPE TY_DATA,
           IT_PO TYPE STANDARD TABLE OF TY_PO,
           WA_ TYPE TY_PO.

Approach 1: Using SPLIT statement

CONSTANTS : C_SEP TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.  " The value will be #

   CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
            filename        = gd_file   " Your file path
            filetype        = 'ASC'
       TABLES
            data_tab        = it_data  "ITBL_IN_RECORD[]
       EXCEPTIONS
            file_open_error = 1
            OTHERS          = 2.
  IF sy-subrc NE 0.
  ELSE.
    LOOP AT IT_DATA INTO WA_DATA.
      SPLIT WA_DATA AT C_SEP INTO  WA_PO-PO_NO 
       WA_PO-ITM_NO 
       WA_PO-ITM_TXT.

      APPEND WA_PO TO IT_PO.
CLEAR: WA_PO , WA_DATA.
    ENDLOOP.
  ENDIF.

Approach 2: Without using SPLIT statements.

CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gd_file  " Your file name
      has_field_separator     = 'X'  "file is TAB delimited
    TABLES
      data_tab                = IT_PO
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.

Hope this code piece will help you. Since i have given the item text field as 400 char length it can accomodate more longer strings as well.

Please let me know for any further help.

<begging removed and points reduced by moderator>

Regards,

Praveenkumar T.

Edited by: Thomas Zloch on Feb 14, 2012

18 REPLIES 18

Former Member
0 Kudos
171

hi,

Please check this program wherein u can upload ur excel file content without trauncating the values.

http://wiki.sdn.sap.com/wiki/display/Snippets/ReadmultiplesheetsofanExcelfileintoSAPthroughABAP

Thanks,

Prachi.

Former Member
0 Kudos
171

Hi

Try to upload data with notepad.just copy data from excel to notepad and upload, your issue has been resolved.

Regards

Ajit

Former Member
0 Kudos
171

Hi,

Please check the follwing sap wiki.

These link will explain how to send email with more than 255 char . The procedure for you is to create only the text file . The flow is similar and easily understood.

[http://wiki.sdn.sap.com/wiki/display/Snippets/Tosendamailattachmentwithmorethan255charactersinaline]

You may also look at Thomas Jung snippet : [http://www.sdn.sap.com/irj/scn/weblogs?blog=/cs/user/view/cs_msg/34969]

Former Member
0 Kudos
171

Hi Meenakshi Sunderaswaran,

Declare your PO text field as STRING for more that 255 char in your internal table.

And to avoid Special characters(#) in the internal table, Make your text file as TAB delimiter. Provide TAB space in your text file between data and under Export parameter provide value for HAS_FIELD_SEPARATOR = 'SPACE' in se38 screen.

Hope will help you , let me know ,need any further help.

Regards,

Saravana.S

Former Member
0 Kudos
172

Hi,

It seems that you are uploading a .txt file from your local drive to the SAP and your file is TAB delimited. If your file is TAB delimited then it will appear as '#' in place of separators in your internal table. In this case you can try and follow 2 different approaches,

This code is commomn for both the approaches.

TYPES: BEGIN OF TY_PO,
     PO_NO TYPE EBELN,
     ITM_NO TYPE EBELP,
     ITM_TXT(400) TYPE c,
  END OF TY_PO,

BEGIN OF TY_DATA,
  DATA(500) TYPE c,
END OF TY_DATA.
DATA: IT_DATA TYPE STANDARD TABLE OF TY_DATA,
           WA_DATA TYPE TY_DATA,
           IT_PO TYPE STANDARD TABLE OF TY_PO,
           WA_ TYPE TY_PO.

Approach 1: Using SPLIT statement

CONSTANTS : C_SEP TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.  " The value will be #

   CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
            filename        = gd_file   " Your file path
            filetype        = 'ASC'
       TABLES
            data_tab        = it_data  "ITBL_IN_RECORD[]
       EXCEPTIONS
            file_open_error = 1
            OTHERS          = 2.
  IF sy-subrc NE 0.
  ELSE.
    LOOP AT IT_DATA INTO WA_DATA.
      SPLIT WA_DATA AT C_SEP INTO  WA_PO-PO_NO 
       WA_PO-ITM_NO 
       WA_PO-ITM_TXT.

      APPEND WA_PO TO IT_PO.
CLEAR: WA_PO , WA_DATA.
    ENDLOOP.
  ENDIF.

Approach 2: Without using SPLIT statements.

CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gd_file  " Your file name
      has_field_separator     = 'X'  "file is TAB delimited
    TABLES
      data_tab                = IT_PO
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.

Hope this code piece will help you. Since i have given the item text field as 400 char length it can accomodate more longer strings as well.

Please let me know for any further help.

<begging removed and points reduced by moderator>

Regards,

Praveenkumar T.

Edited by: Thomas Zloch on Feb 14, 2012

0 Kudos
171

Hi all,

Thanks for the answer , but my problem is not with the "#', I need to capture the item text which is more than 255 CHAR long and process it separately. Could you let me know how to consider only the text file characters from the file only as string.

Thanks

Meenakshi

0 Kudos
171

Hi,

If i understood your requirement properly you would like to know if it is possible to check if the item text is more than 255 characters long and if it is long then you will have to capture it in a separate variable and process it.

Please let me know if i understood you correctly or correct me if my understanding is wrong

Thanks!

Praveenkumar T.

0 Kudos
171

Praveen

You are correct; the item text is more than 255 char long and has got no separators in the file. Thatu2019s the reason I wanted to capture the entire text in a variable or a string and process it. Split command works perfectly until the line item but for item text it is not working correctly.

Please suggest.

Thanks

Meenakshi

0 Kudos
171

Hi,

May i know the data type of the variable into which you are trying to capture the item text after splitting.

If it is of TYPE STRING try to change it to character of length 400.

Regards,

Praveenkumar T.

0 Kudos
171

Meenakshi,

Would it be possible for you to post a code snippet of the relevant section, If i take a look at what you have done so far i would be able to provide an efficient solution as there are many ways to go about it.

0 Kudos
171

I am assuming you have successfully uploaded your data into the SAP system.

please ref below to see What you could do to segregate the text part.

loop at itab into wa_itab " Tab containing records from flat file into work area

w_length = strlen( wa_itab ) - 1. " get current length of work area

search wa_itab for sy-abcde " searches the workarea for text containing alphabets.

if sy-subrc = 0.

w_len1 = w_len - sy-FDPOS " Length of only text part

w_text = wa_itab+sy-fdpos(w_len1). " getting the entire text part to another variable

      • Perform your operations on the text ***

endif.

endloop.

0 Kudos
171

Nayak,

Thanks for the suggestion, please find the code below. The T_INFILE is the data uploaded from the note pad

&----


*

*& Form SUB_LOAD_DATA

&----


  • Split tab delimited input data into separate fields

----


FORM sub_load_data.

CONSTANTS: c_delim(1) TYPE x VALUE 09. "tab value

LOOP AT t_infile.

SPLIT t_infile AT c_delim INTO

t_inrec2-ebeln

t_inrec2-ebelp

t_inrec2-seqno

t_inrec2-notes_txt1.

  • t_inrec2-notes_txt2.

APPEND t_inrec2.

ENDLOOP.

ENDFORM. " SUB_LOAD_DATA

but the data looks like the one in the debugging need to consider only the text part from it.ie from 09/1411.Please suggest.

4500150650#00000010#000001#09/14/11 SY/AGI SHIPMENT RECEIVED PROCESSING MR 09/09/11 SY/AGI WILL SHIP BY 09/14 OR BEFORE 09/07/11 SY/AGI SENT JOE/PUFFER REQUEST FOR SHIP STATUS 09/01/11 SY/AGI FLUID FOUND SHOULD BE ABLE TO SHIP BY 09/07. 08/30/1

Thanks

Meenkashi

0 Kudos
171

Hi Meenakshi,

Can you please post the Type of t_inrec2. specifically the field notes_txt1. Can you please provide that as well.

Thanks!

Praveenkumar T.

0 Kudos
171

Praveen

Here is the declaration for the t_inrec2.

DATA: BEGIN OF t_inrec2 OCCURS 0,

ebeln LIKE ekpo-ebeln,

ebelp(8), " LIKE ekpo-ebelp,

seqno(6) type c,

notes_txt1 TYPE SAEDATALIN,

  • notes_txt1(255) type c, "Notes

notes_txt2(255) type c,

notes_txt3(255) type c,

notes_txt4(255) type c,

notes_txt5(255) type c,

notes_txt6(255) type c,

END OF t_inrec2.

Thanks

Meenakshi

0 Kudos
171

Great, every thing seems fine except for the split operation. So, first try giving the 09 in quotes.

exactly as below.

CONSTANTS: c_delim TYPE x VALUE '09'. "tab value

if that doesnt work try this way to define your tab delimiter.

c_delim type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

should resolve the issue

0 Kudos
171

Hi Meenakshi,

Just change the delimiter it should be

c_delim TYPE c VALUE cl_abap_char_utilities=>Horizontal_tab. This should split the file perfectly into all the fields.

I have tried the below piece of logic also with your data and everything worked fine.

CONSTANTS: c_delim(1) TYPE c VALUE cl_abap_char_utilities=>HORIZONTAL_TAB. "tab value
DATA: t_infile TYPE SAEDATALIN.

DATA: BEGIN OF t_inrec2,
ebeln LIKE ekpo-ebeln,
ebelp(8), " LIKE ekpo-ebelp,
seqno(6) type c,
notes_txt1 TYPE SAEDATALIN,

notes_txt2(255) type c,
notes_txt3(255) type c,
notes_txt4(255) type c,
notes_txt5(255) type c,
notes_txt6(255) type c,
END OF t_inrec2.

CONCATENATE '4500150650' '00000010' '000001' '09/14/11 SY/AGI SHIPMENT RECEIVED PROCESSING MR 09/09/11 SY/AGI WILL SHIP BY 09/14 OR BEF RE 09/07/11 SY/AGI SENT JOE/PUFFER REQUEST FOR SHIP STATUS 09/01/11 SY/AGI FLUID FOUND SHOULD BE ABLE TO SHIP BY'
  INTO t_infile SEPARATED BY cl_abap_char_utilities=>HORIZONTAL_TAB.

SPLIT t_infile AT c_delim INTO
t_inrec2-ebeln
t_inrec2-ebelp
t_inrec2-seqno
t_inrec2-notes_txt1.
* t_inrec2-notes_txt2.
WRITE t_inrec2-notes_txt1.

Hope this solves your problem.

Please let me know for more details.

0 Kudos
171

Hi,

The file which you are uploading is it tab delimited file ?

if it is a tab delimited file then the file will be uploaded in in internal table directly if created with the to the appropiate field, but ur internal table should be in the file format .i.e PO,ebelp,seqno,text. and pass the file type in the FM DAT.

Or u can try the below option not sure it will work-

SPLIT t_infile AT '#' INTO

t_inrec2-ebeln

t_inrec2-ebelp

t_inrec2-seqno

t_inrec2-notes_txt1..

Regards,

Madhukar Shetty

Former Member
0 Kudos
171

You can use the TEXT_CONVERT_TEX_TO_SAP function instead of split command.


  DATA: lt_raw TYPE truxs_t_text_data.

  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename = 'C;\my_file.txt'
    CHANGING
      data_tab = lt_raw
    EXCEPTIONS
      OTHERS   = 1.

  CHECK sy-subrc EQ 0.

  CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
    EXPORTING
      i_field_seperator    = ';'
      i_tab_raw_data       = lt_raw
    TABLES
      i_tab_converted_data = my_table[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.