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

Help me with this code

Former Member
0 Likes
834

Dear gurus.

This is my code please guide me where im wrong..

TABLES: vbap , vbup.

DATA: abc LIKE vbup OCCURS 1 WITH HEADER LINE.
DATA: status LIKE vbup-gbsta.

status = 'C'.

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECT-OPTIONS so FOR vbup-vbeln OBLIGATORY.
SELECT-OPTIONS li FOR vbup-posnr OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 100.



SELECTION-SCREEN: BEGIN OF TABBED BLOCK b2 FOR 4 LINES,
                  TAB (50) title USER-COMMAND '' DEFAULT SCREEN 100,
                  END OF BLOCK b2.

INITIALIZATION.
  title = 'Selection OF Sales Order And Line Items'.

START-OF-SELECTION.

  SELECT *
    FROM vbup
    INTO TABLE abc
    WHERE gbsta EQ 'A'
    AND lfgsa EQ 'A'
    AND absta EQ 'A'.

LOOP AT abc WHERE vbeln IN so AND posnr IN li.


    abc-gbsta = status.
    abc-lfgsa = status.
    abc-absta = status.

    vbup-gbsta = abc-gbsta.
    vbup-lfgsa = abc-lfgsa.
    vbup-absta = abc-absta.

    APPEND  abc.
    MODIFY vbup FROM TABLE abc.

  ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
743

This will run into infinite loop ...

LOOP AT abc WHERE vbeln IN so AND posnr IN li.

abc-gbsta = status.

abc-lfgsa = status.

abc-absta = status.

vbup-gbsta = abc-gbsta.

vbup-lfgsa = abc-lfgsa.

vbup-absta = abc-absta.

APPEND abc. <-- remove this statement

MODIFY vbup FROM TABLE abc.

ENDLOOP.

5 REPLIES 5
Read only

Former Member
0 Likes
744

This will run into infinite loop ...

LOOP AT abc WHERE vbeln IN so AND posnr IN li.

abc-gbsta = status.

abc-lfgsa = status.

abc-absta = status.

vbup-gbsta = abc-gbsta.

vbup-lfgsa = abc-lfgsa.

vbup-absta = abc-absta.

APPEND abc. <-- remove this statement

MODIFY vbup FROM TABLE abc.

ENDLOOP.

Read only

0 Likes
743

If i remove the append code

then the standard table vbup is not modified

it contains the same previous values.

Read only

0 Likes
743

LOOP AT abc WHERE vbeln IN so AND posnr IN li.
 
 
    abc-gbsta = status.
    abc-lfgsa = status.
    abc-absta = status.
 
    vbup-gbsta = abc-gbsta.
    vbup-lfgsa = abc-lfgsa.
    vbup-absta = abc-absta.
 
    APPEND  abc.                            "Coment this
   modify abc index Sy-tabix.           "write this
    MODIFY vbup FROM TABLE abc.  "you are updating VBUP inside the loop so you can update by line by line
Modify VBUP from abc.  "write this
if sy-subrc = o.
commit work.
else.
roll back.
endif.

 
  ENDLOOP.

Regrads,

Prabhudas

Read only

0 Likes
743

try this way

LOOP AT abc WHERE vbeln IN so AND posnr IN li.
 
    abc-gbsta = status.
    abc-lfgsa = status.
    abc-absta = status.
 
    vbup-gbsta = abc-gbsta.
    vbup-lfgsa = abc-lfgsa.
    vbup-absta = abc-absta.
 
    modify  abc transporting gbsta lfgsa absta . " changing the internal table data.
    MODIFY vbup FROM TABLE abc. " changing the DB table
 
  ENDLOOP.

Read only

Former Member
0 Likes
743

You are trying to modify a standard SAP table. Have you done the analysis to ensure that there will not be problems with data consistency?

Rob