Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

update data from work area

Former Member
0 Likes
4,247

dear gurus,

i want update records from internal table to customized table with same structure.

provide me the simplest method to do the needful.

regards

R.Rajendran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,221

Hi

Try this :

Data: it_mara type mara occurs 0.

*Now Fill the internal table it_mara like

it_mara-matnr = '12345'.

*etc.

now modify the customized mara table with ur it_mara

ie

modify mara with table it_mara.

This will do the work

Thanks & Regards

vinsee

11 REPLIES 11
Read only

sachin_mathapati
Contributor
0 Likes
3,221

MODIFY dbtab FROM TABLE itab..

Effect :

Mass modify: Inserts new lines or updates existing lines of a database table. The primary keys for identifying the lines to be inserted or updated and the relevant values are taken from the internal table itab. The lines of the internal table itab must satisfy the same conditions as the work area wa in addition 1 to variant 1.

Read only

former_member195383
Active Contributor
0 Likes
3,221

declare a table of the type same as the ZTABLE..

Then populate the internal table with the reqd. values..in ur program....

Then write as..

modify ztable from itab.

here itab is the internal table that u r filling in ur program...

Reward points...if useful.....

Read only

Former Member
0 Likes
3,221

Hi,

Syntax:

UPDATE dbtab FROM TABLE itab.

The system field SY-DBCNT contains the number of updated lines, i.e. the number of lines in the internal table itab which have key values corresponding to lines in the database table.

When you update records from internal table return code is also set i.e SY-SUBRC

if SY-SUBRC = 0.

All lines from itab could be used to update the database table.

if SY-SUBRC = 4. Then

At least one line of the internal table itab in the database table had no line with the same primary key. The other lines of the database table were updated.

if the internal table is empty then SY-SUBRC and SY-DBCNT set to 0.

Regards,

Rajitha.

Read only

0 Likes
3,221

Hi,

please tell me declaring statement.

regards

R.Rajendran

Read only

Former Member
0 Likes
3,222

Hi

Try this :

Data: it_mara type mara occurs 0.

*Now Fill the internal table it_mara like

it_mara-matnr = '12345'.

*etc.

now modify the customized mara table with ur it_mara

ie

modify mara with table it_mara.

This will do the work

Thanks & Regards

vinsee

Read only

0 Likes
3,221

Dear vinoth,

Is the following syntax correct?

loop at i_itab.

select single * from znprd_mis into corresponding fields of i_itab where pdate eq i_itab-pdate and sloc eq i_itab-sloc and matnr eq i_itab-matnr.

if sy-subrc eq 0.

modify znprd_mis from table i_itab.

else.

insert znprd_mis with table i_itab.

endif.

commit work.

endloop.

Regards

R.Rajendran

Read only

0 Likes
3,221

Hi..

first u are selecting in to internal table from the table znprd_mis...and then trying to update the same ztable with that internal table...so there is no meaning of modifying the table..

In the else part u are deleting the entry...that also wont work...b'coz there wont be any entry in the internal table...so...there is no records to delete...

Read only

0 Likes
3,221

Dear gurus,

I want upload data from xl file to ztable.

Please correct my program.

REPORT yr_PDN_UPLOAD .

tables : znprd_mis.

data : upcnt type p,

uncnt type p.

data : i_itab type znprd_mis occurs 0.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'd:\raj\nprd.prn'

TABLES

DATA_TAB = i_itab

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear i_itab.

loop at i_itab.

modify znprd_mis with table i_itab.

commit work.

endloop.

Regards

Read only

Former Member
0 Likes
3,221

hi.....

use modify dtab from table itab.

here if the entry already exists then it will be modified and if the entry does not exist then it will be inserted.

this is the simplest way to add entries to your custmized table.

the structure of itab and customized table should be same.

Edited by: shlesha K on Jul 4, 2008 6:08 AM

Read only

Former Member
0 Likes
3,221

Hi Rajendran, your code is a good one but you can use the code below...

REPORT yr_PDN_UPLOAD .

*Don't use TABLES as it occupies memory space as the whole

*structure of that table preoccupies memory spaces

*tables : znprd_mis.

DATA : upcnt type p,

uncnt type p.

*don't use occurs instead use initial size to save preoccupied

*memory space and use Work Area as Header Line are obsolete

*in SAP

*data : i_itab type znprd_mis occurs 0.

DATA:

  • Internal table for znprd_mis.

i_tab TYPE STANDARD TABLE OF znprd_mis INITIAL SIZE 0,

  • Work area for znprd_mis.

wa_tab type znprd_mis.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'd:\raj\nprd.prn'

TABLES

DATA_TAB = i_tab

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear wa_tab.

loop at i_tab into wa_tab.

modify znprd_mis from wa_tab.

if sy-subrc = 0.

commit work.

endif.

endloop.

*The MODIFY statement will update the Z-table if there is record

*with same primary key value if no record exists with the primary

*key value then it will insert a new record in Z-table.

Reward if helpfull

Edited by: Apan Kumar Motilal on Jul 4, 2008 6:54 AM

Read only

0 Likes
3,221

Dear gurus,

After finding the syntax & coding the below program is working fine. Thanks to all for helped me.

REPORT YR_data_UPLOAD .

TABLES : ZNPRD_MIS.

DATA : UPCNT TYPE P,

UNCNT TYPE P.

DATA : I_ITAB TYPE TABLE OF ZNPRD_MIS WITH HEADER LINE.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'd:\raj\nprd.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = '#'

TABLES

DATA_TAB = I_ITAB[]

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CLEAR I_ITAB.

MODIFY ZNPRD_MIS FROM TABLE I_ITAB[].

COMMIT WORK.

Regards

R.Rajendran