2008 Jun 17 9:45 PM
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
Srinivas
2008 Jun 17 10:45 PM
Hello.
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.
2008 Jun 17 10:45 PM
Hello.
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.
2008 Jun 18 12:22 AM
Hi Valter,
done the changes as per your suggestions,but still iam getting the syntax error.
when iam about to assign the value <fs1>-salk3 ='123'.
the following error i got is
The data object <fs1> has no structure and therefore no component called SALK3.
I declared fieldsymbol <fs1> as
FIELD-SYMBOLS: <FS1> type any .
Please help me in resolving this issue.
Thanks in adavance
Srinivas
2008 Jun 18 4:54 AM
Hi Srinivas,
Declare ur field symbol FS1 as below. It will works fine.
FIELD-SYMBOLS: <FS1> TYPE mbew.
Thanks,
Vinod.
2008 Jun 18 12:09 PM
Hello.
Vinod is right. If you did the change I suggested, that field symbol must have the structure of mbew, otherwise, using type ANY, it has no structure itself.
In other words, you shoud define field-symbol TYPE ANY, when you are using it dinamically, i.e, you don't know the type of structure you will ASSIGN. In your case, you know.
Reward if helpfull.
Regards,
Valter Oliveira.
2008 Jun 19 8:00 PM
Thanks for all you for giving me inputs...Now i will try from myside.
Thanks
Srinivas Manda