Application Development 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: 

update the table

Former Member
0 Kudos

hi guyz ,

i wanna update the table with cancellation code in the table...this is my code..structure contains the updated field but table doesnt...

LOOP AT gt_header INTO gs_header.

IF NOT gs_header-to_number IS INITIAL.

gs_header-canx_code = '99'.

ELSE.

gs_header-canx_code = '00'.

ENDIF.

ENDLOOP.

CHECK NOT gt_header[] IS INITIAL.

UPDATE ztcptab_orderhdr FROM TABLE gt_header.

IF sy-subrc = 0.

COMMIT WORK AND WAIT.

ENDIF.

Thanks

1 ACCEPTED SOLUTION

Vijay
Active Contributor
0 Kudos

hi

try like this if u have multiple records in gt_header

create another internal table <b>gt_header1</b> of type gt_header.

______________________________________________________________

LOOP AT gt_header INTO gs_header.

IF NOT gs_header-to_number IS INITIAL.

gs_header-canx_code = '99'.

ELSE.

gs_header-canx_code = '00'.

ENDIF.

append gs_header to gt_header1.

ENDLOOP.

CHECK NOT <b>gt_header1[]</b> IS INITIAL.

UPDATE ztcptab_orderhdr FROM TABLE <b>gt_header1</b>.

IF sy-subrc = 0.

COMMIT WORK AND WAIT.

ENDIF.

______________________________________________________________

regards

vijay

<b>reward points if helpfull</b>

5 REPLIES 5

amit_khare
Active Contributor
0 Kudos

You need to modify the internal table first with structure.

LOOP AT gt_header INTO gs_header.

IF NOT gs_header-to_number IS INITIAL.

gs_header-canx_code = '99'.

ELSE.

gs_header-canx_code = '00'.

ENDIF.

<b>modify gt_header by gs_header transporting canx_code.</b>

ENDLOOP.

former_member386202
Active Contributor
0 Kudos

Hi,

Try like this

&----


*& Form SUB_READ_UPDATE_BSEG

&----


  • text

----


FORM sub_read_update_bseg.

IF NOT it_final[] IS INITIAL.

LOOP AT it_final INTO wa_final.

UPDATE bseg SET zuonr = wa_final-ccnum

WHERE bukrs EQ wa_final-bukrs

AND belnr EQ wa_final-vbeln

AND rfzei EQ wa_final-rfzei

AND saknr NE ' '.

ENDLOOP.

*--Message data updated successfully

MESSAGE i888 WITH text-002.

LEAVE LIST-PROCESSING.

ELSE.

*--Message No data found

MESSAGE i888 WITH text-003.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " SUB_READ_UPDATE_BSEG

Regards,

Prashant

Former Member
0 Kudos

Hi Sudheer,

Try this,

LOOP AT gt_header INTO gs_header.

IF NOT gs_header-to_number IS INITIAL.

gs_header-canx_code = '99'.

ELSE.

gs_header-canx_code = '00'.

ENDIF.

ENDLOOP.

CHECK NOT gt_header[] IS INITIAL.

MODIFY ztcptab_orderhdr FROM gt_header.

IF sy-subrc = 0.

COMMIT WORK AND WAIT.

ENDIF.

    • Please make sure that before modifying , you use dequeue and enqueue to avoid locking of tables.

Reward if useful.

Regards,

Chitra

Former Member
0 Kudos

Use Modify statement instead of Update and lock the table using Enque before modifying it.

Vijay
Active Contributor
0 Kudos

hi

try like this if u have multiple records in gt_header

create another internal table <b>gt_header1</b> of type gt_header.

______________________________________________________________

LOOP AT gt_header INTO gs_header.

IF NOT gs_header-to_number IS INITIAL.

gs_header-canx_code = '99'.

ELSE.

gs_header-canx_code = '00'.

ENDIF.

append gs_header to gt_header1.

ENDLOOP.

CHECK NOT <b>gt_header1[]</b> IS INITIAL.

UPDATE ztcptab_orderhdr FROM TABLE <b>gt_header1</b>.

IF sy-subrc = 0.

COMMIT WORK AND WAIT.

ENDIF.

______________________________________________________________

regards

vijay

<b>reward points if helpfull</b>