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

concatenating to string from an itab

Former Member
0 Likes
715

Hi experts,

Need some help to resolve this issue.

Have an itab structure as follows.

TYPES:BEGIN OF first_itab,
      matnr TYPE matnr,
      land  TYPE c,
      month(5) TYPE c,
      Deliveryqty TYPE p DECIMALS 2,
     END OF t_itab.
TYPES: tt_itab TYPE TABLE OF t_itab WITH KEY matnr land month.

The output of the itab is as follows:

The itab is sorted by matnr land month.

100                A   11.09             5,00
100                A   12.09             0,00
100                A   01.10             5,00
100                A   02.10             4,00
100                A   03.10             5,00
100                B   11.09             0,00
100                B   12.09             5,00
100                B   01.10             0,00
100                B   02.10             0,00
100                B   03.10             0,00
100                C   01.10             0,00
100                C   02.10             0,00
100                C   03.10             0,00
100                C   11.09             4,00
100                C   12.09             0,00

I have an second_itab structure as follows.

type : begin of second_itab
	
	land type string,
	 WholeString type string.
	
	end of second_itab

Now what I would like to have is loop through the first_itab content and fill the second_itab content as follows:

"land" field should have A ,B and C.

"WholeString" field should have -

100               A      5     0     5      4      5       
100               B      0     5     0      0      0 
100               C      0     5     0      4      0

That is to say if land type is "A" then "WholeString" is "100 A 5 0 5 4 5" and so on for other lands as well.

As the first_itab is sorted by matnr land month,

After getting the line "100 A 5" only delivery quantities of land need to be appended at the end.

Same is true for other lands as well.

A sample code would be very useful

Thanks

P

Hi experts,

Need some help to resolve this issue.

Have an itab structure as follows.

TYPES:BEGIN OF first_itab,
      matnr TYPE matnr,
      land  TYPE c,
      month(5) TYPE c,
      Deliveryqty TYPE p DECIMALS 2,
     END OF t_itab.
TYPES: tt_itab TYPE TABLE OF t_itab WITH KEY matnr land month.

The output of the itab is as follows:

The itab is sorted by matnr land month.

100                A   11.09             5,00
100                A   12.09             0,00
100                A   01.10             5,00
100                A   02.10             4,00
100                A   03.10             5,00
100                B   11.09             0,00
100                B   12.09             5,00
100                B   01.10             0,00
100                B   02.10             0,00
100                B   03.10             0,00
100                C   01.10             0,00
100                C   02.10             0,00
100                C   03.10             0,00
100                C   11.09             4,00
100                C   12.09             0,00

I have an second_itab structure as follows.

type : begin of second_itab
	
	land type string,
	 WholeString type string.
	
	end of second_itab

Now what I would like to have is loop through the first_itab content and fill the second_itab content as follows:

"land" field should have A ,B and C.

"WholeString" field should have -

100               A      5     0     5      4      5       
100               B      0     5     0      0      0 
100               C      0     5     0      4      0

That is to say if land type is "A" then "WholeString" is "100 A 5 0 5 4 5" and so on for other lands as well.

As the first_itab is sorted by matnr land month,

After getting the line "100 A 5" only delivery quantities of land need to be appended at the end.

Same is true for other lands as well.

A sample code would be very useful

Thanks

P

4 REPLIES 4
Read only

Former Member
0 Likes
675

use the following code.

LOOP AT <first internal table>

clear <second table>.

sec_t-land = first-land. "second table

CONCATENATE first-matnr first-land into sec_t-WholeString SEPARATED BY space.

LOOP AT <first internal table>

WHERE land = sec_t-land.

v_idx = sy-tabix.

CONCATENATE sec_t-WholeString first-month into sec_t-WholeString SEPARATED BY space.

delete first index v_idx.

ENDLOOP.

append sec_t.

ENDLOOP.

this will work for you.

thks

Abhi

Read only

Former Member
0 Likes
675

HI

Please check this thead, it will resolve your Issue,

Co[Convert Rows of internal table to Columns|http://docs.google.com/Doc?id=dfv2hmgs_5d6bcxqgp&hl=en]

Cheerz

Ram

Read only

venkat_o
Active Contributor
0 Likes
675

Hi, <li>You can follow as Ramakrishna's link insisted if you understand field-symbols concept. <li>Otherwise try the below way.


REPORT ztest.
TYPES:BEGIN OF t_itab,
      matnr TYPE matnr,
      land  TYPE c,
      month(5) TYPE c,
      deliveryqty TYPE p DECIMALS 2,
     END OF t_itab.
DATA: first_itab TYPE TABLE OF t_itab WITH KEY matnr land month WITH HEADER LINE.
TYPES : BEGIN OF t_itab2,
          matnr       TYPE matnr,
          land        TYPE string,
          wholestring TYPE string,
        END OF t_itab2.
DATA: second_itab TYPE TABLE OF t_itab2 WITH HEADER LINE.

DATA: str TYPE string.

START-OF-SELECTION.
  DEFINE populate.
    first_itab-matnr       = &1.
    first_itab-land        = &2.
    first_itab-month       = &3.
    first_itab-deliveryqty = &4.
    append first_itab.
    clear  first_itab.
  END-OF-DEFINITION.
  populate:
           '100' 'A'   '11.09' '5.00',
           '100' 'A'   '12.09' '0.00',
           '100' 'A'   '01.10' '5.00',
           '100' 'A'   '02.10' '4.00',
           '100' 'A'   '03.10' '5.00',
           '100' 'B'   '11.09' '0.00',
           '100' 'B'   '12.09' '5.00',
           '100' 'B'   '01.10' '0.00',
           '100' 'B'   '02.10' '0.00',
           '100' 'B'   '03.10' '0.00',
           '100' 'C'   '01.10' '0.00',
           '100' 'C'   '02.10' '0.00',
           '100' 'C'   '03.10' '0.00',
           '100' 'C'   '11.09' '4.00',
           '100' 'C'   '12.09' '0.00'.
  LOOP AT first_itab.
    second_itab-matnr = first_itab-matnr.
    second_itab-land  = first_itab-land.
    str               = first_itab-deliveryqty.
    CONCATENATE str second_itab-wholestring INTO second_itab-wholestring.
    AT END OF land.
      APPEND second_itab.
      CLEAR  second_itab.
    ENDAT.
  ENDLOOP.

  LOOP AT second_itab.
    WRITE:/ second_itab-matnr, second_itab-land, second_itab-wholestring.
  ENDLOOP.
Thanks Venkat.O

Read only

Former Member
0 Likes
675

Hi venkat,

You almost made my day.It works. Thanks a lot...

1 question though

Is it possible to write to a second_itab structure as follows from the first itab.

TYPES:BEGIN OF second_itab,
      matnr TYPE matnr,
      land  TYPE c,
      period1 type p, 
      period2 type p,
      period3 type p,
      period4 type p,
	....
	......
      period12 type p,
      period13 type p,
      Total  type p
     
     END OF t_itab

As the first_itab is sorted by matnr land month, the Deliveryqty could be written directly to the periods.

That is period1 will contain the qty of 11.09,period2 will contain the qty of 12.09 and so on.

when writing out the itabs some periods will be empty .That means in my current example only 4 periods are there(That means all the other period columns will be empty).

A sample code would be useful....