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

String Length in File.

Former Member
0 Likes
526

Hi ,

I have to download a longtext from SAP into the Dev Server.I am using the Opendataset concept.The length of the longtext has to be fixed 5000 ie...Even if the length of the longtext from SAP is 1000 remaining 4000 spaces should get appended.

I am moving the long text into a variable l_line which I have declared in the following way L_LINE(5000).

But after moving the longtext into this variable it still shows the actual length of the longtext whereas I need 5000 fixed length.

When using Gui_download it works fine coz I have used another dummy variable

after the long text in the internal table.

ie..

BEGIN OF IT_DOWNLOAD OCCURS 0,

QMNUM TYPE QMNUM,

LTEXT(5000),

DUMMY(1),

END OF IT_DOWNLOAD.

How to solve it.

Thanks,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
445

Try it this way:

data: BEGIN OF IT_DOWNLOAD OCCURS 0,
        QMNUM TYPE QMNUM,   
        LTEXT(5000),
        DUMMY(1),
      END OF IT_DOWNLOAD.

data: l_text type string.
" Code to populate data in IT_DOWNLOAD

check not it_download[] is initial.
open dataset <p_file> for output in textmode encoding default.
if sy-subrc ne 0.
  message e001(00) with 'Error Opening file:' <p_file>.
else.
  loop at it_download.
     clear: l_text.
     l_text(12) = it_download-qmnum.
     l_text+12(5000) = it_download-ltext.
     l_text+5012(1) = it_download-dummy.
     transfer l_text to <p_file>.
  endloop.
  close dataset <p_file.
endif.

If you are using dummy character in the table just for the length, you can do it using below method as well:

types: begin of t_down,
        qmnum type qmnum,    " Length 12
        ltext(5000) type c, " Length 5000
       endif.
data: i_down type table of t_down,
      wa_down type t_down.
      
" Code to populate i_down

check not i_down[] is initial.
open dataset <p_file> for output in textmode encoding default.
if sy-subrc ne 0.
  message e001(00) with 'Error Opening file:' <p_file>.
else.
  loop at i_down into wa_down.
    transfer wa_down to <p_file> length 5012.
  endloop.
  close dataset <p_file>
endif.

~Eswar

2 REPLIES 2
Read only

former_member723628
Active Participant
0 Likes
445

Renu,

Try to open the dataset as follows:

OPEN DATASET file

FOR OUTPUT IN LEGACY BINARY MODE

ENCODING DEFAULT.

Regards,

Gajendra

Read only

Former Member
0 Likes
446

Try it this way:

data: BEGIN OF IT_DOWNLOAD OCCURS 0,
        QMNUM TYPE QMNUM,   
        LTEXT(5000),
        DUMMY(1),
      END OF IT_DOWNLOAD.

data: l_text type string.
" Code to populate data in IT_DOWNLOAD

check not it_download[] is initial.
open dataset <p_file> for output in textmode encoding default.
if sy-subrc ne 0.
  message e001(00) with 'Error Opening file:' <p_file>.
else.
  loop at it_download.
     clear: l_text.
     l_text(12) = it_download-qmnum.
     l_text+12(5000) = it_download-ltext.
     l_text+5012(1) = it_download-dummy.
     transfer l_text to <p_file>.
  endloop.
  close dataset <p_file.
endif.

If you are using dummy character in the table just for the length, you can do it using below method as well:

types: begin of t_down,
        qmnum type qmnum,    " Length 12
        ltext(5000) type c, " Length 5000
       endif.
data: i_down type table of t_down,
      wa_down type t_down.
      
" Code to populate i_down

check not i_down[] is initial.
open dataset <p_file> for output in textmode encoding default.
if sy-subrc ne 0.
  message e001(00) with 'Error Opening file:' <p_file>.
else.
  loop at i_down into wa_down.
    transfer wa_down to <p_file> length 5012.
  endloop.
  close dataset <p_file>
endif.

~Eswar