ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to do simple user input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to do simple user input

    I'm new to RPGLE and can't find a single good tutorial anywhere. Could someone please post code for a simple program that;
    1.) Displays "Hello, what is your name?"
    2.) Accepts user input to a variable $name
    3.) Echos back out "It's nice to meet you ". $name

  • #2
    Originally posted by Cbauer00010010 View Post
    I'm new to RPGLE and can't find a single good tutorial anywhere. Could someone please post code for a simple program that;
    1.) Displays "Hello, what is your name?"
    2.) Accepts user input to a variable $name
    3.) Echos back out "It's nice to meet you ". $name
    Here's a tutorial for experienced programs who are new to RPG: https://ibm.biz/rpgCafe_Freeform_Rpg_Tutorial

    Here's a quick and dirty program that will do (sort of) what you want:
    Code:
    **free
    dcl-s name varchar(25);
    dsply 'What is your name?' '' name;
    dsply 'It''s nice to meet you, ' '' name;
    return;
    I say "sort of", because the messages output by the DSPLY opcode all have the word "DSPLY" at the beginning. And the spacing between the "nice to meet you" and the name isn't ideal.
    Code:
    DSPLY  What is your name?               
    X                                       
    DSPLY  It's nice to meet you,    X
    I could have coded the last dsply like this, with better spacing:
    Code:
    dsply ('It''s nice to meet you, ' + name);
    but sometimes when you call a program with only one operand for the DSPLY opcode, the DSPLY might just flash by before you can read it. ("Hello-world" isn't necessarily that simple for RPG ...)

    Chapter 5 (Display Files) of the tutorial has a nicer way of interacting with a user, using a display file. But I'd work through the first four chapters first.

    Comment


    • #3
      Thank you Barbara, that works perfectly. I just need to get some working code so the DSPLY and spacing aren't an issue yet. I'll work through those tutorials.

      Comment

      Working...
      X