Application Development and Automation 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: 
Read only

Split the file into multiple records

Former Member
0 Likes
961

Hello Experts,

I getting the file in the below format.........

AAAA/BBBB/CC/DD/EEEEEEEEEEEEE/fffff/ABCD

EFGH/1248376/...........

Can anyone guide me how to split this file into multiple records at ' / '

like

AAAA

BBBB.....

and the second one would be if the line ending with some string with out ' / ' then i should concatenate the next line string upto ' / ' symbol and pass as next record.

Can anyone guide me how to do this.

I really appreciate your inputs.

Thanks a lot for your anticipation

8 REPLIES 8
Read only

Former Member
0 Likes
927

hi check this example...

data: begin of itab occurs 0,

test(100) type c,

end of itab .

data: begin of itab1 occurs 0,

test1(10) type c,

test2(20) type c,

end of itab1 .

data: v_test1(10),

v_test2(20) .

itab-test = 'fdfdfdffdffdf/wqwqwqwwwwq'.

append itab .

itab-test = 'rererrere/ewewewewee'.

append itab .

itab-test = 'ltltltlt/ptptptptpt'.

append itab .

itab-test = 'oeoeoeoeoe/utytytytyt'.

append itab .

loop at itab .

split itab-test at '/' into v_test1 v_test2 .

itab1-test1 = v_test1.

itab1-test2 = v_test2 .

append itab1.

endloop.

regards,

venkat

Read only

0 Likes
927

Hey Venkat,

I really appreciate quick response.

I am unable to catch your point.

I am getting huge amount of data like that in a file. I need to split the file at that symbol into multiple records. It is not constant like I get only 2 times that symbol in a like, it varies I may get it mulitple time.

Can you plzzzzzzzz guide me now

Read only

Former Member
0 Likes
927

LOOP AT I_ITAB INTO W_ITAB.

SPLIT W_ITAB AT '/' INTO W_REC-SEQNO

W_REC-RECAC

W_REC-TRADT

W_REC-BUILD_ID

W_REC-OWNER_ID

W_REC-EBELN

W_REC-ORD_TYP

W_REC-EBELP

W_REC-MATNR

W_REC-LOT_NO

W_REC-QTY_REC

W_REC-SHP_NO

W_REC-BOL_NO

W_REC-CONT_NO

W_REC-PFLAG

W_REC-PDATE.

APPEND W_REC TO I_REC.

ENDLOOP.

and then display the contents of the loop in your required format.

Read only

0 Likes
927

Ramesh,

Thank you very much for your input. But how can we declare the final internal table. Because I don't know the number of times / symbols comes in a row.

Read only

0 Likes
927

You want this...

AAAA/BBBB/CC/DD/EEEEEEEEEEEEE/fffff/ABCD

EFGH/1248376/

to look like this

AAAA

BBBB

CC

DD

...

or

AAAA BBBB CC DD EEEEEEEEEEEEE fffff ABCDEFGH 1248376

Read only

0 Likes
927

hi Ramiro,

I want to make to look into..........

AAAA

BBBB

CC

DD

Simply I need to split the entire record at / into multiple records........

I will get the multiple lines AAAA/BBBB/CC/DD/EEEEEEEEEEEEE/fffff/ABCD

EFGH/1248376/

like this format.

Or is there any possibility so that I can read the entire file into one record and then split at / into multiple records?

Guide me plzzzzzzzz

Read only

0 Likes
927

Here is some logic to help you do that.

Maybe it's not the best way, but for the way you're working it may be the most flexible alternative,

You can test this report to see the results:



REPORT  zteste.

TYPES: BEGIN OF tFILE,
         line(200),
       end of tfile.

DATA: file_line(200) TYPE c VALUE
      'aaa/bbb/ccc/ddd/eee'.

DATA: internal_table type STANDARD TABLE OF tfile,
      result_table   type STANDARD TABLE OF tfile.

DATA: wa1 type tfile,
      wa2 type tfile.

do 4 times.

  wa1-line = file_line.
  append wa1 to internal_table.

enddo.


DATA: record(200) type c.
DATA: vstart type i,
      vend   type i,
      voff   type i,
      variation   type i,
      v_first,
      v_exit.

LOOP AT internal_table into wa1.
  Clear: vstart,
        vend,
        voff,
        v_first,
        variation,
        v_exit.

  record = wa1-line.
  Do.
    if v_exit = 'X'.
      exit.
    endif.
    FIND FIRST OCCURRENCE OF '/' in record match OFFSET vend.
    if sy-subrc = 0.
*** If Found
      voff = vend - vstart.
      if v_first is initial.
        v_first = 'X'.
        wa2-line = record(voff).
      else.
        wa2-line = record+vstart(voff).
      endif.
    else.
*** Last record handling
      if record is not initial.
        if v_first is not initial.
          vend = STRLEN( record ).
          voff = vend - vstart.
          wa2-line = record+vstart(voff).
        else.
          wa2-line = record.
        endif.
        append wa2 to result_table.
        v_exit = 'X'.
        exit.
      endif.
    endif.
    append wa2 to result_table.
    vstart = vend + 1.
    replace first occurrence of '/' in record with '\'.
  enddo.
ENDLOOP.

loop at result_table into wa2.
  write:/ wa2-line.
endloop.

Hope it helps.

Regards.

Read only

0 Likes
927

Here is some logic that may help you.

REPORT ztestsplit .

DATA: text TYPE char100.

DATA: l_len TYPE i.

DATA: BEGIN OF itab OCCURS 0,

text TYPE char10,

END OF itab.

text = 'AAAAA/BBBBB/CCCCC/DDDDD/EEEEE'.

DO.

l_len = strlen( text ).

IF l_len GT 0.

SPLIT text AT '/' INTO itab-text text.

APPEND itab.

ELSE.

EXIT.

ENDIF.

ENDDO.

LOOP AT itab.

WRITE:/ itab-text.

ENDLOOP.

Cheers...

Prasad.