Application Development 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: 

need to logic for this requirement

Former Member
0 Kudos

HI to all experts,

It seems to be simple but im not able to get the solution

i have internal table with serial no and item no like this

10 12323244

10 12334343

10 12434343

20 12434343

20 23434243

30 234323243

no my requirement is to get into this format into another internal table

which is of the type

item no and string

10 12323244 12334343 12434343 (seperated by space)

20 12434343 23434243

30 234323243

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Abdul,

Please run the below code.

U will get your desired output..

data: BEGIN OF it_data OCCURS 10,
        srno(2) ,
        item_num TYPE string,
      END OF it_data.
data: str type string.

data: it_final like it_data OCCURS 10 WITH HEADER LINE.

it_data-srno = 10. it_Data-item_num = 12323244. append it_data.
it_data-srno = 10. it_Data-item_num = 12334343.append it_data.
it_data-srno = 10. it_Data-item_num = 12434343.append it_data.
it_data-srno = 20. it_Data-item_num = 12434343.append it_data.
it_data-srno = 20. it_Data-item_num = 23434243.append it_data.
it_data-srno = 30. it_Data-item_num = 234323243.append it_data.

sort it_data STABLE by srno.
LOOP AT it_data.
*  at NEW srno.
  CONCATENATE it_data-item_num str into str SEPARATED BY ''.

  at END OF srno.
    CONCATENATE str it_data-srno into str SEPARATED BY ''.
    it_final-item_num = str.
    it_final-srno = it_data-srno.
    APPEND it_final.
    clear: str,it_data,it_final.
 endat.
ENDLOOP.

LOOP AT it_final.
write:it_final-srno, it_final-item_num.
skip.
ENDLOOP.

Please Let me know in case of any doubt ,

Regards,

Apoorv

9 REPLIES 9

Former Member
0 Kudos

Hello,

Try this logic. Itab is the original internal table and ITAB2 is the one in which u need your requirements into.

loop at itab.

loop at itab where item = itab-item.

itab2-item = itab1-item.

concatenate itab1-text into itab2-text.

delete itab index sy-tabix.

endloop.

append itab2.

clear itab2.

endloop.

Hope this helps.

Regards,

Mansi.

Edited by: SAP USER on Apr 27, 2010 7:58 AM

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi, Build internal table type string.

AT new col1 , move the col2 value to string and concatenate with existing string separated by space.

Former Member
0 Kudos

Do u have any idea that how many maximum columns can u have for a item number...? ?

Former Member
0 Kudos

you can achieve as sundeep said,

Using AT new or AT end of statments...

data : v_string type string.

sort it_itab by serial no.

Loop at it_itab

concatenate V-string wa_itab-string into v_string.

at end of serial no.

wa_new-serialno = wa_itab-serialno.

wa_new-string = v_string.

clear v_string

append wa_new to it_new.

endat.

endloop.

Former Member
0 Kudos

Hi mohammed,

Your logic can be implemented using AT NEW or END AT statement in ABAP.

you can loop at internal table 1 and keep concatenating Item no in some field in Internal table 2

and at new <serial no> just append into int2.



loop at int1 into wa_int1

wa_int2-ser_no = wa_int1-ser_no

concatenate wa_int1-item_no into wa_int2-item_no with space.

at end of ser_no.
append wa_int2 into int2.
atend.

I hope this works for you.

Regards,

Salil Sonam.

Former Member
0 Kudos

Hi Abdul,

Please run the below code.

U will get your desired output..

data: BEGIN OF it_data OCCURS 10,
        srno(2) ,
        item_num TYPE string,
      END OF it_data.
data: str type string.

data: it_final like it_data OCCURS 10 WITH HEADER LINE.

it_data-srno = 10. it_Data-item_num = 12323244. append it_data.
it_data-srno = 10. it_Data-item_num = 12334343.append it_data.
it_data-srno = 10. it_Data-item_num = 12434343.append it_data.
it_data-srno = 20. it_Data-item_num = 12434343.append it_data.
it_data-srno = 20. it_Data-item_num = 23434243.append it_data.
it_data-srno = 30. it_Data-item_num = 234323243.append it_data.

sort it_data STABLE by srno.
LOOP AT it_data.
*  at NEW srno.
  CONCATENATE it_data-item_num str into str SEPARATED BY ''.

  at END OF srno.
    CONCATENATE str it_data-srno into str SEPARATED BY ''.
    it_final-item_num = str.
    it_final-srno = it_data-srno.
    APPEND it_final.
    clear: str,it_data,it_final.
 endat.
ENDLOOP.

LOOP AT it_final.
write:it_final-srno, it_final-item_num.
skip.
ENDLOOP.

Please Let me know in case of any doubt ,

Regards,

Apoorv

0 Kudos

Approv Coding is correct But juse Need to change the concatenate statement to get desired output.

>CONCATENATE it_data-item_num str into str SEPARATED BY ''.

Change this to

CONCATENATE str it_data-item_num into str SEPARATED BY ''.

Best Wishes

Sas

Former Member
0 Kudos

Hi,

Please make use of the below code.

data: begin of itab occurs 0,

sernum(2),

item(10),

end of itab,

begin of newtab occurs 0,

sernum(2),

string(100),

end of newtab.

itab-sernum = '10'.itab-item = '12323244'.

append itab.

itab-sernum = '10'.itab-item = '12323243'.

append itab.

itab-sernum = '10'.itab-item = '12434343'.

append itab.

itab-sernum = '20'.itab-item = '12434343'.

append itab.

itab-sernum = '20'.itab-item = '23434243'.

append itab.

itab-sernum = '30'.itab-item = '234323243'.

append itab.

LOOP AT itab.

concatenate newtab-string itab-item INTO newtab-string SEPARATED BY space.

AT END OF sernum.

newtab-sernum = itab-sernum.

APPEND newtab.

CLEAR newtab.

ENDAT.

ENDLOOP.

LOOP AT newtab.

WRITE:/ newtab-sernum, newtab-string.

ENDLOOP.

Hope this may help you.

Regards,

Smart Varghese

vallamuthu_madheswaran2
Active Contributor
0 Kudos

START-OF-SELECTION.

itab-sno = '10'.

itab-valu = '12323244'.

APPEND itab.

CLEAR itab.

itab-sno = '10'.

itab-valu = '12334343'.

APPEND itab.

CLEAR itab.

itab-sno = '10'.

itab-valu = '12434343'.

APPEND itab.

CLEAR itab.

itab-sno = '20'.

itab-valu = '12434343'.

APPEND itab.

CLEAR itab.

itab-sno = '20'.

itab-valu = '23434243'.

APPEND itab.

CLEAR itab.

itab-sno = '30'.

itab-valu = '234323243'.

APPEND itab.

CLEAR itab.

WRITE: ' '.

itab1[] = itab[].

CLEAR itab. REFRESH itab.

DATA: lv_sno TYPE i,

lv_valu(100) TYPE c.

READ TABLE itab1 INDEX 1.

lv_sno = itab1-sno.

LOOP AT itab1.

IF lv_sno = itab1-sno.

CONCATENATE itab1-valu itab-valu INTO itab-valu SEPARATED BY space.

AT END OF sno.

CONCATENATE itab1-sno itab-valu INTO itab-valu SEPARATED BY space.

APPEND itab. CLEAR itab.

ENDAT.

lv_sno = itab1-sno.

ELSE.

CONCATENATE itab1-valu itab-valu INTO itab-valu SEPARATED BY space.

AT END OF sno.

CONCATENATE itab1-sno itab-valu INTO itab-valu SEPARATED BY space.

APPEND itab. CLEAR itab.

ENDAT.

lv_sno = itab1-sno.

ENDIF.

ENDLOOP.