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

Why last line?

Former Member
0 Likes
2,351

Hello,

I was trying to define an internal table in such a way that say 'string_a (tab_sign) string_b' I have, and I used split statement to split them into an internal table with 2 columns that are both of type string.

However, when I tried to read the internal table of index 1, i always ended up getting the last line of the record instead of the first one. May I know why that happen? Thanks a lot!

Regards,

anyi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,233

Hi,

Try using Read gt_inbound into wa_inbound index 1.

Best regards,

Prashant

PS : Check in debug mode whether the internal table is populated correctly

Hello,

I was trying to define an internal table in such a way that say 'string_a (tab_sign) string_b' I have, and I used split statement to split them into an internal table with 2 columns that are both of type string.

However, when I tried to read the internal table of index 1, i always ended up getting the last line of the record instead of the first one. May I know why that happen? Thanks a lot!

Regards,

anyi

20 REPLIES 20
Read only

Former Member
0 Likes
2,233

Sort the internal table once before u read it.

theja.

Read only

0 Likes
2,233

Err...the problem is I just want to read the first record that was taken in w.r.t. the original order, with no sorting...

any suggestions?

Thanks!

anyi

Read only

0 Likes
2,233

Can we see your code?

Regards,

Rich Heilman

Read only

0 Likes
2,233

Sure, sorry

 FORM PC_SSL_UPLOAD  TABLES P_UPLOAD_DATA
                     USING WA_UPLOAD_DATA STRUCTURE WA_UPLOAD_DATA.
   LOOP AT LT_UPLOAD_DATA INTO WA_UPLOAD_DATA.
     SPLIT WA_UPLOAD_DATA-DATA AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
           INTO:
           WA_INBOUND-REC_TYPE
           WA_INBOUND-DATA,
           TABLE GT_INBOUND.
      APPEND WA_INBOUND TO GT_INBOUND.
   ENDLOOP.
 ENDFORM.                    "PC_SSL_UPLOAD

This is the code used to split the internal table

   READ TABLE GT_INBOUND INDEX 1 INTO WA_INBOUND.

This is the code used to read the table

And the first line always ends up to be the last line from the internal table where the .txt file was loaded into.

Thanks!

Anyi

Read only

0 Likes
2,233

Did you mean to be looping at P_UPLOAD_DATA instead of LT_UPLOAD_DATA?

Read only

0 Likes
2,233

> Did you mean to be looping at P_UPLOAD_DATA instead

> of LT_UPLOAD_DATA?

Nope, P_UPLOAD_DATA is where I load the txt from and LT_UOPLOAD_DATA is where I load the file into.

Thanks for the comments.

Anyi

Read only

0 Likes
2,233

FORM PC_SSL_UPLOAD TABLES P_UPLOAD_DATA

USING WA_UPLOAD_DATA STRUCTURE WA_UPLOAD_DATA.

LOOP AT LT_UPLOAD_DATA INTO WA_UPLOAD_DATA.

SPLIT WA_UPLOAD_DATA-DATA AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

INTO

WA_INBOUND-REC_TYPE

WA_INBOUND-DATA.

APPEND WA_INBOUND TO GT_INBOUND.

clear wa_inbound.

ENDLOOP.

ENDFORM. "PC_SSL_UPLOAD

READ TABLE GT_INBOUND INDEX 1 INTO WA_INBOUND.

Do as above.

Regards,

ravi

Read only

Former Member
0 Likes
2,233

hi anyi,

sort the internal table .

and in read stmt give...

read itab with key.. binary search.

Read only

Former Member
0 Likes
2,233

Hi,

The syntax is :

read table it_tab into wa_tab index 1.

Best regards,

Prashant

PS. Please paste the code if in case the problem is not solved

Read only

Former Member
0 Likes
2,234

Hi,

Try using Read gt_inbound into wa_inbound index 1.

Best regards,

Prashant

PS : Check in debug mode whether the internal table is populated correctly

Read only

0 Likes
2,233

I checked my input internal table, it does work properly, also I changed the code that Prashant has suggested. However, the problem seems that each time the loop runs, the previous line in the internal table was overwritten, instead of getting stored in the actual internal table. Any more suggestions?

Anyi

Read only

0 Likes
2,233

I'm thinking you need to remove the TABLE from your SPLIT statement.

Read only

0 Likes
2,233

Really smart guy, thanks a lot Matt.

> I'm thinking you need to remove the TABLE from your

> SPLIT statement.

Read only

0 Likes
2,233

You are welcome Anyi.

Read only

Former Member
0 Likes
2,233

you are not sorting the table before u read it. Try doing that once.

Read only

Former Member
0 Likes
2,232

Hi Anyi,

Add(in bold) the Following in the FORM.


FORM pc_ssl_upload  TABLES p_upload_data
                     USING wa_upload_data STRUCTURE wa_upload_data.

  <b>SORT  lt_upload_data  BY rec_type.</b>

  LOOP AT lt_upload_data INTO wa_upload_data.
    SPLIT wa_upload_data-data AT cl_abap_char_utilities=>horizontal_tab
          INTO:
          wa_inbound-rec_type
          wa_inbound-data,
          TABLE gt_inbound.
    APPEND wa_inbound TO gt_inbound.

   <b> CLEAR wa_inbound.</b>

  ENDLOOP.

ENDFORM.                    "PC_SSL_UPLOAD

Then try reading.

Regards,

Arun Sambargi.

Read only

0 Likes
2,232

Err...I do believe in the previous post, I mentioned that I would like to have the order of the code as the way it is (i.e., the way it was loaded from p_upload_data), and not in any other order.

Thanks!

Anyi

> Hi Anyi,

>

> Add(in bold) the Following in the FORM.

>

>


> FORM pc_ssl_upload  TABLES p_upload_data
> USING wa_upload_data STRUCTURE
> upload_data STRUCTURE wa_upload_data.
> 
>   <b>SORT  lt_upload_data  BY rec_type.</b>
> 
>   LOOP AT lt_upload_data INTO wa_upload_data.
> SPLIT wa_upload_data-data AT
> a AT cl_abap_char_utilities=>horizontal_tab
>           INTO:
>           wa_inbound-rec_type
>           wa_inbound-data,
>           TABLE gt_inbound.
>     APPEND wa_inbound TO gt_inbound.
> 
>    <b> CLEAR wa_inbound.</b>
> 
>   ENDLOOP.
> 
> ENDFORM.                    "PC_SSL_UPLOAD
> 
> 

>

> Then try reading.

>

> Regards,

> Arun Sambargi.

Err...I do

Read only

0 Likes
2,232

HI,

Try this



LOOP AT lt_upload_data INTO wa_upload_data.
 SPLIT wa_upload_data-data AT
 a AT cl_abap_char_utilities=>horizontal_tab
           INTO:
           wa_inbound-rec_type
           wa_inbound-data,
           table lit_temp.


           append lines of lit_temp to gt_inbound.

           APPEND wa_inbound TO gt_inbound.
 
     CLEAR wa_inbound.
 
ENDLOOP.




Read only

srinivas_akiri
Active Participant
0 Likes
2,232

Hi

for not to disturb the original order we can do it by below coding:

data : l_lines type i.

describe table gt_inbound lines into l_lines.

READ TABLE GT_INBOUND INDEX l_lines INTO WA_INBOUND.

Read only

srinivas_akiri
Active Participant
0 Likes
2,232

Hi

you need to remove the table parameter.

either you need to used only fields or table.