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

insert line in itab

Former Member
0 Likes
977

Hi experts,

I have itab like this...


AUFNR	MATNR	MTART	REVNR
	<b>02A34B	HALB	</b>
4007049			33145679
4007051			33145679
4007052			33145679
<b>	36F14B	HALB</b>	
4007049			33145679
4007050			33145679
4007051			33145679
4007052			33145679

Now i want to insert one line like this.


AUFNR	MATNR	MTART	REVNR
<b>	02A34B	HALB	
----------------------------------</b>
4007049			33145679
4007051			33145679
4007052			33145679
<b>	36F14B	HALB	
----------------------------------</b>
4007049			33145679
4007050			33145679
4007051			33145679
4007052			33145679

I want to insert line in the itab itself.Not in the output.Can any one tell me how to do this? Is it possible?

reward guaranteed

thanks

kaki

11 REPLIES 11
Read only

Former Member
0 Likes
946

Hi Kaki,

DATA wa LIKE LINE OF itab.

CLEAR wa.

wa-matnr = '02A34B'.

wa-mtart = 'HALB'.

APPEND wa TO itab.

CLEAR wa.

wa-aufnr = '4007049'.

wa-revnr = '33145679'.

APPEND wa TO itab.

But if you mean to insert line '----'

This would not be possible.

Else you can create another internal table of type string and insert '---' in that table.

DATA itab TYPE TABLE OF string.

Regards,

Wenceslaus.

Read only

vinod_gunaware2
Active Contributor
0 Likes
946

Instead of that just put some code say AUFNR is &&&&&

and put condition in output display that if it &&&&& occusrs then print line.

regards

vinod

Read only

Former Member
0 Likes
946

HI

GOOD

CHECK OUT WITH THE FOLLOWING EXAMPLES

Inserting a Single Line

INSERT <line> INTO TABLE <itab>.

Inserting Several Lines

INSERT LINES OF <itab1> [FROM <n1>] [TO <n 2>] INTO TABLE <itab2>.

DATA: BEGIN OF LINE,

LAND(3) TYPE C,

NAME(10) TYPE C,

AGE TYPE I,

WEIGHT TYPE P DECIMALS 2,

END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE

WITH NON-UNIQUE KEY LAND NAME AGE WEIGHT.

LINE-LAND = 'G'. LINE-NAME = 'Hans'.

LINE-AGE = 20. LINE-WEIGHT = '80.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'USA'. LINE-NAME = 'Nancy'.

LINE-AGE = 35. LINE-WEIGHT = '45.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'USA'. LINE-NAME = 'Howard'.

LINE-AGE = 40. LINE-WEIGHT = '95.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'GB'. LINE-NAME = 'Jenny'.

LINE-AGE = 18. LINE-WEIGHT = '50.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'F'. LINE-NAME = 'Michele'.

LINE-AGE = 30. LINE-WEIGHT = '60.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'G'. LINE-NAME = 'Karl'.

LINE-AGE = 60. LINE-WEIGHT = '75.00'.

INSERT LINE INTO TABLE ITAB.

LOOP AT ITAB INTO LINE.

WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.

ENDLOOP.

-


DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA: ITAB LIKE STANDARD TABLE OF LINE,

JTAB LIKE SORTED TABLE OF LINE

WITH NON-UNIQUE KEY COL1 COL2.

DO 3 TIMES.

LINE-COL1 = SY-INDEX. LINE-COL2 = SY-INDEX ** 2.

APPEND LINE TO ITAB.

LINE-COL1 = SY-INDEX. LINE-COL2 = SY-INDEX ** 3.

APPEND LINE TO JTAB.

ENDDO.

INSERT LINES OF ITAB INTO TABLE JTAB.

LOOP AT JTAB INTO LINE.

WRITE: / SY-TABIX, LINE-COL1, LINE-COL2.

ENDLOOP.

THANKS

MRUTYUN

Read only

Former Member
0 Likes
946
try this

itab-AUFNR = '-------------'. "give as many dashes as length
itab-MATNR = '-------------'.
itab-MTART = '-------------'.
itab-REVNR = '-------------'.

append itab.
clear itab.
Read only

Former Member
0 Likes
946

Hi,

What is the data type of REVNR.

If its CHAR, you can do it as all others are of type CHAR.

Also, your table cant have any primary key as the field '----


' would get repeated.

Regards,

Tanveer.

Please mark helpful answers

Read only

Former Member
0 Likes
946

Hi,

Yes it is possible.

Loop at the internal table

LOOP AT ITAB INTO LINE.

AT END OF XXX.

assign all the fields the value '----' and appended it to the internal table

ENDAT.

AT LAST.

assign all the fields the value '----' and appended it to the internal table

ENDAT.

ENDLOOP.

Regards,

Sameena

Read only

naimesh_patel
Active Contributor
0 Likes
946

Hello,

Do like,

Loop at itab.

if itab-aufnr is initial.

l_index = sy-index.

l_index = l_index + 1.

wa_itab = '----


'.

insert itab from wa_itab index l_index.

endif.

endloop..

Regards,

Naimesh

Read only

0 Likes
946

add one field in itab.

lgtxt(50), " like t512t-lgtxt,

and when ever u want line just add

loop at itab.

itab-lgtxt = '----


'.

APPEND itab.

endloop.

Read only

Former Member
0 Likes
946
REPORT  YCHATEST                                .

tables : mara.

data : begin of itab occurs 0,
          matnr like mara-matnr,
          ernam like mara-ernam,
       end of itab.

       itab-matnr = '10003030'.
       itab-ernam = '52525'.
       append itab.
       clear itab.

       itab-matnr = '------------------'.
       itab-ernam = '--------'.
       append itab.
       clear itab.

       loop at itab.

          write : / itab-matnr , itab-ernam.
       endloop.
Read only

Former Member
0 Likes
946

Hi,

Use the following code.

REPORT y_test_itab .

TYPES: BEGIN OF ty_itab,

name TYPE char10,

age TYPE CHAR2,

END OF ty_itab.

DATA: lit_itab TYPE TABLE OF ty_itab.

DATA: wa_itab LIKE LINE OF lit_itab.

break mishraa.

wa_itab-name = 'AMIT'.

wa_itab-age = '20'.

APPEND wa_itab TO lit_itab.

wa_itab-name = sy-uline.

wa_itab-age = sy-uline.

APPEND wa_itab TO lit_itab.

wa_itab-name = 'AMIT'.

wa_itab-age = '20'.

APPEND wa_itab TO lit_itab.

Please ensure that your fields in the internal tables are character data type or you can move them into char type if required.

Hope this helps.

Please reward some poins here.

Read only

Former Member
0 Likes
946

Kaki - this works:


REPORT ztest MESSAGE-ID 00.

DATA: BEGIN OF itab OCCURS 0,
        aufnr(07) TYPE n,
        matnr(06),
        mtart(04),
        revnr(08) TYPE n,
      END   OF itab,

      BEGIN OF index_tab OCCURS 0,
        pos LIKE sy-tabix,
      END   OF index_tab.

DATA wa(27) VALUE '---------------------------'.

PERFORM load_itab.

LOOP AT itab.
  IF itab-aufnr IS INITIAL.
    index_tab-pos = sy-tabix + 1.
    APPEND index_tab.
  ENDIF.
ENDLOOP.

SORT index_tab DESCENDING BY pos.

LOOP AT index_tab.
  INSERT wa INTO itab INDEX index_tab-pos.
ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  load_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM load_itab.

  REFRESH itab.
  CLEAR   itab.
  itab-matnr = '02A34B'.
  itab-mtart = 'HALB'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007049'.
  itab-revnr = '33145679'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007051'.
  itab-revnr = '33145679'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007052'.
  itab-revnr = '33145679'.
  APPEND itab.

  CLEAR   itab.
  itab-matnr = '36F14B'.
  itab-mtart = 'HALB'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007049'.
  itab-revnr = '33145679'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007050'.
  itab-revnr = '33145679'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007051'.
  itab-revnr = '33145679'.
  APPEND itab.

  CLEAR   itab.
  itab-aufnr = '4007052'.
  itab-revnr = '33145679'.
  APPEND itab.

ENDFORM.                    " load_itab

Rob