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

printing ranges for smartforms

cywings
Explorer
0 Likes
510

dear all,

i have a task which requires me to find the ranges in a set of numbers..

sample data: R09004016, R020185M01, R050015M<M04, R09004018, R020185M03, R050015M<M05,

R09004017, R020185M02, R050015M<M06, R020185M12, R09004002

these are the norsec numbers... which are needed to group them together if these numbers have the same characteristics..

the expected output would be

R09004002, R09004016 TO R09004018, R020185M01 TO R020185M03, R020185M12,

R050015M<M04 TO R050015M<M06

my question is, how do i put these norsec numbers into ranges...? and the problem is that some norsec numbers have characters inside...the norsec numbers are alphanumeric..

any help is very much appreciated..thanks..

urgent.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
480

Hi

Please check if below code can help to lead you.

data: begin of itab occurs 0,
        fld1(20) type c,
      end of itab.
data: begin of it_out occurs 0,
        text(50) type c,
      end of it_out.

itab-fld1 = 'R09004016'.
append itab.
itab-fld1 = 'R020185M01'.
append itab.
itab-fld1 = 'R050015M<M04'.
append itab.
itab-fld1 = 'R09004018'.
append itab.
itab-fld1 = 'R020185M03'.
append itab.
itab-fld1 = 'R050015M<M05'.
append itab.
itab-fld1 = 'R09004017'.
append itab.
itab-fld1 = 'R020185M02'.
append itab.
itab-fld1 = 'R050015M<M06'.
append itab.
itab-fld1 = 'R020185M12'.
append itab.
itab-fld1 = 'R09004002'.
append itab.


data: from(20) type n,
      to(20) type n.

data: from_c like itab-fld1, "type c,
      to_c like itab-fld1. "type c.

sort itab by fld1.

loop at itab.

     if sy-tabix eq 1.
        from = itab-fld1.
        from_c = itab-fld1.
     else.
        perform compare using itab-fld1 to changing from.
     endif.

     to = itab-fld1.
     to_c = itab-fld1.

     at last.
        perform compare using to to changing from.
     endat.

 endloop.

 loop at it_out.
    write:/ it_out-text.
 endloop.

 form compare using p_fld1 p_to changing p_from.

 data: l_to(20) type n.
 data: l_fld(20) type n.

    l_to = p_to + 1.
    l_fld = p_fld1.
    
    if l_fld ne l_to.
       if p_to > p_from.
          concatenate from_c 'TO' to_c into it_out-text
                      separated by space.
          append it_out.
       else.
          move from_c to it_out-text.
          append it_out.
       endif.
       p_from = itab-fld1.
       from_c = itab-fld1.
     endif.

 endform.

Kind Regards

Eswar

Hi

Please check if below code can help to lead you.

data: begin of itab occurs 0,
        fld1(20) type c,
      end of itab.
data: begin of it_out occurs 0,
        text(50) type c,
      end of it_out.

itab-fld1 = 'R09004016'.
append itab.
itab-fld1 = 'R020185M01'.
append itab.
itab-fld1 = 'R050015M<M04'.
append itab.
itab-fld1 = 'R09004018'.
append itab.
itab-fld1 = 'R020185M03'.
append itab.
itab-fld1 = 'R050015M<M05'.
append itab.
itab-fld1 = 'R09004017'.
append itab.
itab-fld1 = 'R020185M02'.
append itab.
itab-fld1 = 'R050015M<M06'.
append itab.
itab-fld1 = 'R020185M12'.
append itab.
itab-fld1 = 'R09004002'.
append itab.


data: from(20) type n,
      to(20) type n.

data: from_c like itab-fld1, "type c,
      to_c like itab-fld1. "type c.

sort itab by fld1.

loop at itab.

     if sy-tabix eq 1.
        from = itab-fld1.
        from_c = itab-fld1.
     else.
        perform compare using itab-fld1 to changing from.
     endif.

     to = itab-fld1.
     to_c = itab-fld1.

     at last.
        perform compare using to to changing from.
     endat.

 endloop.

 loop at it_out.
    write:/ it_out-text.
 endloop.

 form compare using p_fld1 p_to changing p_from.

 data: l_to(20) type n.
 data: l_fld(20) type n.

    l_to = p_to + 1.
    l_fld = p_fld1.
    
    if l_fld ne l_to.
       if p_to > p_from.
          concatenate from_c 'TO' to_c into it_out-text
                      separated by space.
          append it_out.
       else.
          move from_c to it_out-text.
          append it_out.
       endif.
       p_from = itab-fld1.
       from_c = itab-fld1.
     endif.

 endform.

Kind Regards

Eswar

3 REPLIES 3
Read only

Former Member
0 Likes
481

Hi

Please check if below code can help to lead you.

data: begin of itab occurs 0,
        fld1(20) type c,
      end of itab.
data: begin of it_out occurs 0,
        text(50) type c,
      end of it_out.

itab-fld1 = 'R09004016'.
append itab.
itab-fld1 = 'R020185M01'.
append itab.
itab-fld1 = 'R050015M<M04'.
append itab.
itab-fld1 = 'R09004018'.
append itab.
itab-fld1 = 'R020185M03'.
append itab.
itab-fld1 = 'R050015M<M05'.
append itab.
itab-fld1 = 'R09004017'.
append itab.
itab-fld1 = 'R020185M02'.
append itab.
itab-fld1 = 'R050015M<M06'.
append itab.
itab-fld1 = 'R020185M12'.
append itab.
itab-fld1 = 'R09004002'.
append itab.


data: from(20) type n,
      to(20) type n.

data: from_c like itab-fld1, "type c,
      to_c like itab-fld1. "type c.

sort itab by fld1.

loop at itab.

     if sy-tabix eq 1.
        from = itab-fld1.
        from_c = itab-fld1.
     else.
        perform compare using itab-fld1 to changing from.
     endif.

     to = itab-fld1.
     to_c = itab-fld1.

     at last.
        perform compare using to to changing from.
     endat.

 endloop.

 loop at it_out.
    write:/ it_out-text.
 endloop.

 form compare using p_fld1 p_to changing p_from.

 data: l_to(20) type n.
 data: l_fld(20) type n.

    l_to = p_to + 1.
    l_fld = p_fld1.
    
    if l_fld ne l_to.
       if p_to > p_from.
          concatenate from_c 'TO' to_c into it_out-text
                      separated by space.
          append it_out.
       else.
          move from_c to it_out-text.
          append it_out.
       endif.
       p_from = itab-fld1.
       from_c = itab-fld1.
     endif.

 endform.

Kind Regards

Eswar

Read only

cywings
Explorer
0 Likes
480

thanks!! it worked...

edit: how come i cant award points when i clicked on the radio button on the left...

Message was edited by: Yew Wing Chen

Read only

Former Member
0 Likes
480

Glad could help you Yew.

Maybe the server is down for points system. Please remember to reward when the server is up.

Kind Regards

Eswar