Add field in an internal table
Hi There,
How to add a field in an internal table created at the runtime using
CREATE DATA D1 TYPE TABLE OF (VAR).
where say var contains name of a DDIC table.
Rgds,
deb.
after creating internal table use the method for creation of dynamic table and try , i am not sure
DATA: LineType TYPE string,
ItabRef TYPE REF TO DATA.
FIELD-SYMBOLS: TYPE STANDARD TABLE.
LineType = 'SFLIGHT'.
" Create internal table and attach a field-symbol
CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).
ASSIGN ItabRef->* TO .
<b>after this check this and try</b>
******DATA DECLARATION*****************************
FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,
<wa_final> TYPE ANY,
<w_field> TYPE ANY.
***DYNAMIC CREATION OF FIELDCATALOG****************
*FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
*LIKEWISE DYNAMIC FIELDCATALOG IS CREATED
wa_fieldcatalog-fieldname = 'FIELD1'.
wa_fieldcatalog-ref_table = 'E070'.
wa_fieldcatalog-outputlen = '13'.
wa_fieldcatalog-reptext = 'Created On'.
wa_fieldcatalog-seltext = 'Created On'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'FIELD1'.
wa_fieldcatalog-ref_table = 'E070'.
wa_fieldcatalog-outputlen = '13'.
wa_fieldcatalog-reptext = 'Created On'.
wa_fieldcatalog-seltext = 'Created On'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
LOOP AT it_mandt WHERE mandt IN s_mandt.
CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
wa_fieldcatalog-inttype = 'NUMC'.
wa_fieldcatalog-outputlen = '14'.
wa_fieldcatalog-reptext = it_mandt.
wa_fieldcatalog-seltext = it_mandt.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR :wa_fieldcatalog ,it_mandt.
ENDLOOP.
********CREATE DYNAMIC TABLE************************
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = new_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ASSIGN new_table->* TO <it_final>.
*********CREATE WORK AREA****************************
CREATE DATA new_line LIKE LINE OF <it_final>.
ASSIGN new_line->* TO <wa_final>.
*********INSERTTING WORK AREAR TO INTERNAL TABLE******
INSERT <wa_final> INTO TABLE <it_final>.
*******POPULATING DATA*******************************
LOOP.
ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.
<w_field> = '12345'.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.
<w_field> = '21453DD'.
FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.
ENDLOOP.
ENDLOOP.
Similar Messages
-
I need to add check whether 21 fields of a internal table are empty or not.
Hello,
I need to add check whether 21 fields of a internal table are empty or not.How can we write a code for the same wand what would be the correct syntax for it.
I tried entering all the fields in the IF loop with AND condition but its giving syntax error.Perhaps this is because the lenght of the IF condition would be more than the allowed one.Hi,
After the select quiery.
If not itab is initial.
Message 'Table is not empty' type 'I'.
Endif.
Regards,
Jagadish. -
How to add new field into dynamic internal table
Hello Expert.
how to add new field into dynamic internal table.
PARAMETERS: P_TABLE(30). "table name
DATA: I_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <TAB> TYPE standard TABLE.
*Create dynamic FS
create DATA I_TAB TYPE TABLE OF (p_table).
ASSIGN I_TAB->* TO <TAB>.
SELECT * FROM (p_table) INTO TABLE <TAB>.
here i want to add one more field into <TAB> at LAST position and my
Field name = field_stype and
Field type = 'LVC_T_STYL'
could you please helpme out .Hi,
Please find the code below.You can add the field acc to your requirement.
Creating Dynamic internal table
TYPE-POOLS: slis.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name
<fs_dyntable>, u201C Field symbol to create work area
<fs_fldval> type any. u201C Field symbol to assign values
PARAMETERS: p_cols(5) TYPE c. u201C Input number of columns
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_fldcat TYPE slis_t_fldcat_alv,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat,
wa_colno(2) TYPE n,
wa_flname(5) TYPE c.
Create fields .
DO p_cols TIMES.
CLEAR wa_it_fldcat.
move sy-index to wa_colno.
concatenate 'COL'
wa_colno
into wa_flname.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
ENDDO.
Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
Populating Dynamic internal table
DATA: fieldname(20) TYPE c.
DATA: fieldvalue(10) TYPE c.
DATA: index(3) TYPE c.
DO p_cols TIMES.
index = sy-index.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
Set up fieldvalue
CONCATENATE 'VALUE' index INTO
fieldvalue.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
ENDDO.
Append to the dynamic internal table
APPEND <fs_dyntable> TO <t_dyntable>.
Displaying dynamic internal table using Grid.
DATA: wa_cat LIKE LINE OF fs_fldcat.
DO p_cols TIMES.
CLEAR wa_cat.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
wa_cat-fieldname = wa_flname.
wa_cat-seltext_s = wa_flname.
wa_cat-outputlen = '10'.
APPEND wa_cat TO fs_fldcat.
ENDDO.
Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fs_fldcat
TABLES
t_outtab = <t_dyntable>. -
Aggregate a numeric field in an internal table
Hi All,
I have a small requirement in ABAP it goes in this fashion
I need to aggregate a numeric field in an internal table, the table is as follows
FLD1 FLD2 NUM1 FLD3
123A B1 10 C1
123A B1 25 C1
123B B1 20 C2
123C B2 10 C3
Note: FLD1, FLD2, FLD3 are of type numeric characters and NUM1 is of type number or integer
I want the result to be as follows
FLD1 FLD2 NUM1 FLD3
123A B1 35 C1
123B B1 20 C2
123C B2 10 C3
i.e. values in field NUM1 should get add up when the values in all other fields are same
I am not able to use _collect_ for this as the fields contain numeric characters.
Regards and Thanks,
AntonyHi Antony
collect here works like this:-
use at new field
sum
end at.
Pls reward points if it wil be helpful.
Regards
Depanker -
Mapping corresponding field in the internal table
Hi guys I need help with putting XML value into the appropriate fields in the internal table struc. I attempted to use if else condition to map the element name (cname)over to the fields but those internal table within an internal table post an issue of when to append and so on ... I am using FM SMUM_XML_PARSE and the output in to this table type smum_xmltb (containing all the XML Element and Values) I want to map it to its corresponding field in the internal table (defined below)
Pls pardon this newbie here as this is very new to me. Hope to hear fr u all soon and points will be given! ")
XML->>
<?xml version="1.0" encoding="iso-8859-1"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<BOOKLIST>
<DATE>2006-09-25</DATE>
<TIME>16:27:20</TIME>
<BOOK_RECORD>
<BOOK_NUM>0012345678</BOOK_NUM>
<SHORT_DESC>OMS BOOK</SHORT_DESC>
<BOOK_GROUP>
<BOOK_CATEGORY>
<CATEGORY_ID>03</CATEGORY_ID>
<CATEGORY_DESC>BOOK group 3</CATEGORY_DESC>
</BOOK_CATEGORY>
<BOOK_CATEGORY>
<CATEGORY_ID>02</CATEGORY_ID>
<CATEGORY_DESC>BOOK group 2</CATEGORY_DESC>
</BOOK_CATEGORY>
</BOOK_GROUP>
</BOOK_RECORD>
<BOOK_RECORD>
<BOOK_NUM>0012345679</BOOK_NUM>
<SHORT_DESC>SAP BOOK</SHORT_DESC>
<BOOK_GROUP>
<BOOK_CATEGORY>
<CATEGORY_ID>01</CATEGORY_ID>
<CATEGORY_DESC>BOOK group 1</CATEGORY_DESC>
</BOOK_CATEGORY>
<BOOK_CATEGORY>
<CATEGORY_ID>09</CATEGORY_ID>
<CATEGORY_DESC>BOOK group 9</CATEGORY_DESC>
</BOOK_CATEGORY>
</BOOK_GROUP>
</BOOK_RECORD>
</BOOKLIST>
</asx:values>
</asx:abap>
INTERNAL TABLE ->>
TYPES: BEGIN OF ADD_CATEGORY,
CATEGORY_ID(10),
CATEGORY_DESC(40),
END OF ADD_CATEGORY,
ADD_T_CATEGORY TYPE ADD_CATEGORY OCCURS 0.
TYPES: BEGIN OF ADD_BOOK_GRP,
BOOK_CATEGORY TYPE ADD_T_CATEGORY,
END OF ADD_BOOK_GRP,
ADD_T_BOOK_GRP TYPE ADD_BOOK_GRP OCCURS 0.
TYPES: BEGIN OF ADD_BOOK,
BOOK_NUM(10) TYPE C,
SHORT_DESC(40) TYPE C,
BOOK_GROUP TYPE ADD_T_BOOK_GRP,
END OF ADD_BOOK,
ADD_T_BOOK TYPE ADD_BOOK OCCURS 0.
TYPES: BEGIN OF TYPE_DATA,
DATE TYPE SY-DATUM,
TIME TYPE SY-TIMLO,
BOOK_RECORD TYPE ADD_T_BOOK,
END OF TYPE_DATA.
DATA: I_DATA TYPE TYPE_DATA OCCURS 0 WITH HEADER LINE.hi,
here is the code sample using ixml library .
just create a report program and copy paste the following code.
REPORT y_test_xml.
DATA: l_ixml TYPE REF TO if_ixml,
l_ixml_sf TYPE REF TO if_ixml_stream_factory,
l_istream TYPE REF TO if_ixml_istream,
l_ostream TYPE REF TO if_ixml_ostream,
l_booklist TYPE REF TO if_ixml_element,
l_document TYPE REF TO if_ixml_document,
l_parser TYPE REF TO if_ixml_parser,
l_root_element TYPE REF TO if_ixml_element,
l_book_record TYPE REF TO if_ixml_element,
l_date TYPE REF TO if_ixml_element ,
l_time TYPE REF TO if_ixml_element ,
l_book_group TYPE REF TO if_ixml_element,
l_book_cat TYPE REF TO if_ixml_element ,
others TYPE REF TO if_ixml_element ,
link TYPE REF TO if_ixml_element ,
description TYPE REF TO if_ixml_element ,
xml TYPE xstring ,
size TYPE i ,
l_xml TYPE REF TO cl_xml_document .
DATA: xml_out TYPE string ,
temp_string TYPE string .
TYPES: BEGIN OF add_category,
category_id(10),
category_desc(40),
END OF add_category,
add_t_category TYPE add_category OCCURS 0 .
TYPES: BEGIN OF add_book_grp,
book_category TYPE add_t_category,
END OF add_book_grp,
add_t_book_grp TYPE add_book_grp OCCURS 0.
TYPES: BEGIN OF add_book,
book_num(10) TYPE c,
short_desc(40) TYPE c,
book_group TYPE add_t_book_grp,
END OF add_book,
add_t_book TYPE add_book OCCURS 0.
TYPES: BEGIN OF type_data,
date TYPE sy-datum,
time TYPE sy-uzeit,
book_record TYPE add_t_book,
END OF type_data.
DATA: i_data TYPE type_data OCCURS 0 WITH HEADER LINE.
DATA: itab LIKE soli OCCURS 0 WITH HEADER LINE.
DATA: cat_wa TYPE add_category ,
bk_gp_wa TYPE add_book_grp ,
bk_rec_wa TYPE add_book ,
bk_wa LIKE LINE OF i_data .
DATA: cat_tab TYPE STANDARD TABLE OF add_category ,
bk_gp_tab TYPE STANDARD TABLE OF add_book_grp ,
bk_rec_tab TYPE STANDARD TABLE OF add_book .
MOVE: '03' TO cat_wa-category_id ,
' BK GP 3' TO cat_wa-category_desc .
APPEND cat_wa TO cat_tab .
MOVE: '02' TO cat_wa-category_id ,
' BK GP 2' TO cat_wa-category_desc .
APPEND cat_wa TO cat_tab .
bk_gp_wa-book_category = cat_tab.
APPEND bk_gp_wa TO bk_gp_tab .
MOVE: '0012345678' TO bk_rec_wa-book_num ,
'OMS book' TO bk_rec_wa-short_desc .
bk_rec_wa-book_group = bk_gp_tab .
APPEND bk_rec_wa TO bk_rec_tab .
CLEAR:bk_gp_tab, cat_tab .
REFRESH :bk_gp_tab, cat_tab .
MOVE: '01' TO cat_wa-category_id ,
' BK GP 1' TO cat_wa-category_desc .
APPEND cat_wa TO cat_tab .
MOVE: '09' TO cat_wa-category_id ,
' BK GP 9' TO cat_wa-category_desc .
APPEND cat_wa TO cat_tab .
bk_gp_wa-book_category = cat_tab.
APPEND bk_gp_wa TO bk_gp_tab .
MOVE: '00123456789' TO bk_rec_wa-book_num ,
'SAP book' TO bk_rec_wa-short_desc .
bk_rec_wa-book_group = bk_gp_tab .
APPEND bk_rec_wa TO bk_rec_tab .
MOVE: sy-datum TO bk_wa-date ,
sy-uzeit TO bk_wa-time .
bk_wa-book_record = bk_rec_tab .
APPEND bk_wa TO i_data .
CLEAR: cat_wa , bk_gp_wa ,bk_rec_wa , bk_wa .
l_ixml = cl_ixml=>create( ).
l_ixml_sf = l_ixml->create_stream_factory( ).
l_document = l_ixml->create_document( ).
l_root_element = l_document->create_element( name = 'asx:abap' ).
l_root_element->set_attribute( name = 'xmlns:asx' value = 'http://www.sap.com/abapxml' ) .
l_root_element->set_attribute( name = 'version' value = '1.0' ).
l_document->append_child( new_child = l_root_element ).
others = l_document->create_simple_element( parent = l_root_element name = 'asx:values' ).
l_booklist = l_document->create_simple_element( parent = others name = 'BOOKLIST' ).
LOOP AT i_data INTO bk_wa .
CLEAR temp_string .
MOVE: bk_wa-date TO temp_string .
l_date = l_document->create_simple_element( parent = l_booklist name = 'DATE' value = temp_string ).
CLEAR temp_string .
MOVE: bk_wa-time TO temp_string .
l_time = l_document->create_simple_element( parent = l_booklist name = 'TIME' value = temp_string ).
LOOP AT bk_wa-book_record INTO bk_rec_wa .
l_book_record = l_document->create_simple_element( parent = l_booklist name = 'BOOK_RECORD' ) .
CLEAR temp_string .
MOVE: bk_rec_wa-book_num TO temp_string .
l_date = l_document->create_simple_element( parent = l_book_record name = 'BOOK_NUM' value = temp_string ).
CLEAR temp_string .
MOVE: bk_rec_wa-short_desc TO temp_string .
l_time = l_document->create_simple_element( parent = l_book_record name = 'SHORT_DESC' value = temp_string ).
l_book_group = l_document->create_simple_element( parent = l_book_record name = 'BOOK_GROUP' ).
LOOP AT bk_rec_wa-book_group INTO bk_gp_wa .
LOOP AT bk_gp_wa-book_category INTO cat_wa .
l_book_cat = l_document->create_simple_element( parent = l_book_group name = 'BOOK_CATEGORY' ).
CLEAR temp_string .
MOVE: cat_wa-category_id TO temp_string .
l_date = l_document->create_simple_element( parent = l_book_cat name = 'CATEGORY_ID' value = temp_string ).
CLEAR temp_string .
MOVE: cat_wa-category_desc TO temp_string .
l_time = l_document->create_simple_element( parent = l_book_cat name = 'CATEGORY_DESC' value = temp_string ).
ENDLOOP .
ENDLOOP .
ENDLOOP .
ENDLOOP .
l_ostream = l_ixml_sf->create_ostream_xstring( xml ).
l_document->render( ostream = l_ostream ).
CREATE OBJECT l_xml.
CALL METHOD l_xml->parse_xstring
EXPORTING
stream = xml.
l_xml->render_2_string(
EXPORTING
pretty_print = 'X'
IMPORTING
RETCODE = RETCODE
stream = xml_out
size = size
CALL METHOD l_xml->display.
to read the xml data to abap itab you could parse node by node or write a XSLT to map it to your itab or use the following method. (add the following code to the earlier program)
data: result_xml type standard table of smum_xmltb .
data: return type standard table of bapiret2 .
after the statement
l_document->render( ostream = l_ostream ).
add
converting xml to itab
call function 'SMUM_XML_PARSE'
exporting
xml_input = xml
tables
xml_table = result_xml
return = return .
now check the result_xml itab.
rgds
anver -
Colour to field in an internal table
how to colour a particular data in a particular field of an internal table.
See this
1. add one more field to ur final internal table say COLOR(4)
2. in layout wa_layout-style_fname = 'COLOR'. " if its grid
wa_layout-style_fieldname = 'COLOR'. "if its list
3. read table itab index 3.
itab-color = 'C410'.
modify itab index 3
4. see program SHOWCOLO for all color codes
1. Add a field of data type CHAR(3) to the internal output table.
2. Enter the color code in the appropriate field of the row to be colored in the internal
output table:
Code: 'Cxy'
C = Color (all codes begin with 'C')
x = color number ('1' - '9')
y = highlight ('0' = off, '1' = on)
3. Assign the internal output table color code field name to the IS_LAYOUT importing
structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call
interface.
To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, lets modify declaration of our list data table gt_list.
you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field INFO_FNAME of the layout structure.
e.g.
ps_layout-info_fname = <field_name_containing_color_codes>. e.g. ROWCOLOR
You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.
You can color an entire row as described in the next section. However, this method is less time consuming.
Coloring Individual Cells
This is the last point about coloring procedures for the ALV Grid. The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by more is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.
The structure that should be included must be of type LVC_T_SCOL. If you want to color the entire row, this inner table should contain only one row with field fname is set to space, some color value at field col, 0 or 1 at fields int (intensified) and inv (inverse).
If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field fname. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.
If it is in ALv refer the following code:
*& Report ZDEMO_ALVGRID *
*& Example of a simple ALV Grid Report *
*& The basic ALV grid, Enhanced to display each row in a different *
*& colour *
REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) type c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
form build_fieldcatalog.
There are a number of ways to create a fieldcat.
For the purpose of this example i will build the fieldcatalog manualy
by populating the internal table fields individually and then
appending the rows. This method can be the most time consuming but can
also allow you more control of the final product.
Beware though, you need to ensure that all fields required are
populated. When using some of functionality available via ALV, such as
total. You may need to provide more information than if you were
simply displaying the result
I.e. Field type may be required in-order for
the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
Build layout for ALV grid report
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname = 'LINE_COLOR'.
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
Display report using ALV grid
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
form data_retrieval.
data: ld_color(1) type c.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
Populate color variable with colour properties
Char 1 = C (This is a color property)
Char 2 = 3 (Color codes: 1 - 7)
Char 3 = Intensified on/off ( 1 or 0 )
Char 4 = Inverse display on/off ( 1 or 0 )
i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
wa_ekko-line_color = 'C410'.
modify it_ekko from wa_ekko.
endloop.
endform. " DATA_RETRIEVAL
Please give me reward points... -
Extract a value of a fields from an internal table
hello everyone,
i need to extract a value of a fields from an internal table, the fields is in a postion "sy-tabix" that i know, so i need to pick this value without using a loop
thank you.Like this?
DATA: FIELD1 TYPE C,
FIELD2 TYPE C.
READ TABLE T_TAB INDEX 3.
FIELD1 = T_TAB-FIELD1.
FIELD2 = T_TAB-FIELD2.
Greetings,
Blag. -
Field catalog for internal table in ALV
In my program the internal table consists many fields from various tables and structure doesn't belong to a single data table.
In order to get output in ALV grid following FM has been used
REUSE_ALV_GRID_DISPLAY
for field catalog the fields are defined specifically.
l_fieldcat-fieldname = 'VBELN'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Billing doc'.
l_fieldcat-no_zero = 'X'.
l_fieldcat-hotspot = 'X'.
append l_fieldcat to p_fieldtab.
..............and so on for all the fields.
Just wanted to know is there any other method to display all the fields of this internal table automatically so each field is not specified specifically.
anyaHi
Try this instead:
*& Form create_fieldcatalog
* Create a field catalogue from any internal table
* -->PT_TABLE Internal table
* -->PT_FIELDCAT Field Catalogue
FORM create_fieldcatalog
USING pt_table TYPE ANY TABLE
CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA:
lr_tabdescr TYPE REF TO cl_abap_structdescr
, lr_data TYPE REF TO data
, lt_dfies TYPE ddfields
, ls_dfies TYPE dfies
, ls_fieldcat TYPE lvc_s_fcat
CLEAR pt_fieldcat.
CREATE DATA lr_data LIKE LINE OF pt_table.
lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).
lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
LOOP AT lt_dfies
INTO ls_dfies.
CLEAR ls_fieldcat.
MOVE-CORRESPONDING ls_dfies TO ls_fieldcat.
APPEND ls_fieldcat TO pt_fieldcat.
ENDLOOP.
ENDFORM. "create_fieldcatalog -
How to find number of fields in an internal table ?
my requirement is i have 20 internal tables and the data is being uploaded into an application server. so how to find no of fields in a particular internal tableconcatenate all the fields and move them to final internal table , call the function module "GET_COMPONENT_LIST" and pass the work area of the final internal table in the parameter fieldname
***For getting no of FIELDS in an internal table ********
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = syrepid
FIELDNAME = 't_payr'
TABLES
COMPONENTS = fieldlist.
describe table fieldlist lines pyr_no_fields.
********end of getting no of fields**********
TRANSFER wa_mat_out_head TO P_FNAME.
LOOP AT GT_PAYR.
MOVE: GT_payr-LIFNR TO T_payr-lifnr,
GT_payr-ZBUKR TO T_payr-zbukr,
GT_payr-LAUFD TO T_payr-LAUFD,
GT_payr-CHECT TO T_payr-CHECT,
GT_payr-RWBTR TO T_payr-RWBTR.
Concatenate T_payr-lifnr t_payr-zbukr T_payr-laufd T_payr-chect
T_payr-rwbtr into wa_mat_out-rec SEPARATED by ',' . -
Changing the order of fields in an internal table
Hi all,
I'm using field symbol as internal table. this table has got a standard database structure.
I want to make the 3rd column of this internal table as 1st colums keeping rest of the columns as it is.
Is there any way to do this?
Thanks,
Anil.Hi
Instead of directly taking the type as a standard structure , declare the FS internal table as type of types structure.
Data: fs_scarr like type_s_scarr.
FIELD-SYMBOLS <scarr2> TYPE fs_scarr
In the types put the third column as first one and use into corresponding in select query
or else
while displaying the internal table change the order of the columns
Loop at itab into fs_itab.
write : col3
col2
col4
endloop.
Thanks,
Viquar Iqbal -
First occurence of a value from a field in the internal table.
How to select the first occurence of a value from a field in an internal table ?
I don think , we can use select query .
Any suggestions?
provide syntaxs also .Hi...
You have to use this code.
DATA : Begin of IT_MARA occurs 0,
mtart type mara-mtart,
matnr type mara-matnr,
meins type mara-meins,
END OF IT_MARA.
START-of-SELECTION.
SELECT MTART MATNR MEINS FROM MARA INTO TABLE IT_MARA.
END-OF-SELECTION.
LOOP AT IT_MARA.
<b> AT NEW MTART. "This will trigger for every first/new value of the field
<<<<WRITE YOUR CODE here>>
ENDAT.</b>
ENDLOOP.
You can also use.
LOOP AT IT_MARA.
<b> <b> ON CHANGE OF IT_MARA-TART.
<<<<WRITE YOUR CODE here>>
ENDON.</b></b>
ENDLOOP.
<b>Reward if Helpful.</b> -
Coloring a field in the internal table
Hi all,
How can I color a field in the internal table knowing that I'm developing a classic report.
Thanks in advance.hi,,,
check this code.
*-----TABLES DECLARATION
tables : kna1, "Customer Master
vbak, "Sales Document Header
vbap, "Sales Document Item
sscrfields. "Screen Field Table
& D A T A D E C L A R A T I O N &
data : begin of it_kna1 occurs 0,
kunnr type kna1-kunnr, "Customer Number
land1 type kna1-land1, "Country Key
name1 type kna1-name1, "Name
ort01 type kna1-ort01, "City
end of it_kna1.
data : begin of it_kna2 occurs 0,
kunnr type kna1-kunnr, "Customer Number
land1 type kna1-land1, "Country Key
name1 type kna1-name1, "Name
ort01 type kna1-ort01, "City
end of it_kna2.
data: begin of it_vbak occurs 0,
vbeln type vbak-vbeln, "Sales Document
erdat type vbak-erdat, "Date
ernam type vbak-ernam, "Name of Person
auart type vbak-auart, "Sales Document Type
end of it_vbak.
data: begin of it_vbap occurs 0,
vbeln type vbap-vbeln, "Sales Document
posnr type vbap-posnr, "Sales Document Item
matnr type vbap-matnr, "Material Number
matkl type vbap-matkl, "Material group
end of it_vbap.
data: v_count type int4, "Current Row Index
v_line like sy-lisel, "Contents of selected line
v_kunnr like kna1-kunnr.
& S E L E C T I O N S C R E E N &
selection-screen begin of block b1 with frame title text-001.
selection-screen begin of line.
parameters : rb1 radiobutton group g1 default 'X'.
selection-screen comment 5(20) text-002 for field rb1.
selection-screen end of line.
select-options : so_kunnr for kna1-kunnr obligatory.
parameters : p_hits(3) type c.
selection-screen begin of line.
parameters : rb2 radiobutton group g1.
selection-screen comment 5(20) text-003 for field rb2.
selection-screen end of line.
parameters : p_file like rlgrap-filename default 'c:\test'.
selection-screen pushbutton /33(10) custl user-command push1.
selection-screen pushbutton 58(10) custd user-command push2.
selection-screen end of block b1.
& I N I T I A L I Z A T I O N &
initialization.
move 'LOAD' to custl.
move 'DISP' to custd.
& A T L I N E S E L E C T I O N &
at selection-screen.
perform validate_kunnr.
& A T S E L E C T I O N S C R E E N O N V A L U E-R E Q U E S T &
at selection-screen on value-request for p_file.
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
importing
file_name = p_file.
& S T A R T O F S E L E C T I O N &
start-of-selection.
perform cust_details.
& S T A R T O F S E L E C T I O N &
top-of-page.
format color 3 intensified off.
write :/02(25) sy-repid.
write : 39(15) 'Page'(010), sy-pagno.
format color off.
format color 6 intensified off.
format color col_heading.
uline at :/1(60).
write: /1 sy-vline,
2 'Cust Number'(000),
14 sy-vline,
16 'Country'(007),
25 sy-vline,
26 'City'(008),
42 sy-vline,
43 'Region'(009),
60 sy-vline.
uline at :/1(60).
format color col_heading off.
& T O P O F P A G E D U R I N G L I N E S E L E C T I O N &
top-of-page during line-selection.
if sy-lsind eq 1 or sy-ucomm eq 'VBAK'.
format color col_heading.
uline at :/1(60).
write : /1 sy-vline,
2 'Docu No.'(011),
14 sy-vline,
16 'Date'(012),
26 sy-vline,
27 'Name'(013),
42 sy-vline,
43 'DType'(014),
60 sy-vline.
uline at :/1(60).
elseif sy-lsind eq 2 or sy-ucomm eq 'VBAK'.
set pf-status space.
uline at :/1(60).
write : /1 sy-vline,
2 'Docu No.'(015),
14 sy-vline,
16 'Sales Item'(016),
25 sy-vline,
26 'Mat No'(017),
42 sy-vline,
43 vbap-matkl,
50 'Mat Grp'(018),
60 sy-vline.
uline at :/1(60).
endif.
& AT USER-COMMAND &
at user-command.
case sy-ucomm.
when 'VBAK'.
perform sales_item.
when 'DELIVERY'.
clear it_vbak-vbeln.
get cursor value it_vbak-vbeln.
set parameter id 'AUN' field it_vbak-vbeln.
call transaction 'VA03' and skip first screen.
when 'DISP'.
perform display_basic.
endcase.
& AT LINE SELECTION &
at line-selection.
if sy-lsind = 1.
set pf-status 'DDDD'.
perform sales_header.
elseif sy-lsind = 2.
case sy-ucomm.
when 'PICK'.
set pf-status space.
perform sales_item.
when 'DELIVERY'.
clear it_vbak-vbeln.
get cursor value it_vbak-vbeln.
set parameter id 'AUN' field it_vbak-vbeln.
call transaction 'VA03' and skip first screen.
when 'DISP'.
perform display_basic.
endcase.
PERFORM sales_item.
endif.
& AT USER-COMMAND &
at user-command.
case sy-ucomm.
when 'VBAK'.
perform sales_item.
when 'DELIVERY'.
clear it_vbak-vbeln.
get cursor value it_vbak-vbeln.
set parameter id 'AUN' field it_vbak-vbeln.
call transaction 'VA03' and skip first screen.
when 'DISP'.
perform display_basic.
endcase.
& Form CUST_DETAILS &
form cust_details .
select kunnr
land1
name1
ort01
from kna1
into table it_kna1
where kunnr in so_kunnr.
if sy-subrc <> 0.
message 'SELECT VALID CUST NO' type 'I'.
else.
loop at it_kna1.
v_count = v_count + 1.
if sy-tabix < p_hits.
IF v_count <= p_hits.
move it_kna1 to it_kna2.
append it_kna2.
else.
exit.
endif.
endloop.
endif.
if not it_kna2[] is initial.
loop at it_kna2.
write : /1 sy-vline,
2 it_kna2-kunnr,
14 sy-vline,
16 it_kna2-land1,
25 sy-vline,
26 it_kna2-name1,
42 sy-vline,
43 it_kna2-ort01,
60 sy-vline.
uline at :/1(60).
endloop.
endif.
endform. " CUST_DETAILS
**& Form load_file
*form load_file .
*endform. " load_file
**& Form disp_file
*form disp_file .
*endform. " disp_file
*& Form VALIDATE_KUNNR
form validate_kunnr .
select single kunnr
from kna1
into kna1
where kunnr = so_kunnr.
endform. " VALIDATE_KUNNR
*& Form SALES_HEADER
form sales_header .
data : v_kna1(13).
v_kna1 = 'IT_KNA2-KUNNR'.
*get cursor line sy-lilli value v_line
clear v_kunnr.
get cursor field v_kna1 value v_kunnr.
v_kunnr = v_line+1(10).
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = v_kunnr
importing
output = v_kunnr.
select vbeln
erdat
ernam
auart
from vbak
into table it_vbak
where kunnr = v_kunnr.
if sy-subrc = 0.
loop at it_vbak.
write : /1 sy-vline,
2 it_vbak-vbeln,
14 sy-vline,
16 it_vbak-erdat,
26 sy-vline,
27 it_vbak-ernam,
42 sy-vline,
43 it_vbak-auart,
60 sy-vline.
uline at :/1(60).
endloop.
endif.
endform. " SALES_HEADER
*& Form SALES_ITEM
form sales_item .
data : v_vbeln(13).
v_vbeln = 'IT_VBAK-VBELN'.
clear it_vbak-vbeln.
get cursor field v_vbeln value it_vbak-vbeln.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = it_vbak-vbeln
importing
output = it_vbak-vbeln.
select vbeln
posnr
matnr
matkl
from vbap
into table it_vbap
where vbeln = it_vbak-vbeln.
loop at it_vbap .
write : /1 sy-vline,
2 it_vbap-vbeln,
14 sy-vline,
16 it_vbap-posnr,
25 sy-vline,
26 it_vbap-matnr,
42 sy-vline,
43 it_vbap-matkl,
60 sy-vline.
uline at :/1(60).
endloop.
endform. " SALES_ITEM
*& Form DISP_DOCU
form display_basic .
loop at it_kna1 into it_kna1.
format hotspot on.
write : /03 it_kna1-kunnr,
24 it_kna1-name1.
hide it_kna1-kunnr.
endloop.
endform. " display_basic
pls reward if useful
regards,
rekha -
Field length in internal table
hi,
how to selt field length in internal table?.
i have created on report the report out puts down load to using download function .
the out format is:
op1 op2 op3 op4
1 3 4
i want
op1 op2 op3 op4
1 3 4
how to set this please give sample code.HI,
Give internal table like this.
DATA: BEGIN OF itab OCCURS 100,
op1(04),
op2(04),
op3(04),
op4(04),
END OF itab.
So it will allocate space between 1, 3 and 4.
Reward if it useful.
Thanks. -
Difference between the Field Group and Internal Table.
Hi all,
Can anybody tell me the difference between the Field group and Internal table and when they will used?
Thanks,
Sriram.Hi
Internal Tables: They are used to store record type data in tabular form temporarily in ABAP programming. Or we can say, it stores multiple lines of records for temporary use in ABAP programming.
A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.
Use
The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.
When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.
Regards
Ashish -
How to increase field size in Internal table
Hi friends,
I want to concatenate around 20 fields in one internal table field,
i declared the destination filed as character, now i am able to get around 12 to 13 fileds only , how to increase the length of this field to include all fields ?
or how can i do this ? can any body help me ?
I concatenate this to create a file which will be send as email attachment.
its very urgent issue, kindly help me to resolve as early as possible.
Thanks in advance.
JosephHi,
Use the string data type..
Example
DATA: IT_STRING TYPE STRING OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF WA,
MATNR(18),
WERKS(4),
VBELN(10),
END OF WA.
CONCATENATE WA-MATNR WA-WERKS WA-VBELN INTO IT_STRING.
APPEND IT_STRING.
Thanks,
Naren
Maybe you are looking for
-
Question 1: I am unable to load the Windows 8 Installation DVD in UEFI (only) mode on my T420s. As a result, I can only run the installer in Legacy mode (or both UEFI/Legacy which effectively means the same thing). This in turn means Windows 8 is ins
-
Incomplete Downloads over 750M cannot be resumed
This has been a problem since forever. I have successfully downloaded many many TV Shows and movies. However, sometimes I start downloading a TV Show, it gets interrupted. Many times this interrupted download has already downloaded 750M work of the T
-
Workflow keying off changes in the customer master
I have created a workflow that triggers off of changes to a particular field in the customer master. Everything works great.. However, users are requesting to see the old value as well as the newly changed value. The event container doesn't seem to
-
TS3276 all my apps load information slowly
can someone help me with my imac, running mountain lion, all seemed well after initial setupbut then all programs are slow to respond especially loading new information and even recieving mail takes forever. any suggestions? Ihave check all my incomi
-
Why is it taking so long to download OS X Mavericks
I started my download last night around 8:00 pm, this morning I woke up to find that I needed to power down and power on just to sign in. After signing in I noticed that the downloading of OS X Mavericks had paused close to the point it was when I we