Skip to Content
-2

Restrict input according to the previous value of the field, Module Pool Programming.

Mar 12, 2017 at 02:01 PM

172

avatar image
Former Member


I am currently designing a custom screen in Module Pool for For Fleet Management (delivery trucks). The client wants to maintain the history of the Vehicle and the associated Driver. Each time there is a Release/ Receival of Vehicle The Primary keu autoupdates to create a new record

The Vehicle Stataus Field (trans_type) contains 2 values:

1. Release to Driver
2. Receive from Driver.

The user should not be allowed to save Release/ Receive of the same Vehicle twice on any future date.

I tried this select query but the user is allowed to give the same vehicle status with different date, which sould not be allowed. Kindly help in this regard.

When 'SAVE'.

Select *
from ztable
into table it_ztable
where vehicle_ID = ztable-vehicle_ID.

SORT it_ztable by vdate descending.

IF sy-subrc = 0.

Message ' Vehicle already Released/ Received' Type 'E'.

ELSE.

Message : i002 (c5) with ' New Transaction Created'.

Perform GEN_NEXT. " FM for Primary Key Auto generate.

Modify Ztable.

10 |10000 characters needed characters left characters exceeded

There is nothing especially challenging about the requirement and I'm sorry but you need to learn how to program before you start work. (Or someone needs to supervise and guide you until you gain more experience.) The question shows no evidence of troubleshooting. You can use debugger to find why "the user is allowed to give the same vehicle status with different date" and adjust the program accordingly or come back with more specific questions.

I had to learn module pool programming myself at some point but you'll find 0 questions from me on SCN on this. I simply used the existing SAP programs and documentation. This is what ABAPers do, it's our job.

1
Former Member

Thanks for the word of advice. Infact, this is better than the answer since you went out of the way and showed me how to think and where to look for when faced with such problems. Sorry if my question was not up to the standard, will try harder to look for the solution in the above mentioned places as per your advice before I post any further questions on SCN.

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Matthew Billingham
Mar 13, 2017 at 07:05 AM
1

Use the locking mechanism (ENQUEUE/DEQUEUE).

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Kindly, bear with me as I am new to ABAP. I created a Lock table and called the ENQUEUE Function Module in my program as below. But still it allows me to change the date and save the last or previous status of the vehicle again. Kindly direct me as to where is my mistake ?.

WHEN 'SAVE'.

Select *
from ztable
INTO TABLE it_ztable
WHERE vehicle_ID = ztable-vehicle_ID
AND trans_type = ztable-trans_type
AND vdate = ztable-vdate.

if sy-subrc = 0 .

Message 'Vehicle already Released/Received' type 'E'.

CALL FUNCTION 'ENQUEUE_EZLOCK2'
EXPORTING
MODE_ZTABLE = 'E'
MANDT = SY-MANDT
TRANS_KEY = ZTABLE-TRANS_KEY
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS.

ELSE.

Message 'New Transaction Created' type 'S'.

PERFORM GEN_NEXT.

MODIFY Ztable.

ENDIF.

0

You need to read up on logical units of work, and how to use the enqueue/dequeue mechanism, It's all well documented, it's in your course notes and there are many examples if you'll search.

1
Former Member

Thanks for your quick reply, will look into it.

0
Venkatramesh V Mar 13, 2017 at 07:28 AM
-2

Hi,

Try this,

TYPES:
BEGIN OF ty_id,
NO(10),
status(10),
date TYPE DATS,
flag TYPE c,
END OF ty_id.

DATA: it_id TYPE TABLE OF ty_id,
wa_id LIKE LINE OF it_id,
it_rec LIKE it_id,
it_rel LIKE it_id.
FIELD-SYMBOLS: <fs> LIKE LINE OF it_id.


PARAMETERS: p_id(10) TYPE C,
p_stat(10) TYPE c.
START-OF-SELECTION.
wa_id-no = '1'.
wa_id-status = 'REL'.
wa_id-date = '20170101'.
APPEND wa_id to it_id.

wa_id-no = '1'.
wa_id-status = 'REC'.
wa_id-date = '20170110'.
APPEND wa_id to it_id.

wa_id-no = '2'.
wa_id-status = 'REL'.
wa_id-date = '20170110'.
APPEND wa_id to it_id.
SORT it_id by no status.
it_rel[] = it_id[].
it_rec[] = it_id[].

DELETE it_rec WHERE status NE 'REC'.
DELETE it_rel WHERE status NE 'REL'.

"Logic without releasing vehicle can't be recieved irrespective of date's

LOOP AT it_rel ASSIGNING <fs>. "Released
READ TABLE it_rec TRANSPORTING NO FIELDS WITH key no = wa_id-no.
IF sy-subrc IS INITIAL.
DELETE it_rel INDEX sy-tabix.
ENDIF.
ENDLOOP.

READ TABLE it_rel TRANSPORTING NO FIELDS WITH KEY no = p_id.
IF sy-subrc <> 0.
IF p_stat = 'REC'.
MESSAGE 'Not Released for choosing Receive Options ' TYPE 'E'.
ENDIF.
ELSE.
IF p_stat = 'REC'.
MESSAGE 'Already Released only recieved options is available' TYPE 'E'.
ENDIF.
ENDIF.

Hope it helful,

Regards,

Ramesh

Share
10 |10000 characters needed characters left characters exceeded
VINAY REDDY Mar 13, 2017 at 06:32 AM
-3

hi ,

irrespective of date check vehicle id , if it already exists in data base throw an error..

regards,

vinay.

Share
10 |10000 characters needed characters left characters exceeded