2008 Jul 02 3:44 AM
Hi Friends,
I am getting the dump when i am trying to modify the internal table form work area.
here is the code..
Data: ls_data type zls_header,
gt_data type table of zls_header.
ls_data-status = 'Submitted'.
Modify gt_data from ls_data.
this is going for dump
but when i code
MODIFY GT_DATA FROM LS_DATA
TRANSPORTING STATUS
WHERE INVCNUM = LS_DATA-INVCNUM AND
INVCDT = LS_DATA-INVCDT.
This is working fine
I want to know what is making the former statement go for dump?????
Rgds,
Simha
Edited by: Simha on Jul 2, 2008 4:44 AM
2008 Jul 02 4:26 AM
in the first case when you say to modify its unable to find out which index( which record) to modify..
in the second case you are specifying the index using where clause.. so its able to proceed.
2008 Jul 02 4:38 AM
>
> Hi Friends,
>
> I am getting the dump when i am trying to modify the internal table form work area.
>
> here is the code..
>
>
> Data: ls_data type zls_header, > gt_data type table of zls_header. > > ls_data-status = 'Submitted'. > Modify gt_data from ls_data. >> this is going for dump
>
> but when i code
>
> MODIFY GT_DATA FROM LS_DATA > TRANSPORTING STATUS > WHERE INVCNUM = LS_DATA-INVCNUM AND > INVCDT = LS_DATA-INVCDT. >> This is working fine
>
> I want to know what is making the former statement go for dump?????
>
> Rgds,
> Simha
>
> Edited by: Simha on Jul 2, 2008 4:44 AM
Add the keyword TABLE in the MODIFY statement.
Modify TABLE gt_data from ls_data.
Check the following extract from SAP help documentation
Addition 1
... TABLE itab
Effect
The line to be changed is determined by the fact that the content of the table key matches the content of the corresponding components in the wa work area. For tables with a key that is not unique, the first entry that is found is changed.
If you only have to change one record of the internal table, then ensure that
key of the ls_data matches with the table key entry that need to be modified
If you have to change all the records in the internal table, I reckon you have to do
that in a LOOP ENDLOOP.
Edited by: Rajesh on Jul 2, 2008 9:12 AM
2008 Jul 02 5:07 AM
Hi Rajesh,
Thanks for your inputs.
Well, i tried adding "Table" to the modify statement but its return code is 4.
I could understand that its not able to find the key.
But when we usually generate the field catalog and want to change the table for a particular column,
we do
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
here this statement works perfect.
All i understand is, key is not identified properly in the former statement. But here they are standard tables. So how do we know what forms the key unless we specify in declaration.
So in this case why is it working for fieldcat internal table and not for this data internal table.
Thanks,
Simha
2008 Jul 02 5:12 AM
to work in all the cases better catch the index like sy-index or in loop sy-tabix and update the record.
loop at itab
modify itab from wa_itab index sy-tabix.
endloop.
2008 Jul 02 5:30 AM
Hi Simha,
Please let us know the order and technical details of all fields in the work area zls_header.
2008 Jul 02 5:40 AM
Below is the structure of ZLS_header
Field Name Type length
LED CHAR 5
APSTAFF CHAR 12
STATUS CHAR 30
ZBUKRS CHAR 4
INVCNUM CHAR 30
INVCDT DATS 8
ZLIFNR CHAR 10
VNDRNAME CHAR 80
PONUM CHAR 30
ZEBELN CHAR 10
CURR CHAR 3
FRTAMNT DEC 23
GSTAMNT DEC 23
GROSSAMNT DEC 23
GSTREGNUM CHAR 12
CO CHAR 12
COAPRVD CHAR 10
AO CHAR 12
AOAPRVD CHAR 10
INVCTYPE CHAR 10
COPNUM CHAR 50
CHKSTAFF CHAR 12
ZKOSTL CHAR 10
ACCDOCNUM CHAR 10
PAYDOCNUM CHAR 10
ZDESC CHAR 254
Edited by: Simha on Jul 2, 2008 6:41 AM
2008 Jul 02 5:50 AM
Hi Simha,
Can you also provide a piece of code where you were able to execute the MODIFY statement successfully with out the TABLE addition(not within LOOP ENDLOOP), at least the code below
returns the value of SY-SUBRC as 4 for me.
DATA:
t_fieldcat TYPE lvc_t_fcat,
w_fieldcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'MARA'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = t_fieldcat
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_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.
w_fieldcat-edit = 'X'.
w_fieldcat-outputlen = 12.
MODIFY TABLE t_fieldcat FROM w_fieldcat.
WRITE: sy-subrc.
Edited by: Rajesh on Jul 2, 2008 10:23 AM
2008 Jul 02 6:00 AM
here it goes.
DATA: LS_FIELDCAT TYPE LVC_S_FCAT.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZLS_APSTAFF'
CHANGING
CT_FIELDCAT = GT_FIELDCAT100.
LOOP AT GT_FIELDCAT100 INTO LS_FIELDCAT.
CASE LS_FIELDCAT-FIELDNAME.
WHEN 'APSTAFF'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
LS_FIELDCAT-REF_TABLE = ' '.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
CLEAR LS_FIELDCAT.
WHEN 'CO'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
LS_FIELDCAT-F4AVAILABL = 'X'.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
CLEAR LS_FIELDCAT.
WHEN 'AO'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
LS_FIELDCAT-F4AVAILABL = 'X'.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
CLEAR LS_FIELDCAT.
WHEN 'INVCTYPE'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
LS_FIELDCAT-DRDN_HNDL = '1'.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
CLEAR LS_FIELDCAT.
WHEN 'COPNUM'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
CLEAR LS_FIELDCAT.
WHEN 'CHKSTAFF'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-OUTPUTLEN = 12.
LS_FIELDCAT-F4AVAILABL = 'X'.
MODIFY GT_FIELDCAT100 FROM LS_FIELDCAT.
CLEAR LS_FIELDCAT.
ENDCASE.
ENDLOOP.
I checked the return code in my case and i am getting 0 here
2008 Jul 02 9:09 AM
Hi Simha,
Case 1
Check this sample code, which returns the sy-subrc as 0,
TYPES:
BEGIN OF zls_header,
matnr TYPE mara-matnr,
status TYPE char40,
END OF zls_header.
DATA: ls_data TYPE zls_header,
gt_data TYPE TABLE OF zls_header WITH KEY matnr.
ls_data-matnr = '10'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '20'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '30'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '40'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '20'.
ls_data-status = 'Submitted'.
MODIFY TABLE gt_data FROM ls_data.
WRITE : sy-subrc.
Case 2
The code below returns sy-subrc as 4
TYPES:
BEGIN OF zls_header,
matnr TYPE mara-matnr,
status TYPE char40,
END OF zls_header.
DATA: ls_data TYPE zls_header,
gt_data TYPE TABLE OF zls_header.
ls_data-matnr = '10'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '20'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '30'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '40'.
ls_data-status = 'In process'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-matnr = '20'.
ls_data-status = 'Submitted'.
MODIFY TABLE gt_data FROM ls_data.
WRITE : sy-subrc.
The difference in case 1 and case 2 is the internal table declaration
gt_data TYPE TABLE OF zls_header WITH KEY matnr.
Since, we have explicitly defined the key in case 1, the system is able to identify the key, same is the case in the program you have provided(as you are modifying the internal table in the LOOP...ENDLOOP the work area is filled with all the relevant key fields, so that the system can indentify the record with identical key in the internal table).
To learn more about KEY specification in internal table decalrations, check the links
below
http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3646358411d1829f0000e829fbfe/content.htm
2008 Jul 02 9:24 AM
Hi Rajesh,
Thanks for your patient help.
Well in both of my cases, i had a standard internal table with out key, but in one case i get sy-subrc 0 and other case i get 4.
Thats what i am surprised about and was only curious whether i am missing something v basic.
Not only with respect to fieldcat, i have a similar code which is working fine when i use modify itab from wa
Any ways i am using where clause to modify the row of itab.
Thanks a lot for your help.
Regards,
Simha
i have given u the points and marking this as answered
2008 Jul 02 4:41 AM
modify internal table from work area , works only with in loop.
do as given below:
Data: ls_data type zls_header,
gt_data type table of zls_header.
ls_data-status = 'Submitted'.
loop at gt_data into ls_data.
ls_data-statu = 'Submitted'.
Modify gt_data from ls_data.
endloop.
the below code worked because you are modifying based on a particular key.
MODIFY GT_DATA FROM LS_DATA
TRANSPORTING STATUS
WHERE INVCNUM = LS_DATA-INVCNUM AND
INVCDT = LS_DATA-INVCDT.
2008 Jul 02 4:58 AM
hi....
i hjave faced this problem earlier.....
modify itab from wa.
You can use modify itab from wa index tab.
use the index extension it will not give any dump then..just try and lemme know....
2013 Aug 14 3:48 PM
2008 Jul 02 6:04 AM
The former statement giving dump as you have not mentioned the 'TRANSPORTING' key word.
The 'TRANSPORTING' key word makes it understand that which field of the Work Area to be transported to update the Internal Table,
The 'WHERE' clause identifies the record that needs to be updated.
But while Modifying an Internal Table within a loop then it's better practice to use 'INDEX' it's the best approach
Syntax:
loop at i_tab into wa_tab.
idx = sy-tabix.
wa_tab-field1 = 'EUR'.
MODIFY i_tab INDEX idx FROM wa_tab
TRANSPORTING field1.
endloop.