cancel
Showing results for 
Search instead for 
Did you mean: 

Plz make me understand the code!!!!!!!!!!

Former Member
0 Kudos

Dear All,

I am giving you the code below. Please any one can explain me the whole program and the purpose. specially form LOOP section to the end of the program.

I will be very kind if someone will help to make me understood.

Regards,

Abhay.

TABLES:bseg.

DATA: it_bseg LIKE bseg OCCURS 0 WITH HEADER LINE.

DATA: it_zseco LIKE zseco OCCURS 0 WITH HEADER LINE.

*DATA: it_zseco TYPE zseco OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS:s_bukrs FOR bseg-bukrs,

s_gjahr FOR bseg-gjahr,

s_belnr FOR bseg-belnr.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

PERFORM get_data.

&----


*& Form get_data

&----


FORM get_data .

SELECT *

FROM bseg INTO TABLE it_bseg

WHERE belnr IN s_belnr AND

bukrs IN s_bukrs AND

gjahr IN s_gjahr.

IF sy-subrc = 0.

LOOP AT it_bseg .

MOVE-CORRESPONDING it_bseg TO it_zseco.

it_zseco-bupla_old = it_bseg-bupla.

it_zseco-zdate = sy-datum.

it_zseco-usernam = sy-uname.

it_zseco-ztime = sy-uzeit.

IF it_bseg-bupla NE 'B001'.

it_bseg-bupla = 'B001'.

MODIFY it_bseg.

ENDIF.

it_zseco-bupla_new = 'B001'.

APPEND it_zseco.

CLEAR it_zseco.

ENDLOOP.

MODIFY bseg FROM TABLE it_bseg.

MODIFY zseco FROM TABLE it_zseco.

MESSAGE i000 WITH 'tables BSEG & ZSECO updated successfully'.

ELSE.

MESSAGE i000 WITH 'No data found'.

ENDIF.

Accepted Solutions (1)

Accepted Solutions (1)

naimesh_patel
Active Contributor
0 Kudos

This program is updating to tables BSEG and ZSECO.

In the LOOP of the IT_BSEG, it is modifying BUPLA of the IT_BSEG and appending the values in the IT_ZSECO.

After the LOOP, it is trying to update both the tables with the vales from the internal table.

But, it not <b>ADVISABLE</b> to update the database table IT_BSEG. This table is a cluster table of so many other tables. Please contact your system administration on this concern.

Regards,

Naimesh Patel

Answers (2)

Answers (2)

former_member1345686
Active Participant
0 Kudos

LOOP AT it_bseg . " reading table it_bseg sequentially

" fill the it_bseg values into it_zseco field which has the same fieldname

MOVE-CORRESPONDING it_bseg TO it_zseco.

" change some fields in it_zseco with the given values

it_zseco-bupla_old = it_bseg-bupla.

it_zseco-zdate = sy-datum. " current date

it_zseco-usernam = sy-uname. " current user ID

it_zseco-ztime = sy-uzeit. " current time

" Hardcode the values of it_bseg-bupla to B001

" Only change the specified record to save run time ( modify takes a longer time )

IF it_bseg-bupla NE 'B001'.

it_bseg-bupla = 'B001'.

MODIFY it_bseg.

ENDIF.

" change field bupla_new in it_zseco with the given values

it_zseco-bupla_new = 'B001'.

" append the current header values of it_zseco to its record

APPEND it_zseco.

" clear the header of it_zseco

CLEAR it_zseco.

ENDLOOP.

" Check if it_bseg and bseg has different values, update the values in table BSEG

" This kind of method should not be performed, since BSEG is a standard SAP table

MODIFY bseg FROM TABLE it_bseg.

" Check if it_zseco and zseco has different values, update the values in table zseco

MODIFY zseco FROM TABLE it_zseco.

    • HERE IN THIS LINE You should add IF SY-SUBRC = 0

MESSAGE i000 WITH 'tables BSEG & ZSECO updated successfully'.

ELSE.

MESSAGE i000 WITH 'No data found'.

ENDIF.

raymond_giuseppi
Active Contributor
0 Kudos

This program updates BSEG <i>(wild and not advisable)</i> and insert into a Z-table.

In the BSEG loop it modifies BSEG-BUPLA

- But it leaves records unchanged in the internal table (so update database with same data...) add a delete it_bseg if it_bseg-bupla already equal 'B001'.

- It uses MODIFY BESG where UPDATE would give better performance

- It update a standard database without reporting changes to other tables of FI application, in peculiar secondary index table like <b>BSIS, BSAS, BSID, BSAD</b>, etc. <b>THIS IS NOT CORRECT</b> - use a CALL TRANSACTION FB09 or a suitable BAPI for that (i don't know one) insure also in Customizing that thos field is changeable on finacial document item.

I suppose that the Z_table is filled here, so use INSERT and not MODIFY provided you only keep in internal table the actually modifier records.

Regards