Work area and internal table
hi friends,
Please let me know when do we use work area and when do we use internal table.
Thanks in advance
Tina Wilson
Work areas are used with internal tables. For example if you have an internal table defined like this.
data: itab type table of mara.
This internal table can hold many rows of data, right? SO say you need to read this data. Well you will need to LOOP or READ the internal table, since this internal table has no header line(please to put the read data), you need to have a work area to put the data into.
<b>data: wa like line of itab.</b>
Loop at itab <b>into wa</b>.
endloop.
Now if you defined the internal table with a header line, there is no reason to have the work area and you can just do the same like this.
data: itab type table of mara <b>with header line</b>.
Loop at itab.
endloop.
It is now best practice to use work areas instead of header lines because in ABAP OO, header lines are not allowed.
Regards,
Rich Heilman
Similar Messages
-
Difference between work area and internal tables.
Hi I wanna know the difference between work area and internal tables.
what happend if i give with out header line in internal table.
also how to assosiate work area to internal table in that scenario.Hi Balaji..
The internal table is an ABAP runtime object which has two parts the Body and the header.
Whereas a work area cannot have a body.. It is mere a field or group of fields which can hold values at runtime..
In the SAP higher versions mySAP ERP, the use of tables with header line is made obsolete.. But there is absolutely no problem with the same..
Just think that when you define an internal table with occurs or with header line statement, the system automatically creates a workarea with this table, using which you can access the contents in the bosy of tyhe table.. You can read a record from the table body to this header or add a record in the header to the internal table body..
When you work with a table ITAB without a header line, you can not use statements like READ TABLE, APPEND, INSERT etc without giving an explicit work area..
Suppose i have an internal table like:
DATA : itab TYPE STANDARD TABLE OF t001.
This table will not have a header with it.
If you will use APPEND itab. The compilor will give error.
Here i will create a work area with same structure of the table.
DATA : e_wa TYPE t001.
Now i will write:
APPEND e_wa TO itab.
READ TABLE itab INTO e_wa WITH KEY xxxxxx
LOOP AT itab INTO e_wa... etc..
In a better approach we use Field symbols with such tables, instead of structures
FIELD-SYMBOLS: <fs_itab> TYPE t001.
So,
LOOP AT itab ASSIGNING <fs_itab>
READ TABLE itab ASSIGNING <fs_itab> etc.. However we can not use field symbols in few cases..
I hope this will help you..
Thanks and Best Regards,
Vikas Bittera.
**Points for usefull answers** -
The type of the database table and work area (or internal table)...
Hello
I am trying to use a database and select all records from it and store them into an internal table.
My code:
Select * from xixi_dbcurrency into table gt_currency.
The error:
"The type of the database table and work area (or internal table) "GT_CURRENCY" are not Unicode-convertible . . . . . . . . . . "
Any suggestions?
Thank youHi Thomas,
Thank you for your inputs above.
But as you suggested is we use INTO CORRESPONDING FIELDS OF TABLE then it resolve the error.
But I have below piece of code:
DATA: it_new_source TYPE STANDARD TABLE OF _ty_s_sc_1,
wa_source TYPE _ty_s_sc_1,
wa_new_source TYPE _ty_s_sc_1,
ls_target_key TYPE t_target_key.
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_new_source
FROM /bic/afao06pa100
FOR ALL ENTRIES IN SOURCE_PACKAGE
where /bic/fcckjobno = SOURCE_PACKAGE-/bic/fcckjobno
and /bic/fcckjitid = SOURCE_PACKAGE-/bic/fcckjitid.
But since this is reading into corresponding fields of table the data load from one DSO to other DOS is running for long more that 15 hours and still not getting completed and giving dump.
So if I switch the search to below:
SELECT * FROM /bic/afao06pa100
INTO TABLE it_new_source
FOR ALL ENTRIES IN SOURCE_PACKAGE
where /bic/fcckjobno = SOURCE_PACKAGE-/bic/fcckjobno
and /bic/fcckjitid = SOURCE_PACKAGE-/bic/fcckjitid.
Then I am getting below error:E:The type of the database table and work area (or internal table) "IT_NEW_SOURCE" are not Unicode convertible.
Can you please advice on this, as performance need to improve in start routine code.
Thank You. -
The work area (or internal table) "IT_ZLE_LAGERPLANUNG" is not flat,
***Data declaration
TYPES : BEGIN OF t_zle_lagerplanung,
SEl, "stores which row user has selected
kdauf TYPE zle_lagerplanung-kdauf,
kdpos TYPE zle_lagerplanung-kdpos,
etenr TYPE zle_lagerplanung-etenr,
papiermaschine TYPE zle_lagerplanung-papiermaschine,
runnr TYPE zle_lagerplanung-runnr,
prio TYPE zle_lagerplanung-prio,
werk TYPE zle_lagerplanung-werk,
durchmesser TYPE zle_lagerplanung-durchmesser,
breite TYPE zle_lagerplanung-breite,
anzle TYPE zle_lagerplanung-anzle,
occupied TYPE zle_lagerplanung-text30,
free TYPE zle_lagerplanung-text30,
lgpla TYPE zle_lagerplanung-lgpla,
lgtyp TYPE zle_lagerplanung-lgtyp,
art TYPE zle_lagerplanung-art,
anzhoehe TYPE zle_lagerplanung-anzle,
zindicator TYPE zle_lagerplanung-text30,
fa TYPE zle_lagerplanung-fa,
field_style TYPE lvc_t_styl, "FOR DISABLE
END OF t_zle_lagerplanung.
I am getting the data in internal table by using thiis select statement.
SELECT kdauf kdpos etenr papiermaschine runnr prio werk durchmesser breite
anzle lgpla lgtyp art anzhoehe fa
FROM zle_lagerplanung INTO CORRESPONDING FIELDS OF TABLE it_zle_lagerplanung
WHERE kdauf IN s_kdauf
" AND kdpos = p_kdpos
AND KDPOS IN s_kdpos
AND werk = p_werks.
But while updating the particular field in ztable using this statement
UPDATE zle_lagerplanung from table it_zle_lagerplanung.
it is giving syntax error
"The work area (or internal table) "IT_ZLE_LAGERPLANUNG" is not flat, or
contains reference or internal tables as components. components.
components. components. components."
Could any one help me out how to resolve this problem....
Thanks in advanceHi Shyamal,
lvc_s_styl is a structure so you will get the same error.
for your select and update statement you dont need field "field_style".
regards
rea -
Difference between Field symbols and work area for Internal tables
Hi,
In ECC versions we all know that we need to declare the internal tables without headerline, and for handling the internal tables we need to use exclusive work areas.
Currently i have an issue that we have been asked to use field symbols instead of work areas...can any one help me how to use the field symbols and also let me know how it will improve the performance of the program..
Thanks and Regards,
KathirHi
DATA: WA TYPE ITAB.
LOOP AT ITAB INTO WA.
IF WA-FIELD = .....
ENDIF.
ENDLOOP.[(code]
FIELD-SYMBOLS <WA> TYPE ANY.
LOOP AT ITAB ASSIGNING <WA>.
ENDLOOP.
Now the problem is you can't know the name of the fields of the table at runtime, so you can't write:
IF <WA>-FIELD = .....
ENDIF.
Anyway you can create a field-symbols strcturated like the table:
[code]FIELD-SYMBOLS <WA> TYPE ITAB.
LOOP AT ITAB ASSIGNING <WA>.
IF <WA>-FIELD = .....
ENDIF.
ENDLOOP.
I don't know which are the differences for the performance between to use a field-symbol and to use a structure as work-area.
The differnce between the field-symbols and work-area is the field-symbol is assigned directly to the record, so u don't need to do a MODIFY statament to change something:
LOOP AT ITAB INTO WA.
WA-FIELD =
MODIFY ITAB FROM WA.
ENDLOOP.
LOOP AT ITAB ASSIGNING <WA>.
<WA>-FIELD =
ENDLOOP.
These two pieces of abap code do the same action, so probably the field-symbol improve the performance because it do an access directly to the record without to use an external structure as workarea.
Max -
Working Area for Internal Table
Hi,
i know that process of internal table if it is with headerline but i don't know how the data pass to our internal table if it is with out header line plzz give me the example code for that.
Thanks in advanceThe 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 -
Dynamic ALV and internal table.
Hi all,
I have a requirement of creating a dynamic field catelog based on input values in selection screen.
Example:
1) When I enter date range, say 20/03/2008 to 25/03/2008 I should have 6 columns in the output for each date with column heading as date itself.
2) For entering values for these date columns, i need to create an dynamic internal table.(values in the column will be some numbers like 10 on 20/03/2008, 15 on 21/03/2008 etc)
A rough output format would look like this:
Component | 20/03/2008 | 21/03/2008 | ..... |25/03/2008
comp1 | 10 | 15 | | 5
comp2 | 20 | 10 | | 10
Please let me know how can i achieve this...
Need it very urgently..
Regards,
DhareppaHi Dhareppa,
Refer the code below. Its almost on the same line as your requirments.
REPORT zglo2fr_master_planing_sedul NO STANDARD PAGE HEADING.
P R O G R A M H E A D E R *
ArthroCare Corporation *
Program : ZGLO2FR_MASTER_PLANING_SEDUL *
Author : Munvar Basha *
Creation Date : 11Mar08 *
Release : SAP ECC 6.0 *
Request : D01K904032 *
Description : Master Schedule Planning *
Change log (Revisions) *
Author Date Request Description *
P R O G R A M *
DATA DECLARATION *
**--Structure to hold matrial & plant combination records.
TYPES : BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
dispo TYPE dispo,
beskz TYPE beskz,
mtart TYPE mtart,
END OF ty_marc.
**--structure to hold MRP LIST Data.
TYPES : BEGIN OF ty_mrp_list,
matnr TYPE matnr,
werks TYPE werks_d,
maktx TYPE maktx,
meins TYPE meins,
mtart TYPE mtart,
week TYPE kweek,
mng01 TYPE mng01,
delkz TYPE delkz,
END OF ty_mrp_list.
**--structure to hold no of weeks.
TYPES: BEGIN OF ty_week,
week TYPE kweek,
END OF ty_week.
**--structure to hold output data.
TYPES : BEGIN OF ty_final,
matnr TYPE matnr,
werks TYPE werks_d,
maktx TYPE maktx,
meins TYPE meins,
mtart TYPE mtart,
week TYPE kweek,
mng01 TYPE mng01,
END OF ty_final.
TYPES : BEGIN OF ty_range,
sign TYPE sign,
option TYPE option,
low TYPE sy-datum,
high TYPE sy-datum,
END OF ty_range.
Definitions of Table types. *
TYPES : ty_marctab TYPE STANDARD TABLE OF ty_marc.
Definitions of Ranges *
*RANGES ran_delkz FOR mdez-delkz.
DATA : i_ran_delkz TYPE RANGE OF mdez-delkz,
wa_ran_delkz LIKE LINE OF i_ran_delkz,
wa_date type ty_range.
Definitions of internal tables. *
data : i_marc type standard table of ty_marc,
i_mrp_list type standard table of ty_mrp_list,
i_week type standard table of ty_week,
i_final type standard table of ty_final,
i_mdps type standard table of mdps,
i_mdez type standard table of mdez,
i_mdsu type standard table of mdsu.
Definitions of work areas for internal tables *
DATA : wa_marc TYPE ty_marc,
wa_mrp_list TYPE ty_mrp_list,
wa_week TYPE ty_week,
wa_final TYPE ty_final,
wa_mt61d TYPE mt61d,
wa_mdez TYPE mdez.
Definitiions of General variables *
DATA : v_matnr TYPE mara-matnr, " Material Number
v_mtart TYPE mara-mtart, " Material Type
v_beskz TYPE marc-beskz, " Procurement Type
v_werks TYPE marc-werks, " Plant
v_dispo TYPE marc-dispo. " MRP Controller (Materials Planner)
DATA : v_mng01 TYPE mng01. "Requirement Quantity
DATA : v_year TYPE char4,
v_week TYPE char2,
v_ok_code TYPE sy-ucomm.
Definitiions of Constants *
CONSTANTS : k_slash TYPE c VALUE '/',
k_6 TYPE char8 VALUE '6',
k_x TYPE c VALUE 'X'.
Definitiions of Field Catlog *
DATA : wa_fieldcat TYPE lvc_s_fcat,
i_fieldcat TYPE lvc_t_fcat,
v_container TYPE scrfname VALUE 'CONTAINER_OUTPUT',
v_custom_container TYPE REF TO cl_gui_custom_container,
v_grid TYPE REF TO cl_gui_alv_grid,
i_gp_table TYPE REF TO data,
wa_gp_line TYPE REF TO data.
FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
<gwa_table> TYPE ANY,
<l_field> TYPE ANY,
<l_matnr> TYPE ANY,
<l_werks> TYPE ANY,
<l_maktx> TYPE ANY,
<l_meins> TYPE ANY,
<l_mtart> TYPE ANY.
DECLERATIONS FOR SELECTION SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR v_matnr,
s_mtart FOR v_mtart NO INTERVALS,
s_beskz FOR v_beskz NO INTERVALS NO-EXTENSION,
s_werks FOR v_werks NO INTERVALS NO-EXTENSION
OBLIGATORY,
s_dispo FOR v_dispo,
s_date FOR sy-datum OBLIGATORY.
PARAMETERS : p_dattp TYPE dattp OBLIGATORY DEFAULT '1'.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION EVENT *
INITIALIZATION.
CALL FUNCTION '/BEV4/PLPS__ADD_MONTH_TO_DATE'
EXPORTING
months = k_6
olddate = sy-datum
IMPORTING
newdate = wa_date-high.
wa_date-low = sy-datum.
wa_date-option = 'EQ'.
wa_date-sign = 'I'.
APPEND wa_date to s_date.
SELECTION SCREEN EVENT *
**--Validation for Material
AT SELECTION-SCREEN ON s_matnr.
PERFORM validate_material.
**--Validation for Plant
AT SELECTION-SCREEN ON s_werks.
PERFORM validate_plant.
AT SELECTION-SCREEN ENENT *
AT SELECTION-SCREEN.
IF s_matnr IS INITIAL AND s_dispo IS INITIAL.
MESSAGE text-002 TYPE 'E'.
ENDIF.
IF s_date-low LT sy-datum.
MESSAGE text-003 TYPE 'E'.
ENDIF.
START-OF-SELECTION EVENT *
START-OF-SELECTION.
**--refreshing the internal tables
REFRESH : i_marc,
i_mrp_list,
i_week,
i_final,
i_mdps,
i_mdez,
i_mdsu.
**--clearing the work areas of internal tables.
CLEAR : wa_marc,
wa_mrp_list,
wa_week,
wa_final,
wa_mt61d,
wa_mdez.
To get all the matrial(s) and plant combination records
SELECT a~matnr
a~werks
a~dispo
a~beskz
b~mtart
INTO TABLE i_marc
FROM marc AS a INNER JOIN
mara AS b
ON a~matnr = b~matnr
WHERE a~werks IN s_werks AND
a~matnr IN s_matnr AND
a~dispo IN s_dispo AND
a~beskz IN s_beskz AND
b~mtart IN s_mtart.
IF sy-subrc <> 0.
MESSAGE text-005 TYPE 'S'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT i_marc BY matnr werks.
Ranges to Filter the MRP list only for the following MRP Elements.
MRP Elements are : BA, BE, FE, LE and PA
wa_ran_delkz-sign = 'I'.
wa_ran_delkz-option = 'EQ'.
wa_ran_delkz-low = 'BA'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'BE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'FE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'LE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'PA'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
LOOP AT i_marc INTO wa_marc.
CALL FUNCTION 'MD_MRP_LIST_API'
EXPORTING
matnr = wa_marc-matnr
werks = wa_marc-werks
sinfg = k_x
inper = p_dattp
IMPORTING
e_mt61d = wa_mt61d
TABLES
mdpsx = i_mdps
mdezx = i_mdez
mdsux = i_mdsu
EXCEPTIONS
mrp_list_not_found = 1
material_plant_not_found = 2
error = 3
OTHERS = 4.
IF sy-subrc = 0.
LOOP AT i_mdez INTO wa_mdez WHERE dat00 IN s_date AND
delkz IN i_ran_delkz.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = wa_mdez-dat00
IMPORTING
week = wa_mrp_list-week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc = 0.
wa_mrp_list-matnr = wa_mt61d-matnr.
wa_mrp_list-werks = wa_mt61d-werks.
wa_mrp_list-maktx = wa_mt61d-maktx.
wa_mrp_list-meins = wa_mt61d-meins.
wa_mrp_list-mtart = wa_mt61d-mtart.
wa_mrp_list-delkz = wa_mdez-delkz.
wa_mrp_list-mng01 = wa_mdez-mng01.
APPEND wa_mrp_list TO i_mrp_list.
CLEAR : wa_mrp_list,
wa_mdez.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR: wa_marc.
ENDLOOP.
IF i_mrp_list IS INITIAL.
MESSAGE text-006 TYPE 'S'.
LEAVE LIST-PROCESSING.
ENDIF.
CLEAR : v_mng01.
LOOP AT i_mrp_list INTO wa_mrp_list.
v_mng01 = v_mng01 + wa_mrp_list-mng01.
AT END OF week.
wa_final-matnr = wa_mrp_list-matnr.
wa_final-werks = wa_mrp_list-werks.
wa_final-maktx = wa_mrp_list-maktx.
wa_final-meins = wa_mrp_list-meins.
wa_final-mtart = wa_mrp_list-mtart.
wa_final-week = wa_mrp_list-week.
wa_final-mng01 = v_mng01.
wa_week-week = wa_mrp_list-week.
APPEND : wa_final TO i_final,
wa_week TO i_week.
CLEAR : v_mng01,
wa_final,
wa_week.
ENDAT.
CLEAR : wa_mrp_list.
ENDLOOP.
**-- Populate the Field catalog
PERFORM populate_fieldcat.
**--Create table dynamically
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcat
IMPORTING
ep_table = i_gp_table.
ASSIGN i_gp_table->* TO <gt_table>.
**--fill table with final output data
PERFORM fill_table.
CALL SCREEN 100.
SUB ROUTINES *
*& Form validate_material *
Validating Material Number(s) *
FORM validate_material .
TYPES : BEGIN OF l_ty_matnr,
matnr TYPE matnr,
END OF l_ty_matnr.
DATA : l_i_matnr TYPE STANDARD TABLE OF l_ty_matnr.
SELECT matnr
FROM mara
INTO TABLE l_i_matnr
WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
MESSAGE text-004 TYPE 'E'.
ENDIF.
ENDFORM. " validate_material
*& Form validate_plant *
Validating Plant Number *
FORM validate_plant .
DATA : l_v_werks TYPE werks_d.
SELECT SINGLE werks
FROM t001w
INTO l_v_werks
WHERE werks = s_werks-low.
IF sy-subrc <> 0.
MESSAGE e019(zartc) WITH s_werks-low.
ENDIF.
ENDFORM. " validate_plant
*& Form populate_fieldcat
text
--> p1 text
<-- p2 text
FORM populate_fieldcat .
DATA : l_v_colname TYPE char7.
SORT i_week BY week.
DELETE ADJACENT DUPLICATES FROM i_week COMPARING week.
LOOP AT i_week INTO wa_week.
AT FIRST.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_l = text-007.
wa_fieldcat-scrtext_m = text-007.
wa_fieldcat-scrtext_s = text-007.
wa_fieldcat-fix_column = 'X'.
wa_fieldcat-outputlen = 18.
wa_fieldcat-tooltip = text-007.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-scrtext_l = text-008.
wa_fieldcat-scrtext_m = text-008.
wa_fieldcat-scrtext_s = text-008.
wa_fieldcat-fix_column = 'X'.
wa_fieldcat-outputlen = 4.
wa_fieldcat-tooltip = text-008.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'MAKTX'.
wa_fieldcat-scrtext_l = text-009.
wa_fieldcat-scrtext_m = text-010.
wa_fieldcat-scrtext_s = text-011.
wa_fieldcat-tooltip = text-009.
wa_fieldcat-outputlen = 40.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_l = text-012.
wa_fieldcat-scrtext_m = text-013.
wa_fieldcat-scrtext_s = text-014.
wa_fieldcat-outputlen = 4.
wa_fieldcat-tooltip = text-012.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'MTART'.
wa_fieldcat-scrtext_l = text-015.
wa_fieldcat-scrtext_m = text-015.
wa_fieldcat-scrtext_s = text-016.
wa_fieldcat-tooltip = text-015.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
ENDAT.
v_year = wa_week-week+0(4).
v_week = wa_week-week+4(2).
CONCATENATE v_week k_slash v_year INTO l_v_colname.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 6 + sy-index.
wa_fieldcat-fieldname = wa_week-week.
wa_fieldcat-quantity = 'X'.
wa_fieldcat-outputlen = 18.
wa_fieldcat-scrtext_l = l_v_colname.
wa_fieldcat-tooltip = l_v_colname.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR : wa_fieldcat,
l_v_colname,
wa_week.
ENDLOOP.
ENDFORM. " populate_fieldcat
*& Form fill_table
text
--> p1 text
<-- p2 text
FORM fill_table .
**--Create Work Area Dynamically
CREATE DATA wa_gp_line LIKE LINE OF <gt_table>.
ASSIGN wa_gp_line->* TO <gwa_table>.
DATA : l_v_col TYPE char25,
l_v_val TYPE char25.
LOOP AT i_final INTO wa_final.
l_v_col = wa_final-week.
ASSIGN COMPONENT l_v_col OF STRUCTURE <gwa_table>
TO <l_field>.
IF <l_field> IS ASSIGNED.
l_v_val = wa_final-mng01.
CONDENSE l_v_val.
<l_field> = l_v_val.
clear : l_v_val,
l_v_col.
ENDIF.
AT END OF matnr.
READ TABLE i_final INTO wa_final WITH KEY matnr = wa_final-matnr
BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gwa_table>
TO <l_matnr>.
IF <l_matnr> IS ASSIGNED.
<l_matnr> = wa_final-matnr.
ENDIF.
ASSIGN COMPONENT 'WERKS' OF STRUCTURE <gwa_table>
TO <l_werks>.
IF <l_werks> IS ASSIGNED.
<l_werks> = wa_final-werks.
ENDIF.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <gwa_table>
TO <l_maktx>.
IF <l_maktx> IS ASSIGNED.
<l_maktx> = wa_final-maktx.
ENDIF.
ASSIGN COMPONENT 'MEINS' OF STRUCTURE <gwa_table>
TO <l_meins>.
IF <l_meins> IS ASSIGNED.
<l_meins> = wa_final-meins.
ENDIF.
ASSIGN COMPONENT 'MTART' OF STRUCTURE <gwa_table>
TO <l_mtart>.
IF <l_mtart> IS ASSIGNED.
<l_mtart> = wa_final-mtart.
ENDIF.
APPEND <gwa_table> TO <gt_table>.
CLEAR <gwa_table>.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. " fill_table
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZMUNNA'.
SET TITLEBAR 'MRP'.
IF v_custom_container IS INITIAL.
CREATE OBJECT v_custom_container
EXPORTING
container_name = v_container.
CREATE OBJECT v_grid
EXPORTING
i_parent = v_custom_container.
CALL METHOD v_grid->set_table_for_first_display
CHANGING
it_outtab = <gt_table>
it_fieldcatalog = i_fieldcat.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE user_command_0100 INPUT.
v_ok_code = sy-ucomm.
CLEAR sy-ucomm.
CASE v_ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
SET SCREEN 000.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form exit_program
text
--> p1 text
<-- p2 text
FORM exit_program .
CALL METHOD v_custom_container->free.
CALL METHOD cl_gui_cfw=>flush.
ENDFORM. " exit_program
Reward points if that helps.
Manish -
Internal table declaration - work area and body
Hi all
I have declared my internal table in my program as
data : itab_wa type ZRESULT_LINE,
itab type ZRESULT_ROW.
Where ZRESULT_LINE and ZRESULT_ROW are the structure and table types.
Now I want to add
data: TCOLOR TYPE SLIS_T_SPECIALCOL_ALV.
in my internal table declaration. How can I do this. Please remember I need to have work area and body in my internal table as I have used work area and body in my code.
Waiting..............
Message was edited by: Raju BodaHI,
See the Declarion types of workarea and Internal tables
* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0, "itab with header line
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF tab_ekpo.
*Table declaration (new method) "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0, "itab
wa_ekpo TYPE t_ekpo. "work area (header line)
* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0, "old method
wa_datatab LIKE LINE OF tab_ekpo.
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE tab_ekpo. "could include EKKO table itself!!
TYPES: bukrs TYPE ekpo-werks,
bstyp TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0, "itab
wa_repdata TYPE t_repdata. "work area (header line
you need to maintain same structure for both workarea as well Internal table
Regards
Sudheer -
What are dyanmic internal tables and what s the exact use of forall entries
what are dyanmic internal tables and what s the exact use of forall entries?
hi,
<u><b>dynamic internal table.</b></u>
http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html
http://www.sap-img.com/ab030.htm
<u><b>
FOR ALL ENTRIES</b></u> is an effective way of doing away with using JOIN on two tables.
You can check the below code -
SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....
SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.
*******************************8
look another example
what is the use of FOR ALL ENTRIES
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
Hope this helps!
Regards,
Anver -
DIFF: Field string ,Structure and Internal table declaration
Hai,
what is the diference between Field string ,Structure in ABAP program and Internal table declaration and how it will work ?
Thank you
ASHOK KUMAR.hi,
Look this u will get a good idea.
*& Report ZTYPES *
REPORT ZTYPES .
* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0, "itab with header line
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF tab_ekpo.
*Table declaration (new method) "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0, "itab
wa_ekpo TYPE t_ekpo. "work area (header line)
* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0, "old method
wa_datatab LIKE LINE OF tab_ekpo.
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE tab_ekpo. "could include EKKO table itself!!
TYPES: bukrs TYPE ekpo-werks,
bstyp TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0, "itab
wa_repdata TYPE t_repdata. "work area (header line)
Regards
Reshma -
Difference between line type and internal table?
Hi..
I wanted to know, what is the difference between Line type and Internal Table?Hi,
Before the 4.7 release in SAP if we want to define an internal table we have to write the defination using the occurs statement and we need to define all the fields using INCLUDE STRUCTURE or indidually all the fields ine by one.
From 4.7 release of R/3 SAP introduced the Line type concept and it's part of the ABAP OOPS concept. for internal table defination we don't need to use the occur statements. Instead INCLUDE structure we need to create a Line type for that structure in Se11 and then we can define the internal table like :
DATA : ITAB TYPE TABLE OF <LINE_TYPE>.
Only thing is this table will be a table without header. So for internal table processing we need to define a work area structure of type line of line type . EX:
DATA: WA_ITAB TYPE LINE OF <LINE_TYPE>.
Hope this helps.
Thanks,
Greetson -
What are nested Internal tables
Hi Guru's,
I am new to ABAP ...just trying to learn things.Can you please explain me what are nested internal tables and what is the purpose of nested internal table?where can it be used and why a header line is not written in a Nested Internal table...
Kindly explain it (scenario where nested internal tables are used) with an example it will be helpful.
Cheers,
PriyankaHi,
When storing data in internal tables, you often use one internal table for each database you read.
Each one contains some or all columns of the relevant database table. It is up to you whether
you create an internal table with a flat structure for each database table or if you create, for
example, internal tables with nested structures. If you have several tables, each one with a flat
structure, you have to work with redundant key fields to link the tables. If, on the other hand, you
use nested internal tables, you can store the data from the database tables hierarchically.
Saving and processing very large amounts of data in internal tables has disadvantages. If you
divide up the data into different internal tables, processing it can be very runtime-intensive, since
the tables have to be processed individually. Furthermore, it requires a lot of storage space,
since internal tables are not stored in compressed form. The system may even need to store the
dataset outside of its working memory. This means that processing it takes even longer.
An example of nested internal table:
Assume the following program is linked to the logical database [Page 1163] F1S.
REPORT DEMO.
DATA: SUM TYPE I, CNT TYPE I.
NODES: SPFLI, SFLIGHT, SBOOK.
DATA: BEGIN OF WA_SBOOK,
BOOKID TYPE SBOOK-BOOKID,
SMOKER TYPE SBOOK-SMOKER,
CLASS TYPE SBOOK-CLASS,
LUGGWEIGHT TYPE SBOOK-LUGGWEIGHT,
WUNIT TYPE SBOOK-WUNIT,
END OF WA_SBOOK.
DATA: BEGIN OF WA_SFLIGHT,
FLDATE TYPE SFLIGHT-FLDATE,
SBOOK LIKE TABLE OF WA_SBOOK,
END OF WA_SFLIGHT.
DATA: BEGIN OF WA_SPFLI,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
CITYFROM TYPE SPFLI-CITYFROM,
CITYTO TYPE SPFLI-CITYTO,
SFLIGHT LIKE TABLE OF WA_SFLIGHT,
END OF WA_SPFLI.
DATA TAB_SPFLI LIKE TABLE OF WA_SPFLI.
START-OF-SELECTION.
GET SPFLI.
REFRESH WA_SPFLI-SFLIGHT.
GET SFLIGHT.
REFRESH WA_SFLIGHT-SBOOK.
GET SBOOK.
MOVE-CORRESPONDING SBOOK TO WA_SBOOK.
APPEND WA_SBOOK TO WA_SFLIGHT-SBOOK.
GET SFLIGHT LATE.
MOVE-CORRESPONDING SFLIGHT TO WA_SFLIGHT.
APPEND WA_SFLIGHT TO WA_SPFLI-SFLIGHT.
GET SPFLI LATE.
MOVE-CORRESPONDING SPFLI TO WA_SPFLI.
APPEND WA_SPFLI TO TAB_SPFLI.
END-OF-SELECTION.
SORT TAB_SPFLI BY CITYFROM CITYTO CONNID.
LOOP AT TAB_SPFLI INTO WA_SPFLI.
SKIP.
WRITE: / WA_SPFLI-CARRID,
WA_SPFLI-CONNID,
'from', (15) WA_SPFLI-CITYFROM,
'to', (15) WA_SPFLI-CITYTO.
ULINE.
SORT WA_SPFLI-SFLIGHT BY FLDATE.
LOOP AT WA_SPFLI-SFLIGHT INTO WA_SFLIGHT.
SKIP.
WRITE: / 'Date:', WA_SFLIGHT-FLDATE.
WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.
ULINE.
SORT WA_SFLIGHT-SBOOK BY CLASS SMOKER BOOKID.
SUM = 0.
CNT = 0.
LOOP AT WA_SFLIGHT-SBOOK INTO WA_SBOOK.
WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',
WA_SBOOK-SMOKER UNDER 'Smoker',
WA_SBOOK-CLASS UNDER 'Class'.
SUM = SUM + WA_SBOOK-LUGGWEIGHT.
CNT = CNT + 1.
ENDLOOP.
ULINE.
WRITE: 'Number of bookings: ', (3) CNT,
/ 'Total luggage weight:',
(3) SUM, WA_SBOOK-WUNIT.
ENDLOOP.
ENDLOOP.
Thanks. -
Dynamic Work Area and field symbol
Hi All,
I'm have a big internal table like this
data: begin of data occurs 0,
Field01,
Field02,
Field03,
*bucket 1
Field04,
Field05,
Field06,
*bucket 2
Field04,
Field05,
Field06,
*bucket 3
Field04,
Field05,
Field06,
Field 1, 2 3 will be the same for pernr, first last name.
Field 4, 5, 6 are the same format but different numbers (or values ) in different buckets.
Each bucket can be shown (or not) based on the condition of a person, for example if that person live in 2 states, it will show 2 bucket with 2 address info inside each.
I will run this under get pernr to sort out each person who have many address or not.
Can I use dynamic work area and field symbol here? if I can, how?
Really appreciate your help with points...You can use the ASSIGN COMPONENT ... and than APPEND the work area to the table.
Check out this sample program:
REPORT ZTEST_NP.
DATA: BEGIN OF ITAB OCCURS 0,
F1 TYPE I,
F2 TYPE I,
F3 TYPE I,
END OF ITAB.
DATA: WA_ITAB LIKE ITAB.
DATA: L_CNT TYPE I.
FIELD-SYMBOLS: <F_FLD> TYPE ANY.
DO 10 TIMES. " I want 10 reocrds
CLEAR L_CNT.
DO 3 TIMES. " I have 3 fields
L_CNT = L_CNT + 1.
ASSIGN COMPONENT L_CNT OF STRUCTURE WA_ITAB TO <F_FLD>.
<F_FLD> = L_CNT.
ENDDO.
APPEND WA_ITAB TO ITAB.
CLEAR ITAB.
ENDDO.
LOOP AT ITAB INTO WA_ITAB.
WRITE: / WA_ITAB-F1,
WA_ITAB-F2,
WA_ITAB-F3.
ENDLOOP.
Regards,
Naimesh Patel -
SAP QUERY LOOPS AND INTERNAL TABLE
Hi All, I have a query which i have made. It runs from Table EKPO which has PO details and what I want to do is now via ABAP Code pull through the total of goods receipt for the PO and Line Item into a field. Sounds Easy enough..Problem now,
The table which contains the GR data is EKBE which agains a PO and Line Item can have many 101 movements and 102 movements so what I want is an ABAP Statent to basically sum up the total of 101 for the PO & LINE ITEMS and then minus this from the total of 102 for the PO & LINE ITEMS and post the result in to this new field I have created.
I am pretty decent with ABAP Code in Querys I.e Select statements etc but from what I can see i need to create an internal table and do a loop and collect statement but I keep on failing due to not enough knowledge. Please can some one help me with this and provide me with the code and explanation as i would like to understand,
POINTS WILL BE REWARDED
Thanks
Kind Regards
Adeel SarwarHi,
This is the full code i have entered but its not working. Any help would be appreciated. If you could rectify the code and internal tables that would be great.
Thanks
TABLES: EKBE.
DATA: PurO LIKE EKPO-EBELN,
POLI LIKE EKPO-EBELP.
*New Table and Vars defined
DATA: BEGIN OF IT_EKBE,
IT_EKBE LIKE EKBE,
END OF IT_EKBE.
DATA: BEGIN OF IT_SUM OCCURS 0,
EBELN TYPE EBELN,
EBELP TYPE EBELP,
DMBTR TYPE DMBTR,
MENGE TYPE MENGE,
END OF IT_SUM.
CLEAR: QTYD.
MOVE: EKPO-EBELN TO PurO,
EKPO-EBELP TO POLI.
SELECT * FROM EKBE INTO IT_EKBE
WHERE EBELN = PurO
AND EBELP = POLI
AND BEWTP = 'E'
LOOP AT IT_EKBE.
MOVE CORRESPOING IT_EKBE TO IT_SUM.
IF IT_EKBE-BWART = '102'.
IT_SUM-DMBTR = IT_SUM-DMBTR * -1.
IT_SUM-MENGE = IT_SUM-MENGE * -1.
ENIDF.
COLLECT IT_SUM.
CLEAR IT_SUM.
ENDLOOP.
ENDSELECT.
If sy-subrc = 0.
QTYD = IT_SUM.
ELSE.
QTYD = 0.
ENDIF. -
Export - Import In ABAP ( for variables and internal table)
how can we pass value for the variable and internal table using Export and Import?
data: var type sy-uzeit.
var = sy-uzeit.
EXPORT var TO MEMORY ID 'TIME'.
data: var type sy-uzeit.
IMPORT var FROM MEMORY ID 'TIME'.
write:/ var,sy-subrc,sy-uzeit.
i found var value 0 while importing.
what is the right syntax for passing value of variable and internaltable.
regards,
dushyant.Hi,
There are two possible solutions.
Solution1:
Program1.Should be run before atleast once so that TIME should be filled.
data: var type sy-uzeit.
var = sy-uzeit.
EXPORT var TO MEMORY ID 'TIME'.
Program2.IF the TIME is filled,then only it will produce the result.
data: var type sy-uzeit.
clear var.
IMPORT var FROM MEMORY ID 'TIME'.
write:/ var, sy-subrc, sy-uzeit.
Solution2:
Single program:
data: var type sy-uzeit.
var = sy-uzeit.
EXPORT var TO MEMORY ID 'TIME'.
clear var.
IMPORT var FROM MEMORY ID 'TIME'.
write:/ var, sy-subrc, sy-uzeit.
Kindly reward points by clikcing the star on the left of reply,if it helps.
Maybe you are looking for
-
Yosemite starts on Safe Mode only (iMac 2009)
Hello Everybody, I have installed Yosemite on my iMac 2009 and after the reboot the system starts in safe mode only. Does anyone have an idea how I can fix this? Here the log: 12/23/14 8:51:47.000 AM syslogd[17]: Configuration Notice: ASL Module "com
-
Is there anyway to reverse or go back to the previous update, I've update from 1.0.1 to 1.0.2 and my Nano has now frozen, have reset - put it into disk mode, and reinstalled software update BUT with posts on here its clear there is a major problem wi
-
Regarding Deletion or Archiving the Data based on Account Group
Hi All, How to find the solution for Deletion or archiving the vendors in different SAP servers which is haviing account group. And tell me what is use for SARA Tcode? Please send documents or links.. Can anyone help us ....its Urgent..... Thanks, Ra
-
Virus Barrier X4 question and a Top 10 Network/Security question
I am currently running Norton AV/Mac. It runs fine, no problems, no slow down, am happy! However, I know that there are some very experienced Mac users who are very down on Norton AV as far as causing problems/hogging resources/slowing things down...
-
Pages will not load on my 2012 macbook pro
I just had my hard drive replaced and I used a time capsule to re-upload all of my information. The application won't even open a new blank document, so I'm guessing that the application is corrupt. I'm running Yosemite 10.10.1-Please help!