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

How to populate an internal table from a string variable

Former Member
0 Likes
2,574

Hi Experts,

My internal table contains a field of length 255 characters.

I have a string variable. I need to populate the internal table from the string variable.

How should I code for this.

Thanks,

Sangeeta.

1 ACCEPTED SOLUTION
Read only

venkat_o
Active Contributor
0 Likes
1,207

Hi Sangeetha, <li>Try this way.


REPORT ztest_notepad.

DATA: BEGIN OF it_file OCCURS 0,
       data TYPE c LENGTH 255,
      END OF it_file.
DATA str     TYPE string.
DATA g_len   TYPE i.
DATA g_off   TYPE i.
DATA g_loops TYPE i.
CONCATENATE
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890x'
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890y'
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890z'
'12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789m'
INTO str SEPARATED BY space.

g_len   = STRLEN( str ).
g_loops = g_len / 255.

g_off = 1.
DO g_loops TIMES.
  IF g_loops NE sy-index.
    IF sy-index EQ 1.
      it_file-data = str+0(255).
    ELSE.
      it_file-data = str+g_off(255).
    ENDIF.
    APPEND it_file.
    CLEAR  it_file.
    g_off = sy-index * 255.
  ELSE.
    g_len = g_len - g_off.
    it_file-data = str+g_off(g_len).
    APPEND it_file.
    CLEAR  it_file.
  ENDIF.
ENDDO.
LOOP AT it_file.
  WRITE:/ it_file-data.
ENDLOOP.
Thanks Venkat.O

3 REPLIES 3
Read only

venkat_o
Active Contributor
0 Likes
1,208

Hi Sangeetha, <li>Try this way.


REPORT ztest_notepad.

DATA: BEGIN OF it_file OCCURS 0,
       data TYPE c LENGTH 255,
      END OF it_file.
DATA str     TYPE string.
DATA g_len   TYPE i.
DATA g_off   TYPE i.
DATA g_loops TYPE i.
CONCATENATE
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890x'
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890y'
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890z'
'12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789m'
INTO str SEPARATED BY space.

g_len   = STRLEN( str ).
g_loops = g_len / 255.

g_off = 1.
DO g_loops TIMES.
  IF g_loops NE sy-index.
    IF sy-index EQ 1.
      it_file-data = str+0(255).
    ELSE.
      it_file-data = str+g_off(255).
    ENDIF.
    APPEND it_file.
    CLEAR  it_file.
    g_off = sy-index * 255.
  ELSE.
    g_len = g_len - g_off.
    it_file-data = str+g_off(g_len).
    APPEND it_file.
    CLEAR  it_file.
  ENDIF.
ENDDO.
LOOP AT it_file.
  WRITE:/ it_file-data.
ENDLOOP.
Thanks Venkat.O

Read only

Former Member
0 Likes
1,207

This will solve your problem..

DATA VAR VALUE '/' .

split text1 at VAR into table it_text. " chops the string at '/' and puts sequentially in table it_text(field shud b char)

OR USE FM..

DATA: BEGIN OF TABLE OCCURS 10 ,
STR(100),
  END OF TABLE.

DATA WA LIKE LINE OF TABLE.

CALL FUNCTION 'IQAPI_WORD_WRAP'
  EXPORTING
    TEXTLINE                  = 'sumit12sddadsadasd3456789'
*   DELIMITER                 = ' '
   OUTPUTLEN                 = 5               " this is the length of each peice --> give 255 in your case
* IMPORTING
*   OUT_LINE1                 =
*   OUT_LINE2                 =
*   OUT_LINE3                 =
 TABLES
   OUT_LINES                 = TABLE
* EXCEPTIONS
*   OUTPUTLEN_TOO_LARGE       = 1
*   OTHERS                    = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

Regards,

Sumit Nene

Read only

Former Member
0 Likes
1,207

Hi,

Concatenate all the fields you need move into the file seperated by space or comma into your string,

and then populate the string into your internal table.

Thanks,

sudheer