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

Help on ABAP code

Former Member
0 Likes
529

Hi,

Lets say I have a table with 2 columns. Lets call this table IT_2.

Column 1 - Value is either a space or *

Column 2 - Text

So here is what I need to do, looping into a new table (Call it IT_3).

Loop at IT_2.

When Column 1 = *.

Create a new line with the value of column 2.

When Column 1 = space

Add the current column 2 text to the column 2 text of the previous row.

Please help. This is very important and I am unsure as to how to implement this.

Thanks,

John

4 REPLIES 4
Read only

Former Member
0 Likes
510

Hi John, Try as below:

data: l_str type string,
      i_str type table of string.

loop at it_2.

   if it_2-column1 = '*' and sy-tabix ne 1.
      append l_str to i_str.
      clear: l_str.
      move it_2-column2 to l_str.
   else.
      concantenate l_str it_2-column2 into l_str.
   endif.
   
   at last.
      append l_str to i_str.
   endat.
   
endloop.

Read only

Former Member
0 Likes
510

Hi, John Damion.

Try this:


TYPES: BEGIN OF TYP_IT_2,
         COLUMN1 TYPE C,
         COLUMN2 TYPE C LENGTH 10,
       END OF TYP_IT_2.

TYPES: BEGIN OF TYP_IT_3,
         COLUMN1 TYPE C,
         COLUMN2 TYPE C LENGTH 100,
       END OF TYP_IT_3.

DATA: IT_2    TYPE STANDARD TABLE OF TYP_IT_2,
      WA_IT_2 TYPE TYP_IT_2,
      IT_3    TYPE STANDARD TABLE OF TYP_IT_3,
      WA_IT_3 TYPE TYP_IT_3,
      WA_IT   TYPE TYP_IT_3.

WA_IT_2-COLUMN1 = '*'.
WA_IT_2-COLUMN2 = 'A'.
APPEND WA_IT_2 TO IT_2.

WA_IT_2-COLUMN1 = ' '.
WA_IT_2-COLUMN2 = 'B'.
APPEND WA_IT_2 TO IT_2.

WA_IT_2-COLUMN1 = '*'.
WA_IT_2-COLUMN2 = 'C'.
APPEND WA_IT_2 TO IT_2.

WA_IT_2-COLUMN1 = ' '.
WA_IT_2-COLUMN2 = 'D'.
APPEND WA_IT_2 TO IT_2.

WA_IT_2-COLUMN1 = ' '.
WA_IT_2-COLUMN2 = 'E'.
APPEND WA_IT_2 TO IT_2.

WRITE 'IT_2:'.
LOOP AT IT_2 INTO WA_IT_2.
  WRITE: / WA_IT_2-COLUMN1,
           WA_IT_2-COLUMN2.
ENDLOOP.

READ TABLE IT_2 INTO WA_IT INDEX 1.
LOOP AT IT_2 INTO WA_IT_2 FROM 2.
  IF WA_IT_2-COLUMN1 = ' '.
    CONCATENATE WA_IT-COLUMN2 WA_IT_2 INTO WA_IT-COLUMN2.
  ELSE.
    APPEND WA_IT TO IT_3.
    WA_IT = WA_IT_2.
  ENDIF.
ENDLOOP.
APPEND WA_IT TO IT_3.

WRITE / 'IT_3:'.
LOOP AT IT_3 INTO WA_IT.
  WRITE: / WA_IT-COLUMN1,
           WA_IT-COLUMN2.
ENDLOOP.

And the result is:


IT_2:
* A
  B
* C
  D
  E
IT_3:
* A B
* C D E

I hope this can help you.

Regards,

feng.

Read only

Former Member
0 Likes
510

Sorry, because of the slow Internet, I put the same message again.

And I have a question: How to insert a picture into a message in this forum?

Regards,

feng.

Edited by: feng zhang on Feb 26, 2008 10:17 AM

Read only

Former Member
0 Likes
510

Hi John

It is very simple , You need to take a temp variable and keep storing of column 2 value till it gets to an end . it seems that you want to use IT_3 as result table .

Sample code for you

Data l_text(20) type c.

Data it_2_lines type I.

Clear l_text .

Describe table it_2 lines it_2_lines.

Loop at it_2.

If it_2-column1 = ‘*’.

Move-corresponding it_2 to it_3.

Append it_3.

Endif.

If it_2-column1 = space .

.

Concantenate l_text it_2-column2 into l_text

Move l_text to it_3-column2.

Append it_3.

Note : I didn't execute the code in sap system so it might give some syntax error . Please let me know if you stuck in nay more problem I will provide you the solution after executing the code . Rewards if helpful