06-21-2006 9:28 AM
Hi,
I have a hashed table and I am using field symbols to point to it to retrieve the field content. I then use it in the READ TABLE statement in the following way:
Loop at x_data assign <fs>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c1>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c2>.
READ TABLE ZZZZ assign <fs> with table key a1 = <c1>
a2 = <c2>.
If sy-subrc = 0.
endif.
I ran the debugger and I keep getting a 4. I am not able to get the value from a1 and a2 to see what it is and why it is causing a 4 sy-subrc. I know the value from the hashed table and the values c1 and c2 are the same, so the sy-subrc should be 0.
How would I read a hashed table using field symbols? I know that usig a standard table, I have to sort the table on the key fields() before I actually can do the READ TABLE using the binary search.
Please advise. Thanks
RT
06-21-2006 11:39 AM
Hi,
do you really have a component called 'xxx'. Anyway, it should be uppercase letters of an existing field in the structure like 'GJAHR' or 'BUKRS'.
Looks good for me.
Regards,
Clemens
06-21-2006 9:41 AM
Hi Thomas,
Check this Coding and u will definitely solve u r problem,
TYPES: BEGIN OF it_vbak_line,
vbeln LIKE vbak-vbeln,
vkorg LIKE vbak-vkorg,
vtweg LIKE vbak-vtweg,
spart LIKE vbak-spart,
kunnr LIKE vbak-kunnr,
END OF it_vbak_line.
DATA: it_vbak TYPE TABLE OF it_vbak_line.
FIELD-SYMBOLS: <it_vbak_line> TYPE it_vbak_line.
LOOP AT it_vbak ASSIGNING <it_vbak_line>.
look at records--populate it_zpartner
READ TABLE it_vbpa ASSIGNING <it_vbpa_line>
WITH TABLE KEY vbeln = <it_vbak_line>-vbeln.
IF sy-subrc = 0.
CLEAR: wa_zpartner.
wa_zpartner-mandt = sy-mandt.
wa_zpartner-vkorg = <it_vbak_line>-vkorg.
wa_zpartner-vtweg = <it_vbak_line>-vtweg.
wa_zpartner-spart = <it_vbak_line>-spart.
wa_zpartner-kunag = <it_vbak_line>-kunnr.
wa_zpartner-kunwe = <it_vbpa_line>-kunnr.
APPEND wa_zpartner TO it_zpartner.
ENDIF.
*
ENDLOOP.
alternatively at...
http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
Why u r using assign component before Read...? check once...
Regards,
Sridhar
06-21-2006 10:08 AM
Hai Rob
Go through the following Code
Field-Symbols are place holders for existing fields.
A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.
Field-Symbols are like Pointers in Programming language C .
Syntax check is not effective.
Syntax :
Data : v1(4) value abcd.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
Thanks & regards
Sreenivasulu P
06-21-2006 11:39 AM
Hi,
do you really have a component called 'xxx'. Anyway, it should be uppercase letters of an existing field in the structure like 'GJAHR' or 'BUKRS'.
Looks good for me.
Regards,
Clemens