08-12-2007 7:49 PM
what is difference between with header line & without header line ?
08-12-2007 8:47 PM
Hello
It is the difference between <b>bad </b>and (hopefully) <b>good </b>programming.
Itabs with header lines apparently make programming somewhat easier. However, if it comes to maintenance or enhancing of the program, in particular by someone different then the original developer, header lines become a nightmare.
ABAP-OO does not allow header lines anymore. And that is what you should stick to even in classical programming.
Regards
Uwe
08-13-2007 7:51 AM
Hi ,
When u declare an internal table with header line , a work area is also created alomg with that internal table . So u dont need to create additions work area to process the elements innthat internal table .
Without header line means u have to create additional workarea with same structure to process the elements in the internal table .
with header is considered as bad programming practice .
Regards
08-13-2007 7:57 AM
Hi Spart,
if the internal table dont have header line u if u want to read the entries in that internal table u should create the work area wiith same structure as internal table and move the each record from int table to work area and process that record and move to int table.
if u have int table with header line u dont need to create work area its simple (easy ) to use with header line
reward points to all helpful answers
kiran.M
08-13-2007 11:33 AM
hi
good
while declaring the internal table two thing you might have identify
one is
DATA: begin of itab occurs 0 with header line.
DATA:begin of itab occurs 0,
first one is with header line and second one is without header line.
thanks
mrutyun^
08-14-2007 6:50 AM
if U use <b> with header line</b> U can directly assign data to internal table header and can append .
otherwise U need to create <b>work area </b> similat to <b>internal table structure</b> and to assign tha data to that <b>work area</b> and <b>append data from workarea to internal table using append lines statement</b>.
regards
Vijaykumar Reddy. S
08-17-2007 10:21 AM
HI,
f you specify WITH HEADER LINE, the table is created with a header line,
that is, a field with the same name. It has the same type as the line
type of the table.
For the sake of clarity, the table name should identify the table
uniquely, or then it depends on the statement whether the body or header
line of a table is accessed (header or table?).
Without header lines programs are easier to read. Table data and
structure are separated.
Tables with header lines do not improve performance and only tables
without header lines can be declared in ABAP Objects.
So it's better to use the syntax:
DATA: itab TYPE|LIKE TABLE OF ... ,
wa LIKE LINE OF itab.
Example:
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c,
END OF line.
DATA: with_header_tab LIKE TABLE OF line WITH HEADER LINE,
without_header_tab LIKE TABLE OF line.
line-col1 = 'A'. line-col2 = 'B'.
APPEND line TO with_header_tab.
with header line, SAP creates de work area
LOOP AT with_header_tab.
WRITE: / with_header_tab-col1, with_header_tab-col2.
ENDLOOP.
MOVE with_header_tab[] TO without_header_tab.
without header line, you create de work area and use into
LOOP AT without_header_tab INTO line.
WRITE: / line-col1, line-col2.
ENDLOOP.
08-17-2007 11:55 AM
Hi frend,
With header line is used mainly when data is to be fetched single record-wise into our structure.
Without header line is used mainly when data is to be fethed whole at a time from one table to other.
Regards,
Ameet
08-17-2007 12:59 PM
When you create an internal table object you can also declare a header line with the same name. You can use the header line as a work area when you process the internal table. The ABAP statements that you use with internal tables have short forms that you can use if your internal table has a header line. These statements automatically assume the header line as an implicit work area. The following table shows the statements that you must use for internal tables without a header line, and the equivalent statements that you can use for internal tables with a header line:
Operations without header line
Operations with header line
Operations for all Table Types
INSERT <wa> INTO TABLE <itab>.
INSERT TABLE ITAB.
COLLECT <wa> INTO <itab>.
COLLECT <itab>.
READ TABLE <itab> ... INTO <wa>.
READ TABLE <itab> ...
MODIFY TABLE <itab> FROM <wa> ...
MODIFY TABLE <itab> ...
MODIFY <itab> FROM <wa> ...WHERE ...
MODIFY <itab> ... WHERE ...
DELETE TABLE <itab> FROM <wa>.
DELETE TABLE <itab>.
LOOP AT ITAB INTO <wa> ...
LOOP AT ITAB ...
Operations for Index Tables
APPEND <wa> TO <itab>.
APPEND <itab>.
INSERT <wa> INTO <itab> ...
INSERT <itab> ...
MODIFY <itab> FROM <wa> ...
MODIFY <itab> ...
Using the header line as a work area means that you can use shorter statements; however, they are not necessarily easier to understand, since you cannot immediately recognize the origin and target of the assignment. Furthermore, the fact that the table and its header line have the same name can cause confusion in operations with entire internal tables. To avoid confusion, you should use internal tables with differently-named work areas.
The following example shows two programs with the same function. One uses a header line, the other does not.
With header line:
TYPES: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1
WITH HEADER LINE.
DO 4 TIMES.
ITAB-COL1 = SY-INDEX.
ITAB-COL2 = SY-INDEX ** 2.
INSERT TABLE ITAB.
ENDDO.
ITAB-COL1 = 2.
READ TABLE ITAB FROM ITAB.
ITAB-COL2 = 100.
MODIFY TABLE ITAB.
ITAB-COL1 = 4.
DELETE TABLE ITAB.
LOOP AT ITAB.
WRITE: / ITAB-COL1, ITAB-COL2.
ENDLOOP.
Without header line:
TYPES: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA: ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1,
WA LIKE LINE OF ITAB.
DO 4 TIMES.
WA-COL1 = SY-INDEX.
WA-COL2 = SY-INDEX ** 2.
INSERT WA INTO TABLE ITAB.
ENDDO.
WA-COL1 = 2.
READ TABLE ITAB FROM WA INTO WA.
WA-COL2 = 100.
MODIFY TABLE ITAB FROM WA.
WA-COL1 = 4.
DELETE TABLE ITAB FROM WA.
LOOP AT ITAB INTO WA.
WRITE: / WA-COL1, WA-COL2.
ENDLOOP.
The list, in both cases, appears as follows:
1 1
2 100
3 9
The statements in the program that does not use a header line are easier to understand. As a further measure, you could have a further work area just to specify the key of the internal table, but to which no other values from the table are assigned.
Internal table with header line
you can use anywhere except obkect oriented concept.
Internal table without header line :
You should use in Object oriented concept..
Always try to use without header line,performance point of view it is best..
Example :
Without header line.
Structure
types : begin of ty_itab ,
matnr type mara-matnr,
end of ty_itab.
Internal table
data i_itab type standard table of ty_itab .
Work area
data wa_itab like line of i_itab
With header line
data : begin of i_itab occurs 0,
matnr like mara-matnr,
end of i_itab
itab with header lines are obsolete, anyway it will work but not recommended. instead use work area or more effiecient is field symbols. so donot use itab with header line.
i will explain use of itab w/o header line.
Data: itab1 type standard table of mara with header line occurs 0,
itab2 type standard table of mara,
wa_itab2 type mara.
loop at itab1.
"This will work fine.
endloop.
loop at itab2.
"This will give erro that itabd does not hav workarea
endloop.
"so write
loop at itab2 into wa_itab2.
"This will work
endloop.
<b>The difference between
whih header line and with out heater line of internal table.
ex:-
a) Data : itab like mara occurs 0 with header line.
b) Data: itab like mara occurs 0.
-While adding or retrieving records to / from internal table we have to keep the record temporarily.
-The area where this record is kept is called as work area for the internal table.
-The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
-Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
a) Data : itab like mara occurs 0 with header line.
table is with header line
b) Data: itab like mara occurs 0.
table is without header line</b>
regards,
srinivas
<b>*reward for useful answers*</b>
10-22-2007 5:42 AM
Hi Expert
Can anyone tell me how to add header line to my small report
Below is the report for document changes for 2 tables CDPOS, CDHDR
I need some modification for how to add the ranges
Plant from ________ to ___________
Udate from __________ to ___________-
Document No from ________ to __________
Change date from ____________ to _____________
username by __________
If i don't enter anything the it should display all the records esle the ranges defined.
I even want to add plant code from and to but not getting idea from which table it has to be taken? I want this to be display in ALV Gride table
Please could anyone help me in modification please urgent.........v urgent
REPORT ZCHGDOC.
TABLES: CDHDR,
CDPOS.
DATA: BEGIN OF itab occurs 0,
UDATE TYPE sy-datum,
end of itab.
SELECT-OPTIONS udate for sy-datum .
SELECTION-SCREEN BEGIN OF BLOCK DOCUMENT WITH FRAME TITLE TEXT-701.
PARAMETER: CHANGENR LIKE CDHDR-CHANGENR.
SELECTION-SCREEN END OF BLOCK DOCUMENT.
END-OF-SELECTION.
DATA: BEGIN OF IT_CDHDR OCCURS 0,
OBJECTCLAS LIKE CDHDR-OBJECTCLAS,
OBJECTID LIKE CDHDR-OBJECTID,
CHANGENR LIKE CDHDR-CHANGENR,
USERNAME LIKE CDHDR-USERNAME,
UDATE LIKE CDHDR-UDATE,
UTIME LIKE CDHDR-UTIME,
VALUE_NEW LIKE CDPOS-VALUE_NEW,
VALUE_OLD LIKE CDPOS-VALUE_OLD,
END OF IT_CDHDR.
DATA: WA LIKE LINE OF IT_CDHDR.
DATA: WA LIKE LINE OF IT_CDPOS.
DATA: BEGIN OF IT_CDPOS OCCURS 0,
OBJECTCLAS LIKE CDHDR-OBJECTCLAS,
OBJECTID LIKE CDHDR-OBJECTID,
CHANGENR LIKE CDHDR-CHANGENR,
TABNAME LIKE CDPOS-TABNAME,
FNAME LIKE CDPOS-FNAME,
VALUE_NEW LIKE CDPOS-VALUE_NEW,
VALUE_OLD LIKE CDPOS-VALUE_OLD,
END OF IT_CDPOS.
SELECT OBJECTCLAS
OBJECTID
CHANGENR
USERNAME
UDATE
UTIME INTO CORRESPONDING FIELDS OF TABLE IT_CDHDR
FROM CDHDR
WHERE OBJECTCLAS = 'VERKBELEG'.
IF IT_CDHDR[] IS NOT INITIAL.
SELECT OBJECTCLAS
OBJECTID
CHANGENR
VALUE_NEW
VALUE_OLD
FNAME
TABNAME
INTO CORRESPONDING FIELDS OF TABLE IT_CDPOS FROM CDPOS
FOR ALL ENTRIES IN IT_CDHDR
WHERE
OBJECTCLAS = IT_CDHDR-OBJECTCLAS
AND OBJECTID = IT_CDHDR-OBJECTID
AND CHANGENR = IT_CDHDR-CHANGENR.
SORT IT_CDPOS BY OBJECTCLAS OBJECTID CHANGENR.
ENDIF.
Add tables CDPOS DATA TO CDHDR.
DATA: INDEX TYPE i.
LOOP AT IT_CDHDR.
INDEX = SY-TABIX.
READ TABLE IT_CDPOS WITH KEY OBJECTCLAS = IT_CDHDR-OBJECTCLAS
OBJECTID = IT_CDHDR-OBJECTID
CHANGENR = IT_CDHDR-CHANGENR BINARY SEARCH.
IF SY-SUBRC = 0.
IT_CDHDR-VALUE_NEW = IT_CDPOS-VALUE_NEW.
IT_CDHDR-VALUE_OLD = IT_CDPOS-VALUE_OLD.
MODIFY IT_CDHDR INDEX index TRANSPORTING value_new value_old.
ENDIF.
LOOP AT IT_CDHDR INTO WA.
WRITE: WA-OBJECTID.
WRITE: / WA-UDATE,WA-CHANGENR,WA-USERNAME,WA-VALUE_NEW,WA-VALUE_OLD.
WRITE: / WA-CHANGENR,WA-VALUE_NEW,WA-VALUE_OLD.
ENDLOOP.
ENDLOOP.
08-17-2007 2:04 PM
HI SPART,
IF U DONT MIND CAN I SUGGEST ONE THING ,,
BEFORE POSTING ANY QUESTION Y CANT U SEARCH IN THE FORUM (IF UR NOT FINDOUT THE PROPER SOLUTION )THEN U GO FOR POSTING..
see most of the Aswers which u have got right now most of these stuff is already seen if u once go for search one ur question..
So plz next time onwards try to search a moment and post ..
Treat me as a Friend and dont mind.
Thanks
Naveen khan
10-22-2007 6:32 AM
There are two types of internal tables.
Internal tables with HEADER line and the other
Internal tables without HEADER line.
Internal Tables with Header Line : Here the system automatically creates the work area. The work area has the same data type as internal table. This work area is called the HEADER line. It is here that all the changes or any of the action on the contents of the table are done. As a result of this, records can be directly inserted into the table or accessed from the internal table directly.
Internal Tables without Header Line : Here there is no work area associated with the table. Work area is to be explicitly specified when we need to access such tables. Hence these tables cannot be accessed directly.
10-22-2007 6:28 PM
Hi,
With header line the table have additional work area, so u can use this work area to process the data filled in the table by reading it into this work area (which have the same name of the table)
Ex: READ TABLE itab_with_header_line INDEX 1.
then itab_with_header_line-column will be the value of the column column of the first line (INDEX 1).
You can also use this work area to append the table.
Ex:
itab_with_header_line-column1 = value1.
itab_with_header_line-column2 = value2.
itab_with_header_line-column3 = value3.
...
APPEND itab_with_header_line.
While, when the table is without header line, that means this work area does not exit.
So, as in the example above if u wanna read such a table u do so:
READ TABLE itab_without_header_line INTO structure_like_the_itab INDEX 1.
In structure_like_the_itab-column1 we have the value of the first column & first line (INDEX 1).
There is several ways to declare a table with header line :
1-
DATA: itab_with_head_line TYPE STANDARD TABLE OF dbtab_or_defined_type
WITH HEADER LINE.
2-
DATA: BEGIN OF itab_with_header_line OCCURS n,
field1 TYPE type1,
field2 TYPE type2,
field3 TYPE type3,
.....
END OF itab_with_header_line.
3-
DATA: BEGIN OF itab_with_header_line OCCURS n.
INCLUDE STRUCTURE dbtab.
DATA: END OF itab_with_header_line.
...
And to declare a table without header line:
1-
DATA: itab_without_headline TYPE STANDARD TABLE OF dbtab_or_defined_type.
....
As said in some of the above answers, it's recommended to use internal tables <b>without header line</b>.
I hope that will be helpfull.
Regards,
Amine