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: 

Guessing an ABAP PIN in 3 attempts using a loop?

0 Kudos
DATA: pin_correct TYPE i VALUE 1234.
DATA pin_correct TYPE i VALUE 1234.
PARAMETERS lv_pin TYPE i.

if lv_pin EQ pin_correct.
WRITE 'Richtig'.
else.
WRITE' Falsch'.
ENDIF. 
  

Als Neuling in der Programmierung frage ich mich, ob es möglich ist, den Code in einer Schleife zu integrieren, die dem Benutzer drei Versuche gibt, um den PIN zu erraten. Kann mir jemand dabei helfen oder einen Tipp geben?

3 REPLIES 3

moshenaveh
Community Manager
Community Manager
0 Kudos

Welcome to the SAP Community. Thank you for visiting us to get answers to your questions.

Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.

First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Second, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html, as that will help you when submitting questions to the community.

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

Now for some specific suggestions on how you might improve your question:

* Outline what steps you took to find answers (and why they weren't helpful) -- so members don't make suggestions that you've already tried.

* Share screenshots of what you've seen/done (if possible), as images always helps our members better understand your problem.

Should you wish, you can revise your question by selecting Actions, then Edit.

The more details you provide (in questions tagged correctly), the more likely it is that members will be able to respond.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

Sandra_Rossi
Active Contributor
0 Kudos

Better use a German title if you ask the question in German.

turkaj
Active Participant

Hallo Obaidulllah,

du kannst in deinem Report die Fehlversuche hochzählen und wenn 3 Fehlversuche gemacht wurden. Hierfür habe ich jetzt den Befehl MEMORY ID verwendet um die Anzahl der Fehlversuche in einer Memory Variable PIN_DATA zu speichern. Besser ist sowas natürlich, wenn du es richtig implementieren willst in einer Datenbanktabelle userabhängig zu speichern oder was genau deine Anforderung ist. Der Memoryspeicher wird zurückgesetzt wenn der Wert richtig angegeben wird. Dieses Coding ist nur ein Beispiel und du kannst selber noch weiter damit experimentieren.

*&---------------------------------------------------------------------*
*& Report  zpin_entry
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zpin_entry.<br>DATA: pin_correct TYPE i VALUE 1234.
DATA: BEGIN OF gs_pin_data,
        attempts TYPE i,
      END OF gs_pin_data.

PARAMETERS: p_pin TYPE i.

INITIALIZATION.
  IMPORT gs_pin_data FROM MEMORY ID 'PIN_DATA'.
  IF sy-subrc NE 0.
    CLEAR gs_pin_data.
  ENDIF.

AT SELECTION-SCREEN.
  IF p_pin NE pin_correct.
    ADD 1 TO gs_pin_data-attempts.

    IF gs_pin_data-attempts >= 3.
      FREE MEMORY ID 'PIN_DATA'.
      MESSAGE 'Fehler: Zu viele Versuche' TYPE 'E'.
    ELSE.
      MESSAGE |Falsch - { gs_pin_data-attempts }| TYPE 'I'.
    ENDIF.
  ELSE.
    MESSAGE 'Richtig' TYPE 'I'.
    FREE MEMORY ID 'PIN_DATA'.
    LEAVE PROGRAM.
  ENDIF.

START-OF-SELECTION.

END-OF-SELECTION.
  EXPORT gs_pin_data TO MEMORY ID 'PIN_DATA'.

In einem LOOP geht das nicht direkt, da du hier den Prozess unterbrechen müsstest und die neue Eingabe validieren.

Gruß
Jim