06-21-2022 7:32 AM
Hi Experts,
I have a requirement in which I am uploading csv files in my abap program, the file has some text fields , for ex- supplier comment. records are separated by ||. user is writing comment in text field and pressing enter to write in new line. when I am uploading this file and split it into required internal table, the line is breaking from between( where the text field is) and next records are being generated in new row. do anyone hve any suggestions?
06-21-2022 8:11 AM
If I understand well, the user enters this::
my first line
my second line
And in the file:
my first line||my second line
Correct?
Then show your code and we'll tell you where you're wrong.
06-21-2022 8:43 AM
actually file is like this..
abc|| my first line
my second line || cdef|| ghi and so on
the records in internal table should be like..
abc | my first line ##(crlf) my second line | cdef | ghi..
earlier I wrote a code..
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = iv_content
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = gv_length
TABLES
binary_tab = gt_upload.
CALL FUNCTION 'SCMS_BINARY_TO_TEXT'
EXPORTING
input_length = gv_length
TABLES
binary_tab = gt_upload
text_tab = gt_str
EXCEPTIONS
failed = 1
OTHERS = 2.
LOOP AT gt_str INTO DATA(gs_str).
" split csv data to convert it into standard table format
SPLIT gs_str-line AT '||' INTO gs_data_tech-statebox
gs_data_tech-taskbox
gs_data_tech-validationbox
gs_data_tech-prioritybox
gs_data_tech-rfrno
gs_data_tech-nctext
gs_data_tech-msn
gs_data_tech-version
gs_data_tech-nctype
gs_data_tech-program
gs_data_tech-plant
gs_data_tech-state
gs_data_tech-ncopened
gs_data_tech-ncclosed
gs_data_tech-supplier
gs_data_tech-activeoss
gs_data_tech-taskopened
gs_data_tech-priority
gs_data_tech-productgrp
gs_data_tech-partdesc
gs_data_tech-partno
gs_data_tech-category
gs_data_tech-airbuscomment
gs_data_tech-liability
gs_data_tech-liabilitycat
gs_data_tech-liabilityval
gs_data_tech-validationstatus
gs_data_tech-validationcomment
gs_data_tech-suppliercomment
gs_data_tech-completiondate
gs_data_tech-prod_deadline_datetime
gs_data_tech-matavailabledate
gs_data_tech-affectedsubcomp
gs_data_tech-trackingno
gs_data_tech-currency
gs_data_tech-labourhrsoss
gs_data_tech-adminhrsoss
gs_data_tech-matcostsoss
gs_data_tech-shipcostsoss
gs_data_tech-datasource
gs_data_tech-notificationid
gs_data_tech-dossierid
gs_data_tech-tasknumber
gs_data_tech-qrpref
gs_data_tech-cfifilter
gs_data_tech-technical_fields_marker.
IF sy-subrc <> 0.
ELSE.
APPEND gs_data_tech TO gt_data_tech. " append lines of all csv files to one table
CLEAR gs_data_tech.
ENDIF.
ENDLOOP.
there should be 2 records only(one is header file).. but you see there are three
06-21-2022 8:45 AM
Then I tried like this
DATA: ls_string TYPE string,
lv_rec TYPE i,
gv_rec TYPE i VALUE 0.
FIELD-SYMBOLS: <fs_val> TYPE any.
DATA: it_st TYPE STANDARD TABLE OF ts_data_tech,
wa_st TYPE ts_data_tech.
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = iv_content
IMPORTING
out_string = ls_string.
SPLIT ls_string AT '||' INTO TABLE it_text.
DESCRIBE TABLE it_text LINES lv_rec.
DATA(lv_count) = lv_rec / 43.
lo_struct ?= cl_abap_structdescr=>describe_by_data( gs_data_tech2 ).
DO lv_count TIMES.
APPEND INITIAL LINE TO gt_data_tech2 ASSIGNING FIELD-SYMBOL(<fs_data_tech>).
LOOP AT lo_struct->components ASSIGNING FIELD-SYMBOL(<fs_components>).
gv_rec = gv_rec + 1.
READ TABLE it_text INTO DATA(wa_text) INDEX gv_rec.
ASSIGN COMPONENT <fs_components>-name
OF STRUCTURE <fs_data_tech> TO <fs_val>.
<fs_val> = wa_text-line.
ENDLOOP.
ENDDO.
*_______________________________________
but for this to work I hve to put delimeter || at the end of every record.. but my manager said it is not a good solution