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
Similar Messages
-
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. -
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 -
Coloring of Particular Cells in a dynamic internal table(field symbols)
Hi,
I have a requirement to introduce color into some particular cells in a dynamic internal table(Field symbol) based on some conditions.I know that color can be introduced at cell level in the case of static internal table.But, can anybody tell me whether it is possible to introduce color to particular cells in the dynamic internal table(Field Symbol) .Please suggest me on this issue.
Thanks in advance,
RajeshHi,
This is the sample coding for the colour cell report.
Kindly go through it. It will helps u.
REPORT YMS_COLOURTEST .
DATA: BEGIN OF TP OCCURS 10, ID, NR(8), TEXT(255), END OF TP.
DATA: LENGTH TYPE I VALUE 8, " Length of list
TESTSTRING(15) TYPE C VALUE '012345678901234',
WIDTH TYPE I. " Width of list
DATA: TXT_REPORT LIKE DOKHL-OBJECT.
START-OF-SELECTION.
PERFORM HEADING.
PERFORM OUTPUT_BODY.
FORM HEADING.
FORMAT INTENSIFIED OFF. " Remove any INTENSIFIED
ULINE AT (WIDTH). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED." Title color
WRITE: / SY-VLINE. " Left border
WRITE: 'No |Colour |intensified |intensified off|',
'inverse' NO-GAP.
WRITE: AT WIDTH SY-VLINE. " Right border
ULINE AT (WIDTH). " Line below titles
FORMAT COLOR OFF.
ENDFORM.
FORM OUTPUT_BODY.
DO LENGTH TIMES.
PERFORM WRITE_LINE USING SY-INDEX.
ENDDO.
ENDFORM.
FORM WRITE_LINE USING COUNT TYPE I.
DATA: HELP(14) TYPE C,
COUNT1 TYPE I.
COUNT1 = SY-INDEX - 1.
WRITE: / SY-VLINE NO-GAP.
WRITE: (4) COUNT1 COLOR COL_KEY INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
CASE COUNT1.
WHEN '0'.
HELP = 'COL_BACKGROUND'.
WHEN '1'.
HELP = 'COL_HEADING'.
WHEN '2'.
HELP = 'COL_NORMAL'.
WHEN '3'.
HELP = 'COL_TOTAL'.
WHEN '4'.
HELP = 'COL_KEY'.
WHEN '5'.
HELP = 'COL_POSITIVE'.
WHEN '6'.
HELP = 'COL_NEGATIVE'.
WHEN '7'.
HELP = 'COL_GROUP'.
ENDCASE.
WRITE: HELP COLOR COL_KEY INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED OFF NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INVERSE NO-GAP.
WRITE AT WIDTH SY-VLINE NO-GAP.
ENDFORM.
Thanks,
Shankar -
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
TomHi,
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 -
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 -
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. -
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. -
Dynamic table with field type table
Hi,
I´m using "cl_alv_table_create=>create_dynamic_table" to create a dynamic table for ALV Grid.
But...I need to use colors in ALV, then I need to declare a field type LVC_S_SCOL in dynamic table from "cl_alv_table_create=>create_dynamic_table".
How can I declare this in fieldcat?
The code:
Creating dynamic table
DATA: table_agrup TYPE REF TO data,
line_agrup TYPE REF TO data.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fieldcat
IMPORTING
ep_table = table_agrup
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN table_agrup->* TO .
Printing ALV
CALL METHOD obj_grid->set_table_for_first_display
EXPORTING
is_variant = w_variant
i_save = 'A'
is_layout = w_layout
CHANGING
it_outtab =
it_fieldcatalog = t_fieldcat
it_sort = t_sort
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
Thanks.It is not possible with the METHOD cl_alv_table_create=>create_dynamic_table to include another table inside that newly generated table.
I have tried to do it with the code and I got the dynamic table created after at the end of the program.
In the code,
<DYN_TABLE> has same effect as your <table> variable
<DYN_WA> has same effect as your <HEADER>
REPORT ZTEST_NP_DYNAMIC.
DATA: DY_TABLE TYPE REF TO DATA,
DY_LINE TYPE REF TO DATA.
FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>,
<DYN_FIELD>.
FIELD-SYMBOLS: <FS> TYPE ANY.
* To generate the Dyanmic table with the COLOR
DATA: LS_SOURCE TYPE STRING.
DATA: LT_SOURCE LIKE STANDARD TABLE OF LS_SOURCE WITH HEADER LINE.
DATA: L_NAME LIKE SY-REPID.
DATA: L_MESSAGE(240) TYPE C,
L_LINE TYPE I,
L_WORD(72) TYPE C.
DATA: L_FORM(30) TYPE C VALUE 'TABLE_CREATE'.
LT_SOURCE = 'REPORT ZTEST_SUBROUTINE_POOL.'.
APPEND LT_SOURCE.
LT_SOURCE = 'FORM TABLE_CREATE USING I_FS TYPE ANY.'.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: BEGIN OF LT_GENTAB OCCURS 0.'.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: BUKRS TYPE BUKRS. '.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: BKTXT TYPE BKTXT. '.
APPEND LT_SOURCE.
* you can add your fields here.....
LT_SOURCE = 'DATA: COLOR TYPE lvc_t_scol. '.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: END OF LT_GENTAB.'.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: POINTER TYPE REF TO DATA.'.
APPEND LT_SOURCE.
LT_SOURCE = 'CREATE DATA POINTER LIKE STANDARD TABLE OF LT_GENTAB.'.
APPEND LT_SOURCE.
LT_SOURCE = 'I_FS = POINTER.'.
APPEND LT_SOURCE.
LT_SOURCE = 'ENDFORM. '.
APPEND LT_SOURCE.
L_NAME = 'ZTEST_SUBROUTINE_POOL'.
CATCH SYSTEM-EXCEPTIONS GENERATE_SUBPOOL_DIR_FULL = 9.
GENERATE SUBROUTINE POOL LT_SOURCE NAME L_NAME
MESSAGE L_MESSAGE LINE L_LINE WORD L_WORD. "#EC CI_GENERATE
ENDCATCH.
IF NOT L_MESSAGE IS INITIAL.
MESSAGE E000(0K) WITH L_MESSAGE L_LINE L_WORD.
ENDIF.
ASSIGN DY_TABLE TO <FS>.
PERFORM (L_FORM) IN PROGRAM (L_NAME) USING <FS>.
ASSIGN DY_TABLE->* TO <DYN_TABLE>.
* Create dynamic work area and assign to FS
CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.
ASSIGN DY_LINE->* TO <DYN_WA>.
Write: 'bye'.
Regards,
Naimesh Patel -
EXTREME Dynamic List of Field Symbols
Hi All,
This requirement have created lots of issues fo me and oculd not reach it, hence i am here :
Internal table 1 with 'a' columns Internal Table 2 with 'b' columns
a1 a2 a3 b1 b2 b3
11 22 150 10 20 30
Note: BOTH ARE FIELD-SYMBOL INTERNAL TABLE of TYPE ANY and HAVE NO STRUCTURE UNTIL RUNTIME
What I want is a
- Get a List of How many columns are in FIELD SYMBOL Internal Table 1 at RUNTIME.
- DYNAMIC MAPPING TABLE that reads the HEADER OF COLUMNS and its DATA maps them in a Internal table at RUNTIME.
Col1 Col2 Col3 Col4
a1 11 b1 10
a2 22 b2 20
a3 150 b3 30Hi,
- Get a List of How many columns are in FIELD SYMBOL Internal Table 1 at RUNTIME.
You will have to use RTTS class for that. Something like:
lo_sdescr ?= cl_abap_typedescr=>describe_by_data_ref( lo_data ). "lo_data containing ref. to your field-symbols
LOOP AT lo_sdescr->components INTO ls_component.
ENDLOOP
- DYNAMIC MAPPING TABLE that reads the HEADER OF COLUMNS and its DATA maps them in a Internal table at RUNTIME.
I don't see the need of a dynamic itab here, since the number/type of column seems to be fixed...
If needed, build it up using RTTS as well.
Kr,
m. -
Dynamic SELECT with FOR ALL ENTRIES IN: take 2
Hello Xperts,
we are now having a bit of new trouble with the following SELECT ... special thanks to Raul and Suhas for their previous contributions.
FIELD-SYMBOLS:
<itab1> TYPE standard table.
ASSIGN ATTR_T_I->* TO <itab1>.
select
FIELD1
FIELD2
from DBTAB1
into CORRESPONDING FIELDS OF table <itab1>
FOR ALL ENTRIES IN <itab1>
where
(condition).
ATTR_T_I is a static attibute of type table containing 10 records where all records have FIELD1 and FIELD2 empty.
The select finds in DBTAB1 entries fulfilling the 'condition' for 8 of the above 10 records in ATTR_T_I.
Hence, after the select 8 of the 10 records in ATTR_T_I have the fields FIELD1 and FIELD2 filled (ie not empty).
So far so good!
BUT: the 2 remaining records (i.e. those without entries in DBTAB1 fullfilling 'condition') have been deleted! Why? This is not what we want nor expected.
Any ideas out there how to fix this?
Thanx!Martin Helmstein wrote:
> Yes, 'condition' contains all the key fields of DBTAB1.
Hi Martin,
It's not the Where condition fields i was talking about. I was referring to the Select fields, you have to SELECT all the keyfields when using FAE. Something like this:
SELECT key1 key2 ... keyn "all the key fields of the table
field1 field2 ... fieldn
FROM table
INTO CORRESPONDING FIELDS OF it_data
FOR ALL ENTRIES IN <itab>
WHERE (condition).
You can search in the forums for further details. It has been discussed many a times.
BR,
Suhas -
Dynamic SELECT with FOR ALL ENTRIES IN
Hello Xperts,
we are having a bit of trouble with the following SELECT
FIELD-SYMBOLS:
<itab1> TYPE standard table.
ASSIGN ATTR_T_I->* TO <itab1>.
select
FIELD1
FIELD2
from DBTAB1
into CORRESPONDING FIELDS OF table <itab1>
FOR ALL ENTRIES IN <itab1>
where
FIELD3 = <itab1>-FIELD3 and
FIELD4 = <itab1>-FIELD4
ATTR_T_I is a static attibute of type table.
The syntax check throws the following message:
The specified type has no structure and therefore no component called FIELD3.
Any ideas out there how to solve this issue?
Thanx!Hi Martin,
Change your code like this and try.
DATA: itab2 TYPE TABLE OF string.
FIELD-SYMBOLS:
<itab1> TYPE standard table.
ASSIGN ATTR_T_I->* TO <itab1>.
APPEND 'FIELD3 = <itab1>-FIELD3 and' TO itab2.
APPEND 'FIELD4 = <itab1>-FIELD4' TO itab2.
select
FIELD1
FIELD2
from DBTAB1
into CORRESPONDING FIELDS OF table <itab1>
FOR ALL ENTRIES IN <itab1>
where
(itab2)
Regards,
Rahul Muraleedharan. -
How to do dynamic selection for fields
Hi,
Can you please help me on this.
I am adding the custom fields to the standard trasactions CJI3, CJI4, CJI5 for dispalying the line items. For this I am using COOMEP01 CO-OM: Information system -> line item reports enhancement.
I am displaying the custom fileds for line items.
The problem is...In all three t.codes I am having dynamic selection icon. user wants, selection is based on my custom fields...How to get my custom fileds on the selection screen?
Please assist me as soon.
Regards,
RaviHai reddy
This example shows how different transactions codes can be used to produce different selection options for the same program. The example allows for lookups on Sales Order number, Purchase Order Number, Delivery Number or Invoice number.
*--- SELECTION OPTIONS -
SELECTION-SCREEN BEGIN OF BLOCK SO WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,"Sales order number
S_VBELND FOR LIKP-VBELN,"Delivery number
S_VBELNI FOR VBRK-VBELN,"Invoice number
S_VBELNP FOR VBKD-BSTKD."PO number
SELECTION-SCREEN END OF BLOCK SO.
*--- EVENT AT SCREEN OUTPUT -
AT SELECTION-SCREEN OUTPUT.
CASE SY-TCODE.
WHEN 'ZEDI6'.
LOOP AT SCREEN.
CASE SCREEN-GROUP4.
WHEN '001'. "Sales order select
SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '002'. "Delivery select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '003'. "Invoice select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '004'. "PO Select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
WHEN 'ZEDI6D'. "Delivery select
LOOP AT SCREEN.
CASE SCREEN-GROUP4.
WHEN '001'. "Sales order select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '002'. "Delivery select
SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '003'. "Invoice select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '004'. "PO Select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
WHEN 'ZEDI6I'. "Invoice select
LOOP AT SCREEN.
CASE SCREEN-GROUP4.
WHEN '001'. "Sales order select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '002'. "Delivery select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '003'. "Invoice select
SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '004'. "PO Select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
WHEN 'ZEDI6P'. "PO select
LOOP AT SCREEN.
CASE SCREEN-GROUP4.
WHEN '001'. "Sales order select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '002'. "Delivery select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '003'. "Invoice select
SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display
MODIFY SCREEN.
WHEN '004'. "PO Select
SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
ENDCASE.
Thanks & regards
Sreenivasulu P -
Hi!
I have a problem with a field-symbol like this:
DATA: gt_coep_ext TYPE kaep_t_coep_ext.
field-symbols <gt_data> type table.
ASSIGN gt_coep_ext TO <gt_pos_data>
This field symbol is used in the FM REUSE_ALV_GRID_DISPLAY as output table. I need add two fields in this <gt_data>. Is there any way to add new fields in the <gt_data> structure.
Thanks!!Create your one Fieldcat
Global data declaration ***
TYPE-POOLS: SLIS.
<types: ... . " user definded types>
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: G_REPID LIKE SY-REPID.
DATA: GT_OUTTAB TYPE <UD_STRUCT> OCCURS 0 WITH HEADER LINE.
<data: ... . " user specific data>
Initialization field catalog ***
INITIALIZATION.
G_REPID = SY-REPID.
PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].
Data selection ***
START-OF-SELECTION.
PERFORM SELECT_DATA TABLES GT_OUTTAB.
Display list ***
END-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IT_FIELDCAT = GT_FIELDCAT[]
TABLES
T_OUTTAB = GT_OUTTAB.
FORMS ***
FORM FIELDCAT_INIT USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: POS TYPE I VALUE 1.
Initialize keyfield(s)
CLEAR LS_FIELDCAT.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = <GT_OUTTAB_FIELD_NAME>.
LS_FIELDCAT-REF_FIELDNAME = <DDIC_REF_FIELD_NAME>.
LS_FIELDCAT-REF_TABNAME = <DDIC_REF_TABLE_NAME>.
LS_FIELDCAT-KEY = 'X'. " sets key field
APPEND LS_FIELDCAT TO RT_FIELDCAT.
Initialize normal field(s)
POS = POS + 1.
clear ls_fieldcat.
ls_fieldcat-col_pos = pos.
LS_FIELDCAT-FIELDNAME = <GT_OUTTAB_FIELD_NAME>.
LS_FIELDCAT-REF_FIELDNAME = <DDIC_REF_FIELD_NAME>.
LS_FIELDCAT-REF_TABNAME = <DDIC_REF_TABLE_NAME>.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
Initialize hidden field(s)
POS = POS + 1.
clear ls_fieldcat.
ls_fieldcat-col_pos = pos.
LS_FIELDCAT-FIELDNAME = <GT_OUTTAB_FIELD_NAME>.
LS_FIELDCAT-REF_FIELDNAME = <DDIC_REF_FIELD_NAME>.
LS_FIELDCAT-REF_TABNAME = <DDIC_REF_TABLE_NAME>.
LS_FIELDCAT-NO_OUT = 'X'. " sets hidden field
APPEND LS_FIELDCAT TO RT_FIELDCAT.
ENDFORM. " fieldcat_init
FORM SELECT_DATA TABLES RT_OUTTAB LIKE GT_OUTTAB[].
<user specific data selection>
ENDFORM. " select_data -
Dynamic selections with FBL1N transaction
Hello,
I want to add new fields to do dynamic selections using FBL1N transaction.
I have "House bank" field in the company code fields, but I want this field in the document fields.
How could I do it?
Thank you very muchDear Beatriz
Yes this is possible. You need to extend the selection view for the logical database KDF using transaction SE36, to have more selection fields available in the dynamic selections of the line item display.
Call up Transaction SE36 and enter the logical database KDF.
Choose "Extras --> Selection views".
Select the origin of view.
Choose "Display" or "Change".
Vendors: logical database: KDF
Permitted tables:
LFA1, LFB1: All fields are permitted that are contained in the VF_KRED
view. If necessary, you have to include additional fields in
the view fields category using Transaction SE11.
BSIK: all fields
Change the source code in program SAPDBKDF, Form INIT as explained in the SAP note 310886.
If this helps please reward with points.
Best Regards
Kesav
Maybe you are looking for
-
How do i reformat a external hard drive and how do i partition a drive?
hi, i have a seagate free agent desk 1.5 tb external harddrive! i have the back up software installed on the home pc. i have a macbook now! so i still want to be able to use the pc for photos and stuff because if i were to transfer everything onto th
-
Blank page on Windows 2003 server.
Hi there, I got a blank page on a fresh apex install on a fresh integrated webserver install. It just moves to: http://localhost/pls/apex/apex then in IE 6 it just shows a blank page, anybody any idea? Thanks so much....
-
Re: Qosmio F750 EasyControl Volume bar - illuminated or not?
On the EasyControl panel between the two volume adjustment buttons (+ and -) is a strip of the volume level. It is illuminated, glowing or it is just a innactive figure? What is it for? On promo pictures i saw it glowing For example [here|http://imag
-
Hello, We upgraded our database to 10g 10.2.0 from 9.0. After upgradatiion we cannot see snapshots under schema browser. However using SQl Developer we could see all the snapshots. What could be the reason for this? Thanks
-
Error in Appraisal HAP_DOCUMENT bsp appliation - Weight zero for objectives
Error in Appraisal HAP_DOCUMENT bsp appliation - My client requirement is to store appraisal document with induvidual performance objectives even with zero (0.00) weighting. But on processing (saving/navigating to next status), standard business chec