Control out of hand....

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
A Thompson

Control out of hand....

Post by A Thompson » Wed Feb 19, 2003 4:24 pm

Hi,

I've a transaction program to enter records, store them in an internal table to use them in a BDC program. Once I 'save' records, they are saved but, whatever action i perform afterwards (even 'clear' also is clearing values but inserting BLANK records...) the control was returning to loop...endloop and it's inserting records again and again. what could be the basic problem and how to address this? thanks in advance.

best wishes,

A Thompson.

Jumanji
Posts: 23
Joined: Wed Feb 19, 2003 12:48 am
Location: Hyderabad, India

Control out of hand....

Post by Jumanji » Thu Feb 20, 2003 1:12 am

Hi Thompson,
I think u r not clearing ok_code.
If u r clearing ok_code, please check where u have pleced the insert command.If u can give me the code i can help u.

bye

A Thompson

Post by A Thompson » Thu Feb 20, 2003 4:29 am

Hi Jumanji,

Thanks a lot. I'm providing my code below.

"THIS IS HOW MY MODULE POOL PROGRAM LOOKS LIKE (I'VE IGNORED THE CODE WHICH IS NOT RELEVANT)".


DATA: OKCODE(10).

CONTROLS: ZSTOCK TYPE TABLEVIEW USING SCREEN 9002.

TABLES: LFA1, ZSTOCK_INTAKE, TZONE, DYNPREAD, TZONT.

DATA: LINE_COUNT TYPE I,
RECORDS TYPE I,
ARRIVAL_TIME(5),
TRIP_START(5),
TRIP_END(5),
DATE LIKE SY-DATUM,
TRIP(5).


DATA: BEGIN OF STOCK_ITAB OCCURS 10,
ROUTE LIKE ZSTOCK_INTAKE-ZROUTE_NUMBER,
VEHICLE LIKE ZSTOCK_INTAKE-ZVEHICLE_NUMBER,
ARRIVAL(4),
HAULIER LIKE ZSTOCK_INTAKE-ZHAULIER,
TRIPSTART(4),
TRIPEND(4),
TEMPARATURE LIKE ZSTOCK_INTAKE-ZTEMPARATURE,
DATE LIKE ZSTOCK_INTAKE-ZDATE,
NUMBER(10)," LIKE ZSTOCK_INTAKE-ZSUPPLIER_NUMBER,
SILO1 LIKE ZSTOCK_INTAKE-ZSILO1,
SILO2 LIKE ZSTOCK_INTAKE-ZSILO2,
SILO3 LIKE ZSTOCK_INTAKE-ZSILO3,
SILO4 LIKE ZSTOCK_INTAKE-ZSILO4,
SILO5 LIKE ZSTOCK_INTAKE-ZSILO5,
SILO6 LIKE ZSTOCK_INTAKE-ZSILO6,
SILO7 LIKE ZSTOCK_INTAKE-ZSILO7,
TOTAL LIKE ZSTOCK_INTAKE-ZTOTAL,
NAME LIKE ZSTOCK_INTAKE-ZSUPPLIER_NAME,
END OF STOCK_ITAB,
TOTAL LIKE ZSTOCK_INTAKE-ZTOTAL.


DATA: WA_STOCK LIKE STOCK_ITAB.


MODULE STATUS_9002 OUTPUT.
SET PF-STATUS 'YDSTOCK_INTAKE'.
SET TITLEBAR 'YDSTOCK'.

ENDMODULE. " STATUS_9002 OUTPUT


MODULE DISPLAY_VALUES OUTPUT.
ZSTOCK_INTAKE-ZSUPPLIER_NAME = FNAME.
ZSTOCK_INTAKE-ZSUPPLIER_NUMBER = STOCK_ITAB-NUMBER.
ZSTOCK_INTAKE-ZSILO1 = STOCK_ITAB-SILO1.
TOTAL = WA_STOCK-TOTAL.
ENDMODULE. " DISPLAY_VALUES OUTPUT


MODULE EXIT_9002 INPUT.
CASE OKCODE.
WHEN 'BACK'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'CANCEL'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDMODULE.

MODULE USER_COMMAND_9002 INPUT.

CASE OKCODE.
WHEN 'SAVE'.
TOTAL = WA_STOCK-TOTAL.
WHEN 'ENTR'.
TOTAL = STOCK_ITAB-TOTAL.
PERFORM FARM_NAME.
PERFORM ROUTE_NAME.
PERFORM HAULIER_NAME.
ENDMODULE. " USER_COMMAND_9002 INPUT



MODULE MOVE_VALUES INPUT.

WA_STOCK-ROUTE = TZONE-ZONE1.
WA_STOCK-VEHICLE = ZSTOCK_INTAKE-ZVEHICLE_NUMBER.
WA_STOCK-DATE = DATE.
WA_STOCK-ARRIVAL = ARRIVAL_TIME.
WA_STOCK-TRIPSTART = TRIP_START.
WA_STOCK-TRIPEND = TRIP_END.
WA_STOCK-HAULIER = LFA1-LIFNR.
WA_STOCK-TEMPARATURE = ZSTOCK_INTAKE-ZTEMPARATURE.
WA_STOCK-NUMBER = ZSTOCK_INTAKE-ZSUPPLIER_NUMBER.
WA_STOCK-SILO1 = ZSTOCK_INTAKE-ZSILO1.
WA_STOCK-SILO2 = ZSTOCK_INTAKE-ZSILO2.
WA_STOCK-SILO3 = ZSTOCK_INTAKE-ZSILO3.
WA_STOCK-TOTAL = WA_STOCK-TOTAL + ZSTOCK_INTAKE-ZSILO1.


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_STOCK-NUMBER
IMPORTING
OUTPUT = WA_STOCK-NUMBER.


INSERT WA_STOCK INTO TABLE STOCK_ITAB.
IF SY-SUBRC EQ 0.
MESSAGE S005(ZSTOCK) WITH SY-TABIX.
ELSE.
MESSAGE I006(ZSTOCK).
ENDIF.
ENDMODULE. " MOVE_VALUES INPUT


MODULE TIMES INPUT.
CASE OKCODE.
WHEN 'ARR'.
ARRIVAL_TIME = SY-UZEIT+0(4).
WHEN 'T_START'.
TRIP_START = SY-UZEIT+0(4).
WHEN 'T_END'.
TRIP_END = SY-UZEIT+0(4).
ENDCASE.
ENDMODULE. " TIMES INPUT

FORM FARM_NAME.

SELECT NAME2 FROM LFA1 INTO FNAME
WHERE LIFNR = STOCK_ITAB-NUMBER.
ZSTOCK_INTAKE-ZSUPPLIER_NAME = FNAME.
ENDSELECT.

ENDFORM.

FORM ROUTE_NAME.
DATA: RNAME LIKE TZONT-VTEXT.
SELECT VTEXT FROM TZONT INTO RNAME
WHERE ZONE1 = TZONE-ZONE1.
TZONT-VTEXT = RNAME.
ENDSELECT.
ENDFORM.

FORM HAULIER_NAME.
DATA: HNAME LIKE LFA1-NAME1.
SELECT NAME1 FROM LFA1 INTO HNAME
WHERE LIFNR = LFA1-LIFNR.
LFA1-NAME1 = HNAME.
ENDSELECT.
ENDFORM.


"MY PBO AND PAI LOOKS LIKE THIS"


PROCESS BEFORE OUTPUT.
MODULE STATUS_9002.
*
MODULE TIMES_PBO.

MODULE DYN_VALUES.

LOOP AT STOCK_ITAB WITH CONTROL ZSTOCK CURSOR ZSTOCK-CURRENT_LINE.
MODULE DISPLAY_VALUES.
ENDLOOP.

PROCESS AFTER INPUT.

MODULE EXIT_9002 AT EXIT-COMMAND.


MODULE TIMES.



LOOP AT STOCK_ITAB.
MODULE MOVE_VALUES.
*MODULE LINE_COUNT.
ENDLOOP.


MODULE USER_COMMAND_9002.


I tried with CLEAR OKCODE (after i used every 'WHEN' statement) but that was giving me some bizarre results so i've deleted all of them. any suggestions for me? Thanks in advance.

Best Wishes,

A Thompson.

Jumanji
Posts: 23
Joined: Wed Feb 19, 2003 12:48 am
Location: Hyderabad, India

Post by Jumanji » Thu Feb 20, 2003 4:50 am

Hi Thompson,
The problem is that u r inserting every time u r entering into PAI without any condition.Therefore for every action performed wether it is enter or any button it will go into PAI and it will insert the record.
what u can do here is check before inserting check if all the fields are empty(ie; complete empty record).if the record is completely empty,do not insert else insert.
As for okcode it is actually must to clear ok_code after when.
suppose u say insert, ur okcode will have 'insert'.if u dont clear it,everytime u press enter,when the control reaches PAI,the okcode is still insert and it wil insert a new record.

would be happy to clear any more doubts
bye

Post Reply