Dynamically table read / write with field symbols
Hi,
I like to read dynamically from a table via field symbols. The reading part is working.
But now I like to do some changes on the entry and then write it to another table with a similar structure.
I use SAP 4.6c
There I have two problems:
1. At the statement I get a dump:
<l_sysid> = sy-sysid.
--> Field symbol has not yet been assigned.
I think that the problem is somewhere around
assign <table_to> to <wa_to>.
2. the data change inside the loop. There I like to add the sysid to the target-wa and then copy the source-wa it to the new target-wa to append it to the target table.
But this does not work. What kind of code do I need? The "move-correspondig" is not correct.
--> see code around
loop at <table_from> assigning <wa_from>.
Below you can find my code. The problem is within the last loop-statement.
FUNCTION Z_MIG_COPY_TABLE.
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(I_TABNAME_FROM) TYPE TABNAME
*" REFERENCE(I_TABNAME_TO) TYPE TABNAME
*" REFERENCE(I_KOMP_TRANS) LIKE ZS_KOMP_TRANS STRUCTURE
*" ZS_KOMP_TRANS OPTIONAL
*" TABLES
*" I_SELCON STRUCTURE ZS_SELCON
*" EXCEPTIONS
*" NOT_FOUND
*" OTHERS
* zeilenweiser Aufbau Tabelle I_SELCON z.B.:
* bukrs = 3011
* AND
* bstyp = 'F'
* I_KOMP_TRANS
* dient zur Uebersetzung von alt/neu, z.B. bei LIFNR
* der angegebene Funktionsbaustein wird genutzt,
* um den neuen Wert der übergebenen Komponente zu ermitteln
* Angabe z.B.:
* LIFNR
DATA: dref TYPE REF TO data,
dref_to TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat,
i_alv_cat_to TYPE TABLE OF lvc_s_fcat,
ls_alv_cat_to LIKE LINE OF i_alv_cat.
DATA: BEGIN OF itab OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab.
DATA: BEGIN OF itab_to OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab_to.
FIELD-SYMBOLS: <table_from> TYPE ANY TABLE.
FIELD-SYMBOLS: <table_to> TYPE Standard TABLE.
FIELD-SYMBOLS: <wa_from> TYPE ANY.
FIELD-SYMBOLS: <wa_to> TYPE ANY.
FIELD-SYMBOLS: <l_komp> TYPE ANY.
FIELD-SYMBOLS: <l_sysid> TYPE ANY.
Data: l_alt type ELIFN.
Data: l_neu type ELIFN.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_from
TABLES
DFIES_TAB = itab
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = i_tabname_from.
ls_alv_cat-ref_field = itab-fieldname.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = dref.
ASSIGN dref->* TO <table_from>.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_to
TABLES
DFIES_TAB = itab_to
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab_to.
ls_alv_cat_to-fieldname = itab_to-fieldname.
ls_alv_cat_to-ref_table = i_tabname_to.
ls_alv_cat_to-ref_field = itab_to-fieldname.
APPEND ls_alv_cat_to TO i_alv_cat_to.
ENDLOOP.
* break-point.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat_to
IMPORTING
ep_table = dref_to.
ASSIGN dref_to->* TO <table_to>.
*Select Ursprungstabelle mit Selektionsbedingungen
SELECT * FROM (i_tabname_from) up to 5 rows
INTO CORRESPONDING FIELDS OF TABLE <table_from>
where (i_selcon).
* break-point.
*Aufbau interne Tabelle mit eventuell geänderten Feldern
assign <table_to> to <wa_to>.
if not I_KOMP_TRANS is initial.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
* move-corresponding <wa_from> to <wa_to>.
append <wa_to> to <table_to>.
endloop.
* break-point.
*Speichern der ausgelesenen Daten in Zieltabelle
MODIFY (i_tabname_to) FROM TABLE <table_to>.
if sy-subrc <> 0.
MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Modify von Tabelle '&'.
endif.
else.
*Speichern der ausgelesenen Daten in Zieltabelle
MODIFY (i_tabname_to) FROM TABLE <table_from>.
if sy-subrc <> 0.
MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Modify von Tabelle '&'.
endif.
endif.
commit work.
if sy-subrc <> 0.
MESSAGE E002(ZMESSAGES) WITH i_tabname_to.
* Fehler beim Commit von Tabelle '&'.
endif.
* break-point.
ENDFUNCTION.
Thanks a lot for any hints.
Regards
Tom
Hi,
Answers below.
1) For this...you assigning an internal table to a work area...
assign <table_to> to <wa_to>.
This should solve the problem..
* Create the target work area..
DATA: new_line TYPE REF TO data.
CREATE DATA new_line LIKE LINE OF <table_to>.
ASSIGN new_line->* TO <wa_to>.
Now the target work area is created..
2) For the second one...
************New code
FIELD-SYMBOLS: <FS>,<FS1>.
************New code End.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
************New code
LOOP AT itab .
ASSIGN COMPONENT itab-fieldname of structure <WA_FROM> TO <FS>.
CHECK SY-SUBRC = 0.
ASSIGN COMPONENT itab-fieldname of structure <WA_TO> TO <FS1>.
CHECK SY-SUBRC = 0.
* Move from source to target.
<FS1> = <FS>.
ENDLOOP.
************New code End
append <wa_to> to <table_to>.
endloop.
Thanks
Naren
Similar Messages
-
Dynamic select with field symbols
Hi guys,
I have 2 tables.
First table is the popup fields using fm popup_get_values:
tab1-tabname
tab1-fieldname
tab1-value
Second table is the input fields to be displayed in the popup box:
tab2-transactno
tab2-docno
tab2-customer
tab2-postdate
etc... (it has many fields)
Let's say currently i loop at tab2 and assign each value of the individual fields to a variable each:
loop at tab2
v_transactno = tab2-transactno
v_docno = tab2-docno
etc...
endloop.
My question is how do i assign each variable to the popup fields according to the fieldname so that it can get its corresponding value correctly?
How can this be done dynamically?
Can the loop above be done dynamically as well coz it has alot of fields to cater for?
Please help me solve this problem. Futher similar examples would be much appreciated as well.
Thank you very much!Hi
see the concept of field sysmbols and do accordingly
Field Symbols
Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.
Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.
Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects.
All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.
You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.
Field symbols provide greater flexibility when you address data objects:
If you want to process sections of fields, you can specify the offset and length of the field dynamically.
You can assign one field symbol to another, which allows you to address parts of fields.
Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.
You can also force a field symbol to take different technical attributes from those of the field assigned to it.
The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.
While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.
For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.
check the below links u will get the answers for your questions
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
Syntax Diagram
FIELD-SYMBOLS
Basic form
FIELD-SYMBOLS <fs>.
Extras:
1. ... TYPE type
2. ... TYPE REF TO cif
3. ... TYPE REF TO DATA
4. ... TYPE LINE OF type
5. ... LIKE s
6. ... LIKE LINE OF s
7. ... TYPE tabkind
8. ... STRUCTURE s DEFAULT wa
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
Effect
This statement declares a symbolic field called <fs>. At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.
You can only use one of the additions.
Example
Output aircraft type from the table SFLIGHT using a field symbol:
FIELD-SYMBOLS <PT> TYPE ANY.
DATA SFLIGHT_WA TYPE SFLIGHT.
ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
WRITE <PT>.
Addition 1
... TYPE type
Addition 2
... TYPE REF TO cif
Addition 3
... TYPE REF TO DATA
Addition 4
... TYPE LINE OF type
Addition 5
... LIKE s
Addition 6
... LIKE LINE OF s
Addition 7
... TYPE tabkind
Effect
You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
Effect
Assigns any (internal) field string or structure to the field symbol from the ABAP Dictionary (s). All fields of the structure can be addressed by name: <fs>-fieldname. The structured field symbol points initially to the work area wa specified after DEFAULT.
The work area wa must be at least as long as the structure s. If s contains fields of the type I or F, wa should have the structure s or at least begin in that way, since otherwise alignment problems may occur.
Example
Address components of the flight bookings table SBOOK using a field symbol:
DATA SBOOK_WA LIKE SBOOK.
FIELD-SYMBOLS <SB> STRUCTURE SBOOK
DEFAULT SBOOK_WA.
WRITE: <SB>-BOOKID, <SB>-FLDATE.
Regards
Anji -
Assign Type conflict with field symbols
I have two tables tab1 & tab2, want to assign field values from tab1 to tab2 suing field symbols. Deatils are :
TYPES: BEGIN OF ty_tab1,
item1 TYPE char20,
item2 TYPE char20,
val1 type i,
val2 type i,
END OF ty_tab1,
BEGIN OF ty_tab2,
item1 TYPE char20,
item2 TYPE char20,
END OF ty_tab2.
DATA: it_tab1 TYPE TABLE OF ty_tab1,
it_tab2 TYPE TABLE OF ty_tab2.
FIELD-SYMBOLS <fs_tab1> TYPE ty_tab1.
<fs_tab2t> type ty_tab2.
LOOP AT it_tab1 assigning <fs_tab1>.
READ TABLE it_tab2 assigning <fs_tab2> WITH KEY item1 = <fs_tab1>-item1
item2 = <fs_tab1>-item2.
IF sy-subrc EQ 0.
ASSIGN COMPONENT 'ITEM1' OF STRUCTURE <fs_tab1> TO <fs_tab2>.
ASSIGN COMPONENT 'ITEM2' OF STRUCTURE <fs_tab1> TO <fs_tab2>.
endif.
endloop.
Getting error msg
You attempted to assign a field to a typed field symbol, but the field does not have the required type.
whats the reason of error.
Edited by: Matt on May 27, 2011 8:59 AM - added tagsTaken from example dump
A new value is to be assigned to the field "...", although this field is
entirely or partly protected against changes.
The following are protected against changes:
- Character literals or numeric literals
- Constants (CONSTANTS)
- Parameters of the category IMPORTING REFERENCE for functions and
methods
- Untyped field symbols not yet assigned a field using ASSIGN
- TABLES parameters if the actual parameter is protected against changes
- USING reference parameters and CHANGING parameters for FORMs, if the
actual parameter is protected against changes and
- Accesses using field symbols if the field assigned using ASSIGN is
protected (or partially protected, e.g. key components of an internal
table with the type SORTED or HASHED TABLE) against changes
- Accesses using references, if the field bound to the reference is
protected (or partially protected) against changes
- External write accesses to READ-ONLY attributes,
- Content of a shared object area instance accessed using a shared lock
(ATTACH_FOR_READ).
You likely fall in one of these cases. Check each and if still unsure please share your code so we can reproduce the error.
Regards
Marcin -
FOR ALL ENTRIES... with FIELD SYMBOL
Is it possible to use FOR ALL ENTRIES with a FIELD-SYMBOL that points to a data reference of type STANDARD TABLE ?
I have the following:
SELECT * FROM mara
INTO TABLE table
FOR ALL ENTRIES IN another_table
WHERE matnr EQ another_table-matnr.
The code above is what exists, (working), but I'm improving the program and one of the improvements is to allow dynamic querying by providing a field symbol instead of a hard-coded table like "another_table". But I get the message "the specified type has no structure and therefore no component called "MATNR".
My code just have the field symbol that points to a previously data reference created for a table passed as a parameter (this is working, having checked via debugging) replacing "another_table" and <fs>-matnr instead of "another_table-matnr".
What solutions would you guys suggest ?
Thanks
AvrahamWhy is that that the commented line doesn't work, but under debugging I can reach <ls_items>-matnr ?
Everything is fine with <lt_items>, it contains 8 lines, and debugging shows <ls_items> receiving one line each loop pass, just as expected. I wanted to understand why/when does this error of "has no structure therefore there is no component"... appears.
LOOP AT <lt_items> INTO <ls_items>.
* SELECT SINGLE * INTO ls_mara FROM mara WHERE mara~matnr = <ls_items>-matnr.
IF sy-subrc = 0.
APPEND ls_mara TO lt_mara.
ENDIF.
ENDLOOP. -
How to populate one internal table from another using field symbols
Hi Gurus,
I have a problem. I have to populate one internal table (sructure t_otput) from another internal table (sructure t_from) using field symbol.
Structure for from table.
types: begin of t_from,
year(4) type c,
ww(2) type c,
site type marc-werks,
demand type i,
end of t_from.
Structure for output table.
types: begin of t_display,
title(30),
WW1(10),
WW2(10),
WW3(10),
end of t_display.
The from table looks like this:
Year | WW | Site | Demand
2005 | 1 | OR1 | 12.00
2005 | 2 | OR1 | 13.00
2005 | 3 | OR1 | 14.00
The display table which has to be populated should look like this:
Title | WW1 | WW2 | WW3
OR1 | | |
Demand | 12.00 | 13.00 | 14.00
How to populate display table using field symbol?
Please give code snippets
Thanks,
GopalGopal,
Here is the code, however I am not vary clear about the ORG1 and Demand display that you have shown in the display. I am sure with this code it should not be a big deal to tweak in whatever manner you want.
TABLES : marc.
TYPES: BEGIN OF type_display,
title(30),
ww1(10),
ww2(10),
ww3(10),
END OF type_display.
TYPES: BEGIN OF type_from,
year(4) TYPE c,
ww(2) TYPE c,
site TYPE marc-werks,
demand TYPE i,
END OF type_from.
data : t_from type table of type_from,
t_display type table of type_display.
field-symbols : <fs_from> type type_from,
<fs_display> type type_display.
data : wa_from type type_From,
wa_display type type_display.
wa_from-year = '2005'.
wa_from-ww = '1'.
wa_from-site = 'OR1'.
wa_from-demand = '12.00'.
insert wa_from into table t_from.
wa_from-year = '2005'.
wa_from-ww = '2'.
wa_from-site = 'OR1'.
wa_from-demand = '13.00'.
insert wa_from into table t_from.
wa_from-year = '2005'.
wa_from-ww = '3'.
wa_from-site = 'OR1'.
wa_from-demand = '14.00'.
insert wa_from into table t_from.
data : variable(3) type c.
field-symbols : <fs_any> type any.
break-point.
Loop at t_from assigning <fs_from>.
variable = 'WW'.
wa_display-title = <fs_from>-site.
concatenate variable <fs_from>-ww into variable.
assign component variable of structure wa_display to <fs_any>.
<fs_any> = <fs_from>-demand.
endloop.
append wa_display to t_display.
clear wa_display.
loop at t_display assigning <Fs_display>.
write :/ <fs_display>.
endloop.
Note : Please award points if this helps you.
Regards,
Ravi -
Hi ,
I have to use an internal table in a form which can have differnet structures at diffrenet points of time.
As the internal table is dynamic , I have declared a field symbol for this.I need to use th efields in this internal table for processing inside a loop.But because i have to use an untyped field symbol , I am getting an error that the field QUANT is not there in <fs_order_tab>.
Please let me know what to do in such a situation.Thanks in advance.
FIELD-SYMBOLS :<fs_order_tab> TYPE STANDARD TABLE,
<fs_order_wa> TYPE ANY.
ASSIGN i_so TO <fs_order_tab>.
ASSIGN wa_so TO <fs_order_wa>.
LOOP AT<fs_order_tab> into <fs_order_wa>..
l_quant = <fs_order_wa>-QUANT.
ENDLOOP.Hi Rashmi,
Kindly follow the steps given below.
After assigning the internal table to the field symbol,
create 1 more field symbols of the following type
<fs_quant> TYPE vbep-bmeng,
Create 1 constant.
CONSTANTS: lc_quant TYPE c LENGTH 5 VALUE 'QUANT'.
and then assign the field quantity to the field symbol
ASSIGN COMPONENT lc_quant OF STRUCTURE <fs_order_wa> TO <fs_quant>.
Inside the loop write the following statement
l_quant = <fs_quant>
Hope this helps in solving your query.
Edited by: Kadian.Arjun on Nov 22, 2010 9:56 AM -
Copying an internal table data to a field symbol(only corresponding field)
Hi,
Iam having field symbol type standard table which has 4 fields in it already.
I am having an internal table which has 10 columns in it.
Now i want to copy the data from internal table to field symbol .But the problem is the fields which are matched in field symbol alone should be copied from the internal table.
for eg.
field symbol type table.
field1.
field2.
field3.
itab type internal table.
field1
field2
field3
field4
field5
field6.
i want to copy the first 3 fields alone from the internal table itab to the field symbols. Can anyone help me on how to do this. thanks...
Regards,
Rose.Hi,
Chk below example, and match with ur scenario.
data: begin of itab,
a , b ,c , d,e,
end of itab,
wa like itab,
jtab like table of itab,
begin of fsy,
a, b ,c,
end of fsy.
field-symbols:<fs> type any.
assign fsy to <fs>.
wa-a = 'x'. wa-b = 'y'. wa-c = 'z'. wa-d = 'r'.
append wa to jtab.
loop at jtab into wa.
move-corresponding wa to <fs>.
endloop.
REGARDS,
SENTHIL KUMAR.S -
Sum for Dynamic Fields in a Dynamic Table with Field Symbol
Hi All,
I currently have an report which I am looking to update with some totals. The information is currently output in an ALV which is fed data from a dynamic table defined with a field symbol. The modification that needs to be applied is a summation per currency code where each of the fields to be summed is a dynamically named field at runtime. I am now just looking to see if anyone has any recommendations on how to obtain these totals it would be appreciated. I have no problem doing the leg work in piecing the solution together but am just stuck on which approach I should be investigating here. I have looked into several options but do to the fact that the totals are for dynamic fields in a dynamic table and it is a field symbol I am having some difficulties thinking of the easiest approach to obtain these totals.
Below is a simple sample of what the report currently looks like and what we are looking to add.
====================================================================================
As-Is Report:
DETAILED DATA ALV
Company Code | Plant | 2006 Total | 2007 Total | 2008 Total | CURRENCY
0001 | ABCD | 1,500 | 1,200 | 1,700 | USD
0001 | BCDE | 2,300 | 4,100 | 3,600 | GBP
0003 | DBCA | 3,200 | 1,600 | 6,200 | USD
Addition 1:
TOTALS PER CURRENCY
Currency | 2006 Total | 2007 Total | 2008 Total |
USD | 4,700 | 2,800 | 7,900 |
GBP | 2,300 | 4,100 | 3,600 |
Addition 2:
CONVERSIONS TO USD
| 2006 Curr | 2006 USD | 2008 Curr | 2006 USD |
USD | 4,700 USD | 4,700 USD | 7,900 USD | 7,900 USD |
GBP (1.5GBP/1 USD) | 2,300 GBP | 1,150 USD | 2,300 GBP | 1,800 USD |
====================================================================================
Any recommendations will be appreciated.Hi,
We cannot use the key word SUM in the loop at assigning statement.
The way i see is
When you are creating the first dynamic internal table , create one more with the structure below:
Currency | 2006 Total | 2007 Total | 2008 Total |
Then while populating the data into first itab,also move the contents to the second itab using collect statement. -
Dynamic Internal table with field symbol
I made the report where the user enters two different tables and two fields that are to be compared.
Eg. If I enter (MARA & NAME1) and (MARC & NAME2) , I wish to compare all the entries of Mara-name1 against all entries in Marc-name2.
<u>The code I need to write is:</u>
DATA:
gdo_data TYPE REF TO data.
DATA:
gdo_data1 TYPE REF TO data.
FIELD-SYMBOLS:
<gt_itab> TYPE table,
<wa> LIKE <gt_itab>, "<gt_itab>,
<gs_entry> TYPE ANY.
FIELD-SYMBOLS:
<gt_itab1> TYPE table,
<wa1> LIKE <gt_itab>, "<gt_itab>,
<gs_entry1> TYPE ANY.
PARAMETERS:
p_table TYPE tabname, " DEFAULT 'KNA1',
p_fld TYPE fieldname. " DEFAULT 'KUNNR'.
PARAMETERS:
p_table1 TYPE tabname, " DEFAULT 'KNA1',
p_fld1 TYPE fieldname.
DATA: var TYPE fieldname.
var = p_fld.
DATA: var1 TYPE fieldname.
var1 = p_fld1.
START-OF-SELECTION.
CREATE DATA gdo_data TYPE TABLE OF (p_table).
ASSIGN gdo_data->* TO <gt_itab>.
CREATE DATA gdo_data1 TYPE TABLE OF (p_table1).
ASSIGN gdo_data1->* TO <gt_itab1>.
SELECT * FROM (p_table) INTO CORRESPONDING FIELDS OF TABLE <gt_itab>.
SELECT * FROM (p_table1) INTO CORRESPONDING FIELDS OF TABLE <gt_itab1>.
<b> LOOP AT <gt_itab> ASSIGNING <gs_entry>.
READ TABLE <gt_itab1> ASSIGNING <gs_entry1>
WITH KEY (var1) = <gt_itab>-(var).
IF sy-subrc EQ 0.
MESSAGE 'Success' TYPE 'S'.
ENDIF.
ENDLOOP.</b>
END-OF-SELECTION.
But the portion in bold is creating error: <b><gt_itab> is a table without a header lineand therefore has no component called "".</b>
please help.Hi Amit
Try like this
LOOP AT <gt_itab> ASSIGNING <gs_entry>.
READ TABLE <gt_itab1> ASSIGNING <gs_entry1>
WITH KEY (var1) = <b><gs_entry></b>-(var).
IF sy-subrc EQ 0.
MESSAGE 'Success' TYPE 'S'.
ENDIF.
ENDLOOP.
Regards,
Atish -
How to read data from field symbol containing Table
I defined a field symbols for reading output of a BRF plus rule however since fielk symbol is of type any
I cannot read its contents
Any inputs are highly appreciated
Please see attachment explaining problemThanks a lot for your help
However It did not work for me as it started giving error incompatible types
Here is my code
constants:lv_function_id type if_fdt_types=>id value '3440B5B078B21EE3BC9EB53C42F84A45'.
data:lv_timestamp type timestamp,
lt_name_value type abap_parmbind_tab,
ls_name_value type abap_parmbind,
lr_data type ref to data,
lv_counter type i value 0,
lr_target type ref to data,
lx_fdt type ref to cx_fdt,
lo_trace type ref to if_fdt_trace,
lo_lean_trace type ref to if_fdt_lean_trace,
la_z_string type if_fdt_types=>element_text,
lv_role_name type grac_role_name,
lv_result type string.
field-symbols <la_any> type any.
field-symbols <role_name> type grac_s_od_role_detail.
field-symbols <system> type string.
types:
begin of ys_access ,
role_name type string,
system_name type string,
end of ys_access .
types:
yt_access type table of ys_access .
field-symbols: <access_item> type table,
<ls_req_access> type ys_access.
data con_name type if_fdt_types=>element_text.
data ls_any type ys_access.
* All method calls within one processing cycle calling the same function must use the same timestamp.
* For subsequent calls of the same function, we recommend to use the same timestamp for all calls.
* This is to improve the system performance.
* If you are using structures or tables without DDIC binding, you have to declare the respective types
* by yourself. Insert the according data type at the respective source code line.
* GET TIME STAMP FIELD lv_timestamp.
* Process a function and record trace data, passing context data objects via a name/value table.
* Prepare function processing:
ls_name_value-name = 'Z_STRING'.
la_z_string = 'P1'.
get reference of la_z_string into lr_data.
ls_name_value-value = lr_data.
insert ls_name_value into table lt_name_value.
* Create the data to store the result value after processing the function
* You can skip the following call, if you already have
* a variable for the result. Please replace also the parameter
* EA_RESULT in the method call CL_FDT_FUNCTION_PROCESS=>PROCESS
* with the desired variable.
cl_fdt_function_process=>get_data_object_reference( exporting iv_function_id = lv_function_id
iv_data_object = '_V_RESULT'
iv_timestamp = lv_timestamp
iv_trace_generation = abap_true
importing er_data = lr_data ).
assign lr_data->* to <la_any>.
try.
cl_fdt_function_process=>process( exporting iv_function_id = lv_function_id
iv_timestamp = lv_timestamp
iv_trace_mode = if_fdt_constants=>gc_trace_mode_lean
"iv_trace_mode = if_fdt_constants=>gc_trace_mode_lean_required
importing ea_result = <la_any>
eo_trace = lo_trace
changing ct_name_value = lt_name_value ).
lo_lean_trace ?= lo_trace.
lo_lean_trace->save( ).
catch cx_fdt into lx_fdt.
* You can check CX_FDT->MT_MESSAGE for error handling.
endtry.
* Get context values after processing:
cl_fdt_function_process=>get_context_value( exporting iv_function_id = lv_function_id
iv_trace_generation = abap_true
iv_timestamp = lv_timestamp:
iv_data_object = '3440B5B078B21EE3BC9EFF599C110ADD' "Z_STRING
importing ev_data = lv_result ). " Suggested variable: la_z_string
create data lr_target type grac_s_od_role_detail.
* assign <la_any> to <role_name>.
assign lr_target->* to <la_any>.
loop at lt_name_value into ls_name_value.
if ls_name_value-name cs 'RESULT'.
assign ls_name_value-value to <la_any>.
ls_any = ls_name_value-value .
endif.
endloop.
access_item = <la_any>.
* assign ( )<la_any> to <access_item>.
* assign component 1 of structure <la_any> to <rolename>.
* assign <la_any> to <ls_req_access>.
* lr_target = <la_any>.
* assign lr_target->* to <role_name>.
* lv_role_name = <role_name>.
lv_result = lv_result. -
Options for read/write form field data with VBA/Reader
I have a project which requires reading and writing field data to a PDF form using VBA in PowerPoint. The code I have works properly with the full version of Acrobat, but the client this project is for will be using Reader. I'm looking for suggestions to what options I have to be able to access the form field data (I don't need any other features other than access to the field data). Ideally, I would love a solution which doesn't require the client to install anything extra for this to work, but I'm assuming that this isn't possible without an extra install.
Is there a library that exists in Reader (or could be licensed to be installed on the client's machine) that would allow the data to be read without needing the full version of Acrobat?
Does a plug-in exist for Reader, or could be written, that would allow this? Writing a plug-in would certainly be beyond my current capabilities, but I am interested in knowing every and any choices that are available.
Are there any other options to do what I need to do?
I had originally thought about exporting the form data and parsing it in the VBA program, but this would take a bit more work to write the parsing routine instead of accessing the fields directly. Plus, it appears to me that Exporting is not enabled in Reader.
Thanks for any insight you may be able to provide.Thanks for the response; this was my original suggestion, but I don't think this is feasable for our client. I suggested to our account people that this might be the only way to do this (and the easiest, although possibly the costliest since it would have to be purchased for their entire sales force) and they initially said that this would not be an option, so I wanted to be able to cover all the bases, and explore any other ways that they could do what they want. Is this the absolute only option to do this?
Someone also suggested to me that licensing the Acrobat PDF Library SDK might be a way to do this, or that it could possibly be done with a plug-in for Reader (although from what I have found, Reader plug-ins would have to be approved by Adobe). These options, if possible, are beyond my current knowledge but I do want to be able to give them a complete list of possibilities.
Thanks again. -
Dynamic Table UI Element with different data type for each cell
Hi Experts,
I have a problem with a dynamic Table UI Element in Web Dynpro ABAP. I have the following coding:
METHOD set_col_row .
TYPE-POOLS: icon.
DATA:
lv_node TYPE REF TO if_wd_context_node,
lv_node_info TYPE REF TO if_wd_context_node_info,
lv_element TYPE REF TO if_wd_context_element,
lt_attributes TYPE wdr_context_attr_info_map,
lv_table TYPE REF TO cl_wd_table,
lv_table_column TYPE REF TO cl_wd_table_column,
lv_text_view TYPE REF TO cl_wd_text_view,
lv_image TYPE REF TO cl_wd_image,
lv_text_edit TYPE REF TO cl_wd_text_edit,
lv_header TYPE REF TO cl_wd_caption,
attribute LIKE LINE OF lt_attributes,
lv_index TYPE string,
lv_cur_row TYPE i,
path TYPE string,
lv_value TYPE string,
attr_name TYPE string,
l_trc_point_id TYPE string,
l_num_cols TYPE string,
l_num_rows TYPE string,
lv_text TYPE string,
lv_index2 TYPE i,
lr_ress_selections TYPE REF TO /its/di_2_cpr_ress_selections,
lt_comp_tab TYPE cl_abap_structdescr=>component_table,
ls_comp_tab LIKE LINE OF lt_comp_tab,
lv_count TYPE i,
lv_col_count TYPE i,
lv_col_count_read TYPE i,
lv_index_read TYPE i,
lv_num_cols_minus_1 TYPE i,
lv_bind_lv_value TYPE string,
wd_standard_cell TYPE REF TO cl_wd_table_standard_cell,
lv_data_count TYPE i,
lv_data_count_str TYPE string,
wd_table_column TYPE REF TO cl_wd_table_column,
lv_column_id TYPE string.
FIELD-SYMBOLS:
TYPE ANY.
Instanz der Klasse /ITS/DI_2_CPR_RESS_SELECTIONS
lr_ress_selections = /its/di_2_cpr_ress_selections=>factory( ).
ASSIGN lr_ress_selections->gr_table->* TO gt_comp_tab.
ls_comp_tab-name = 'SUMME'.
APPEND ls_comp_tab TO lt_comp_tab.
ls_comp_tab-name = 'CELL_VARIANT'.
APPEND ls_comp_tab TO lt_comp_tab.
CLEAR ls_comp_tab.
l_num_rows = num_rows + 1.
CONDENSE l_num_rows.
l_num_cols = num_columns + 1.
CONDENSE l_num_cols.
UI-Element 'TABLE'
lv_table ?= wd_this->m_view->get_element( 'TBL_TABLE' ).
lv_table->remove_all_columns( ).
Kontext-Knoten 'TABLE'
lv_node = wd_context->get_child_node( 'TABLE' ).
lv_node_info = lv_node->get_node_info( ).
lv_node_info->remove_dynamic_attributes( ).
attribute-type_name = 'STRING'.
lv_num_cols_minus_1 = num_columns - 1.
Für jede Spalte einmal tun
DO lv_num_cols_minus_1 TIMES.
lv_index = sy-index + 1.
CONDENSE lv_index.
lv_table_column = cl_wd_table_column=>new_table_column( ).
lv_column_id = lv_table_column->id.
Spaltenüberschriften setzen
IF lv_index EQ 1. "Beim ersten Durchlauf --> erste Spalte = "Ressourcen"
lv_text = text-010.
sy-index = 0.
ELSE. "Danach für jede weitere Spalte eine Zeile aus der gt_comp_tab nehmen
lv_index_read = lv_index - 1.
READ TABLE lt_comp_tab INDEX lv_index_read INTO ls_comp_tab.
lv_text = ls_comp_tab-name.
lv_header = cl_wd_caption=>new_caption( text = lv_text ).
lv_table_column->set_header( lv_header ).
ENDIF.
CONCATENATE 'TABLE.A' lv_index INTO path.
lv_text_view = cl_wd_text_view=>new_text_view( bind_text = path ).
lv_table_column->set_table_cell_editor( lv_text_view ).
lv_table_column->bind_selected_cell_variant( 'TABLE.CELL_VARIANT' ).
lv_table->add_column( lv_table_column ).
wd_table_column ?= wd_this->m_view->get_element( lv_column_id ).
*****************Test Cell Variant*************************************************
IF lv_index GT 1.
LOOP AT .
IF sy-tabix EQ lv_cur_row.
Name zuweisen
ASSIGN COMPONENT 'NAME' OF STRUCTURE .
Zuweisen ob Blatt oder nicht
lv_element->set_attribute( name = 'NAME' value = lv_value ).
ASSIGN COMPONENT 'IS_LEAF' OF STRUCTURE set_attribute( name = attr_name value = lv_value ).
ENDIF.
ENDLOOP.
Now my problem is, that I need for every ROW of my table UI Element a different cell editor. I know how to change it for the column. But is not my issue. I want to have images (traffic lights red and green) in some rows. The other rows should have numbers. The coding works, so that I have all the data at the right place in my table, only the images are shown as a string, because the cells of these rows have the cell editor Text_View. I tried something with cell variants (with cl_wd_table_standard_cell), but it was not possible for me to get a cell variant "image" in these cells/rows were I need it.
I hope you understand my problem and now what to do here.
Thanks a lot in advance.
Best Regards,
IngmarHi Experts, I have a problem with a dynamic Table UI Element in Web Dynpro ABAP. I have the following coding: METHOD set_col_row . TYPE-POOLS: icon. DATA: lv_node TYPE REF TO if_wd_context_node, lv_node_info TYPE REF TO if_wd_context_node_info, lv_element TYPE REF TO if_wd_context_element, lt_attributes TYPE wdr_context_attr_info_map, lv_table TYPE REF TO cl_wd_table, lv_table_column TYPE REF TO cl_wd_table_column, lv_text_view TYPE REF TO cl_wd_text_view, lv_image TYPE REF TO cl_wd_image, lv_text_edit TYPE REF TO cl_wd_text_edit, lv_header TYPE REF TO cl_wd_caption, attribute LIKE LINE OF lt_attributes, lv_index TYPE string, lv_cur_row TYPE i, path TYPE string, lv_value TYPE string, attr_name TYPE string, l_trc_point_id TYPE string, l_num_cols TYPE string, l_num_rows TYPE string, lv_text TYPE string, lv_index2 TYPE i, lr_ress_selections TYPE REF TO /its/di_2_cpr_ress_selections, lt_comp_tab TYPE cl_abap_structdescr=>component_table, ls_comp_tab LIKE LINE OF lt_comp_tab, lv_count TYPE i, lv_col_count TYPE i, lv_col_count_read TYPE i, lv_index_read TYPE i, lv_num_cols_minus_1 TYPE i, lv_bind_lv_value TYPE string, wd_standard_cell TYPE REF TO cl_wd_table_standard_cell, lv_data_count TYPE i, lv_data_count_str TYPE string, wd_table_column TYPE REF TO cl_wd_table_column, lv_column_id TYPE string. FIELD-SYMBOLS: LIKE LINE OF lt_attributes, TYPE ANY TABLE, TYPE ANY, TYPE ANY, TYPE ANY. * Instanz der Klasse /ITS/DI_2_CPR_RESS_SELECTIONS lr_ress_selections = /its/di_2_cpr_ress_selections=>factory( ). ASSIGN lr_ress_selections->gr_table->* TO . lt_comp_tab = lr_ress_selections->gt_comp_tab. ls_comp_tab-name = 'SUMME'. * APPEND ls_comp_tab TO lt_comp_tab. * ls_comp_tab-name = 'CELL_VARIANT'. APPEND ls_comp_tab TO lt_comp_tab. CLEAR ls_comp_tab. l_num_rows = num_rows + 1. CONDENSE l_num_rows. l_num_cols = num_columns + 1. CONDENSE l_num_cols. * UI-Element 'TABLE' lv_table ?= wd_this->m_view->get_element( 'TBL_TABLE' ). lv_table->remove_all_columns( ). * Kontext-Knoten 'TABLE' lv_node = wd_context->get_child_node( 'TABLE' ). lv_node_info = lv_node->get_node_info( ). lv_node_info->remove_dynamic_attributes( ). attribute-type_name = 'STRING'. lv_num_cols_minus_1 = num_columns - 1. * Für jede Spalte einmal tun DO lv_num_cols_minus_1 TIMES. lv_index = sy-index + 1. CONDENSE lv_index. lv_table_column = cl_wd_table_column=>new_table_column( ). lv_column_id = lv_table_column->id. * Spaltenüberschriften setzen IF lv_index EQ 1. "Beim ersten Durchlauf --> erste Spalte = "Ressourcen" lv_text = text-010. sy-index = 0. ELSE. "Danach für jede weitere Spalte eine Zeile aus der gt_comp_tab nehmen lv_index_read = lv_index - 1. READ TABLE lt_comp_tab INDEX lv_index_read INTO ls_comp_tab. lv_text = ls_comp_tab-name. lv_header = cl_wd_caption=>new_caption( text = lv_text ). lv_table_column->set_header( lv_header ). ENDIF. CONCATENATE 'TABLE.A' lv_index INTO path. lv_text_view = cl_wd_text_view=>new_text_view( bind_text = path ). lv_table_column->set_table_cell_editor( lv_text_view ). lv_table_column->bind_selected_cell_variant( 'TABLE.CELL_VARIANT' ). lv_table->add_column( lv_table_column ). wd_table_column ?= wd_this->m_view->get_element( lv_column_id ). ******************Test Cell Variant************************************************** IF lv_index GT 1. LOOP AT ASSIGNING . ASSIGN COMPONENT 'TYPE' OF STRUCTURE TO . ADD 1 TO lv_data_count. lv_data_count_str = lv_data_count. CONCATENATE 'A' lv_index lv_data_count_str INTO path. wd_standard_cell = cl_wd_table_standard_cell=>new_table_standard_cell( view = wd_this->m_view variant_key = 'FLDATE' ). IF = '01' OR = '04'. lv_image = cl_wd_image=>new_image( bind_source = path view = wd_this->m_view ). wd_standard_cell->set_editor( lv_image ). wd_standard_cell->set_cell_design( '01' ). ELSE. lv_text_view = cl_wd_text_view=>new_text_view( bind_text = path view = wd_this->m_view ). wd_standard_cell->set_editor( lv_text_view ). wd_standard_cell->set_cell_design( '02' ). ENDIF. wd_table_column->add_cell_variant( wd_standard_cell ). ENDLOOP. ENDIF. ************************************************************************************* CONCATENATE 'A' lv_index INTO attribute-name. lv_node_info->add_attribute( attribute ). ENDDO. DO num_rows TIMES." Für jede Zeile einmal tun lv_cur_row = sy-index. lv_element = lv_node->create_element( ). lv_node->bind_element( new_item = lv_element set_initial_elements = abap_false ). DO l_num_cols TIMES. ADD 1 TO lv_col_count. IF lv_count LT 1. LOOP AT ASSIGNING . IF sy-tabix EQ lv_cur_row. * Name zuweisen ASSIGN COMPONENT 'NAME' OF STRUCTURE TO . "NAME lv_value = . * Zuweisen ob Blatt oder nicht lv_element->set_attribute( name = 'NAME' value = lv_value ). ASSIGN COMPONENT 'IS_LEAF' OF STRUCTURE TO . "NAME lv_value = . lv_element->set_attribute( name = 'IS_LEAF' value = lv_value ). ENDIF. ENDLOOP. ENDIF. IF lv_count GT 0. lv_col_count_read = lv_col_count - 1. lv_index = sy-index. LOOP AT ASSIGNING . IF sy-tabix EQ lv_cur_row. CLEAR ls_comp_tab. READ TABLE lt_comp_tab INDEX lv_col_count_read INTO ls_comp_tab. ASSIGN COMPONENT ls_comp_tab-name OF STRUCTURE TO . lv_value = . CONDENSE lv_index. CONCATENATE 'A' lv_index INTO attr_name. lv_element->set_attribute( name = attr_name value = lv_value ). ENDIF. ENDLOOP. ENDIF. lv_count = lv_count + 1. ENDDO. CLEAR lv_col_count. CLEAR lv_count. ENDDO. ENDMETHOD. I definied my table in Layout Tab of the View and create here in thos method dynamicly my columns. lv_table_column = cl_wd_table_column=>new_table_column( ). . . lv_table->add_column( lv_table_column ). In I have my data that should be shown later in my table. So I create for each row in this fieldsymbol in a loop: lv_element = lv_node->create_element( ). lv_node->bind_element( new_item = lv_element set_initial_elements = abap_false ). Later I fill every cell in my table with a different value with this loop: LOOP AT ASSIGNING . IF sy-tabix EQ lv_cur_row. CLEAR ls_comp_tab. READ TABLE lt_comp_tab INDEX lv_col_count_read INTO ls_comp_tab. ASSIGN COMPONENT ls_comp_tab-name OF STRUCTURE TO . lv_value = . CONDENSE lv_index. CONCATENATE 'A' lv_index INTO attr_name. lv_element->set_attribute( name = attr_name value = lv_value ). ENDIF. ENDLOOP. Now my problem is, that I need for every ROW of my table UI Element a different cell editor. I know how to change it for the column. But is not my issue. I want to have images (traffic lights red and green) in some rows. The other rows should have numbers. The coding works, so that I have all the data at the right place in my table, only the images are shown as a string, because the cells of these rows have the cell editor Text_View. I tried something with cell variants (with cl_wd_table_standard_cell), but it was not possible for me to get a cell variant "image" in these cells/rows were I need it. I hope you understand my problem and now what to do here. Thanks a lot in advance. Best Regards, Ingmar
-
To Modify a field value with field symbols
we had a requirement like we are getting in a floating point value in a field of an IDoc segment like 12.327- .Here if we see that the negative sign is after the floating point value and if we try to insert this into a database then it will throw out an error.Before inserting the value we need to covert the incoming value in the form -12.327.
I used the field symbols inorder to get the values and to change them.
But iam not able to modify the internal table from the new value.
Here is my sample code.
DATA: IT_MBEW TYPE TABLE OF MBEW,
WA_MBEW TYPE MBEW,
IT_DFIES TYPE TABLE OF DFIES,
WA_DFIES TYPE DFIES,
IT_DD03L TYPE TABLE OF DD03L,
WA_DD03L TYPE DD03L,
L_FIELD TYPE VALUE,
WA_VALUE TYPE mbew,
L_MBEW TYPE DDOBJNAME VALUE 'MBEW'.
FIELD-SYMBOLS: <FS1> TYPE ANY.
FIELD-SYMBOLS: <FS3> TYPE ANY.
FIELD-SYMBOLS: <FS2> TYPE ANY.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_MBEW
FROM MBEW WHERE MATNR = '000000000000100110'.
LOOP AT IT_MBEW INTO WA_MBEW.
WA_MBEW-SALK3 = - 354471.
MODIFY IT_MBEW FROM WA_MBEW.
ENDLOOP.
To call the FM inorder to get the fieldnames for MBEW table
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = L_MBEW
FIELDNAME = ' '
LANGU = SY-LANGU
LFIELDNAME = ' '
ALL_TYPES = ' '
GROUP_NAMES = ' '
UCLEN =
IMPORTING
X030L_WA =
DDOBJTYPE =
DFIES_WA =
LINES_DESCR =
TABLES
DFIES_TAB = IT_DFIES
FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SELECT TABNAME FIELDNAME DATATYPE POSITION INTO CORRESPONDING FIELDS OF TABLE
IT_DD03L FROM DD03L
WHERE TABNAME = 'MBEW'
AND DATATYPE = 'CURR'
ORDER BY POSITION ASCENDING.
*LOOP AT IT_MBEW INTO WA_MBEW.
LOOP AT IT_MBEW assigning <fs1>.
ASSIGN WA_MBEW TO <FS1>.
do.
LOOP AT IT_DD03L INTO WA_DD03L.
READ TABLE IT_DFIES INTO WA_DFIES WITH KEY FIELDNAME = WA_DD03L-FIELDNAME
DATATYPE = WA_DD03L-DATATYPE.
IF SY-SUBRC = 0.
ASSIGN WA_DFIES-FIELDNAME TO <FS2>.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE <FS1> TO <FS3>.
MOVE <FS3> TO L_FIELD.
CONDENSE L_FIELD.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
VALUE = L_FIELD.
IF SY-SUBRC = 0.
ASSIGN L_FIELD TO <FS3>.
MODIFY ITMBEW INDEX SY-TABIX FROM <FS3>._
ENDIF.
ENDIF.
ENDLOOP.
*enddo.
ENDLOOP.
The Modify statement is not working.....Plesae help me in this regard.
Thanks
SrinivasHello.
When you write,
LOOP AT it_mbew ASSIGNING <fs1>.
ENDLOOP.
you don't need to use statements:
ASSIGN WA_MBEW TO <FS1>
nor
MODIFY it_mbew
after that.
If you just write:
LOOP AT it_mbew ASSIGNING <fs1>.
<fs1>-field1 = 'A'.
<fs1>-field2 = 'B'.
ENDLOOP.
all records of it_mbew will have field1 = 'A' and field2 = 'B'.
The point is, statement LOOP assigning <fs1> will make the field symbol to became a pointer to the records of the internal table. So, if you change the field symbol, you are changing the internal table already.
Regards.
Valter Oliveira. -
Problem with field-symbol values not updating
H i ,
I have following piece of code :
Assigning Dynamic Table to Field Symbol
ASSIGN ist_dyn_table->* TO <gs_dyn_table>.
* Creating Structure for dynamic table
CREATE DATA gs_dyn_line LIKE LINE OF <gs_dyn_table>.
* Creating line type for the Dynamic Values
ASSIGN gs_dyn_line->* TO <gs_line>.
* Populating values in the dynamic table
LOOP AT ist_pwcl_main INTO wa_pwcl_main.
ASSIGN COMPONENT gc_fld_werks OF STRUCTURE <gs_line> TO <gs_field>.
1 IF sy-subrc EQ 0.
2 <gs_field> = wa_pwcl_main-werks.
3 ENDIF.
5 IF <gs_field> IS ASSIGNED.
6 <gs_field> = wa_pwcl_main-vbeln.
ENDIF.
7 IF <gs_field> IS ASSIGNED.
8 <gs_field> = wa_pwcl_main-posnr.
ENDIF.
IF <gs_field> IS ASSIGNED.
<gs_field> = wa_pwcl_main-quant.
ENDIF.
on debugging at line 2 <gs_filed> contains the value of werks .
but at line 6 <gs_field> contains value of vbeln as 0 and at 8 of posnr as 0 .
What can be the problem ? Other values are getting assigned properly .
Plz help ...
Regards .Hi,
Assigning Dynamic Table to Field Symbol
ASSIGN ist_dyn_table->* TO <gs_dyn_table>.
Creating Structure for dynamic table
CREATE DATA gs_dyn_line LIKE LINE OF <gs_dyn_table>.
Creating line type for the Dynamic Values
ASSIGN gs_dyn_line->* TO <gs_line>.
Populating values in the dynamic table
LOOP AT ist_pwcl_main INTO wa_pwcl_main.
ASSIGN COMPONENT gc_fld_werks OF STRUCTURE <gs_line> TO <gs_field>.
1 IF sy-subrc EQ 0.
2 <gs_field> = wa_pwcl_main-werks.
3 ENDIF.
5 IF <gs_field> IS ASSIGNED.
6 <gs_field> = wa_pwcl_main-vbeln.
ENDIF.
7 IF <gs_field> IS ASSIGNED.
8 <gs_field> = wa_pwcl_main-posnr.
ENDIF.
IF <gs_field> IS ASSIGNED.
<gs_field> = wa_pwcl_main-quant.
ENDIF.
Based on your coding above, <gs_field> has been assigned with data type 'WERKS' (i'd assume component gc_fld_werks found from structure <gs_line> is a plant typed), which is a CHAR(4) data type.
Meaning, if <gs_field> is assigned with Plant type value, e.g. <gs_field> = '1000', field symbol <gs_field> will contain 4 character only.
At line 6, if wa_pwcl_main-vbeln = '0000201000', <gs_field> is only capturing '0000' only. This is also happened to line 8.
However, it looks like that <gs_field> is getting over-write if ASSIGNED statement returns SY-SUBRC = 0.
Hope this helps.
Regards,
Patrick -
Dynamic ITAB copy problem with field type P
Hello everyone
I need to copy the structure of an internal table that is pass by reference into a method.
Actually everything is fine else than the field type P with decimal is not created properly in the new itab.
Scenario:
An internal table is pass by reference to a method. We need to trait the data without modifying the original table. The Idea is to copy the structure and the data of the referenced internal table into an internal table created dymanically in the method.
Here is what I did and working fine when there are no field of data type "CURR".
Extract the structure of the reference data.
Create a dynamic internal table.
So far so good. Everything seams to work fine. BUT
when I am trying to copy the data from the reference table to the just created internal table the field with data type "CURR" doesn't work.
Here is my example:
FIELD-SYMBOLS: <FS_TABLE> TYPE STANDARD TABLE,
<TMP_TABLE> TYPE STANDARD TABLE,
<LS_TMP_TABLE> TYPE ANY,
<LS_TABLE> TYPE ANY,
<LS_VALUE> TYPE ANY.
DATA: lt_data TYPE STANDARD TABLE OF vbak,
ls_data LIKE LINE OF lt_sortfield,
ref_data TYPE REF TO data,
l_structure TYPE REF TO DATA,
lv_ltname TYPE string.
select * from vbak UP TO 10 rows INTO CORRESPONDING FIELDS OF TABLE lt_data.
* --- Assign the reference variable to the table
* ---- Only use to simulate a parameter that is assign to a reference to a internal table
unassign <FS_TABLE>.
lv_ltname = 'lt_data[]'.
ASSIGN (lv_ltname) to <FS_TABLE>.
GET REFERENCE OF <FS_TABLE>[] INTO ref_data.
* --- Assign the reference to the field-symbol
UNASSIGN <FS_TABLE>.
ASSIGN ref_data->* TO <FS_TABLE>.
* --- Create a working area for the reference table to a field-table
CREATE DATA l_structure LIKE LINE OF <FS_TABLE>.
ASSIGN l_structure->* TO <LS_TABLE>.
* --- Retrieve the structure of the field-symbol pointing to the internal table
DATA: lr_tabledescr TYPE REF TO cl_abap_tabledescr, " Internal Table description
_r_structdescr TYPE REF TO cl_abap_structdescr.
lr_tabledescr ?= cl_abap_tabledescr=>describe_by_data( <fs_table> ).
_r_structdescr ?= lr_tabledescr->get_table_line_type( ).
* --- Read internal table structure to create dynamic internal table
data: ls_struc like LINE OF _r_structdescr->components,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
* --- Why the field (component) NETWR length is now 8 instead of 15?
LOOP AT _r_structdescr->components into ls_struc.
clear xfc.
xfc-fieldname = ls_struc-name .
xfc-datatype = ls_struc-type_kind.
xfc-inttype = ls_struc-type_kind.
xfc-intlen = ls_struc-length.
xfc-decimals = ls_struc-decimals.
append xfc to ifc.
ENDLOOP.
DATA: dy_table type ref to data,
* --- Create dynamic internal table
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
* --- assign reference internal table to Field-symbol
assign dy_table->* to <tmp_table>.
unassign <ls_tmp_table>.
DATA: ls_tmp_struc type REF TO DATA.
CREATE DATA ls_tmp_struc like LINE OF <tmp_table>.
ASSIGN ls_tmp_struc->* TO <ls_tmp_table>.
Loop at <fs_table> INTO <LS_TABLE>.
MOVE-CORRESPONDING <ls_table> TO <ls_tmp_table>.
APPEND <ls_tmp_table> TO <tmp_table>.
ENDLOOP.
* <fs_table>-netwr length is 15
* <ls_tmp_table>-netwr length is 8
* ??????????? Why the length is different?
* ??????????? It should a structure copy and have the
* ??????????? same length
I use VBAK as example, and the field NETWR is using data type "NETWR_AK" where it us a data type "CURR" with length 15 and decimal 2.
When reading the structure, the method get_table_line_type of the class cl_abap_tabledescr return a length of 8 instead of 15.
Any idea how to get the exact structure of a variable that is refering to a data type?
Regards
DanielHello Everyone
Thank you for your replies.
I think I didn't explain myself clearly.
My goal is to be able to create an exact structure copy of a "Type ref to data" into a new internal table that is not defined yet.
Example:
A method contain a parameter that is a ref to DATA type.
That parameter is refering to an internal table from the calling program.
Now I want to create an internal table into the method where this one will be an exact structure copy of the parameter.
So, lets put some name here.
parameter: ip_data type ref to data.
FIELD-SYMBOLS: <FS_REF_DATA> TYPE STANDARD TABLE,
<FS_CP_DATA> TYPE STANDARD TABLE.
ASSIGN ip_data->* TO <FS_REF_DATA>.
" some code to assign the same structure to <FS_CP_DATA> from <FS_REF_DATA>
" than copy the data from <FS_REF_DATA> to <FS_CP_DATA>.
<FS_CP_DATA> [ ] = <FS_REF_DATA> [ ]. " This is working if no type P with decimal exist into the structure
" Than I can play with the data of <FS_CP_DATA> without modifying the data of <FS_REF_DATA>.
My problem would be solved if I can create dynamically an internal table that has an exact structure copy of the passed parameter.
Regards
Daniel
Maybe you are looking for
-
Can't download song purchased from Itunes from one computer to another using same Apple ID
Hi, I am operating itunes 11 at home, using Mac OS 10.7.5.. I purchased a song at work (also a Mac, I am not sure which version of OSM or itunes). I accessed the purchase of the song in the "Purchased" menu option in itunes on my home Mac. When I tri
-
I just started using a new version of Illustrator and the text I am creating has a pink box behind, looks to be about the depth of the normal linespace, it is not visible in outline view, only in preview. What is it and how do I get rid of it?
-
Podcast Subscriptions and System Recovery
I am planning on doing a System Recovery tomorrow (Sept 13) and I'm wondering about my Podcasts. The podcasts themselves, I've taken and copied into my backup folder, which I'll burn before I do the system recovery, so I know those will be fine. What
-
Multicamclips workflow step by step
I loaded two clips recorded by two cameras, now, whatkind is the workflow for multicameraclips?
-
Help How to Boot SATA drive? Serial ATA (NOT)- Raid
hi, i have the Msi K8N Neo Platinum and i despertly tried to boot from the Serial ATA drive. i have 2 hd in the IDE primary channels and 2 Cdrw and Cd Rom connected to the IDE Secondary Channels the Serial ATA is connected to 3 port due to overclocki